Commit 2c3854b4 by 张晓

CONFIRM的订单再次入表(1占用时间窗 2,可视化需要展示)

1 parent 7f062990
...@@ -94,8 +94,8 @@ public class PrepareController { ...@@ -94,8 +94,8 @@ public class PrepareController {
DispatchSolution problem = solveService.prepareSolution(groupId, batchNo); DispatchSolution problem = solveService.prepareSolution(groupId, batchNo);
if (problem.getCustomerList().size() <= 0) { if (problem.getCustomerList().size() <= 0) {
log.info("dispatchRun no order , group:{}, day:{}, batch:{}, order-size:{}", groupId, day, batchNo, problem.getCustomerList().size()); log.info("dispatchRun 当前批次没有待指派工单 , group:{}, day:{}, batch:{}, order-size:{}", groupId, day, batchNo, problem.getCustomerList().size());
return Result.failed("当前批次没有工单数据"); return Result.failed("当前批次没有待指派工单");
} }
DispatchSolution solution = solver.solve(problem); DispatchSolution solution = solver.solve(problem);
......
package com.dituhui.pea.dispatch.dao; package com.dituhui.pea.dispatch.dao;
import com.dituhui.pea.dispatch.entity.DispatchOrder; import com.dituhui.pea.dispatch.entity.DispatchOrder;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
...@@ -11,10 +10,12 @@ import java.util.Optional; ...@@ -11,10 +10,12 @@ import java.util.Optional;
public interface DispatchOrderRepository extends CrudRepository<DispatchOrder, Long> { public interface DispatchOrderRepository extends CrudRepository<DispatchOrder, Long> {
List<DispatchOrder> findByGroupIdAndBatchNo(String groupId, String batchNo); @Query("from DispatchOrder where groupId=?1 and batchNo=?2 and status !='CONFIRM' and (engineerCode is null or engineerCode='' ) ")
List<DispatchOrder> findNotAssigned(String groupId, String batchNo);
@Query("from DispatchOrder where groupId=?1 and batchNo=?2 and engineerCode is not null and engineerCode!='' ") // 查看算法指派成功且非confirm状态的
@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); List<DispatchOrder> findAssigned(String groupId, String batchNo);
Optional<DispatchOrder> findByGroupIdAndBatchNoAndOrderId(String groupId, String batchNo, String orderId); Optional<DispatchOrder> findByGroupIdAndBatchNoAndOrderId(String groupId, String batchNo, String orderId);
......
...@@ -122,8 +122,8 @@ public class Customer { ...@@ -122,8 +122,8 @@ public class Customer {
*/ */
public long getDistanceFromPreviousStandstill() { public long getDistanceFromPreviousStandstill() {
if (technician == null) { if (technician == null) {
throw new IllegalStateException( return 0;
"This method must not be called when the shadow variables are not initialized yet."); // throw new IllegalStateException("This method must not be called when the shadow variables are not initialized yet.");
} }
if (previousCustomer == null) { if (previousCustomer == null) {
return technician.getDepot().getLocation().getDistanceTo(location); return technician.getDepot().getLocation().getDistanceTo(location);
...@@ -138,8 +138,8 @@ public class Customer { ...@@ -138,8 +138,8 @@ public class Customer {
*/ */
public int getPathTimeFromPreviousStandstill() { public int getPathTimeFromPreviousStandstill() {
if (technician == null) { if (technician == null) {
throw new IllegalStateException( return 0;
"This method must not be called when the shadow variables are not initialized yet."); // throw new IllegalStateException("This method must not be called when the shadow variables are not initialized yet.");
} }
if (previousCustomer == null) { if (previousCustomer == null) {
return technician.getDepot().getLocation().getPathTimeTo(location); return technician.getDepot().getLocation().getPathTimeTo(location);
......
...@@ -101,7 +101,7 @@ public class BatchScheduler { ...@@ -101,7 +101,7 @@ public class BatchScheduler {
DispatchSolution problem = solveService.prepareSolution(groupId, batchNo); DispatchSolution problem = solveService.prepareSolution(groupId, batchNo);
if (problem.getCustomerList().size() <= 0) { if (problem.getCustomerList().size() <= 0) {
log.info("dispatchRun no order , group:{}, day:{}, batch:{}, problemId:{}, order-size:{}", groupId, currDay, batchNo, problemId, problem.getCustomerList().size()); log.info("dispatchRun 当前批次没有待指派工单 , group:{}, day:{}, batch:{}, problemId:{}, order-size:{}", groupId, currDay, batchNo, problemId, problem.getCustomerList().size());
continue; continue;
} }
log.info("dispatchRun prepare done, group:{}, day:{}, batch:{}, problemId:{}", groupId, currDay, batchNo, problemId); log.info("dispatchRun prepare done, group:{}, day:{}, batch:{}, problemId:{}", groupId, currDay, batchNo, problemId);
......
...@@ -36,7 +36,6 @@ import java.util.Optional; ...@@ -36,7 +36,6 @@ import java.util.Optional;
public class BatchServiceImpl implements BatchService { public class BatchServiceImpl implements BatchService {
@Autowired @Autowired
DispatchBatchRepository batchRepository; DispatchBatchRepository batchRepository;
...@@ -123,21 +122,36 @@ public class BatchServiceImpl implements BatchService { ...@@ -123,21 +122,36 @@ public class BatchServiceImpl implements BatchService {
" where a.org_group_id=? and a.status='OPEN' \n" + " where a.org_group_id=? and a.status='OPEN' \n" +
" and a.dt = ? " + " and a.dt = ? " +
" and a.appointment_status = 'ASSIGNED' and appointment_method like 'AUTO%' \n" + " and a.appointment_status = 'ASSIGNED' and appointment_method like 'AUTO%' \n" +
" and o.pre_status ='PRE' \n" + " and o.pre_status in ('PRE') \n" +
" order by a.expect_time_begin asc "; " order by a.expect_time_begin asc ";
int orderCountPre = jdbcTemplate.update(sqlOrderPre, batchNo, groupId, batchDay); int orderCountPre = jdbcTemplate.update(sqlOrderPre, batchNo, groupId, batchDay);
// CONFIRM的订单再次入表(1占用时间窗 2,可视化需要展示)
String sqlOrderConfirm = "INSERT INTO dispatch_order (group_id, batch_no, order_id , x, y, expect_time_begin, expect_time_end, tags, priority , skills , take_time, " +
" engineer_code, seq, time_begin, time_end, status )\n" +
" select a.org_group_id, ?, a.order_id, a.x, a.y , \n" +
" a.expect_time_begin, a.expect_time_end, a.tags, a.priority , concat(a.brand,'-', a.type, '-', a.skill) skills , b.take_time, \n" +
" o.engineer_code, -1, o.expect_start_time, o.expect_end_time, o.pre_status " +
" from order_request a " +
" left join skill_info b on (a.brand=b.brand and a.type=b.type and a.skill=b.skill )\n" +
" left join order_appointment o on (a.order_id =o.order_id)\n" +
" where a.org_group_id=? and a.status='OPEN' \n" +
" and a.dt = ? " +
" and o.pre_status in ('CONFIRM') \n" +
" order by a.expect_time_begin asc ";
int orderCountConfirm = jdbcTemplate.update(sqlOrderConfirm, batchNo, groupId, batchDay);
log.info("准备批次数据 orderCount :{}", orderCount); log.info("准备批次数据 orderCount :{}", orderCount);
log.info("准备批次数据 orderCountPre :{}", orderCountPre); log.info("准备批次数据 orderCountPre :{}", orderCountPre);
log.info("准备批次数据 orderCountConfirm :{}", orderCountConfirm);
if (orderCount + orderCountPre > 0) { if (orderCount + orderCountPre > 0) {
jdbcTemplate.update("update dispatch_batch set engineer_num=? , order_num=?, start_time=?, end_time=null, status='RUNNING' where group_id=? and batch_no=?", jdbcTemplate.update("update dispatch_batch set engineer_num=? , order_num=?, start_time=?, end_time=null, status='RUNNING' where group_id=? and batch_no=?",
engCount, orderCount + orderCountPre, LocalDateTime.now(), groupId, batchNo); engCount, orderCount + orderCountPre + orderCountConfirm, LocalDateTime.now(), groupId, batchNo);
} else { } else {
jdbcTemplate.update("update dispatch_batch set engineer_num=? , order_num=?, start_time=?, end_time=?, status='DONE' where group_id=? and batch_no=?", jdbcTemplate.update("update dispatch_batch set engineer_num=? , order_num=?, start_time=?, end_time=?, status='DONE' where group_id=? and batch_no=?",
engCount, orderCount + orderCountPre, LocalDateTime.now(), LocalDateTime.now(), groupId, batchNo); engCount, 0, LocalDateTime.now(), LocalDateTime.now(), groupId, batchNo);
} }
log.info("准备批次数据完成, groupId:{}, day:{}, batchNo:{}", groupId, batchDay, batchNo); log.info("准备批次数据完成, groupId:{}, day:{}, batchNo:{}", groupId, batchDay, batchNo);
......
...@@ -20,18 +20,15 @@ import org.optaplanner.core.api.solver.SolverFactory; ...@@ -20,18 +20,15 @@ import org.optaplanner.core.api.solver.SolverFactory;
import org.optaplanner.core.config.solver.SolverConfig; import org.optaplanner.core.config.solver.SolverConfig;
import org.optaplanner.persistence.jackson.impl.domain.solution.JacksonSolutionFileIO; import org.optaplanner.persistence.jackson.impl.domain.solution.JacksonSolutionFileIO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
...@@ -104,7 +101,7 @@ public class SolveServiceImpl implements SolveService { ...@@ -104,7 +101,7 @@ public class SolveServiceImpl implements SolveService {
// customerlist // customerlist
ArrayList<Customer> customerList = new ArrayList<>(); ArrayList<Customer> customerList = new ArrayList<>();
List<DispatchOrder> dispatchOrderList = dispatchOrderRepo.findByGroupIdAndBatchNo(groupId, batchNo); List<DispatchOrder> dispatchOrderList = dispatchOrderRepo.findNotAssigned(groupId, batchNo);
log.info("组织问题对象, dispatchorder-list, groupId:{}, batchNo:{}, dispatchorder-size:{}", groupId, batchNo, dispatchOrderList.size()); log.info("组织问题对象, dispatchorder-list, groupId:{}, batchNo:{}, dispatchorder-size:{}", groupId, batchNo, dispatchOrderList.size());
...@@ -200,8 +197,8 @@ public class SolveServiceImpl implements SolveService { ...@@ -200,8 +197,8 @@ public class SolveServiceImpl implements SolveService {
// Load the problem // Load the problem
DispatchSolution problem = prepareSolution(groupId, batchNo); DispatchSolution problem = prepareSolution(groupId, batchNo);
if (problem.getCustomerList().size() <= 0) { if (problem.getCustomerList().size() <= 0) {
log.info("dispatchRun no order , group:{}, batch:{}, order-size:{}", groupId, batchNo, problem.getCustomerList().size()); log.info("dispatchRun 当前批次没有待指派工单 , group:{}, batch:{}, order-size:{}", groupId, batchNo, problem.getCustomerList().size());
throw new RuntimeException("当前批次没有工单信息"); throw new RuntimeException("当前批次没有待指派工单");
} }
......
...@@ -4,7 +4,7 @@ server: ...@@ -4,7 +4,7 @@ server:
dispatch: dispatch:
cron: cron:
expr: 0 */30 8-18 * * ? expr: 0 */30 8-18 * * ?
next-day-limit: 3 next-day-limit: 2
spring: spring:
application: application:
...@@ -33,7 +33,7 @@ spring: ...@@ -33,7 +33,7 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
jpa: jpa:
show-sql: true show-sql: false
hibernate: hibernate:
ddl-auto: none ddl-auto: none
......
package com.dituhui.pea.dispatch; package com.dituhui.pea.dispatch;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.dispatch.constraint.DispatchConstraintProvider; import com.dituhui.pea.dispatch.constraint.DispatchConstraintProvider;
import com.dituhui.pea.dispatch.pojo.Customer; import com.dituhui.pea.dispatch.pojo.Customer;
import com.dituhui.pea.dispatch.pojo.DispatchSolution; import com.dituhui.pea.dispatch.pojo.DispatchSolution;
import com.dituhui.pea.dispatch.pojo.Technician; import com.dituhui.pea.dispatch.pojo.Technician;
import com.dituhui.pea.dispatch.service.BatchService;
import com.dituhui.pea.dispatch.service.ExtractService; import com.dituhui.pea.dispatch.service.ExtractService;
import com.dituhui.pea.dispatch.service.SolveService; import com.dituhui.pea.dispatch.service.SolveService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.drools.commands.fluent.Batch;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.optaplanner.core.api.solver.Solver; import org.optaplanner.core.api.solver.Solver;
import org.optaplanner.core.api.solver.SolverFactory; import org.optaplanner.core.api.solver.SolverFactory;
...@@ -28,13 +31,16 @@ import static java.lang.Thread.sleep; ...@@ -28,13 +31,16 @@ import static java.lang.Thread.sleep;
class SolveServiceTest { class SolveServiceTest {
@Autowired @Autowired
BatchService batchService;
@Autowired
SolveService solveService; SolveService solveService;
@Autowired @Autowired
ExtractService extractService; ExtractService extractService;
String groupId = "gsuzhou"; String groupId = "gsuzhou";
String batchNo = "20230705-1500"; String day = "2023-03-20";
private SolverManager<DispatchSolution, UUID> solverManager; private SolverManager<DispatchSolution, UUID> solverManager;
...@@ -52,33 +58,25 @@ class SolveServiceTest { ...@@ -52,33 +58,25 @@ class SolveServiceTest {
solverManager = SolverManager.create(solverConfig, new SolverManagerConfig()); solverManager = SolverManager.create(solverConfig, new SolverManagerConfig());
} }
@Test
public void test1() {
log.info("init");
DispatchSolution solution = solveService.prepareAndSolveTest(groupId, batchNo);
log.info("result:{}", solution);
log.info("done");
}
@Test @Test
public void testAsync() throws InterruptedException { public void testAsync() throws InterruptedException {
log.info("testAsync init"); log.info("testAsync init");
UUID problemId = solveService.generateProblemId(groupId, batchNo);
log.info("testAsync problemId:{}", problemId); String batchNo = batchService.buildBatchData(groupId, day);
DispatchSolution problem = solveService.prepareSolution(groupId, batchNo);
DispatchSolution solution = solver.solve(problem);
solveService.saveSolutionWrp(solution);
log.info("调用引擎处理, groupId:{}, day:{}, batchNo:{}", groupId, day, batchNo);
DispatchSolution problem = solveService.prepareSolution(groupId, batchNo);
if (problem.getCustomerList().size() <= 0) {
log.info("调用引擎处理, 没有待指派工单 , group:{}, day:{}, batch:{}, order-size:{}", groupId, day, batchNo, 0);
return;
}
/* solverManager.solveAndListen(problemId, id -> problem, DispatchSolution solution = solver.solve(problem);
this.solveService::saveSolutionWrp);*/ solveService.saveSolutionWrp(solution);
extractService.extractDispatchToOrder(groupId, batchNo, false);
log.info("testAsync done"); log.info("testAsync done");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!