Commit 730790c9 by 丁伟峰

Merge remote-tracking branch 'origin/develop' into develop

2 parents 87f053c0 daa7b2b1
Showing with 356 additions and 362 deletions
...@@ -10,13 +10,14 @@ import java.util.Optional; ...@@ -10,13 +10,14 @@ import java.util.Optional;
public interface DispatchOrderRepository extends CrudRepository<DispatchOrder, Long> { public interface DispatchOrderRepository extends CrudRepository<DispatchOrder, Long> {
// 查看未指派非confirm的,供算法计算
@Query("from DispatchOrder where groupId=?1 and batchNo=?2 and status !='CONFIRM' and (engineerCode is null or engineerCode='' ) ") @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); List<DispatchOrder> findNotAssigned(String groupId, String batchNo);
// 查看算法指派成功且非confirm状态的 // 查看算法指派成功且非confirm状态的
@Query("from DispatchOrder where groupId=?1 and batchNo=?2 and status !='CONFIRM' and engineerCode is not null and engineerCode!='' ") @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> findByGroupIdAndBatchNoAndOrderIdAndDt(String groupId, String batchNo, String orderId, String dt);
} }
\ No newline at end of file
package com.dituhui.pea.dispatch.dao;
import com.dituhui.pea.dispatch.entity.OrderAppointment;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import java.util.Optional;
public interface OrderAppointmentRepository extends CrudRepository<OrderAppointment, Long> {
@Query(value = "SELECT * FROM order_appointment WHERE order_id=:orderId ORDER BY id DESC LIMIT 1", nativeQuery = true)
Optional<OrderAppointment> findByOrderId(String orderId);
}
package com.dituhui.pea.dispatch.dao;
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;
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> findOrderInfoByOrderIdAndDt(String orderId, LocalDate dt);
}
package com.dituhui.pea.dispatch.dao;
import com.dituhui.pea.dispatch.entity.OrderRequest;
import org.springframework.data.repository.CrudRepository;
import java.util.Optional;
public interface OrderRequestRepository extends CrudRepository<OrderRequest, Long> {
Optional<OrderRequest> findByOrderId(String orderId);
}
...@@ -30,9 +30,15 @@ public class DispatchOrder implements Serializable { ...@@ -30,9 +30,15 @@ public class DispatchOrder implements Serializable {
@Column(name = "batch_no") @Column(name = "batch_no")
private String batchNo; private String batchNo;
@Column(name = "team_id")
private String teamId;
@Column(name = "order_id") @Column(name = "order_id")
private String orderId; private String orderId;
@Column(name = "dt")
private String dt;
@Column(name = "x") @Column(name = "x")
private String X; private String X;
...@@ -73,6 +79,14 @@ public class DispatchOrder implements Serializable { ...@@ -73,6 +79,14 @@ public class DispatchOrder implements Serializable {
@Column(name = "time_end") @Column(name = "time_end")
private LocalDateTime timeEnd; private LocalDateTime timeEnd;
//到达耗时(分钟)
@Column(name = "path_time")
private Integer pathTime;
//到达距离(米)
@Column(name = "path_distance")
private Integer pathDistance;
private String status; private String status;
private String ext; private String ext;
......
...@@ -45,11 +45,6 @@ public class EngineerInfo implements Serializable { ...@@ -45,11 +45,6 @@ public class EngineerInfo implements Serializable {
private String credentials; private String credentials;
private Integer vehicle;
@Column(name = "vehicle_no")
private String vehicleNo;
@Column(name = "bean_status") @Column(name = "bean_status")
private Integer beanStatus; private Integer beanStatus;
......
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
@Entity
@Table(name = "order_appointment")
public class OrderAppointment implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
@Column(name = "order_id")
private String orderId;
@Column(name = "suborder_id")
private String suborderId;
@Column(name = "main_sub")
private Integer mainSub;
@Column(name = "engineer_code")
private String engineerCode;
@Column(name = "engineer_name")
private String engineerName;
@Column(name = "engineer_phone")
private String engineerPhone;
@Column(name = "engineer_age")
private Integer engineerAge;
@Column(name = "is_workshop")
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")
@Column(name = "expect_start_time")
private LocalDateTime expectStartTime;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "expect_end_time")
private LocalDateTime expectEndTime;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "actual_time")
private LocalDateTime actualTime;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "actual_start_time")
private LocalDateTime actualStartTime;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "actual_end_time")
private LocalDateTime actualEndTime;
@Column(name = "pre_status")
private String preStatus;
private String status;
private String memo;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "create_time")
private LocalDateTime createTime;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "update_time")
private LocalDateTime updateTime;
}
package com.dituhui.pea.dispatch.entity; package com.dituhui.pea.dispatch.entity;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
...@@ -17,20 +18,34 @@ import java.time.LocalDateTime; ...@@ -17,20 +18,34 @@ import java.time.LocalDateTime;
@Data @Data
@Entity @Entity
@Table(name = "order_request") @Table(name = "order_info")
public class OrderRequest implements Serializable { public class OrderInfo implements Serializable {
@Id @Id
@GeneratedValue(strategy=GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private String id; private Integer id;
@Column(name = "order_id") @Column(name = "order_id")
private String orderId; private String orderId;
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate dt;
@Column(name = "sub_id")
private String subId;
private String name; private String name;
private String phone; private String phone;
private String province;
private String city;
private String county;
private String address; private String address;
@Column(name = "x") @Column(name = "x")
...@@ -39,11 +54,8 @@ public class OrderRequest implements Serializable { ...@@ -39,11 +54,8 @@ public class OrderRequest implements Serializable {
@Column(name = "y") @Column(name = "y")
private String Y; private String Y;
private String province; @Column(name = "bean_brand")
private String beanBrand;
private String city;
private String county;
private String brand; private String brand;
...@@ -51,19 +63,17 @@ public class OrderRequest implements Serializable { ...@@ -51,19 +63,17 @@ public class OrderRequest implements Serializable {
private String skill; private String skill;
@Column(name = "apply_note") @Column(name = "take_time")
private String applyNote; private Integer takeTime;
@Column(name = "is_workshop")
private Integer isWorkshop;
@Column(name = "fault_describe") @Column(name = "fault_describe")
private String faultDescribe; private String faultDescribe;
@Column(name = "apply_note")
@JsonDeserialize(using = LocalDateDeserializer.class) private String applyNote;
@JsonSerialize(using = LocalDateSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@Column(name = "dt")
private LocalDate dt;
@JsonDeserialize(using = LocalDateTimeDeserializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class) @JsonSerialize(using = LocalDateTimeSerializer.class)
...@@ -82,53 +92,96 @@ public class OrderRequest implements Serializable { ...@@ -82,53 +92,96 @@ public class OrderRequest implements Serializable {
private String source; private String source;
@Column(name = "bean_priority")
private String beanPriority;
@Column(name = "bean_tags")
private String beanTags;
@Column(name = "bean_status")
private String beanStatus;
@Column(name = "bean_sub_status")
private String beanSubStatus;
@Column(name = "area_id") @Column(name = "area_id")
private String areaId; private String areaId;
@Column(name = "order_priority") @Column(name = "org_cluster_id")
private String orderPriority; private String orgClusterId;
@Column(name = "order_tags") @Column(name = "org_branch_id")
private String orderTags; private String orgBranchId;
@Column(name = "org_group_id")
private String orgGroupId;
@Column(name = "org_team_id")
private String orgTeamId;
private Integer priority; private Integer priority;
private String tags; private String tags;
private String status; @Column(name = "appointment_method")
private String appointmentMethod;
@Column(name = "appointment_status") @Column(name = "appointment_status")
private String appointmentStatus; private String appointmentStatus;
@Column(name = "appointment_method") @Column(name = "order_status")
private String appointmentMethod; private String orderStatus;
@Column(name = "org_cluster_id") @Column(name = "service_status")
private String orgClusterId; private String serviceStatus;
@Column(name = "org_cluster_name") @Column(name = "engineer_code")
private String orgClusterName; private String engineerCode;
@Column(name = "org_branch_id") @Column(name = "engineer_name")
private String orgBranchId; private String engineerName;
@Column(name = "org_branch_name") @Column(name = "engineer_phone")
private String orgBranchName; private String engineerPhone;
@Column(name = "org_group_id") @Column(name = "engineer_code_sub")
private String orgGroupId; private String engineerCodeSub;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "plan_start_time")
private LocalDateTime planStartTime;
@Column(name = "org_group_name") @JsonDeserialize(using = LocalDateTimeDeserializer.class)
private String orgGroupName; @JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "plan_end_time")
private LocalDateTime planEndTime;
@Column(name = "org_team_id") @Column(name = "arrive_elapsed")
private String orgTeamId; private Integer arriveElapsed;
@Column(name = "org_team_name") @Column(name = "arrive_distance")
private String orgTeamName; private Integer arriveDistance;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "actual_start_time")
private LocalDateTime actualStartTime;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "actual_end_time")
private LocalDateTime actualEndTime;
private String description; private String description;
@Column(name = "extra_info")
private String extraInfo;
@JsonDeserialize(using = LocalDateTimeDeserializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class) @JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
......
...@@ -21,6 +21,8 @@ public class Customer { ...@@ -21,6 +21,8 @@ public class Customer {
private long id; private long id;
private String code; private String code;
// orderid(code)+dt 确定唯一一条工单
private String dt;
@JsonIgnore @JsonIgnore
private Location location; private Location location;
// 时间窗 分钟 // 时间窗 分钟
...@@ -45,10 +47,11 @@ public class Customer { ...@@ -45,10 +47,11 @@ public class Customer {
public 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) { int serviceDuration) {
this.id = id; this.id = id;
this.code = code; this.code = code;
this.dt = dt;
this.location = location; this.location = location;
this.startTime = startTime; this.startTime = startTime;
this.endTime = endTime; this.endTime = endTime;
...@@ -116,7 +119,7 @@ public class Customer { ...@@ -116,7 +119,7 @@ public class Customer {
} }
/** /**
* 与前一个订单或者出发地depot的距离 * 与前一个订单或者出发地depot的距离(米)
* *
* @return * @return
*/ */
...@@ -132,7 +135,7 @@ public class Customer { ...@@ -132,7 +135,7 @@ public class Customer {
} }
/** /**
* 与前一个订单或者出发地depot的路程时间 * 与前一个订单或者出发地depot的路程时间(分钟)
* *
* @return * @return
*/ */
...@@ -168,16 +171,17 @@ public class Customer { ...@@ -168,16 +171,17 @@ public class Customer {
return "Customer{" + return "Customer{" +
"id=" + id + "id=" + id +
", code='" + code + '\'' + ", code='" + code + '\'' +
", dt='" + dt + '\'' +
", location=" + location + ", location=" + location +
", startTime=" + startTime + ", startTime=" + startTime +
", endTime=" + endTime + ", endTime=" + endTime +
", serviceDuration=" + serviceDuration + ", serviceDuration=" + serviceDuration +
", requiredSkill='" + requiredSkill + '\'' + ", requiredSkill='" + requiredSkill + '\'' +
", technician=" + ((technician!=null) ? technician.getCode() : "null") + ", technician=" + ((technician != null) ? technician.getCode() : "null") +
", previousCustomer=" + ((previousCustomer != null) ? previousCustomer.getCode() : "null") + ", previousCustomer=" + ((previousCustomer != null) ? previousCustomer.getCode() : "null") +
", nextCustomer=" + ((nextCustomer != null) ? nextCustomer.getCode() : "null") + ", nextCustomer=" + ((nextCustomer != null) ? nextCustomer.getCode() : "null") +
", arrivalTime=" + arrivalTime + ", arrivalTime=" + arrivalTime +
", departureTime=" + ((getDepartureTime() != null )? getDepartureTime() : 0) + ", departureTime=" + ((getDepartureTime() != null) ? getDepartureTime() : 0) +
'}'; '}';
} }
} }
...@@ -38,7 +38,7 @@ public class BatchScheduler { ...@@ -38,7 +38,7 @@ public class BatchScheduler {
@Value("${dispatch.cron.next-day-limit}") @Value("${dispatch.cron.next-day-limit}")
int nextDaysLimit = 3; int nextDaysLimit = 2;
@Autowired @Autowired
BatchService batchService; BatchService batchService;
...@@ -75,10 +75,11 @@ public class BatchScheduler { ...@@ -75,10 +75,11 @@ public class BatchScheduler {
log.info("dispatchRun begin----- group:{}, day:{}", groupId, currDay); log.info("dispatchRun begin----- group:{}, day:{}", groupId, currDay);
LocalTime currentTime = LocalTime.now(); LocalTime currentTime = LocalTime.now();
LocalTime cutoffTime = LocalTime.parse("16:00:00", DateTimeFormatter.ISO_LOCAL_TIME); LocalTime cutoffTime = LocalTime.parse("18:00:00", DateTimeFormatter.ISO_LOCAL_TIME);
// 明天单才有cutoff // 明天单才有cutoff
if (i == 1 && currentTime.isAfter(cutoffTime)) {
/*if (i == 1 && currentTime.isAfter(cutoffTime)) {
log.info("dispatchRun 已过cutoff时间,更新pre状态为confirm----- group:{}, day:{}", groupId, currDay); log.info("dispatchRun 已过cutoff时间,更新pre状态为confirm----- group:{}, day:{}", groupId, currDay);
DispatchBatch dispatchBatch = batchService.queryBatchInfoByDay(groupId, currDay); DispatchBatch dispatchBatch = batchService.queryBatchInfoByDay(groupId, currDay);
if (null == dispatchBatch.getBatchNo()) { if (null == dispatchBatch.getBatchNo()) {
...@@ -97,6 +98,7 @@ public class BatchScheduler { ...@@ -97,6 +98,7 @@ public class BatchScheduler {
} }
continue; continue;
} }
*/
String batchNo = batchService.buildBatchData(groupId, currDay); String batchNo = batchService.buildBatchData(groupId, currDay);
UUID problemId = solveService.generateProblemId(groupId, batchNo); UUID problemId = solveService.generateProblemId(groupId, batchNo);
......
...@@ -11,7 +11,7 @@ import java.sql.SQLException; ...@@ -11,7 +11,7 @@ import java.sql.SQLException;
* @author zhangx * @author zhangx
* <p> * <p>
* 排班算法数据准备 * 排班算法数据准备
* 排班结果解析到dispatch_order(更新补充技术员工号、上门时间) ,order_appointment、order_request * 排班结果解析到dispatch_order(更新补充技术员工号、上门时间) ,order_info
*/ */
public interface ExtractService { public interface ExtractService {
...@@ -19,9 +19,7 @@ public interface ExtractService { ...@@ -19,9 +19,7 @@ public interface ExtractService {
/* /*
* 将dispath_order 中的计算结果,回写到 order_request, order_appointment * 将dispath_order 中的计算结果,回写到 order_info
* order_appointment(新增、更新)
* order_request(主要更新状态)
* */ * */
void extractDispatchToOrder(String groupId, String batchNo, boolean isConfirm) ; void extractDispatchToOrder(String groupId, String batchNo, boolean isConfirm) ;
......
...@@ -101,54 +101,39 @@ public class BatchServiceImpl implements BatchService { ...@@ -101,54 +101,39 @@ public class BatchServiceImpl implements BatchService {
" order by a.engineer_code asc"; " order by a.engineer_code asc";
int engCount = jdbcTemplate.update(sqlEngineer, batchNo, groupId); int engCount = jdbcTemplate.update(sqlEngineer, batchNo, groupId);
// 未派过的工单(虚拟指派不更改order_request.appointment_status,所以也包含在当前条件中) // 未派过的工单(已派过PRE状态还可以再次派)
String sqlOrder = "INSERT INTO dispatch_order (group_id, batch_no, order_id , x, y, expect_time_begin, expect_time_end, tags, priority , skills , take_time )\n" + String sqlOrder = "INSERT INTO dispatch_order (group_id, batch_no, team_id, order_id , dt, x, y, \n" +
" select a.org_group_id, ? , a.order_id, a.x, a.y , \n" + " expect_time_begin, expect_time_end, tags, priority , skills , take_time, status )\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" + " select a.org_group_id, ?, a.org_team_id , a.order_id, a.dt, a.x, a.y , \n" +
" 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" + " a.expect_time_begin, a.expect_time_end, a.tags, a.priority , \n" +
" where a.org_group_id=? and a.status='OPEN' " + " concat(a.brand, '-', a.type, '-', a.skill) skills , a.take_time , a.appointment_status\n" +
" and a.dt = ? " + " from order_info a \n" +
" and a.appointment_status ='NOT_ASSIGNED' and a.appointment_method like 'AUTO%' \n" + " where a.org_group_id=? and a.dt = ? and bean_status='OPEN'\n" +
" and appointment_method like 'AUTO%' and a.appointment_status in ('INIT','VIRTUAL', 'PRE')\n" +
" and order_status ='NORMAL' and service_status='INIT'\n" +
" order by a.expect_time_begin asc "; " order by a.expect_time_begin asc ";
int orderCount = jdbcTemplate.update(sqlOrder, batchNo, groupId, batchDay); int orderCount = jdbcTemplate.update(sqlOrder, batchNo, groupId, batchDay);
// 已派过PRE状态还可以再次派 // confirm的要做预占用,所以也加入进来
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" + String sqlOrderConfirm = "INSERT INTO dispatch_order (group_id, batch_no, team_id, order_id , dt, x, y, \n" +
" select a.org_group_id, ?, a.order_id, a.x, a.y , \n" + " expect_time_begin, expect_time_end, tags, priority , skills , take_time, status, engineer_code, time_begin, time_end )\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" + " select a.org_group_id, ?, a.org_team_id , a.order_id, a.dt, a.x, a.y , \n" +
" from order_request a " + " a.expect_time_begin, a.expect_time_end, a.tags, a.priority , \n" +
" left join skill_info b on (a.brand=b.brand and a.type=b.type and a.skill=b.skill )\n" + " concat(a.brand, '-', a.type, '-', a.skill) skills , a.take_time, a.appointment_status, \n" +
" left join order_appointment o on (a.order_id =o.order_id)\n" + " a.engineer_code, a.plan_start_time, a.plan_end_time \n" +
" where a.org_group_id=? and a.status='OPEN' \n" + " from order_info a \n" +
" and a.dt = ? " + " where a.org_group_id=? and a.dt = ? and bean_status='OPEN'\n" +
" and a.appointment_status = 'ASSIGNED' and a.appointment_method like 'AUTO%' \n" + " and appointment_method like 'AUTO%' and a.appointment_status in ('CONFIRM')\n" +
" and o.pre_status in ('PRE') \n" + " and order_status ='NORMAL' and service_status='INIT'\n" +
" order by a.expect_time_begin asc "; " order by a.expect_time_begin asc ";
int orderCountPre = jdbcTemplate.update(sqlOrderPre, batchNo, groupId, batchDay); int orderConfirmCount = jdbcTemplate.update(sqlOrderConfirm, 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:{}, orderConfirmCount:{}", orderCount, orderConfirmCount);
log.info("准备批次数据 orderCountPre :{}", orderCountPre);
// log.info("准备批次数据 orderCountConfirm :{}", orderCountConfirm);
if (orderCount + orderCountPre > 0) { if (orderCount + orderConfirmCount > 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 + orderConfirmCount, 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, 0, LocalDateTime.now(), LocalDateTime.now(), groupId, batchNo); engCount, 0, LocalDateTime.now(), LocalDateTime.now(), groupId, batchNo);
......
...@@ -264,7 +264,7 @@ public class DataUtils { ...@@ -264,7 +264,7 @@ public class DataUtils {
// 初始化订单+技能服务时间 // 初始化订单+技能服务时间
List<Customer> customerList = new ArrayList<>(); List<Customer> customerList = new ArrayList<>();
for (int i = 0; i < customerIndexMap.keySet().size(); i++) { 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), customerStartMap.get(i + 1), customerEndMap.get(i + 1), customerSkillMap.get(i + 1),
// 初始化技能服务时间 // 初始化技能服务时间
customerCodeServiceTimeMap.get(customerIndexMap.get(i + 1)))); customerCodeServiceTimeMap.get(customerIndexMap.get(i + 1))));
......
...@@ -44,6 +44,7 @@ class SolveServiceTest { ...@@ -44,6 +44,7 @@ class SolveServiceTest {
String groupId = "gsuzhou"; String groupId = "gsuzhou";
String day = "2023-07-25"; String day = "2023-07-25";
private SolverManager<DispatchSolution, UUID> solverManager; private SolverManager<DispatchSolution, UUID> solverManager;
private SolverFactory<DispatchSolution> solverFactory; private SolverFactory<DispatchSolution> solverFactory;
private Solver<DispatchSolution> solver; private Solver<DispatchSolution> solver;
...@@ -55,6 +56,7 @@ class SolveServiceTest { ...@@ -55,6 +56,7 @@ class SolveServiceTest {
solverConfig.withConstraintProviderClass(DispatchConstraintProvider.class); solverConfig.withConstraintProviderClass(DispatchConstraintProvider.class);
solverConfig.withTerminationSpentLimit(Duration.ofSeconds(20)); solverConfig.withTerminationSpentLimit(Duration.ofSeconds(20));
solverFactory = SolverFactory.create(solverConfig); solverFactory = SolverFactory.create(solverConfig);
solver = solverFactory.buildSolver(); solver = solverFactory.buildSolver();
solverManager = SolverManager.create(solverConfig, new SolverManagerConfig()); solverManager = SolverManager.create(solverConfig, new SolverManagerConfig());
...@@ -81,7 +83,17 @@ class SolveServiceTest { ...@@ -81,7 +83,17 @@ class SolveServiceTest {
solveService.saveSolutionWrp(solution); solveService.saveSolutionWrp(solution);
extractService.extractDispatchToOrder(groupId, batchNo, false); extractService.extractDispatchToOrder(groupId, batchNo, false);
log.info("testAsync done"); 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");
}
} }
...@@ -50,7 +50,7 @@ public class DispatchController { ...@@ -50,7 +50,7 @@ public class DispatchController {
// 派工台确认派单 // 派工台确认派单
Result<?> res = null; Result<?> res = null;
try { try {
res = dispatchService.dispatchOrderConfirm(req.getEngineerCode(), req.getOrderIds()); res = dispatchService.dispatchOrderConfirm(req.getEngineerCode(), req.getDate(), req.getOrderIds());
}catch (BusinessException e){ }catch (BusinessException e){
return Result.failed(e.getMessage()); return Result.failed(e.getMessage());
} }
......
package com.dituhui.pea.order.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dituhui.pea.order.entity.OrderInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.time.LocalDate;
import java.util.List;
@Mapper
public interface OrderInfoMPDao extends BaseMapper<OrderInfo> {
@Select("select * from order_info where order_id=#{orderId} order by dt desc")
OrderInfo getByOrderId(String orderId);
@Select("select * from order_info where order_id=#{orderId} and dt=#{dt}")
OrderInfo getByOrderIdAndDt(String orderId, LocalDate dt);
@Select("select * from order_info where order_id=#{orderId}")
List<OrderInfo> selectByOrderId(String orderId);
@Select("<script> select * from order_request where dt=#{dt} and order_id in " +
"<foreach item='orderId' index='index' collection='orderIds' open='(' separator=',' close=')'>#{orderId}</foreach></script>")
List<OrderInfo> selectByDtAndOrderIds(@Param("dt") LocalDate dt, @Param("orderIds") List<String> orderIds);
@Select("select * from order_info where dt=#{dt} and engineerCode=#{engineerCode}")
List<OrderInfo> selectByEngineerCodeAndDt(String engineerCode, LocalDate dt);
@Select("select * from order_info where dt=#{dt} and engineerCode=#{engineerCode} and appointment_status=#{appointmentStatus}")
List<OrderInfo> selectByEngineerCodeAndDtAndAppointmentStatus(String engineerCode, LocalDate dt, String appointmentStatus);
}
...@@ -7,5 +7,6 @@ import java.util.List; ...@@ -7,5 +7,6 @@ import java.util.List;
@Data @Data
public class DispatchOrderConfirmReqDTO { public class DispatchOrderConfirmReqDTO {
private String engineerCode; private String engineerCode;
private String date;
private List<String> orderIds; private List<String> orderIds;
} }
package com.dituhui.pea.order.entity;
import lombok.Data;
import java.sql.Timestamp;
import java.time.LocalDate;
@Data
public class OrderInfo {
private Long id;
private String orderId;
private LocalDate dt;
private String subId;
private String name;
private String phone;
private String address;
private String x;
private String y;
private String province;
private String city;
private String county;
private String brand;
private String type;
private String skill;
private String applyNote;
private String faultDescribe;
private Timestamp expectTimeBegin;
private Timestamp expectTimeEnd;
private String expectTimeDesc;
private String source;
private String beanPriority;
private String beanTags;
private String beanStatus;
private String beanSubStatus;
private String areaId;
private String orgClusterId;
private String orgBranchId;
private String orgGroupId;
private String orgTeamId;
private Integer priority;
private String tags;
private String appointmentStatus;
private String appointmentMethod;
private String orderStatus;
private String serviceStatus;
private String engineerCode;
private String engineerName;
private String engineerPhone;
private String engineerCodeSub;
private Timestamp planStartTime;
private Timestamp planEndTime;
private Integer arriveElapsed;
private Integer arriveDistance;
private Timestamp actualStartTime;
private Timestamp actualEndTime;
private String description;
private Timestamp createTime;
private Timestamp updateTime;
}
\ No newline at end of file
...@@ -12,5 +12,5 @@ public interface DispatchService { ...@@ -12,5 +12,5 @@ public interface DispatchService {
Result<?> getDispatchEngineerOrderList(DispatchEngineerOrderListReq reqDTO); Result<?> getDispatchEngineerOrderList(DispatchEngineerOrderListReq reqDTO);
Result<?> dispatchOrderConfirm(String engineerCode, List<String> orderIds); Result<?> dispatchOrderConfirm(String engineerCode, String date, List<String> orderIds);
} }
...@@ -30,10 +30,7 @@ import java.util.stream.Collectors; ...@@ -30,10 +30,7 @@ import java.util.stream.Collectors;
public class OrderAssignImpl implements OrderAssign { public class OrderAssignImpl implements OrderAssign {
@Autowired @Autowired
private OrderRequestMPDao orderRequestMPDao; private OrderInfoMPDao orderInfoMPDao;
@Autowired
private OrderAppointmentMPDao orderAppointmentMPDao;
@Autowired @Autowired
private EngineerInfoMPDao engineerInfoMPDao; private EngineerInfoMPDao engineerInfoMPDao;
...@@ -63,7 +60,7 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -63,7 +60,7 @@ public class OrderAssignImpl implements OrderAssign {
@Override @Override
public Result<?> getOrderAssignRecommendEngineers(String orderId, String key, String distance, String recommend) { public Result<?> getOrderAssignRecommendEngineers(String orderId, String key, String distance, String recommend) {
// 服务单指派-推荐技术员列表 // 服务单指派-推荐技术员列表
OrderRequest order = orderRequestMPDao.getByOrderId(orderId); OrderInfo order = orderInfoMPDao.getByOrderId(orderId);
if (order == null) { if (order == null) {
throw new BusinessException("订单不存在"); throw new BusinessException("订单不存在");
} }
...@@ -84,13 +81,13 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -84,13 +81,13 @@ public class OrderAssignImpl implements OrderAssign {
} }
// 获取已技术员已指派订单列表 // 获取已技术员已指派订单列表
List<OrderAppointment> orderAppointments = orderAppointmentMPDao.selectByEngineerCodeAndDt(engineer.getEngineerCode(), order.getDt()); List<OrderInfo> orderAppointments = orderInfoMPDao.selectByEngineerCodeAndDtAndAppointmentStatus(engineer.getEngineerCode(), order.getDt(), "CONFIRM");
// 获取订单tips // 获取订单tips
HashMap<String, List<LabelValueDTO>> orderTips = new HashMap<>(); HashMap<String, List<LabelValueDTO>> orderTips = new HashMap<>();
List<String> orderIds = orderAppointments.stream().map(OrderAppointment::getOrderId).collect(Collectors.toList()); List<String> orderIds = orderAppointments.stream().map(OrderInfo::getOrderId).collect(Collectors.toList());
if (!orderIds.isEmpty()) { if (!orderIds.isEmpty()) {
List<OrderRequest> orders = orderRequestMPDao.selectByOrderIds(orderIds); List<OrderInfo> orders = orderInfoMPDao.selectByDtAndOrderIds(TimeUtils.IsoDate2LocalDate(date), orderIds);
orderTips = this.packOrderTips(orders); orderTips = this.packOrderTips(orders);
} }
...@@ -126,7 +123,8 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -126,7 +123,8 @@ public class OrderAssignImpl implements OrderAssign {
@Override @Override
public Result<?> orderAssign(String orderId, String engineerCode) throws BusinessException { public Result<?> orderAssign(String orderId, String engineerCode) throws BusinessException {
// 服务单指派-指派提交 // 服务单指派-指派提交
OrderRequest order = orderRequestMPDao.getByOrderId(orderId);
OrderInfo order = orderInfoMPDao.getByOrderId(orderId);
if (order == null) { if (order == null) {
throw new BusinessException("订单不存在"); throw new BusinessException("订单不存在");
} }
...@@ -134,7 +132,7 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -134,7 +132,7 @@ public class OrderAssignImpl implements OrderAssign {
EngineerInfo engineer = engineerInfoMPDao.getByEngineerCode(engineerCode); EngineerInfo engineer = engineerInfoMPDao.getByEngineerCode(engineerCode);
boolean record = false; boolean record = false;
OrderAppointment op = orderAppointmentMPDao.getByOrderIdAndDt(orderId, order.getDt()); OrderInfo op = orderInfoMPDao.getByOrderIdAndDt(orderId, order.getDt());
if (op != null) { if (op != null) {
record = true; record = true;
} }
...@@ -148,39 +146,17 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -148,39 +146,17 @@ public class OrderAssignImpl implements OrderAssign {
if (!result.getCanAssign()) { if (!result.getCanAssign()) {
throw new BusinessException("指派失败, 未能找到合适的时间段, 请选择其他技术员"); throw new BusinessException("指派失败, 未能找到合适的时间段, 请选择其他技术员");
} }
Timestamp expectStartTime = Timestamp.valueOf(result.getStart()); Timestamp planStartTime = Timestamp.valueOf(result.getStart());
Timestamp expectEndTime = Timestamp.valueOf(result.getEnd()); Timestamp planEndTime = Timestamp.valueOf(result.getEnd());
// 更新或插入指派单
if (!record) {
op = new OrderAppointment();
}
op.setOrderId(orderId);
op.setSuborderId(Long.toString(System.currentTimeMillis()));
op.setMainSub(1);
op.setEngineerCode(engineerCode);
op.setEngineerName(engineer.getName());
op.setEngineerAge(0);
op.setEngineerPhone(engineer.getPhone());
op.setIsWorkshop(0);
op.setDt(order.getDt());
op.setExpectStartTime(expectStartTime);
op.setExpectEndTime(expectEndTime);
op.setPreStatus("CONFIRM");
op.setStatus("ASSIGNED");
if (!record) {
orderAppointmentMPDao.insert(op);
} else {
orderAppointmentMPDao.updateById(op);
}
// 更新order_request表状态 // 更新order_request表状态
LambdaUpdateWrapper<OrderRequest> wrapper = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<OrderInfo> wrapper = new LambdaUpdateWrapper<>();
wrapper.set(OrderRequest::getAppointmentStatus, "ASSIGNED"); wrapper.set(OrderInfo::getAppointmentStatus, "CONFIRM");
wrapper.set(OrderRequest::getAppointmentMethod, "MANUAL"); wrapper.set(OrderInfo::getAppointmentMethod, "MANUAL");
wrapper.eq(OrderRequest::getOrderId, orderId); wrapper.set(OrderInfo::getPlanStartTime, planStartTime);
orderRequestMPDao.update(null, wrapper); wrapper.set(OrderInfo::getPlanEndTime, planEndTime);
wrapper.eq(OrderInfo::getOrderId, orderId);
orderInfoMPDao.update(null, wrapper);
// 工单变更登记 // 工单变更登记
commonService.addOrderEvent(orderId, "", "PEA-WEB", "API", "工单指派", "工单指派", ""); commonService.addOrderEvent(orderId, "", "PEA-WEB", "API", "工单指派", "工单指派", "");
...@@ -190,20 +166,16 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -190,20 +166,16 @@ public class OrderAssignImpl implements OrderAssign {
@Override @Override
public Result<?> orderRevokeAssign(String orderId) throws BusinessException { public Result<?> orderRevokeAssign(String orderId) throws BusinessException {
OrderRequest order = orderRequestMPDao.getByOrderId(orderId); // 放回工单池
OrderInfo order = orderInfoMPDao.getByOrderId(orderId);
if (order == null) { if (order == null) {
throw new BusinessException("订单不存在"); throw new BusinessException("订单不存在");
} }
// 更新order_request表为未指派 // 更新order_request表为未指派
order.setAppointmentStatus("NOT_ASSIGNED"); order.setAppointmentStatus("INIT");
orderRequestMPDao.updateById(order); orderInfoMPDao.updateById(order);
// 更新order_appointment表为未指派
LambdaUpdateWrapper<OrderAppointment> appWrapper = new LambdaUpdateWrapper<>();
appWrapper.set(OrderAppointment::getStatus, "NOT_ASSIGNED")
.eq(OrderAppointment::getOrderId, orderId).eq(OrderAppointment::getDt, order.getDt());
orderAppointmentMPDao.update(null, appWrapper);
// 登记事件 // 登记事件
OrderEvent oe = new OrderEvent(); OrderEvent oe = new OrderEvent();
...@@ -225,7 +197,8 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -225,7 +197,8 @@ public class OrderAssignImpl implements OrderAssign {
@Override @Override
public Result<?> orderReschedule(String orderId, LocalDateTime expectBegin, LocalDateTime expectEnd, String expectDesc) throws BusinessException { public Result<?> orderReschedule(String orderId, LocalDateTime expectBegin, LocalDateTime expectEnd, String expectDesc) throws BusinessException {
// 工单改约接口(当前同放回工单池处理) // 工单改约接口(当前同放回工单池处理)
OrderRequest order = orderRequestMPDao.getByOrderId(orderId);
OrderInfo order = orderInfoMPDao.getByOrderId(orderId);
if (order == null) { if (order == null) {
throw new BusinessException("订单不存在"); throw new BusinessException("订单不存在");
} }
...@@ -239,18 +212,12 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -239,18 +212,12 @@ public class OrderAssignImpl implements OrderAssign {
LocalDate originDate = order.getDt(); // 改约前的日期 LocalDate originDate = order.getDt(); // 改约前的日期
// 更新order_request表为未指派 // 更新order_request表为未指派
order.setAppointmentStatus("NOT_ASSIGNED"); order.setAppointmentStatus("INIT");
order.setDt(expectBegin.toLocalDate()); order.setDt(expectBegin.toLocalDate());
order.setExpectTimeBegin(Timestamp.valueOf(expectBegin)); order.setExpectTimeBegin(Timestamp.valueOf(expectBegin));
order.setExpectTimeEnd(Timestamp.valueOf(expectEnd)); order.setExpectTimeEnd(Timestamp.valueOf(expectEnd));
order.setExpectTimeDesc(expectDesc); order.setExpectTimeDesc(expectDesc);
orderRequestMPDao.updateById(order); orderInfoMPDao.updateById(order);
// 更新order_appointment表为未指派
LambdaUpdateWrapper<OrderAppointment> appWrapper = new LambdaUpdateWrapper<>();
appWrapper.set(OrderAppointment::getStatus, "RESCHEDULED")
.eq(OrderAppointment::getOrderId, orderId).eq(OrderAppointment::getDt, originDate);
orderAppointmentMPDao.update(null, appWrapper);
// 登记事件 // 登记事件
OrderEvent oe = new OrderEvent(); OrderEvent oe = new OrderEvent();
...@@ -269,7 +236,7 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -269,7 +236,7 @@ public class OrderAssignImpl implements OrderAssign {
return Result.success(null); return Result.success(null);
} }
private List<String> searchEngineerCodes(OrderRequest order, String distance, String key, String recommend) { private List<String> searchEngineerCodes(OrderInfo order, String distance, String key, String recommend) {
Set<String> engineerCodes1 = this.searchEngineerByRecommend(order, recommend); Set<String> engineerCodes1 = this.searchEngineerByRecommend(order, recommend);
if (engineerCodes1.isEmpty()) { if (engineerCodes1.isEmpty()) {
log.info("recommend:{}筛选条件未找到技术员", recommend); log.info("recommend:{}筛选条件未找到技术员", recommend);
...@@ -316,7 +283,7 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -316,7 +283,7 @@ public class OrderAssignImpl implements OrderAssign {
return new ArrayList<>(engineerCodes1); return new ArrayList<>(engineerCodes1);
} }
private Set<String> searchEngineerByRecommend(OrderRequest order, String recommend) { private Set<String> searchEngineerByRecommend(OrderInfo order, String recommend) {
if (StringUtils.isNotEmpty(recommend) && recommend.equals("team")) { if (StringUtils.isNotEmpty(recommend) && recommend.equals("team")) {
return orgTeamEngineerMPDao.selectByTeamId(order.getOrgTeamId()).stream().map(OrgTeamEngineer::getEngineerCode).collect(Collectors.toSet()); return orgTeamEngineerMPDao.selectByTeamId(order.getOrgTeamId()).stream().map(OrgTeamEngineer::getEngineerCode).collect(Collectors.toSet());
} }
...@@ -355,18 +322,17 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -355,18 +322,17 @@ public class OrderAssignImpl implements OrderAssign {
return engineerInfoMPDao.selectList(lqw).stream().map(EngineerInfo::getEngineerCode).collect(Collectors.toSet()); return engineerInfoMPDao.selectList(lqw).stream().map(EngineerInfo::getEngineerCode).collect(Collectors.toSet());
} }
private List<TimeLineDTO> packTimelines(List<OrderAppointment> orders, HashMap<String, List<LabelValueDTO>> orderTips) { private List<TimeLineDTO> packTimelines(List<OrderInfo> orders, HashMap<String, List<LabelValueDTO>> orderTips) {
List<LabelValueDTO> empty = new ArrayList<>(); List<LabelValueDTO> empty = new ArrayList<>();
List<TimeLineDTO> items = new ArrayList<>(); List<TimeLineDTO> items = new ArrayList<>();
for (OrderAppointment order : orders) { for (OrderInfo order : orders) {
TimeLineDTO item = new TimeLineDTO(); TimeLineDTO item = new TimeLineDTO();
item.setOrderId(order.getOrderId()); item.setOrderId(order.getOrderId());
item.setPreStatus(order.getPreStatus()); item.setAppointmentStatus(order.getAppointmentStatus());
item.setAppointmentStatus(order.getStatus()); item.setStartTime(TimeUtils.IsoTimestamp2DateTime(order.getPlanStartTime()));
item.setStartTime(TimeUtils.IsoTimestamp2DateTime(order.getExpectStartTime())); item.setEndTime(TimeUtils.IsoTimestamp2DateTime(order.getPlanEndTime()));
item.setEndTime(TimeUtils.IsoTimestamp2DateTime(order.getExpectEndTime()));
item.setTips(orderTips.getOrDefault(order.getOrderId(), empty)); item.setTips(orderTips.getOrDefault(order.getOrderId(), empty));
items.add(item); items.add(item);
...@@ -374,12 +340,12 @@ public class OrderAssignImpl implements OrderAssign { ...@@ -374,12 +340,12 @@ public class OrderAssignImpl implements OrderAssign {
return items; return items;
} }
private HashMap<String, List<LabelValueDTO>> packOrderTips(List<OrderRequest> orders) { private HashMap<String, List<LabelValueDTO>> packOrderTips(List<OrderInfo> orders) {
return orders.stream().collect(Collectors.toMap( return orders.stream().collect(Collectors.toMap(
OrderRequest::getOrderId, this::packOrderTip, (l1, l2) -> l1, HashMap::new)); OrderInfo::getOrderId, this::packOrderTip, (l1, l2) -> l1, HashMap::new));
} }
private List<LabelValueDTO> packOrderTip(OrderRequest order) { private List<LabelValueDTO> packOrderTip(OrderInfo order) {
// pack订单tips // pack订单tips
List<LabelValueDTO> items = new ArrayList<>(); List<LabelValueDTO> items = new ArrayList<>();
items.add(new LabelValueDTO("类型/品牌", String.format("%s %s %s", order.getSkill(), order.getType(), order.getBrand()))); items.add(new LabelValueDTO("类型/品牌", String.format("%s %s %s", order.getSkill(), order.getType(), order.getBrand())));
......
...@@ -22,10 +22,7 @@ import java.util.stream.Collectors; ...@@ -22,10 +22,7 @@ import java.util.stream.Collectors;
public class OrderServiceDetailImpl implements OrderServiceDetail { public class OrderServiceDetailImpl implements OrderServiceDetail {
@Autowired @Autowired
private OrderRequestMPDao orderRequestMPDao; private OrderInfoMPDao orderInfoMPDao;
@Autowired
private OrderAppointmentMPDao orderAppointmentMPDao;
@Autowired @Autowired
private EngineerInfoMPDao engineerInfoMPDao; private EngineerInfoMPDao engineerInfoMPDao;
...@@ -45,11 +42,12 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -45,11 +42,12 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
@Autowired @Autowired
private SkillInfoMPDao skillInfoMPDao; private SkillInfoMPDao skillInfoMPDao;
@Transactional @Transactional
@Override @Override
public Result<?> getOrderServiceDetail(String orderId) { public Result<?> getOrderServiceDetail(String orderId) {
OrderRequest order = orderRequestMPDao.getByOrderId(orderId); OrderInfo order = orderInfoMPDao.getByOrderId(orderId);
List<KV> items = this.packOrderDetail(order); List<KV> items = this.packOrderDetail(order);
...@@ -66,8 +64,8 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -66,8 +64,8 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
res.setOrderId(orderId); res.setOrderId(orderId);
res.setRisk(""); res.setRisk("");
res.setRiskDesc(""); res.setRiskDesc("");
res.setStatusDesc("打开"); res.setStatusDesc("正常");
res.setStatus(order.getStatus()); res.setStatus(order.getOrderStatus());
res.setAppointmentStatus(order.getAppointmentStatus()); res.setAppointmentStatus(order.getAppointmentStatus());
res.setLocation(String.format("%s,%s", order.getX(), order.getY())); res.setLocation(String.format("%s,%s", order.getX(), order.getY()));
res.setReschedulingParams(detail); res.setReschedulingParams(detail);
...@@ -94,52 +92,44 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -94,52 +92,44 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
@Transactional @Transactional
@Override @Override
public Result<?> getOrderAppointmentList(String orderId) throws BusinessException{ public Result<?> getOrderAppointmentList(String orderId) throws BusinessException {
// 获取预约单里列表 // 获取预约单里列表
OrderAppointmentListResp res = new OrderAppointmentListResp(); OrderAppointmentListResp res = new OrderAppointmentListResp();
OrderRequest order = orderRequestMPDao.getByOrderId(orderId);
if(order == null){
throw new BusinessException("订单不存在");
}
LocalDate curDate = order.getDt();
// 查询预约单列表 // 查询预约单列表
List<OrderAppointment> appoints = orderAppointmentMPDao.selectByOrderId(orderId); List<OrderInfo> orders = orderInfoMPDao.selectByOrderId(orderId);
if (appoints.isEmpty()) { if (orders.isEmpty()) {
// 没有指派单列表,返回 // 没有指派单列表,返回
res.setOrderId(orderId); res.setOrderId(orderId);
res.setOrders(new ArrayList<>()); res.setOrders(new ArrayList<>());
return Result.success(res); return Result.success(res);
} }
// 工程师ID列表
List<String> egCodes = appoints.stream().map(OrderAppointment::getEngineerCode).collect(Collectors.toList());
// 获取工程师基础信息列表 // 获取工程师基础信息列表
HashMap<String, EngineerInfo> egInfo = this.getEngineerInfos(egCodes); Set<String> set = new HashSet<>();
orders.stream().map(OrderInfo::getEngineerCode).forEach(set::add);
orders.stream().map(OrderInfo::getEngineerCodeSub).forEach(set::add);
List<String> engineerCodes = new ArrayList<>(set);
HashMap<String, EngineerInfo> egInfo = this.getEngineerInfos(engineerCodes);
// 获取groupIds 和 group信息 // 获取groupIds 和 group信息
List<String> groupIds = egInfo.values().stream().map(EngineerInfo::getGroupId).collect(Collectors.toList()); List<String> groupIds = egInfo.values().stream().map(EngineerInfo::getGroupId).collect(Collectors.toList());
HashMap<String, OrgGroup> groups = this.queryOrgGroups(groupIds); HashMap<String, OrgGroup> groups = this.queryOrgGroups(groupIds);
// 获取工程师技能列表<engineerCode, skills> // 获取工程师技能列表<engineerCode, skills>
Map<String, String> egSkill = this.getEngineerSkills(egCodes); Map<String, String> egSkill = this.getEngineerSkills(engineerCodes);
// 获取subOrder订单timeline // 获取subOrder订单timeline
Map<String, List<OrderTimeline>> timelines = this.getOrderTimelines(orderId); Map<String, List<OrderTimeline>> timelines = this.getOrderTimelines(orderId);
// 对指派单列表按照subOrderId降序排序, 获取排序的subOrderId列表, 然后根据subOrderId分组 Comparator<OrderInfo> dtDesc = Comparator.comparing(OrderInfo::getDt).reversed();
Comparator<OrderAppointment> sbDesc = Comparator.comparing(OrderAppointment::getSuborderId, String.CASE_INSENSITIVE_ORDER).reversed(); List<OrderInfo> results = orders.stream().sorted(dtDesc).collect(Collectors.toList());
List<OrderAppointment> results = appoints.stream().sorted(sbDesc).collect(Collectors.toList());
String lastSubOrderId = results.get(0).getSuborderId(); LocalDate lastDt = results.get(0).getDt();
List<OrderAppointmentListResp.OrderAppointment> items = new ArrayList<>(); List<OrderAppointmentListResp.OrderAppointment> items = new ArrayList<>();
for (OrderAppointment o : results) { for (OrderInfo o : results) {
String subOrderId = o.getSuborderId();
EngineerInfo eg = egInfo.getOrDefault(o.getEngineerCode(), null); EngineerInfo eg = egInfo.getOrDefault(o.getEngineerCode(), null);
String skill = egSkill.getOrDefault(o.getEngineerCode(), null); String skill = egSkill.getOrDefault(o.getEngineerCode(), null);
...@@ -148,15 +138,15 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -148,15 +138,15 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
// 获取title // 获取title
String title = engineerName; String title = engineerName;
if (!lastSubOrderId.equals(subOrderId) || o.getDt().isBefore(curDate)) { if (o.getDt().isBefore(lastDt)) {
title = String.format("%s_%s", engineerName, TimeUtils.IsoLocalDate2String(o.getDt())); title = String.format("%s_%s", engineerName, TimeUtils.IsoLocalDate2String(o.getDt()));
} }
OrderAppointmentListResp.OrderAppointment item = new OrderAppointmentListResp.OrderAppointment(); OrderAppointmentListResp.OrderAppointment item = new OrderAppointmentListResp.OrderAppointment();
item.setTitle(title); item.setTitle(title);
item.setEngineerCode(o.getEngineerCode()); item.setEngineerCode(o.getEngineerCode());
item.setExpectTime(TimeUtils.IsoTimestamp2DateTime(o.getExpectStartTime())); item.setExpectTime(TimeUtils.IsoTimestamp2DateTime(o.getExpectTimeBegin()));
item.setTimelines(this.packOrderTimeline(timelines.get(subOrderId))); item.setTimelines(this.packOrderTimeline(timelines.get(o.getSubId())));
item.setItems(this.packEngineerItems(eg, skill, groups.get(eg.getGroupId()))); item.setItems(this.packEngineerItems(eg, skill, groups.get(eg.getGroupId())));
items.add(item); items.add(item);
...@@ -173,7 +163,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -173,7 +163,7 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
List<String> block = new ArrayList<>(); List<String> block = new ArrayList<>();
// 获取订单详情 // 获取订单详情
OrderRequest order = orderRequestMPDao.getByOrderId(orderId); OrderInfo order = orderInfoMPDao.getByOrderId(orderId);
OrderTeamBlockResp res = new OrderTeamBlockResp(); OrderTeamBlockResp res = new OrderTeamBlockResp();
res.setOrderId(orderId); res.setOrderId(orderId);
...@@ -236,7 +226,6 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -236,7 +226,6 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
Comparator<EngineerSkillGroup> cmp = Comparator.comparing(EngineerSkillGroup::getEngineerCode); Comparator<EngineerSkillGroup> cmp = Comparator.comparing(EngineerSkillGroup::getEngineerCode);
List<EngineerSkillGroup> sortedResults = rows.stream().sorted(cmp).collect(Collectors.toList()); List<EngineerSkillGroup> sortedResults = rows.stream().sorted(cmp).collect(Collectors.toList());
// 根据engineerCode分组 // 根据engineerCode分组
Map<String, List<EngineerSkillGroup>> results = sortedResults.stream().collect(Collectors.groupingBy(EngineerSkillGroup::getEngineerCode)); Map<String, List<EngineerSkillGroup>> results = sortedResults.stream().collect(Collectors.groupingBy(EngineerSkillGroup::getEngineerCode));
...@@ -339,11 +328,11 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -339,11 +328,11 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
return items; return items;
} }
private List<KV> packOrderDetail(OrderRequest order) { private List<KV> packOrderDetail(OrderInfo order) {
List<KV> items = new ArrayList<>(); List<KV> items = new ArrayList<>();
items.add(this.packOrderItem("客户姓名", order.getName())); items.add(this.packOrderItem("客户姓名", order.getName()));
items.add(this.packOrderItem("客户电话", order.getPhone())); items.add(this.packOrderItem("客户电话", order.getPhone()));
items.add(this.packOrderItem("客户地址", String.format("%s%s%s",order.getCity(), order.getCounty(), order.getAddress()))); items.add(this.packOrderItem("客户地址", String.format("%s%s%s", order.getCity(), order.getCounty(), order.getAddress())));
items.add(this.packOrderItem("品牌", order.getBrand())); items.add(this.packOrderItem("品牌", order.getBrand()));
items.add(this.packOrderItem("设备", order.getType())); items.add(this.packOrderItem("设备", order.getType()));
items.add(this.packOrderItem("服务", order.getSkill())); items.add(this.packOrderItem("服务", order.getSkill()));
......
...@@ -8,7 +8,7 @@ import com.dituhui.pea.order.dto.OrderChangeListDTO; ...@@ -8,7 +8,7 @@ import com.dituhui.pea.order.dto.OrderChangeListDTO;
import com.dituhui.pea.order.dto.WorkbenchSummaryResp; import com.dituhui.pea.order.dto.WorkbenchSummaryResp;
import com.dituhui.pea.order.entity.OrderEventEntity; import com.dituhui.pea.order.entity.OrderEventEntity;
import com.dituhui.pea.order.entity.OrderInfoEntity; import com.dituhui.pea.order.entity.OrderInfoEntity;
import com.dituhui.pea.order.entity.OrderRequest; import com.dituhui.pea.order.entity.OrderInfo;
import com.dituhui.pea.order.service.WorkbenchService; import com.dituhui.pea.order.service.WorkbenchService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -28,7 +28,7 @@ public class WorkbenchServiceImpl implements WorkbenchService { ...@@ -28,7 +28,7 @@ public class WorkbenchServiceImpl implements WorkbenchService {
private OrderEventDao orderEventDao; private OrderEventDao orderEventDao;
@Autowired @Autowired
private OrderRequestMPDao orderRequestMPDao; private OrderInfoMPDao orderInfoMPDao;
@Autowired @Autowired
private OrderInfoDao orderInfoDao; private OrderInfoDao orderInfoDao;
...@@ -89,27 +89,27 @@ public class WorkbenchServiceImpl implements WorkbenchService { ...@@ -89,27 +89,27 @@ public class WorkbenchServiceImpl implements WorkbenchService {
} }
private List<Map<String, Object>> queryCountByAppointmentMethod(String levelType, String levelValue, LocalDate dt) { private List<Map<String, Object>> queryCountByAppointmentMethod(String levelType, String levelValue, LocalDate dt) {
QueryWrapper<OrderRequest> wrapper = new QueryWrapper<>(); QueryWrapper<OrderInfo> wrapper = new QueryWrapper<>();
wrapper.select("appointment_method, appointment_status, COUNT(*) as count") wrapper.select("appointment_method, appointment_status, COUNT(*) as count")
.lambda() .lambda()
.eq(OrderRequest::getDt, dt) .eq(OrderInfo::getDt, dt)
.eq(levelType.equals("cluster"), OrderRequest::getOrgClusterId, levelValue) .eq(levelType.equals("cluster"), OrderInfo::getOrgClusterId, levelValue)
.eq(levelType.equals("branch"), OrderRequest::getOrgBranchId, levelValue) .eq(levelType.equals("branch"), OrderInfo::getOrgBranchId, levelValue)
.eq(levelType.equals("group"), OrderRequest::getOrgGroupId, levelValue) .eq(levelType.equals("group"), OrderInfo::getOrgGroupId, levelValue)
.groupBy(OrderRequest::getAppointmentMethod, OrderRequest::getAppointmentStatus); .groupBy(OrderInfo::getAppointmentMethod, OrderInfo::getAppointmentStatus);
return orderRequestMPDao.selectMaps(wrapper); return orderInfoMPDao.selectMaps(wrapper);
} }
private List<Map<String, Object>> queryCountByOrderStatus(String levelType, String levelValue, LocalDate dt) { private List<Map<String, Object>> queryCountByOrderStatus(String levelType, String levelValue, LocalDate dt) {
QueryWrapper<OrderRequest> wrapper = new QueryWrapper<>(); QueryWrapper<OrderInfo> wrapper = new QueryWrapper<>();
wrapper.select("appointment_status, COUNT(*) as count") wrapper.select("appointment_status, COUNT(*) as count")
.lambda() .lambda()
.eq(OrderRequest::getDt, dt) .eq(OrderInfo::getDt, dt)
.eq(levelType.equals("cluster"), OrderRequest::getOrgClusterId, levelValue) .eq(levelType.equals("cluster"), OrderInfo::getOrgClusterId, levelValue)
.eq(levelType.equals("branch"), OrderRequest::getOrgBranchId, levelValue) .eq(levelType.equals("branch"), OrderInfo::getOrgBranchId, levelValue)
.eq(levelType.equals("group"), OrderRequest::getOrgGroupId, levelValue) .eq(levelType.equals("group"), OrderInfo::getOrgGroupId, levelValue)
.groupBy(OrderRequest::getAppointmentStatus); .groupBy(OrderInfo::getAppointmentStatus);
return orderRequestMPDao.selectMaps(wrapper); return orderInfoMPDao.selectMaps(wrapper);
} }
private HashMap<String, Long> transAppointmentMethod(List<Map<String, Object>> results) { private HashMap<String, Long> transAppointmentMethod(List<Map<String, Object>> results) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!