From 5cd4558fb1a7178653d77e1a982e6f26d06b5db5 Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期一, 31 三月 2025 17:39:00 +0800 Subject: [PATCH] 中心综合利用率趋势接口 --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java | 229 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 226 insertions(+), 3 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 0d7ebe1..631c938 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 @@ -17,6 +17,7 @@ import org.jeecg.modules.system.service.IMdcProductionService; import org.jeecg.modules.system.service.ISysDepartService; import org.jeecg.modules.system.service.ISysDictService; +import org.jeecg.modules.system.vo.MdcProOptionsVo; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -1749,7 +1750,7 @@ * @return */ @Override - public Map<String, Object> equipmentEfficiencyAnalyze(EquEffVo equEffVo) { + public Map<String, Object> equipmentEfficiencyAnalyze(String userId, EquEffVo equEffVo) { Map<String, Object> result = new HashMap<>(); List<String> mdcProductionIds = new ArrayList<>(); if (StringUtils.isBlank(equEffVo.getProductionIds())) { @@ -1758,6 +1759,8 @@ mdcProductionIds.addAll(Arrays.asList(equEffVo.getProductionIds().split(","))); } List<String> allProductionIds = mdcProductionService.findChildren(mdcProductionIds); + //鏁版嵁鏉冮檺杩囨护 + allProductionIds = mdcProductionService.findProIdsByUId(userId, allProductionIds); List<MdcEquipment> equipmentList = mdcEquipmentService.findByProductionIds(allProductionIds); if (equipmentList != null && !equipmentList.isEmpty()) { List<String> equipmentIdList = equipmentList.stream().map(MdcEquipment::getEquipmentId).collect(Collectors.toList()); @@ -1770,7 +1773,7 @@ } @Override - public Map<String, Object> teamEquipmentEfficiencyAnalyze(EquEffVo equEffVo) { + public Map<String, Object> teamEquipmentEfficiencyAnalyze(String userId, EquEffVo equEffVo) { Map<String, Object> result = new HashMap<>(); // 1. 澶勭悊鐢熶骇ID List<String> mdcProductionIds = StringUtils.isBlank(equEffVo.getProductionIds()) @@ -1781,7 +1784,8 @@ if (allProductionIds.isEmpty()) { return result; // 鎻愬墠杩斿洖绌虹粨鏋� } - + //鏁版嵁鏉冮檺杩囨护 + allProductionIds = mdcProductionService.findProIdsByUId(userId, allProductionIds); // 2. 鑾峰彇璁惧鍒楄〃 List<MdcEquipment> equipmentList = StringUtils.isNotBlank(equEffVo.getTeamCodes()) ? mdcEquipmentService.findByProIdsAndTeamCode(allProductionIds, Arrays.asList(equEffVo.getTeamCodes().split(","))) @@ -1831,6 +1835,225 @@ } + @Override + public Map<String, Object> teamEfficiencyAnalyzeByMonth(String userId, EquEffVo equEffVo) { + Map<String, Object> result = new HashMap<>(); + + // 1. 鏃ユ湡澶勭悊 + LocalDate now = LocalDate.now(); + Date start = DateUtils.toDate(now.plusMonths(-6).toString(), DateUtils.STR_DATE); + Date end = DateUtils.toDate(now.plusMonths(-1).toString(), DateUtils.STR_DATE); + + List<String> monthBetween = DateUtils.getMonthBetween(start, end); + List<String> dateList = monthBetween.stream() + .map(date -> date.substring(date.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "鏈�") + .collect(Collectors.toList()); + result.put("dateList", dateList); + + // 2. 鑾峰彇浜х嚎鏁版嵁 + List<MdcProduction> mdcProductions = mdcProductionService.findMdcPros(userId, equEffVo.getProductionId()); + + // 3. 鍒濆鍖栫粨鏋滈泦 + List<TeamEquEffMonthDto> utilizationRateList = new ArrayList<>(); + List<TeamEquEffMonthDto> shiftUtilizationRateList = new ArrayList<>(); + List<TeamEquEffMonthDto> amendUtilizationRateList = new ArrayList<>(); + + // 4. 澶勭悊姣忎釜浜х嚎 + mdcProductions.forEach(mdcProduction -> { + // 4.1 鑾峰彇涓嬬骇浜х嚎骞惰繃婊� + List<String> allProductionIds = mdcProductionService.recursionChildren(mdcProduction.getId()); + // 鏁版嵁鏉冮檺杩囨护 + allProductionIds = mdcProductionService.findProIdsByUId(userId, allProductionIds); + // 4.2 鑾峰彇璁惧鍒楄〃 + List<MdcEquipment> equipmentList = mdcEquipmentService.findByProductionIds(allProductionIds); + if (equipmentList == null || equipmentList.isEmpty()) { + return; + } + //鎻愬彇id闆嗗悎 + List<String> equipmentIdList = equipmentList.stream() + .map(MdcEquipment::getEquipmentId) + .collect(Collectors.toList()); + + TeamEquEffMonthDto urDto = new TeamEquEffMonthDto(); + TeamEquEffMonthDto surDto = new TeamEquEffMonthDto(); + TeamEquEffMonthDto aurDto = new TeamEquEffMonthDto(); + urDto.setProductionName(mdcProduction.getProductionName()); + surDto.setProductionName(mdcProduction.getProductionName()); + aurDto.setProductionName(mdcProduction.getProductionName()); + List<TeamEquEffMonthChildDto> urDataList = new ArrayList<>(); + List<TeamEquEffMonthChildDto> surDataList = new ArrayList<>(); + List<TeamEquEffMonthChildDto> aurDataList = new ArrayList<>(); + + monthBetween.forEach(date -> { + TeamEquEffMonthChildDto urCDto = new TeamEquEffMonthChildDto(); + TeamEquEffMonthChildDto surCDto = new TeamEquEffMonthChildDto(); + TeamEquEffMonthChildDto aurCDto = new TeamEquEffMonthChildDto(); + String month = date.substring(date.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "鏈�"; + urCDto.setMonth(month); + surCDto.setMonth(month); + aurCDto.setMonth(month); + List<TeamEquEffDto> dataList = mdcEfficiencyReportMapper.teamEquipmentEfficiencyAnalyze(equipmentIdList, date.replaceAll("-", "")); + if (dataList != null && !dataList.isEmpty()) { + // 璁$畻骞冲潎鍊� + BigDecimal ur = dataList.stream() + .map(TeamEquEffDto::getUtilizationRate) + .reduce(BigDecimal.ZERO, BigDecimal::add) + .divide(BigDecimal.valueOf(dataList.size()), 2, RoundingMode.HALF_UP); + //鍒╃敤鐜� + urCDto.setUtilizationRate(ur); + //鐝鍒╃敤鐜� + BigDecimal sur = dataList.stream() + .map(TeamEquEffDto::getShiftUtilizationRate) + .reduce(BigDecimal.ZERO, BigDecimal::add) + .divide(BigDecimal.valueOf(dataList.size()), 2, RoundingMode.HALF_UP); + surCDto.setUtilizationRate(sur); + //鍘婚櫎鏁呴殰24灏忔椂鍒╃敤鐜� + BigDecimal aur = dataList.stream() + .map(TeamEquEffDto::getAmendUtilizationRate) + .reduce(BigDecimal.ZERO, BigDecimal::add) + .divide(BigDecimal.valueOf(dataList.size()), 2, RoundingMode.HALF_UP); + aurCDto.setUtilizationRate(aur); + } + urDataList.add(urCDto); + surDataList.add(surCDto); + aurDataList.add(aurCDto); + }); + urDto.setDataList(urDataList); + surDto.setDataList(surDataList); + aurDto.setDataList(aurDataList); + utilizationRateList.add(urDto); + shiftUtilizationRateList.add(surDto); + amendUtilizationRateList.add(aurDto); + }); + result.put("utilizationRateList", utilizationRateList); + result.put("shiftUtilizationRateList", shiftUtilizationRateList); + result.put("amendUtilizationRateList", amendUtilizationRateList); + return result; + } + + @Override + public Map<String, Object> comprehensiveRateAnalyze(String userId, EquEffVo vo) { + Map<String, Object> result = new HashMap<>(); + // 1. 鏃ユ湡澶勭悊 + LocalDate now = LocalDate.now(); + Date start = DateUtils.toDate(now.plusMonths(-12).toString(), DateUtils.STR_DATE); + Date end = DateUtils.toDate(now.plusMonths(-1).toString(), DateUtils.STR_DATE); + + List<String> monthBetween = DateUtils.getMonthBetween(start, end); + List<String> dateList = monthBetween.stream() + .map(date -> date.substring(date.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "鏈�") + .collect(Collectors.toList()); + result.put("dateList", dateList); + + // 1. 澶勭悊鐢熶骇ID + List<String> mdcProductionIds = StringUtils.isBlank(vo.getProductionIds()) + ? Collections.singletonList(vo.getProductionId()) + : Arrays.asList(vo.getProductionIds().split(",")); + + List<String> allProductionIds = mdcProductionService.findChildren(mdcProductionIds); + if (allProductionIds.isEmpty()) { + return result; // 鎻愬墠杩斿洖绌虹粨鏋� + } + //鏁版嵁鏉冮檺杩囨护 + allProductionIds = mdcProductionService.findProIdsByUId(userId, allProductionIds); + // 2. 鑾峰彇璁惧鍒楄〃 + List<MdcEquipment> equipmentList = StringUtils.isNotBlank(vo.getEquipmentType()) + ? mdcEquipmentService.findByProIdsAndType(allProductionIds, Arrays.asList(vo.getEquipmentType().split(","))) + : mdcEquipmentService.findByProductionIds(allProductionIds); + + if (equipmentList.isEmpty()) { + return result; + } + + // 3. 鏁版嵁澶勭悊 + List<String> equipmentIdList = equipmentList.stream() + .map(MdcEquipment::getEquipmentId) + .collect(Collectors.toList()); + String startStr = monthBetween.get(0).replaceAll("-", ""); + String endStr = monthBetween.get(monthBetween.size() - 1).replaceAll("-", ""); + List<ComRateDto> comRateDtoList = mdcEfficiencyReportMapper.comprehensiveRateAnalyze(equipmentIdList, startStr, endStr); + if (comRateDtoList.isEmpty()) { + return result; // 鎻愬墠杩斿洖绌虹粨鏋� + } + List<ComRateDto> dataList = new ArrayList<>(); + Map<String, ComRateDto> map = comRateDtoList.stream().collect(Collectors.toMap(ComRateDto::getTheMonth, comRateDto -> comRateDto)); + monthBetween.forEach(date -> { + String d = date.replaceAll("-", ""); + String month = date.substring(date.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "鏈�"; + if (map.containsKey(d)) { + ComRateDto comRateDto = map.get(d); + comRateDto.setTheMonth(month); + comRateDto.setUtilizationRate(comRateDto.getUtilizationRate().setScale(2, RoundingMode.HALF_UP)); + comRateDto.setShiftUtilizationRate(comRateDto.getShiftUtilizationRate() != null ? comRateDto.getShiftUtilizationRate().setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); + comRateDto.setAmendUtilizationRate(comRateDto.getAmendUtilizationRate().setScale(2, RoundingMode.HALF_UP)); + comRateDto.setProcessLong(comRateDto.getProcessLong().divide(new BigDecimal("3600"), 2, RoundingMode.HALF_UP)); + dataList.add(comRateDto); + } else { + ComRateDto comRateDto = new ComRateDto(); + comRateDto.setTheMonth(month); + dataList.add(comRateDto); + } + }); + result.put("dataList", dataList); + + if (StringUtils.isNotBlank(vo.getShiftId())) { + List<MdcShiftSub> shiftSubList = mdcShiftSubService.list(new LambdaQueryWrapper<MdcShiftSub>().eq(MdcShiftSub::getShiftId, vo.getShiftId())); + if (shiftSubList == null || shiftSubList.isEmpty()) { + return result; + } + List<String> shiftSubNameList = shiftSubList.stream().map(MdcShiftSub::getShiftSubName).collect(Collectors.toList()); + result.put("shiftSubList", shiftSubNameList); + + List<ComShiftRateDto> comShiftRateDtoList = mdcEfficiencyReportMapper.comprehensiveShiftRateAnalyze(equipmentIdList, startStr, endStr, vo.getShiftId()); + Map<String, List<ComShiftRateDto>> groupMap; + if (comShiftRateDtoList != null && !comShiftRateDtoList.isEmpty()) { + groupMap = comShiftRateDtoList.stream().collect(Collectors.groupingBy(ComShiftRateDto::getShiftSub)); + } else { + groupMap = new HashMap<>(); + } + List<ComShiftDto> shiftDataList = new ArrayList<>(); + shiftSubList.forEach(mdcShiftSub -> { + ComShiftDto comShiftDto = new ComShiftDto(); + comShiftDto.setShiftSubName(mdcShiftSub.getShiftSubName()); + if (groupMap.containsKey(mdcShiftSub.getId())) { + List<ComShiftRateDto> csrd = groupMap.get(mdcShiftSub.getId()); + Map<String, ComShiftRateDto> collect = csrd.stream().collect(Collectors.toMap(ComShiftRateDto::getTheMonth, comShiftRateDto -> comShiftRateDto)); + List<ComShiftChildDto> comShiftChildDtoList = new ArrayList<>(); + monthBetween.forEach(date -> { + String d = date.replaceAll("-", ""); + String month = date.substring(date.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "鏈�"; + if (collect.containsKey(d)) { + ComShiftRateDto comShiftRateDto = collect.get(d); + ComShiftChildDto comShiftChildDto = new ComShiftChildDto(); + comShiftChildDto.setMonth(month); + comShiftChildDto.setUtilizationRate(comShiftRateDto.getUtilizationRate().setScale(2, RoundingMode.HALF_UP)); + comShiftChildDtoList.add(comShiftChildDto); + } else { + ComShiftChildDto comShiftChildDto = new ComShiftChildDto(); + comShiftChildDto.setMonth(month); + comShiftChildDtoList.add(comShiftChildDto); + } + }); + comShiftDto.setDataList(comShiftChildDtoList); + } else { + List<ComShiftChildDto> comShiftChildDtoList = new ArrayList<>(); + monthBetween.forEach(date -> { + String month = date.substring(date.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "鏈�"; + ComShiftChildDto comShiftChildDto = new ComShiftChildDto(); + comShiftChildDto.setMonth(month); + comShiftChildDtoList.add(comShiftChildDto); + }); + comShiftDto.setDataList(comShiftChildDtoList); + } + shiftDataList.add(comShiftDto); + }); + + result.put("shiftDataList", shiftDataList); + } + + return result; + } + // 鎻愬彇鐨勫钩鍧囧�艰绠楁柟娉� private TeamEquEffDto calculateAverages(List<TeamEquEffDto> items) { BigDecimal size = new BigDecimal(items.size()); -- Gitblit v1.9.3