| | |
| | | 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; |
| | |
| | | * @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())) { |
| | |
| | | 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()); |
| | |
| | | } |
| | | |
| | | @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()) |
| | |
| | | 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(","))) |
| | |
| | | |
| | | } |
| | | |
| | | @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; |
| | | } |
| | | |
| | | // 提取的平均值计算方法 |
| | | private TeamEquEffDto calculateAverages(List<TeamEquEffDto> items) { |
| | | BigDecimal size = new BigDecimal(items.size()); |