Commit cb03a9b4 by wangli

修改指派单实现

1 parent 62852712
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dituhui.pea.common.BusinessException; import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result; import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.OrderAssignCheck;
import com.dituhui.pea.order.common.TimeUtils; import com.dituhui.pea.order.common.TimeUtils;
import com.dituhui.pea.order.dao.EngineerInfoMPDao; import com.dituhui.pea.order.dao.EngineerInfoMPDao;
import com.dituhui.pea.order.dao.OrderAppointmentMPDao; import com.dituhui.pea.order.dao.OrderAppointmentMPDao;
...@@ -19,6 +20,7 @@ import com.dituhui.pea.order.entity.OrderRequest; ...@@ -19,6 +20,7 @@ import com.dituhui.pea.order.entity.OrderRequest;
import com.dituhui.pea.order.service.CommonService; import com.dituhui.pea.order.service.CommonService;
import com.dituhui.pea.order.service.OrderAssign; import com.dituhui.pea.order.service.OrderAssign;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -32,6 +34,7 @@ import java.util.List; ...@@ -32,6 +34,7 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@Slf4j
public class OrderAssignImpl implements OrderAssign { public class OrderAssignImpl implements OrderAssign {
@Autowired @Autowired
...@@ -116,26 +119,31 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -116,26 +119,31 @@ public class OrderAssignImpl implements OrderAssign {
throw new BusinessException("订单不存在"); throw new BusinessException("订单不存在");
} }
if (!order.getAppointmentStatus().equals("NOT_ASSIGNED")) {
throw new BusinessException("订单已指派成功,不必重新指派");
}
EngineerInfo engineer = engineerInfoMPDao.getByEngineerCode(engineerCode); EngineerInfo engineer = engineerInfoMPDao.getByEngineerCode(engineerCode);
String date = TimeUtils.timestamp2DateTime(order.getExpectTimeBegin(), TimeUtils.DATE_GAP_FORMAT); boolean record = false;
List<OrderAppointment> orderAppointments = this.queryOrderAppointments(engineerCode, date); OrderAppointment op = orderAppointmentMPDao.getByOrderIdAndDt(orderId, order.getDt());
if(op != null) {
record = true;
}
OrderRecommend recommend = new OrderRecommend(); if(op != null && !order.getAppointmentStatus().equals("NOT_ASSIGNED") && op.getEngineerCode().equals(engineerCode)) {
RecommendResult rr = recommend.recommend(order, orderAppointments); throw new BusinessException(String.format("订单已指派个技术员[%s], 不必重复指派给同一个技术员", engineer.getName()));
if (rr.getIndex() == -1) {
throw new BusinessException("指派失败, 未能找到合适的时间段, 请选择其他技术员");
} }
LineSegment seg = rr.getSeg(); OrderAssignCheck ck = new OrderAssignCheck(orderId, engineerCode);
Timestamp expectStartTime = recommend.linePoint2Timestamp(seg.start, date); OrderAssignCheck.Result result = ck.orderAssignCheck();
Timestamp expectEndTime = recommend.linePoint2Timestamp(seg.end, date); log.info("指派检查结果:{}", result);
if(!result.getCanAssign()){
throw new BusinessException("指派失败, 未能找到合适的时间段, 请选择其他技术员");
}
Timestamp expectStartTime = Timestamp.valueOf(result.getStart());;
Timestamp expectEndTime = Timestamp.valueOf(result.getEnd());
OrderAppointment op = new OrderAppointment(); // 更新或插入指派单
if(!record){
op = new OrderAppointment();
}
op.setOrderId(orderId); op.setOrderId(orderId);
op.setSuborderId(Long.toString(System.currentTimeMillis())); op.setSuborderId(Long.toString(System.currentTimeMillis()));
op.setMainSub(1); op.setMainSub(1);
...@@ -144,12 +152,17 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -144,12 +152,17 @@ public class OrderAssignImpl implements OrderAssign {
op.setEngineerAge(0); op.setEngineerAge(0);
op.setEngineerPhone(engineer.getPhone()); op.setEngineerPhone(engineer.getPhone());
op.setIsWorkshop(0); op.setIsWorkshop(0);
op.setDt(order.getDt());
op.setExpectStartTime(expectStartTime); op.setExpectStartTime(expectStartTime);
op.setExpectEndTime(expectEndTime); op.setExpectEndTime(expectEndTime);
op.setPreStatus("PRE"); op.setPreStatus("CONFIRM");
op.setStatus("ASSIGNED"); op.setStatus("ASSIGNED");
orderAppointmentMPDao.insert(op); if(!record) {
orderAppointmentMPDao.insert(op);
} else {
orderAppointmentMPDao.updateById(op);
}
// 更新order_request表状态 // 更新order_request表状态
LambdaUpdateWrapper<OrderRequest> wrapper = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<OrderRequest> wrapper = new LambdaUpdateWrapper<>();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!