Commit 8cb9e567 by 刘鑫

Merge branch 'develop-16542' into 'develop'

Develop 16542

See merge request !366
2 parents e171ae61 9f35b44d
......@@ -28,6 +28,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
......@@ -244,11 +245,11 @@ public class CapacityUtils {
.flatMap(Collection::stream).collect(Collectors.toList());
timeSlots = calculateUnion(timeSlots);
long engineerMaxDuration = Optional.ofNullable(timeSlots).orElse(Collections.emptyList())
OptionalLong optionalEngineerMaxDuration = Optional.ofNullable(timeSlots).orElse(Collections.emptyList())
.stream()
.mapToLong(OccupyInfoDetail::getDuration)
.sum();
engineerMaxDurationList.add(engineerMaxDuration);
.mapToLong(t1 -> Duration.between(t1.getBeginTime(), t1.getEndTime()).abs().toMinutes())
.max();
engineerMaxDurationList.add(optionalEngineerMaxDuration.orElse(0L));
});
long maxDuration = Collections.max(engineerMaxDurationList);
......
......@@ -71,7 +71,7 @@ public interface EngineerInfoDao extends JpaRepository<EngineerInfoEntity, Integ
" LEFT JOIN engineer_info ei ON esg.engineer_code = ei.engineer_code\n" +
" LEFT JOIN org_team_engineer ote ON ote.engineer_code = ei.engineer_code \n" +
" WHERE si.brand = :brand AND si.type= :productType AND si.skill = :skill \n" +
" AND ote.team_id = :teamId ", nativeQuery = true)
" AND ote.team_id = :teamId AND ote.status = 1", nativeQuery = true)
Set<EngineerInfoEntity> listByBrandAndTypeAndSkillAndTeamId(@Param("brand") String brand, @Param("productType") String productType,
@Param("skill") String skill, @Param("teamId") String teamId);
......@@ -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 AND ote.`status` = 1", nativeQuery = true)
EngineerInfoEntity selectEngineerByEngineerCodeAndTeamId(@Param("engineerCode") String engineerCode, @Param("teamId") String teamId);
}
......@@ -51,6 +51,7 @@ public interface OrgTeamDao extends JpaRepository<OrgTeamEntity, Integer>, JpaSp
* @param engineerCode 工程师代码
* @return 工程师所在工作队信息
*/
@Query(value = "SELECT ot.* FROM org_team ot LEFT JOIN org_team_engineer ote ON ote.team_id = ot.team_id WHERE ote.engineer_code = :engineerCode", nativeQuery = true)
@Query(value = "SELECT ot.* FROM org_team_engineer ote LEFT JOIN org_team ot ON ote.team_id = ot.team_id WHERE ote.engineer_code = :engineerCode " +
" AND ote.`status` = 1 AND ot.status = 1 ", nativeQuery = true)
Set<OrgTeamEntity> selectTeamByEngineerCode(String engineerCode);
}
......@@ -15,39 +15,39 @@ public class ScheduleEngineerOverviewResp {
private List<TimeLineDTO> orders;
private List<Order> orderDetails;
@Data
public static class Order {
private String orderId;
private String location;
private String type;
private String skill;
private String orderStatus;
private String orderStatusName;
/**
* 在途公里数
*/
private Integer distance;
/**
* 上门时间
*/
private String arriveTime;
private String timeType;
/**
* 在途时间段
*/
private String expectArriveDuration;
/**
* 实际到达时间
*/
private String arriveDuration;
/**
* 计划工时
*/
private String expectWorkDuration;
/**
* 工实际工时
*/
private String workDuration;
}
@Data
public static class Order {
private String orderId;
private String location;
private String type;
private String skill;
private String orderStatus;
private String orderStatusName;
/**
* 在途公里数
*/
private Integer distance;
/**
* 上门时间
*/
private String arriveTime;
private String timeType;
/**
* 在途时间段
*/
private String expectArriveDuration;
/**
* 实际到达时间
*/
private String arriveDuration;
/**
* 计划工时
*/
private String expectWorkDuration;
/**
* 工实际工时
*/
private String workDuration;
}
}
......@@ -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);
}
package com.dituhui.pea.order.service.impl;
import cn.hutool.core.util.IdUtil;
import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.DateUtils;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.dao.EngineerInfoDao;
import com.dituhui.pea.order.dao.OrgGroupDao;
import com.dituhui.pea.order.dao.OrgTeamDao;
import com.dituhui.pea.order.dao.OrgTeamEngineerDao;
import com.dituhui.pea.order.dao.OrgWarehouseInfoDao;
import com.dituhui.pea.order.dto.BusinessTeamAddDTO;
import com.dituhui.pea.order.dto.BusinessTeamConfigInitDTO;
import com.dituhui.pea.order.dto.BusinessTeamConfigSubmitDTO;
import com.dituhui.pea.order.dto.BusinessTeamDeleteDTO;
import com.dituhui.pea.order.dto.BusinessTeamDetailDTO;
import com.dituhui.pea.order.dto.BusinessTeamUpdateDTO;
import com.dituhui.pea.order.dto.BusinessTeamWarehousesDTO;
import com.dituhui.pea.order.dto.BusinessTeamsDTO;
import com.dituhui.pea.order.entity.OrgGroupEntity;
import com.dituhui.pea.order.entity.OrgTeamEngineerEntity;
import com.dituhui.pea.order.entity.OrgTeamEntity;
......@@ -12,6 +24,7 @@ import com.dituhui.pea.order.entity.OrgWarehouseInfoEntity;
import com.dituhui.pea.order.service.BusinessTeamService;
import com.dituhui.pea.order.service.CommonService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
......@@ -20,10 +33,18 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.MessageFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import static com.dituhui.pea.order.config.OrderConfig.TEAMTYPE_PEA;
......@@ -190,20 +211,47 @@ public class BusinessTeamServiceImpl implements BusinessTeamService {
// 技术员列表
if (req.getEngineerCodes() != null && !req.getEngineerCodes().isEmpty()) {
updateTeamEngineers(req.getTeamId(), req.getEngineerCodes());
updateTeamEngineers(entity, req.getEngineerCodes());
}
return Result.success(null);
}
public void updateTeamEngineers(String teamId, List<String> engineerCodes) {
public void updateTeamEngineers(OrgTeamEntity targetTeam, List<String> engineerCodes) {
// 获取现有的工作队和技术员之间的所有关系
List<OrgTeamEngineerEntity> existingRelations = orgTeamEngineerDao.findAllByTeamId(teamId);
final String targetTeamId = String.valueOf(targetTeam.getId());
List<String> targetTeamWorkDayOfWeek = List.of(targetTeam.getWorkdays().split(","));
List<OrgTeamEngineerEntity> existingRelations = orgTeamEngineerDao.findAllByTeamId(targetTeamId);
// 查询工程师在其它工作队的工作时间以及当前工作队的工作时间
final String message = "工号为{0}的工程师在{1}工作队的周{2}已有工作日安排";
List<String> warnMessage = new ArrayList<>();
for (String engineerCode : engineerCodes) {
Set<OrgTeamEntity> teamEntitySet = orgTeamDao.selectTeamByEngineerCode(engineerCode);
if (CollectionUtils.isEmpty(teamEntitySet)) {
continue;
}
//移除当前工作队并校验工作队工作时间
teamEntitySet.stream()
.filter(t -> !Objects.equals(targetTeamId, t.getTeamId()))
.forEach(team -> {
//返回任何一个有工作日冲突的工作队
List<String> fixedWorkDayOfWeek = List.of(team.getWorkdays().split(","));
List<String> workDays = targetTeamWorkDayOfWeek.stream().filter(dayOfWeek -> fixedWorkDayOfWeek.stream().anyMatch(fixDay -> Objects.equals(fixDay, dayOfWeek)))
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(workDays)) {
warnMessage.add(MessageFormat.format(message, engineerCode, team.getTeamName(), StringUtils.join(workDays, ",")));
}
});
}
if (!CollectionUtils.isEmpty(warnMessage)) {
throw new BusinessException(StringUtils.join(warnMessage, ";"));
}
// 构建新的关系映射
Map<String, OrgTeamEngineerEntity> newRelationsMap = new HashMap<>();
for (String engineerCode : engineerCodes) {
OrgTeamEngineerEntity relation = new OrgTeamEngineerEntity();
relation.setTeamId(teamId);
relation.setTeamId(targetTeamId);
relation.setEngineerCode(engineerCode);
relation.setCreateTime(LocalDateTime.now());
relation.setUpdateTime(LocalDateTime.now());
......
......@@ -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,
......@@ -118,16 +121,18 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
}
//分站、网点ID
List<String> groupIdList = mapBlockInBlockIdsList.stream().map(MapBlockInfoEntity::getGroupId).distinct()
List<String> teamIdList = mapBlockInBlockIdsList.stream().map(MapBlockInfoEntity::getTeamId).distinct()
.collect(Collectors.toList());
List<String> groupList = mapBlockInBlockIdsList.stream().map(MapBlockInfoEntity::getGroupId).distinct()
.collect(Collectors.toList());
final String groupId = groupIdList.get(0);
final String teamId = teamIdList.get(0);
//3. 查询分站下拥有对应技能的工程师(排重) 技能码转换为对应的技能汉字
List<SkillInfoEntity> querySkillGroup = new ArrayList<>();
Set<EngineerInfoEntity> allFulfillEngineer = Sets.newConcurrentHashSet();
for (CapacityQueryDTO.Service service : services) {
Set<EngineerInfoEntity> engineerInfoEntities = engineerInfoDao.listByBrandAndTypeAndSkillAndGroupId(service.getBrand(),
service.getProductType(), service.getServiceType(), groupId);
Set<EngineerInfoEntity> engineerInfoEntities = engineerInfoDao.listByBrandAndTypeAndSkillAndTeamId(service.getBrand(),
service.getProductType(), service.getServiceType(), teamId);
//查询对应的技能信息
SkillInfoEntity skillInfo = skillInfoDao.getByBrandAndTypeAndSkill(service.getBrand(),
......@@ -154,7 +159,7 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
LocalDate currentDate = beginDate;
//定义返回值
CapacityQueryDTO.Result result = new CapacityQueryDTO.Result();
result.setGroupId(groupId);
result.setGroupId(groupList.get(0));
result.setTakeTime(totalTakeTime);
final int corePoolSize = Runtime.getRuntime().availableProcessors();
......@@ -166,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);
......@@ -210,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());
......@@ -354,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 {
......@@ -361,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 {
......@@ -373,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!