Lius
2024-11-07 81eae83295642387de38a97fdc5a35f485307587
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcOeeInfoServiceImpl.java
@@ -105,22 +105,22 @@
            }
            queryWrapper.orderByAsc(MdcEquipment::getEquipmentName);
            List<MdcEquipment> equipmentList = mdcEquipmentService.list(queryWrapper);
            vo.setStartTime(DateUtils.format(DateUtils.toDate(vo.getStartTime(), DateUtils.STRDATE), DateUtils.STR_DATE));
            vo.setEndTime(DateUtils.format(DateUtils.toDate(vo.getEndTime(), DateUtils.STRDATE), DateUtils.STR_DATE));
            //查询oee数据
            List<MdcOeeInfo> oeeList = this.baseMapper.oeeList(vo);
            //数据处理
            String shiftSubName = "全部";
            if (!StringUtils.isBlank(vo.getShiftId())) {
                List<MdcShiftSub> mdcShiftSubList = new ArrayList<>();
                if (StringUtils.isNotBlank(vo.getShiftSubId())) {
                    mdcShiftSubList = mdcShiftSubService.list(new LambdaQueryWrapper<MdcShiftSub>().eq(MdcShiftSub::getId, vo.getShiftSubId()).eq(MdcShiftSub::getShiftSubStatus, "1"));
                    oeeList = oeeList.stream().filter(mdcOeeInfo -> mdcOeeInfo.getShiftId().equals(vo.getShiftId()) && mdcOeeInfo.getShiftSubId().equals(vo.getShiftSubId())).collect(Collectors.toList());
                } else {
                    mdcShiftSubList = mdcShiftSubService.list(new LambdaQueryWrapper<MdcShiftSub>().eq(MdcShiftSub::getShiftId, vo.getShiftId()).eq(MdcShiftSub::getShiftSubStatus, "1"));
                    oeeList = oeeList.stream().filter(mdcOeeInfo -> mdcOeeInfo.getShiftId().equals(vo.getShiftId())).collect(Collectors.toList());
                }
            List<MdcShiftSub> mdcShiftSubList = new ArrayList<>();
            if (StringUtils.isNotBlank(vo.getShiftSubId())) {
                mdcShiftSubList = mdcShiftSubService.list(new LambdaQueryWrapper<MdcShiftSub>().eq(MdcShiftSub::getId, vo.getShiftSubId()).eq(MdcShiftSub::getShiftSubStatus, "1"));
                //oeeList = oeeList.stream().filter(mdcOeeInfo -> mdcOeeInfo.getShiftId().equals(vo.getShiftId()) && mdcOeeInfo.getShiftSubId().equals(vo.getShiftSubId())).collect(Collectors.toList());
                List<String> shiftSubNames = mdcShiftSubList.stream().map(MdcShiftSub::getShiftSubName).collect(Collectors.toList());
                shiftSubName = String.join(",", shiftSubNames);
            }
            for (MdcEquipment mdcEquipment : equipmentList) {
                MdcOeeListDto mdcOeeListDto = new MdcOeeListDto();
                mdcOeeListDto.setEquipmentId(mdcEquipment.getEquipmentId());
@@ -137,7 +137,7 @@
                    BigDecimal oeeRate = BigDecimal.ZERO;
                    if (!mdcOeeInfoList.isEmpty()) {
                        BigDecimal count = mdcOeeInfoList.stream().map(MdcOeeInfo::getOeeRate).reduce(BigDecimal.ZERO, BigDecimal::add);
                        oeeRate = count.divide(new BigDecimal(mdcOeeInfoList.size()), 2, RoundingMode.HALF_UP);
                        oeeRate = count.divide(new BigDecimal(mdcOeeInfoList.size()), 4, RoundingMode.HALF_UP);
                        mdcOeeResultDto.setOeeRate(oeeRate);
                    }
                    long rate = oeeRate.multiply(new BigDecimal("100")).longValue();
@@ -193,8 +193,8 @@
                    .eq(MdcProductDayschedule::getEquipmentId, equipment.getEquipmentid()));
            if (productDayScheduleList != null && !productDayScheduleList.isEmpty()) {
                MdcProductDayschedule mdcProductDayschedule;
                MdcOeeInfo mdcOeeInfo = new MdcOeeInfo();
                for (MdcShiftSub mdcShiftSub : mdcShiftSubList) {
                    MdcOeeInfo mdcOeeInfo = new MdcOeeInfo();
                    String id = mdcShiftSub.getId();
                    if (productDayScheduleList.stream().anyMatch(productDayschedule -> productDayschedule.getOrderId().substring(8, 10).equals(id))) {
                        mdcOeeInfo.setEquipmentId(equipment.getEquipmentid());
@@ -207,7 +207,7 @@
                        //获取设备运行数据
                        MdcEquipmentStatisticalShiftInfo mdcEquipmentStatisticalShiftInfo = mdcEquipmentStatisticalShiftInfoService.getOne(new LambdaQueryWrapper<MdcEquipmentStatisticalShiftInfo>()
                                .eq(MdcEquipmentStatisticalShiftInfo::getEquipmentId, equipment.getEquipmentid())
                                .eq(MdcEquipmentStatisticalShiftInfo::getTheDate, validDate)
                                .eq(MdcEquipmentStatisticalShiftInfo::getTheDate, validDate.replaceAll("-", ""))
                                .eq(MdcEquipmentStatisticalShiftInfo::getShiftSubId, id));
                        if (mdcEquipmentStatisticalShiftInfo == null) {
                            continue;
@@ -217,7 +217,7 @@
                        mdcOeeInfo.setOpenLong(mdcEquipmentStatisticalShiftInfo.getOpenLong());
                        mdcOeeInfo.setCloseLong(mdcEquipmentStatisticalShiftInfo.getCloseLong());
                        //获取设备生产计划
                        mdcProductDayschedule = productDayScheduleList.stream().filter(productDayschedule -> productDayschedule.getOrderId().substring(8, 10).equals(id)).findAny().orElse(null);
                        mdcProductDayschedule = productDayScheduleList.stream().filter(productDayschedule -> productDayschedule.getOrderId().substring(productDayschedule.getOrderId().length() - 5, productDayschedule.getOrderId().length() - 3).equals(id)).findAny().orElse(null);
                        if (mdcProductDayschedule == null) {
                            continue;
                        }
@@ -244,11 +244,13 @@
                            continue;
                        }
                        mdcOeeInfo.setScheduleNum(mdcComponentInfo.getScheduleNum());
                        BigDecimal oeeRate = mdcOeeInfo.getProcessLong().multiply(new BigDecimal(mdcOeeInfo.getPlanNum())).multiply(new BigDecimal(mdcOeeInfo.getQualityNum()))
                                        .divide(mdcEquipmentStatisticalShiftInfo.getTotalLong(), 2, RoundingMode.HALF_UP)
                                        .divide(new BigDecimal(mdcOeeInfo.getScheduleNum()), 2, RoundingMode.HALF_UP)
                                        .divide(new BigDecimal(mdcOeeInfo.getCompleteNum()), 2, RoundingMode.HALF_UP);
                        BigDecimal oeeRate = BigDecimal.ZERO;
                        if (!mdcOeeInfo.getCompleteNum().equals(0)) {
                            oeeRate = mdcOeeInfo.getProcessLong().multiply(new BigDecimal(mdcOeeInfo.getPlanNum())).multiply(new BigDecimal(mdcOeeInfo.getQualityNum()))
                                    .divide(mdcEquipmentStatisticalShiftInfo.getTotalLong(), 4, RoundingMode.HALF_UP)
                                    .divide(new BigDecimal(mdcOeeInfo.getScheduleNum()), 4, RoundingMode.HALF_UP)
                                    .divide(new BigDecimal(mdcOeeInfo.getCompleteNum()), 4, RoundingMode.HALF_UP);
                        }
                        mdcOeeInfo.setOeeRate(oeeRate);
                        result.add(mdcOeeInfo);
                    }
@@ -259,5 +261,4 @@
            this.saveBatch(result);
        }
    }
}