| | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.vo.DictModel; |
| | | import org.jeecg.modules.mdc.dto.*; |
| | | import org.jeecg.modules.mdc.entity.*; |
| | | import org.jeecg.modules.mdc.mapper.MdcEfficiencyReportMapper; |
| | |
| | | import org.jeecg.modules.system.entity.SysDepart; |
| | | import org.jeecg.modules.system.service.IMdcProductionService; |
| | | import org.jeecg.modules.system.service.ISysDepartService; |
| | | import org.jeecg.modules.system.service.ISysDictService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | @Resource |
| | | private IMdcEquipmentRunningSectionService mdcEquipmentRunningSectionService; |
| | | |
| | | @Resource |
| | | private ISysDictService sysDictService; |
| | | |
| | | /** |
| | | * 利用率报表 |
| | |
| | | /** |
| | | * 班组各设备综合利用率 |
| | | * |
| | | * @param teamEquEffVo |
| | | * @param equEffVo |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Map<String, Object> teamEquipmentEfficiencyAnalyze(TeamEquEffVo teamEquEffVo) { |
| | | public Map<String, Object> equipmentEfficiencyAnalyze(EquEffVo equEffVo) { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | List<String> mdcProductionIds = new ArrayList<>(); |
| | | if (StringUtils.isEmpty(teamEquEffVo.getProductionIds())) { |
| | | mdcProductionIds.add(teamEquEffVo.getProductionId()); |
| | | if (StringUtils.isBlank(equEffVo.getProductionIds())) { |
| | | mdcProductionIds.add(equEffVo.getProductionId()); |
| | | } else { |
| | | mdcProductionIds.addAll(Arrays.asList(teamEquEffVo.getProductionIds().split(","))); |
| | | mdcProductionIds.addAll(Arrays.asList(equEffVo.getProductionIds().split(","))); |
| | | } |
| | | List<String> allProductionIds = mdcProductionService.findChildren(mdcProductionIds); |
| | | List<MdcEquipment> equipmentList = mdcEquipmentService.findByProductionIds(allProductionIds); |
| | | if (equipmentList != null && !equipmentList.isEmpty()) { |
| | | List<String> equipmentIdList = equipmentList.stream().map(MdcEquipment::getEquipmentId).collect(Collectors.toList()); |
| | | List<TeamEquipmentEfficiencyAnalyzeDto> dataList = mdcEfficiencyReportMapper.teamEquipmentEfficiencyAnalyze(equipmentIdList, teamEquEffVo.getMonth()); |
| | | List<EquipmentEfficiencyAnalyzeDto> dataList = mdcEfficiencyReportMapper.equipmentEfficiencyAnalyze(equipmentIdList, equEffVo.getMonth()); |
| | | result.put("dataList", dataList); |
| | | List<String> equipmentNameList = dataList.stream().map(TeamEquipmentEfficiencyAnalyzeDto::getEquipmentName).collect(Collectors.toList()); |
| | | List<String> equipmentNameList = dataList.stream().map(EquipmentEfficiencyAnalyzeDto::getEquipmentName).collect(Collectors.toList()); |
| | | result.put("equipmentNameList", equipmentNameList); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> teamEquipmentEfficiencyAnalyze(EquEffVo equEffVo) { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | // 1. 处理生产ID |
| | | List<String> mdcProductionIds = StringUtils.isBlank(equEffVo.getProductionIds()) |
| | | ? Collections.singletonList(equEffVo.getProductionId()) |
| | | : Arrays.asList(equEffVo.getProductionIds().split(",")); |
| | | |
| | | List<String> allProductionIds = mdcProductionService.findChildren(mdcProductionIds); |
| | | if (allProductionIds.isEmpty()) { |
| | | return result; // 提前返回空结果 |
| | | } |
| | | |
| | | // 2. 获取设备列表 |
| | | List<MdcEquipment> equipmentList = StringUtils.isNotBlank(equEffVo.getTeamCodes()) |
| | | ? mdcEquipmentService.findByProIdsAndTeamCode(allProductionIds, Arrays.asList(equEffVo.getTeamCodes().split(","))) |
| | | : mdcEquipmentService.findByProductionIds(allProductionIds); |
| | | |
| | | if (equipmentList.isEmpty()) { |
| | | return result; |
| | | } |
| | | |
| | | // 3. 数据处理 |
| | | List<String> equipmentIdList = equipmentList.stream() |
| | | .map(MdcEquipment::getEquipmentId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<TeamEquEffDto> dataList = mdcEfficiencyReportMapper |
| | | .teamEquipmentEfficiencyAnalyze(equipmentIdList, equEffVo.getMonth()); |
| | | |
| | | if (dataList.isEmpty()) { |
| | | return result; |
| | | } |
| | | |
| | | // 4. 分组计算平均值 |
| | | Map<String, TeamEquEffDto> grouped = dataList.stream() |
| | | .collect(Collectors.groupingBy( |
| | | TeamEquEffDto::getTeamCode, |
| | | Collectors.collectingAndThen( |
| | | Collectors.toList(), |
| | | this::calculateAverages // 提取计算方法 |
| | | ))); |
| | | |
| | | // 5. 字典转换 |
| | | Map<String, String> dictMap = sysDictService.queryEnableDictItemsByCode(CommonConstant.DICT_MDC_STAFF_TEAM) |
| | | .stream() |
| | | .collect(Collectors.toMap(DictModel::getValue, DictModel::getText)); |
| | | |
| | | List<TeamEquEffDto> resultList = grouped.entrySet().stream() |
| | | .map(entry -> buildResultDto(entry, dictMap))// 提取构建方法 |
| | | .sorted(Comparator.comparing(TeamEquEffDto::getUtilizationRate).reversed()) |
| | | .collect(Collectors.toList()); |
| | | |
| | | result.put("dataList", resultList); |
| | | result.put("teamCodeList", resultList.stream() |
| | | .map(TeamEquEffDto::getTeamCode) |
| | | .collect(Collectors.toList())); |
| | | |
| | | return result; |
| | | |
| | | } |
| | | |
| | | // 提取的平均值计算方法 |
| | | private TeamEquEffDto calculateAverages(List<TeamEquEffDto> items) { |
| | | BigDecimal size = new BigDecimal(items.size()); |
| | | return new TeamEquEffDto( |
| | | calculateAverage(items, TeamEquEffDto::getUtilizationRate, size), |
| | | calculateAverage(items, TeamEquEffDto::getShiftUtilizationRate, size), |
| | | calculateAverage(items, TeamEquEffDto::getAmendUtilizationRate, size) |
| | | ); |
| | | } |
| | | |
| | | // 通用的平均值计算 |
| | | private BigDecimal calculateAverage(List<TeamEquEffDto> items, Function<TeamEquEffDto, BigDecimal> mapper, BigDecimal size) { |
| | | return items.stream() |
| | | .map(mapper) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add) |
| | | .divide(size, 2, RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | // 构建结果DTO |
| | | private TeamEquEffDto buildResultDto(Map.Entry<String, TeamEquEffDto> entry, Map<String, String> dictMap) { |
| | | TeamEquEffDto dto = entry.getValue(); |
| | | dto.setTeamCode(dictMap.getOrDefault(entry.getKey(), entry.getKey())); |
| | | return dto; |
| | | } |
| | | |
| | | private MdcUtilizationResultDto utilizationRate(String equipmentId, String equipmentName, String equipmentType, Date startTime, Date endTime, String date, List<MdcUtilizationRate> mdcUtilizationRateList) { |
| | |
| | | } |
| | | } |
| | | BigDecimal totalLong = new BigDecimal(DateUtils.differentSecond(startTime, endTime)); |
| | | BigDecimal utilizationRate = processLong.divide(totalLong, 6, BigDecimal.ROUND_HALF_UP); |
| | | BigDecimal utilizationRate = processLong.divide(totalLong, 6, RoundingMode.HALF_UP); |
| | | dto.setUtilizationRate(utilizationRate); |
| | | } else { |
| | | dto.setUtilizationRate(new BigDecimal("0")); |