Commit 7f8a7f8f by 丁伟峰

创建订单的时候,尝试虚拟指派

1 parent 720102c6
package com.dituhui.pea.order.common;
import cn.hutool.core.date.DateUtil;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.time.temporal.ChronoUnit;
import java.util.Locale;
import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATE;
......@@ -37,4 +40,8 @@ public class DateUtils {
public static String formatDate(LocalDate d){
return formatDate(d, PATTERN_DATE);
}
public static long getAge(String birth){
return ChronoUnit.YEARS.between(LocalDate.parse(birth), LocalDate.now());
}
}
......@@ -19,16 +19,13 @@ package com.dituhui.pea.order.service.impl;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.CapacityUtils;
import com.dituhui.pea.order.common.SaasUtils;
import com.dituhui.pea.order.dao.OrderRequestDao;
import com.dituhui.pea.order.dao.OrgTeamDao;
import com.dituhui.pea.order.common.*;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.LabelValueDTO;
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.OrderRequestEntity;
import com.dituhui.pea.order.entity.OrgTeamEntity;
import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.service.CommonService;
import com.dituhui.pea.order.service.OrderCreateService;
import io.seata.core.context.RootContext;
......@@ -37,6 +34,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
......@@ -61,6 +59,16 @@ public class OrderCreateServiceImpl implements OrderCreateService {
private CapacityUtils capacityUtils;
@Autowired
private SaasUtils saasUtils;
@Autowired
private EngineerUtils engineerUtils;
@Autowired
private EngineerSkillDao engineerSkillDao;
@Autowired
private OrderAssignCheck orderAssignCheck;
@Autowired
private OrderAppointmentDao orderAppointmentDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
private List<LabelValueDTO> getPriorities() {
String[] priorities = {"紧急", "正常"};
......@@ -145,7 +153,6 @@ public class OrderCreateServiceImpl implements OrderCreateService {
entity.setOrgBranchId(teamEntity.getBranchId());
entity.setOrgGroupId(teamEntity.getGroupId());
entity.setOrgTeamId(teamId);
entity.setX(req.getLocation().getLng().toString());
entity.setY(req.getLocation().getLat().toString());
entity.setOrderTags(String.join(",", req.getOrderTags()));
......@@ -154,10 +161,44 @@ public class OrderCreateServiceImpl implements OrderCreateService {
entity.setStatus("OPEN");
entity.setAppointmentStatus("NOT_ASSIGNED");
entity.setAppointmentMethod("AUTO_NOW");
orderRequestDao.save(entity);
// 登记
commonService.addOrderEvent(orderId, "", req.getSource(), "API", "创建订单", "创建订单", "" );
// 指派检查,简单处理,遇到第一个可以指派的就停止检查
List<String> engineerCodes = engineerUtils.getEngineersByLevel("team", teamId).stream()
.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)){
OrderAppointmentEntity oa = new OrderAppointmentEntity();
oa.setDt(entity.getDt());
oa.setOrderId(entity.getOrderId());
oa.setEngineerCode(assignEngineerCode);
EngineerInfoEntity engineerInfo = engineerInfoDao.getByEngineerCode(assignEngineerCode);
oa.setEngineerName(engineerInfo.getName());
int age = (int)DateUtils.getAge(engineerInfo.getBirth());
oa.setEngineerAge(age);
oa.setEngineerPhone(engineerInfo.getPhone());
oa.setPreStatus("VIRTUAL");
oa.setStatus("ASSIGNED");
oa.setCreateTime(LocalDateTime.now());
oa.setUpdateTime(LocalDateTime.now());
orderAppointmentDao.save(oa);
// 登记
commonService.addOrderEvent(orderId, "", req.getSource(), "API", "虚拟指派", "虚拟指派", "" );
}
return Result.success(null);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!