Commit cb03a9b4 by wangli

修改指派单实现

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