Commit 5d7a522a by Ren Ping

Merge remote-tracking branch 'origin/develop' into develop

2 parents 23e3d84e 75f99c75
...@@ -147,6 +147,8 @@ public enum StatusCodeEnum { ...@@ -147,6 +147,8 @@ public enum StatusCodeEnum {
ORDER_FINISHED("030", "订单已结束,请勿操作", false), ORDER_FINISHED("030", "订单已结束,请勿操作", false),
FENDAN_IS_TRANSCEND_AND_SPECIAL("031", "分单超派和特殊时间", false), FENDAN_IS_TRANSCEND_AND_SPECIAL("031", "分单超派和特殊时间", false),
ENGINEER_IS_LEAVE_TIME("032", "工单(%s)指派失败!%s的工作日历在该时间段已有日程安排", false),
; ;
/** /**
......
...@@ -357,7 +357,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -357,7 +357,7 @@ public class DispatchServiceImpl implements DispatchService {
Result<OrderInfoEntity> entityResult = orderInfoService.insterEngineerOrders(engineerOrders, entity, skill, byTeamId, engineer); Result<OrderInfoEntity> entityResult = orderInfoService.insterEngineerOrders(engineerOrders, entity, skill, byTeamId, engineer);
if (!entityResult.getCode().equals(ResultEnum.SUCCESS.getCode())) { if (!entityResult.getCode().equals(ResultEnum.SUCCESS.getCode())) {
// return Result.failed("当前工程师无法预约合适时间"); // return Result.failed("当前工程师无法预约合适时间");
errorList.add(entity.getOrderId()); errorList.add("单号:" + entity.getOrderId());
continue; continue;
} }
entity = entityResult.getResult(); entity = entityResult.getResult();
...@@ -378,11 +378,9 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -378,11 +378,9 @@ public class DispatchServiceImpl implements DispatchService {
successList.add(entity.getOrderId()); successList.add(entity.getOrderId());
} }
List<String> resultList = new ArrayList<>(); List<String> resultList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(successList)) {
resultList.add(String.format("%s订单指派(改派)成功", String.join(",", successList)));
}
if (CollectionUtils.isNotEmpty(errorList)) { if (CollectionUtils.isNotEmpty(errorList)) {
resultList.add(String.format("%s订单指派(改派)失败,当前工程师无法预约合适时间", String.join(",", errorList))); String msg = errorList.size() > 3 ? String.join(",", errorList.subList(0, 3)) + "..." : String.join(",", errorList);
resultList.add(String.format(StatusCodeEnum.ENGINEER_IS_LEAVE_TIME.getDesc(), msg, engineer.getName()));
} }
return Result.success(CollectionUtils.isNotEmpty(resultList) ? String.join(",", resultList) : null); return Result.success(CollectionUtils.isNotEmpty(resultList) ? String.join(",", resultList) : null);
} }
......
...@@ -35,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -35,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -450,7 +451,7 @@ public class OrderInfoServiceImpl implements OrderInfoService { ...@@ -450,7 +451,7 @@ public class OrderInfoServiceImpl implements OrderInfoService {
/** /**
* 根据工程师当日订单插入订单 * 根据工程师当日订单插入订单(根据工单预计开始时间插入,其他顺延)
* *
* @param skillInfo 待指派订单技能 * @param skillInfo 待指派订单技能
* @param engineerOrders 待指派工程师当日工单 * @param engineerOrders 待指派工程师当日工单
...@@ -462,20 +463,16 @@ public class OrderInfoServiceImpl implements OrderInfoService { ...@@ -462,20 +463,16 @@ public class OrderInfoServiceImpl implements OrderInfoService {
@Transactional @Transactional
@Override @Override
public Result<OrderInfoEntity> insterEngineerOrders(List<OrderInfoEntity> engineerOrders, OrderInfoEntity insertOrder, SkillInfoEntity skillInfo, OrgTeamEntity orgTeam, EngineerInfoEntity engineer) { public Result<OrderInfoEntity> insterEngineerOrders(List<OrderInfoEntity> engineerOrders, OrderInfoEntity insertOrder, SkillInfoEntity skillInfo, OrgTeamEntity orgTeam, EngineerInfoEntity engineer) {
// 获取客户期望时间段
LocalDateTime workStartTime = insertOrder.getExpectTimeBegin();
LocalDateTime workEndTime = insertOrder.getExpectTimeEnd();
//查询工程师当天出勤时间
// List<OccupyInfoDetail> engineerWorkTimeSlice = engineerCalendarService.timeWindowsSlice(engineer.getEngineerCode(), orgTeam.getTeamId(), insertOrder.getDt());
//查询工程师当天请假时间 //查询工程师当天请假时间
List<OccupyInfoDetail> engineerLeaveTimeSlice = engineerCalendarService.getEngineerWorkDayCalendar(engineer.getEngineerCode(), insertOrder.getDt()); List<OccupyInfoDetail> engineerLeaveTimeSlice = engineerCalendarService.getEngineerWorkDayCalendar(engineer.getEngineerCode(), insertOrder.getDt());
log.info("【engineerWorkTimeSlice】结果------------->{}", JsonUtil.toJson(engineerLeaveTimeSlice)); log.info("【engineerWorkTimeSlice】结果------------->{}", JsonUtil.toJson(engineerLeaveTimeSlice));
// 没有单直接返回 // 没有单直接返回
if (CollectionUtils.isEmpty(engineerOrders)) { if (CollectionUtils.isEmpty(engineerOrders)) {
LocalDateTime planStartTime = handleLeaveTime(engineerLeaveTimeSlice, insertOrder.getExpectTimeBegin(), insertOrder.getExpectTimeEnd(), skillInfo.getTakeTime()); Result handleLeaveTimeResult = handleLeaveTime(engineerLeaveTimeSlice, insertOrder.getExpectTimeBegin(), insertOrder.getExpectTimeEnd(), skillInfo.getTakeTime(), true, insertOrder);
if (ObjectUtil.isNull(planStartTime)) { if (!handleLeaveTimeResult.getCode().equals(StatusCodeEnum.SUCCESS)) {
return Result.failed(insertOrder); return Result.failed(insertOrder);
} }
LocalDateTime planStartTime = (LocalDateTime) handleLeaveTimeResult.getResult();
insertOrder.setTakeTime(skillInfo.getTakeTime()); insertOrder.setTakeTime(skillInfo.getTakeTime());
insertOrder.setPlanStartTime(planStartTime); insertOrder.setPlanStartTime(planStartTime);
insertOrder.setPlanEndTime(planStartTime.plusMinutes(skillInfo.getTakeTime())); insertOrder.setPlanEndTime(planStartTime.plusMinutes(skillInfo.getTakeTime()));
...@@ -501,96 +498,114 @@ public class OrderInfoServiceImpl implements OrderInfoService { ...@@ -501,96 +498,114 @@ public class OrderInfoServiceImpl implements OrderInfoService {
} }
// 没有单直接返回 // 没有单直接返回
if (CollectionUtils.isEmpty(orderSegments)) { if (CollectionUtils.isEmpty(orderSegments)) {
LocalDateTime planStartTime = handleLeaveTime(engineerLeaveTimeSlice, insertOrder.getExpectTimeBegin(), insertOrder.getExpectTimeEnd(), skillInfo.getTakeTime()); Result handleLeaveTimeResult = handleLeaveTime(engineerLeaveTimeSlice, insertOrder.getExpectTimeBegin(), insertOrder.getExpectTimeEnd(), skillInfo.getTakeTime(), true, insertOrder);
if (ObjectUtil.isNull(planStartTime)) { if (!handleLeaveTimeResult.getCode().equals(StatusCodeEnum.SUCCESS)) {
return Result.failed(insertOrder); return Result.failed(insertOrder);
} }
LocalDateTime planStartTime = (LocalDateTime) handleLeaveTimeResult.getResult();
insertOrder.setTakeTime(skillInfo.getTakeTime()); insertOrder.setTakeTime(skillInfo.getTakeTime());
insertOrder.setPlanStartTime(planStartTime); insertOrder.setPlanStartTime(planStartTime);
insertOrder.setPlanEndTime(planStartTime.plusMinutes(skillInfo.getTakeTime())); insertOrder.setPlanEndTime(planStartTime.plusMinutes(skillInfo.getTakeTime()));
return Result.success(insertOrder); return Result.success(insertOrder);
} }
OrderSegment seg = new OrderSegment();
seg.setX(Double.parseDouble(insertOrder.getX()));
seg.setY(Double.parseDouble(insertOrder.getY()));
seg.setOrderId(insertOrder.getOrderId());
seg.setElapsed(insertOrder.getArriveElapsed());
seg.setDistance(insertOrder.getArriveDistance());
seg.setStart(insertOrder.getExpectTimeBegin());
seg.setEnd(insertOrder.getExpectTimeEnd());
orderSegments.add(seg);
orderSegments = orderSegments.stream().sorted(Comparator.comparing(OrderSegment::getStart)).collect(Collectors.toList()); orderSegments = orderSegments.stream().sorted(Comparator.comparing(OrderSegment::getStart)).collect(Collectors.toList());
// 工单排序
boolean isMove = false;
int moveTime = 0;
for (int i = 0; i < orderSegments.size(); i++) { for (int i = 0; i < orderSegments.size(); i++) {
OrderSegment orderSegment = orderSegments.get(i); OrderSegment orderSegment = orderSegments.get(i);
Result<DistanceDTO> roadResult = pathService.getRoadDistance(insertOrder.getOrderId(), orderSegment.getOrderId(), engineer.getVehicle()); if (isMove && !orderSegment.getOrderId().equals(insertOrder.getOrderId()) && moveTime > 0) {
log.info("【getRoadDistance】参数------------->{},{},{}", insertOrder.getOrderId(), orderSegment.getOrderId(), engineer.getVehicle()); OrderInfoEntity nestOrder = orderInfoDao.getByOrderId(orderSegment.getOrderId());
log.info("【getRoadDistance】结果------------->{}", JsonUtil.toJson(roadResult)); nestOrder.setPlanStartTime(nestOrder.getPlanStartTime().plusMinutes(moveTime));
if (!roadResult.getCode().equals(ResultEnum.SUCCESS.getCode())) { nestOrder.setPlanEndTime(nestOrder.getPlanEndTime().plusMinutes(moveTime));
orderInfoDao.save(nestOrder);
continue; continue;
} }
OrderSegment nestOrderSegment = orderSegments.get(i + 1);
//最近两单都不是需要插入的单直接跳过当前单
if (!orderSegment.getOrderId().equals(insertOrder.getOrderId()) && !nestOrderSegment.getOrderId().equals(insertOrder.getOrderId())) {
continue;
}
Result<DistanceDTO> roadResult = pathService.getRoadDistance(orderSegment.getOrderId(), nestOrderSegment.getOrderId(), engineer.getVehicle());
log.info("【getRoadDistance】参数------------->{},{},{}", orderSegment.getOrderId(), nestOrderSegment.getOrderId(), engineer.getVehicle());
log.info("【getRoadDistance】结果------------->{}", JsonUtil.toJson(roadResult));
DistanceDTO distanceDTO = roadResult.getResult(); DistanceDTO distanceDTO = roadResult.getResult();
// int roadTime = distanceDTO.getTime() / 60;
int roadTime = BigDecimal.valueOf(distanceDTO.getTime()).divide(BigDecimal.valueOf(60), 0, RoundingMode.HALF_UP).intValue(); int roadTime = BigDecimal.valueOf(distanceDTO.getTime()).divide(BigDecimal.valueOf(60), 0, RoundingMode.HALF_UP).intValue();
// 先判断第一单开始时间 if (orderSegment.getOrderId().equals(insertOrder.getOrderId())) {
if (i == 0 && orderSegment.getStart().compareTo(workStartTime.plusMinutes(takeTime + roadTime)) >= 0) { Result handleLeaveTimeResult = handleLeaveTime(engineerLeaveTimeSlice, insertOrder.getExpectTimeBegin(), insertOrder.getExpectTimeEnd(), skillInfo.getTakeTime(), true, insertOrder);
LocalDateTime planStartTime = handleLeaveTime(engineerLeaveTimeSlice, insertOrder.getExpectTimeBegin(), insertOrder.getExpectTimeEnd(), skillInfo.getTakeTime()); if (!handleLeaveTimeResult.getCode().equals(ResultEnum.SUCCESS.getCode())) {
if (ObjectUtil.isNull(planStartTime)) {
return Result.failed(insertOrder); return Result.failed(insertOrder);
} }
LocalDateTime planStartTime = (LocalDateTime) handleLeaveTimeResult.getResult();
insertOrder.setTakeTime(skillInfo.getTakeTime()); insertOrder.setTakeTime(skillInfo.getTakeTime());
insertOrder.setPlanStartTime(planStartTime); insertOrder.setPlanStartTime(planStartTime);
insertOrder.setPlanEndTime(planStartTime.plusMinutes(skillInfo.getTakeTime())); insertOrder.setPlanEndTime(planStartTime.plusMinutes(skillInfo.getTakeTime()));
OrderInfoEntity nestOrder = orderInfoDao.getByOrderId(orderSegment.getOrderId()); OrderInfoEntity nestOrder = orderInfoDao.getByOrderId(nestOrderSegment.getOrderId());
nestOrder.setArriveDistance(roadTime); nestOrder.setArriveElapsed(roadTime);
insertOrder.setArriveDistance(BigDecimal.valueOf(distanceDTO.getDis() * 1000).intValue()); nestOrder.setArriveDistance(BigDecimal.valueOf(distanceDTO.getDis() * 1000).intValue());
if (orderSegment.getStart().plusMinutes(takeTime + roadTime).compareTo(nestOrder.getPlanStartTime()) > 0) {
long minutes = Duration.between(nestOrder.getPlanStartTime(), planStartTime.plusMinutes(skillInfo.getTakeTime() + roadTime)).toMinutes();
nestOrder.setPlanStartTime(nestOrder.getPlanStartTime().plusMinutes(minutes));
nestOrder.setPlanEndTime(nestOrder.getPlanEndTime().plusMinutes(minutes));
orderInfoDao.save(nestOrder);
moveTime = (int) minutes;
isMove = true;
continue;
}
orderInfoDao.save(nestOrder); orderInfoDao.save(nestOrder);
return Result.success(insertOrder); return Result.success(insertOrder);
} }
// 判断当前是不是最后一单 if (nestOrderSegment.getOrderId().equals(insertOrder.getOrderId())) {
if (i == orderSegments.size() - 1) { Result handleLeaveTimeResult = handleLeaveTime(engineerLeaveTimeSlice, insertOrder.getExpectTimeBegin(), insertOrder.getExpectTimeEnd(), skillInfo.getTakeTime(), true, insertOrder);
// 最后一单如果没有符合条件的则代表没有合适时间 if (!handleLeaveTimeResult.getCode().equals(ResultEnum.SUCCESS.getCode())) {
if (workEndTime.compareTo(orderSegment.getEnd().plusMinutes(takeTime + roadTime)) < 0) { return handleLeaveTimeResult;
return Result.failed(insertOrder);
} }
// 判断工单开始时间 LocalDateTime planStartTime = (LocalDateTime) handleLeaveTimeResult.getResult();
LocalDateTime planStartTime = insertOrder.getExpectTimeBegin().compareTo(orderSegment.getEnd().plusMinutes(roadTime)) >= 0 ? if (orderSegment.getEnd().plusMinutes(roadTime).compareTo(planStartTime) <= 0) {
insertOrder.getExpectTimeBegin() : orderSegment.getEnd().plusMinutes(roadTime); OrderInfoEntity nestOrder = orderInfoDao.getByOrderId(nestOrderSegment.getOrderId());
planStartTime = handleLeaveTime(engineerLeaveTimeSlice, planStartTime, insertOrder.getExpectTimeEnd(), skillInfo.getTakeTime()); nestOrder.setArriveElapsed(roadTime);
if (ObjectUtil.isNull(planStartTime)) { nestOrder.setArriveDistance(BigDecimal.valueOf(distanceDTO.getDis() * 1000).intValue());
return Result.failed(insertOrder); orderInfoDao.save(nestOrder);
continue;
} }
insertOrder.setArriveElapsed(roadTime);
insertOrder.setArriveDistance(BigDecimal.valueOf(distanceDTO.getDis() * 1000).intValue());
insertOrder.setTakeTime(skillInfo.getTakeTime()); insertOrder.setTakeTime(skillInfo.getTakeTime());
insertOrder.setPlanStartTime(planStartTime); insertOrder.setPlanStartTime(planStartTime);
insertOrder.setPlanEndTime(planStartTime.plusMinutes(skillInfo.getTakeTime())); insertOrder.setPlanEndTime(planStartTime.plusMinutes(skillInfo.getTakeTime()));
return Result.success(insertOrder); if (i > 0) {
} OrderSegment orderSegmentPrev = orderSegments.get(i - 1);
// 当前单在中间 Result<DistanceDTO> roadResultPrev = pathService.getRoadDistance(orderSegmentPrev.getOrderId(), insertOrder.getOrderId(), engineer.getVehicle());
OrderSegment nestOrderSegment = orderSegments.get(i + 1); log.info("【getRoadDistancePrev】参数------------->{},{},{}", orderSegmentPrev.getOrderId(), insertOrder.getOrderId(), engineer.getVehicle());
Result<DistanceDTO> roadResult2 = pathService.getRoadDistance(nestOrderSegment.getOrderId(), insertOrder.getOrderId(), engineer.getVehicle()); log.info("【getRoadDistancePrev】结果------------->{}", JsonUtil.toJson(roadResultPrev));
log.info("【getRoadDistance2】参数------------->{},{},{}", nestOrderSegment.getOrderId(), insertOrder.getOrderId(), engineer.getVehicle()); int roadTimePrev = BigDecimal.valueOf(roadResultPrev.getResult().getTime()).divide(BigDecimal.valueOf(60), 0, RoundingMode.HALF_UP).intValue();
log.info("【getRoadDistance2】结果------------->{}", JsonUtil.toJson(roadResult2)); insertOrder.setArriveElapsed(roadTimePrev);
if (!roadResult.getCode().equals(ResultEnum.SUCCESS.getCode())) { insertOrder.setArriveDistance(BigDecimal.valueOf(roadResultPrev.getResult().getDis() * 1000).intValue());
continue;
}
int roadTime2 = BigDecimal.valueOf(roadResult2.getResult().getTime()).divide(BigDecimal.valueOf(60), 0, RoundingMode.HALF_UP).intValue();
// 判断工单开始时间 todo 计算不准确 if (nestOrderSegment.getStart().minusMinutes(roadTime2).compareTo(planStartTime.plusMinutes(takeTime + roadTime)) >= 0) {
LocalDateTime planStartTime = insertOrder.getExpectTimeBegin().compareTo(orderSegment.getEnd().plusMinutes(roadTime)) >= 0 ?
insertOrder.getExpectTimeBegin() : orderSegment.getEnd().plusMinutes(roadTime);
if (nestOrderSegment.getStart().minusMinutes(roadTime2).compareTo(planStartTime.plusMinutes(takeTime + roadTime)) >= 0) {
planStartTime = handleLeaveTime(engineerLeaveTimeSlice, planStartTime, insertOrder.getExpectTimeEnd(), skillInfo.getTakeTime());
if (ObjectUtil.isNull(planStartTime)) {
return Result.failed(insertOrder);
} }
insertOrder.setArriveElapsed(roadTime);
insertOrder.setArriveDistance(BigDecimal.valueOf(distanceDTO.getDis() * 1000).intValue());
insertOrder.setTakeTime(skillInfo.getTakeTime());
insertOrder.setPlanStartTime(planStartTime);
insertOrder.setPlanEndTime(planStartTime.plusMinutes(skillInfo.getTakeTime()));
OrderInfoEntity nestOrder = orderInfoDao.getByOrderId(nestOrderSegment.getOrderId()); OrderInfoEntity nestOrder = orderInfoDao.getByOrderId(orderSegment.getOrderId());
nestOrder.setArriveElapsed(roadTime2); nestOrder.setArriveElapsed(roadTime);
nestOrder.setArriveDistance(BigDecimal.valueOf(roadResult2.getResult().getDis() * 1000).intValue()); nestOrder.setArriveDistance(BigDecimal.valueOf(distanceDTO.getDis() * 1000).intValue());
long minutes = Duration.between(nestOrder.getPlanStartTime(), planStartTime.plusMinutes(skillInfo.getTakeTime() + roadTime)).toMinutes();
nestOrder.setPlanStartTime(nestOrder.getPlanStartTime().plusMinutes(minutes));
nestOrder.setPlanEndTime(nestOrder.getPlanEndTime().plusMinutes(minutes));
orderInfoDao.save(nestOrder); orderInfoDao.save(nestOrder);
return Result.success(insertOrder); moveTime = (int) minutes;
isMove = true;
} }
} }
return Result.failed(insertOrder); return Result.success(insertOrder);
} }
/** /**
* 处理工程师请假时间和工单计划开始时间 * 处理工程师请假时间和工单计划开始时间
* *
...@@ -599,22 +614,64 @@ public class OrderInfoServiceImpl implements OrderInfoService { ...@@ -599,22 +614,64 @@ public class OrderInfoServiceImpl implements OrderInfoService {
* @param expectTimeEnd * @param expectTimeEnd
* @return 工单计划开始时间 * @return 工单计划开始时间
*/ */
private LocalDateTime handleLeaveTime(List<OccupyInfoDetail> engineerLeaveTimeSlice, LocalDateTime expectTimeBegin, LocalDateTime expectTimeEnd, Integer takeTime) { private LocalDateTime handleLeaveTime(List<OccupyInfoDetail> engineerLeaveTimeSlice, LocalDateTime expectTimeBegin, LocalDateTime expectTimeEnd, Integer takeTime, Integer rodeTime, boolean isLeave) {
if (CollectionUtils.isEmpty(engineerLeaveTimeSlice)) { if (CollectionUtils.isEmpty(engineerLeaveTimeSlice)) {
return expectTimeBegin; return expectTimeBegin;
} }
for (int i = 0; i < engineerLeaveTimeSlice.size(); i++) { for (int i = 0; i < engineerLeaveTimeSlice.size(); i++) {
OccupyInfoDetail occupyInfoDetail = engineerLeaveTimeSlice.get(i); OccupyInfoDetail occupyInfoDetail = engineerLeaveTimeSlice.get(i);
// 处理请假开始时间 // 请假之中
if (expectTimeBegin.plusMinutes(takeTime).compareTo(occupyInfoDetail.getBeginTime()) <= 0) { if (isLeave && (expectTimeBegin.compareTo(occupyInfoDetail.getBeginTime()) >= 0 || expectTimeBegin.plusMinutes(takeTime + rodeTime).compareTo(occupyInfoDetail.getBeginTime()) >= 0) &&
(expectTimeEnd.compareTo(occupyInfoDetail.getEndTime()) <= 0 || expectTimeEnd.plusMinutes(takeTime + rodeTime).compareTo(occupyInfoDetail.getEndTime()) <= 0)) {
return null;
}
// 请假开始之前能插入
if (expectTimeBegin.plusMinutes(takeTime + rodeTime).compareTo(occupyInfoDetail.getBeginTime()) <= 0) {
return expectTimeBegin; return expectTimeBegin;
} }
if (expectTimeEnd.compareTo(occupyInfoDetail.getEndTime().plusMinutes(takeTime)) >= 0) { // 请假时间内则顺延
if (expectTimeBegin.compareTo(occupyInfoDetail.getBeginTime()) >= 0 || expectTimeBegin.compareTo(occupyInfoDetail.getEndTime()) <= 0) {
return occupyInfoDetail.getEndTime();
}
if (expectTimeEnd.compareTo(occupyInfoDetail.getEndTime().plusMinutes(takeTime + rodeTime)) >= 0) {
return expectTimeBegin.compareTo(occupyInfoDetail.getEndTime()) >= 0 ? expectTimeBegin : occupyInfoDetail.getEndTime(); return expectTimeBegin.compareTo(occupyInfoDetail.getEndTime()) >= 0 ? expectTimeBegin : occupyInfoDetail.getEndTime();
} }
return null;
} }
return null; return expectTimeBegin;
}
/**
* 处理工程师请假时间和工单计划开始时间
*
* @param engineerLeaveTimeSlice
* @param expectTimeBegin
* @param expectTimeEnd
* @return 工单计划开始时间
*/
private Result<?> handleLeaveTime(List<OccupyInfoDetail> engineerLeaveTimeSlice, LocalDateTime expectTimeBegin, LocalDateTime expectTimeEnd, Integer takeTime, boolean isLeave, OrderInfoEntity insertOrder) {
if (CollectionUtils.isEmpty(engineerLeaveTimeSlice)) {
return Result.success(expectTimeBegin);
}
for (int i = 0; i < engineerLeaveTimeSlice.size(); i++) {
OccupyInfoDetail occupyInfoDetail = engineerLeaveTimeSlice.get(i);
// 请假之中
if (isLeave && (expectTimeBegin.compareTo(occupyInfoDetail.getBeginTime()) >= 0 || expectTimeBegin.plusMinutes(takeTime).compareTo(occupyInfoDetail.getBeginTime()) >= 0) &&
(expectTimeEnd.compareTo(occupyInfoDetail.getEndTime()) <= 0 || expectTimeEnd.plusMinutes(takeTime).compareTo(occupyInfoDetail.getEndTime()) <= 0)) {
return Result.failed(StatusCodeEnum.ENGINEER_IS_LEAVE_TIME);
}
// 请假开始之前能插入
if (expectTimeBegin.plusMinutes(takeTime).compareTo(occupyInfoDetail.getBeginTime()) <= 0) {
return Result.success(expectTimeBegin);
}
// 请假时间内则顺延
if (expectTimeBegin.compareTo(occupyInfoDetail.getBeginTime()) >= 0 || expectTimeBegin.compareTo(occupyInfoDetail.getEndTime()) <= 0) {
return Result.success(occupyInfoDetail.getEndTime());
}
if (expectTimeEnd.compareTo(occupyInfoDetail.getEndTime().plusMinutes(takeTime)) >= 0) {
return Result.success(expectTimeBegin.compareTo(occupyInfoDetail.getEndTime()) >= 0 ? expectTimeBegin : occupyInfoDetail.getEndTime());
}
}
return Result.success(expectTimeBegin);
} }
/** /**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!