| | |
| | | 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)); |
| | | mdcEfficiencyResultDto1.setFaultLong(mdcEfficiencyResultDto.getFaultLong()); |
| | | mdcEfficiencyResultDto.setFaultLong(mdcEfficiencyResultDto.getFaultLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto1.setFaultRate(mdcEfficiencyResultDto.getFaultRate()); |
| | | mdcEfficiencyResultDto.setFaultRate(mdcEfficiencyResultDto.getFaultRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto1.setRemoveFaultRunLong(mdcEfficiencyResultDto.getRemoveFaultRunLong()); |
| | | mdcEfficiencyResultDto.setRemoveFaultRunLong(mdcEfficiencyResultDto.getRemoveFaultRunLong().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.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)); |
| | | mdcEfficiencyResultDto1.setFaultLong(mdcEfficiencyResultDto.getFaultLong()); |
| | | mdcEfficiencyResultDto.setFaultLong(mdcEfficiencyResultDto.getFaultLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto1.setFaultRate(mdcEfficiencyResultDto.getFaultRate()); |
| | | mdcEfficiencyResultDto.setFaultRate(mdcEfficiencyResultDto.getFaultRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto1.setRemoveFaultRunLong(mdcEfficiencyResultDto.getRemoveFaultRunLong()); |
| | | mdcEfficiencyResultDto.setRemoveFaultRunLong(mdcEfficiencyResultDto.getRemoveFaultRunLong().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()) { |
| | |
| | | a.getOpenRate().add(b.getOpenRate()), |
| | | a.getOpenLong().add(b.getOpenLong()), |
| | | a.getWaitLong().add(b.getWaitLong()), |
| | | a.getCloseLong().add(b.getCloseLong()))).ifPresent(result::add); |
| | | a.getCloseLong().add(b.getCloseLong()), |
| | | a.getFaultLong().add(b.getFaultLong()), |
| | | a.getFaultRate().add(b.getFaultRate()), |
| | | a.getRemoveFaultRunLong().add(b.getRemoveFaultRunLong()))).ifPresent(result::add); |
| | | }); |
| | | for (MdcEfficiencyResultDto mdcEfficiencyResultDto : result) { |
| | | mdcEfficiencyResultDto.setUtilizationRate(mdcEfficiencyResultDto.getUtilizationRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP)); |
| | |
| | | a.getOpenRate().add(b.getOpenRate()), |
| | | a.getOpenLong().add(b.getOpenLong()), |
| | | a.getWaitLong().add(b.getWaitLong()), |
| | | a.getCloseLong().add(b.getCloseLong()))).ifPresent(result::add); |
| | | a.getCloseLong().add(b.getCloseLong()), |
| | | a.getFaultLong().add(b.getFaultLong()), |
| | | a.getFaultRate().add(b.getFaultRate()), |
| | | a.getRemoveFaultRunLong().add(b.getRemoveFaultRunLong()))).ifPresent(result::add); |
| | | }); |
| | | for (MdcEfficiencyResultDto mdcEfficiencyResultDto : result) { |
| | | mdcEfficiencyResultDto.setUtilizationRate(mdcEfficiencyResultDto.getUtilizationRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP)); |
| | |
| | | a.getOpenRate().add(b.getOpenRate()), |
| | | a.getOpenLong().add(b.getOpenLong()), |
| | | a.getWaitLong().add(b.getWaitLong()), |
| | | a.getCloseLong().add(b.getCloseLong()))).ifPresent(result::add); |
| | | a.getCloseLong().add(b.getCloseLong()), |
| | | a.getFaultLong().add(b.getFaultLong()), |
| | | a.getFaultRate().add(b.getFaultRate()), |
| | | a.getRemoveFaultRunLong().add(b.getRemoveFaultRunLong()))).ifPresent(result::add); |
| | | }); |
| | | for (MdcEfficiencyResultDto mdcEfficiencyResultDto : result) { |
| | | mdcEfficiencyResultDto.setUtilizationRate(mdcEfficiencyResultDto.getUtilizationRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP)); |
| | |
| | | mdcEfficiencyResultDto.setWaitLong(mdcEfficiencyResultDto.getWaitLong().divide(new BigDecimal(mdcEfficiencyList.size()), 0, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto.setOpenLong(mdcEfficiencyResultDto.getOpenLong().divide(new BigDecimal(mdcEfficiencyList.size()), 0, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto.setProcessLong(mdcEfficiencyResultDto.getProcessLong().divide(new BigDecimal(mdcEfficiencyList.size()), 0, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto.setFaultLong(mdcEfficiencyResultDto.getFaultLong().divide(new BigDecimal(mdcEfficiencyList.size()), 0, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto.setFaultRate(mdcEfficiencyResultDto.getFaultRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto.setRemoveFaultRunLong(mdcEfficiencyResultDto.getRemoveFaultRunLong().divide(new BigDecimal(mdcEfficiencyList.size()), 0, RoundingMode.HALF_UP)); |
| | | long rate = mdcEfficiencyResultDto.getStartRate().multiply(new BigDecimal("100")).longValue(); |
| | | for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) { |
| | | if (rate >= mdcUtilizationRate.getMinimumRange() && rate < mdcUtilizationRate.getMaximumRange()) { |
| | |
| | | a.getOpenRate().add(b.getOpenRate()), |
| | | a.getOpenLong().add(b.getOpenLong()), |
| | | a.getWaitLong().add(b.getWaitLong()), |
| | | a.getCloseLong().add(b.getCloseLong()))).ifPresent(result::add); |
| | | a.getCloseLong().add(b.getCloseLong()), |
| | | a.getFaultLong().add(b.getFaultLong()), |
| | | a.getFaultRate().add(b.getFaultRate()), |
| | | a.getRemoveFaultRunLong().add(b.getRemoveFaultRunLong()))).ifPresent(result::add); |
| | | }); |
| | | for (MdcEfficiencyResultDto mdcEfficiencyResultDto : result) { |
| | | mdcEfficiencyResultDto.setUtilizationRate(mdcEfficiencyResultDto.getUtilizationRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto.setOpenRate(mdcEfficiencyResultDto.getOpenRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto.setStartRate(mdcEfficiencyResultDto.getStartRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto.setFaultRate(mdcEfficiencyResultDto.getFaultRate().divide(new BigDecimal(mdcEfficiencyList.size()), 4, RoundingMode.HALF_UP)); |
| | | long rate = mdcEfficiencyResultDto.getStartRate().multiply(new BigDecimal("100")).longValue(); |
| | | for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) { |
| | | if (rate >= mdcUtilizationRate.getMinimumRange() && rate < mdcUtilizationRate.getMaximumRange()) { |
| | |
| | | List<String> equipmentIdList = equipmentList.stream().map(MdcEquipment::getEquipmentId).collect(Collectors.toList()); |
| | | List<EquipmentEfficiencyAnalyzeDto> dataList = mdcEfficiencyReportMapper.equipmentEfficiencyAnalyze(equipmentIdList, equEffVo.getMonth()); |
| | | result.put("dataList", dataList); |
| | | List<String> equipmentNameList = dataList.stream().map(EquipmentEfficiencyAnalyzeDto::getEquipmentName).collect(Collectors.toList()); |
| | | List<String> equipmentNameList = dataList.stream().map(EquipmentEfficiencyAnalyzeDto::getEquipmentId).collect(Collectors.toList()); |
| | | result.put("equipmentNameList", equipmentNameList); |
| | | } |
| | | return result; |
| | |
| | | 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()); |
| | |
| | | mdcEfficiencyResultDto.setOpenLong(efficiencyDto.getOpenLong()); |
| | | mdcEfficiencyResultDto.setWaitLong(efficiencyDto.getWaitLong()); |
| | | mdcEfficiencyResultDto.setCloseLong(efficiencyDto.getCloseLong()); |
| | | mdcEfficiencyResultDto.setFaultLong(efficiencyDto.getFaultLong()); |
| | | mdcEfficiencyResultDto.setFaultRate(efficiencyDto.getFaultRate()); |
| | | mdcEfficiencyResultDto.setRemoveFaultRunLong(efficiencyDto.getRemoveFaultRunLong()); |
| | | long rate = efficiencyDto.getUtilizationRate().multiply(new BigDecimal("100")).longValue(); |
| | | for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) { |
| | | if (rate >= mdcUtilizationRate.getMinimumRange() && rate < mdcUtilizationRate.getMaximumRange()) { |
| | |
| | | mdcEfficiencyResultDto.setOpenLong(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setWaitLong(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setCloseLong(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setFaultLong(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setFaultRate(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setRemoveFaultRunLong(new BigDecimal("0")); |
| | | for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) { |
| | | if (0 >= mdcUtilizationRate.getMinimumRange() && 0 < mdcUtilizationRate.getMaximumRange()) { |
| | | mdcEfficiencyResultDto.setColor(mdcUtilizationRate.getRateParameterColor()); |
| | |
| | | mdcEfficiencyResultDto.setOpenLong(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setWaitLong(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setCloseLong(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setFaultLong(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setFaultRate(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setRemoveFaultRunLong(new BigDecimal("0")); |
| | | for (MdcUtilizationRate mdcUtilizationRate : mdcUtilizationRateList) { |
| | | if (0 >= mdcUtilizationRate.getMinimumRange() && 0 < mdcUtilizationRate.getMaximumRange()) { |
| | | mdcEfficiencyResultDto.setColor(mdcUtilizationRate.getRateParameterColor()); |
| | |
| | | efficiencyResultDto.setOpenLong(efficiencyResultDto.getOpenLong().add(mdcEfficiencyResultDto.getOpenLong())); |
| | | efficiencyResultDto.setWaitLong(efficiencyResultDto.getWaitLong().add(mdcEfficiencyResultDto.getWaitLong())); |
| | | efficiencyResultDto.setCloseLong(efficiencyResultDto.getCloseLong().add(mdcEfficiencyResultDto.getCloseLong())); |
| | | efficiencyResultDto.setFaultLong(efficiencyResultDto.getFaultLong().add(mdcEfficiencyResultDto.getFaultLong())); |
| | | efficiencyResultDto.setFaultRate(efficiencyResultDto.getFaultRate().add(mdcEfficiencyResultDto.getFaultRate())); |
| | | efficiencyResultDto.setRemoveFaultRunLong(efficiencyResultDto.getRemoveFaultRunLong().add(mdcEfficiencyResultDto.getRemoveFaultRunLong())); |
| | | return mdcEfficiencyResultDto; |
| | | } |
| | | |