lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEfficiencyReportServiceImpl.java
@@ -4,6 +4,7 @@
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;
@@ -15,6 +16,8 @@
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.jeecg.modules.system.vo.MdcProOptionsVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -24,6 +27,7 @@
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -53,6 +57,9 @@
    @Resource
    private IMdcEquipmentRunningSectionService mdcEquipmentRunningSectionService;
    @Resource
    private ISysDictService sysDictService;
    /**
     * 利用率报表
@@ -189,6 +196,12 @@
                    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()) {
@@ -277,6 +290,12 @@
                    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()) {
@@ -342,7 +361,10 @@
                            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));
@@ -385,7 +407,10 @@
                            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));
@@ -448,7 +473,7 @@
        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);
@@ -689,7 +714,10 @@
                            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));
@@ -699,6 +727,9 @@
            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()) {
@@ -733,12 +764,16 @@
                            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()) {
@@ -1736,6 +1771,342 @@
        return mdcEfficiencyReportMapper.getEfficiencyRate(equipmentId, date);
    }
    /**
     * 班组各设备综合利用率
     *
     * @param equEffVo
     * @return
     */
    @Override
    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.add(equEffVo.getProductionId());
        } else {
            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());
            List<EquipmentEfficiencyAnalyzeDto> dataList = mdcEfficiencyReportMapper.equipmentEfficiencyAnalyze(equipmentIdList, equEffVo.getMonth());
            result.put("dataList", dataList);
            List<String> equipmentNameList = dataList.stream().map(EquipmentEfficiencyAnalyzeDto::getEquipmentId).collect(Collectors.toList());
            result.put("equipmentNameList", equipmentNameList);
        }
        return result;
    }
    @Override
    public Map<String, Object> teamEquipmentEfficiencyAnalyze(String userId, 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; // 提前返回空结果
        }
        //数据权限过滤
        allProductionIds = mdcProductionService.findProIdsByUId(userId, allProductionIds);
        // 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;
    }
    @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());
        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) {
        MdcUtilizationResultDto dto = new MdcUtilizationResultDto();
        dto.setEquipmentId(equipmentId);
@@ -1760,7 +2131,7 @@
                }
            }
            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"));
@@ -1803,6 +2174,9 @@
                    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()) {
@@ -1820,6 +2194,9 @@
            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());
@@ -1835,6 +2212,9 @@
            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());
@@ -1848,6 +2228,9 @@
        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;
    }