Commit 3c9980d8 by wangli

修改

1 parent c279415f
......@@ -3,7 +3,6 @@ package com.dituhui.pea.order.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result;
......@@ -25,6 +24,9 @@ import java.util.stream.Collectors;
public class ScheduleServiceImpl implements ScheduleService {
@Autowired
private OrderInfoMPDao orderInfoMPDao;
@Autowired
private OrgTeamMPDao orgTeamMPDao;
@Autowired
......@@ -34,12 +36,6 @@ public class ScheduleServiceImpl implements ScheduleService {
private OrgGroupMPDao orgGroupMPDao;
@Autowired
private OrderRequestMPDao orderRequestMPDao;
@Autowired
private OrderAppointmentMPDao orderAppointmentMPDao;
@Autowired
private EngineerInfoMPDao engineerInfoMPDao;
@Autowired
......@@ -71,6 +67,7 @@ public class ScheduleServiceImpl implements ScheduleService {
@Override
public Result<?> getScheduleOverview(long page, long size, LocalDate date, String levelType, List<String> levelIds) {
// 排班结果
// 获取team列表, 以team排序分页
IPage<OrgTeam> pg = this.queryOrgTeams(page, size, levelType, levelIds);
......@@ -89,15 +86,16 @@ public class ScheduleServiceImpl implements ScheduleService {
team.setLevel("team");
// 获取改team订单列表
List<OrderRequest> orders = this.queryOrderRequests(t.getTeamId(), date);
List<OrderInfo> orders = this.queryOrderRequests(t.getTeamId(), date);
team.setOrder(this.getTeamOrderSum(orders, skillMapping));
// 技术员指派单列表
Map<String, List<OrderAppointment>> engineerOrders = new HashMap<>();
Map<String, List<OrderInfo>> engineerOrders = new HashMap<>();
if (ListUtils.isNotEmpty(orders)) {
List<String> orderRequestIds = orders.stream().map(OrderRequest::getOrderId).collect(Collectors.toList());
List<OrderAppointment> orderAppointments = this.queryOrderAppointments(orderRequestIds, date);
engineerOrders = orderAppointments.stream().collect(Collectors.groupingBy(OrderAppointment::getEngineerCode));
List<String> orderRequestIds = orders.stream().map(OrderInfo::getOrderId).collect(Collectors.toList());
List<OrderInfo> orderAppointments = orderInfoMPDao.selectByDtAndOrderIds(date, orderRequestIds);
orderAppointments.sort(Comparator.comparing(OrderInfo::getEngineerCode));
engineerOrders = orderAppointments.stream().collect(Collectors.groupingBy(OrderInfo::getEngineerCode));
}
// 获取team技术员列表
......@@ -115,10 +113,10 @@ public class ScheduleServiceImpl implements ScheduleService {
String engineerCode = entry.getKey();
EngineerInfo engineerInfo = entry.getValue().get(0);
List<String> orderIds = engineerOrders.getOrDefault(engineerCode, new ArrayList<>()).stream().map(OrderAppointment::getOrderId).collect(Collectors.toList());
List<String> orderIds = engineerOrders.getOrDefault(engineerCode, new ArrayList<>()).stream().map(OrderInfo::getOrderId).collect(Collectors.toList());
List<OrderRequest> orders2 = new ArrayList<>();
for (OrderRequest o : orders) {
List<OrderInfo> orders2 = new ArrayList<>();
for (OrderInfo o : orders) {
if (orderIds.contains(o.getOrderId())) {
orders2.add(o);
}
......@@ -153,28 +151,29 @@ public class ScheduleServiceImpl implements ScheduleService {
@Override
public Result<?> getScheduleEngineerOverview(LocalDate date, String engineerCode) throws BusinessException {
// 获取技术员已排班概况
EngineerInfo engineer = engineerInfoMPDao.getByEngineerCode(engineerCode);
if (engineer == null) {
throw new BusinessException("分销员不存在");
}
List<LabelValueDTO> emptyTips = new ArrayList<>();
List<OrderAppointment> orderAppointments = orderAppointmentMPDao.selectByEngineerCodeAndDt(engineerCode, date);
List<OrderInfo> orderAppointments = orderInfoMPDao.selectByEngineerCodeAndDtAndAppointmentStatus(engineerCode, date, "CONFIRM");
List<TimeLineDTO> timelines = new ArrayList<>();
for (OrderAppointment o : orderAppointments) {
for (OrderInfo o : orderAppointments) {
TimeLineDTO item = new TimeLineDTO();
item.setOrderId(o.getOrderId());
item.setPreStatus(o.getPreStatus());
item.setAppointmentStatus(o.getStatus());
item.setStartTime(TimeUtils.IsoTimestamp2DateTime(o.getExpectStartTime()));
item.setEndTime(TimeUtils.IsoTimestamp2DateTime(o.getExpectEndTime()));
item.setAppointmentStatus(o.getAppointmentStatus());
item.setStartTime(TimeUtils.IsoTimestamp2DateTime(o.getPlanStartTime()));
item.setEndTime(TimeUtils.IsoTimestamp2DateTime(o.getPlanEndTime()));
item.setTips(emptyTips);
timelines.add(item);
}
Map<String, List<OrderAppointment>> statusGroup = orderAppointments.stream().collect(Collectors.groupingBy(OrderAppointment::getStatus));
List<OrderAppointment> empty = new ArrayList<>();
Integer countPending = statusGroup.getOrDefault("ASSIGNED", empty).size() + statusGroup.getOrDefault("CONTACTED", empty).size() + statusGroup.getOrDefault("DEPARTED", empty).size();
Map<String, List<OrderInfo>> statusGroup = orderAppointments.stream().collect(Collectors.groupingBy(OrderInfo::getServiceStatus));
List<OrderInfo> empty = new ArrayList<>();
Integer countPending = statusGroup.getOrDefault("INIT", empty).size() + statusGroup.getOrDefault("CONTACTED", empty).size() + statusGroup.getOrDefault("PENDING", empty).size();
List<LabelValueDTO> dynamics = new ArrayList<>();
dynamics.add(new LabelValueDTO("姓名", engineer.getName()));
......@@ -190,13 +189,13 @@ public class ScheduleServiceImpl implements ScheduleService {
dynamics.add(new LabelValueDTO("工作时间", "08:00-18:00"));
dynamics.add(new LabelValueDTO("交通工具", "电动车"));
List<String> orderIds = orderAppointments.stream().map(OrderAppointment::getOrderId).collect(Collectors.toList());
List<OrderRequest> orderRequests = new ArrayList<>();
List<String> orderIds = orderAppointments.stream().map(OrderInfo::getOrderId).collect(Collectors.toList());
List<OrderInfo> orderRequests = new ArrayList<>();
if (orderIds != null && !orderIds.isEmpty()) {
orderRequests = orderRequestMPDao.selectByOrderIds(orderIds);
orderRequests = orderInfoMPDao.selectByDtAndOrderIds(date, orderIds);
}
List<ScheduleEngineerOverviewResp.Order> orders = new ArrayList<>();
for (OrderRequest o : orderRequests) {
for (OrderInfo o : orderRequests) {
ScheduleEngineerOverviewResp.Order item = new ScheduleEngineerOverviewResp.Order();
item.setOrderId(o.getOrderId());
item.setLocation(String.format("%s,%s", o.getX(), o.getY()));
......@@ -255,31 +254,23 @@ public class ScheduleServiceImpl implements ScheduleService {
return orgTeamEngineerMPDao.selectList(lqw);
}
private List<OrderRequest> queryOrderRequests(String teamId, LocalDate date) {
LambdaQueryWrapper<OrderRequest> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderRequest::getDt, date);
lqw.in(OrderRequest::getOrgTeamId, teamId);
lqw.eq(OrderRequest::getAppointmentStatus, "ASSIGNED");
return orderRequestMPDao.selectList(lqw);
private List<OrderInfo> queryOrderRequests(String teamId, LocalDate date) {
LambdaQueryWrapper<OrderInfo> lqw = new LambdaQueryWrapper<>();
lqw.eq(OrderInfo::getDt, date);
lqw.in(OrderInfo::getOrgTeamId, teamId);
lqw.eq(OrderInfo::getAppointmentStatus, "CONFIRM");
return orderInfoMPDao.selectList(lqw);
}
private List<OrderAppointment> queryOrderAppointments(List<String> orderIds, LocalDate date) {
LambdaQueryWrapper<OrderAppointment> lqw = new LambdaQueryWrapper<>();
lqw.in(OrderAppointment::getOrderId, orderIds);
lqw.eq(OrderAppointment::getDt, date);
lqw.orderByAsc(OrderAppointment::getEngineerCode);
return orderAppointmentMPDao.selectList(lqw);
}
private ScheduleOverviewResp.OrderSum getTeamOrderSum(List<OrderRequest> orders, HashMap<String, String> skillMapping) {
private ScheduleOverviewResp.OrderSum getTeamOrderSum(List<OrderInfo> orders, HashMap<String, String> skillMapping) {
ScheduleOverviewResp.OrderSum s = new ScheduleOverviewResp.OrderSum();
List<OrderRequest> emtpy = new ArrayList<>();
List<OrderInfo> emtpy = new ArrayList<>();
HashMap<String, Integer> skillCounter = new HashMap<>();
Map<String, List<OrderRequest>> cc = orders.stream().collect(Collectors.groupingBy(OrderRequest::getSkill));
for(Map.Entry<String, List<OrderRequest>> entry: cc.entrySet()){
Map<String, List<OrderInfo>> cc = orders.stream().collect(Collectors.groupingBy(OrderInfo::getSkill));
for (Map.Entry<String, List<OrderInfo>> entry : cc.entrySet()) {
String skill = entry.getKey();
Integer count = entry.getValue().size();
String skillCategory = skillMapping.get(skill);
......@@ -313,15 +304,15 @@ public class ScheduleServiceImpl implements ScheduleService {
// 获取skill映射
HashMap<String, String> skillMap = this.getSkillCategoryMapping();
QueryWrapper<OrderRequest> wrapper = new QueryWrapper<>();
QueryWrapper<OrderInfo> wrapper = new QueryWrapper<>();
wrapper.select("skill, COUNT(*) as count")
.lambda()
.eq(OrderRequest::getDt, date)
.in(levelType.equals("cluster"), OrderRequest::getOrgClusterId, levelValue)
.in(levelType.equals("branch"), OrderRequest::getOrgBranchId, levelValue)
.in(levelType.equals("group"), OrderRequest::getOrgGroupId, levelValue)
.groupBy(OrderRequest::getSkill);
List<Map<String, Object>> results = orderRequestMPDao.selectMaps(wrapper);
.eq(OrderInfo::getDt, date)
.in(levelType.equals("cluster"), OrderInfo::getOrgClusterId, levelValue)
.in(levelType.equals("branch"), OrderInfo::getOrgBranchId, levelValue)
.in(levelType.equals("group"), OrderInfo::getOrgGroupId, levelValue)
.groupBy(OrderInfo::getSkill);
List<Map<String, Object>> results = orderInfoMPDao.selectMaps(wrapper);
for (Map<String, Object> result : results) {
String skill = (String) result.get("skill");
Long countValue = (Long) result.get("count");
......@@ -340,15 +331,15 @@ public class ScheduleServiceImpl implements ScheduleService {
HashMap<String, Integer> groupCategoryMapping = this.getGroupCategoryMapping(levelType, levelValue);
QueryWrapper<OrderRequest> wrapper = new QueryWrapper<>();
QueryWrapper<OrderInfo> wrapper = new QueryWrapper<>();
wrapper.select("org_group_id, COUNT(*) as count")
.lambda()
.eq(OrderRequest::getDt, date)
.in(levelType.equals("cluster"), OrderRequest::getOrgClusterId, levelValue)
.in(levelType.equals("branch"), OrderRequest::getOrgBranchId, levelValue)
.in(levelType.equals("group"), OrderRequest::getOrgGroupId, levelValue)
.groupBy(OrderRequest::getOrgGroupId);
List<Map<String, Object>> results = orderRequestMPDao.selectMaps(wrapper);
.eq(OrderInfo::getDt, date)
.in(levelType.equals("cluster"), OrderInfo::getOrgClusterId, levelValue)
.in(levelType.equals("branch"), OrderInfo::getOrgBranchId, levelValue)
.in(levelType.equals("group"), OrderInfo::getOrgGroupId, levelValue)
.groupBy(OrderInfo::getOrgGroupId);
List<Map<String, Object>> results = orderInfoMPDao.selectMaps(wrapper);
for (Map<String, Object> result : results) {
String groupId = (String) result.get("org_group_id");
Long countValue = (Long) result.get("count");
......@@ -364,15 +355,15 @@ public class ScheduleServiceImpl implements ScheduleService {
private HashMap<String, Integer> queryCountByAppointment(LocalDate date, String levelType, List<String> levelValue) {
HashMap<String, Integer> map = new HashMap<>();
QueryWrapper<OrderRequest> wrapper = new QueryWrapper<>();
QueryWrapper<OrderInfo> wrapper = new QueryWrapper<>();
wrapper.select("appointment_method, appointment_status, COUNT(*) as count")
.lambda()
.eq(OrderRequest::getDt, date)
.in(levelType.equals("cluster"), OrderRequest::getOrgClusterId, levelValue)
.in(levelType.equals("branch"), OrderRequest::getOrgBranchId, levelValue)
.in(levelType.equals("group"), OrderRequest::getOrgGroupId, levelValue)
.groupBy(OrderRequest::getAppointmentMethod, OrderRequest::getAppointmentStatus);
List<Map<String, Object>> results = orderRequestMPDao.selectMaps(wrapper);
.eq(OrderInfo::getDt, date)
.in(levelType.equals("cluster"), OrderInfo::getOrgClusterId, levelValue)
.in(levelType.equals("branch"), OrderInfo::getOrgBranchId, levelValue)
.in(levelType.equals("group"), OrderInfo::getOrgGroupId, levelValue)
.groupBy(OrderInfo::getAppointmentMethod, OrderInfo::getAppointmentStatus);
List<Map<String, Object>> results = orderInfoMPDao.selectMaps(wrapper);
Integer autoTotal = 0;
Integer manualTotal = 0;
......@@ -480,12 +471,10 @@ public class ScheduleServiceImpl implements ScheduleService {
return items;
}
private <T> HashMap<String, List<T>> packParams(String key, T ...values) {
private <T> HashMap<String, List<T>> packParams(String key, T... values) {
HashMap<String, List<T>> map = new HashMap<>();
List<T> value = new ArrayList<>();
for(T v: values){
value.add(v);
}
Collections.addAll(value, values);
map.put(key, value);
return map;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!