Commit 7bd427a3 by 张晓

调整路由接口;补充appointment.dt字段

1 parent cc00a640
### 批次准备数据、aps引擎处理
* 接口
* ### 重新组织数据并开始计算
GET http://localhost:8011/dispatch/prepare/solveAsync/gsuzhou/2023-07-07
* 查看实时处理状态
GET http://localhost:8011/dispatch/prepare/solveStatus/gsuzhou/2023-07-07
* 停止实时处理状态
GET http://localhost:8011/dispatch/prepare/solveStop/gsuzhou/2023-07-07
......@@ -56,7 +56,7 @@ public class BatchController {
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat( pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime endTime;
String status;
}
......@@ -88,29 +88,10 @@ public class BatchController {
}
/*
* 检查指定日期的小组是否有在运行的批次任务,有则返回,没有则创建后返回批次码
*/
@GetMapping("/build/{groupId}/{day}")
public Result<?> buildBatch(@PathVariable String groupId, @PathVariable String day) {
@GetMapping("/query/{groupId}/{day}")
public Result<?> queryBatch(@PathVariable String groupId, @PathVariable String day) {
log.info("buildBatch, groupId:{}, day:{}", groupId, day);
try {
String batchNo = batchService.buildBatchData(groupId, day);
DispatchBatch batch = batchService.queryBatch(groupId, batchNo);
DispatchBatchDTO batchDTO = new DispatchBatchDTO();
BeanUtil.copyProperties(batch, batchDTO, CopyOptions.create().setIgnoreNullValue(true));
return Result.success(batchDTO);
} catch (SQLException e) {
log.error("buildBatch error", e);
return Result.failed(e.getMessage());
}
}
@GetMapping("/query/{groupId}/{batchNo}")
public Result<?> queryBatch(@PathVariable String groupId, @PathVariable String batchNo) {
log.info("buildBatch, groupId:{}, batchNo:{}", groupId, batchNo);
DispatchBatch batch = batchService.queryBatch(groupId, batchNo);
DispatchBatch batch = batchService.queryBatchInfoByDay(groupId, day);
DispatchBatchDTO batchDTO = new DispatchBatchDTO();
BeanUtil.copyProperties(batch, batchDTO, CopyOptions.create().setIgnoreNullValue(true));
......
......@@ -7,9 +7,11 @@ 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.apache.commons.lang3.StringUtils;
import org.optaplanner.core.api.score.buildin.hardsoftlong.HardSoftLongScore;
import org.optaplanner.core.api.solver.SolverManager;
import org.optaplanner.core.api.solver.SolverStatus;
......@@ -21,6 +23,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.sql.SQLException;
import java.time.Duration;
import java.util.*;
......@@ -39,6 +42,9 @@ public class PrepareController {
@Autowired
SolveService solveService;
@Autowired
BatchService batchService;
private SolverManager<DispatchSolution, UUID> solverManager;
......@@ -54,7 +60,7 @@ public class PrepareController {
/*
* 运行批次任务,直接返回结果
* 运行批次任务,直接返回结果(不重新进行数据准备)
*/
@GetMapping("/solveTest/{groupId}/{batchNo}")
public Result<?> prepareAndSolve(@PathVariable String groupId, @PathVariable String batchNo) {
......@@ -70,10 +76,12 @@ public class PrepareController {
return Result.success(resultMap);
}
// 异步任务运行 todo
@GetMapping("/solveAsync/{groupId}/{batchNo}")
public Result<?> solveAsync(@PathVariable String groupId, @PathVariable String batchNo) {
log.info("调用引擎处理-异步处理, groupId:{}, batchNo:{}", groupId, batchNo);
// 重新进行数据准备、异步任务运行
@GetMapping("/solveAsync/{groupId}/{day}")
public Result<?> solveAsync(@PathVariable String groupId, @PathVariable String day) throws SQLException {
log.info("调用引擎处理-异步处理, groupId:{}, day:{}", groupId, day);
String batchNo = batchService.buildBatchData(groupId, day);
log.info("调用引擎处理-异步处理, groupId:{}, day:{}, batchNo:{}", groupId, day, batchNo);
UUID problemId = solveService.generateProblemId(groupId, batchNo);
// 提交问题开始求解
DispatchSolution problem = solveService.prepareSolution(groupId, batchNo);
......@@ -86,22 +94,32 @@ public class PrepareController {
return Result.success("已触发异步执行");
}
@GetMapping("/solveStatus/{groupId}/{batchNo}")
public Result<?> solveStatus(@PathVariable String groupId, @PathVariable String batchNo) {
log.info("查询引擎处理状态, groupId:{}, batchNo:{}", groupId, batchNo);
@GetMapping("/solveStatus/{groupId}/{day}")
public Result<?> solveStatus(@PathVariable String groupId, @PathVariable String day) {
log.info("查询引擎处理状态, groupId:{}, day:{}", groupId, day);
String batchNo = batchService.queryBatchNoByDay(groupId, day);
log.info("查询引擎处理状态, groupId:{}, day:{}, batchNo:{}", groupId, day, batchNo);
if (StringUtils.isEmpty(batchNo)) {
return Result.failed("未查询到到批次数据信息");
}
UUID problemId = solveService.generateProblemId(groupId, batchNo);
SolverStatus status = solverManager.getSolverStatus(problemId);
log.info("查询引擎处理状态, groupId:{}, batchNo:{}, status:{}", groupId, batchNo, status.toString());
log.info("查询引擎处理状态, groupId:{}, day:{}, batchNo:{}, status:{}", groupId, day, batchNo, status.toString());
return Result.success(status);
}
@GetMapping("/solveStop/{groupId}/{batchNo}")
public Result<?> solveStop(@PathVariable String groupId, @PathVariable String batchNo) {
log.info("停止引擎处理批次, groupId:{}, batchNo:{}", groupId, batchNo);
@GetMapping("/solveStop/{groupId}/{day}")
public Result<?> solveStop(@PathVariable String groupId, @PathVariable String day) {
log.info("停止引擎处理批次, groupId:{}, day:{}", groupId, day);
String batchNo = batchService.queryBatchNoByDay(groupId, day);
log.info("查询引擎处理状态, groupId:{}, day:{}, batchNo:{}", groupId, day, batchNo);
if (StringUtils.isEmpty(batchNo)) {
return Result.failed("未查询到到批次数据信息");
}
UUID problemId = solveService.generateProblemId(groupId, batchNo);
solverManager.terminateEarly(problemId);
SolverStatus status = solverManager.getSolverStatus(problemId);
log.info("停止引擎处理批次, groupId:{}, batchNo:{}, status:{}", groupId, batchNo, status.toString());
log.info("停止引擎处理批次, groupId:{}, day:{}, batchNo:{}, status:{}", groupId, day, batchNo, status.toString());
return Result.success(status);
}
......
......@@ -4,12 +4,15 @@ package com.dituhui.pea.dispatch.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Data
......@@ -46,6 +49,13 @@ public class OrderAppointment implements Serializable {
private Integer isWorkshop;
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@Column(name = "dt")
private LocalDate dt;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
......
......@@ -4,12 +4,15 @@ package com.dituhui.pea.dispatch.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Data
......@@ -57,6 +60,14 @@ public class OrderRequest implements Serializable {
@Column(name = "fault_describe")
private String faultDescribe;
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@Column(name = "dt")
private LocalDate dt;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
......
......@@ -19,6 +19,8 @@ public interface BatchService {
@Transactional
String buildBatchData(String groupId, String day) throws SQLException;
DispatchBatch queryBatchInfoByDay(String groupId, String day);
String queryBatchNoByDay(String groupId, String day);
DispatchBatch queryBatch(String groupId, String day);
}
......@@ -103,7 +103,7 @@ public class BatchServiceImpl implements BatchService {
" and a.dt = ? " +
" and appointment_status ='NOT_ASSIGNED' and appointment_method like 'AUTO%' \n" +
" order by a.expect_time_begin asc ";
int orderCount = jdbcTemplate.update(sqlOrder, batchNo, groupId, batchDay );
int orderCount = jdbcTemplate.update(sqlOrder, batchNo, groupId, batchDay);
// 已派过PRE状态还可以再次派
String sqlOrderPre = "INSERT INTO dispatch_order (group_id, batch_no, order_id , x, y, expect_time_begin, expect_time_end, tags, priority , skills , take_time )\n" +
......@@ -117,14 +117,14 @@ public class BatchServiceImpl implements BatchService {
" and a.appointment_status = 'ASSIGNED' and appointment_method like 'AUTO%' \n" +
" and o.pre_status ='PRE' \n" +
" order by a.expect_time_begin asc ";
int orderCountPre = jdbcTemplate.update(sqlOrderPre, batchNo, groupId, batchDay );
int orderCountPre = jdbcTemplate.update(sqlOrderPre, batchNo, groupId, batchDay);
log.info("准备批次数据 order1 :{}", orderCount);
log.info("准备批次数据 order2 :{}", orderCountPre);
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, LocalDateTime.now(), groupId, batchNo);
log.info("准备批次数据完成, groupId:{}, day:{}, batchNo:{}", groupId, batchDay, batchNo);
......@@ -132,13 +132,20 @@ public class BatchServiceImpl implements BatchService {
}
public DispatchBatch queryBatch(String groupId, String batchNo) {
List<DispatchBatch> batchList = batchRepository.findLatestGroup(groupId, batchNo);
if (batchList.size() > 0) {
return batchList.get(0);
@Override
public String queryBatchNoByDay(String groupId, String day) {
Optional<DispatchBatch> optional = batchRepository.findByGroupIdAndBatchDate(groupId, day);
if (optional.isPresent()) {
return optional.get().getBatchNo();
} else {
return new DispatchBatch();
return "";
}
}
@Override
public DispatchBatch queryBatchInfoByDay(String groupId, String day) {
Optional<DispatchBatch> optional = batchRepository.findByGroupIdAndBatchDate(groupId, day);
return optional.orElseGet(DispatchBatch::new);
}
......
......@@ -223,6 +223,7 @@ public class ExtractServiceImpl implements ExtractService {
appointment.setEngineerName(engName);
appointment.setEngineerPhone(phone);
appointment.setEngineerAge(age);
appointment.setDt(orderRequest.getDt());
appointment.setExpectStartTime(dispatchOrder.getTimeBegin());
appointment.setExpectEndTime(dispatchOrder.getTimeEnd());
appointment.setUpdateTime(LocalDateTime.now());
......@@ -240,6 +241,7 @@ public class ExtractServiceImpl implements ExtractService {
appointment.setEngineerPhone(phone);
appointment.setEngineerAge(age);
appointment.setIsWorkshop(0);
appointment.setDt(orderRequest.getDt());
appointment.setExpectStartTime(dispatchOrder.getTimeBegin());
appointment.setExpectEndTime(dispatchOrder.getTimeEnd());
appointment.setPreStatus("PRE");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!