Commit ec749538 by chamberone

Merge branch 'develop' of https://zhangguoping@gitlab.dituhui.com/bsh/project/pr…

…oject.git into develop
2 parents c77735cf 51cb6f03
......@@ -2,6 +2,7 @@ package com.dituhui.pea.order.controller;
import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.TimeUtils;
import com.dituhui.pea.order.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -9,8 +10,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;
import java.util.List;
import java.util.function.BooleanSupplier;
@RestController
@RequestMapping("/pea-order")
......@@ -20,11 +21,12 @@ public class ScheduleController {
private ScheduleService scheduleService;
@GetMapping("/schedule/summary")
public Result<?> getScheduleSummary(@RequestParam String date, @RequestParam String levelType, @RequestParam("levelValue") List<String> levelIds){
public Result<?> getScheduleSummary(@RequestParam String date, @RequestParam String levelType, @RequestParam("levelValue") List<String> levelIds) {
Result<?> res = null;
LocalDate localDate = TimeUtils.IsoDate2LocalDate(date);
try {
res = scheduleService.getScheduleSummary(date, levelType, levelIds);
} catch(BusinessException e) {
res = scheduleService.getScheduleSummary(localDate, levelType, levelIds);
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
return res;
......
package com.dituhui.pea.order.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import java.util.List;
@Data
public class ScheduleSummaryResp {
private List<ItemDTO> summary;
@Data
public static class ItemDTO {
private String type;
private List<ValueDTO> rows;
}
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class ValueDTO {
private String title;
private Integer value;
private String valueColor;
private String url;
public ValueDTO(String title, Integer value, String valueColor, String url){
this.title = title;
this.value = value;
this.valueColor = valueColor;
this.url = url;
}
}
}
......@@ -2,11 +2,12 @@ package com.dituhui.pea.order.service;
import com.dituhui.pea.common.Result;
import java.time.LocalDate;
import java.util.List;
public interface ScheduleService {
Result<?> getScheduleSummary(String date, String levelType, List<String> levelIds);
Result<?> getScheduleSummary(LocalDate date, String levelType, List<String> levelIds);
Result<?> getScheduleOverview(long page, long size, String date, String levelType, List<String> levelIds);
......
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.extension.plugins.pagination.Page;
import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.TimeUtils;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.LabelValueDTO;
import com.dituhui.pea.order.dto.ScheduleEngineerOverviewResp;
import com.dituhui.pea.order.dto.ScheduleOverviewResp;
import com.dituhui.pea.order.dto.TimeLineDTO;
import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -44,9 +43,31 @@ public class ScheduleServiceImpl implements ScheduleService {
@Autowired
private EngineerInfoMPDao engineerInfoMPDao;
@Autowired
private SkillInfoMPDao skillInfoMPDao;
@Override
public Result<?> getScheduleSummary(String date, String levelType, List<String> levelIds) {
return null;
public Result<?> getScheduleSummary(LocalDate date, String levelType, List<String> levelValue) {
List<ScheduleSummaryResp.ItemDTO> items = new ArrayList<>();
ScheduleSummaryResp.ItemDTO skillItem = new ScheduleSummaryResp.ItemDTO();
skillItem.setType("order");
skillItem.setRows(this.packSkillSummary(this.queryCountBySkill(date, levelType, levelValue)));
items.add(skillItem);
ScheduleSummaryResp.ItemDTO groupItem = new ScheduleSummaryResp.ItemDTO();
groupItem.setType("order");
groupItem.setRows(this.packGroupCategorySummary(this.queryCountByGroupId(date, levelType, levelValue)));
items.add(groupItem);
ScheduleSummaryResp.ItemDTO appointmentItem = new ScheduleSummaryResp.ItemDTO();
appointmentItem.setType("order");
appointmentItem.setRows(this.packAppointmentSummary(this.queryCountByAppointment(date, levelType, levelValue)));
items.add(appointmentItem);
ScheduleSummaryResp res = new ScheduleSummaryResp();
res.setSummary(items);
return Result.success(res);
}
@Override
......@@ -169,7 +190,7 @@ public class ScheduleServiceImpl implements ScheduleService {
List<String> orderIds = orderAppointments.stream().map(OrderAppointment::getOrderId).collect(Collectors.toList());
List<OrderRequest> orderRequests = new ArrayList<>();
if(orderIds!=null && !orderIds.isEmpty()) {
if (orderIds != null && !orderIds.isEmpty()) {
orderRequests = orderRequestMPDao.selectByOrderIds(orderIds);
}
List<ScheduleEngineerOverviewResp.Order> orders = new ArrayList<>();
......@@ -271,4 +292,158 @@ public class ScheduleServiceImpl implements ScheduleService {
s.setCleanNum(cc.getOrDefault("清洗", emtpy).size());
return s;
}
private HashMap<String, Integer> queryCountBySkill(LocalDate date, String levelType, List<String> levelValue) {
HashMap<String, Integer> map = new HashMap<>();
// 获取skill映射
HashMap<String, String> skillMap = this.getSkillCategoryMapping();
QueryWrapper<OrderRequest> 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);
for (Map<String, Object> result : results) {
String skill = (String) result.get("skill");
Long countValue = (Long) result.get("count");
Integer count = countValue.intValue();
String skillCategory = skillMap.get(skill);
Integer value = map.getOrDefault(skillCategory, 0);
value = value + count;
map.put(skillCategory, value);
}
return map;
}
private HashMap<Integer, Integer> queryCountByGroupId(LocalDate date, String levelType, List<String> levelValue) {
HashMap<Integer, Integer> map = new HashMap<>();
HashMap<String, Integer> groupCategoryMapping = this.getGroupCategoryMapping(levelType, levelValue);
QueryWrapper<OrderRequest> 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);
for (Map<String, Object> result : results) {
String groupId = (String) result.get("org_group_id");
Long countValue = (Long) result.get("count");
Integer count = countValue.intValue();
Integer groupCategory = groupCategoryMapping.get(groupId);
Integer value = map.getOrDefault(groupCategory, 0);
value = value + count;
map.put(groupCategory, value);
}
return map;
}
private HashMap<String, Integer> queryCountByAppointment(LocalDate date, String levelType, List<String> levelValue) {
HashMap<String, Integer> map = new HashMap<>();
QueryWrapper<OrderRequest> 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);
Integer autoTotal = 0;
Integer manualTotal = 0;
Integer notAssignTotal = 0;
for (Map<String, Object> result : results) {
String method = (String) result.get("appointment_method");
String status = (String) result.get("appointment_status");
Long countValue = (Long) result.get("count");
int count = countValue.intValue();
if (status.equals("NOT_ASSIGNED")) {
notAssignTotal += count;
continue;
}
if (method.equals("MANUAL")) {
manualTotal += count;
} else {
autoTotal += count;
}
}
map.put("autoTotal", autoTotal);
map.put("manualTotal", manualTotal);
map.put("notAssignTotal", notAssignTotal);
return map;
}
private HashMap<String, String> getSkillCategoryMapping() {
// 获取skill与skillCategory(面向前端)的映射
HashMap<String, String> skillMap = new HashMap<>();
QueryWrapper<SkillInfo> wrapper = new QueryWrapper<>();
wrapper.select("skill, skill_category")
.lambda()
.groupBy(SkillInfo::getSkill, SkillInfo::getSkillCategory);
List<Map<String, Object>> results = skillInfoMPDao.selectMaps(wrapper);
for (Map<String, Object> result : results) {
String skill = (String) result.get("skill");
String skillCategory = (String) result.get("skill_category");
skillMap.put(skill, skillCategory);
}
return skillMap;
}
private HashMap<String, Integer> getGroupCategoryMapping(String levelType, List<String> levelValue) {
HashMap<String, Integer> map = new HashMap<>();
LambdaQueryWrapper<OrgGroup> lqw = new LambdaQueryWrapper<>();
lqw.select(OrgGroup::getGroupId, OrgGroup::getCategory);
lqw.in(levelType.equals("cluster"), OrgGroup::getClusterId, levelValue);
lqw.in(levelType.equals("branch"), OrgGroup::getBranchId, levelValue);
lqw.in(levelType.equals("group"), OrgGroup::getGroupId, levelValue);
List<OrgGroup> groups = orgGroupMPDao.selectList(lqw);
for (OrgGroup g : groups) {
map.put(g.getGroupId(), g.getCategory());
}
return map;
}
private List<ScheduleSummaryResp.ValueDTO> packSkillSummary(HashMap<String, Integer> map) {
Integer sum = 0;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
sum += entry.getValue();
}
String url = "/dispatchBench/index";
List<ScheduleSummaryResp.ValueDTO> items = new ArrayList<>();
items.add(new ScheduleSummaryResp.ValueDTO("总单量", sum, "#469967", url));
items.add(new ScheduleSummaryResp.ValueDTO("安装", map.getOrDefault("安装", 0), null, url));
items.add(new ScheduleSummaryResp.ValueDTO("维修", map.getOrDefault("维修", 0), null, url));
items.add(new ScheduleSummaryResp.ValueDTO("清洁保养", map.getOrDefault("清洁保养", 0), null, url));
items.add(new ScheduleSummaryResp.ValueDTO("整改", map.getOrDefault("整改", 0), null, url));
return items;
}
private List<ScheduleSummaryResp.ValueDTO> packGroupCategorySummary(HashMap<Integer, Integer> map) {
String url = "/dispatchBench/index";
List<ScheduleSummaryResp.ValueDTO> items = new ArrayList<>();
items.add(new ScheduleSummaryResp.ValueDTO("自有", map.getOrDefault(1, 0), null, url));
items.add(new ScheduleSummaryResp.ValueDTO("网点", map.getOrDefault(2, 0), null, url));
return items;
}
private List<ScheduleSummaryResp.ValueDTO> packAppointmentSummary(HashMap<String, Integer> map) {
String url = "/dispatchBench/index";
List<ScheduleSummaryResp.ValueDTO> items = new ArrayList<>();
items.add(new ScheduleSummaryResp.ValueDTO("自动指派", map.getOrDefault("autoTotal", 0), null, url));
items.add(new ScheduleSummaryResp.ValueDTO("人工指派", map.getOrDefault("manualTotal", 0), null, url));
items.add(new ScheduleSummaryResp.ValueDTO("未指派", map.getOrDefault("notAssignTotal", 0), null, url));
return items;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!