From b2503dcbc841b1d3ded59abd782d9a3e44d13ce4 Mon Sep 17 00:00:00 2001 From: shenzhouyu Date: Thu, 14 May 2026 15:20:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=80hist=E8=A1=A8=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=BC=80=E5=A7=8B=E6=97=B6=E9=97=B4=E6=9F=A5=E8=AF=A2=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E5=8F=98=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/ThreeColorLampDownlogMapper.java | 10 +++++- .../impl/ModbusCollectServiceImpl.java | 35 ++++++++++++------- .../dao/ThreeColorLampDownlogMapper.xml | 13 +++++-- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/threecolor-modbus-collector/src/main/java/com/xujie/modbus/mapper/ThreeColorLampDownlogMapper.java b/threecolor-modbus-collector/src/main/java/com/xujie/modbus/mapper/ThreeColorLampDownlogMapper.java index 8e394a1..263a76d 100644 --- a/threecolor-modbus-collector/src/main/java/com/xujie/modbus/mapper/ThreeColorLampDownlogMapper.java +++ b/threecolor-modbus-collector/src/main/java/com/xujie/modbus/mapper/ThreeColorLampDownlogMapper.java @@ -28,6 +28,14 @@ public interface ThreeColorLampDownlogMapper extends BaseMapper lamps) { + if (lamps == null || lamps.isEmpty()) { + return null; + } + return lamps.stream() + .map(ThreeColorLamp::getCreateDate) + .filter(Objects::nonNull) + .min(Date::compareTo) + .orElse(null); + } @Override public void handleSignal(DeviceInfo deviceInfo) { @@ -404,8 +415,8 @@ public class ModbusCollectServiceImpl Date currentTime = new Date(); Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000); //sfdcTimeHist.setEventTime(fiveMinutesAgo); - ThreeColorLampDownlog sfdcTimeHistStartTime =threeColorLampDownlogMapper.selectThreeColorLampDownlogStartTime(folderLocation.getSite(), folderLocation.getResourceId(),resourceScheduled.getSeqNo()) ; - sfdcTimeHist.setEventTime(sfdcTimeHistStartTime.getStartDate() == null?fiveMinutesAgo:sfdcTimeHistStartTime.getStartDate()); + ThreeColorLampDownlog sfdcTimeHistStartTime = threeColorLampDownlogMapper.selectThreeColorLampDownlogStartTime(folderLocation.getSite(), folderLocation.getResourceId(), resourceScheduled.getSeqNo(), earliestLampCreateDate(colorLampLisByTime)); + sfdcTimeHist.setEventTime(sfdcTimeHistStartTime == null || sfdcTimeHistStartTime.getStartDate() == null ? fiveMinutesAgo : sfdcTimeHistStartTime.getStartDate()); sfdcTimeHist.setEnteredBy(null); sfdcTimeHist.setEventDesc(null); sfdcTimeHist.setDowntimeCode(null); @@ -461,8 +472,8 @@ public class ModbusCollectServiceImpl Date currentTime = new Date(); Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000); //sfdcTimeHist.setEventTime(fiveMinutesAgo); - ThreeColorLampDownlog sfdcTimeHistStartTime =threeColorLampDownlogMapper.selectThreeColorLampDownlogStartTime(folderLocation.getSite(), folderLocation.getResourceId(),resourceScheduled.getSeqNo()) ; - sfdcTimeHist.setEventTime(sfdcTimeHistStartTime.getStartDate() == null?fiveMinutesAgo:sfdcTimeHistStartTime.getStartDate()); + ThreeColorLampDownlog sfdcTimeHistStartTime = threeColorLampDownlogMapper.selectThreeColorLampDownlogStartTime(folderLocation.getSite(), folderLocation.getResourceId(), resourceScheduled.getSeqNo(), earliestLampCreateDate(colorLampLisByTime)); + sfdcTimeHist.setEventTime(sfdcTimeHistStartTime == null || sfdcTimeHistStartTime.getStartDate() == null ? fiveMinutesAgo : sfdcTimeHistStartTime.getStartDate()); sfdcTimeHist.setEnteredBy(null); sfdcTimeHist.setEventDesc(null); sfdcTimeHist.setDowntimeCode(null); @@ -553,8 +564,8 @@ public class ModbusCollectServiceImpl Date currentTime = new Date(); Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000); //sfdcTimeHist.setEventTime(fiveMinutesAgo); - ThreeColorLampDownlog sfdcTimeHistStartTime =threeColorLampDownlogMapper.selectThreeColorLampDownlogStartTime(folderLocation.getSite(), folderLocation.getResourceId(),resourceScheduled.getSeqNo()) ; - sfdcTimeHist.setEventTime(sfdcTimeHistStartTime.getStartDate() == null?fiveMinutesAgo:sfdcTimeHistStartTime.getStartDate()); + ThreeColorLampDownlog sfdcTimeHistStartTime = threeColorLampDownlogMapper.selectThreeColorLampDownlogStartTime(folderLocation.getSite(), folderLocation.getResourceId(), resourceScheduled.getSeqNo(), earliestLampCreateDate(colorLampLisByTime)); + sfdcTimeHist.setEventTime(sfdcTimeHistStartTime == null || sfdcTimeHistStartTime.getStartDate() == null ? fiveMinutesAgo : sfdcTimeHistStartTime.getStartDate()); sfdcTimeHist.setEnteredBy(null); sfdcTimeHist.setEventDesc(null); sfdcTimeHist.setDowntimeCode(null); @@ -610,8 +621,8 @@ public class ModbusCollectServiceImpl Date currentTime = new Date(); Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000); //sfdcTimeHist.setEventTime(fiveMinutesAgo); - ThreeColorLampDownlog sfdcTimeHistStartTime =threeColorLampDownlogMapper.selectThreeColorLampDownlogStartTime(folderLocation.getSite(), folderLocation.getResourceId(),resourceScheduled.getSeqNo()) ; - sfdcTimeHist.setEventTime(sfdcTimeHistStartTime.getStartDate() == null?fiveMinutesAgo:sfdcTimeHistStartTime.getStartDate()); + ThreeColorLampDownlog sfdcTimeHistStartTime = threeColorLampDownlogMapper.selectThreeColorLampDownlogStartTime(folderLocation.getSite(), folderLocation.getResourceId(), resourceScheduled.getSeqNo(), earliestLampCreateDate(colorLampLisByTime)); + sfdcTimeHist.setEventTime(sfdcTimeHistStartTime == null || sfdcTimeHistStartTime.getStartDate() == null ? fiveMinutesAgo : sfdcTimeHistStartTime.getStartDate()); sfdcTimeHist.setEnteredBy(null); sfdcTimeHist.setEventDesc(null); sfdcTimeHist.setDowntimeCode(null); @@ -702,8 +713,8 @@ public class ModbusCollectServiceImpl Date currentTime = new Date(); Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000); //sfdcTimeHist.setEventTime(fiveMinutesAgo); - ThreeColorLampDownlog sfdcTimeHistStartTime =threeColorLampDownlogMapper.selectThreeColorLampDownlogStartTime(folderLocation.getSite(), folderLocation.getResourceId(),resourceScheduled.getSeqNo()) ; - sfdcTimeHist.setEventTime(sfdcTimeHistStartTime.getStartDate() == null?fiveMinutesAgo:sfdcTimeHistStartTime.getStartDate()); + ThreeColorLampDownlog sfdcTimeHistStartTime = threeColorLampDownlogMapper.selectThreeColorLampDownlogStartTime(folderLocation.getSite(), folderLocation.getResourceId(), resourceScheduled.getSeqNo(), earliestLampCreateDate(colorLampLisByTime)); + sfdcTimeHist.setEventTime(sfdcTimeHistStartTime == null || sfdcTimeHistStartTime.getStartDate() == null ? fiveMinutesAgo : sfdcTimeHistStartTime.getStartDate()); sfdcTimeHist.setEnteredBy(null); sfdcTimeHist.setEventDesc(null); sfdcTimeHist.setDowntimeCode(null); @@ -759,8 +770,8 @@ public class ModbusCollectServiceImpl Date currentTime = new Date(); Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000); // sfdcTimeHist.setEventTime(fiveMinutesAgo); - ThreeColorLampDownlog sfdcTimeHistStartTime =threeColorLampDownlogMapper.selectThreeColorLampDownlogStartTime(folderLocation.getSite(), folderLocation.getResourceId(),resourceScheduled.getSeqNo()) ; - sfdcTimeHist.setEventTime(sfdcTimeHistStartTime.getStartDate() == null?fiveMinutesAgo:sfdcTimeHistStartTime.getStartDate()); + ThreeColorLampDownlog sfdcTimeHistStartTime = threeColorLampDownlogMapper.selectThreeColorLampDownlogStartTime(folderLocation.getSite(), folderLocation.getResourceId(), resourceScheduled.getSeqNo(), earliestLampCreateDate(colorLampLisByTime)); + sfdcTimeHist.setEventTime(sfdcTimeHistStartTime == null || sfdcTimeHistStartTime.getStartDate() == null ? fiveMinutesAgo : sfdcTimeHistStartTime.getStartDate()); sfdcTimeHist.setEnteredBy(null); sfdcTimeHist.setEventDesc(null); sfdcTimeHist.setDowntimeCode(null); diff --git a/threecolor-modbus-collector/src/main/resources/dao/ThreeColorLampDownlogMapper.xml b/threecolor-modbus-collector/src/main/resources/dao/ThreeColorLampDownlogMapper.xml index 65c2db3..3aa9a18 100644 --- a/threecolor-modbus-collector/src/main/resources/dao/ThreeColorLampDownlogMapper.xml +++ b/threecolor-modbus-collector/src/main/resources/dao/ThreeColorLampDownlogMapper.xml @@ -63,7 +63,16 @@ WHERE site = #{site} and resource_id = #{resourceId} and seq_no = #{seqNo} and start_date is not null - and end_date is null - ORDER BY start_date DESC + + AND FORMAT(#{lampEarliestCreateDate}, 'yyyy-MM-dd HH:mm') <= FORMAT(start_date, 'yyyy-MM-dd HH:mm') + + + + ORDER BY start_date ASC + + + ORDER BY start_date DESC + + \ No newline at end of file