Commit aa078d92 by 刘鑫

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

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