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