Commit 750a4a41 by 张晓

dispatch_order表调整

1 parent 4d9524c5
......@@ -19,5 +19,5 @@ public interface DispatchOrderRepository extends CrudRepository<DispatchOrder, L
@Query("from DispatchOrder where groupId=?1 and batchNo=?2 and status !='CONFIRM' and ( engineerCode is not null and engineerCode!='') ")
List<DispatchOrder> findAssigned(String groupId, String batchNo);
Optional<DispatchOrder> findByGroupIdAndBatchNoAndOrderId(String groupId, String batchNo, String orderId);
Optional<DispatchOrder> findByGroupIdAndBatchNoAndOrderIdAndDt(String groupId, String batchNo, String orderId, String dt);
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import com.dituhui.pea.dispatch.entity.OrderInfo;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import java.time.LocalDate;
import java.util.Optional;
......@@ -11,5 +12,6 @@ public interface OrderInfoRepository extends CrudRepository<OrderInfo, Long> {
// @Query(value = "SELECT * FROM order_info WHERE order_id=:orderId ORDER BY dt DESC LIMIT 1",nativeQuery = true)
Optional<OrderInfo> findOrderInfoByOrderIdOrderByDtDesc(String orderId);
Optional<OrderInfo> findOrderInfoByOrderIdAndDt(String orderId, LocalDate dt);
}
......@@ -36,6 +36,9 @@ public class DispatchOrder implements Serializable {
@Column(name = "order_id")
private String orderId;
@Column(name = "dt")
private String dt;
@Column(name = "x")
private String X;
......@@ -76,6 +79,14 @@ public class DispatchOrder implements Serializable {
@Column(name = "time_end")
private LocalDateTime timeEnd;
//到达耗时(分钟)
@Column(name = "path_time")
private Integer pathTime;
//到达距离(米)
@Column(name = "path_distance")
private Integer pathDistance;
private String status;
private String ext;
......
......@@ -28,7 +28,10 @@ public class OrderInfo implements Serializable {
@Column(name = "order_id")
private String orderId;
private java.sql.Date dt;
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate dt;
@Column(name = "sub_id")
private String subId;
......
......@@ -21,6 +21,8 @@ public class Customer {
private long id;
private String code;
// orderid(code)+dt 确定唯一一条工单
private String dt;
@JsonIgnore
private Location location;
// 时间窗 分钟
......@@ -45,10 +47,11 @@ public class Customer {
public Customer() {
}
public Customer(long id, String code, Location location, int startTime, int endTime, String requiredSkill,
public Customer(long id, String code, String dt, Location location, int startTime, int endTime, String requiredSkill,
int serviceDuration) {
this.id = id;
this.code = code;
this.dt = dt;
this.location = location;
this.startTime = startTime;
this.endTime = endTime;
......@@ -116,7 +119,7 @@ public class Customer {
}
/**
* 与前一个订单或者出发地depot的距离
* 与前一个订单或者出发地depot的距离(米)
*
* @return
*/
......@@ -132,7 +135,7 @@ public class Customer {
}
/**
* 与前一个订单或者出发地depot的路程时间
* 与前一个订单或者出发地depot的路程时间(分钟)
*
* @return
*/
......@@ -168,16 +171,17 @@ public class Customer {
return "Customer{" +
"id=" + id +
", code='" + code + '\'' +
", dt='" + dt + '\'' +
", location=" + location +
", startTime=" + startTime +
", endTime=" + endTime +
", serviceDuration=" + serviceDuration +
", requiredSkill='" + requiredSkill + '\'' +
", technician=" + ((technician!=null) ? technician.getCode() : "null") +
", technician=" + ((technician != null) ? technician.getCode() : "null") +
", previousCustomer=" + ((previousCustomer != null) ? previousCustomer.getCode() : "null") +
", nextCustomer=" + ((nextCustomer != null) ? nextCustomer.getCode() : "null") +
", arrivalTime=" + arrivalTime +
", departureTime=" + ((getDepartureTime() != null )? getDepartureTime() : 0) +
", departureTime=" + ((getDepartureTime() != null) ? getDepartureTime() : 0) +
'}';
}
}
......@@ -19,9 +19,7 @@ public interface ExtractService {
/*
* 将dispath_order 中的计算结果,回写到 order_request, order_appointment
* order_appointment(新增、更新)
* order_request(主要更新状态)
* 将dispath_order 中的计算结果,回写到 order_info
* */
void extractDispatchToOrder(String groupId, String batchNo, boolean isConfirm) ;
......
......@@ -16,7 +16,9 @@ import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.Optional;
......@@ -34,7 +36,6 @@ import static org.springframework.transaction.annotation.Isolation.READ_COMMITTE
@Service
public class ExtractServiceImpl implements ExtractService {
@Autowired
EngineerInfoRepository engineerInfoRepo;
......@@ -60,9 +61,8 @@ public class ExtractServiceImpl implements ExtractService {
/**
* 将dispath_order 中的计算结果,回写到 order_request, order_appointment
* order_appointment(新增、更新)
* order_request(主要更新状态)
* 将dispath_order 中的计算结果,回写到 order_info
* order_info(主要更新状态)
*/
@Transactional(isolation = READ_COMMITTED, propagation = Propagation.REQUIRED)
@Override
......@@ -82,11 +82,13 @@ public class ExtractServiceImpl implements ExtractService {
int idx = atomicInteger.getAndIncrement();
String orderId = dispatchOrder.getOrderId();
String engCode = dispatchOrder.getEngineerCode();
log.info("算法结果更新到工单, step1.1-loop, {}/{}, groupId:{}, batchNo:{}, orderId:{}, engCode:{}",
idx, dispatchOrderList.size(), groupId, batchNo, orderId, engCode);
String dt = dispatchOrder.getDt();
log.info("算法结果更新到工单, step1.1-loop, {}/{}, groupId:{}, batchNo:{}, orderId:{}, dt:{}, engCode:{}",
idx, dispatchOrderList.size(), groupId, batchNo, orderId, dt, engCode);
Optional<OrderInfo> orderOpt = orderInfoRepo.findOrderInfoByOrderIdOrderByDtDesc(orderId);
if (!orderOpt.isPresent()) {
LocalDate localDt = LocalDate.parse(dt, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
Optional<OrderInfo> orderOpt = orderInfoRepo.findOrderInfoByOrderIdAndDt(orderId, localDt);
if (orderOpt.isEmpty()) {
log.warn("算法结果更新到工单, step1.1-loop, 工单不存在, groupId:{}, batchNo:{}, orderId:{}",
groupId, batchNo, orderId);
return;
......@@ -121,15 +123,13 @@ public class ExtractServiceImpl implements ExtractService {
age = DateUtil.age(birthDate.toJdkDate(), DateUtil.date());
}*/
if ("NOT_ASSIGNED".equals(orderInfo.getAppointmentStatus())) {
jdbcTemplate.update("update order_request set appointment_status ='ASSIGNED' where order_id =? and appointment_status='NOT_ASSIGNED'", orderId);
}
orderInfo.setEngineerCode(engCode);
orderInfo.setEngineerName(engName);
orderInfo.setEngineerPhone(phone);
orderInfo.setPlanStartTime(dispatchOrder.getTimeBegin());
orderInfo.setPlanEndTime(dispatchOrder.getTimeEnd());
orderInfo.setArriveElapsed(dispatchOrder.getPathTime());
orderInfo.setArriveDistance(dispatchOrder.getPathDistance());
orderInfo.setAppointmentStatus(isConfirm ? "CONFIRM" : "PRE");
orderInfo.setUpdateTime(LocalDateTime.now());
orderInfoRepo.save(orderInfo);
......
......@@ -264,7 +264,7 @@ public class DataUtils {
// 初始化订单+技能服务时间
List<Customer> customerList = new ArrayList<>();
for (int i = 0; i < customerIndexMap.keySet().size(); i++) {
customerList.add(new Customer(i + 1, customerIndexMap.get(i + 1), locationIndex.get(i + 2),
customerList.add(new Customer(i + 1, customerIndexMap.get(i + 1), "2000-01-01", locationIndex.get(i + 2),
customerStartMap.get(i + 1), customerEndMap.get(i + 1), customerSkillMap.get(i + 1),
// 初始化技能服务时间
customerCodeServiceTimeMap.get(customerIndexMap.get(i + 1))));
......
......@@ -42,7 +42,7 @@ class SolveServiceTest {
ExtractService extractService;
String groupId = "gsuzhou";
String day = "2023-03-20";
String day = "2023-07-23";
private SolverManager<DispatchSolution, UUID> solverManager;
private SolverFactory<DispatchSolution> solverFactory;
......@@ -53,7 +53,7 @@ class SolveServiceTest {
SolverConfig solverConfig = new SolverConfig().withSolutionClass(DispatchSolution.class);
solverConfig.withEntityClassList(Arrays.asList(Technician.class, Customer.class));// 这里不能漏掉,否则约束不生效
solverConfig.withConstraintProviderClass(DispatchConstraintProvider.class);
solverConfig.withTerminationSpentLimit(Duration.ofSeconds(10));
solverConfig.withTerminationSpentLimit(Duration.ofSeconds(5));
solverFactory = SolverFactory.create(solverConfig);
solver = solverFactory.buildSolver();
......@@ -81,7 +81,17 @@ class SolveServiceTest {
solveService.saveSolutionWrp(solution);
extractService.extractDispatchToOrder(groupId, batchNo, false);
log.info("testAsync done");
}
@Test
public void testExtraceToOrder() throws InterruptedException {
log.info("testExtraceToOrder init");
String batchNo = "20230723-0810";
extractService.extractDispatchToOrder(groupId, batchNo, false);
log.info("testExtraceToOrder done");
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!