Lius
2025-06-17 2b6aad0dabc78496e8eb7d49f7fb63d93cccb816
设备日志页面添加设备故障时间段显示
已添加1个文件
已修改6个文件
269 ■■■■ 文件已修改
lxzn-module-mdc-common/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipmentRunningSection.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentRunningSectionMapper.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentRunningSectionMapper.xml 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentFaultInfoServiceImpl.java 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentRunningSectionServiceImpl.java 117 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/TimeInterval.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc-common/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java
@@ -6,9 +6,7 @@
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.*;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.util.*;
@@ -1086,4 +1084,32 @@
        return dateString;
    }
    /**
     * Date与LocalDateTime互相转换的工具方法
     *
     * @param date
     * @return
     */
    public static LocalDateTime convertToLocalDateTime(Date date) {
        if (date == null) {
            return null;
        }
        return Instant.ofEpochMilli(date.getTime())
                .atZone(ZoneId.systemDefault())
                .toLocalDateTime();
    }
    /**
     * Date与LocalDateTime互相转换的工具方法
     *
     * @param localDateTime
     * @return
     */
    public static Date convertToDate(LocalDateTime localDateTime) {
        if (localDateTime == null) {
            return null;
        }
        return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipmentRunningSection.java
@@ -100,4 +100,15 @@
    @TableField(exist = false)
    private Set<TmpEquipmentAlarm> tmpEquipmentAlarmSet;
    public MdcEquipmentRunningSection() {
    }
    public MdcEquipmentRunningSection(Integer status, String equipmentId, Date startTime, Date endTime, Long startLong, Long endLong) {
        this.status = status;
        this.equipmentId = equipmentId;
        this.startTime = startTime;
        this.endTime = endTime;
        this.startLong = startLong;
        this.endLong = endLong;
    }
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentRunningSectionMapper.java
@@ -5,6 +5,7 @@
import org.jeecg.modules.mdc.dto.MdcAlarmListDto;
import org.jeecg.modules.mdc.dto.MdcEquipmentWaitSectionDto;
import org.jeecg.modules.mdc.entity.MdcEquipmentRunningSection;
import org.jeecg.modules.mdc.vo.EquFaultRecord;
import org.jeecg.modules.mdc.vo.MdcAlarmAnalyzeQueryVo;
import java.util.Date;
@@ -78,4 +79,6 @@
    List<Integer> getDataList(@Param("equipmentId") String equipmentId, @Param("date") Date date);
    List<MdcEquipmentWaitSectionDto> findWaitList(@Param("date") String date);
    List<EquFaultRecord> findFaultList(@Param("equipmentId") String equipmentId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentRunningSectionMapper.xml
@@ -188,5 +188,20 @@
            equipment_id, start_time DESC
    </select>
    <select id="findFaultList" resultType="org.jeecg.modules.mdc.vo.EquFaultRecord">
        SELECT
            t3.equipment_code equipmentId,
            t1.fault_start_time startTime,
            t2.actual_end_time endTime
        FROM
            eam_report_repair t1
                LEFT JOIN eam_repair_order t2 ON t2.report_id = t1.id
                LEFT JOIN eam_equipment t3 ON t1.equipment_id = t3.id
        WHERE
            ( ( t1.fault_start_time BETWEEN #{startTime} AND #{endTime} ) OR ( t2.actual_end_time BETWEEN #{startTime} AND #{endTime} ) )
          AND t3.equipment_code = #{equipmentId}
          AND t1.report_status != 'ABOLISH'
    </select>
</mapper>
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentFaultInfoServiceImpl.java
@@ -10,6 +10,7 @@
import org.jeecg.modules.mdc.service.IMdcSystemParametersService;
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.mdc.vo.EquFaultRecord;
import org.jeecg.modules.mdc.vo.TimeInterval;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -130,8 +131,8 @@
    }
    public static long calculateTotalFaultDuration(List<EquFaultRecord> records, Date startTime, Date endTime) {
        LocalDateTime start = convertToLocalDateTime(startTime);
        LocalDateTime end = convertToLocalDateTime(endTime);
        LocalDateTime start = DateUtils.convertToLocalDateTime(startTime);
        LocalDateTime end = DateUtils.convertToLocalDateTime(endTime);
        // ä¿®æ­£è®°å½•æ—¶é—´
        List<EquFaultRecord> correctedRecords = correctRecordTimes(records, start, end);
@@ -144,16 +145,16 @@
        // è®¡ç®—总时长(秒)
        return mergedIntervals.stream()
                .mapToLong(interval -> ChronoUnit.SECONDS.between(interval.start, interval.end))
                .mapToLong(interval -> ChronoUnit.SECONDS.between(interval.getStart(), interval.getEnd()))
                .sum();
    }
    private static List<EquFaultRecord> correctRecordTimes(List<EquFaultRecord> records, LocalDateTime startTime, LocalDateTime endTime) {
        return records.stream()
                .map(record -> {
                    LocalDateTime recordStart = convertToLocalDateTime(record.getStartTime());
                    LocalDateTime recordStart = DateUtils.convertToLocalDateTime(record.getStartTime());
                    LocalDateTime recordEnd = record.getEndTime() != null ?
                            convertToLocalDateTime(record.getEndTime()) : null;
                            DateUtils.convertToLocalDateTime(record.getEndTime()) : null;
                    // ä¿®æ­£å¼€å§‹æ—¶é—´
                    LocalDateTime correctedStart = recordStart.isBefore(startTime) ?
@@ -166,8 +167,8 @@
                    // åˆ›å»ºä¿®æ­£åŽçš„记录
                    return new EquFaultRecord(
                            record.getEquipmentId(),
                            convertToDate(correctedStart),
                            convertToDate(correctedEnd)
                            DateUtils.convertToDate(correctedStart),
                            DateUtils.convertToDate(correctedEnd)
                    );
                })
                .collect(Collectors.toList());
@@ -176,8 +177,8 @@
    private static List<TimeInterval> mergeIntervals(List<EquFaultRecord> records) {
        List<TimeInterval> intervals = records.stream()
                .map(record -> new TimeInterval(
                        convertToLocalDateTime(record.getStartTime()),
                        convertToLocalDateTime(record.getEndTime())))
                        DateUtils.convertToLocalDateTime(record.getStartTime()),
                        DateUtils.convertToLocalDateTime(record.getEndTime())))
                .collect(Collectors.toList());
        if (intervals.isEmpty()) {
@@ -189,9 +190,9 @@
        for (int i = 1; i < intervals.size(); i++) {
            TimeInterval next = intervals.get(i);
            if (next.start.isBefore(current.end) || next.start.equals(current.end)) {
            if (next.getStart().isBefore(current.getEnd()) || next.getStart().equals(current.getEnd())) {
                // æœ‰é‡å ï¼Œåˆå¹¶åŒºé—´
                current.end = current.end.isAfter(next.end) ? current.end : next.end;
                current.setEnd(current.getEnd().isAfter(next.getEnd()) ? current.getEnd() : next.getEnd());
            } else {
                // æ— é‡å ï¼Œæ·»åŠ å½“å‰åŒºé—´å¹¶æ›´æ–°å½“å‰åŒºé—´
                merged.add(current);
@@ -203,33 +204,6 @@
        return merged;
    }
    // Date与LocalDateTime互相转换的工具方法
    private static LocalDateTime convertToLocalDateTime(Date date) {
        if (date == null) {
            return null;
        }
        return Instant.ofEpochMilli(date.getTime())
                .atZone(ZoneId.systemDefault())
                .toLocalDateTime();
    }
    private static Date convertToDate(LocalDateTime localDateTime) {
        if (localDateTime == null) {
            return null;
        }
        return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }
    static class TimeInterval {
        LocalDateTime start;
        LocalDateTime end;
        public TimeInterval(LocalDateTime start, LocalDateTime end) {
            this.start = start;
            this.end = end;
        }
    }
    // è®¡ç®—去除故障时长后的加工时间
    private long calculateProcessingTimeWithoutFaults(
            List<MdcEquipmentRunningSection> runningSections,
@@ -238,8 +212,8 @@
            Date endTime) {
        // è½¬æ¢ä¸ºLocalDateTime进行处理
        LocalDateTime start = convertToLocalDateTime(startTime);
        LocalDateTime end = convertToLocalDateTime(endTime);
        LocalDateTime start = DateUtils.convertToLocalDateTime(startTime);
        LocalDateTime end = DateUtils.convertToLocalDateTime(endTime);
        // å°†æ•…障记录转换为时间区间并合并重叠部分
//        List<TimeInterval> faultIntervals = faultRecords.stream()
@@ -253,8 +227,8 @@
        // éåŽ†æ¯ä¸ªåŠ å·¥åŒºé—´ï¼ŒæŽ’é™¤æ•…éšœæ—¶é—´
        for (MdcEquipmentRunningSection section : runningSections) {
            LocalDateTime sectionStart = convertToLocalDateTime(section.getStartTime());
            LocalDateTime sectionEnd = convertToLocalDateTime(section.getEndTime());
            LocalDateTime sectionStart = DateUtils.convertToLocalDateTime(section.getStartTime());
            LocalDateTime sectionEnd = DateUtils.convertToLocalDateTime(section.getEndTime());
            // æŽ’除故障时间后的有效加工时间
            List<TimeInterval> validIntervals = excludeFaultsFromSection(
@@ -263,7 +237,7 @@
            // ç´¯åŠ æœ‰æ•ˆåŠ å·¥æ—¶é—´ï¼ˆç§’ï¼‰
            for (TimeInterval interval : validIntervals) {
                totalProcessingTime += ChronoUnit.SECONDS.between(interval.start, interval.end);
                totalProcessingTime += ChronoUnit.SECONDS.between(interval.getStart(), interval.getEnd());
            }
        }
@@ -301,7 +275,7 @@
    // åˆ¤æ–­ä¸¤ä¸ªæ—¶é—´åŒºé—´æ˜¯å¦é‡å 
    private boolean isOverlapping(TimeInterval a, TimeInterval b) {
        return a.start.isBefore(b.end) && b.start.isBefore(a.end);
        return a.getStart().isBefore(b.getEnd()) && b.getStart().isBefore(a.getEnd());
    }
    // åˆ†å‰²åŒºé—´ï¼ˆæ‰£é™¤é‡å éƒ¨åˆ†ï¼‰
@@ -311,13 +285,13 @@
            List<TimeInterval> result) {
        // é‡å å‰çš„部分
        if (valid.start.isBefore(fault.start)) {
            result.add(new TimeInterval(valid.start, fault.start));
        if (valid.getStart().isBefore(fault.getStart())) {
            result.add(new TimeInterval(valid.getStart(), fault.getStart()));
        }
        // é‡å åŽçš„部分
        if (valid.end.isAfter(fault.end)) {
            result.add(new TimeInterval(fault.end, valid.end));
        if (valid.getEnd().isAfter(fault.getEnd())) {
            result.add(new TimeInterval(fault.getEnd(), valid.getEnd()));
        }
    }
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentRunningSectionServiceImpl.java
@@ -13,15 +13,20 @@
import org.jeecg.modules.mdc.service.*;
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.mdc.util.TimeFieldUtils;
import org.jeecg.modules.mdc.vo.EquFaultRecord;
import org.jeecg.modules.mdc.vo.MdcAlarmAnalyzeQueryVo;
import org.jeecg.modules.mdc.vo.MdcEquipmentRunningSectionVo;
import org.jeecg.modules.mdc.vo.TimeInterval;
import org.jeecg.modules.system.service.ISysDictService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
 * @Description: è®¾å¤‡è¿è¡Œæ—¶æ®µçŠ¶æ€è¡¨
@@ -64,6 +69,8 @@
        List<MdcEquipmentRunningSection> running = loadEquipmentRunningTrace(equipmentRunningSectionVo.getEquipmentId(), equipmentRunningSectionVo.getCollectTimeStr());
        //查询报警数据
        List<MdcEquipmentRunningSection> errs = loadEquipmentErrorTrace(equipmentRunningSectionVo.getEquipmentId(), equipmentRunningSectionVo.getCollectTimeStr());
        //查询故障数据
        List<MdcEquipmentRunningSection> faults = loadEquipmentFaultTrace(equipmentRunningSectionVo.getEquipmentId(), equipmentRunningSectionVo.getCollectTimeStr());
        Equipment equip = equipmentService.getOne(new LambdaQueryWrapper<Equipment>().eq(Equipment::getEquipmentid, equipmentRunningSectionVo.getEquipmentId()));
        if (!running.isEmpty()) {
            MdcEquipmentRunningSectionDto dto;
@@ -100,22 +107,12 @@
                        }
                    }
                }
//                Set<TmpEquipmentAlarm> set = entity.getTmpEquipmentAlarmSet();
//                if (entity.getStatus() == 22 && set != null && !set.isEmpty()) {
//                    Iterator<TmpEquipmentAlarm> iterator = entity.getTmpEquipmentAlarmSet().iterator();
//                    //获取报警编号相同的报警信息
//                    while (iterator.hasNext()) {
//                        TmpEquipmentAlarm next = iterator.next();
//                        if (StringUtils.isNotBlank(next.getAlarmNo()) && next.getAlarmNo().equals(entity.getStatus())) {
//                            dto.setAlarmContent(next.getAlarmContent());
//                        }
//                    }
//                }
                dtos.add(dto);
            }
        }
        List<MdcEquipmentRunningSectionDto> result = new ArrayList<>();
        //合并相同状态数据
        for (int i = 0; i < dtos.size() - 1; i++) {
            MdcEquipmentRunningSectionDto mdcEquipmentRunningSectionDto = dtos.get(i);
@@ -141,9 +138,107 @@
            result.addAll(dtos);
        }
        if (faults != null && !faults.isEmpty()) {
            MdcEquipmentRunningSectionDto dto;
            for (MdcEquipmentRunningSection entity : faults) {
                dto = new MdcEquipmentRunningSectionDto();
                BeanUtils.copyProperties(entity, dto);
                result.add(dto);
            }
        }
        return result;
    }
    private List<MdcEquipmentRunningSection> loadEquipmentFaultTrace(String equipmentId, String collectTimeStr) {
        List<MdcEquipmentRunningSection> result = new ArrayList<>();
        Date startTime = DateUtils.getShortDate(collectTimeStr);
        Date now = DateUtils.removeTime(DateUtils.getNow());
        long second = DateUtils.differentSecond(startTime, now);
        Date endTime = DateUtils.plusTime(startTime, 1);
        if (collectTimeStr.equals(LocalDate.now().toString())) {
            endTime = DateUtils.getNow();
        }
        if (second < 0) {
            return Collections.emptyList();
        } else {
            List<EquFaultRecord> equFaultRecordList = this.baseMapper.findFaultList(equipmentId, startTime, endTime);
            if (equFaultRecordList != null && !equFaultRecordList.isEmpty()) {
                // ä¿®æ­£è®°å½•æ—¶é—´
                List<EquFaultRecord> correctedRecords = correctRecordTimes(equFaultRecordList, DateUtils.convertToLocalDateTime(startTime), DateUtils.convertToLocalDateTime(endTime));
                // æŒ‰å¼€å§‹æ—¶é—´æŽ’序
                correctedRecords.sort(Comparator.comparing(EquFaultRecord::getStartTime));
                // åˆå¹¶é‡å æ—¶é—´æ®µ
                List<TimeInterval> mergedIntervals = mergeIntervals(correctedRecords);
                for (TimeInterval mergedInterval : mergedIntervals) {
                    MdcEquipmentRunningSection mdcEquipmentRunningSection = new MdcEquipmentRunningSection(25, equipmentId, DateUtils.convertToDate(mergedInterval.getStart()), DateUtils.convertToDate(mergedInterval.getEnd()), DateUtils.convertToDate(mergedInterval.getStart()).getTime(), DateUtils.convertToDate(mergedInterval.getEnd()).getTime());
                    mdcEquipmentRunningSection.setDuration(DateUtils.differentSecond(mdcEquipmentRunningSection.getStartTime(), mdcEquipmentRunningSection.getEndTime()));
                    result.add(mdcEquipmentRunningSection);
                }
            }
        }
        return result;
    }
    private static List<EquFaultRecord> correctRecordTimes(List<EquFaultRecord> records, LocalDateTime startTime, LocalDateTime endTime) {
        return records.stream()
                .map(record -> {
                    LocalDateTime recordStart = DateUtils.convertToLocalDateTime(record.getStartTime());
                    LocalDateTime recordEnd = record.getEndTime() != null ?
                            DateUtils.convertToLocalDateTime(record.getEndTime()) : null;
                    // ä¿®æ­£å¼€å§‹æ—¶é—´
                    LocalDateTime correctedStart = recordStart.isBefore(startTime) ?
                            startTime : recordStart;
                    // ä¿®æ­£ç»“束时间
                    LocalDateTime correctedEnd = recordEnd == null || recordEnd.isAfter(endTime) ?
                            endTime : recordEnd;
                    // åˆ›å»ºä¿®æ­£åŽçš„记录
                    return new EquFaultRecord(
                            record.getEquipmentId(),
                            DateUtils.convertToDate(correctedStart),
                            DateUtils.convertToDate(correctedEnd)
                    );
                })
                .collect(Collectors.toList());
    }
    private static List<TimeInterval> mergeIntervals(List<EquFaultRecord> records) {
        List<TimeInterval> intervals = records.stream()
                .map(record -> new TimeInterval(
                        DateUtils.convertToLocalDateTime(record.getStartTime()),
                        DateUtils.convertToLocalDateTime(record.getEndTime())))
                .collect(Collectors.toList());
        if (intervals.isEmpty()) {
            return Collections.emptyList();
        }
        List<TimeInterval> merged = new ArrayList<>();
        TimeInterval current = intervals.get(0);
        for (int i = 1; i < intervals.size(); i++) {
            TimeInterval next = intervals.get(i);
            if (next.getStart().isBefore(current.getEnd()) || next.getStart().equals(current.getEnd())) {
                // æœ‰é‡å ï¼Œåˆå¹¶åŒºé—´
                current.setEnd(current.getEnd().isAfter(next.getEnd()) ? current.getEnd() : next.getEnd());
            } else {
                // æ— é‡å ï¼Œæ·»åŠ å½“å‰åŒºé—´å¹¶æ›´æ–°å½“å‰åŒºé—´
                merged.add(current);
                current = next;
            }
        }
        merged.add(current); // æ·»åŠ æœ€åŽä¸€ä¸ªåŒºé—´
        return merged;
    }
    /**
     * æŸ¥è¯¢è¿è¡Œæ•°æ®
     */
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/TimeInterval.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,21 @@
package org.jeecg.modules.mdc.vo;
import lombok.Data;
import java.time.LocalDateTime;
/**
 * @Author: Lius
 * @CreateTime: 2025-06-17
 * @Description:
 */
@Data
public class TimeInterval {
    LocalDateTime start;
    LocalDateTime end;
    public TimeInterval(LocalDateTime start, LocalDateTime end) {
        this.start = start;
        this.end = end;
    }
}