Commit f79879b9 by wangli

修改

1 parent 5409e6e1
...@@ -11,6 +11,12 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -11,6 +11,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -21,19 +27,19 @@ import java.util.stream.Stream; ...@@ -21,19 +27,19 @@ import java.util.stream.Stream;
public class EngineerTimelineServiceImpl implements EngineerTimelineService { public class EngineerTimelineServiceImpl implements EngineerTimelineService {
@Autowired @Autowired
private OrderInfoMPDao orderInfoMPDao; private OrderInfoDao orderInfoDao;
@Autowired @Autowired
private EngineerInfoMPDao engineerInfoMPDao; private EngineerInfoDao engineerInfoDao;
@Autowired @Autowired
private WarehouseInfoMPDao warehouseInfoMPDao; private WarehouseInfoDao warehouseInfoDao;
@Autowired @Autowired
private OrgGroupMPDao orgGroupMPDao; private OrgGroupDao orgGroupDao;
@Autowired @Autowired
private OrderEventMPDao orderEventMPDao; private EntityManager entityManager;
@Transactional @Transactional
@Override @Override
...@@ -42,14 +48,14 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService { ...@@ -42,14 +48,14 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService {
LocalDate localDate = TimeUtils.IsoDate2LocalDate(date); LocalDate localDate = TimeUtils.IsoDate2LocalDate(date);
// 工程師信息 // 工程師信息
EngineerInfo engineerInfo = engineerInfoMPDao.getByEngineerCode(engineerCode); EngineerInfoEntity engineerInfo = engineerInfoDao.getByEngineerCode(engineerCode);
// 获取工程师date日的订单数据 // 获取工程师date日的订单数据
List<OrderInfo> orders = this.selectEngineerOrders(engineerCode, localDate); List<OrderInfoEntity> orders = this.selectEngineerOrders(engineerCode, localDate);
// 获取工程师已完成的timeline数据 // 获取工程师已完成的timeline数据
List<String> orderIds = orders.stream().map(OrderInfo::getOrderId).collect(Collectors.toList()); List<String> orderIds = orders.stream().map(OrderInfoEntity::getOrderId).collect(Collectors.toList());
List<OrderEvent> timelines = this.engineerTimelines(orderIds, date); List<OrderEventEntity> timelines = this.engineerTimelines(orderIds, date);
// 获取客户地址 // 获取客户地址
HashMap<String, String> orderLocations = this.orderRequestsLocation(orders); HashMap<String, String> orderLocations = this.orderRequestsLocation(orders);
...@@ -67,30 +73,39 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService { ...@@ -67,30 +73,39 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService {
return Result.success(res); return Result.success(res);
} }
private List<OrderInfo> selectEngineerOrders(String engineerCode, LocalDate dt){ private List<OrderInfoEntity> selectEngineerOrders(String engineerCode, LocalDate dt){
LambdaQueryWrapper<OrderInfo> lqw = new LambdaQueryWrapper<>(); List<OrderInfoEntity> orders = orderInfoDao.findByEngineerCodeAndDtAndAppointmentStatusIn(
lqw.eq(OrderInfo::getDt, dt); engineerCode, dt, List.of("PRE", "CONFIRM"));
lqw.eq(OrderInfo::getEngineerCode, engineerCode); return orders.stream().filter(o -> !o.getOrderStatus().equals("CANCEL")).collect(Collectors.toList());
lqw.ne(OrderInfo::getAppointmentStatus, "INIT");
lqw.ne(OrderInfo::getOrderStatus, "CANCEL");
return orderInfoMPDao.selectList(lqw);
} }
private List<OrderEvent> engineerTimelines(List<String> orderIds, String date){ public List<OrderEventEntity> engineerTimelines(List<String> orderIds, String date) {
// 获取工程师timeline List<String> events = Arrays.asList("分站取还配件", "已出发", "加单");
List<String> events = Stream.of("分站取还配件", "已出发", "加单").collect(Collectors.toList());
LambdaQueryWrapper<OrderEvent> lqw = new LambdaQueryWrapper<>(); CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
lqw.in(OrderEvent::getOrderId, orderIds); CriteriaQuery<OrderEventEntity> criteriaQuery = criteriaBuilder.createQuery(OrderEventEntity.class);
lqw.ge(OrderEvent::getHappen, date+" 00:00:00"); Root<OrderEvent> root = criteriaQuery.from(OrderEvent.class);
lqw.le(OrderEvent::getHappen, date + " 23:59:59");
lqw.in(OrderEvent::getEvent, events); List<Predicate> predicates = new ArrayList<>();
return orderEventMPDao.selectList(lqw);
predicates.add(root.get("orderId").in(orderIds));
predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("happen"), date + " 00:00:00"));
predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("happen"), date + " 23:59:59"));
predicates.add(root.get("event").in(events));
criteriaQuery.where(predicates.toArray(new Predicate[0]));
TypedQuery<OrderEventEntity> typedQuery = entityManager.createQuery(criteriaQuery);
List<OrderEventEntity> result = typedQuery.getResultList();
return result;
} }
private HashMap<String, String> orderRequestsLocation(List<OrderInfo> orders) {
private HashMap<String, String> orderRequestsLocation(List<OrderInfoEntity> orders) {
// 获取客户地址location // 获取客户地址location
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
for(OrderInfo o: orders){ for(OrderInfoEntity o: orders){
map.put(o.getOrderId(), String.format("%s,%s", o.getX(), o.getY())); map.put(o.getOrderId(), String.format("%s,%s", o.getX(), o.getY()));
} }
return map; return map;
...@@ -98,38 +113,30 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService { ...@@ -98,38 +113,30 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService {
private String getWarehouseLocation(String branchId) { private String getWarehouseLocation(String branchId) {
// 获取配送站location // 获取配送站location
LambdaQueryWrapper<OrgWarehouseInfo> lqw = new LambdaQueryWrapper<>(); List<OrgWarehouseInfoEntity> wares = warehouseInfoDao.findByBranchId(branchId);
lqw.eq(OrgWarehouseInfo::getBranchId, branchId); OrgWarehouseInfoEntity w = wares.get(0);
List<OrgWarehouseInfo> wares = warehouseInfoMPDao.selectList(lqw);
OrgWarehouseInfo w = wares.get(0);
return String.format("%s,%s", w.getX(), w.getY()); return String.format("%s,%s", w.getX(), w.getY());
} }
private String getEngineerBranchId(String engineerCode) { private String getEngineerBranchId(String engineerCode) {
LambdaQueryWrapper<EngineerInfo> lqw = new LambdaQueryWrapper<>(); EngineerInfoEntity e = engineerInfoDao.getByEngineerCode(engineerCode);
lqw.select(EngineerInfo::getGroupId);
lqw.eq(EngineerInfo::getEngineerCode, engineerCode);
EngineerInfo e = engineerInfoMPDao.selectOne(lqw);
if (e == null) { if (e == null) {
return ""; return "";
} }
OrgGroupEntity g = orgGroupDao.getByGroupId(e.getGroupId());
LambdaQueryWrapper<OrgGroup> lqw2 = new LambdaQueryWrapper<>();
lqw2.select(OrgGroup::getBranchId);
lqw2.eq(OrgGroup::getGroupId, e.getGroupId());
OrgGroup g = orgGroupMPDao.selectOne(lqw2);
return (g==null)? "": g.getBranchId(); return (g==null)? "": g.getBranchId();
} }
private List<EngineerTimelineResp.DynamicItem> packItems(List<OrderEvent> timelines, List<OrderInfo> orders, HashMap<String, String> locations, String warehouseLocation) { private List<EngineerTimelineResp.DynamicItem> packItems(List<OrderEventEntity> timelines, List<OrderInfoEntity> orders,
HashMap<String, String> locations, String warehouseLocation) {
int index = 0; int index = 0;
String order_id, title, type, text, location; String order_id, title, type, text, location;
List<EngineerTimelineResp.DynamicItem> items = new ArrayList<>(); List<EngineerTimelineResp.DynamicItem> items = new ArrayList<>();
Set<String> s = new HashSet<>(); Set<String> s = new HashSet<>();
for (OrderEvent t: timelines){ for (OrderEventEntity t: timelines){
EngineerTimelineResp.DynamicItem item = new EngineerTimelineResp.DynamicItem(); EngineerTimelineResp.DynamicItem item = new EngineerTimelineResp.DynamicItem();
if (t.getEvent().equals("分站取还配件")) { if (t.getEvent().equals("分站取还配件")) {
...@@ -146,7 +153,7 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService { ...@@ -146,7 +153,7 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService {
continue; continue;
} }
item.setTitle(title); item.setTitle(title);
item.setTime(TimeUtils.IsoTimestamp2DateTime(t.getHappen())); item.setTime(TimeUtils.IsoLocalDateTime2String(t.getHappen()));
item.setStatus(1); item.setStatus(1);
item.setText(text); item.setText(text);
...@@ -157,8 +164,8 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService { ...@@ -157,8 +164,8 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService {
s.add(t.getOrderId() + t.getSuborderId()); s.add(t.getOrderId() + t.getSuborderId());
} }
List<OrderInfo> records = orders.stream().sorted(Comparator.comparing(OrderInfo::getPlanStartTime)).collect(Collectors.toList()); List<OrderInfoEntity> records = orders.stream().sorted(Comparator.comparing(OrderInfoEntity::getPlanStartTime)).collect(Collectors.toList());
for(OrderInfo o: records){ for(OrderInfoEntity o: records){
order_id = o.getOrderId() + o.getSubId(); order_id = o.getOrderId() + o.getSubId();
if (s.contains(order_id)) { if (s.contains(order_id)) {
continue; continue;
...@@ -166,7 +173,7 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService { ...@@ -166,7 +173,7 @@ public class EngineerTimelineServiceImpl implements EngineerTimelineService {
index += 1; index += 1;
EngineerTimelineResp.DynamicItem item = new EngineerTimelineResp.DynamicItem(); EngineerTimelineResp.DynamicItem item = new EngineerTimelineResp.DynamicItem();
item.setTitle(String.format("第%d单出发", index)); item.setTitle(String.format("第%d单出发", index));
item.setTime(TimeUtils.IsoTimestamp2DateTime(o.getPlanStartTime())); item.setTime(TimeUtils.IsoLocalDateTime2String(o.getPlanStartTime()));
item.setStatus(0); item.setStatus(0);
item.setText(String.format("%d", index)); item.setText(String.format("%d", index));
item.setLocation(locations.get(o.getOrderId())); item.setLocation(locations.get(o.getOrderId()));
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!