Commit f83368b1 by 张晓

Merge branch 'feature-dispatch-zx' into develop

2 parents 2068103e 2c3854b4
......@@ -94,8 +94,8 @@ public class PrepareController {
DispatchSolution problem = solveService.prepareSolution(groupId, batchNo);
if (problem.getCustomerList().size() <= 0) {
log.info("dispatchRun no order , group:{}, day:{}, batch:{}, order-size:{}", groupId, day, batchNo, problem.getCustomerList().size());
return Result.failed("当前批次没有工单数据");
log.info("dispatchRun 当前批次没有待指派工单 , group:{}, day:{}, batch:{}, order-size:{}", groupId, day, batchNo, problem.getCustomerList().size());
return Result.failed("当前批次没有待指派工单");
}
DispatchSolution solution = solver.solve(problem);
......
package com.dituhui.pea.dispatch.dao;
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.repository.CrudRepository;
......@@ -11,10 +10,12 @@ import java.util.Optional;
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);
Optional<DispatchOrder> findByGroupIdAndBatchNoAndOrderId(String groupId, String batchNo, String orderId);
......
......@@ -122,8 +122,8 @@ public class Customer {
*/
public long getDistanceFromPreviousStandstill() {
if (technician == null) {
throw new IllegalStateException(
"This method must not be called when the shadow variables are not initialized yet.");
return 0;
// throw new IllegalStateException("This method must not be called when the shadow variables are not initialized yet.");
}
if (previousCustomer == null) {
return technician.getDepot().getLocation().getDistanceTo(location);
......@@ -138,8 +138,8 @@ public class Customer {
*/
public int getPathTimeFromPreviousStandstill() {
if (technician == null) {
throw new IllegalStateException(
"This method must not be called when the shadow variables are not initialized yet.");
return 0;
// throw new IllegalStateException("This method must not be called when the shadow variables are not initialized yet.");
}
if (previousCustomer == null) {
return technician.getDepot().getLocation().getPathTimeTo(location);
......
......@@ -101,7 +101,7 @@ public class BatchScheduler {
DispatchSolution problem = solveService.prepareSolution(groupId, batchNo);
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;
}
log.info("dispatchRun prepare done, group:{}, day:{}, batch:{}, problemId:{}", groupId, currDay, batchNo, problemId);
......
......@@ -36,7 +36,6 @@ import java.util.Optional;
public class BatchServiceImpl implements BatchService {
@Autowired
DispatchBatchRepository batchRepository;
......@@ -123,21 +122,36 @@ public class BatchServiceImpl implements BatchService {
" where a.org_group_id=? and a.status='OPEN' \n" +
" and a.dt = ? " +
" 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 ";
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("准备批次数据 orderCountPre :{}", orderCountPre);
log.info("准备批次数据 orderCountConfirm :{}", orderCountConfirm);
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=?",
engCount, orderCount + orderCountPre, LocalDateTime.now(), groupId, batchNo);
engCount, orderCount + orderCountPre + orderCountConfirm, LocalDateTime.now(), groupId, batchNo);
} else {
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);
......
......@@ -20,18 +20,15 @@ import org.optaplanner.core.api.solver.SolverFactory;
import org.optaplanner.core.config.solver.SolverConfig;
import org.optaplanner.persistence.jackson.impl.domain.solution.JacksonSolutionFileIO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.*;
......@@ -104,7 +101,7 @@ public class SolveServiceImpl implements SolveService {
// customerlist
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());
......@@ -200,8 +197,8 @@ public class SolveServiceImpl implements SolveService {
// Load the problem
DispatchSolution problem = prepareSolution(groupId, batchNo);
if (problem.getCustomerList().size() <= 0) {
log.info("dispatchRun no order , group:{}, batch:{}, order-size:{}", groupId, batchNo, problem.getCustomerList().size());
throw new RuntimeException("当前批次没有工单信息");
log.info("dispatchRun 当前批次没有待指派工单 , group:{}, batch:{}, order-size:{}", groupId, batchNo, problem.getCustomerList().size());
throw new RuntimeException("当前批次没有待指派工单");
}
......
......@@ -4,7 +4,7 @@ server:
dispatch:
cron:
expr: 0 */30 8-18 * * ?
next-day-limit: 3
next-day-limit: 2
spring:
application:
......@@ -33,7 +33,7 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource
jpa:
show-sql: true
show-sql: false
hibernate:
ddl-auto: none
......
package com.dituhui.pea.dispatch;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.dispatch.constraint.DispatchConstraintProvider;
import com.dituhui.pea.dispatch.pojo.Customer;
import com.dituhui.pea.dispatch.pojo.DispatchSolution;
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.SolveService;
import lombok.extern.slf4j.Slf4j;
import org.drools.commands.fluent.Batch;
import org.junit.jupiter.api.Test;
import org.optaplanner.core.api.solver.Solver;
import org.optaplanner.core.api.solver.SolverFactory;
......@@ -28,13 +31,16 @@ import static java.lang.Thread.sleep;
class SolveServiceTest {
@Autowired
BatchService batchService;
@Autowired
SolveService solveService;
@Autowired
ExtractService extractService;
String groupId = "gsuzhou";
String batchNo = "20230705-1500";
String day = "2023-03-20";
private SolverManager<DispatchSolution, UUID> solverManager;
......@@ -52,33 +58,25 @@ class SolveServiceTest {
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
public void testAsync() throws InterruptedException {
log.info("testAsync init");
UUID problemId = solveService.generateProblemId(groupId, batchNo);
log.info("testAsync problemId:{}", problemId);
DispatchSolution problem = solveService.prepareSolution(groupId, batchNo);
DispatchSolution solution = solver.solve(problem);
solveService.saveSolutionWrp(solution);
String batchNo = batchService.buildBatchData(groupId, day);
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,
this.solveService::saveSolutionWrp);*/
DispatchSolution solution = solver.solve(problem);
solveService.saveSolutionWrp(solution);
extractService.extractDispatchToOrder(groupId, batchNo, false);
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!