Commit aa078d92 by 刘鑫

feat(容量): 添加一个工程师挂多个工作队逻辑

1 parent d3450601
......@@ -98,4 +98,15 @@ public interface EngineerInfoDao extends JpaRepository<EngineerInfoEntity, Integ
" order by mlc.priority ", nativeQuery = true)
List<EngineerInfoEntity> listBrandAndSkillAndEngineerCodes(@Param("brand") String brand, @Param("productType") String productType,
@Param("skill") String skill, @Param("engineerCodes") List<String> engineerCodes);
/**
* 查询工作队下的指定工程师信息
*
* @param engineerCode 工程师编号
* @param teamId 工作队ID
* @return 工作队下没有工程师则返回空
*/
@Query(value = "SELECT ei.* from org_team_engineer ote left join engineer_info ei ON ote.engineer_code = ei.engineer_code " +
"WHERE ote.team_id = :teamId AND ote.engineer_code = :engineerCode", nativeQuery = true)
EngineerInfoEntity selectEngineerByEngineerCodeAndTeamId(@Param("engineerCode") String engineerCode, @Param("teamId") String teamId);
}
......@@ -43,11 +43,21 @@ public interface EngineerCalendarService {
EngineerCalendarResultDTO queryEngineerCalendar(String engineerCode, LocalDate startDate, LocalDate endDate);
/**
* 获取工程师在指定日期的非工作时间安排 包含工作队休息时间和日程表事件记录时间, 其中日程表内事件未与工作队时间判定交集, 实际计算非工作时间时需求并集
* 获取工程师在指定日期的“非工作”时间安排 包含工作队休息时间和日程表事件记录时间, 其中日程表内事件未与工作队时间判定交集, 实际计算非工作时间时需求并集
*
* @param engineerCode 工程师编号
* @param targetDate 目标日期
* @return 没有交集的事件日程时间段即已占用的时间段
*/
List<OccupyInfoDetail> getEngineerWorkDayCalendar(String engineerCode, LocalDate targetDate);
/**
* 判定工程师指定日期是否在工作队的工作日期
*
* @param teamId 工作队
* @param engineerCode 工程师编号
* @param targetDate 目标日期
* @return 工作队内日期工作时间信息
*/
boolean engineerTeamDateWorkTime(String teamId, String engineerCode, LocalDate targetDate);
}
......@@ -31,6 +31,7 @@ import com.dituhui.pea.order.entity.SkillInfoEntity;
import com.dituhui.pea.order.entity.TimeSliceEntity;
import com.dituhui.pea.order.feign.ISaaSRemoteService;
import com.dituhui.pea.order.service.CapacityQueryService;
import com.dituhui.pea.order.service.EngineerCalendarService;
import com.dituhui.pea.pojo.fendan.FendanDTO;
import com.google.common.collect.Sets;
import lombok.AllArgsConstructor;
......@@ -92,6 +93,8 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
private TimeSliceDao timeSliceDao;
@Autowired
private EngineerSliceUsedCapacityDao engineerSliceUsedCapacityDao;
@Autowired
private EngineerCalendarService engineerCalendarService;
@Override
public Result<CapacityQueryDTO.Result> matchCapacityData(CapacityQueryDTO.Request request,
......@@ -168,7 +171,7 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
while (!currentDate.isAfter(endDate)) {
log.info("【matchCapacityData】----------->开始计算{}的容量", currentDate);
Task task = new Task(allFulfillEngineer, currentDate, halfDayTypeTimeSlice,
totalTakeTime, allDayTypeTimeSlice, timeSliceEntities, semaphore);
totalTakeTime, allDayTypeTimeSlice, timeSliceEntities, semaphore, teamId);
Future<CapacityQueryDTO.Data> dataFuture = poolExecutor.submit(task);
futureDatas.add(dataFuture);
currentDate = currentDate.plusDays(1);
......@@ -212,9 +215,12 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
List<CapacityEngineerSliceUsedEntity> allEngineerTimeSlice = new CopyOnWriteArrayList<>();
for (EngineerInfoEntity engineerInfo : engineerInfoEntities) {
List<CapacityEngineerSliceUsedEntity> engineerTimeSlice = engineerSliceUsedCapacityDao
.findByWorkdayAndEngineerCode(DateTimeUtil.formatDate(targetDate), engineerInfo.getEngineerCode());
allEngineerTimeSlice.addAll(engineerTimeSlice);
boolean isWorkDay = engineerCalendarService.engineerTeamDateWorkTime(teamId, engineerInfo.getEngineerCode(), targetDate);
if (isWorkDay) {
List<CapacityEngineerSliceUsedEntity> engineerTimeSlice = engineerSliceUsedCapacityDao
.findByWorkdayAndEngineerCode(DateTimeUtil.formatDate(targetDate), engineerInfo.getEngineerCode());
allEngineerTimeSlice.addAll(engineerTimeSlice);
}
}
log.info("[matchCapacityData]【符合技能要求的工程师总数为:{} 个】", engineerInfoEntities.size());
......@@ -356,6 +362,10 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
private CopyOnWriteArrayList<TimeSliceEntity> allDayTypeTimeSlice;
private CopyOnWriteArrayList<TimeSliceEntity> timeSliceEntities;
private Semaphore semaphore;
/**
* 工作队ID
*/
private String teamId;
@Override
public CapacityQueryDTO.Data call() throws Exception {
......@@ -363,7 +373,7 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
try {
semaphore.acquire();
data = getData(allFulfillEngineer, currentDate, halfDayTypeTimeSlice,
totalTakeTime, allDayTypeTimeSlice, timeSliceEntities);
totalTakeTime, allDayTypeTimeSlice, timeSliceEntities, teamId);
} catch (InterruptedException e) {
log.error("【计算日期为:{} 的容量失败】Task: 失败原因{}", currentDate, e.getMessage());
} finally {
......@@ -375,12 +385,16 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
public CapacityQueryDTO.Data getData(Set<EngineerInfoEntity> allFulfillEngineer, LocalDate currentDate,
List<TimeSliceEntity> halfDayTypeTimeSlice, int totalTakeTime,
List<TimeSliceEntity> allDayTypeTimeSlice,
List<TimeSliceEntity> timeSliceEntities) {
List<TimeSliceEntity> timeSliceEntities, String targetTeamId) {
List<CapacityEngineerSliceUsedEntity> allEngineerTimeSlice = new CopyOnWriteArrayList<>();
for (EngineerInfoEntity engineerInfo : allFulfillEngineer) {
List<CapacityEngineerSliceUsedEntity> engineerTimeSlice = engineerSliceUsedCapacityDao
.findByWorkdayAndEngineerCode(DateTimeUtil.formatDate(currentDate), engineerInfo.getEngineerCode());
allEngineerTimeSlice.addAll(engineerTimeSlice);
//一个工程师多个工作队情况,获取当前工作队的工作日期, 如果是则将当天的时间片容量纳入计算范围, 否则不纳入
boolean isWorkDay = engineerCalendarService.engineerTeamDateWorkTime(targetTeamId, engineerInfo.getEngineerCode(), currentDate);
if (isWorkDay) {
List<CapacityEngineerSliceUsedEntity> engineerTimeSlice = engineerSliceUsedCapacityDao
.findByWorkdayAndEngineerCode(DateTimeUtil.formatDate(currentDate), engineerInfo.getEngineerCode());
allEngineerTimeSlice.addAll(engineerTimeSlice);
}
}
List<CapacityQueryDTO.Segment> objects = new ArrayList<>();
//计算所有工程师全天天类型容量
......
......@@ -92,6 +92,8 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
@Autowired
private IUser user;
private final static List<String> ALL_WORK_DAY_OF_WEEK = List.of("1", "2", "3", "4", "5", "6", "7");
@Override
public Result<?> getEngineersCalendar(EngineerCalendarDTO.Request req) {
// 技术员日历,查询 capacity_engineer_calendar表,如果当日有各种事项,进行显示;否则显示正常上班;
......@@ -579,11 +581,10 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
.flatMap(Collection::stream)
.distinct()
.collect(Collectors.toList());
List<String> allWorkDayOfWeek = List.of("1", "2", "3", "4", "5", "6", "7");
// 求多个工作队的公共空闲时间
final int dayOfWeek = targetDate.getDayOfWeek().getValue();
List<String> commonLeisureDayOfWeek = allWorkDayOfWeek.stream().filter(day -> teamCommonWorkdaysOfWeek.stream().noneMatch(tDay -> Objects.equals(day, tDay)))
List<String> commonLeisureDayOfWeek = ALL_WORK_DAY_OF_WEEK.stream().filter(day -> teamCommonWorkdaysOfWeek.stream().noneMatch(tDay -> Objects.equals(day, tDay)))
.collect(Collectors.toList());
if (commonLeisureDayOfWeek.contains(String.valueOf(dayOfWeek))) {
LocalDateTime startTime = LocalDateTime.of(targetDate, LocalTime.of(8, 0));
......@@ -596,6 +597,20 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
return calendarInfoList;
}
@Override
public boolean engineerTeamDateWorkTime(String teamId, String engineerCode, LocalDate targetDate) {
//根据工作队信息查工程师, 如果该工作队不存在该工程师直接返回空数组
EngineerInfoEntity engineerInfoEntity = engineerInfoDao.selectEngineerByEngineerCodeAndTeamId(engineerCode, teamId);
if (Objects.isNull(engineerInfoEntity)) {
return false;
}
//排除工作队休息时间(整天)
OrgTeamEntity e = orgTeamDao.getByTeamId(teamId);
List<String> workDay = List.of(e.getWorkdays().split(","));
final int dayOfWeek = targetDate.getDayOfWeek().getValue();
return workDay.contains(String.valueOf(dayOfWeek));
}
private EngineerCalendarDTO.Calendar getEmptyCalendar(String teamId, String date) {
// 初始化一天的日历
OrgTeamEntity e = orgTeamDao.getByTeamId(teamId);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!