Commit 5326e11c by 丁伟峰

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

# Conflicts:
#	project-order/src/main/java/com/alibaba/cloud/integration/order/controller/OrderController.java
2 parents 8131f888 935a8faf
Showing with 1096 additions and 30 deletions
......@@ -2,40 +2,20 @@ spring:
cloud:
gateway:
routes:
- id: placeOrder
uri: lb://project-order
predicates:
- Path=/order/create
- id: queryStorage
uri: lb://project-storage
predicates:
- Path=/storage/
- id: queryAccount
uri: lb://project-account
predicates:
- Path=/account/
- id: praiseItemRocketMQ
uri: lb://project-provider
predicates:
- Path=/praise/rocketmq
- id: praiseItemSentinel
uri: lb://project-provider
predicates:
- Path=/praise/sentinel
- id: queryPraise
uri: lb://project-consumer
predicates:
- Path=/praise/query
- id: user
uri: lb://user
predicates:
- Path=/user/**, /v1/team/**, /v1/user/**
- id: order
uri: lb://project-order
predicates:
- Path=/order/**
- id: gis
uri: lb://gis
uri: lb://project-gis
predicates:
- Path=/gis/**
- id: district
uri: lb://district
uri: lb://project-district
predicates:
- Path=/district/**
......
......@@ -15,7 +15,7 @@
<properties>
<druid.version>1.1.10</druid.version>
<mybatis.version>2.1.2</mybatis.version>
<mybatisplus.version>3.5.3.1</mybatisplus.version>
</properties>
<dependencies>
......@@ -36,9 +36,9 @@
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.version}</version>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatisplus.version}</version>
</dependency>
<dependency>
......
package com.alibaba.cloud.integration.order.config;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MPConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return interceptor;
}
}
\ No newline at end of file
package com.alibaba.cloud.integration.order.controller;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dto.EnginnerTimelineReq;
import com.alibaba.cloud.integration.order.service.EnginnerTimelineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class EnginnerTimelineController {
@Autowired
private EnginnerTimelineService enginnerTimelineService;
@GetMapping("/enginner/work/trace")
public Result<?> GetEnginnerTimeline(@RequestParam EnginnerTimelineReq req) {
return enginnerTimelineService.GetEnginnerTimelines(req.getEnginnerCode(), req.getDate());
}
}
......@@ -28,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* @author TrevorLink
*/
......@@ -76,4 +77,10 @@ public class OrderController {
}
return res;
}
@GetMapping("/test")
public Result<?> test(@RequestParam(value = "param", required = false) String param) {
System.out.println("test ok");
return Result.success("test ok");
}
}
package com.alibaba.cloud.integration.order.controller;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.service.OrderServiceDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class OrderServiceDetailController {
@Autowired
private OrderServiceDetail orderServiceDetail;
@GetMapping("/order/service/detail")
public Result<?> GetOrderServiceDetail(@RequestParam String orderId) {
return orderServiceDetail.GetOrderServiceDetail(orderId);
}
}
\ No newline at end of file
package com.alibaba.cloud.integration.order.controller;
import com.alibaba.cloud.integration.common.BusinessException;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dto.OrderServiceListReq;
import com.alibaba.cloud.integration.order.service.OrderServiceList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @author wangl@zjhuixinyun.com
*/
@RestController
public class OrderServiceListController {
@Autowired
private OrderServiceList orderServiceList;
@GetMapping("/order/service/list")
public Result<?> GetOrderServiceList(@RequestParam OrderServiceListReq req) {
Result<?> res = null;
try {
res = orderServiceList.GetOrderServiceList(req);
}
catch (BusinessException e) {
return Result.failed(e.getMessage());
}
return res;
}
}
package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.EngineerInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface EngineerInfoDao extends BaseMapper<EngineerInfo> {
}
package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.EngineerSkill;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface EngineerSkillDao extends BaseMapper<EngineerSkill> {
}
\ No newline at end of file
package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.EngineerTimeline;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface EngineerTimelineDao extends BaseMapper<EngineerTimeline> {
}
package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.OrderAppointment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface OrderAppointmentDao extends BaseMapper<OrderAppointment> {
}
package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.OrderRequest;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface OrderRequestDao extends BaseMapper<OrderRequest> {
}
package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.OrderTimeline;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface OrderTimelineDao extends BaseMapper<OrderTimeline> {
}
\ No newline at end of file
package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.WarehouseInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface WarehouseInfoDao extends BaseMapper<WarehouseInfo> {
}
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
@Data
public class EnginnerTimelineReq {
private String enginnerCode;
private String date;
}
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
import java.util.List;
@Data
public class EnginnerTimelineResp {
private String engineerCode;
private String engineerName;
private List<DynamicItem> dynamics;
@Data
public static class DynamicItem{
private String title;
private String time;
private Integer status;
private String text;
private String location;
private String type;
}
}
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
@Data
public class KV {
private String title;
private String value;
private String type;
private String status;
private Object params;
}
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
import java.util.List;
@Data
public class OrderServiceDetailResp {
private String orderId;
private String status;
private String statusDesc;
private String risk;
private String riskDesc;
private List<KV> orderServiceItems;
private List<OrderAppointment> orderAppointments;
@Data
public static class OrderAppointment{
private String title;
private String expectTime;
private List<List<KV>> engineers;
private List<KV> timelines;
}
}
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
@Data
public class OrderServiceList {
private String orderId;
private String type;
private String brand;
private String skill;
private String faultDescribe;
private String name;
private String phone;
private String address;
private String x;
private String y;
private String expectTimeBegin;
private String expectTimeEnd;
private String source;
private String description;
private String orgBranchName;
private Integer engineerNum;
private String engineerNames;
private String appointmentTime;
private String appointmentStatus;
private String appointmentType;
private String createTime;
}
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode
public class OrderServiceListReq {
private String startDate;
private String endDate;
private long page;
private long size;
private String sort;
private String appointmentType;
private String appointmentStatus;
private String type;
private String brand;
private String skill;
}
\ No newline at end of file
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
import java.util.List;
@Data
public class OrderServiceListResp {
private long total;
private long pages;
private long pageCurrent;
private long pageSize;
private List<OrderServiceList> content;
}
package com.alibaba.cloud.integration.order.entity;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class EngineerInfo {
private Integer id;
private String engineerCode;
private String branchId;
private String code;
private String name;
private String cosmosId;
private String gender;
private String birth;
private String phone;
private String addr;
private Integer kind;
private String grade;
private String credentials;
private String vehicle;
private String vehicleNo;
private String beanStatus;
private String memo;
private Timestamp createTime;
private Timestamp updateTime;
}
package com.alibaba.cloud.integration.order.entity;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class EngineerSkill {
private Integer id;
private String engineerCode;
private String categoryId;
private String brand;
private String kind;
private String skill;
private Integer status;
private String memo;
private Timestamp createTime;
private Timestamp updateTime;
}
\ No newline at end of file
package com.alibaba.cloud.integration.order.entity;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class EngineerTimeline {
private String engineerCode;
private String event;
private Timestamp happen;
private String orderId;
private String suborderId;
private Integer status;
private String memo;
private Timestamp createTime;
private Timestamp updateTime;
}
package com.alibaba.cloud.integration.order.entity;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class OrderAppointment {
private Integer id;
private String orderId;
private String suborderId;
private String mainSub;
private String engineerCode;
private String engineerName;
private String engineerPhone;
private String engineerAge;
private String engineerGroupId;
private String engineerGroupName;
private String isWorkshop;
private Timestamp expectTime;
private Timestamp actualTime;
private Timestamp startTime;
private Timestamp endTime;
private String status;
private String memo;
private Timestamp createTime;
private Timestamp updateTime;
}
package com.alibaba.cloud.integration.order.entity;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class OrderRequest {
private Integer id;
private String orderId;
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 categoryId;
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 priority;
private String areaId;
private String orderTags;
private String tags;
private String status;
private String statusAppointment;
private String orgClusterId;
private String orgClusterName;
private String orgBranchId;
private String orgBranchName;
private String orgGroupId;
private String orgGroupName;
private String orgTeamId;
private String orgTeamName;
private String description;
private Timestamp createTime;
private Timestamp updateTime;
}
package com.alibaba.cloud.integration.order.entity;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class OrderTimeline {
private String orderId;
private String suborderId;
private String event;
private String happen;
private Integer status;
private Timestamp createTime;
private Timestamp updateTime;
}
package com.alibaba.cloud.integration.order.entity;
import lombok.Data;
@Data
public class WarehouseInfo {
private Integer warehouseId;
private String warehouseNname;
private String branchId;
private String cityCode;
private String address;
private String x;
private String y;
}
package com.alibaba.cloud.integration.order.service;
import com.alibaba.cloud.integration.common.Result;
public interface EnginnerTimelineService {
Result<?> GetEnginnerTimelines(String engineerCode, String date);
}
package com.alibaba.cloud.integration.order.service;
import com.alibaba.cloud.integration.common.Result;
public interface OrderServiceDetail {
Result<?> GetOrderServiceDetail(String orderId);
}
package com.alibaba.cloud.integration.order.service;
import com.alibaba.cloud.integration.common.BusinessException;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dto.OrderServiceListReq;
import com.alibaba.cloud.integration.order.dto.OrderServiceListResp;
public interface OrderServiceList {
Result<OrderServiceListResp> GetOrderServiceList(OrderServiceListReq req) throws BusinessException;
}
package com.alibaba.cloud.integration.order.service.impl;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dao.*;
import com.alibaba.cloud.integration.order.dto.EnginnerTimelineResp;
import com.alibaba.cloud.integration.order.entity.EngineerInfo;
import com.alibaba.cloud.integration.order.entity.EngineerTimeline;
import com.alibaba.cloud.integration.order.entity.OrderRequest;
import com.alibaba.cloud.integration.order.entity.WarehouseInfo;
import com.alibaba.cloud.integration.order.entity.OrderAppointment;
import com.alibaba.cloud.integration.order.service.EnginnerTimelineService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Timestamp;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service
public class EnginnerTimelineServiceImpl implements EnginnerTimelineService {
@Autowired
private EngineerTimelineDao engineerTimelineDao;
@Autowired
private OrderAppointmentDao orderAppointmentDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private OrderRequestDao orderRequestDao;
@Autowired
private WarehouseInfoDao warehouseInfoDao;
@Transactional
@Override
public Result<?> GetEnginnerTimelines(String engineerCode, String date){
// 工程师姓名
String name = this.GetEnginnerName(engineerCode);
// 获取工程师已完成的timeline数据
List<EngineerTimeline> timelines = this.EnginnerTimelines(engineerCode, date);
// 获取工程师date日的订单数据
List<OrderAppointment> orders = this.OrderAppointments(engineerCode, date);
// 获取客户地址
List<String> orderIds = new ArrayList<>();
for(OrderAppointment o: orders) {
orderIds.add(o.getOrderId());
}
HashMap<String, String> orderLocations = this.OrderRequestsLocation(orderIds);
// 获取配送站地址
String branchId = this.EngineerBranchId(engineerCode);
String warehouseLocation = this.WarehouseLocation(branchId);
List<EnginnerTimelineResp.DynamicItem> dynamics = this.PackItems(timelines, orders, orderLocations, warehouseLocation);
EnginnerTimelineResp res = new EnginnerTimelineResp();
res.setEngineerCode(engineerCode);
res.setEngineerName(name);
res.setDynamics(dynamics);
return Result.success(res);
}
private String GetEnginnerName(String enginerrCode){
LambdaQueryWrapper<EngineerInfo> lqw = new LambdaQueryWrapper<>();
lqw.eq(EngineerInfo::getEngineerCode, enginerrCode);
EngineerInfo e = engineerInfoDao.selectOne(lqw);
return e.getName();
}
private List<OrderAppointment> OrderAppointments(String engineerCode, String date){
// 获取指派单列表
LambdaQueryWrapper<OrderAppointment> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderAppointment::getEngineerCode, engineerCode);
lqw.ge(OrderAppointment::getExpectTime, date + " 00:00:00");
lqw.le(OrderAppointment::getExpectTime, date + " 23:59:59");
return orderAppointmentDao.selectList(lqw);
}
private List<EngineerTimeline> EnginnerTimelines(String engineerCode, String date){
// 获取工程师timeline
List<String> events = Stream.of("分站取还配件", "已出发", "加单").collect(Collectors.toList());
LambdaQueryWrapper<EngineerTimeline> lqw = new LambdaQueryWrapper<>();
lqw.eq(EngineerTimeline::getEngineerCode, engineerCode);
lqw.ge(EngineerTimeline::getHappen, date+" 00:00:00");
lqw.le(EngineerTimeline::getHappen, date + " 23:59:59");
lqw.in(EngineerTimeline::getEvent, events);
return engineerTimelineDao.selectList(lqw);
}
private HashMap<String, String> OrderRequestsLocation(List<String> orderIds) {
// 获取客户地址location
HashMap<String, String> map = new HashMap<>();
LambdaQueryWrapper<OrderRequest> lqw = new LambdaQueryWrapper<>();
lqw.in(OrderRequest::getOrderId, orderIds);
List<OrderRequest> orders = orderRequestDao.selectList(lqw);
for(OrderRequest o: orders){
map.put(o.getOrderId(), String.format("%s,%s", o.getX(), o.getY()));
}
return map;
}
private String WarehouseLocation(String branchId) {
// 获取配送站location
LambdaQueryWrapper<WarehouseInfo> lqw = new LambdaQueryWrapper<>();
lqw.eq(WarehouseInfo::getBranchId, branchId);
WarehouseInfo w = warehouseInfoDao.selectOne(lqw);
return String.format("%s,%s", w.getX(), w.getY());
}
private String EngineerBranchId(String engineerCode) {
LambdaQueryWrapper<EngineerInfo> lqw = new LambdaQueryWrapper<>();
lqw.eq(EngineerInfo::getEngineerCode, engineerCode);
return engineerInfoDao.selectOne(lqw).getBranchId();
}
private List<EnginnerTimelineResp.DynamicItem> PackItems(List<EngineerTimeline> timelines, List<OrderAppointment> orders, HashMap<String, String> locations, String warehouseLocation) {
Integer index = 1;
String order_id, title, type, text, location;
List<EnginnerTimelineResp.DynamicItem> items = new ArrayList<>();
Set<String> s = new HashSet<>();
for (EngineerTimeline t: timelines){
EnginnerTimelineResp.DynamicItem item = new EnginnerTimelineResp.DynamicItem();
if (t.getEvent() == "分站取还配件") {
title = t.getEvent();
text = "取";
type = "other";
location = warehouseLocation;
} else if (t.getEvent() == "加单") {
title = t.getEvent();
text = "加";
type = "other";
location = locations.get(t.getOrderId());
} else {
index += 1;
title = String.format("第%d单出发", index);
text = String.format("%d", index);
type = "order";
location = locations.get(t.getOrderId());
}
item.setTitle(title);
item.setTime(this.Timestamp2Datetime(t.getHappen()));
item.setStatus(1);
item.setText(text);
item.setLocation(location);
item.setType(type);
items.add(item);
s.add(t.getOrderId() + t.getSuborderId());
}
for(OrderAppointment o: orders){
order_id = o.getOrderId() + o.getSuborderId();
if (s.equals(order_id)) {
continue;
}
index += 1;
EnginnerTimelineResp.DynamicItem item = new EnginnerTimelineResp.DynamicItem();
item.setTitle(String.format("第%d单出发", index));
item.setTime(this.Timestamp2Datetime(o.getExpectTime()));
item.setStatus(0);
item.setText(String.format("%d", index));
item.setLocation(locations.get(o.getOrderId()));
item.setType("order");
items.add(item);
}
// 根据items的time升序排序
items.stream().sorted(Comparator.comparing(EnginnerTimelineResp.DynamicItem::getTime)).collect(Collectors.toList());
return items;
}
private String Timestamp2Datetime(Timestamp t) {
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-mm-dd HH:MM:SS");
return df.format(t.toLocalDateTime());
}
}
package com.alibaba.cloud.integration.order.service.impl;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dao.*;
import com.alibaba.cloud.integration.order.dto.KV;
import com.alibaba.cloud.integration.order.dto.OrderServiceDetailResp;
import com.alibaba.cloud.integration.order.entity.OrderRequest;
import com.alibaba.cloud.integration.order.entity.OrderAppointment;
import com.alibaba.cloud.integration.order.entity.EngineerInfo;
import com.alibaba.cloud.integration.order.entity.EngineerSkill;
import com.alibaba.cloud.integration.order.entity.OrderTimeline;
import com.alibaba.cloud.integration.order.service.OrderServiceDetail;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class OrderServiceDetailImpl implements OrderServiceDetail {
@Autowired
private OrderRequestDao orderRequestDao;
@Autowired
private OrderAppointmentDao orderAppointmentDao;
@Autowired
private EngineerSkillDao engineerSkillDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private OrderTimelineDao orderTimelineDao;
@Transactional
@Override
public Result<?> GetOrderServiceDetail(String orderId) {
// 查询订单详情
OrderRequest detail = this.GetOrderDetail(orderId);
// 查询指派列表
List<OrderServiceDetailResp.OrderAppointment> items = new ArrayList<>();
List<OrderAppointment> appoints = this.GetOrderAppointments(orderId);
// 工程师ID列表
List<String> egCodes = new ArrayList<>();
for(OrderAppointment o: appoints) {
egCodes.add(o.getEngineerCode());
}
// 获取工程师基础信息列表
HashMap<String, EngineerInfo> egInfo = this.GetEngineerInfos(egCodes);
// 获取工程师技能列表
HashMap<String, EngineerSkill> egSkill = this.GetEngineerSkills(egCodes);
// 获取订单timeline
Map<String, List<OrderTimeline>> timelines = this.GetOrderTimelines(orderId);
// 对指派单列表按照subOrderId降序排序, 获取排序的subOrderId列表, 然后根据subOrderId分组
Comparator<OrderAppointment> sbDesc = Comparator.comparing(OrderAppointment::getSuborderId, String.CASE_INSENSITIVE_ORDER).reversed();
List<OrderAppointment> results = appoints.stream().sorted(sbDesc).collect(Collectors.toList());
// 根据subOrderId分组
Map<String, List<OrderAppointment>> appointOrders = results.stream().collect(Collectors.groupingBy(OrderAppointment::getSuborderId));
// 获取排序的subOrderId(降序)
List<String> subOrderIds = new ArrayList<>();
for (String k: appointOrders.keySet()){
subOrderIds.add(k);
}
Collections.reverse(subOrderIds);
for(String subOrderId: subOrderIds){
List<OrderAppointment> orders = appointOrders.get(subOrderId);
OrderAppointment order = orders.get(0); // 第一个订单
OrderServiceDetailResp.OrderAppointment op = new OrderServiceDetailResp.OrderAppointment();
// 获取工程师列表信息
List<List<KV>> egInfos = new ArrayList<>();
for (OrderAppointment o: orders) {
String egCode = o.getEngineerCode();
egInfos.add(this.PackEngineerInfos(egInfo.get(egCode), egSkill.get(egCode)));
}
op.setEngineers(egInfos);
//获取timeline信息
op.setTimelines(this.PackOrderTimeline(timelines.get(subOrderId)));
op.setTitle(order.getSuborderId());
op.setExpectTime(order.getExpectTime().toString());
items.add(op);
}
// 返回结果
OrderServiceDetailResp res = new OrderServiceDetailResp();
res.setOrderId(orderId);
res.setStatus(detail.getStatus());
res.setOrderServiceItems(this.PackOrderDetail(detail));
res.setOrderAppointments(items);
return Result.success(res);
}
private OrderRequest GetOrderDetail(String orderId) {
// 获取服务单记录
LambdaQueryWrapper<OrderRequest> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderRequest::getOrderId, orderId);
return orderRequestDao.selectOne(lqw);
}
private List<OrderAppointment> GetOrderAppointments(String orderId) {
// 获取指派单记录列表
LambdaQueryWrapper<OrderAppointment> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderAppointment::getOrderId, orderId);
return orderAppointmentDao.selectList(lqw);
}
private HashMap<String, EngineerInfo> GetEngineerInfos(List<String> egCodes){
// 获取工程师信息列表
HashMap<String, EngineerInfo> map = new HashMap<>();
LambdaQueryWrapper<EngineerInfo> lqw = new LambdaQueryWrapper<>();
lqw.in(EngineerInfo::getEngineerCode, egCodes);
List<EngineerInfo> rows = engineerInfoDao.selectList(lqw);
for (EngineerInfo row: rows){
map.put(row.getEngineerCode(), row);
}
return map;
}
private HashMap<String, EngineerSkill> GetEngineerSkills(List<String> egCodes) {
// 获取工程师技能列表
HashMap<String, EngineerSkill> map = new HashMap<>();
LambdaQueryWrapper<EngineerSkill> lqw = new LambdaQueryWrapper<>();
lqw.in(EngineerSkill::getEngineerCode, egCodes);
List<EngineerSkill> rows = engineerSkillDao.selectList(lqw);
for (EngineerSkill row: rows){
map.put(row.getEngineerCode(), row);
}
return map;
}
private Map<String, List<OrderTimeline>> GetOrderTimelines(String orderId) {
HashMap<String, List<OrderTimeline>> map = new HashMap<>();
LambdaQueryWrapper<OrderTimeline> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderTimeline::getOrderId, orderId);
List<OrderTimeline> timelines = orderTimelineDao.selectList(lqw);
// 根据subOrderId + happend字段排序
Comparator<OrderTimeline> sb = Comparator.comparing(OrderTimeline::getSuborderId, String.CASE_INSENSITIVE_ORDER);
Comparator<OrderTimeline> happen = Comparator.comparing(OrderTimeline::getHappen);
Comparator<OrderTimeline> comp = sb.thenComparing(happen);
List<OrderTimeline> results = timelines.stream().sorted(comp).collect(Collectors.toList());
// 根据subOrderId分组
return results.stream().collect(Collectors.groupingBy(OrderTimeline::getSuborderId));
}
private List<KV> PackOrderDetail(OrderRequest order) {
List<KV> items = new ArrayList<>();
items.add(this.PackOrderItem("客户姓名:", order.getName()));
items.add(this.PackOrderItem("标签:", order.getTags()));
items.add(this.PackOrderItem("客户电话:", order.getPhone()));
items.add(this.PackOrderItem("设备:", order.getType()));
items.add(this.PackOrderItem("服务:", order.getSkill()));
items.add(this.PackOrderItem("故障描述:", order.getFaultDescribe()));
items.add(this.PackOrderItem("备注:", order.getApplyNote()));
items.add(this.PackOrderItem("意向时间:", ""));
items.add(this.PackOrderItem("时间要求:", order.getExpectTimeDesc()));
items.add(this.PackOrderItem("预约方式:", order.getSource()));
return items;
}
private List<KV> PackEngineerInfos(EngineerInfo eg, EngineerSkill skill) {
// 获取工程师信息
String kind = "";
String age = "";
if (eg.getKind() == 1) {
kind = "全职";
} else {
kind = "兼职";
}
if (age.isEmpty()) {
age="未知";
} else {
age = eg.getBirth();
}
List<KV> items = new ArrayList<>();
items.add(this.PackEngineer("技术员:", eg.getName(), "engineer"));
items.add(this.PackEngineer("小组:", "老王组", ""));
items.add(this.PackEngineer("类型:", kind, ""));
items.add(this.PackEngineer("性别/年龄:", eg.getGender()+"/"+age, ""));
items.add(this.PackEngineer("手机号:", eg.getPhone(), ""));
items.add(this.PackEngineer("工号:", eg.getCode(), "" ));
items.add(this.PackEngineer("技能:", skill.getSkill(), ""));
return items;
}
private List<KV> PackOrderTimeline(List<OrderTimeline> timelines) {
List<KV> items = new ArrayList<>();
if (timelines == null) {
return items;
}
for (OrderTimeline o:timelines) {
items.add(this.PackTimeline(o.getEvent(), o.getHappen(), o.getStatus().toString()));
}
return items;
}
private KV PackOrderItem(String title, String value) {
return this.PackKV(title, value, null, null, null);
}
private KV PackEngineer(String title, String value, Object params) {
return this.PackKV(title, value, null, null, params);
}
private KV PackTimeline(String title, String value, String status) {
return this.PackKV(title, value, null, status, null);
}
private KV PackKV(String title, String value, String type, String status, Object params) {
KV item = new KV();
item.setTitle(title);
item.setValue(value);
item.setType(type);
item.setStatus(status);
item.setParams(params);
return item;
}
}
\ No newline at end of file
package com.alibaba.cloud.integration.order.service.impl;
import com.alibaba.cloud.integration.common.BusinessException;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dao.OrderAppointmentDao;
import com.alibaba.cloud.integration.order.dao.OrderRequestDao;
import com.alibaba.cloud.integration.order.dto.OrderServiceList;
import com.alibaba.cloud.integration.order.dto.OrderServiceListReq;
import com.alibaba.cloud.integration.order.dto.OrderServiceListResp;
import com.alibaba.cloud.integration.order.entity.OrderAppointment;
import com.alibaba.cloud.integration.order.entity.OrderRequest;
import com.alibaba.cloud.integration.order.service.OrderService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Timestamp;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class OrderServiceListImpl implements com.alibaba.cloud.integration.order.service.OrderServiceList {
@Autowired
private OrderRequestDao orderRequestDao;
@Autowired
private OrderAppointmentDao orderAppointmentDao;
@Override
@Transactional
public Result<OrderServiceListResp> GetOrderServiceList(OrderServiceListReq req) throws BusinessException {
//分页
IPage<OrderRequest> page = new Page(req.getPage(), req.getSize());
LambdaQueryWrapper<OrderRequest> lqw = new LambdaQueryWrapper<>();
lqw.ge(OrderRequest::getExpectTimeBegin, this.GetTimestampFromDate(req.getStartDate())); //预约开始日期
lqw.le(OrderRequest::getExpectTimeBegin, this.GetTimestampFromDate(req.getEndDate())); //预约结束日期
lqw.eq(Strings.isNotEmpty(req.getAppointmentStatus()), OrderRequest::getStatusAppointment, req.getAppointmentStatus()); //指派状态
lqw.eq(Strings.isNotEmpty(req.getType()), OrderRequest::getType, req.getType()); //设备类型
lqw.eq(Strings.isNotEmpty(req.getBrand()), OrderRequest::getBrand, req.getBrand()); //品牌
lqw.eq(Strings.isNotEmpty(req.getSkill()), OrderRequest::getSkill, req.getSkill()); //技能
// 查询工单表列表
orderRequestDao.selectPage(page, lqw);
List<OrderRequest> records = page.getRecords();
//获取工单订单号列表
List<String> orderIds = new ArrayList<>();
for(OrderRequest r: records) {
orderIds.add(r.getOrderId());
}
// 获取指派订单列表
HashMap<String, List<OrderAppointment>> appointOrders = this.PackOrderAppointment(this.GetOrderAppointment(orderIds));
List<OrderAppointment> appoint;
List<OrderServiceList> content = new ArrayList<>();
for (OrderRequest o: records) {
OrderServiceList record = new OrderServiceList();
appoint = appointOrders.getOrDefault(o.getOrderId(), List.of());
record.setOrderId(o.getOrderId());
record.setType(o.getType());
record.setBrand(o.getBrand());
record.setFaultDescribe(o.getFaultDescribe());
record.setSkill(o.getSkill());
record.setName(o.getName());
record.setPhone(o.getPhone());
record.setAddress(o.getAddress());
record.setX(o.getX());
record.setY(o.getY());
record.setSource(o.getSource());
record.setDescription(o.getDescription());
record.setOrgBranchName(o.getOrgBranchName());
record.setEngineerNum(this.getEngNum(appoint)); //工程师数量
record.setEngineerNames(this.getEngNames(appoint)); //工程师姓名列表
content.add(record);
}
// 组装
OrderServiceListResp res = new OrderServiceListResp();
res.setTotal(page.getTotal());
res.setPages(page.getPages());
res.setPageCurrent(page.getCurrent());
res.setPageSize(page.getSize());
res.setContent(content);
return Result.success(res);
}
public List<OrderAppointment> GetOrderAppointment(List<String> orderIds) {
// 获取指派单列表
LambdaQueryWrapper<OrderAppointment> lqw = new LambdaQueryWrapper<>();
lqw.in(OrderAppointment::getOrderId, orderIds);
return orderAppointmentDao.selectList(lqw);
}
public HashMap<String, List<OrderAppointment>> PackOrderAppointment(List<OrderAppointment> orders){
HashMap<String, List<OrderAppointment>> map = new HashMap<>();
// 根据订单ID-子订单降序排序
Comparator<OrderAppointment> byOrderIdDesc = Comparator.comparing(OrderAppointment::getOrderId, String.CASE_INSENSITIVE_ORDER).reversed();
Comparator<OrderAppointment> bySuborderIdDesc = Comparator.comparing(OrderAppointment::getSuborderId, String.CASE_INSENSITIVE_ORDER).reversed();
Comparator<OrderAppointment> comp = byOrderIdDesc.thenComparing(bySuborderIdDesc);
List<OrderAppointment> results = orders.stream().sorted(comp).collect(Collectors.toList());
Set<String> set = new HashSet<>();
for(OrderAppointment o: results){
set.add(o.getOrderId());
}
for (String s: set){
map.put(s, new ArrayList<OrderAppointment>());
}
// 根据订单ID-子订单分组, 只取一组子订单分组
String flagOrderId = "";
String flagSuborderId = "";
for (OrderAppointment o: results) {
}
// TODO
return map;
}
private Integer getEngNum(List<OrderAppointment> orders){
/*获取工程师数量*/
return orders.size();
}
private String getEngNames(List<OrderAppointment> orders) {
/*获取工程师姓名列表*/
List<String> names = new ArrayList<>();
for (OrderAppointment o: orders) {
names.add(o.getEngineerName());
}
return String.join("、", names);
}
public Timestamp GetTimestampFromDate(String date){
return Timestamp.valueOf(date + " 00:00:00");
}
}
......@@ -17,6 +17,12 @@ spring:
import:
- optional:nacos:project-order.yaml
- optional:nacos:datasource-config.yaml
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://10.10.0.116:3306/saas_aftersale_test?serverTimezone=UTC
username: root
password: NhZjIxNzNhNTU5OGE4M
type: com.alibaba.druid.pool.DruidDataSource
seata:
application-id: ${spring.application.name}
......@@ -26,3 +32,11 @@ seata:
project-order-group: default
grouplist:
default: seata-server:8091
mybatis-plus:
global-config:
db-config:
id-type: auto
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!