Commit 383cc4a8 by wangli

新增实现工单统计

1 parent 90bf1153
...@@ -9,8 +9,11 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -9,8 +9,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/pea-order") @RequestMapping("/pea-order")
...@@ -29,4 +32,15 @@ public class WorkbenchController { ...@@ -29,4 +32,15 @@ public class WorkbenchController {
} }
return res; return res;
} }
@GetMapping("/workbench/summary")
public Result<?> workbenchSummary(@RequestParam String levelType, @RequestParam String levelValue, @RequestParam LocalDate date) {
Result<?> res = null;
try{
res = workbenchService.getWorkbenchSummary(levelType, levelValue, date);
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
return res;
}
} }
...@@ -4,6 +4,10 @@ import com.dituhui.pea.common.Result; ...@@ -4,6 +4,10 @@ import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dto.EngineersGanttReqDTO; import com.dituhui.pea.order.dto.EngineersGanttReqDTO;
import com.dituhui.pea.order.dto.OrderChangeListReqDTO; import com.dituhui.pea.order.dto.OrderChangeListReqDTO;
import java.time.LocalDate;
public interface WorkbenchService { public interface WorkbenchService {
Result<?> getOrderChangeList(OrderChangeListReqDTO orderChangeListReqDTO); Result<?> getOrderChangeList(OrderChangeListReqDTO orderChangeListReqDTO);
Result<?> getWorkbenchSummary(String levelType, String levelValue, LocalDate dt);
} }
package com.dituhui.pea.order.service.impl; package com.dituhui.pea.order.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dituhui.pea.common.Result; import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dao.*; import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.OrderChangeListReqDTO; import com.dituhui.pea.order.dto.OrderChangeListReqDTO;
import com.dituhui.pea.order.dto.OrderChangeListRespDTO; import com.dituhui.pea.order.dto.OrderChangeListRespDTO;
import com.dituhui.pea.order.dto.WorkbenchSummaryResp;
import com.dituhui.pea.order.entity.OrderChangeEntity; import com.dituhui.pea.order.entity.OrderChangeEntity;
import com.dituhui.pea.order.entity.OrderRequest;
import com.dituhui.pea.order.entity.OrderRequestEntity; import com.dituhui.pea.order.entity.OrderRequestEntity;
import com.dituhui.pea.order.service.WorkbenchService; import com.dituhui.pea.order.service.WorkbenchService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -14,8 +17,11 @@ import org.springframework.data.domain.PageRequest; ...@@ -14,8 +17,11 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
@Slf4j @Slf4j
@Service @Service
...@@ -36,6 +42,9 @@ public class WorkbenchServiceImpl implements WorkbenchService { ...@@ -36,6 +42,9 @@ public class WorkbenchServiceImpl implements WorkbenchService {
@Autowired @Autowired
private CapacityEngineerStatDao capacityEngineerStatDao; private CapacityEngineerStatDao capacityEngineerStatDao;
@Autowired
private OrderRequestMPDao orderRequestMPDao;
@Override @Override
public Result<?> getOrderChangeList(OrderChangeListReqDTO reqDTO) { public Result<?> getOrderChangeList(OrderChangeListReqDTO reqDTO) {
Pageable pageable = PageRequest.of(reqDTO.getPage() - 1, reqDTO.getSize()); Pageable pageable = PageRequest.of(reqDTO.getPage() - 1, reqDTO.getSize());
...@@ -69,4 +78,130 @@ public class WorkbenchServiceImpl implements WorkbenchService { ...@@ -69,4 +78,130 @@ public class WorkbenchServiceImpl implements WorkbenchService {
.setContent(contents); .setContent(contents);
return Result.success(respDTO); return Result.success(respDTO);
} }
@Override
public Result<?> getWorkbenchSummary(String levelType, String levelValue, LocalDate dt) {
List<WorkbenchSummaryResp.ItemDTO> items = new ArrayList<>();
HashMap<String, Integer> methodSummary = this.transAppointmentMethod(this.queryCountByAppointmentMethod(levelType, levelValue, dt));
WorkbenchSummaryResp.ItemDTO methodItem = new WorkbenchSummaryResp.ItemDTO();
methodItem.setType("order");
methodItem.setRows(this.packValueAppointmentMethod(methodSummary));
items.add(methodItem);
HashMap<String, Integer> statusSummary = this.transOrderStatus(this.queryCountByOrderStatus(levelType, levelValue, dt));
WorkbenchSummaryResp.ItemDTO statusItem = new WorkbenchSummaryResp.ItemDTO();
methodItem.setType("order");
methodItem.setRows(this.packValueOrderStatus(statusSummary));
items.add(statusItem);
WorkbenchSummaryResp res = new WorkbenchSummaryResp();
res.setSummary(items);
return Result.success(res);
}
private List<Map<String, Object>> queryCountByAppointmentMethod(String levelType, String levelValue, LocalDate dt) {
QueryWrapper<OrderRequest> wrapper = new QueryWrapper<>();
wrapper.select("appointment_method, appointment_status, COUNT(*) as count")
.lambda()
.eq(OrderRequest::getDt, dt)
.eq(levelType.equals("cluster"), OrderRequest::getOrgClusterId, levelValue)
.eq(levelType.equals("branch"), OrderRequest::getOrgBranchId, levelValue)
.eq(levelType.equals("group"), OrderRequest::getOrgGroupId, levelValue)
.groupBy(OrderRequest::getAppointmentMethod, OrderRequest::getAppointmentStatus);
return orderRequestMPDao.selectMaps(wrapper);
}
private List<Map<String, Object>> queryCountByOrderStatus(String levelType, String levelValue, LocalDate dt) {
QueryWrapper<OrderRequest> wrapper = new QueryWrapper<>();
wrapper.select("appointment_status, COUNT(*) as count")
.lambda()
.eq(OrderRequest::getDt, dt)
.eq(levelType.equals("cluster"), OrderRequest::getOrgClusterId, levelValue)
.eq(levelType.equals("branch"), OrderRequest::getOrgBranchId, levelValue)
.eq(levelType.equals("group"), OrderRequest::getOrgGroupId, levelValue)
.groupBy(OrderRequest::getAppointmentStatus);
return orderRequestMPDao.selectMaps(wrapper);
}
private HashMap<String, Integer> transAppointmentMethod(List<Map<String, Object>> results) {
HashMap<String, Integer> map = new HashMap<>();
Integer manualTotal = 0; // 人工
Integer autoTotal = 0;
Integer total = 0;
for (Map<String, Object> result : results) {
String method = (String) result.get("appointment_method");
String status = (String) result.get("appointment_status");
Integer count = (int) result.get("count");
total += count;
if (method.equals("MANUAL")) {
manualTotal += count;
} else if (method.startsWith("AUTO_")) {
autoTotal += count;
}
if (method.equals("MANUAL") && status.equals("NOT_ASSIGNED")) {
map.put("manualDealing", count);
} else if (method.equals("AUTO_") && status.equals("NOT_ASSIGNED")) {
map.put("autoDealing", count);
}
}
map.put("manualTotal", manualTotal);
map.put("autoTotal", autoTotal);
map.put("total", total);
return map;
}
private HashMap<String, Integer> transOrderStatus(List<Map<String, Object>> results) {
HashMap<String, Integer> map = new HashMap<>();
for (Map<String, Object> result : results) {
String status = (String) result.get("appointment_status");
Integer count = (int) result.get("count");
map.put(status, count);
}
return map;
}
private List<WorkbenchSummaryResp.ValueDTO> packValueAppointmentMethod(HashMap<String, Integer> summary) {
List<WorkbenchSummaryResp.ValueDTO> items = new ArrayList<>();
String url = "/dispatchBench/index";
Integer manualDealing = summary.getOrDefault("manualDealing", 0);
Integer manualTotal = summary.getOrDefault("manualTotal", 0);
Integer autoDealing = summary.getOrDefault("autoDealing", 0);
Integer autoTotal = summary.getOrDefault("autoTotal", 0);
Integer total = summary.getOrDefault("total", 0);
items.add(new WorkbenchSummaryResp.ValueDTO("待人工处理", manualDealing.toString(), manualTotal.toString(), "#FF8000", url));
items.add(new WorkbenchSummaryResp.ValueDTO("待自动处理", autoDealing.toString(), autoTotal.toString(), "#469967", url));
items.add(new WorkbenchSummaryResp.ValueDTO("全部订单", null, total.toString(), null, url));
return items;
}
private List<WorkbenchSummaryResp.ValueDTO> packValueOrderStatus(HashMap<String, Integer> summary) {
List<WorkbenchSummaryResp.ValueDTO> items = new ArrayList<>();
String url = "/dispatchBench/index";
Integer assigned = summary.getOrDefault("ASSIGNED", 0);
Integer contacted = summary.getOrDefault("CONTACTED", 0);
Integer departed = summary.getOrDefault("DEPARTED", 0);
Integer dealing = assigned + contacted + departed;
Integer started = summary.getOrDefault("STARTED", 0);
Integer cancel = summary.getOrDefault("CANCELED", 0);
Integer finished = summary.getOrDefault("FINISHED", 0);
items.add(new WorkbenchSummaryResp.ValueDTO("待上门", dealing.toString(), null, "#469967", url));
items.add(new WorkbenchSummaryResp.ValueDTO("服务中", started.toString(), null, "#016FFF", url));
items.add(new WorkbenchSummaryResp.ValueDTO("已完成", finished.toString(), null, null, url));
items.add(new WorkbenchSummaryResp.ValueDTO("已取消", cancel.toString(), null, null, url));
items.add(new WorkbenchSummaryResp.ValueDTO("已改约", "0", null, null, url));
items.add(new WorkbenchSummaryResp.ValueDTO("已延误", "0", null, "#FF3D44", url));
return items;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!