From 5d46e0ff88980e6ce6957a3708a71157902d8061 Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期五, 14 三月 2025 13:10:52 +0800
Subject: [PATCH] UPDATE

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java |  441 +++++++++++++++++++++++++++---------------------------
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java        |    4 
 2 files changed, 223 insertions(+), 222 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java
index f1dbb69..c5899fb 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java
@@ -69,238 +69,236 @@
     public MdcEfficiencyVo efficiencyList(String userId, MdcEfficiencyReportQueryVo vo) {
         MdcEfficiencyVo result = new MdcEfficiencyVo();
         List<MdcEfficiencyListDto> listDtos = new ArrayList<>();
-        List<String> equipmentIds = new ArrayList<>();
-        if (StringUtils.isNotEmpty(vo.getParentId()) && StringUtils.isEmpty(vo.getEquipmentId())) {
-            if ("2".equals(vo.getTypeTree())) {
-                // 閮ㄩ棬灞傜骇
-                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, vo.getParentId());
-            } else {
-                // 浜х嚎灞傜骇
-                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, vo.getParentId());
-            }
-        } else if (StringUtils.isNotEmpty(vo.getEquipmentId())) {
-            // 鍗曞彴璁惧淇℃伅
-            vo.setEquipmentIdList(Collections.singletonList(vo.getEquipmentId()));
-        } else {
-            // 鏌ヨ鐢ㄦ埛鎷ユ湁鐨勬墍鏈夎澶囦俊鎭�
-            if ("2".equals(vo.getTypeTree())) {
-                // 閮ㄩ棬灞傜骇
-                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null);
-            } else {
-                // 浜х嚎灞傜骇
-                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null);
-            }
-        }
+
+        // 鑾峰彇璁惧 ID 鍒楄〃
+        List<String> equipmentIds = getEquipmentIds(userId, vo);
         if (vo.getEquipmentIdList() == null || vo.getEquipmentIdList().isEmpty()) {
             vo.setEquipmentIdList(equipmentIds);
         }
 
+        // 鑾峰彇鏃ユ湡鍒楄〃
         List<String> dates = DateUtils.getDatesStringList2(DateUtils.getShortDate2(vo.getStartTime()), DateUtils.getShortDate2(vo.getEndTime()));
         result.setDates(dates);
 
-        // 鍒╃敤鐜囩瓑绾�
+        // 鑾峰彇璁惧鍒╃敤鐜囧垪琛�
         List<MdcUtilizationRate> mdcUtilizationRateList = mdcUtilizationRateService.listByType("lyl");
 
+        // 濡傛灉璁惧 ID 鍒楄〃涓虹┖锛岀洿鎺ヨ繑鍥�
         if (vo.getEquipmentIdList() == null || vo.getEquipmentIdList().isEmpty()) {
             result.setMdcEfficiencyList(listDtos);
-        } else {
-
-            List<String> equipmentIdList = mdcEquipmentService.listEquipmentId(vo);
-            if (equipmentIdList != null && !equipmentIdList.isEmpty()) {
-                vo.setEquipmentIdList(equipmentIdList);
-            } else {
-                result.setMdcEfficiencyList(listDtos);
-                return result;
-            }
-
-            // 鏌ヨ鍒╃敤鐜囨暟鎹�
-            List<MdcEfficiencyDto> efficiencyList = mdcEfficiencyReportMapper.efficiencyList(vo);
-            // 灏佽缁撴灉
-            if ("2".equals(vo.getTypeTree())) {
-                // 閮ㄩ棬灞傜骇
-                List<MdcEquDepDto> equipmentList = mdcEquipmentService.findEquDepList(vo.getEquipmentIdList());
-                // 鏌ヨ鎵�鏈夐儴闂ㄤ俊鎭�
-                List<SysDepart> departList = sysDepartService.list(new LambdaQueryWrapper<SysDepart>().ne(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_1.toString()).orderByAsc(SysDepart::getDepartOrder));
-
-                for (MdcEquDepDto mdcEquDepDto : equipmentList) {
-                    MdcEfficiencyListDto mdcEfficiencyListDto = new MdcEfficiencyListDto();
-                    mdcEfficiencyListDto.setEquipmentId(mdcEquDepDto.getEquipmentId());
-                    mdcEfficiencyListDto.setEquipmentName(mdcEquDepDto.getEquipmentName());
-                    mdcEfficiencyListDto.setEquipmentType(mdcEquDepDto.getEquipmentType());
-                    mdcEfficiencyListDto.setEquipmentModel(mdcEquDepDto.getEquipmentModel());
-                    switch (mdcEquDepDto.getOrgType()) {
-                        case "1":
-                            mdcEfficiencyListDto.setLevel1(mdcEquDepDto.getDepartName());
-                            break;
-                        case "2":
-                            mdcEfficiencyListDto.setLevel2(mdcEquDepDto.getDepartName());
-                            break;
-                        case "3":
-                            mdcEfficiencyListDto.setLevel3(mdcEquDepDto.getDepartName());
-                            break;
-                        default:
-                    }
-
-                    SysDepart sysDepart = departList.stream().filter(depart -> depart.getId().equals(mdcEquDepDto.getParentId())).findAny().orElse(null);
-                    if (sysDepart != null) {
-                        switch (sysDepart.getOrgType()) {
-                            case "1":
-                                mdcEfficiencyListDto.setLevel1(sysDepart.getDepartName());
-                                break;
-                            case "2":
-                                mdcEfficiencyListDto.setLevel2(sysDepart.getDepartName());
-                                break;
-                            case "3":
-                                mdcEfficiencyListDto.setLevel3(sysDepart.getDepartName());
-                                break;
-                            default:
-                        }
-                        if (StringUtils.isNotEmpty(sysDepart.getParentId())) {
-                            departList.stream().filter(depart -> depart.getId().equals(sysDepart.getParentId())).findAny().ifPresent(depart1 -> {
-                                switch (depart1.getOrgType()) {
-                                    case "1":
-                                        mdcEfficiencyListDto.setLevel1(depart1.getDepartName());
-                                        break;
-                                    case "2":
-                                        mdcEfficiencyListDto.setLevel2(depart1.getDepartName());
-                                        break;
-                                    case "3":
-                                        mdcEfficiencyListDto.setLevel3(depart1.getDepartName());
-                                        break;
-                                    default:
-                                }
-                            });
-                        }
-                    }
-                    List<MdcEfficiencyResultDto> list = new ArrayList<>();
-                    MdcEfficiencyResultDto mdcEfficiencyResultDto = new MdcEfficiencyResultDto();
-                    MdcEfficiencyResultDto mdcEfficiencyResultDto1 = new MdcEfficiencyResultDto();
-                    mdcEfficiencyResultDto1.setTheDate("鍚堣");
-                    mdcEfficiencyResultDto.setTheDate("骞冲潎鍊�");
-                    for (String date : dates) {
-                        list.add(this.efficiencyRate(efficiencyList, date, mdcEquDepDto.getEquipmentId(), mdcUtilizationRateList, mdcEfficiencyResultDto));
-                    }
-                    mdcEfficiencyResultDto1.setProcessLong(mdcEfficiencyResultDto.getProcessLong());
-                    mdcEfficiencyResultDto.setProcessLong(mdcEfficiencyResultDto.getProcessLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
-                    mdcEfficiencyResultDto.setUtilizationRate(mdcEfficiencyResultDto.getUtilizationRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP));
-                    mdcEfficiencyResultDto1.setUtilizationRate(mdcEfficiencyResultDto.getUtilizationRate());
-                    mdcEfficiencyResultDto.setStartRate(mdcEfficiencyResultDto.getStartRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP));
-                    mdcEfficiencyResultDto1.setStartRate(mdcEfficiencyResultDto.getStartRate());
-                    mdcEfficiencyResultDto.setOpenRate(mdcEfficiencyResultDto.getOpenRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP));
-                    mdcEfficiencyResultDto1.setOpenRate(mdcEfficiencyResultDto.getOpenRate());
-                    mdcEfficiencyResultDto1.setOpenLong(mdcEfficiencyResultDto.getOpenLong());
-                    mdcEfficiencyResultDto.setOpenLong(mdcEfficiencyResultDto.getOpenLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
-                    mdcEfficiencyResultDto1.setWaitLong(mdcEfficiencyResultDto.getWaitLong());
-                    mdcEfficiencyResultDto.setWaitLong(mdcEfficiencyResultDto.getWaitLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
-                    mdcEfficiencyResultDto1.setCloseLong(mdcEfficiencyResultDto.getCloseLong());
-                    mdcEfficiencyResultDto.setCloseLong(mdcEfficiencyResultDto.getCloseLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
-                    long rate = mdcEfficiencyResultDto.getUtilizationRate().multiply(new BigDecimal("100")).longValue();
-                    for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) {
-                        if (rate >= mdcUtilizationRate.getMinimumRange() && rate < mdcUtilizationRate.getMaximumRange()) {
-                            mdcEfficiencyResultDto.setColor(mdcUtilizationRate.getRateParameterColor());
-                            mdcEfficiencyResultDto1.setColor(mdcUtilizationRate.getRateParameterColor());
-                        }
-                    }
-                    list.add(mdcEfficiencyResultDto1);
-                    list.add(mdcEfficiencyResultDto);
-                    mdcEfficiencyListDto.setDataList(list);
-                    listDtos.add(mdcEfficiencyListDto);
-                }
-            } else {
-                // 浜х嚎灞傜骇
-                List<MdcEquProDto> equipmentList = mdcEquipmentService.findEquProList(vo.getEquipmentIdList());
-                // 鏌ヨ鎵�鏈変骇绾夸俊鎭�
-                List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().ne(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_1.toString()).orderByAsc(MdcProduction::getProductionOrder));
-
-                for (MdcEquProDto mdcEquProDto : equipmentList) {
-                    MdcEfficiencyListDto mdcEfficiencyListDto = new MdcEfficiencyListDto();
-                    mdcEfficiencyListDto.setEquipmentId(mdcEquProDto.getEquipmentId());
-                    mdcEfficiencyListDto.setEquipmentName(mdcEquProDto.getEquipmentName());
-                    mdcEfficiencyListDto.setEquipmentType(mdcEquProDto.getEquipmentType());
-                    mdcEfficiencyListDto.setEquipmentModel(mdcEquProDto.getEquipmentModel());
-                    switch (mdcEquProDto.getOrgType()) {
-                        case "1":
-                            mdcEfficiencyListDto.setLevel1(mdcEquProDto.getProductionName());
-                            break;
-                        case "2":
-                            mdcEfficiencyListDto.setLevel2(mdcEquProDto.getProductionName());
-                            break;
-                        case "3":
-                            mdcEfficiencyListDto.setLevel3(mdcEquProDto.getProductionName());
-                            break;
-                        default:
-                    }
-                    MdcProduction mdcProduction = productionList.stream().filter(production -> production.getId().equals(mdcEquProDto.getParentId())).findAny().orElse(null);
-                    if (mdcProduction != null) {
-                        switch (mdcProduction.getOrgType()) {
-                            case "1":
-                                mdcEfficiencyListDto.setLevel1(mdcProduction.getProductionName());
-                                break;
-                            case "2":
-                                mdcEfficiencyListDto.setLevel2(mdcProduction.getProductionName());
-                                break;
-                            case "3":
-                                mdcEfficiencyListDto.setLevel3(mdcProduction.getProductionName());
-                                break;
-                            default:
-                        }
-                        if (StringUtils.isNotEmpty(mdcProduction.getParentId())) {
-                            productionList.stream().filter(production -> production.getId().equals(mdcProduction.getParentId())).findAny().ifPresent(production1 -> {
-                                switch (production1.getOrgType()) {
-                                    case "1":
-                                        mdcEfficiencyListDto.setLevel1(production1.getProductionName());
-                                        break;
-                                    case "2":
-                                        mdcEfficiencyListDto.setLevel2(production1.getProductionName());
-                                        break;
-                                    case "3":
-                                        mdcEfficiencyListDto.setLevel3(production1.getProductionName());
-                                        break;
-                                    default:
-                                }
-                            });
-                        }
-                    }
-                    List<MdcEfficiencyResultDto> list = new ArrayList<>();
-                    MdcEfficiencyResultDto mdcEfficiencyResultDto = new MdcEfficiencyResultDto();
-                    MdcEfficiencyResultDto mdcEfficiencyResultDto1 = new MdcEfficiencyResultDto();
-                    mdcEfficiencyResultDto1.setTheDate("鍚堣");
-                    mdcEfficiencyResultDto.setTheDate("骞冲潎鍊�");
-                    for (String date : dates) {
-                        list.add(this.efficiencyRate(efficiencyList, date, mdcEquProDto.getEquipmentId(), mdcUtilizationRateList, mdcEfficiencyResultDto));
-                    }
-                    mdcEfficiencyResultDto1.setProcessLong(mdcEfficiencyResultDto.getProcessLong());
-                    mdcEfficiencyResultDto.setProcessLong(mdcEfficiencyResultDto.getProcessLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
-                    mdcEfficiencyResultDto.setUtilizationRate(mdcEfficiencyResultDto.getUtilizationRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP));
-                    mdcEfficiencyResultDto1.setUtilizationRate(mdcEfficiencyResultDto.getUtilizationRate());
-                    mdcEfficiencyResultDto.setStartRate(mdcEfficiencyResultDto.getStartRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP));
-                    mdcEfficiencyResultDto1.setStartRate(mdcEfficiencyResultDto.getStartRate());
-                    mdcEfficiencyResultDto.setOpenRate(mdcEfficiencyResultDto.getOpenRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP));
-                    mdcEfficiencyResultDto1.setOpenRate(mdcEfficiencyResultDto.getOpenRate());
-                    mdcEfficiencyResultDto1.setOpenLong(mdcEfficiencyResultDto.getOpenLong());
-                    mdcEfficiencyResultDto.setOpenLong(mdcEfficiencyResultDto.getOpenLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
-                    mdcEfficiencyResultDto1.setWaitLong(mdcEfficiencyResultDto.getWaitLong());
-                    mdcEfficiencyResultDto.setWaitLong(mdcEfficiencyResultDto.getWaitLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
-                    mdcEfficiencyResultDto1.setCloseLong(mdcEfficiencyResultDto.getCloseLong());
-                    mdcEfficiencyResultDto.setCloseLong(mdcEfficiencyResultDto.getCloseLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
-                    long rate = mdcEfficiencyResultDto.getUtilizationRate().multiply(new BigDecimal("100")).longValue();
-                    for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) {
-                        if (rate >= mdcUtilizationRate.getMinimumRange() && rate < mdcUtilizationRate.getMaximumRange()) {
-                            mdcEfficiencyResultDto.setColor(mdcUtilizationRate.getRateParameterColor());
-                            mdcEfficiencyResultDto1.setColor(mdcUtilizationRate.getRateParameterColor());
-                        }
-                    }
-                    list.add(mdcEfficiencyResultDto1);
-                    list.add(mdcEfficiencyResultDto);
-                    mdcEfficiencyListDto.setDataList(list);
-                    listDtos.add(mdcEfficiencyListDto);
-                }
-            }
-            result.setMdcEfficiencyList(listDtos);
+            return result;
         }
+
+        // 鑾峰彇璁惧 ID 鍒楄〃
+        List<String> equipmentIdList = mdcEquipmentService.listEquipmentId(vo);
+        if (equipmentIdList == null || equipmentIdList.isEmpty()) {
+            result.setMdcEfficiencyList(listDtos);
+            return result;
+        }
+
+        vo.setEquipmentIdList(equipmentIdList);
+
+        // 鏌ヨ璁惧鏁堢巼鏁版嵁
+        List<MdcEfficiencyDto> efficiencyList = mdcEfficiencyReportMapper.efficiencyList(vo);
+
+        // 鏍规嵁绫诲瀷鏍戝鐞嗕笉鍚岀殑灞傜骇
+        if ("2".equals(vo.getTypeTree())) {
+            // 閮ㄩ棬灞傜骇
+            listDtos = processDepartmentLevel(vo, efficiencyList, dates, mdcUtilizationRateList);
+        } else {
+            // 浜х嚎灞傜骇
+            listDtos = processProductionLevel(vo, efficiencyList, dates, mdcUtilizationRateList);
+        }
+
+        result.setMdcEfficiencyList(listDtos);
+
         // 娣诲姞鍚堣鍊煎拰骞冲潎鍊�
+        addSummaryAndAverage(result, listDtos, mdcUtilizationRateList);
+
+        return result;
+    }
+
+    /**
+     * 鑾峰彇璁惧 ID 鍒楄〃
+     */
+    private List<String> getEquipmentIds(String userId, MdcEfficiencyReportQueryVo vo) {
+        if (StringUtils.isNotEmpty(vo.getParentId()) && StringUtils.isEmpty(vo.getEquipmentId())) {
+            return "2".equals(vo.getTypeTree())
+                    ? mdcEquipmentService.getEquipmentIdsByDepart(userId, vo.getParentId())
+                    : mdcEquipmentService.getEquipmentIdsProduction(userId, vo.getParentId());
+        } else if (StringUtils.isNotEmpty(vo.getEquipmentId())) {
+            vo.setEquipmentIdList(Collections.singletonList(vo.getEquipmentId()));
+            return Collections.emptyList();
+        } else {
+            return "2".equals(vo.getTypeTree())
+                    ? mdcEquipmentService.getEquipmentIdsByDepart(userId, null)
+                    : mdcEquipmentService.getEquipmentIdsProduction(userId, null);
+        }
+    }
+
+    /**
+     * 澶勭悊閮ㄩ棬灞傜骇
+     */
+    private List<MdcEfficiencyListDto> processDepartmentLevel(MdcEfficiencyReportQueryVo vo, List<MdcEfficiencyDto> efficiencyList, List<String> dates, List<MdcUtilizationRate> mdcUtilizationRateList) {
+        List<MdcEquDepDto> equipmentList = mdcEquipmentService.findEquDepList(vo.getEquipmentIdList());
+        List<SysDepart> departList = sysDepartService.list(new LambdaQueryWrapper<SysDepart>()
+                .ne(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_1.toString())
+                .orderByAsc(SysDepart::getDepartOrder));
+
+        return equipmentList.stream().map(mdcEquDepDto -> {
+            MdcEfficiencyListDto mdcEfficiencyListDto = createEfficiencyListDto(mdcEquDepDto);
+            setDepartmentLevels(mdcEfficiencyListDto, mdcEquDepDto, departList);
+            mdcEfficiencyListDto.setDataList(processEfficiencyData(efficiencyList, dates, mdcEquDepDto.getEquipmentId(), mdcUtilizationRateList));
+            return mdcEfficiencyListDto;
+        }).collect(Collectors.toList());
+    }
+
+    /**
+     * 澶勭悊浜х嚎灞傜骇
+     */
+    private List<MdcEfficiencyListDto> processProductionLevel(MdcEfficiencyReportQueryVo vo, List<MdcEfficiencyDto> efficiencyList, List<String> dates, List<MdcUtilizationRate> mdcUtilizationRateList) {
+        List<MdcEquProDto> equipmentList = mdcEquipmentService.findEquProList(vo.getEquipmentIdList());
+        List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>()
+                .ne(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_1.toString())
+                .orderByAsc(MdcProduction::getProductionOrder));
+
+        return equipmentList.stream().map(mdcEquProDto -> {
+            MdcEfficiencyListDto mdcEfficiencyListDto = createEfficiencyListDto(mdcEquProDto);
+            setProductionLevels(mdcEfficiencyListDto, mdcEquProDto, productionList);
+            mdcEfficiencyListDto.setDataList(processEfficiencyData(efficiencyList, dates, mdcEquProDto.getEquipmentId(), mdcUtilizationRateList));
+            return mdcEfficiencyListDto;
+        }).collect(Collectors.toList());
+    }
+
+    /**
+     * 鍒涘缓 MdcEfficiencyListDto 瀵硅薄
+     */
+    private MdcEfficiencyListDto createEfficiencyListDto(MdcEquDepDto mdcEquDepDto) {
+        MdcEfficiencyListDto dto = new MdcEfficiencyListDto();
+        dto.setEquipmentId(mdcEquDepDto.getEquipmentId());
+        dto.setEquipmentName(mdcEquDepDto.getEquipmentName());
+        dto.setEquipmentType(mdcEquDepDto.getEquipmentType());
+        dto.setEquipmentModel(mdcEquDepDto.getEquipmentModel());
+        return dto;
+    }
+
+    private MdcEfficiencyListDto createEfficiencyListDto(MdcEquProDto mdcEquProDto) {
+        MdcEfficiencyListDto dto = new MdcEfficiencyListDto();
+        dto.setEquipmentId(mdcEquProDto.getEquipmentId());
+        dto.setEquipmentName(mdcEquProDto.getEquipmentName());
+        dto.setEquipmentType(mdcEquProDto.getEquipmentType());
+        dto.setEquipmentModel(mdcEquProDto.getEquipmentModel());
+        return dto;
+    }
+
+    /**
+     * 璁剧疆閮ㄩ棬灞傜骇淇℃伅
+     */
+    private void setDepartmentLevels(MdcEfficiencyListDto dto, MdcEquDepDto mdcEquDepDto, List<SysDepart> departList) {
+        switch (mdcEquDepDto.getOrgType()) {
+            case "1": dto.setLevel1(mdcEquDepDto.getDepartName()); break;
+            case "2": dto.setLevel2(mdcEquDepDto.getDepartName()); break;
+            case "3": dto.setLevel3(mdcEquDepDto.getDepartName()); break;
+        }
+
+        Optional<SysDepart> sysDepart = departList.stream().filter(depart -> depart.getId().equals(mdcEquDepDto.getParentId())).findAny();
+        sysDepart.ifPresent(depart -> {
+            switch (depart.getOrgType()) {
+                case "1": dto.setLevel1(depart.getDepartName()); break;
+                case "2": dto.setLevel2(depart.getDepartName()); break;
+                case "3": dto.setLevel3(depart.getDepartName()); break;
+            }
+            if (StringUtils.isNotEmpty(depart.getParentId())) {
+                departList.stream().filter(d -> d.getId().equals(depart.getParentId())).findAny().ifPresent(parent -> {
+                    switch (parent.getOrgType()) {
+                        case "1": dto.setLevel1(parent.getDepartName()); break;
+                        case "2": dto.setLevel2(parent.getDepartName()); break;
+                        case "3": dto.setLevel3(parent.getDepartName()); break;
+                    }
+                });
+            }
+        });
+    }
+
+    /**
+     * 璁剧疆閮ㄩ棬灞傜骇淇℃伅
+     */
+    private void setProductionLevels(MdcEfficiencyListDto dto, MdcEquProDto mdcEquProDto, List<MdcProduction> productionList) {
+        switch (mdcEquProDto.getOrgType()) {
+            case "1": dto.setLevel1(mdcEquProDto.getProductionName()); break;
+            case "2": dto.setLevel2(mdcEquProDto.getProductionName()); break;
+            case "3": dto.setLevel3(mdcEquProDto.getProductionName()); break;
+        }
+
+        Optional<MdcProduction> mdcProduction = productionList.stream().filter(production -> production.getId().equals(mdcEquProDto.getParentId())).findAny();
+        mdcProduction.ifPresent(production -> {
+            switch (production.getOrgType()) {
+                case "1": dto.setLevel1(production.getProductionName()); break;
+                case "2": dto.setLevel2(production.getProductionName()); break;
+                case "3": dto.setLevel3(production.getProductionName()); break;
+            }
+            if (StringUtils.isNotEmpty(production.getParentId())) {
+                productionList.stream().filter(p -> p.getId().equals(production.getParentId())).findAny().ifPresent(parent -> {
+                    switch (parent.getOrgType()) {
+                        case "1": dto.setLevel1(parent.getProductionName()); break;
+                        case "2": dto.setLevel2(parent.getProductionName()); break;
+                        case "3": dto.setLevel3(parent.getProductionName()); break;
+                    }
+                });
+            }
+        });
+    }
+
+    /**
+     * 澶勭悊璁惧鏁堢巼鏁版嵁
+     */
+    private List<MdcEfficiencyResultDto> processEfficiencyData(List<MdcEfficiencyDto> efficiencyList, List<String> dates, String equipmentId, List<MdcUtilizationRate> mdcUtilizationRateList) {
+        List<MdcEfficiencyResultDto> list = new ArrayList<>();
+        MdcEfficiencyResultDto avgDto = new MdcEfficiencyResultDto();
+        avgDto.setTheDate("骞冲潎鍊�");
+        MdcEfficiencyResultDto sumDto = new MdcEfficiencyResultDto();
+        sumDto.setTheDate("鍚堣");
+
+        for (String date : dates) {
+            MdcEfficiencyResultDto dto = efficiencyRate(efficiencyList, date, equipmentId, mdcUtilizationRateList, avgDto);
+            list.add(dto);
+        }
+
+        sumDto.setProcessLong(avgDto.getProcessLong());
+        avgDto.setProcessLong(avgDto.getProcessLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
+        avgDto.setUtilizationRate(avgDto.getUtilizationRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP));
+        sumDto.setUtilizationRate(avgDto.getUtilizationRate());
+        avgDto.setStartRate(avgDto.getStartRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP));
+        sumDto.setStartRate(avgDto.getStartRate());
+        avgDto.setOpenRate(avgDto.getOpenRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP));
+        sumDto.setOpenRate(avgDto.getOpenRate());
+        sumDto.setOpenLong(avgDto.getOpenLong());
+        avgDto.setOpenLong(avgDto.getOpenLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
+        sumDto.setWaitLong(avgDto.getWaitLong());
+        avgDto.setWaitLong(avgDto.getWaitLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
+        sumDto.setCloseLong(avgDto.getCloseLong());
+        avgDto.setCloseLong(avgDto.getCloseLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP));
+
+        long rate = avgDto.getUtilizationRate().multiply(new BigDecimal("100")).longValue();
+        for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) {
+            if (rate >= mdcUtilizationRate.getMinimumRange() && rate < mdcUtilizationRate.getMaximumRange()) {
+                avgDto.setColor(mdcUtilizationRate.getRateParameterColor());
+                sumDto.setColor(mdcUtilizationRate.getRateParameterColor());
+            }
+        }
+
+        list.add(sumDto);
+        list.add(avgDto);
+        return list;
+    }
+
+    /**
+     * 娣诲姞鍚堣鍊煎拰骞冲潎鍊�
+     */
+    private void addSummaryAndAverage(MdcEfficiencyVo result, List<MdcEfficiencyListDto> listDtos, List<MdcUtilizationRate> mdcUtilizationRateList) {
         result.getDates().add("鍚堣");
         result.getDates().add("骞冲潎鍊�");
+
         MdcEfficiencyListDto sum = new MdcEfficiencyListDto();
         sum.setLevel1("鍚堣");
         sum.setLevel2("鍚堣");
@@ -308,8 +306,7 @@
         sum.setEquipmentId("鍚堣");
         sum.setEquipmentName("鍚堣");
         sum.setEquipmentType("鍚堣");
-        //璁$畻鍚堣鍊�
-        sum.setDataList(this.calculateTotal(result.getMdcEfficiencyList(), mdcUtilizationRateList));
+        sum.setDataList(calculateTotal(listDtos, mdcUtilizationRateList));
 
         MdcEfficiencyListDto avg = new MdcEfficiencyListDto();
         avg.setLevel1("骞冲潎鍊�");
@@ -318,13 +315,13 @@
         avg.setEquipmentId("骞冲潎鍊�");
         avg.setEquipmentName("骞冲潎鍊�");
         avg.setEquipmentType("骞冲潎鍊�");
-        //璁$畻骞冲潎鍊�
-        avg.setDataList(this.calculateAverage(result.getMdcEfficiencyList(), mdcUtilizationRateList));
+        avg.setDataList(calculateAverage(listDtos, mdcUtilizationRateList));
+
         result.getMdcEfficiencyList().add(sum);
         result.getMdcEfficiencyList().add(avg);
-        return result;
     }
 
+
     /**
      * 璁$畻骞冲潎鍊�
      *
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
index 0f7bbce..e6ba463 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
@@ -422,15 +422,19 @@
                         } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "spindlespeed".equals(englishName) && oporation == 3) {
                             // ZUOLAN璁惧涓昏酱杞�熷瓧娈祍pindlespeed
                             value = String.valueOf(((new Random().nextInt(35)) + 1) * 100);
+                            mdcEquipmentDto.setSpindlespeed(value);
                         } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "spindleload".equals(englishName) && oporation == 3) {
                             // ZUOLAN璁惧涓昏酱璐熻嵎瀛楁spindleload
                             value = String.valueOf(Integer.valueOf(new Random().nextInt(21)));
+                            mdcEquipmentDto.setSpindleload(value);
                         } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "spindlebeilv".equals(englishName) && oporation == 3) {
                             // ZUOLAN璁惧涓昏酱鍊嶇巼瀛楁spindlebeilv
                             value = String.valueOf((new Random().nextInt(13)) * 10);
+                            mdcEquipmentDto.setSpindlebeilv(value);
                         } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "feedbeilv".equals(englishName) && oporation == 3) {
                             // ZUOLAN璁惧杩涚粰鍊嶇巼瀛楁feedbeilv
                             value = String.valueOf((new Random().nextInt(13)) * 10);
+                            mdcEquipmentDto.setFeedbeilv(value);
                         } else if ("spindle_current".equals(englishName)) {
                             // 鍏朵粬璁惧鐢垫祦瀛楁
                             String devicePower = mdcEquipment.getDevicePower();

--
Gitblit v1.9.3