Commit e0b70d34 by chamberone

Merge branch 'develop' of https://zhangguoping@gitlab.dituhui.com/bsh/project/pr…

…oject.git into develop
2 parents bd4ca481 8346a224
Showing with 764 additions and 699 deletions
...@@ -2,6 +2,7 @@ package com.dituhui.pea.order.common; ...@@ -2,6 +2,7 @@ package com.dituhui.pea.order.common;
import com.dituhui.pea.order.dao.*; import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.entity.*; import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.enums.OrderFlowEnum;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -27,327 +28,327 @@ import java.util.stream.Collectors; ...@@ -27,327 +28,327 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public class OrderAssignCheck { public class OrderAssignCheck {
@Autowired @Autowired
private SkillInfoDao skillInfoDao; private SkillInfoDao skillInfoDao;
@Autowired @Autowired
private EngineerBusinessDao engineerBusinessDao; private EngineerBusinessDao engineerBusinessDao;
@Autowired @Autowired
private EngineerInfoDao engineerInfoDao; private EngineerInfoDao engineerInfoDao;
@Autowired @Autowired
private OrgGroupDao orgGroupDao; private OrgGroupDao orgGroupDao;
@Autowired @Autowired
private OrderInfoDao orderInfoDao; private OrderInfoDao orderInfoDao;
@Autowired @Autowired
private EntityManager entityManager; private EntityManager entityManager;
public Result orderAssignCheck(String orderId, LocalDate dt, String engineerCode) { public Result orderAssignCheck(String orderId, LocalDate dt, String engineerCode) {
log.info("begin orderAssignCheck:orderId={}, engineerCode={}", orderId, engineerCode); log.info("begin orderAssignCheck:orderId={}, engineerCode={}", orderId, engineerCode);
OrderInfoEntity order = orderInfoDao.getByOrderIdAndDt(orderId, dt); OrderInfoEntity order = orderInfoDao.getByOrderIdAndDt(orderId, dt);
double curX = Double.parseDouble(order.getX()); double curX = Double.parseDouble(order.getX());
double curY = Double.parseDouble(order.getY()); double curY = Double.parseDouble(order.getY());
// 获取技能需要的时长(分钟) // 获取技能需要的时长(分钟)
SkillInfoEntity skillInfo = skillInfoDao.getByBrandAndTypeAndSkill(order.getBrand(), order.getType(), order.getSkill()); SkillInfoEntity skillInfo = skillInfoDao.getByBrandAndTypeAndSkill(order.getBrand(), order.getType(), order.getSkill());
int takeTime = skillInfo.getTakeTime(); int takeTime = skillInfo.getTakeTime();
// 获取客户期望时间段 // 获取客户期望时间段
int start = this.timestamp2Point(Timestamp.valueOf(order.getExpectTimeBegin())); int start = this.timestamp2Point(Timestamp.valueOf(order.getExpectTimeBegin()));
int end = this.timestamp2Point(Timestamp.valueOf(order.getExpectTimeEnd())); int end = this.timestamp2Point(Timestamp.valueOf(order.getExpectTimeEnd()));
log.info("客户期望的时间段:{}-{}, 技能所需时长:{}, 坐标:{},{}", start, end, takeTime, curX, curY); log.info("客户期望的时间段:{}-{}, 技能所需时长:{}, 坐标:{},{}", start, end, takeTime, curX, curY);
// 获取技术员的已分配订单的时间段, 根据时间段排序 // 获取技术员的已分配订单的时间段, 根据时间段排序
List<OrderSegment> orderSegments = getEngineerOrderSegments(engineerCode, order.getDt()); List<OrderSegment> orderSegments = getEngineerOrderSegments(engineerCode, order.getDt());
// 转化为SegmentInsertion需要的时间段 // 转化为SegmentInsertion需要的时间段
List<SegmentInsertion.Segment> segments = this.orderSegment2Segment(orderSegments); List<SegmentInsertion.Segment> segments = this.orderSegment2Segment(orderSegments);
log.info("技术员已分配时间段列表:{}", segments); log.info("技术员已分配时间段列表:{}", segments);
int index = SegmentInsertion.insertSegment(takeTime, start, end, segments); int index = SegmentInsertion.insertSegment(takeTime, start, end, segments);
if (index == -1) { if (index == -1) {
log.info("没有可连续插入的空间"); log.info("没有可连续插入的空间");
return new Result(-1, false, false, orderId, null,0,0, null, null, null); return new Result(-1, false, false, orderId, null, 0, 0, null, null, null);
} }
log.info("插入位置为第{}单, 已分配单数(不包含本单):{}", index, orderSegments.size()); log.info("插入位置为第{}单, 已分配单数(不包含本单):{}", index, orderSegments.size());
// 计算距离 & 时间 // 计算距离 & 时间
if (index == 0 && orderSegments.isEmpty()) { if (index == 0 && orderSegments.isEmpty()) {
// 第一订单为出发地, 没有其他订单 // 第一订单为出发地, 没有其他订单
// 技术员出发地 // 技术员出发地
double[] location = this.getEngineerDepartureLocation(engineerCode); double[] location = this.getEngineerDepartureLocation(engineerCode);
double preX = location[0]; double preX = location[0];
double preY = location[1]; double preY = location[1];
OrderSegment pre = new OrderSegment(480, 480, preX, preY, 0, 0, 0); OrderSegment pre = new OrderSegment(480, 480, preX, preY, 0, 0, 0);
Pair p = this.getDistanceAndDuration(pre.getX(), pre.getY(), curX, curY); Pair p = this.getDistanceAndDuration(pre.getX(), pre.getY(), curX, curY);
// 最早可插入位置为技术员出发时间+行程时间 // 最早可插入位置为技术员出发时间+行程时间
int startPos = pre.getEnd() + p.getDuration(); int startPos = pre.getEnd() + p.getDuration();
int startInsert = (startPos >= start) ? startPos : start; // 客户期望最早时间是start, 可最早插入时间是startPos int startInsert = (startPos >= start) ? startPos : start; // 客户期望最早时间是start, 可最早插入时间是startPos
int endInsert = startInsert + takeTime; int endInsert = startInsert + takeTime;
LocalDateTime startDateTime = this.point2LocalDateTime(startInsert, order.getDt()); LocalDateTime startDateTime = this.point2LocalDateTime(startInsert, order.getDt());
LocalDateTime endDateTime = this.point2LocalDateTime(endInsert, order.getDt()); LocalDateTime endDateTime = this.point2LocalDateTime(endInsert, order.getDt());
// 当前节点信息 // 当前节点信息
OrderNode curOrder = new OrderNode(); OrderNode curOrder = new OrderNode();
curOrder.setOrderId(orderId); curOrder.setOrderId(orderId);
curOrder.setArriveElapsed(p.getDuration()); curOrder.setArriveElapsed(p.getDuration());
curOrder.setArriveDistance(p.getDistance()); curOrder.setArriveDistance(p.getDistance());
curOrder.setTakeTime(takeTime); curOrder.setTakeTime(takeTime);
curOrder.setPlanStartTime(startDateTime); curOrder.setPlanStartTime(startDateTime);
curOrder.setPlanEndTime(endDateTime); curOrder.setPlanEndTime(endDateTime);
return new Result(index, true, true, orderId, "", p.getDistance(), p.getDuration(), curOrder, null, null); return new Result(index, true, true, orderId, "", p.getDistance(), p.getDuration(), curOrder, null, null);
} else if (index == 0 && !orderSegments.isEmpty()) { } else if (index == 0 && !orderSegments.isEmpty()) {
// 第一订单为出发地, 且有其他订单 // 第一订单为出发地, 且有其他订单
double[] location = this.getEngineerDepartureLocation(engineerCode); double[] location = this.getEngineerDepartureLocation(engineerCode);
double preX = location[0]; double preX = location[0];
double preY = location[1]; double preY = location[1];
OrderSegment pre = new OrderSegment(480, 480, preX, preY, 0, 0, 0); OrderSegment pre = new OrderSegment(480, 480, preX, preY, 0, 0, 0);
OrderSegment cur = new OrderSegment(-1, -1, curX, curY, takeTime, -1, -1); OrderSegment cur = new OrderSegment(-1, -1, curX, curY, takeTime, -1, -1);
OrderSegment post = orderSegments.get(0); OrderSegment post = orderSegments.get(0);
return this.getResult(index, cur, pre, post, order.getDt()); return this.getResult(index, cur, pre, post, order.getDt());
} else if (index == orderSegments.size()) { } else if (index == orderSegments.size()) {
// 有其他订单,最后一个订单出发 // 有其他订单,最后一个订单出发
OrderSegment pre = orderSegments.get(index - 1); OrderSegment pre = orderSegments.get(index - 1);
Pair p = this.getDistanceAndDuration(pre.getX(), pre.getY(), curX, curY); Pair p = this.getDistanceAndDuration(pre.getX(), pre.getY(), curX, curY);
// 最早可插入位置为技术员上一单出发时间+行程时间 // 最早可插入位置为技术员上一单出发时间+行程时间
int startPos = pre.getEnd() + p.getDuration(); int startPos = pre.getEnd() + p.getDuration();
int startInsert = (startPos >= start) ? startPos : start; // 客户期望最早时间是start, 可最早插入时间是startPos int startInsert = (startPos >= start) ? startPos : start; // 客户期望最早时间是start, 可最早插入时间是startPos
int endInsert = startInsert + takeTime; int endInsert = startInsert + takeTime;
LocalDateTime startDateTime = this.point2LocalDateTime(startInsert, order.getDt()); LocalDateTime startDateTime = this.point2LocalDateTime(startInsert, order.getDt());
LocalDateTime endDateTime = this.point2LocalDateTime(endInsert, order.getDt()); LocalDateTime endDateTime = this.point2LocalDateTime(endInsert, order.getDt());
// 当前节点信息 // 当前节点信息
OrderNode curOrder = new OrderNode(); OrderNode curOrder = new OrderNode();
curOrder.setOrderId(orderId); curOrder.setOrderId(orderId);
curOrder.setArriveElapsed(p.getDuration()); curOrder.setArriveElapsed(p.getDuration());
curOrder.setArriveDistance(p.getDistance()); curOrder.setArriveDistance(p.getDistance());
curOrder.setTakeTime(takeTime); curOrder.setTakeTime(takeTime);
curOrder.setPlanStartTime(startDateTime); curOrder.setPlanStartTime(startDateTime);
curOrder.setPlanEndTime(endDateTime); curOrder.setPlanEndTime(endDateTime);
return new Result(index, false, true, orderId, "", p.getDistance(), p.getDuration(), curOrder, null, null); return new Result(index, false, true, orderId, "", p.getDistance(), p.getDuration(), curOrder, null, null);
} else { } else {
// 插入中间位置 // 插入中间位置
OrderSegment pre = orderSegments.get(index - 1); OrderSegment pre = orderSegments.get(index - 1);
OrderSegment cur = new OrderSegment(-1, -1, curX, curY, takeTime, -1, -1); OrderSegment cur = new OrderSegment(-1, -1, curX, curY, takeTime, -1, -1);
OrderSegment post = orderSegments.get(index); OrderSegment post = orderSegments.get(index);
return this.getResult(index, cur, pre, post, order.getDt()); return this.getResult(index, cur, pre, post, order.getDt());
} }
} }
private List<OrderSegment> getEngineerOrderSegments(String engineerCode, LocalDate dt) { private List<OrderSegment> getEngineerOrderSegments(String engineerCode, LocalDate dt) {
List<OrderSegment> orderSegments = new ArrayList<>(); List<OrderSegment> orderSegments = new ArrayList<>();
List<String> appointmentStatusList = Arrays.asList("PRE", "CONFIRM"); List<String> appointmentStatusList = Arrays.asList(OrderFlowEnum.PRE.name(), OrderFlowEnum.CONFIRM.name());
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<OrderInfoEntity> criteriaQuery = criteriaBuilder.createQuery(OrderInfoEntity.class); CriteriaQuery<OrderInfoEntity> criteriaQuery = criteriaBuilder.createQuery(OrderInfoEntity.class);
Root<OrderInfoEntity> root = criteriaQuery.from(OrderInfoEntity.class); Root<OrderInfoEntity> root = criteriaQuery.from(OrderInfoEntity.class);
Predicate dtPredicate = criteriaBuilder.equal(root.get("dt"), dt); Predicate dtPredicate = criteriaBuilder.equal(root.get("dt"), dt);
Predicate engineerCodePredicate = criteriaBuilder.equal(root.get("engineerCode"), engineerCode); Predicate engineerCodePredicate = criteriaBuilder.equal(root.get("engineerCode"), engineerCode);
Predicate orderStatusPredicate = criteriaBuilder.equal(root.get("orderStatus"), "NORMAL"); Predicate orderStatusPredicate = criteriaBuilder.equal(root.get("orderStatus"), "NORMAL");
Predicate appointmentStatusPredicate = root.get("appointmentStatus").in(appointmentStatusList); Predicate appointmentStatusPredicate = root.get("appointmentStatus").in(appointmentStatusList);
criteriaQuery.where(dtPredicate, engineerCodePredicate, orderStatusPredicate, appointmentStatusPredicate); criteriaQuery.where(dtPredicate, engineerCodePredicate, orderStatusPredicate, appointmentStatusPredicate);
List<OrderInfoEntity> appointments = entityManager.createQuery(criteriaQuery).getResultList(); List<OrderInfoEntity> appointments = entityManager.createQuery(criteriaQuery).getResultList();
if (appointments.isEmpty()) { if (appointments.isEmpty()) {
return orderSegments; return orderSegments;
} }
for (OrderInfoEntity o : appointments) { for (OrderInfoEntity o : appointments) {
OrderSegment seg = new OrderSegment(); OrderSegment seg = new OrderSegment();
seg.setOrderId(o.getOrderId()); seg.setOrderId(o.getOrderId());
seg.setX(Double.parseDouble(o.getX())); seg.setX(Double.parseDouble(o.getX()));
seg.setY(Double.parseDouble(o.getY())); seg.setY(Double.parseDouble(o.getY()));
seg.setStart(this.timestamp2Point(Timestamp.valueOf(o.getPlanStartTime()))); seg.setStart(this.timestamp2Point(Timestamp.valueOf(o.getPlanStartTime())));
seg.setEnd(this.timestamp2Point(Timestamp.valueOf(o.getPlanEndTime()))); seg.setEnd(this.timestamp2Point(Timestamp.valueOf(o.getPlanEndTime())));
seg.setElapsed(o.getArriveElapsed()); seg.setElapsed(o.getArriveElapsed());
seg.setDistance(o.getArriveDistance()); seg.setDistance(o.getArriveDistance());
orderSegments.add(seg); orderSegments.add(seg);
} }
return orderSegments.stream().sorted(Comparator.comparing(OrderSegment::getStart)).collect(Collectors.toList()); return orderSegments.stream().sorted(Comparator.comparing(OrderSegment::getStart)).collect(Collectors.toList());
} }
private List<SegmentInsertion.Segment> orderSegment2Segment(List<OrderSegment> orderSegments) { private List<SegmentInsertion.Segment> orderSegment2Segment(List<OrderSegment> orderSegments) {
List<SegmentInsertion.Segment> segments = new ArrayList<>(); List<SegmentInsertion.Segment> segments = new ArrayList<>();
for (OrderSegment s : orderSegments) { for (OrderSegment s : orderSegments) {
segments.add(new SegmentInsertion.Segment(s.getOrderId(), s.getStart(), s.getEnd())); segments.add(new SegmentInsertion.Segment(s.getOrderId(), s.getStart(), s.getEnd()));
} }
return segments; return segments;
} }
private Result getResult(int index, OrderSegment cur, OrderSegment pre, OrderSegment post, LocalDate dt) { private Result getResult(int index, OrderSegment cur, OrderSegment pre, OrderSegment post, LocalDate dt) {
Pair preCurPair = this.getDistanceAndDuration(pre.getX(), pre.getY(), cur.getX(), cur.getY()); Pair preCurPair = this.getDistanceAndDuration(pre.getX(), pre.getY(), cur.getX(), cur.getY());
Pair postCurPair = this.getDistanceAndDuration(post.getX(), post.getY(), cur.getX(), cur.getY()); Pair postCurPair = this.getDistanceAndDuration(post.getX(), post.getY(), cur.getX(), cur.getY());
Pair prePostPair = this.getDistanceAndDuration(post.getX(), post.getY(), pre.getX(), pre.getY()); Pair prePostPair = this.getDistanceAndDuration(post.getX(), post.getY(), pre.getX(), pre.getY());
log.info("pre-cur{}, post-cur:{}, pre-post:{}", preCurPair, postCurPair, prePostPair); log.info("pre-cur{}, post-cur:{}, pre-post:{}", preCurPair, postCurPair, prePostPair);
// 判断增加时间+距离后,时间是否重叠了 // 判断增加时间+距离后,时间是否重叠了
int distance = post.getStart() - postCurPair.getDuration() - (pre.getEnd() + preCurPair.getDuration()); int distance = post.getStart() - postCurPair.getDuration() - (pre.getEnd() + preCurPair.getDuration());
if (distance < cur.getTakeTime()) { if (distance < cur.getTakeTime()) {
// 不支持插入 // 不支持插入
return new Result(-1, false, false, "", "", 0, 0, null, null, null); return new Result(-1, false, false, "", "", 0, 0, null, null, null);
} }
// 插入点(时间点) // 插入点(时间点)
int startInsert = pre.getEnd() + preCurPair.getDuration(); int startInsert = pre.getEnd() + preCurPair.getDuration();
int endInsert = startInsert + cur.getTakeTime(); int endInsert = startInsert + cur.getTakeTime();
LocalDateTime startDateTime = this.point2LocalDateTime(startInsert, dt); LocalDateTime startDateTime = this.point2LocalDateTime(startInsert, dt);
LocalDateTime endDateTime = this.point2LocalDateTime(endInsert, dt); LocalDateTime endDateTime = this.point2LocalDateTime(endInsert, dt);
// 当前节点 // 当前节点
OrderNode curOrder = new OrderNode(); OrderNode curOrder = new OrderNode();
curOrder.setOrderId(cur.getOrderId()); curOrder.setOrderId(cur.getOrderId());
curOrder.setArriveElapsed(cur.getElapsed()); curOrder.setArriveElapsed(cur.getElapsed());
curOrder.setArriveDistance(cur.getDistance()); curOrder.setArriveDistance(cur.getDistance());
curOrder.setTakeTime(cur.getTakeTime()); curOrder.setTakeTime(cur.getTakeTime());
curOrder.setPlanStartTime(startDateTime); curOrder.setPlanStartTime(startDateTime);
curOrder.setPlanEndTime(endDateTime); curOrder.setPlanEndTime(endDateTime);
//后一个节点最新变更情况 //后一个节点最新变更情况
OrderNode postOrder = new OrderNode(); OrderNode postOrder = new OrderNode();
postOrder.setOrderId(post.getOrderId()); postOrder.setOrderId(post.getOrderId());
postOrder.setTakeTime(post.getTakeTime()); postOrder.setTakeTime(post.getTakeTime());
postOrder.setPlanStartTime(this.point2LocalDateTime(post.getStart(), dt)); postOrder.setPlanStartTime(this.point2LocalDateTime(post.getStart(), dt));
postOrder.setPlanEndTime(this.point2LocalDateTime(post.getEnd(), dt)); postOrder.setPlanEndTime(this.point2LocalDateTime(post.getEnd(), dt));
postOrder.setArriveDistance(postCurPair.getDistance()); postOrder.setArriveDistance(postCurPair.getDistance());
postOrder.setArriveElapsed(postCurPair.getDuration()); postOrder.setArriveElapsed(postCurPair.getDuration());
// 后一个节点之前的情况 // 后一个节点之前的情况
OrderNode postOrderOrg = new OrderNode(); OrderNode postOrderOrg = new OrderNode();
postOrder.setOrderId(post.getOrderId()); postOrder.setOrderId(post.getOrderId());
postOrder.setTakeTime(post.getTakeTime()); postOrder.setTakeTime(post.getTakeTime());
postOrder.setPlanStartTime(this.point2LocalDateTime(post.getStart(), dt)); postOrder.setPlanStartTime(this.point2LocalDateTime(post.getStart(), dt));
postOrder.setPlanEndTime(this.point2LocalDateTime(post.getEnd(), dt)); postOrder.setPlanEndTime(this.point2LocalDateTime(post.getEnd(), dt));
postOrder.setArriveDistance(post.getDistance()); postOrder.setArriveDistance(post.getDistance());
postOrder.setArriveElapsed(post.getElapsed()); postOrder.setArriveElapsed(post.getElapsed());
int additionDistance = preCurPair.getDistance() + postCurPair.getDistance() - prePostPair.getDistance(); int additionDistance = preCurPair.getDistance() + postCurPair.getDistance() - prePostPair.getDistance();
int additionElapsed = preCurPair.getDuration() + postCurPair.getDuration() - prePostPair.getDuration(); int additionElapsed = preCurPair.getDuration() + postCurPair.getDuration() - prePostPair.getDuration();
return new Result(index, false, false, cur.getOrderId(), post.getOrderId(), additionDistance, additionElapsed, curOrder, postOrder, postOrderOrg); return new Result(index, false, false, cur.getOrderId(), post.getOrderId(), additionDistance, additionElapsed, curOrder, postOrder, postOrderOrg);
} }
private double[] getEngineerDepartureLocation(String engineerCode) { private double[] getEngineerDepartureLocation(String engineerCode) {
// 获取技术员出发坐标 // 获取技术员出发坐标
// 从技术员配置中获取 // 从技术员配置中获取
EngineerBusinessEntity b = engineerBusinessDao.getByEngineerCode(engineerCode); EngineerBusinessEntity b = engineerBusinessDao.getByEngineerCode(engineerCode);
if (b != null && StringUtils.isNotEmpty(b.getX()) && StringUtils.isNotEmpty(b.getY())) { if (b != null && StringUtils.isNotEmpty(b.getX()) && StringUtils.isNotEmpty(b.getY())) {
return new double[]{Double.parseDouble(b.getX()), Double.parseDouble(b.getY())}; return new double[]{Double.parseDouble(b.getX()), Double.parseDouble(b.getY())};
} }
//从org_group中获取 //从org_group中获取
EngineerInfoEntity e = engineerInfoDao.getByEngineerCode(engineerCode); EngineerInfoEntity e = engineerInfoDao.getByEngineerCode(engineerCode);
OrgGroupEntity g = orgGroupDao.getByGroupId(e.getGroupId()); OrgGroupEntity g = orgGroupDao.getByGroupId(e.getGroupId());
return new double[]{Double.parseDouble(g.getX()), Double.parseDouble(g.getY())}; return new double[]{Double.parseDouble(g.getX()), Double.parseDouble(g.getY())};
} }
private int timestamp2Point(Timestamp t) { private int timestamp2Point(Timestamp t) {
LocalDateTime dt = t.toLocalDateTime(); LocalDateTime dt = t.toLocalDateTime();
return dt.getHour() * 60 + dt.getMinute(); return dt.getHour() * 60 + dt.getMinute();
} }
private LocalTime point2LocalTime(int point) { private LocalTime point2LocalTime(int point) {
int hour = point / 60; int hour = point / 60;
int minute = point % 60; int minute = point % 60;
return LocalTime.of(hour, minute, 0); return LocalTime.of(hour, minute, 0);
} }
private LocalDateTime point2LocalDateTime(int point, LocalDate dt) { private LocalDateTime point2LocalDateTime(int point, LocalDate dt) {
return LocalDateTime.of(dt, this.point2LocalTime(point)); return LocalDateTime.of(dt, this.point2LocalTime(point));
} }
private Pair getDistanceAndDuration(double x1, double y1, double x2, double y2) { private Pair getDistanceAndDuration(double x1, double y1, double x2, double y2) {
Distance cal = new Distance(); Distance cal = new Distance();
long distance = Math.round(cal.calculateDistance(x1, y1, x2, y2) * 1.4); // 单位为米 long distance = Math.round(cal.calculateDistance(x1, y1, x2, y2) * 1.4); // 单位为米
long duration = distance / (19 * 1000 / 60); // 时间为分钟,假设电动车速度为19km/h long duration = distance / (19 * 1000 / 60); // 时间为分钟,假设电动车速度为19km/h
return new Pair((int) distance, (int) duration); return new Pair((int) distance, (int) duration);
} }
@Data @Data
public static class OrderNode { public static class OrderNode {
private String orderId; private String orderId;
private LocalDateTime planStartTime; private LocalDateTime planStartTime;
private LocalDateTime planEndTime; private LocalDateTime planEndTime;
private int takeTime; private int takeTime;
private int arriveDistance; private int arriveDistance;
private int arriveElapsed; private int arriveElapsed;
} }
@Data @Data
public class Result { public class Result {
private int index; private int index;
private boolean isHead; private boolean isHead;
private boolean isTail; private boolean isTail;
private String curOrderId; private String curOrderId;
private String postOrderId; private String postOrderId;
private int additionDistance; private int additionDistance;
private int additionElapsed; private int additionElapsed;
private OrderNode curOrderNode; private OrderNode curOrderNode;
private OrderNode postOrderNode; private OrderNode postOrderNode;
private OrderNode postOrderNodeOrg; private OrderNode postOrderNodeOrg;
public Result(int index, boolean isHead, boolean isTail, String curOrderId, String postOrderId, int additionDistance, int additionElapsed, OrderNode curOrderNode, OrderNode postOrderNode, OrderNode postOrderNodeOrg) { public Result(int index, boolean isHead, boolean isTail, String curOrderId, String postOrderId, int additionDistance, int additionElapsed, OrderNode curOrderNode, OrderNode postOrderNode, OrderNode postOrderNodeOrg) {
this.index = index; this.index = index;
this.isHead = isHead; this.isHead = isHead;
this.isTail = isTail; this.isTail = isTail;
this.curOrderId = curOrderId; this.curOrderId = curOrderId;
this.postOrderId = postOrderId; this.postOrderId = postOrderId;
this.additionDistance = additionDistance; this.additionDistance = additionDistance;
this.additionElapsed = additionElapsed; this.additionElapsed = additionElapsed;
this.curOrderNode = curOrderNode; this.curOrderNode = curOrderNode;
this.postOrderNode = postOrderNode; this.postOrderNode = postOrderNode;
this.postOrderNodeOrg = postOrderNodeOrg; this.postOrderNodeOrg = postOrderNodeOrg;
} }
} }
} }
@Data @Data
class OrderSegment { class OrderSegment {
private String orderId; private String orderId;
private int start; private int start;
private int end; private int end;
private double x; private double x;
private double y; private double y;
private int takeTime; private int takeTime;
private int elapsed; private int elapsed;
private int distance; private int distance;
public OrderSegment() { public OrderSegment() {
} }
public OrderSegment(int start, int end, double x, double y, int takeTime, int elapsed, int distance) { public OrderSegment(int start, int end, double x, double y, int takeTime, int elapsed, int distance) {
this.start = start; this.start = start;
this.end = end; this.end = end;
this.x = x; this.x = x;
this.y = y; this.y = y;
this.takeTime = takeTime; this.takeTime = takeTime;
this.elapsed = elapsed; this.elapsed = elapsed;
this.distance = distance; this.distance = distance;
} }
} }
@Data @Data
class Pair { class Pair {
private int distance; private int distance;
private int duration; private int duration;
public Pair(int distance, int duration) { public Pair(int distance, int duration) {
this.distance = distance; this.distance = distance;
this.duration = duration; this.duration = duration;
} }
} }
...@@ -17,59 +17,57 @@ import java.time.LocalDateTime; ...@@ -17,59 +17,57 @@ import java.time.LocalDateTime;
@RequestMapping("/pea-order") @RequestMapping("/pea-order")
public class OrderAssignController { public class OrderAssignController {
@Autowired @Autowired
private OrderAssign orderAssign; private OrderAssign orderAssign;
@GetMapping("/order/assign/recommend/engineers") @GetMapping("/order/assign/recommend/engineers")
public Result<?> getOrderAssignRecommendEngineers( public Result<?> getOrderAssignRecommendEngineers(
@RequestParam String orderId, @RequestParam(required = false) String key, @RequestParam String orderId, @RequestParam(required = false) String key,
@RequestParam(required = false) String distance, @RequestParam(required = false) String recommend) { @RequestParam(required = false) String distance, @RequestParam(required = false) String recommend) {
//服务单指派-推荐技术员列表 //服务单指派-推荐技术员列表
Result<?> res = null; Result<?> res = null;
try { try {
res = orderAssign.getOrderAssignRecommendEngineers(orderId, key, distance, recommend); res = orderAssign.getOrderAssignRecommendEngineers(orderId, key, distance, recommend);
}catch (BusinessException e) { } catch (BusinessException e) {
return Result.failed(e.getMessage()); return Result.failed(e.getMessage());
} }
return res; return res;
} }
@PostMapping("/order/assign") @PostMapping("/order/assign")
public Result<?> orderAssign(@RequestBody OrderAssignReq req) { public Result<?> orderAssign(@RequestBody OrderAssignReq req) {
// 服务单指派-指派提交 // 服务单指派-指派提交
Result<?> res = null; Result<?> res = null;
try { try {
res = orderAssign.orderAssign(req.getOrderId(), req.getEngineerCode()); res = orderAssign.orderAssign(req);
}catch (BusinessException e) { } catch (BusinessException e) {
return Result.failed(e.getMessage()); return Result.failed(e.getMessage());
} }
return res; return res;
} }
@PostMapping("/order/revoke/assign") @PostMapping("/order/revoke/assign")
public Result<?> orderRevokeAssign(@RequestBody OrderRevokeAssign req){ public Result<?> orderRevokeAssign(@RequestBody OrderRevokeAssign req) {
// 放回工单池 // 放回工单池
Result<?> res = null; Result<?> res = null;
try{ try {
res = orderAssign.orderRevokeAssign(req.getOrderId()); res = orderAssign.orderRevokeAssign(req.getOrderId());
} catch (BusinessException e){ } catch (BusinessException e) {
return Result.failed(e.getMessage()); return Result.failed(e.getMessage());
} }
return res; return res;
} }
@PostMapping("/order/rescheduling") @PostMapping("/order/rescheduling")
public Result<?> orderRescheduling(@RequestBody OrderReschedule req){ public Result<?> orderRescheduling(@RequestBody OrderReschedule req) {
// 订单改约 // 订单改约
Result<?> res = null; Result<?> res = null;
LocalDateTime expectBegin = TimeUtils.IsoDateTime2LocalDateTime(req.getExpectBegin()); try {
LocalDateTime expectEnd = TimeUtils.IsoDateTime2LocalDateTime(req.getExpectEnd()); res = orderAssign.orderReschedule(req);
try{ } catch (BusinessException e) {
res = orderAssign.orderReschedule(req.getOrderId(), expectBegin, expectEnd, req.getExpectDesc()); return Result.failed(e.getMessage());
} catch (BusinessException e){ }
return Result.failed(e.getMessage()); return res;
} }
return res;
}
} }
...@@ -34,7 +34,7 @@ public interface OrderInfoDao extends JpaRepository<OrderInfoEntity, Long>, JpaS ...@@ -34,7 +34,7 @@ public interface OrderInfoDao extends JpaRepository<OrderInfoEntity, Long>, JpaS
List<OrderInfoEntity> findByServiceStatusAndEngineerCode(String serviceStatus, String engineerCode); List<OrderInfoEntity> findByServiceStatusAndEngineerCode(String serviceStatus, String engineerCode);
List<OrderInfoEntity> findByDtAndAddressId(String dt, String addressId); List<OrderInfoEntity> findByDtAndAddressId(LocalDate dt, String addressId);
List<OrderInfoEntity> findByMultipleOrders(String multipleOrders); List<OrderInfoEntity> findByMultipleOrders(String multipleOrders);
} }
...@@ -4,6 +4,11 @@ import lombok.Data; ...@@ -4,6 +4,11 @@ import lombok.Data;
@Data @Data
public class OrderAssignReq { public class OrderAssignReq {
private String engineerCode; private String engineerCode;
private String orderId; private String orderId;
/**
* 操作员
*/
private String operator;
} }
...@@ -8,4 +8,9 @@ public class OrderReschedule { ...@@ -8,4 +8,9 @@ public class OrderReschedule {
private String expectBegin; private String expectBegin;
private String expectEnd; private String expectEnd;
private String expectDesc; private String expectDesc;
/**
* 操作员
*/
private String operator;
} }
package com.dituhui.pea.order.entity; package com.dituhui.pea.order.entity;
import com.dituhui.pea.order.enums.OrderFlowEnum;
import lombok.Data; import lombok.Data;
import javax.persistence.*; import javax.persistence.*;
...@@ -131,7 +132,7 @@ public class OrderInfoEntity { ...@@ -131,7 +132,7 @@ public class OrderInfoEntity {
private String orderStatus = "NORMAL"; private String orderStatus = "NORMAL";
@Column(name = "service_status", nullable = true, length = 20, columnDefinition = "varchar(20) default 'INIT'") @Column(name = "service_status", nullable = true, length = 20, columnDefinition = "varchar(20) default 'INIT'")
private String serviceStatus = "INIT"; private String serviceStatus = OrderFlowEnum.INIT.name();
@Column(name = "engineer_code", nullable = true, length = 32, columnDefinition = "varchar(32) default ''") @Column(name = "engineer_code", nullable = true, length = 32, columnDefinition = "varchar(32) default ''")
private String engineerCode = ""; private String engineerCode = "";
......
package com.dituhui.pea.order.enums;
/**
* 订单流程枚举类
*/
public enum OrderFlowEnum {
// 指派状态: INIT-待指派/PRE-预指派/CONFIRM-确认指派(通知BEAN)
INIT, PRE, CONFIRM,
}
...@@ -3,7 +3,8 @@ package com.dituhui.pea.order.enums; ...@@ -3,7 +3,8 @@ package com.dituhui.pea.order.enums;
public enum OrderStatus { public enum OrderStatus {
NORMAL("正常"), NORMAL("正常"),
CANCELED("已取消"), CANCELED("已取消"),
RESCHEDULED("已改约"); RESCHEDULED("已改约"),
ASSIGN("工单指派");
private final String description; private final String description;
OrderStatus(String description){ OrderStatus(String description){
......
package com.dituhui.pea.order.enums; package com.dituhui.pea.order.enums;
public enum ServiceStatus { public enum ServiceStatus {
// 服务状态:INIT-初始化/PENDING待服务/CONTACTED已排期/STARTED-已开始/FINISHED已完成/UNFINISHED-已上门未完成
INIT("待服务"), INIT("待服务"),
PENDING("待服务"), PENDING("待服务"),
CONTACTED("已排期"), CONTACTED("已排期"),
......
package com.dituhui.pea.order.service; package com.dituhui.pea.order.service;
import com.dituhui.pea.common.Result; import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dto.OrderAssignReq;
import com.dituhui.pea.order.dto.OrderReschedule;
import org.bouncycastle.asn1.cms.TimeStampAndCRL; import org.bouncycastle.asn1.cms.TimeStampAndCRL;
import java.sql.Timestamp; import java.sql.Timestamp;
...@@ -13,9 +15,9 @@ public interface OrderAssign { ...@@ -13,9 +15,9 @@ public interface OrderAssign {
Result<?> getOrderAssignRecommendEngineers(String orderId, String key, String distance, String recommend); Result<?> getOrderAssignRecommendEngineers(String orderId, String key, String distance, String recommend);
// 服务单指派-指派提交 // 服务单指派-指派提交
Result<?> orderAssign(String orderId, String engineerCode); Result<?> orderAssign(OrderAssignReq req);
Result<?> orderRevokeAssign(String orderId); Result<?> orderRevokeAssign(String orderId);
Result<?> orderReschedule(String orderId, LocalDateTime expectBegin, LocalDateTime expectEnd, String expectDesc); Result<?> orderReschedule(OrderReschedule req);
} }
...@@ -2,6 +2,8 @@ package com.dituhui.pea.order.service; ...@@ -2,6 +2,8 @@ package com.dituhui.pea.order.service;
import com.dituhui.pea.common.Result; import com.dituhui.pea.common.Result;
import java.time.LocalDate;
/** /**
* 订单相关 * 订单相关
*/ */
...@@ -14,7 +16,7 @@ public interface OrderInfoService { ...@@ -14,7 +16,7 @@ public interface OrderInfoService {
* @param addressId 地址id * @param addressId 地址id
* @return 有则返回多条订单关联id,没有则不是一家多单 * @return 有则返回多条订单关联id,没有则不是一家多单
*/ */
Result<String> addMultipleOrders(String dt, String addressId); Result<String> addMultipleOrders(LocalDate dt, String addressId, String orderId);
/** /**
* 取消指定订单一家多台 * 取消指定订单一家多台
......
...@@ -10,6 +10,7 @@ import com.dituhui.pea.order.dto.DispatchEngineerOrderListResp; ...@@ -10,6 +10,7 @@ import com.dituhui.pea.order.dto.DispatchEngineerOrderListResp;
import com.dituhui.pea.order.dto.DispatchOrderListReq; import com.dituhui.pea.order.dto.DispatchOrderListReq;
import com.dituhui.pea.order.dto.DispatchOrderListResp; import com.dituhui.pea.order.dto.DispatchOrderListResp;
import com.dituhui.pea.order.entity.*; import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.enums.OrderFlowEnum;
import com.dituhui.pea.order.enums.OrderGroupEnum; import com.dituhui.pea.order.enums.OrderGroupEnum;
import com.dituhui.pea.order.enums.OrderStatus; import com.dituhui.pea.order.enums.OrderStatus;
import com.dituhui.pea.order.service.DispatchService; import com.dituhui.pea.order.service.DispatchService;
...@@ -298,7 +299,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -298,7 +299,7 @@ public class DispatchServiceImpl implements DispatchService {
Root<OrderInfoEntity> root = update.from(OrderInfoEntity.class); Root<OrderInfoEntity> root = update.from(OrderInfoEntity.class);
update.set(root.get("planStartTime"), planStartTime); update.set(root.get("planStartTime"), planStartTime);
update.set(root.get("planEndTime"), planEndTime); update.set(root.get("planEndTime"), planEndTime);
update.set(root.get("appointmentStatus"), "CONFIRM"); update.set(root.get("appointmentStatus"), OrderFlowEnum.CONFIRM.name());
update.set(root.get("appointmentMethod"), "MANUAL"); update.set(root.get("appointmentMethod"), "MANUAL");
update.set(root.get("engineerCode"), engineerCode); update.set(root.get("engineerCode"), engineerCode);
update.where( update.where(
...@@ -441,7 +442,7 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -441,7 +442,7 @@ public class DispatchServiceImpl implements DispatchService {
List<Predicate> predicates = new ArrayList<>(); List<Predicate> predicates = new ArrayList<>();
predicates.add(criteriaBuilder.equal(root.get("dt"), TimeUtils.IsoDate2LocalDate(reqDTO.getDate()))); predicates.add(criteriaBuilder.equal(root.get("dt"), TimeUtils.IsoDate2LocalDate(reqDTO.getDate())));
predicates.add(criteriaBuilder.equal(root.get("appointmentStatus"), "INIT")); predicates.add(criteriaBuilder.equal(root.get("appointmentStatus"), OrderFlowEnum.INIT.name()));
String levelType = reqDTO.getLevelType(); String levelType = reqDTO.getLevelType();
String levelValue = reqDTO.getLevelValue(); String levelValue = reqDTO.getLevelValue();
...@@ -775,7 +776,7 @@ class OrderRequestScheduler { ...@@ -775,7 +776,7 @@ class OrderRequestScheduler {
List<Line> newTasks = new ArrayList<>(); List<Line> newTasks = new ArrayList<>();
for (OrderInfoEntity o : orderRequests) { for (OrderInfoEntity o : orderRequests) {
if (!o.getAppointmentStatus().equals("INIT")) { if (!o.getAppointmentStatus().equals(OrderFlowEnum.INIT.name())) {
continue; continue;
} }
Line t = new Line(o.getOrderId(), 30); Line t = new Line(o.getOrderId(), 30);
......
...@@ -7,6 +7,7 @@ import com.dituhui.pea.order.dao.*; ...@@ -7,6 +7,7 @@ import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.EngineersGanttDTO; import com.dituhui.pea.order.dto.EngineersGanttDTO;
import com.dituhui.pea.order.dto.LabelValueDTO; import com.dituhui.pea.order.dto.LabelValueDTO;
import com.dituhui.pea.order.entity.*; import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.enums.OrderFlowEnum;
import com.dituhui.pea.order.service.EngineerGanttService; import com.dituhui.pea.order.service.EngineerGanttService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -84,7 +85,7 @@ public class EngineerGanttServiceImpl implements EngineerGanttService { ...@@ -84,7 +85,7 @@ public class EngineerGanttServiceImpl implements EngineerGanttService {
slots = new ArrayList<>(); slots = new ArrayList<>();
} }
slot.setBgColor(getColor(order.getServiceStatus())); slot.setBgColor(getColor(order.getServiceStatus()));
if (!order.getAppointmentStatus().equals("CONFIRM")) { if (!order.getAppointmentStatus().equals(OrderFlowEnum.CONFIRM.name())) {
slot.setBorderStyle("dashed"); // 未确认的指派,统一加上虚框 slot.setBorderStyle("dashed"); // 未确认的指派,统一加上虚框
} }
slots.add(slot); slots.add(slot);
......
...@@ -12,6 +12,7 @@ import com.dituhui.pea.order.entity.OrderEventEntity; ...@@ -12,6 +12,7 @@ import com.dituhui.pea.order.entity.OrderEventEntity;
import com.dituhui.pea.order.entity.OrderInfoEntity; import com.dituhui.pea.order.entity.OrderInfoEntity;
import com.dituhui.pea.order.entity.OrgGroupEntity; import com.dituhui.pea.order.entity.OrgGroupEntity;
import com.dituhui.pea.order.entity.OrgWarehouseInfoEntity; import com.dituhui.pea.order.entity.OrgWarehouseInfoEntity;
import com.dituhui.pea.order.enums.OrderFlowEnum;
import com.dituhui.pea.order.service.EngineerTimelineService; import com.dituhui.pea.order.service.EngineerTimelineService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -88,7 +89,7 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService { ...@@ -88,7 +89,7 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService {
private List<OrderInfoEntity> selectEngineerOrders(String engineerCode, LocalDate dt){ private List<OrderInfoEntity> selectEngineerOrders(String engineerCode, LocalDate dt){
List<OrderInfoEntity> orders = orderInfoDao.findByEngineerCodeAndDtAndAppointmentStatusIn( List<OrderInfoEntity> orders = orderInfoDao.findByEngineerCodeAndDtAndAppointmentStatusIn(
engineerCode, dt, List.of("PRE", "CONFIRM")); engineerCode, dt, List.of(OrderFlowEnum.PRE.name(), OrderFlowEnum.CONFIRM.name()));
return orders.stream().filter(o -> !o.getOrderStatus().equals("CANCEL")).collect(Collectors.toList()); return orders.stream().filter(o -> !o.getOrderStatus().equals("CANCEL")).collect(Collectors.toList());
} }
......
...@@ -3,15 +3,18 @@ package com.dituhui.pea.order.service.impl; ...@@ -3,15 +3,18 @@ package com.dituhui.pea.order.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dituhui.pea.common.BusinessException; import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result; import com.dituhui.pea.common.Result;
import com.dituhui.pea.common.ResultEnum;
import com.dituhui.pea.enums.StatusCodeEnum;
import com.dituhui.pea.order.common.OrderAssignCheck; import com.dituhui.pea.order.common.OrderAssignCheck;
import com.dituhui.pea.order.common.TimeUtils; import com.dituhui.pea.order.common.TimeUtils;
import com.dituhui.pea.order.dao.*; import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.LabelValueDTO; import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.dto.OrderAssignRecommendResp;
import com.dituhui.pea.order.dto.TimeLineDTO;
import com.dituhui.pea.order.entity.*; import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.enums.OrderFlowEnum;
import com.dituhui.pea.order.enums.OrderStatus;
import com.dituhui.pea.order.service.CommonService; import com.dituhui.pea.order.service.CommonService;
import com.dituhui.pea.order.service.OrderAssign; import com.dituhui.pea.order.service.OrderAssign;
import com.dituhui.pea.order.service.OrderInfoService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -34,231 +37,252 @@ import java.util.stream.Collectors; ...@@ -34,231 +37,252 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public class OrderAssignImpl implements OrderAssign { public class OrderAssignImpl implements OrderAssign {
@Autowired @Autowired
private OrderInfoDao orderInfoDao; private OrderInfoDao orderInfoDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired @Autowired
private EngineerInfoDao engineerInfoDao; private CommonService commonService;
@Autowired @Autowired
private CommonService commonService; private OrderAssignCheck orderAssignCheck;
@Autowired @Autowired
private OrderAssignCheck orderAssignCheck; private OrgTeamDao orgTeamDao;
@Autowired @Autowired
private OrgTeamDao orgTeamDao; private OrgTeamEngineerDao orgTeamEngineerDao;
@Autowired @Autowired
private OrgTeamEngineerDao orgTeamEngineerDao; private SkillInfoDao skillInfoDao;
@Autowired @Autowired
private SkillInfoDao skillInfoDao; private EngineerSkillGroupDao engineerSkillGroupDao;
@Autowired @Autowired
private EngineerSkillGroupDao engineerSkillGroupDao; private EntityManager entityManager;
@Autowired @Autowired
private EntityManager entityManager; private OrderInfoService orderInfoService;
@Transactional @Transactional
@Override @Override
public Result<?> getOrderAssignRecommendEngineers(String orderId, String key, String distance, String recommend) { public Result<?> getOrderAssignRecommendEngineers(String orderId, String key, String distance, String recommend) {
// 服务单指派-推荐技术员列表 // 服务单指派-推荐技术员列表
OrderInfoEntity order = orderInfoDao.getByOrderId(orderId); OrderInfoEntity order = orderInfoDao.getByOrderId(orderId);
if (order == null) { if (order == null) {
throw new BusinessException("订单不存在"); throw new BusinessException("订单不存在");
} }
String date = TimeUtils.IsoLocalDate2String(order.getDt()); String date = TimeUtils.IsoLocalDate2String(order.getDt());
// 获取符合筛选条件的技术员 // 获取符合筛选条件的技术员
List<String> engineerCodes = this.searchEngineerCodes(order, distance, key, recommend); List<String> engineerCodes = this.searchEngineerCodes(order, distance, key, recommend);
List<EngineerInfoEntity> engineers = engineerInfoDao.findByEngineerCodeIn(engineerCodes); List<EngineerInfoEntity> engineers = engineerInfoDao.findByEngineerCodeIn(engineerCodes);
List<OrderAssignRecommendResp.Engineer> items = new ArrayList<>(); List<OrderAssignRecommendResp.Engineer> items = new ArrayList<>();
for (EngineerInfoEntity engineer : engineers) { for (EngineerInfoEntity engineer : engineers) {
OrderAssignCheck.Result result = orderAssignCheck.orderAssignCheck(orderId, order.getDt(), engineer.getEngineerCode()); OrderAssignCheck.Result result = orderAssignCheck.orderAssignCheck(orderId, order.getDt(), engineer.getEngineerCode());
log.info("指派检查结果:{}", result); log.info("指派检查结果:{}", result);
if (result.getIndex() < 0) { if (result.getIndex() < 0) {
continue; continue;
} }
// 获取已技术员已指派订单列表 // 获取已技术员已指派订单列表
List<OrderInfoEntity> orderAppointments = orderInfoDao.findByEngineerCodeAndDtAndAppointmentStatusIn( List<OrderInfoEntity> orderAppointments = orderInfoDao.findByEngineerCodeAndDtAndAppointmentStatusIn(
engineer.getEngineerCode(), order.getDt(), List.of("CONFIRM")); engineer.getEngineerCode(), order.getDt(), List.of(OrderFlowEnum.CONFIRM.name()));
// 获取订单tips // 获取订单tips
HashMap<String, List<LabelValueDTO>> orderTips = new HashMap<>(); HashMap<String, List<LabelValueDTO>> orderTips = new HashMap<>();
List<String> orderIds = orderAppointments.stream().map(OrderInfoEntity::getOrderId).collect(Collectors.toList()); List<String> orderIds = orderAppointments.stream().map(OrderInfoEntity::getOrderId).collect(Collectors.toList());
if (!orderIds.isEmpty()) { if (!orderIds.isEmpty()) {
List<OrderInfoEntity> orders = orderInfoDao.findAllByDtAndOrderIdIn(order.getDt(), orderIds); List<OrderInfoEntity> orders = orderInfoDao.findAllByDtAndOrderIdIn(order.getDt(), orderIds);
orderTips = this.packOrderTips(orders); orderTips = this.packOrderTips(orders);
} }
OrderAssignRecommendResp.Engineer item = new OrderAssignRecommendResp.Engineer(); OrderAssignRecommendResp.Engineer item = new OrderAssignRecommendResp.Engineer();
OrderAssignRecommendResp.InsertInfo insertInfo = new OrderAssignRecommendResp.InsertInfo(); OrderAssignRecommendResp.InsertInfo insertInfo = new OrderAssignRecommendResp.InsertInfo();
insertInfo.setNumber(String.format("%d/%d", result.getIndex(), orderAppointments.size() + 1)); insertInfo.setNumber(String.format("%d/%d", result.getIndex(), orderAppointments.size() + 1));
insertInfo.setTimeDesc(String.format("+%d分钟", result.getAdditionElapsed())); insertInfo.setTimeDesc(String.format("+%d分钟", result.getAdditionElapsed()));
insertInfo.setDistanceDesc(String.format("+%d公里", result.getAdditionDistance() / 1000)); insertInfo.setDistanceDesc(String.format("+%d公里", result.getAdditionDistance() / 1000));
item.setEngineerCode(engineer.getEngineerCode()); item.setEngineerCode(engineer.getEngineerCode());
item.setEngineerName(engineer.getName()); item.setEngineerName(engineer.getName());
item.setLocation(String.format("%s,%s", order.getX(), order.getY())); item.setLocation(String.format("%s,%s", order.getX(), order.getY()));
item.setInsertInfo(insertInfo); item.setInsertInfo(insertInfo);
item.setDistanceDesc(""); item.setDistanceDesc("");
item.setTimeDesc(""); item.setTimeDesc("");
int index = result.getIndex() + 1; int index = result.getIndex() + 1;
item.setDesc(String.format("将被插入在第%d单,受此影响原第%d单变化第%d单,第%d单将增加%d公里路程,比预计晚到%d分钟,建议调整;", index, index, index + 1, index + 1, result.getAdditionDistance() / 1000, result.getAdditionElapsed())); item.setDesc(String.format("将被插入在第%d单,受此影响原第%d单变化第%d单,第%d单将增加%d公里路程,比预计晚到%d分钟,建议调整;", index, index, index + 1, index + 1, result.getAdditionDistance() / 1000, result.getAdditionElapsed()));
item.setStartTime(String.format("%s 08:00:00", date)); item.setStartTime(String.format("%s 08:00:00", date));
item.setEndTime(String.format("%s 18:00:00", date)); item.setEndTime(String.format("%s 18:00:00", date));
item.setOrders(this.packTimelines(orderAppointments, orderTips)); item.setOrders(this.packTimelines(orderAppointments, orderTips));
items.add(item); items.add(item);
} }
OrderAssignRecommendResp res = new OrderAssignRecommendResp(); OrderAssignRecommendResp res = new OrderAssignRecommendResp();
res.setEngineers(items); res.setEngineers(items);
return Result.success(res); return Result.success(res);
} }
@Transactional @Transactional
@Override @Override
public Result<?> orderAssign(String orderId, String engineerCode) throws BusinessException { public Result<?> orderAssign(OrderAssignReq req) throws BusinessException {
// 服务单指派-指派提交 // 服务单指派-指派提交
OrderInfoEntity order = orderInfoDao.getByOrderId(orderId); OrderInfoEntity order = orderInfoDao.getByOrderId(req.getOrderId());
if (order == null) { if (order == null) {
throw new BusinessException("订单不存在"); throw new BusinessException("订单不存在");
} }
EngineerInfoEntity engineer = engineerInfoDao.getByEngineerCode(engineerCode); EngineerInfoEntity engineer = engineerInfoDao.getByEngineerCode(req.getEngineerCode());
boolean record = false; boolean record = false;
OrderInfoEntity op = orderInfoDao.getByOrderIdAndDt(orderId, order.getDt()); OrderInfoEntity op = orderInfoDao.getByOrderIdAndDt(req.getOrderId(), order.getDt());
if (op != null) { if (op != null) {
record = true; record = true;
} }
if (op != null && !order.getAppointmentStatus().equals("NOT_ASSIGNED") && op.getEngineerCode().equals(engineerCode)) { if (op != null && !order.getAppointmentStatus().equals("NOT_ASSIGNED") && op.getEngineerCode().equals(req.getEngineerCode())) {
throw new BusinessException(String.format("订单已指派个技术员[%s], 不必重复指派给同一个技术员", engineer.getName())); throw new BusinessException(String.format("订单已指派个技术员[%s], 不必重复指派给同一个技术员", engineer.getName()));
} }
OrderAssignCheck.Result result = orderAssignCheck.orderAssignCheck(orderId, order.getDt(), engineerCode); // OrderAssignCheck.Result result = orderAssignCheck.orderAssignCheck(orderId, order.getDt(), engineerCode);
log.info("指派检查结果:{}", result); // log.info("指派检查结果:{}", result);
if (result.getIndex() < 0) { // if (result.getIndex() < 0) {
throw new BusinessException("指派失败, 未能找到合适的时间段, 请选择其他技术员"); // throw new BusinessException("指派失败, 未能找到合适的时间段, 请选择其他技术员");
} // }
OrderAssignCheck.OrderNode insertNode = result.getCurOrderNode(); // OrderAssignCheck.OrderNode insertNode = result.getCurOrderNode();
Timestamp planStartTime = Timestamp.valueOf(insertNode.getPlanStartTime()); // Timestamp planStartTime = Timestamp.valueOf(insertNode.getPlanStartTime());
Timestamp planEndTime = Timestamp.valueOf(insertNode.getPlanEndTime()); // Timestamp planEndTime = Timestamp.valueOf(insertNode.getPlanEndTime());
// 更新order_info表状态 // 更新order_info表状态
String sql = "UPDATE OrderInfo e SET e.appointmentStatus = 'CONFIRM', e.appointmentMethod='MANUAL', e.planStartTime = :planStartTime, e.planEndTime = :panEndTime WHERE e.orderId = :orderId"; // String sql = "UPDATE OrderInfo e SET e.appointmentStatus = 'CONFIRM', e.appointmentMethod='MANUAL', e.planStartTime = :planStartTime, e.planEndTime = :panEndTime WHERE e.orderId = :orderId";
Query query = entityManager.createQuery(sql); // Query query = entityManager.createQuery(sql);
query.setParameter("planStartTime", planStartTime); // query.setParameter("planStartTime", planStartTime);
query.setParameter("planEndTime", planEndTime); // query.setParameter("planEndTime", planEndTime);
query.setParameter("orderId", orderId); // query.setParameter("orderId", orderId);
query.executeUpdate(); // query.executeUpdate();
order.setEngineerCode(engineer.getEngineerCode());
// 工单变更登记 orderInfoDao.save(order);
commonService.addOrderEvent(orderId, "", "PEA-WEB", "API", "工单指派", "工单指派", ""); // 工单变更登记
commonService.addOrderEvent(req.getOrderId(), "", "PEA-WEB", req.getOperator(), OrderStatus.ASSIGN.getDescription(), OrderStatus.ASSIGN.getDescription(), "");
return Result.success(null);
} return Result.success(null);
}
@Override
public Result<?> orderRevokeAssign(String orderId) throws BusinessException { @Override
// 放回工单池 public Result<?> orderRevokeAssign(String orderId) throws BusinessException {
// 放回工单池
OrderInfoEntity order = orderInfoDao.getByOrderId(orderId);
if (order == null) { OrderInfoEntity order = orderInfoDao.getByOrderId(orderId);
throw new BusinessException("订单不存在"); if (order == null) {
} throw new BusinessException("订单不存在");
}
// 更新order_request表为未指派
order.setAppointmentStatus("INIT"); // 更新order_request表为未指派
entityManager.merge(order); order.setAppointmentStatus(OrderFlowEnum.INIT.name());
entityManager.merge(order);
// 操作员ID TODO-用户系统
// 登记事件 // 操作员ID TODO-用户系统
commonService.addOrderEvent(orderId, "", "PEA-WEB", "123", "放回工单池", "放回工单池", ""); // 登记事件
commonService.addOrderEvent(orderId, "", "PEA-WEB", "123", "放回工单池", "放回工单池", "");
return Result.success(null);
} return Result.success(null);
}
@Override
public Result<?> orderReschedule(String orderId, LocalDateTime expectBegin, LocalDateTime expectEnd, String expectDesc) throws BusinessException { @Override
// 工单改约接口(当前同放回工单池处理) public Result<?> orderReschedule(OrderReschedule req) throws BusinessException {
// 工单改约接口(当前同放回工单池处理)
OrderInfoEntity order = orderInfoDao.getByOrderId(orderId);
if (order == null) { LocalDateTime expectBegin = TimeUtils.IsoDateTime2LocalDateTime(req.getExpectBegin());
throw new BusinessException("订单不存在"); LocalDateTime expectEnd = TimeUtils.IsoDateTime2LocalDateTime(req.getExpectEnd());
} OrderInfoEntity order = orderInfoDao.getByOrderId(req.getOrderId());
if (order.getDt().isEqual(expectBegin.toLocalDate())) { if (order == null) {
throw new BusinessException("改约日期不应与之前日期相同"); throw new BusinessException("订单不存在");
} }
if (LocalDate.now().isAfter(expectBegin.toLocalDate())) { if (order.getDt().isEqual(expectBegin.toLocalDate())) {
throw new BusinessException("改约日期不能小于今日"); throw new BusinessException("改约日期不应与之前日期相同");
} }
if (LocalDate.now().isAfter(expectBegin.toLocalDate())) {
LocalDate originDate = order.getDt(); // 改约前的日期 throw new BusinessException("改约日期不能小于今日");
}
// 更新order_info表
String sql = "UPDATE OrderInfo e SET e.appointmentStatus = 'INIT', e.dt=:dt, e.expectTimeBegin = :expectTimeBegin, e.expectTimeEnd = :expectTimeEnd, e.expectTimeDesc = :expectTimeDesc WHERE e.orderId = :orderId"; LocalDate originDate = order.getDt(); // 改约前的日期
Query query = entityManager.createQuery(sql);
query.setParameter("dt", expectBegin.toLocalDate()); // 更新order_info表
query.setParameter("expectTimeBegin", expectBegin); // String sql = "UPDATE OrderInfo e SET e.appointmentStatus = 'INIT', e.dt=:dt, e.expectTimeBegin = :expectTimeBegin, e.expectTimeEnd = :expectTimeEnd, e.expectTimeDesc = :expectTimeDesc WHERE e.orderId = :orderId";
query.setParameter("expectTimeEnd", expectEnd); // Query query = entityManager.createQuery(sql);
query.setParameter("expectTimeDesc", expectDesc); // query.setParameter("dt", expectBegin.toLocalDate());
query.setParameter("orderId", orderId); // query.setParameter("expectTimeBegin", expectBegin);
query.executeUpdate(); // query.setParameter("expectTimeEnd", expectEnd);
// query.setParameter("expectTimeDesc", expectDesc);
// 操作员ID TODO-用户系统 // query.setParameter("orderId", orderId);
// 登记事件 // query.executeUpdate();
commonService.addOrderEvent(orderId, "", "PEA-WEB", "123", "已改约", "已改约", ""); order.setAppointmentStatus(OrderFlowEnum.INIT.name());
order.setDt(expectBegin.toLocalDate());
return Result.success(null); order.setExpectTimeBegin(expectBegin);
} order.setExpectTimeEnd(expectEnd);
order.setExpectTimeDesc(req.getExpectDesc());
private List<String> searchEngineerCodes(OrderInfoEntity order, String distance, String key, String recommend) { //处理一家多单逻辑
Set<String> engineerCodes1 = this.searchEngineerByRecommend(order, recommend); Result<String> deleteMultipleOrders = orderInfoService.deleteMultipleOrders(order.getMultipleOrders(), order.getAddressId());
if (engineerCodes1.isEmpty()) { if (!deleteMultipleOrders.getCode().equals(ResultEnum.SUCCESS.getCode())) {
log.info("recommend:{}筛选条件未找到技术员", recommend); throw new BusinessException("改约日期失败");
return new ArrayList<>(); }
} Result<String> multipleOrdersResult = orderInfoService.addMultipleOrders(expectBegin.toLocalDate(), order.getAddressId(), req.getOrderId());
if (!multipleOrdersResult.getCode().equals(ResultEnum.SUCCESS.getCode())) {
if (StringUtils.isNotEmpty(key)) { throw new BusinessException("改约日期失败");
Set<String> engineerCodes2 = this.searchEngineerByKey(key); }
if (engineerCodes2.isEmpty()) { order.setMultipleOrders(multipleOrdersResult.getResult());
log.info("key:{}筛选条件未找到技术员", key); orderInfoDao.save(order);
return new ArrayList<>(); // 操作员ID TODO-用户系统
} // 登记事件
engineerCodes1.retainAll(engineerCodes2); commonService.addOrderEvent(req.getOrderId(), "", "PEA-WEB", req.getOperator(), OrderStatus.RESCHEDULED.getDescription(), OrderStatus.RESCHEDULED.getDescription(), "");
if (engineerCodes1.isEmpty()) {
log.info("recommend:{} 与 key:{}筛选条件交集未找到技术员", recommend, key); return Result.success(null);
return new ArrayList<>(); }
}
} private List<String> searchEngineerCodes(OrderInfoEntity order, String distance, String key, String recommend) {
// 匹配技能 Set<String> engineerCodes1 = this.searchEngineerByRecommend(order, recommend);
SkillInfoEntity skill = skillInfoDao.getByBrandAndTypeAndSkill(order.getBrand(), order.getType(), order.getSkill()); if (engineerCodes1.isEmpty()) {
if (skill == null) { log.info("recommend:{}筛选条件未找到技术员", recommend);
log.info("skill_info表没有匹配到技能配置:{}-{}-{}", order.getBrand(), order.getY(), order.getSkill()); return new ArrayList<>();
return new ArrayList<>(); }
}
Set<String> engineerCodes3 = engineerSkillGroupDao.findBySkillGroupCode(skill.getSkillGroupCode()).stream().map( if (StringUtils.isNotEmpty(key)) {
EngineerSkillGroupEntity::getEngineerCode).collect(Collectors.toSet()); Set<String> engineerCodes2 = this.searchEngineerByKey(key);
if (engineerCodes3.isEmpty()) { if (engineerCodes2.isEmpty()) {
log.info("没有匹配到技能相匹配的技术员:{}-{}-{}", order.getBrand(), order.getType(), order.getSkill()); log.info("key:{}筛选条件未找到技术员", key);
return new ArrayList<>(); return new ArrayList<>();
} }
engineerCodes1.retainAll(engineerCodes3); engineerCodes1.retainAll(engineerCodes2);
if (engineerCodes1.isEmpty()) { if (engineerCodes1.isEmpty()) {
log.info("recommend:{} 与 key:{}筛选条件, 与技术员所需要的技能:{}-{}-{}交集未找到技术员", recommend, key, order.getBrand(), order.getType(), order.getSkill()); log.info("recommend:{} 与 key:{}筛选条件交集未找到技术员", recommend, key);
return new ArrayList<>(); return new ArrayList<>();
} }
}
// 匹配技能
SkillInfoEntity skill = skillInfoDao.getByBrandAndTypeAndSkill(order.getBrand(), order.getType(), order.getSkill());
if (skill == null) {
log.info("skill_info表没有匹配到技能配置:{}-{}-{}", order.getBrand(), order.getY(), order.getSkill());
return new ArrayList<>();
}
Set<String> engineerCodes3 = engineerSkillGroupDao.findBySkillGroupCode(skill.getSkillGroupCode()).stream().map(
EngineerSkillGroupEntity::getEngineerCode).collect(Collectors.toSet());
if (engineerCodes3.isEmpty()) {
log.info("没有匹配到技能相匹配的技术员:{}-{}-{}", order.getBrand(), order.getType(), order.getSkill());
return new ArrayList<>();
}
engineerCodes1.retainAll(engineerCodes3);
if (engineerCodes1.isEmpty()) {
log.info("recommend:{} 与 key:{}筛选条件, 与技术员所需要的技能:{}-{}-{}交集未找到技术员", recommend, key, order.getBrand(), order.getType(), order.getSkill());
return new ArrayList<>();
}
/* /*
if (StringUtils.isEmpty(distance)) { if (StringUtils.isEmpty(distance)) {
...@@ -267,91 +291,91 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -267,91 +291,91 @@ public class OrderAssignImpl implements OrderAssign {
//进行距离匹配TODO //进行距离匹配TODO
*/ */
return new ArrayList<>(engineerCodes1); return new ArrayList<>(engineerCodes1);
} }
private Set<String> searchEngineerByRecommend(OrderInfoEntity order, String recommend) { private Set<String> searchEngineerByRecommend(OrderInfoEntity order, String recommend) {
if (StringUtils.isNotEmpty(recommend) && recommend.equals("team")) { if (StringUtils.isNotEmpty(recommend) && recommend.equals("team")) {
return orgTeamEngineerDao.findAllByTeamId(order.getOrgTeamId()).stream().map( return orgTeamEngineerDao.findAllByTeamId(order.getOrgTeamId()).stream().map(
OrgTeamEngineerEntity::getEngineerCode).collect(Collectors.toSet()); OrgTeamEngineerEntity::getEngineerCode).collect(Collectors.toSet());
} }
String levelType; String levelType;
String levelValue; String levelValue;
if (StringUtils.isEmpty(recommend) || recommend.equals("branch")) { if (StringUtils.isEmpty(recommend) || recommend.equals("branch")) {
levelType = "branch"; levelType = "branch";
levelValue = order.getOrgBranchId(); levelValue = order.getOrgBranchId();
} else if (recommend.equals("group")) { } else if (recommend.equals("group")) {
levelType = "group"; levelType = "group";
levelValue = order.getOrgGroupId(); levelValue = order.getOrgGroupId();
} else { } else {
return new HashSet<>(); return new HashSet<>();
} }
List<OrgTeamEntity> teams = new ArrayList<>(); List<OrgTeamEntity> teams = new ArrayList<>();
if(levelType.equals("cluster")){ if (levelType.equals("cluster")) {
teams = orgTeamDao.findAllByClusterId(levelValue); teams = orgTeamDao.findAllByClusterId(levelValue);
} else if (levelType.equals("branch")){ } else if (levelType.equals("branch")) {
teams = orgTeamDao.findAllByBranchId(levelValue); teams = orgTeamDao.findAllByBranchId(levelValue);
} else if (levelType.equals("group")){ } else if (levelType.equals("group")) {
teams = orgTeamDao.findAllByGroupId(levelValue); teams = orgTeamDao.findAllByGroupId(levelValue);
} else if (levelType.equals("team")){ } else if (levelType.equals("team")) {
teams = orgTeamDao.findAllByTeamId(levelValue); teams = orgTeamDao.findAllByTeamId(levelValue);
} }
List<String> groupIds = teams.stream().map(OrgTeamEntity::getGroupId).collect(Collectors.toList()); List<String> groupIds = teams.stream().map(OrgTeamEntity::getGroupId).collect(Collectors.toList());
return engineerInfoDao.findByGroupIdIn(groupIds).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toSet()); return engineerInfoDao.findByGroupIdIn(groupIds).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toSet());
} }
private Set<String> searchEngineerByKey(String key) { private Set<String> searchEngineerByKey(String key) {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<EngineerInfoEntity> criteriaQuery = criteriaBuilder.createQuery(EngineerInfoEntity.class); CriteriaQuery<EngineerInfoEntity> criteriaQuery = criteriaBuilder.createQuery(EngineerInfoEntity.class);
Root<EngineerInfoEntity> root = criteriaQuery.from(EngineerInfoEntity.class); Root<EngineerInfoEntity> root = criteriaQuery.from(EngineerInfoEntity.class);
Predicate predicate = criteriaBuilder.equal(root.get("beanStatus"), 1); Predicate predicate = criteriaBuilder.equal(root.get("beanStatus"), 1);
if (StringUtils.isNotEmpty(key)) { if (StringUtils.isNotEmpty(key)) {
Predicate keyPredicate = criteriaBuilder.or( Predicate keyPredicate = criteriaBuilder.or(
criteriaBuilder.like(root.get("phone"), "%" + key + "%"), criteriaBuilder.like(root.get("phone"), "%" + key + "%"),
criteriaBuilder.like(root.get("name"), "%" + key + "%"), criteriaBuilder.like(root.get("name"), "%" + key + "%"),
criteriaBuilder.like(root.get("engineerCode"), "%" + key + "%") criteriaBuilder.like(root.get("engineerCode"), "%" + key + "%")
); );
predicate = criteriaBuilder.and(predicate, keyPredicate); predicate = criteriaBuilder.and(predicate, keyPredicate);
} }
criteriaQuery.where(predicate); criteriaQuery.where(predicate);
CriteriaQuery<EngineerInfoEntity> selectQuery = criteriaQuery.select(root); CriteriaQuery<EngineerInfoEntity> selectQuery = criteriaQuery.select(root);
return entityManager.createQuery(selectQuery).getResultList().stream().map( return entityManager.createQuery(selectQuery).getResultList().stream().map(
EngineerInfoEntity::getEngineerCode).collect(Collectors.toSet()); EngineerInfoEntity::getEngineerCode).collect(Collectors.toSet());
} }
private List<TimeLineDTO> packTimelines(List<OrderInfoEntity> orders, HashMap<String, List<LabelValueDTO>> orderTips) { private List<TimeLineDTO> packTimelines(List<OrderInfoEntity> orders, HashMap<String, List<LabelValueDTO>> orderTips) {
List<LabelValueDTO> empty = new ArrayList<>(); List<LabelValueDTO> empty = new ArrayList<>();
List<TimeLineDTO> items = new ArrayList<>(); List<TimeLineDTO> items = new ArrayList<>();
for (OrderInfoEntity order : orders) { for (OrderInfoEntity order : orders) {
TimeLineDTO item = new TimeLineDTO(); TimeLineDTO item = new TimeLineDTO();
item.setOrderId(order.getOrderId()); item.setOrderId(order.getOrderId());
item.setAppointmentStatus(order.getAppointmentStatus()); item.setAppointmentStatus(order.getAppointmentStatus());
item.setStartTime(TimeUtils.IsoLocalDateTime2String(order.getPlanStartTime())); item.setStartTime(TimeUtils.IsoLocalDateTime2String(order.getPlanStartTime()));
item.setEndTime(TimeUtils.IsoLocalDateTime2String(order.getPlanEndTime())); item.setEndTime(TimeUtils.IsoLocalDateTime2String(order.getPlanEndTime()));
item.setTips(orderTips.getOrDefault(order.getOrderId(), empty)); item.setTips(orderTips.getOrDefault(order.getOrderId(), empty));
items.add(item); items.add(item);
} }
return items; return items;
} }
private HashMap<String, List<LabelValueDTO>> packOrderTips(List<OrderInfoEntity> orders) { private HashMap<String, List<LabelValueDTO>> packOrderTips(List<OrderInfoEntity> orders) {
return orders.stream().collect(Collectors.toMap( return orders.stream().collect(Collectors.toMap(
OrderInfoEntity::getOrderId, this::packOrderTip, (l1, l2) -> l1, HashMap::new)); OrderInfoEntity::getOrderId, this::packOrderTip, (l1, l2) -> l1, HashMap::new));
} }
private List<LabelValueDTO> packOrderTip(OrderInfoEntity order) { private List<LabelValueDTO> packOrderTip(OrderInfoEntity order) {
// pack订单tips // pack订单tips
List<LabelValueDTO> items = new ArrayList<>(); List<LabelValueDTO> items = new ArrayList<>();
items.add(new LabelValueDTO("类型/品牌", String.format("%s %s %s", order.getSkill(), order.getType(), order.getBrand()))); items.add(new LabelValueDTO("类型/品牌", String.format("%s %s %s", order.getSkill(), order.getType(), order.getBrand())));
items.add(new LabelValueDTO("电话/地址", String.format("%s %s\n%s", order.getName(), order.getPhone(), order.getAddress()))); items.add(new LabelValueDTO("电话/地址", String.format("%s %s\n%s", order.getName(), order.getPhone(), order.getAddress())));
items.add(new LabelValueDTO("备注", order.getDescription())); items.add(new LabelValueDTO("备注", order.getDescription()));
items.add(new LabelValueDTO("标签", order.getTags())); items.add(new LabelValueDTO("标签", order.getTags()));
return items; return items;
} }
} }
\ No newline at end of file
...@@ -26,6 +26,7 @@ import com.dituhui.pea.order.dto.LocationDTO; ...@@ -26,6 +26,7 @@ import com.dituhui.pea.order.dto.LocationDTO;
import com.dituhui.pea.order.dto.OrderCreateReqDTO; import com.dituhui.pea.order.dto.OrderCreateReqDTO;
import com.dituhui.pea.order.dto.ParameterRespDTO; import com.dituhui.pea.order.dto.ParameterRespDTO;
import com.dituhui.pea.order.entity.*; import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.enums.OrderFlowEnum;
import com.dituhui.pea.order.service.CommonService; import com.dituhui.pea.order.service.CommonService;
import com.dituhui.pea.order.service.OrderCreateService; import com.dituhui.pea.order.service.OrderCreateService;
import io.seata.core.context.RootContext; import io.seata.core.context.RootContext;
...@@ -145,7 +146,7 @@ public class OrderCreateServiceImpl implements OrderCreateService { ...@@ -145,7 +146,7 @@ public class OrderCreateServiceImpl implements OrderCreateService {
entity.setAddress(location.getFormattedAddress()); entity.setAddress(location.getFormattedAddress());
} }
// 默认值 // 默认值
entity.setAppointmentStatus("INIT"); entity.setAppointmentStatus(OrderFlowEnum.INIT.name());
entity.setBeanStatus("OPEN"); entity.setBeanStatus("OPEN");
entity.setBeanSubStatus(""); entity.setBeanSubStatus("");
entity.setAppointmentStatus("NOT_ASSIGNED"); entity.setAppointmentStatus("NOT_ASSIGNED");
...@@ -226,7 +227,7 @@ public class OrderCreateServiceImpl implements OrderCreateService { ...@@ -226,7 +227,7 @@ public class OrderCreateServiceImpl implements OrderCreateService {
EngineerInfoEntity engineerInfo = engineerInfoDao.getByEngineerCode(assignEngineerCode); EngineerInfoEntity engineerInfo = engineerInfoDao.getByEngineerCode(assignEngineerCode);
thisOrderEntity.setEngineerName(engineerInfo.getName()); thisOrderEntity.setEngineerName(engineerInfo.getName());
thisOrderEntity.setEngineerPhone(engineerInfo.getPhone()); thisOrderEntity.setEngineerPhone(engineerInfo.getPhone());
thisOrderEntity.setAppointmentStatus("PRE"); thisOrderEntity.setAppointmentStatus(OrderFlowEnum.PRE.name());
thisOrderEntity.setDispatcher("AUTO_NOW"); thisOrderEntity.setDispatcher("AUTO_NOW");
thisOrderEntity.setPlanStartTime(insertNode.getPlanStartTime()); thisOrderEntity.setPlanStartTime(insertNode.getPlanStartTime());
thisOrderEntity.setPlanEndTime(insertNode.getPlanEndTime()); thisOrderEntity.setPlanEndTime(insertNode.getPlanEndTime());
......
...@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -32,12 +33,16 @@ public class OrderInfoServiceImpl implements OrderInfoService { ...@@ -32,12 +33,16 @@ public class OrderInfoServiceImpl implements OrderInfoService {
*/ */
@Override @Override
@Transactional @Transactional
public Result<String> addMultipleOrders(String dt, String addressId) { public Result<String> addMultipleOrders(LocalDate dt, String addressId, String orderId) {
List<OrderInfoEntity> infoList = orderInfoDao.findByDtAndAddressId(dt, addressId); List<OrderInfoEntity> infoList = orderInfoDao.findByDtAndAddressId(dt, addressId);
if (CollectionUtils.isEmpty(infoList)) { if (CollectionUtils.isEmpty(infoList)) {
return Result.success(null); return Result.success(null);
} }
List<String> multipleOrdersList = infoList.stream().filter(e -> StringUtils.isNotEmpty(e.getMultipleOrders())).map(OrderInfoEntity::getMultipleOrders).distinct().collect(Collectors.toList()); List<String> multipleOrdersList = infoList.stream().filter(e -> StringUtils.isNotEmpty(e.getMultipleOrders()) && !e.getOrderId().equals(orderId))
.map(OrderInfoEntity::getMultipleOrders).distinct().collect(Collectors.toList());
if (CollectionUtils.isEmpty(multipleOrdersList)) {
return Result.success(null);
}
if (CollectionUtils.isNotEmpty(multipleOrdersList)) { if (CollectionUtils.isNotEmpty(multipleOrdersList)) {
return Result.success(multipleOrdersList.get(0)); return Result.success(multipleOrdersList.get(0));
} }
...@@ -59,6 +64,9 @@ public class OrderInfoServiceImpl implements OrderInfoService { ...@@ -59,6 +64,9 @@ public class OrderInfoServiceImpl implements OrderInfoService {
@Override @Override
@Transactional @Transactional
public Result deleteMultipleOrders(String multipleOrders, String orderId) { public Result deleteMultipleOrders(String multipleOrders, String orderId) {
if (StringUtils.isBlank(multipleOrders)) {
return Result.success();
}
List<OrderInfoEntity> infoList = orderInfoDao.findByMultipleOrders(multipleOrders); List<OrderInfoEntity> infoList = orderInfoDao.findByMultipleOrders(multipleOrders);
for (OrderInfoEntity infoEntity : infoList) { for (OrderInfoEntity infoEntity : infoList) {
if (infoEntity.getOrderId().equals(orderId)) { if (infoEntity.getOrderId().equals(orderId)) {
......
...@@ -9,6 +9,7 @@ import com.dituhui.pea.order.dto.param.Order; ...@@ -9,6 +9,7 @@ import com.dituhui.pea.order.dto.param.Order;
import com.dituhui.pea.order.dto.param.OrderDTO; import com.dituhui.pea.order.dto.param.OrderDTO;
import com.dituhui.pea.order.entity.OrderInfoEntity; import com.dituhui.pea.order.entity.OrderInfoEntity;
import com.dituhui.pea.order.entity.OrgGroupEntity; import com.dituhui.pea.order.entity.OrgGroupEntity;
import com.dituhui.pea.order.enums.OrderFlowEnum;
import com.dituhui.pea.order.service.PeaOuterAPIService; import com.dituhui.pea.order.service.PeaOuterAPIService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -61,7 +62,7 @@ public class PeaOuterAPIServiceImpl implements PeaOuterAPIService { ...@@ -61,7 +62,7 @@ public class PeaOuterAPIServiceImpl implements PeaOuterAPIService {
@Override @Override
public Order orderIncreaseQuery(String engineerCode, Location location, Integer idleDuration) { public Order orderIncreaseQuery(String engineerCode, Location location, Integer idleDuration) {
OrderInfoEntity sss = orderInfoDao.findTopBySkillAndAppointmentStatus("标准安装", "INIT"); OrderInfoEntity sss = orderInfoDao.findTopBySkillAndAppointmentStatus("标准安装", OrderFlowEnum.INIT.name());
Order order = new Order(); Order order = new Order();
order.setOrderId(sss.getOrderId()); order.setOrderId(sss.getOrderId());
......
...@@ -8,6 +8,7 @@ import com.dituhui.pea.order.common.TimeUtils; ...@@ -8,6 +8,7 @@ import com.dituhui.pea.order.common.TimeUtils;
import com.dituhui.pea.order.dao.*; import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.*; import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.entity.*; import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.enums.OrderFlowEnum;
import com.dituhui.pea.order.service.ScheduleService; import com.dituhui.pea.order.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
...@@ -94,7 +95,7 @@ public class ScheduleServiceImpl implements ScheduleService { ...@@ -94,7 +95,7 @@ public class ScheduleServiceImpl implements ScheduleService {
team.setLevel("team"); team.setLevel("team");
// 获取改team订单列表 // 获取改team订单列表
List<OrderInfoEntity> orders = orderInfoDao.findByDtAndOrgTeamIdAndAppointmentStatusIn(date, t.getTeamId(), List.of("PRE", "CONFIRM")); List<OrderInfoEntity> orders = orderInfoDao.findByDtAndOrgTeamIdAndAppointmentStatusIn(date, t.getTeamId(), List.of(OrderFlowEnum.PRE.name(), OrderFlowEnum.CONFIRM.name()));
team.setOrder(this.getTeamOrderSum(orders, skillMapping)); team.setOrder(this.getTeamOrderSum(orders, skillMapping));
// 技术员指派单列表 // 技术员指派单列表
...@@ -159,7 +160,7 @@ public class ScheduleServiceImpl implements ScheduleService { ...@@ -159,7 +160,7 @@ public class ScheduleServiceImpl implements ScheduleService {
List<LabelValueDTO> emptyTips = new ArrayList<>(); List<LabelValueDTO> emptyTips = new ArrayList<>();
List<OrderInfoEntity> orderAppointments = orderInfoDao.findByEngineerCodeAndDtAndAppointmentStatusIn( List<OrderInfoEntity> orderAppointments = orderInfoDao.findByEngineerCodeAndDtAndAppointmentStatusIn(
engineerCode, date, List.of("PRE", "CONFIRM")); engineerCode, date, List.of(OrderFlowEnum.PRE.name(), OrderFlowEnum.CONFIRM.name()));
List<TimeLineDTO> timelines = new ArrayList<>(); List<TimeLineDTO> timelines = new ArrayList<>();
for (OrderInfoEntity o : orderAppointments) { for (OrderInfoEntity o : orderAppointments) {
TimeLineDTO item = new TimeLineDTO(); TimeLineDTO item = new TimeLineDTO();
......
...@@ -10,6 +10,7 @@ import com.dituhui.pea.order.dto.OrderChangeListDTO; ...@@ -10,6 +10,7 @@ import com.dituhui.pea.order.dto.OrderChangeListDTO;
import com.dituhui.pea.order.dto.WorkbenchSummaryResp; import com.dituhui.pea.order.dto.WorkbenchSummaryResp;
import com.dituhui.pea.order.entity.OrderEventEntity; import com.dituhui.pea.order.entity.OrderEventEntity;
import com.dituhui.pea.order.entity.OrderInfoEntity; import com.dituhui.pea.order.entity.OrderInfoEntity;
import com.dituhui.pea.order.enums.OrderFlowEnum;
import com.dituhui.pea.order.service.WorkbenchService; import com.dituhui.pea.order.service.WorkbenchService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -240,7 +241,7 @@ public class WorkbenchServiceImpl implements WorkbenchService { ...@@ -240,7 +241,7 @@ public class WorkbenchServiceImpl implements WorkbenchService {
Long autoTotal = summary.getOrDefault("autoTotal", 0L); Long autoTotal = summary.getOrDefault("autoTotal", 0L);
Long total = summary.getOrDefault("total", 0L); Long total = summary.getOrDefault("total", 0L);
HashMap<String, List<String>> p = this.packParams("appointmentStatus", "INIT"); HashMap<String, List<String>> p = this.packParams("appointmentStatus", OrderFlowEnum.INIT.name());
HashMap<String, List<String>> p1 = this.packParams("appointmentType", "MANUAL"); HashMap<String, List<String>> p1 = this.packParams("appointmentType", "MANUAL");
p1.putAll(p); p1.putAll(p);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!