Lius
2025-06-18 db8133b419aeceed88dbfc2c48cd35509c782375
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentFaultInfoServiceImpl.java
@@ -48,12 +48,31 @@
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void runningAllEquFaultStatistical(String dateTime) {
        String validDate = LocalDate.now().minusDays(1).toString().replaceAll("-", "");
        Date initDate = null;
        if (StringUtils.isNotBlank(dateTime)) {
            validDate = DateUtils.format(DateUtils.toDate(dateTime, DateUtils.STRDATE), DateUtils.STRDATE);
            initDate = DateUtils.toDate(dateTime, DateUtils.STRDATE);
        } else {
            // 取最后的统计时间
            String date = this.baseMapper.getMaxStaticsData();
            if (date != null) {
                initDate = DateUtils.toDate(date, DateUtils.STRDATE);
            } else {
                // 初次取值 取最早时间记录
                MdcEquipmentRunningSection equipmentRunningSection = mdcEquipmentRunningSectionService.getFirstRecord();
                if (equipmentRunningSection != null) {
                    initDate = equipmentRunningSection.getStartTime();
                }
            }
        }
        Date endDate = DateUtils.addDays(DateUtils.getNow(), -1);
        List<String> dateList = DateUtils.getDatesStringList2(initDate, endDate);
        if (dateList.isEmpty()) {
            return;
        }
        try {
            this.remove(new LambdaQueryWrapper<MdcEquipmentFaultInfo>().eq(MdcEquipmentFaultInfo::getTheDate, validDate));
            this.remove(new LambdaQueryWrapper<MdcEquipmentFaultInfo>().in(MdcEquipmentFaultInfo::getTheDate, dateList));
        } catch (Exception e) {
            log.error("参数格式不对", e);
        }
@@ -63,13 +82,6 @@
            return;
        }
        Map<String, MdcEquipmentFaultInfo> map = new HashMap<>();
        String finalValidDate = validDate;
        equipmentList.forEach(equipment -> {
            MdcEquipmentFaultInfo mdcEquipmentFaultInfo = new MdcEquipmentFaultInfo(equipment.getEquipmentid(), finalValidDate);
            map.put(equipment.getEquipmentid(), mdcEquipmentFaultInfo);
        });
        String planTime = "00:00:00";
        MdcSystemParameters mdcSystemParameters = mdcSystemParametersService.getOne(new LambdaQueryWrapper<MdcSystemParameters>().eq(MdcSystemParameters::getCode, "equip_log_statis_time"));
        if (mdcSystemParameters != null) {
@@ -77,6 +89,15 @@
        }
        List<String> equipmentIdList = equipmentList.stream().map(Equipment::getEquipmentid).collect(Collectors.toList());
        for (String validDate : dateList) {
            Map<String, MdcEquipmentFaultInfo> map = new HashMap<>();
            String finalValidDate = validDate;
            equipmentList.forEach(equipment -> {
                MdcEquipmentFaultInfo mdcEquipmentFaultInfo = new MdcEquipmentFaultInfo(equipment.getEquipmentid(), finalValidDate);
                map.put(equipment.getEquipmentid(), mdcEquipmentFaultInfo);
            });
        String startTime = DateUtils.format(DateUtils.setTimeForDay(DateUtils.toDate(validDate, DateUtils.STRDATE), planTime), DateUtils.STR_DATE_TIME_SMALL);
        Date start = DateUtils.toDate(startTime, DateUtils.STR_DATE_TIME_SMALL);
        String endTime = DateUtils.format(DateUtils.addDays(DateUtils.toDate(startTime, DateUtils.STR_DATE_TIME_SMALL), 1), DateUtils.STR_DATE_TIME_SMALL);
@@ -161,6 +182,7 @@
            this.saveBatch(new ArrayList<>(map.values()));
        }
    }
    }
    public static long calculateTotalFaultDuration(List<EquFaultRecord> records, Date startTime, Date endTime) {
        LocalDateTime start = DateUtils.convertToLocalDateTime(startTime);