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