From 2b6aad0dabc78496e8eb7d49f7fb63d93cccb816 Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期二, 17 六月 2025 11:24:46 +0800 Subject: [PATCH] 设备日志页面添加设备故障时间段显示 --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentFaultInfoServiceImpl.java | 70 ++++--------- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentRunningSectionServiceImpl.java | 117 +++++++++++++++++++++-- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentRunningSectionMapper.xml | 15 +++ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/TimeInterval.java | 21 ++++ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipmentRunningSection.java | 11 ++ lxzn-module-mdc-common/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java | 32 +++++ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentRunningSectionMapper.java | 3 7 files changed, 207 insertions(+), 62 deletions(-) diff --git a/lxzn-module-mdc-common/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java b/lxzn-module-mdc-common/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java index 1a41d3e..34592cb 100644 --- a/lxzn-module-mdc-common/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java +++ b/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涓嶭ocalDateTime浜掔浉杞崲鐨勫伐鍏锋柟娉� + * + * @param date + * @return + */ + public static LocalDateTime convertToLocalDateTime(Date date) { + if (date == null) { + return null; + } + return Instant.ofEpochMilli(date.getTime()) + .atZone(ZoneId.systemDefault()) + .toLocalDateTime(); + } + + /** + * Date涓嶭ocalDateTime浜掔浉杞崲鐨勫伐鍏锋柟娉� + * + * @param localDateTime + * @return + */ + public static Date convertToDate(LocalDateTime localDateTime) { + if (localDateTime == null) { + return null; + } + return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); + } } diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipmentRunningSection.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipmentRunningSection.java index df2abf4..00110c7 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipmentRunningSection.java +++ b/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; + } } diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentRunningSectionMapper.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentRunningSectionMapper.java index 3395eea..602ee5c 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentRunningSectionMapper.java +++ b/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); } diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentRunningSectionMapper.xml b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentRunningSectionMapper.xml index dd35b9f..fec2b60 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentRunningSectionMapper.xml +++ b/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> \ No newline at end of file diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentFaultInfoServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentFaultInfoServiceImpl.java index 189a144..df0f7c6 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentFaultInfoServiceImpl.java +++ b/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涓嶭ocalDateTime浜掔浉杞崲鐨勫伐鍏锋柟娉� - 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) { // 杞崲涓篖ocalDateTime杩涜澶勭悊 - 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())); } } diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentRunningSectionServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentRunningSectionServiceImpl.java index d171beb..158aca7 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentRunningSectionServiceImpl.java +++ b/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; + } + /** * 鏌ヨ杩愯鏁版嵁 */ diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/TimeInterval.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/TimeInterval.java new file mode 100644 index 0000000..8193ab1 --- /dev/null +++ b/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; + } +} -- Gitblit v1.9.3