zhangxin пре 1 месец
родитељ
комит
d2210461bf

+ 1 - 1
prod-line-imes/src/main/java/com/huaxia/imes/controller/MesLineController.java

@@ -88,7 +88,7 @@ public class MesLineController extends BaseController {
      * @return
      */
     @GetMapping("/count_day")
-    public R<Map<String,Long>> list(){
+    public R<Map<String,Map<String,Long>>> list(){
         return mesLineService.countDay();
     }
 

+ 31 - 20
prod-line-imes/src/main/java/com/huaxia/imes/service/MesLineService.java

@@ -125,7 +125,7 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
      *
      * @return
      */
-    public R<Map<String, Long>> countDay() {
+    public R<Map<String, Map<String,Long>>> countDay() {
 
         //获取当前时间
         LocalDate now = LocalDate.now();
@@ -137,11 +137,11 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
         LambdaQueryWrapper<MesLine> wr = new LambdaQueryWrapper<>();
         wr.between(MesLine::getCreateTime, mondayOfWeek, sundayOfWeek);
         List<MesLine> boy = mesLineMapper.selectList(wr);
-        Map<String, Long> map = new LinkedHashMap<>();//格式 key:星期几 value:数量
+        Map<String, Map<String,Long>> map = new LinkedHashMap<>();//格式 key:星期几 value:数量
         // 初始化Map中的键,并设置默认值为0
         for (DayOfWeek dayOfWeek : DayOfWeek.values()) {
             String dayOfWeekName = dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CHINA);
-            map.put(dayOfWeekName, 0L);
+            map.put(dayOfWeekName, new HashMap<>());
         }
         //判断集合
         if (boy != null && !boy.isEmpty()) {
@@ -150,8 +150,15 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
                     //获取星期几
                     LocalDate date = mesLine.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                     String week = date.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.CHINA);
-                    Long count = mesLine.getCurrentQty();
-                    map.put(week, map.getOrDefault(week, 0L) + count);
+                    Long count = mesLine.getCurrentQty();//获取产量
+                    String lineName = mesLine.getLineName();//获取产线名称
+                    if (StringUtils.isBlank(lineName)) {
+                        continue;
+                    }
+                    // 获取内层Map
+                    Map<String, Long> innerMap = map.get(week);
+                    // 更新内层Map中的产量
+                    innerMap.put(lineName, innerMap.getOrDefault(lineName, 0L) + count);
                 } catch (Exception e) {
                     log.warn("数据转换异常", e);
                 }
@@ -192,21 +199,22 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
                         Map<String, Object> lineData = lineSummary.computeIfAbsent(lineName, k -> new HashMap<>());
                         //累加产量
                         Long totalOutput = (Long) lineData.getOrDefault("产量", 0L);
-                        Long count = mesLine.getCurrentQty();
-                        lineData.put("产量", totalOutput + count);
+                        Long count = mesLine.getCurrentQty();//产量=产量(包含合格数量)+不合格数量
+                        Long poorQty = mesLine.getPoorQty();//不合格数量
+                        totalOutput+=(count+poorQty);
+                        lineData.put("产量", totalOutput);
                         //累加不合格数量
                         Long totalPoorQty = (Long) lineData.getOrDefault("不合格数量", 0L);
                         Long currentPoorQty = mesLine.getPoorQty();
-                        lineData.put("不合格数量", totalPoorQty + currentPoorQty);
+                        totalPoorQty += currentPoorQty;
+                        lineData.put("不合格数量", totalPoorQty);
                         //计算合格数量
                         Long totalQualifiedQty = (Long) lineData.getOrDefault("合格数量", 0L);
-                        Long updatedTotalOutput = (Long) lineData.get("产量");
-                        Long updatedTotalPoorQty = (Long) lineData.get("不合格数量");
-                        totalQualifiedQty = updatedTotalOutput - updatedTotalPoorQty;
-                        lineData.put("合格数量", totalQualifiedQty);
+                        totalQualifiedQty += count;
+                        lineData.put("合格数量",totalQualifiedQty);
                         //更新合格率
-                        if (updatedTotalOutput > 0) {
-                            double qualificationRate = ((double) totalQualifiedQty / (double) updatedTotalOutput) * 100;
+                        if (totalOutput > 0) {
+                            double qualificationRate = ((double) totalQualifiedQty / (double) totalOutput) * 100;
                             lineData.put("合格率", String.format("%.2f%%", qualificationRate));
                         } else {
                             lineData.put("合格率", "0.00%");
@@ -280,17 +288,20 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
 
                     // 累加总产量
                     Long totalOutput = (Long) dayStats.getOrDefault("产量", 0L);
-                    totalOutput += mesLine.getCurrentQty();
+                    Long count = mesLine.getCurrentQty();//产量+不合格数
+                    Long poorQty = mesLine.getPoorQty();//不合格数量
+                    totalOutput+=(count+poorQty);
                     dayStats.put("产量", totalOutput);
 
                     // 累加不合格数量
-                    Long totalPoorQty = (Long) dayStats.getOrDefault("不合格数", 0L);
+                    Long totalPoorQty = (Long) dayStats.getOrDefault("不合格数", 0L);
                     totalPoorQty += mesLine.getPoorQty();
-                    dayStats.put("不合格数", totalPoorQty);
+                    dayStats.put("不合格数", totalPoorQty);
 
-                    // 计算合格数量
-                    Long totalQualifiedQty = totalOutput - totalPoorQty;
-                    dayStats.put("合格数", totalQualifiedQty);
+                    //计算合格数量
+                    Long totalQualifiedQty = (Long) dayStats.getOrDefault("合格数量", 0L);
+                    totalQualifiedQty += count;
+                    dayStats.put("合格数量",totalQualifiedQty);
 
                     // 更新合格率
                     if (totalOutput > 0) {