Commit bf4eddef by wangli

1、接口新增date字段, 2、逻辑迁移到order_info表

1 parent 6b7d811c
......@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
......@@ -27,12 +28,16 @@ import java.util.stream.Collectors;
interface GroupTag {
// 订单分类tag
String getGroupTag(OrderRequest order);
String getGroupTag(OrderInfo order);
}
@Service
public class DispatchServiceImpl implements DispatchService {
@Autowired
private OrderInfoMPDao orderInfoMPDao;
@Autowired
private OrderRequestMPDao orderRequestMPDao;
......@@ -54,18 +59,19 @@ public class DispatchServiceImpl implements DispatchService {
@Transactional
@Override
public Result<?> getDispatchOrderList(DispatchOrderListReq reqDTO) {
// 获取派工台订单列表
// 获取技能信息
HashMap<String, SkillInfo> skillInfo = this.querySkillInfo();
// 获取工单列表
List<OrderRequest> orders = this.queryOrderRequests(reqDTO);
List<OrderInfo> orders = this.queryOrders(reqDTO);
// 获取分组标签
GroupTag gt = new GroupTagFactory().getGroupTag(reqDTO.getGroupTagId());
List<DispatchOrderListResp.Order> items = new ArrayList<>();
for (OrderRequest o : orders) {
for (OrderInfo o : orders) {
DispatchOrderListResp.Order item = new DispatchOrderListResp.Order();
item.setOrderId(o.getOrderId());
......@@ -84,7 +90,6 @@ public class DispatchServiceImpl implements DispatchService {
item.setSkillCategory(skill.getSkillCategory());
item.setTypeCategory(skill.getTypeCategory());
}
item.setName(o.getName());
item.setPhone(o.getPhone());
item.setCity(o.getCity());
......@@ -105,14 +110,6 @@ public class DispatchServiceImpl implements DispatchService {
item.setGroupTag(tags[0]); // 设置tag名称
item.setGroupWeight(Integer.parseInt(tags[1])); // 设置tag权重
// 暂时兼容待删除 TODO
String time = TimeUtils.timestamp2DateTime(o.getExpectTimeBegin(), "HH:mm");
String timeSlot = this.parseTimeSlot(o.getExpectTimeBegin());
item.setIntentionTime(String.format("%s/%s", time, timeSlot));
item.setCustomerName(o.getName());
item.setRemark(o.getApplyNote());
item.setCategory(String.format("%s-%s", o.getType(), o.getBrand()));
items.add(item);
}
......@@ -126,10 +123,12 @@ public class DispatchServiceImpl implements DispatchService {
public Result<?> getDispatchEngineerOrderList(DispatchEngineerOrderListReq reqDTO) throws BusinessException {
// 派工台技术员预约单列表
LocalDate date = TimeUtils.IsoDate2LocalDate(reqDTO.getDate());
// 获取技能信息
HashMap<String, SkillInfo> skillInfo = this.querySkillInfo();
// 获取groupIds
// 获取teamIds
List<String> teamIds = this.queryOrgTeamIds(reqDTO.getLevelType(), reqDTO.getLevelValue(), reqDTO.getBranchIds(),
reqDTO.getGroupIds(), reqDTO.getTeamIds());
if (teamIds.isEmpty()) {
......@@ -150,7 +149,7 @@ public class DispatchServiceImpl implements DispatchService {
List<String> engineerCodes = engineers.stream().map(EngineerInfo::getEngineerCode).collect(Collectors.toList());
// 获取技术员已指派单列表
Map<String, List<OrderAppointment>> engineerOrders = this.queryEngineerOrders(engineerCodes, reqDTO.getDate());
Map<String, List<OrderInfo>> engineerOrders = this.queryEngineerOrders(engineerCodes, date);
// 获取技术员的容量
HashMap<String, CapacityEngineerStat> engineerCap = this.queryCapacityEngineerStat(engineerCodes, reqDTO.getDate());
......@@ -158,7 +157,7 @@ public class DispatchServiceImpl implements DispatchService {
// 获取订单ID
Set<String> orderIds = new HashSet<>();
for (String k : engineerOrders.keySet()) {
for (OrderAppointment o : engineerOrders.get(k)) {
for (OrderInfo o : engineerOrders.get(k)) {
orderIds.add(o.getOrderId());
}
}
......@@ -177,8 +176,8 @@ public class DispatchServiceImpl implements DispatchService {
List<DispatchEngineerOrderListResp.OrderInfo> items = new ArrayList<>();
// 技术员已指派的订单列表
List<OrderAppointment> records = engineerOrders.getOrDefault(e.getEngineerCode(), new ArrayList<>());
for (OrderAppointment r : records) {
List<OrderInfo> records = engineerOrders.getOrDefault(e.getEngineerCode(), new ArrayList<>());
for (OrderInfo r : records) {
// 获取对应的工单信息
if (ListUtils.isEmpty(orders.get(r.getOrderId()))) {
continue;
......@@ -215,23 +214,17 @@ public class DispatchServiceImpl implements DispatchService {
item.setName(o.getName());
item.setPhone(o.getPhone());
String time = TimeUtils.timestamp2DateTime(r.getExpectStartTime(), "HH:mm");
String timeSlot = this.parseTimeSlot(r.getExpectStartTime());
String time = TimeUtils.timestamp2DateTime(r.getPlanStartTime(), "HH:mm");
String timeSlot = this.parseTimeSlot(r.getPlanStartTime());
item.setExpectTimeDesc(String.format("%s/%s", time, timeSlot));
item.setSource(o.getSource());
item.setAppointmentStatus(o.getAppointmentStatus());
item.setAppointmentType(o.getAppointmentMethod());
item.setOrderStatus(r.getStatus()); // 预约单状态
item.setOrderStatusDesc(r.getStatus()); // 预约单状态描述, TODO
item.setOrderStatus(r.getOrderStatus()); // 预约单状态
item.setOrderStatusDesc(r.getOrderStatus()); // 预约单状态描述, TODO
item.setCreateTime(TimeUtils.IsoTimestamp2DateTime(o.getCreateTime()));
// 暂时兼容待删除 TODO
item.setCategory(String.format("%s-%s", o.getType(), o.getBrand()));
item.setRemark(o.getApplyNote());
item.setCustomerName(o.getName());
item.setIntentionTime(String.format("%s/%s", time, timeSlot));
items.add(item);
}
......@@ -264,135 +257,125 @@ public class DispatchServiceImpl implements DispatchService {
}
@Override
public Result<?> dispatchOrderConfirm(String engineerCode, List<String> orderIds) throws BusinessException {
public Result<?> dispatchOrderConfirm(String engineerCode, String date, List<String> orderIds) throws BusinessException {
// 派工台确认派单
LocalDate localDate = TimeUtils.IsoDate2LocalDate(date);
EngineerInfo engineer = engineerInfoMPDao.getByEngineerCode(engineerCode);
if (engineer == null) {
throw new BusinessException("技术员不存在");
}
List<OrderRequest> orders = orderRequestMPDao.selectByOrderIds(orderIds);
if (orders.isEmpty()) {
throw new BusinessException("订单号错误");
LambdaQueryWrapper<OrderInfo> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderInfo::getDt, localDate);
wrapper.in(OrderInfo::getOrderId, orderIds);
List<OrderInfo> orders = orderInfoMPDao.selectList(wrapper);
if (ListUtils.isEmpty(orders)){
throw new BusinessException("订单不存在");
}
// 通过订单获取日期
Timestamp t = orders.get(0).getExpectTimeBegin();
String date = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(t.toLocalDateTime());
// 已经指派的订单
LambdaQueryWrapper<OrderInfo> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderInfo::getEngineerCode, engineerCode);
lqw.eq(OrderInfo::getDt, date);
lqw.orderByAsc(OrderInfo::getPlanStartTime);
List<OrderInfo> orderAppointments = orderInfoMPDao.selectList(lqw);
LambdaQueryWrapper<OrderAppointment> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderAppointment::getEngineerCode, engineerCode);
lqw.ge(OrderAppointment::getExpectStartTime, TimeUtils.IsoDateTime2Timestamp(String.format("%s 00:00:00", date)));
lqw.le(OrderAppointment::getExpectStartTime, TimeUtils.IsoDateTime2Timestamp(String.format("%s 23:59:59", date)));
lqw.orderByAsc(OrderAppointment::getExpectStartTime);
List<OrderAppointment> orderAppointments = orderAppointmentMPDao.selectList(lqw);
// TODO,临时处理方案,后续调用派单引擎处理
OrderRequestScheduler scheduler = new OrderRequestScheduler();
List<LineSegment> results = scheduler.scheduler(orders, orderAppointments);
for (LineSegment r : results) {
String orderId = r.id;
Timestamp expectStartTime = scheduler.linePoint2Timestamp(r.start, date);
Timestamp expectEndTime = scheduler.linePoint2Timestamp(r.end, date);
OrderAppointment op = new OrderAppointment();
op.setOrderId(orderId);
op.setSuborderId(Long.toString(System.currentTimeMillis()));
op.setMainSub(1);
op.setEngineerCode(engineerCode);
op.setEngineerName(engineer.getName());
op.setEngineerAge(0);
op.setEngineerPhone(engineer.getPhone());
op.setIsWorkshop(0);
op.setExpectStartTime(expectStartTime);
op.setExpectEndTime(expectEndTime);
op.setPreStatus("PRE");
op.setStatus("ASSIGNED");
orderAppointmentMPDao.insert(op);
Timestamp planStartTime = scheduler.linePoint2Timestamp(r.start, date);
Timestamp planEndTime = scheduler.linePoint2Timestamp(r.end, date);
// 更新order request表状态
LambdaUpdateWrapper<OrderRequest> wrapper = new LambdaUpdateWrapper<>();
wrapper.set(OrderRequest::getAppointmentStatus, "ASSIGNED");
wrapper.set(OrderRequest::getAppointmentMethod, "MANUAL");
wrapper.eq(OrderRequest::getOrderId, orderId);
orderRequestMPDao.update(null, wrapper);
LambdaUpdateWrapper<OrderInfo> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.set(OrderInfo::getPlanStartTime, planStartTime);
updateWrapper.set(OrderInfo::getPlanEndTime, planEndTime);
updateWrapper.set(OrderInfo::getAppointmentStatus, "CONFIRM");
updateWrapper.set(OrderInfo::getAppointmentMethod, "MANUAL");
updateWrapper.eq(OrderInfo::getOrderId, orderId);
updateWrapper.eq(OrderInfo::getDt, localDate);
orderInfoMPDao.update(null, updateWrapper);
}
return Result.success(null);
}
private List<OrderRequest> queryOrderRequests(DispatchOrderListReq reqDTO) {
private List<OrderInfo> queryOrders(DispatchOrderListReq reqDTO) {
// 获取服务单列表
LambdaQueryWrapper<OrderRequest> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderRequest::getAppointmentStatus, "NOT_ASSIGNED");
lqw.eq(reqDTO.getLevelType().equals("cluster"), OrderRequest::getOrgClusterId, reqDTO.getLevelValue());
lqw.eq(reqDTO.getLevelType().equals("branch"), OrderRequest::getOrgBranchId, reqDTO.getLevelValue());
lqw.eq(reqDTO.getLevelType().equals("group"), OrderRequest::getOrgGroupId, reqDTO.getLevelValue());
lqw.eq(OrderRequest::getDt, TimeUtils.IsoDate2LocalDate(reqDTO.getDate()));
LambdaQueryWrapper<OrderInfo> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderInfo::getAppointmentStatus, "NOT_ASSIGNED"); // 明确未派工订单
lqw.eq(reqDTO.getLevelType().equals("cluster"), OrderInfo::getOrgClusterId, reqDTO.getLevelValue());
lqw.eq(reqDTO.getLevelType().equals("branch"), OrderInfo::getOrgBranchId, reqDTO.getLevelValue());
lqw.eq(reqDTO.getLevelType().equals("group"), OrderInfo::getOrgGroupId, reqDTO.getLevelValue());
lqw.eq(OrderInfo::getDt, TimeUtils.IsoDate2LocalDate(reqDTO.getDate()));
//筛选项
lqw.eq(StringUtils.isNotEmpty(reqDTO.getPhone()), OrderRequest::getPhone, reqDTO.getPhone());
lqw.eq(StringUtils.isNotEmpty(reqDTO.getOrderId()), OrderRequest::getOrderId, reqDTO.getOrderId());
lqw.in(ListUtils.isNotEmpty(reqDTO.getBranchIds()), OrderRequest::getOrgBranchId, reqDTO.getBranchIds());
lqw.in(ListUtils.isNotEmpty(reqDTO.getGroupIds()), OrderRequest::getOrgGroupId, reqDTO.getGroupIds());
lqw.in(ListUtils.isNotEmpty(reqDTO.getTeamIds()), OrderRequest::getOrgTeamId, reqDTO.getTeamIds());
lqw.in(ListUtils.isNotEmpty(reqDTO.getAppointmentType()), OrderRequest::getAppointmentMethod, reqDTO.getAppointmentType());
lqw.eq(StringUtils.isNotEmpty(reqDTO.getPhone()), OrderInfo::getPhone, reqDTO.getPhone());
lqw.eq(StringUtils.isNotEmpty(reqDTO.getOrderId()), OrderInfo::getOrderId, reqDTO.getOrderId());
lqw.in(ListUtils.isNotEmpty(reqDTO.getBranchIds()), OrderInfo::getOrgBranchId, reqDTO.getBranchIds());
lqw.in(ListUtils.isNotEmpty(reqDTO.getGroupIds()), OrderInfo::getOrgGroupId, reqDTO.getGroupIds());
lqw.in(ListUtils.isNotEmpty(reqDTO.getTeamIds()), OrderInfo::getOrgTeamId, reqDTO.getTeamIds());
lqw.in(ListUtils.isNotEmpty(reqDTO.getAppointmentType()), OrderInfo::getAppointmentMethod, reqDTO.getAppointmentType());
if (ListUtils.isNotEmpty(reqDTO.getPriorities())) {
List<Integer> p = reqDTO.getPriorities();
if (p.contains(0) && p.contains(1)) {
lqw.ge(OrderRequest::getPriority, 1);
lqw.ge(OrderInfo::getPriority, 1);
} else if (p.contains(0) && !p.contains(1)) {
lqw.le(OrderRequest::getPriority, 1);
lqw.le(OrderInfo::getPriority, 1);
} else if (p.contains(1) && !p.contains(0)) {
lqw.ge(OrderRequest::getPriority, 5);
lqw.ge(OrderInfo::getPriority, 5);
}
}
if (ListUtils.isNotEmpty(reqDTO.getEngineerCodes())){
lqw.and(w ->
w.in(OrderInfo::getEngineerCode, reqDTO.getEngineerCodes())
.or()
.in(OrderInfo::getEngineerCodeSub, reqDTO.getEngineerCodes())
);
}
if (ListUtils.isNotEmpty(reqDTO.getTypeCategory())) {
String types = "'" + String.join("','", reqDTO.getTypeCategory()) + "'";
String sql = String.format("select 1 from skill_info sk where sk.brand = order_request.brand and sk.type = order_request.type and sk.skill = order_request.skill and type_category in (%s)", types);
String sql = String.format("select 1 from skill_info sk where sk.brand = order_info.brand and sk.type = order_info.type and sk.skill = order_info.skill and type_category in (%s)", types);
lqw.exists(sql);
}
if (ListUtils.isNotEmpty(reqDTO.getSkillCategory())) {
String skills = "'" + String.join("','", reqDTO.getSkillCategory()) + "'";
String sql = String.format("select 1 from skill_info sk where sk.brand = order_request.brand and sk.type = order_request.type and sk.skill = order_request.skill and skill_category in (%s)", skills);
String sql = String.format("select 1 from skill_info sk where sk.brand = order_info.brand and sk.type = order_info.type and sk.skill = order_info.skill and skill_category in (%s)", skills);
lqw.exists(sql);
}
if (ListUtils.isNotEmpty(reqDTO.getEngineerCodes())) {
String engineerCodes = "'" + String.join("','", reqDTO.getEngineerCodes()) + "'";
String sql = String.format("select 1 from order_appointment oa where oa.order_id = order_request.order_id and oa.dt = order_request.dt and oa.engineer_code in (%s)", engineerCodes);
lqw.exists(sql);
}
if (ListUtils.isNotEmpty(reqDTO.getGroupCategory())) {
String groupCategory = reqDTO.getGroupCategory().stream().map(Object::toString).collect(Collectors.joining(","));
String sql = String.format("select 1 from org_group g where g.group_id = order_request.org_group_id and g.category in (%s)", groupCategory);
String sql = String.format("select 1 from org_group g where g.group_id = order_info.org_group_id and g.category in (%s)", groupCategory);
lqw.exists(sql);
}
return orderRequestMPDao.selectList(lqw);
return orderInfoMPDao.selectList(lqw);
}
private Map<String, List<OrderAppointment>> queryEngineerOrders(List<String> engineerCodes, String date) {
private Map<String, List<OrderInfo>> queryEngineerOrders(List<String> engineerCodes, LocalDate date) {
// 获取工程师服务单列表
Map<String, List<OrderAppointment>> map = new HashMap<>();
LambdaQueryWrapper<OrderAppointment> lqw = new LambdaQueryWrapper<>();
lqw.in(OrderAppointment::getEngineerCode, engineerCodes);
Map<String, List<OrderInfo>> map = new HashMap<>();
lqw.ge(OrderAppointment::getExpectStartTime, TimeUtils.IsoDateTime2Timestamp(String.format("%s 00:00:00", date)));
lqw.le(OrderAppointment::getExpectStartTime, TimeUtils.IsoDateTime2Timestamp(String.format("%s 23:59:59", date)));
LambdaQueryWrapper<OrderInfo> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderInfo::getDt, date);
lqw.in(OrderInfo::getEngineerCode, engineerCodes);
lqw.orderByAsc(OrderAppointment::getEngineerCode);
lqw.orderByAsc(OrderAppointment::getExpectStartTime);
lqw.orderByAsc(OrderInfo::getEngineerCode);
lqw.orderByAsc(OrderInfo::getPlanStartTime);
List<OrderAppointment> records = orderAppointmentMPDao.selectList(lqw);
return records.stream().collect(Collectors.groupingBy(OrderAppointment::getEngineerCode));
List<OrderInfo> records = orderInfoMPDao.selectList(lqw);
return records.stream().collect(Collectors.groupingBy(OrderInfo::getEngineerCode));
}
......@@ -492,7 +475,7 @@ class GroupTagFactory {
class GroupTagUrgency implements GroupTag {
// 根据紧急程度来分组
public String getGroupTag(OrderRequest order) {
public String getGroupTag(OrderInfo order) {
String s = order.getTags();
if (s == null) {
return "正常#1";
......@@ -511,7 +494,7 @@ class GroupTagUrgency implements GroupTag {
class GroupTagOmit implements GroupTag {
public String getGroupTag(OrderRequest order) {
public String getGroupTag(OrderInfo order) {
return "默认分类#5";
}
}
......@@ -590,18 +573,18 @@ class LineSegmentScheduler {
class OrderRequestScheduler {
public List<LineSegment> scheduler(List<OrderRequest> orderRequests, List<OrderAppointment> orderAppointments) {
public List<LineSegment> scheduler(List<OrderInfo> orderRequests, List<OrderInfo> orderAppointments) {
List<LineSegment> used = new ArrayList<>();
for (OrderAppointment o : orderAppointments) {
for (OrderInfo o : orderAppointments) {
LineSegment s = new LineSegment(o.getOrderId(),
this.Timestamp2LinePoint(o.getExpectStartTime()),
this.Timestamp2LinePoint(o.getExpectEndTime()));
this.Timestamp2LinePoint(o.getPlanStartTime()),
this.Timestamp2LinePoint(o.getPlanEndTime()));
used.add(s);
}
List<Line> newTasks = new ArrayList<>();
for (OrderRequest o : orderRequests) {
for (OrderInfo o : orderRequests) {
if (!o.getAppointmentStatus().equals("NOT_ASSIGNED")) {
continue;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!