|
@@ -1,12 +1,28 @@
|
|
|
package org.jeecg.modules.ProdPlan.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import org.jeecg.common.system.vo.DictModel;
|
|
|
import org.jeecg.modules.ProdPlan.entity.DelayProduct;
|
|
|
+import org.jeecg.modules.ProdPlan.entity.DeliveredQuantity;
|
|
|
import org.jeecg.modules.ProdPlan.mapper.DelayProductMapper;
|
|
|
import org.jeecg.modules.ProdPlan.service.IDelayProductService;
|
|
|
+import org.jeecg.modules.ProdPlan.service.IDeliveredQuantityService;
|
|
|
+import org.jeecg.modules.system.service.ISysDictService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.temporal.WeekFields;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* @Description: 延期商品
|
|
|
* @Author: jeecg-boot
|
|
@@ -16,4 +32,108 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
@Service
|
|
|
public class DelayProductServiceImpl extends ServiceImpl<DelayProductMapper, DelayProduct> implements IDelayProductService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysDictService sysDictService;
|
|
|
+ @Autowired
|
|
|
+ private IDeliveredQuantityService deliveredQuantityService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getDelayProductByWeek() {
|
|
|
+ Integer week = LocalDate.now().get(WeekFields.ISO.weekOfYear());
|
|
|
+ //获取饼图数据,前一周,当前周及后两周
|
|
|
+ //String pieQueryWeeks = "W" + (week - 1) + ", W" + week + "', 'W" + (week + 1) + "', 'W" + (week + 2) + "'";
|
|
|
+ QueryWrapper<DelayProduct> pieQueryWrapper = new QueryWrapper<>();
|
|
|
+ List<String> pieWeeks = new ArrayList<>();
|
|
|
+ pieWeeks.add("W" + (week - 1));
|
|
|
+ pieWeeks.add("W" + week);
|
|
|
+ pieWeeks.add("W" + (week + 1));
|
|
|
+ pieWeeks.add("W" + (week + 2));
|
|
|
+ pieQueryWrapper.lambda().in(DelayProduct::getWeek, pieWeeks);
|
|
|
+ List<DelayProduct> pieProducts = this.list(pieQueryWrapper);
|
|
|
+
|
|
|
+ Map<String, String> ruleColor = sysDictService.queryDictItemsByCode("rule_color").stream().collect(Collectors.toMap(DictModel::getText, DictModel::getValue));
|
|
|
+ Map<String, Long> pieInside = pieProducts.stream().collect(Collectors.groupingBy(DelayProduct::getComment1, Collectors.summingLong(item -> item.getPo())));
|
|
|
+ Map<String, Long> pieOutside = pieProducts.stream().collect(Collectors.groupingBy(DelayProduct::getRemark, Collectors.summingLong(item -> item.getPo())));
|
|
|
+ JSONArray pieInsideJSON = new JSONArray();
|
|
|
+ for(String key : pieInside.keySet()) {
|
|
|
+ JSONObject item = new JSONObject();
|
|
|
+ item.put("name", key);
|
|
|
+ item.put("value", pieInside.get(key));
|
|
|
+ Map<String, String> color = new HashMap<>();
|
|
|
+ color.put("color", "#" + ruleColor.get(key).substring(0, 6));
|
|
|
+ item.put("itemStyle", color);
|
|
|
+ pieInsideJSON.add(item);
|
|
|
+ }
|
|
|
+ JSONArray pieOutsideJSON = new JSONArray();
|
|
|
+ for(String key : pieOutside.keySet()) {
|
|
|
+ JSONObject item = new JSONObject();
|
|
|
+ item.put("name", key);
|
|
|
+ item.put("value", pieOutside.get(key));
|
|
|
+ Map<String, String> color = new HashMap<>();
|
|
|
+ color.put("color", "#" + ruleColor.get(key).substring(0, 6));
|
|
|
+ item.put("itemStyle", color);
|
|
|
+ pieOutsideJSON.add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取柱状图数据,前两周,当前周及后两周
|
|
|
+ //String columnarQueryWeeks = "'W" + (week - 3) + "', 'W" + (week - 2) + "', 'W" + (week - 1) + "', 'W" + week + "', 'W" + week + 1 + "', 'W" + week + 2 + "'";
|
|
|
+ List<String> columnarWeeks = new ArrayList<>();
|
|
|
+ columnarWeeks.add("W" + (week - 3));
|
|
|
+ columnarWeeks.add("W" + (week - 2));
|
|
|
+ columnarWeeks.add("W" + (week - 1));
|
|
|
+ columnarWeeks.add("W" + week);
|
|
|
+ columnarWeeks.add("W" + (week + 1));
|
|
|
+ columnarWeeks.add("W" + (week + 2));
|
|
|
+ QueryWrapper<DelayProduct> columnarQueryWrapper = new QueryWrapper<>();
|
|
|
+ columnarQueryWrapper.lambda().in(DelayProduct::getWeek, columnarWeeks);
|
|
|
+ List<DelayProduct> columnarProducts = this.list(columnarQueryWrapper);
|
|
|
+
|
|
|
+ List<DeliveredQuantity> deliveredQuantityList = this.deliveredQuantityService.list();
|
|
|
+ Map<String, Integer> deliveredQuantityMap = deliveredQuantityList.stream().collect(Collectors.toMap(DeliveredQuantity::getWeek, DeliveredQuantity::getQuantity));
|
|
|
+
|
|
|
+ //记录每个部门的每周总和以及每周所有部门的总和
|
|
|
+ Map<String, Integer> total = new HashMap<>();
|
|
|
+ Map<String, Map<String, Integer>> columnarData = new HashMap<>();
|
|
|
+ columnarProducts.forEach(item -> {
|
|
|
+ Map<String, Integer> weekData = columnarData.get(item.getComment1()) == null ? new HashMap<>() : columnarData.get(item.getComment1());
|
|
|
+ if(columnarWeeks.contains(item.getWeek())) {
|
|
|
+ Integer weekValue = weekData.get(item.getWeek()) == null ? 0 : weekData.get(item.getWeek());
|
|
|
+ weekValue += item.getPo();
|
|
|
+ weekData.put(item.getWeek(), weekValue);
|
|
|
+ total.put(item.getWeek(), total.get(item.getWeek()) == null ? item.getPo() : item.getPo() + total.get(item.getWeek()));
|
|
|
+ }
|
|
|
+ columnarData.put(item.getComment1(), weekData);
|
|
|
+ });
|
|
|
+
|
|
|
+ //整合数据,方便前端取,计算loss率
|
|
|
+ Map<String, List<Integer>> columnarResult = new HashMap<>();
|
|
|
+ List<Double> lossResult = new ArrayList<>();
|
|
|
+ for(String key : columnarData.keySet()) {
|
|
|
+ List<Integer> weeks = new ArrayList<>();
|
|
|
+ columnarWeeks.forEach(item -> {
|
|
|
+ Integer weekTotal = columnarData.get(key).get(item);
|
|
|
+ weeks.add(weekTotal);
|
|
|
+ });
|
|
|
+ columnarResult.put(key, weeks);
|
|
|
+ }
|
|
|
+ columnarWeeks.forEach(item -> {
|
|
|
+ if(deliveredQuantityMap.get(item) != null && deliveredQuantityMap.get(item) != 0 && total.get(item) != null) {
|
|
|
+ lossResult.add((double)total.get(item) / deliveredQuantityMap.get(item));
|
|
|
+
|
|
|
+ }else {
|
|
|
+ lossResult.add(Double.valueOf(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("pieInside", pieInsideJSON);
|
|
|
+ result.put("pieOutside", pieOutsideJSON);
|
|
|
+ result.put("columnarWeeks", columnarWeeks);
|
|
|
+ result.put("lossData", lossResult);
|
|
|
+ result.put("columnarData", columnarResult);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|