Commit e6abfb74 by 张晓

增加order_event ,order_log 写记录

1 parent 2c3854b4
package com.dituhui.pea.dispatch.dao;
import java.util.List;
import com.dituhui.pea.dispatch.entity.OrderEvent;
import org.springframework.data.repository.CrudRepository;
import com.fasterxml.jackson.annotation.JsonFormat;
public interface OrderEventRepository extends CrudRepository<OrderEvent, Long> {
}
package com.dituhui.pea.dispatch.dao;
import java.util.List;
import com.dituhui.pea.dispatch.entity.OrderLog;
import org.springframework.data.repository.CrudRepository;
import com.fasterxml.jackson.annotation.JsonFormat;
public interface OrderLogRepository extends CrudRepository<OrderLog, Long> {
}
package com.dituhui.pea.dispatch.entity;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import javax.persistence.*;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.experimental.Accessors;
@Accessors(chain = true)
@Data
@Entity
@Table(name = "order_event")
public class OrderEvent implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "order_id")
private String orderId;
@Column(name = "suborder_id")
private String suborderId;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime happen;
private String event;
private String operator;
@Column(name = "operator_name")
private String operatorName;
private String source;
private String description;
private String memo;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Column(name = "create_time")
private LocalDateTime createTime;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Column(name = "update_time")
private LocalDateTime updateTime;
}
package com.dituhui.pea.dispatch.entity;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.Date;
import javax.persistence.*;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.experimental.Accessors;
@Accessors(chain = true)
@Data
@Entity
@Table(name = "order_log")
public class OrderLog implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
@Column(name = "order_id")
private String orderId;
@Column(name = "suborder_id")
private String suborderId;
private String source;
private String operator;
private String content;
@Column(name = "content_old")
private String contentOld;
private String memo;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Column(name = "create_time")
private LocalDateTime createTime;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Column(name = "update_time")
private LocalDateTime updateTime;
}
...@@ -84,10 +84,10 @@ public class BatchScheduler { ...@@ -84,10 +84,10 @@ public class BatchScheduler {
if (null == dispatchBatch.getCutoffedTime()) { if (null == dispatchBatch.getCutoffedTime()) {
log.info("dispatchRun 已过cutoff时间,更新pre状态为confirm, 执行首次confirm----- group:{}, day:{}", groupId, currDay); log.info("dispatchRun 已过cutoff时间,更新pre状态为confirm, 执行首次confirm----- group:{}, day:{}", groupId, currDay);
this.extractService.extractDispatchToOrder(groupId, dispatchBatch.getBatchNo(), true); this.extractService.extractDispatchToOrder(groupId, dispatchBatch.getBatchNo(), true);
dispatchBatch.setCutoffedTime(LocalDateTime.now()); dispatchBatch.setCutoffedTime(LocalDateTime.now());
batchService.saveDispatchBatch(dispatchBatch); batchService.saveDispatchBatch(dispatchBatch);
} else { } else {
log.info("dispatchRun 已过cutoff时间,更新pre状态为confirm, 已经执行confirm,跳过当次计算 ----- group:{}, day:{}", groupId, currDay); log.info("dispatchRun 已过cutoff时间,更新pre状态为confirm, 已经执行confirm,跳过当次计算 ----- group:{}, day:{}", groupId, currDay);
} }
......
...@@ -3,13 +3,11 @@ package com.dituhui.pea.dispatch.service.impl; ...@@ -3,13 +3,11 @@ package com.dituhui.pea.dispatch.service.impl;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.dituhui.pea.dispatch.dao.*; import com.dituhui.pea.dispatch.dao.*;
import com.dituhui.pea.dispatch.entity.DispatchOrder; import com.dituhui.pea.dispatch.entity.*;
import com.dituhui.pea.dispatch.entity.EngineerInfo;
import com.dituhui.pea.dispatch.entity.OrderAppointment;
import com.dituhui.pea.dispatch.entity.OrderRequest;
import com.dituhui.pea.dispatch.service.ExtractService; import com.dituhui.pea.dispatch.service.ExtractService;
import com.mysql.cj.util.StringUtils; import com.mysql.cj.util.StringUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -51,6 +49,12 @@ public class ExtractServiceImpl implements ExtractService { ...@@ -51,6 +49,12 @@ public class ExtractServiceImpl implements ExtractService {
OrderAppointmentRepository orderAppointmentRepo; OrderAppointmentRepository orderAppointmentRepo;
@Autowired @Autowired
OrderLogRepository orderLogRepo;
@Autowired
OrderEventRepository orderEventRepo;
@Autowired
private EntityManager entityManager; private EntityManager entityManager;
@Autowired @Autowired
...@@ -80,8 +84,8 @@ public class ExtractServiceImpl implements ExtractService { ...@@ -80,8 +84,8 @@ public class ExtractServiceImpl implements ExtractService {
int idx = atomicInteger.getAndIncrement(); int idx = atomicInteger.getAndIncrement();
String orderId = dispatchOrder.getOrderId(); String orderId = dispatchOrder.getOrderId();
String engCode = dispatchOrder.getEngineerCode(); String engCode = dispatchOrder.getEngineerCode();
log.info("算法结果更新到工单, step1.1-loop, groupId:{}, batchNo:{}, {}/{}, orderId:{}, engCode:{}", log.info("算法结果更新到工单, step1.1-loop, {}/{}, groupId:{}, batchNo:{}, orderId:{}, engCode:{}",
groupId, batchNo, idx, dispatchOrderList.size(), orderId, engCode); idx, dispatchOrderList.size(), groupId, batchNo, orderId, engCode);
Optional<OrderRequest> orderOpt = orderRequestRepo.findByOrderId(orderId); Optional<OrderRequest> orderOpt = orderRequestRepo.findByOrderId(orderId);
if (!orderOpt.isPresent()) { if (!orderOpt.isPresent()) {
...@@ -123,8 +127,8 @@ public class ExtractServiceImpl implements ExtractService { ...@@ -123,8 +127,8 @@ public class ExtractServiceImpl implements ExtractService {
if (appointmentOpt.isEmpty()) { if (appointmentOpt.isEmpty()) {
// 没有则插入一条 // 没有则插入一条
OrderAppointment appointment = new OrderAppointment(); OrderAppointment appointment = new OrderAppointment();
appointment.setOrderId(dispatchOrder.getOrderId()); appointment.setOrderId(orderId);
String subId = String.format("%s_%s", dispatchOrder.getOrderId(), DateUtil.format(LocalDateTime.now(), "yyyyMMddHHmmss")); String subId = String.format("%s_%s", orderId, DateUtil.format(LocalDateTime.now(), "yyyyMMddHHmmss"));
appointment.setSuborderId(subId); appointment.setSuborderId(subId);
appointment.setMainSub(1); appointment.setMainSub(1);
appointment.setEngineerCode(engCode); appointment.setEngineerCode(engCode);
...@@ -143,11 +147,26 @@ public class ExtractServiceImpl implements ExtractService { ...@@ -143,11 +147,26 @@ public class ExtractServiceImpl implements ExtractService {
orderAppointmentRepo.save(appointment); orderAppointmentRepo.save(appointment);
// 写order_log
OrderLog orderLog = new OrderLog().setOrderId(orderId).setSuborderId(subId).setSource("PEA-BACKEND").setOperator("DISPATCH")
.setContent(String.format("批量自动指派:<%s,%s>", engCode, engName)).setContentOld("")
.setMemo("批量自动指派").setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now());
orderLogRepo.save(orderLog);
if (isConfirm) {
OrderEvent orderEvent = new OrderEvent().setOrderId(orderId).setSuborderId(subId).setHappen(LocalDateTime.now())
.setEvent("批量自动指派").setOperator("DISPATCH").setOperatorName("算法批量指派").setSource("PEA-BACKEND")
.setDescription(String.format("批量自动指派:<%s,%s>", engCode, engName)).setMemo("")
.setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now());
orderEventRepo.save(orderEvent);
}
} else { } else {
// 如果有记录:1虚拟指派 2排量预派 3 // 如果有记录:1虚拟指派 2排量预派 3
if (Set.of("PRE", "VIRTUAL").contains(appointmentOpt.get().getPreStatus()) && if (Set.of("PRE", "VIRTUAL").contains(appointmentOpt.get().getPreStatus()) &&
Set.of("NOT_ASSIGNED", "ASSIGNED").contains(appointmentOpt.get().getStatus())) { Set.of("NOT_ASSIGNED", "ASSIGNED").contains(appointmentOpt.get().getStatus())) {
OrderAppointment appointment = appointmentOpt.get(); OrderAppointment appointment = appointmentOpt.get();
String lastContent = String.format("批量自动指派:<%s,%s>", appointment.getEngineerCode(), appointment.getEngineerName());
appointment.setStatus("ASSIGNED"); appointment.setStatus("ASSIGNED");
appointment.setPreStatus(isConfirm ? "CONFIRM" : "PRE"); appointment.setPreStatus(isConfirm ? "CONFIRM" : "PRE");
appointment.setEngineerCode(engCode); appointment.setEngineerCode(engCode);
...@@ -159,6 +178,20 @@ public class ExtractServiceImpl implements ExtractService { ...@@ -159,6 +178,20 @@ public class ExtractServiceImpl implements ExtractService {
appointment.setExpectEndTime(dispatchOrder.getTimeEnd()); appointment.setExpectEndTime(dispatchOrder.getTimeEnd());
appointment.setUpdateTime(LocalDateTime.now()); appointment.setUpdateTime(LocalDateTime.now());
orderAppointmentRepo.save(appointment); orderAppointmentRepo.save(appointment);
OrderLog orderLog = new OrderLog().setOrderId(orderId).setSuborderId(appointment.getSuborderId()).setSource("PEA-BACKEND").setOperator("DISPATCH")
.setContent(String.format("批量自动指派:<%s,%s>", engCode, engName)).setContentOld(lastContent)
.setMemo("批量自动指派").setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now());
orderLogRepo.save(orderLog);
if (isConfirm) {
OrderEvent orderEvent = new OrderEvent().setOrderId(orderId).setSuborderId(appointment.getSuborderId()).setHappen(LocalDateTime.now())
.setEvent("批量自动指派").setOperator("DISPATCH").setOperatorName("算法批量指派").setSource("PEA-BACKEND")
.setDescription(String.format("批量自动指派:<%s,%s>", engCode, engName)).setMemo("")
.setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now());
orderEventRepo.save(orderEvent);
}
} else { } else {
// 其它情况待补充(改约) todo // 其它情况待补充(改约) todo
if (Set.of("CONFIRM").contains(appointmentOpt.get().getPreStatus()) && if (Set.of("CONFIRM").contains(appointmentOpt.get().getPreStatus()) &&
...@@ -169,6 +202,7 @@ public class ExtractServiceImpl implements ExtractService { ...@@ -169,6 +202,7 @@ public class ExtractServiceImpl implements ExtractService {
} }
}); });
log.info("算法结果更新到工单完成, groupId:{}, batchNo:{}", groupId, batchNo); log.info("算法结果更新到工单完成, groupId:{}, batchNo:{}", groupId, batchNo);
......
...@@ -7,8 +7,10 @@ import com.dituhui.pea.dispatch.common.GeoDistanceCalculator; ...@@ -7,8 +7,10 @@ import com.dituhui.pea.dispatch.common.GeoDistanceCalculator;
import com.dituhui.pea.dispatch.constraint.DispatchConstraintProvider; import com.dituhui.pea.dispatch.constraint.DispatchConstraintProvider;
import com.dituhui.pea.dispatch.dao.DispatchEngineerRepository; import com.dituhui.pea.dispatch.dao.DispatchEngineerRepository;
import com.dituhui.pea.dispatch.dao.DispatchOrderRepository; import com.dituhui.pea.dispatch.dao.DispatchOrderRepository;
import com.dituhui.pea.dispatch.dao.OrderLogRepository;
import com.dituhui.pea.dispatch.dao.OrgGroupRepository; import com.dituhui.pea.dispatch.dao.OrgGroupRepository;
import com.dituhui.pea.dispatch.entity.DispatchOrder; import com.dituhui.pea.dispatch.entity.DispatchOrder;
import com.dituhui.pea.dispatch.entity.OrderLog;
import com.dituhui.pea.dispatch.entity.OrgGroup; import com.dituhui.pea.dispatch.entity.OrgGroup;
import com.dituhui.pea.dispatch.pojo.*; import com.dituhui.pea.dispatch.pojo.*;
import com.dituhui.pea.dispatch.service.ExtractService; import com.dituhui.pea.dispatch.service.ExtractService;
...@@ -59,9 +61,12 @@ public class SolveServiceImpl implements SolveService { ...@@ -59,9 +61,12 @@ public class SolveServiceImpl implements SolveService {
@Autowired @Autowired
OrgGroupRepository groupRepository; OrgGroupRepository groupRepository;
@Autowired @Autowired
private EntityManager entityManager; private EntityManager entityManager;
@Autowired @Autowired
ExtractService extractService; ExtractService extractService;
......
...@@ -40,7 +40,7 @@ class SolveServiceTest { ...@@ -40,7 +40,7 @@ class SolveServiceTest {
ExtractService extractService; ExtractService extractService;
String groupId = "gsuzhou"; String groupId = "gsuzhou";
String day = "2023-03-20"; String day = "2023-07-11";
private SolverManager<DispatchSolution, UUID> solverManager; private SolverManager<DispatchSolution, UUID> solverManager;
...@@ -76,7 +76,7 @@ class SolveServiceTest { ...@@ -76,7 +76,7 @@ class SolveServiceTest {
DispatchSolution solution = solver.solve(problem); DispatchSolution solution = solver.solve(problem);
solveService.saveSolutionWrp(solution); solveService.saveSolutionWrp(solution);
extractService.extractDispatchToOrder(groupId, batchNo, false); extractService.extractDispatchToOrder(groupId, batchNo, true);
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!