Commit 907ebb6c by 刘鑫

fix(ID1004119): 工程师存在容量,改约查询容量时全部显示置灰---更改查询逻辑为返回分站下的容量

1 parent e5c9fdae
......@@ -94,6 +94,23 @@ public interface EngineerInfoDao extends JpaRepository<EngineerInfoEntity, Integ
" order by ei.engineer_code desc", nativeQuery = true)
Set<EngineerInfoEntity> listBySkillGroupCode(@Param("skillGroupCodes") Collection<String> skillGroupCodes, @Param("skillGroupNumber") int skillGroupNumber, @Param("teamId") String teamId);
/**
* 查询在指定分站,指定技能组中至少满足 skillGroupCodes.size 个技能的工程师
*
* @param skillGroupCodes 技能组编码
* @param skillGroupNumber 至少拥有其中skillGroupCodes.size 个技能
* @param groupId 分站ID
* @return 工程师信息
*/
@Query(value = "SELECT ei.* FROM " +
" (SELECT esg.engineer_code AS engineer_code FROM engineer_skill_group esg " +
" WHERE esg.status = 1 AND esg.skill_group_code IN( :skillGroupCodes ) group by esg.engineer_code having count(esg.skill_group_code) = :skillGroupNumber " +
" ) AS tabA " +
" LEFT JOIN engineer_info ei ON ei.engineer_code = tabA.engineer_code " +
" WHERE ei.group_id = :groupId AND ei.id is not null " +
" order by ei.engineer_code desc ", nativeQuery = true)
Set<EngineerInfoEntity> listByBranchSkillGroupCode(@Param("skillGroupCodes") Collection<String> skillGroupCodes, @Param("skillGroupNumber") int skillGroupNumber, @Param("groupId") String groupId);
@Query(value = "SELECT ei.* from engineer_info ei left join engineer_skill_group esg on ei.engineer_code = esg.engineer_code " +
"left join skill_info si on si.skill_group_code = esg.skill_group_code left join map_layer_customize mlc on mlc.layer_id = si.layer_id " +
......
......@@ -57,11 +57,19 @@ public interface EngineerCalendarService {
* @param teamId 工作队
* @param engineerCode 工程师编号
* @param targetDate 目标日期
* @return 工作队内日期工作时间信息
* @return 是否是工作队内日期工作时间
*/
boolean engineerTeamDateWorkTime(String teamId, String engineerCode, LocalDate targetDate);
/**
* 判定工程师只顶你日期是否休息日
* @param engineerCode 工程师编号
* @param targetDate 目标日期
* @return 是否是工作日
*/
boolean engineerWorkDay(String engineerCode, LocalDate targetDate);
/**
* 获取工程师的工作时间窗
*
* @param engineerCode 工程师编号
......
......@@ -131,8 +131,8 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
.collect(Collectors.toList());
List<String> branchList = mapBlockInBlockIdsList.stream().map(MapBlockInfoEntity::getBranchId).distinct()
.collect(Collectors.toList());
final String teamId = teamIdList.get(0);
final String branchId = branchList.get(0);
final String groupId = groupList.get(0);
//3. 查询分站下拥有对应技能的工程师(排重) 技能码转换为对应的技能汉字
List<SkillInfoEntity> querySkillGroup = new ArrayList<>();
......@@ -151,8 +151,8 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
}
Set<EngineerInfoEntity> allFulfillEngineer = engineerInfoDao.listBySkillGroupCode(skillGroupCodes,
skillGroupCodes.size(), teamId);
Set<EngineerInfoEntity> allFulfillEngineer = engineerInfoDao.listByBranchSkillGroupCode(skillGroupCodes,
skillGroupCodes.size(), groupId);
//查询同时拥有技能组代码的人员信息
log.info("[matchCapacityData]【符合技能要求的工程师总数为:{} 个】", allFulfillEngineer.size());
......@@ -170,12 +170,12 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
}
CopyOnWriteArrayList<TimeSliceEntity> timeSliceEntities = new CopyOnWriteArrayList<>();
if (branchInfo.getCapacityType() == 0) {
timeSliceEntities.addAll(getTimeSliceEntities(teamId));
timeSliceEntities.addAll(getGroupTimeSliceEntities(teamIdList));
}
//定义返回值
CapacityQueryDTO.Result result = new CapacityQueryDTO.Result();
result.setGroupId(groupList.get(0));
result.setGroupId(groupId);
result.setTakeTime(totalTakeTime);
final int corePoolSize = Runtime.getRuntime().availableProcessors();
......@@ -188,7 +188,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, teamId);
totalTakeTime, allDayTypeTimeSlice, timeSliceEntities, semaphore);
Future<CapacityQueryDTO.Data> dataFuture = poolExecutor.submit(task);
futureDatas.add(dataFuture);
currentDate = currentDate.plusDays(1);
......@@ -210,13 +210,37 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
return Result.success(result);
}
private CopyOnWriteArrayList<TimeSliceEntity> getTimeSliceEntities(String teamId) {
private CopyOnWriteArrayList<TimeSliceEntity> getTeamTimeSliceEntities(String teamId) {
//获取工作队信息
OrgTeamEntity team = orgTeamDao.getByTeamId(teamId);
String workOn = String.format("%s:00", team.getWorkOn());
String workOff = String.format("%s:00", team.getWorkOff());
LocalTime teamWorkStartTime = LocalTime.parse(workOn, DateUtil.TIME_FORMATTER);
LocalTime teamWorkEndTime = LocalTime.parse(workOff, DateUtil.TIME_FORMATTER);
return getTimeSliceEntities(teamWorkStartTime, teamWorkEndTime);
}
private CopyOnWriteArrayList<TimeSliceEntity> getGroupTimeSliceEntities(List<String> teamIdOfGroup) {
List<LocalTime> allStartTime = new ArrayList<>();
List<LocalTime> allEndTime = new ArrayList<>();
//获取工作队信息
for (int i = 0; i < teamIdOfGroup.size(); i++) {
OrgTeamEntity team = orgTeamDao.getByTeamId(teamIdOfGroup.get(i));
String workOn = String.format("%s:00", team.getWorkOn());
String workOff = String.format("%s:00", team.getWorkOff());
LocalTime teamWorkStartTime = LocalTime.parse(workOn, DateUtil.TIME_FORMATTER);
allStartTime.add(teamWorkStartTime);
LocalTime teamWorkEndTime = LocalTime.parse(workOff, DateUtil.TIME_FORMATTER);
allEndTime.add(teamWorkEndTime);
}
LocalTime minTeamWorkStartTime = allStartTime.stream().min(LocalTime::compareTo).get();
LocalTime maxTeamWorkEndTime = allStartTime.stream().max(LocalTime::compareTo).get();
return getTimeSliceEntities(minTeamWorkStartTime, maxTeamWorkEndTime);
}
private CopyOnWriteArrayList<TimeSliceEntity> getTimeSliceEntities(LocalTime teamWorkStartTime, LocalTime teamWorkEndTime) {
//切片开始时间
LocalTime sliceStartHour = LocalTime.of(teamWorkStartTime.getHour(), 0);
//切片结束时间
......@@ -462,10 +486,6 @@ 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 {
......@@ -473,7 +493,7 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
try {
semaphore.acquire();
data = getData(allFulfillEngineer, currentDate, halfDayTypeTimeSlice,
totalTakeTime, allDayTypeTimeSlice, timeSliceEntities, teamId);
totalTakeTime, allDayTypeTimeSlice, timeSliceEntities);
} catch (InterruptedException e) {
log.error("【计算日期为:{} 的容量失败】Task: 失败原因{}", currentDate, e.getMessage());
} finally {
......@@ -485,11 +505,11 @@ 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, String targetTeamId) {
List<TimeSliceEntity> timeSliceEntities) {
List<CapacityEngineerSliceUsedEntity> allEngineerTimeSlice = new CopyOnWriteArrayList<>();
for (EngineerInfoEntity engineerInfo : allFulfillEngineer) {
//一个工程师多个工作队情况,获取当前工作队的工作日期, 如果是则将当天的时间片容量纳入计算范围, 否则不纳入
boolean isWorkDay = engineerCalendarService.engineerTeamDateWorkTime(targetTeamId, engineerInfo.getEngineerCode(), currentDate);
boolean isWorkDay = engineerCalendarService.engineerWorkDay(engineerInfo.getEngineerCode(), currentDate);
if (isWorkDay) {
List<CapacityEngineerSliceUsedEntity> engineerTimeSlice = engineerSliceUsedCapacityDao
.findByWorkdayAndEngineerCode(DateTimeUtil.formatDate(currentDate), engineerInfo.getEngineerCode());
......
......@@ -615,6 +615,23 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
}
@Override
public boolean engineerWorkDay(String engineerCode, LocalDate targetDate) {
//查询工程师所有工作队
//获取工作队休息时间, 判定目标时间是否在工作队休息日中
Set<OrgTeamEntity> teams = orgTeamDao.selectTeamByEngineerCode(engineerCode);
if (CollectionUtils.isEmpty(teams)) {
return false;
}
List<String> teamCommonWorkdaysOfWeek = teams.stream()
.map(team -> Arrays.asList(team.getWorkdays().split(",")))
.flatMap(Collection::stream)
.distinct()
.collect(Collectors.toList());
final int dayOfWeek = targetDate.getDayOfWeek().getValue();
return ALL_WORK_DAY_OF_WEEK.contains(String.valueOf(dayOfWeek));
}
@Override
public int[][] timeWindows(String engineerCode, String teamId, LocalDate targetDate) {
final LocalDateTime minDate = LocalDateTime.of(targetDate, LocalTime.MIN);
//工作时间与时间时间并集求差集
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!