Commit df5651fa by 丁伟峰

虚拟指派异常捕获,不影响主流程

1 parent 03360c7c
...@@ -106,7 +106,7 @@ public class OrderCreateServiceImpl implements OrderCreateService { ...@@ -106,7 +106,7 @@ public class OrderCreateServiceImpl implements OrderCreateService {
String orderId = req.getOrderId(); String orderId = req.getOrderId();
if (StringUtils.isEmpty(orderId)) { if (StringUtils.isEmpty(orderId)) {
String s = UUID.randomUUID().toString().replace("-", ""); String s = UUID.randomUUID().toString().replace("-", "");
orderId = s.substring(s.length()-9); orderId = s.substring(s.length() - 9);
} }
entity.setOrderId(orderId); entity.setOrderId(orderId);
entity.setName(req.getName()); entity.setName(req.getName());
...@@ -131,7 +131,7 @@ public class OrderCreateServiceImpl implements OrderCreateService { ...@@ -131,7 +131,7 @@ public class OrderCreateServiceImpl implements OrderCreateService {
List<String> blockIds = null; List<String> blockIds = null;
List<String> layerIds = capacityUtils.getLayers(req.getBrand(), req.getType(), req.getSkill()); List<String> layerIds = capacityUtils.getLayers(req.getBrand(), req.getType(), req.getSkill());
if(req.getLocation() != null){ if (req.getLocation() != null) {
String loc = String.format("%f,%f", req.getLocation().getLng(), req.getLocation().getLat()); String loc = String.format("%f,%f", req.getLocation().getLng(), req.getLocation().getLat());
blockIds = saasUtils.queryBlocksByLocation(loc).stream().map(SaasUtils.BlockInfo::getBlockId).collect(Collectors.toList()); blockIds = saasUtils.queryBlocksByLocation(loc).stream().map(SaasUtils.BlockInfo::getBlockId).collect(Collectors.toList());
} else { } else {
...@@ -165,62 +165,60 @@ public class OrderCreateServiceImpl implements OrderCreateService { ...@@ -165,62 +165,60 @@ public class OrderCreateServiceImpl implements OrderCreateService {
entity.setAppointmentMethod("AUTO_NOW"); entity.setAppointmentMethod("AUTO_NOW");
orderRequestDao.save(entity); orderRequestDao.save(entity);
// 登记 // 登记
commonService.addOrderEvent(orderId, "", req.getSource(), "API", "创建订单", "创建订单", "" ); commonService.addOrderEvent(orderId, "", req.getSource(), "API", "创建订单", "创建订单", "");
// 指派检查,简单处理,遇到第一个可以指派的就停止检查 // 指派检查,简单处理,遇到第一个可以指派的就停止检查
List<String> engineerCodes = engineerUtils.getEngineersByLevel("team", teamId).stream() tryVirtualAppointment(req, entity, orderId, teamId);
.map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList());
List<String> matchEngineerCodes = engineerSkillDao.findAllByBrandAndTypeAndSkillAndEngineerCodeIn(req.getBrand(), req.getType(), req.getSkill(), engineerCodes).stream()
.map(EngineerSkillEntity::getEngineerCode).collect(Collectors.toList());
String assignEngineerCode = null;
for(String engineerCode: matchEngineerCodes){
OrderAssignCheck.Result checkResult = orderAssignCheck.orderAssignCheck(entity.getOrderId(), engineerCode);
if (checkResult.getCanAssign()){
assignEngineerCode = engineerCode;
break;
}
}
// 虚拟指派
if (StringUtils.isNotBlank(assignEngineerCode)){
tryVirtualAppointment(req, entity, orderId, assignEngineerCode);
}
return Result.success(null); return Result.success(null);
} }
private void tryVirtualAppointment(OrderCreateReqDTO req, OrderRequestEntity entity, String orderId, String assignEngineerCode) { private void tryVirtualAppointment(OrderCreateReqDTO req, OrderRequestEntity entity, String orderId, String teamId) {
try { try {
OrderAppointmentEntity oa = new OrderAppointmentEntity(); List<String> engineerCodes = engineerUtils.getEngineersByLevel("team", teamId).stream()
oa.setDt(entity.getDt()); .map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList());
oa.setOrderId(entity.getOrderId()); List<String> matchEngineerCodes = engineerSkillDao.findAllByBrandAndTypeAndSkillAndEngineerCodeIn(req.getBrand(), req.getType(), req.getSkill(), engineerCodes).stream()
oa.setMainSub(true); // 总是主单 .map(EngineerSkillEntity::getEngineerCode).collect(Collectors.toList());
oa.setIsWorkshop(false); String assignEngineerCode = null;
oa.setEngineerCode(assignEngineerCode); for (String engineerCode : matchEngineerCodes) {
EngineerInfoEntity engineerInfo = engineerInfoDao.getByEngineerCode(assignEngineerCode); OrderAssignCheck.Result checkResult = orderAssignCheck.orderAssignCheck(entity.getOrderId(), engineerCode);
oa.setEngineerName(engineerInfo.getName()); if (checkResult.getCanAssign()) {
if (StringUtils.isNotBlank(engineerInfo.getBirth())) { assignEngineerCode = engineerCode;
int age = (int) DateUtils.getAge(engineerInfo.getBirth()); break;
oa.setEngineerAge(age); }
} else { }
oa.setEngineerAge(0); // 虚拟指派登记
if (StringUtils.isNotBlank(assignEngineerCode)) {
OrderAppointmentEntity oa = new OrderAppointmentEntity();
oa.setDt(entity.getDt());
oa.setOrderId(entity.getOrderId());
oa.setMainSub(true); // 总是主单
oa.setIsWorkshop(false);
oa.setEngineerCode(assignEngineerCode);
EngineerInfoEntity engineerInfo = engineerInfoDao.getByEngineerCode(assignEngineerCode);
oa.setEngineerName(engineerInfo.getName());
if (StringUtils.isNotBlank(engineerInfo.getBirth())) {
int age = (int) DateUtils.getAge(engineerInfo.getBirth());
oa.setEngineerAge(age);
} else {
oa.setEngineerAge(0);
}
oa.setEngineerPhone(engineerInfo.getPhone());
oa.setPreStatus("VIRTUAL");
oa.setStatus("ASSIGNED");
oa.setMemo("创建订单,虚拟指派");
oa.setExpectStartTime(entity.getExpectTimeBegin());
oa.setExpectEndTime(entity.getExpectTimeEnd());
oa.setCreateTime(LocalDateTime.now());
oa.setUpdateTime(LocalDateTime.now());
orderAppointmentDao.save(oa);
// 登记
commonService.addOrderEvent(orderId, "", req.getSource(), "API", "虚拟指派", "虚拟指派", "");
} }
oa.setEngineerPhone(engineerInfo.getPhone());
oa.setPreStatus("VIRTUAL");
oa.setStatus("ASSIGNED");
oa.setMemo("创建订单,虚拟指派");
oa.setExpectStartTime(entity.getExpectTimeBegin());
oa.setExpectEndTime(entity.getExpectTimeEnd());
oa.setCreateTime(LocalDateTime.now());
oa.setUpdateTime(LocalDateTime.now());
orderAppointmentDao.save(oa);
// 登记
commonService.addOrderEvent(orderId, "", req.getSource(), "API", "虚拟指派", "虚拟指派", "");
log.info("==== 已经完成虚拟指派 ===="); log.info("==== 已经完成虚拟指派 ====");
} catch (Exception e){ } catch (Exception e) {
log.error("虚拟指派错误: {}", e.getMessage()); log.error("虚拟指派错误: {}", e.getMessage());
} }
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!