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; } }