Browse Source

往hist表添加开始时间查询条件变了

master
shenzhouyu 4 weeks ago
parent
commit
b2503dcbc8
  1. 10
      threecolor-modbus-collector/src/main/java/com/xujie/modbus/mapper/ThreeColorLampDownlogMapper.java
  2. 35
      threecolor-modbus-collector/src/main/java/com/xujie/modbus/service/impl/ModbusCollectServiceImpl.java
  3. 13
      threecolor-modbus-collector/src/main/resources/dao/ThreeColorLampDownlogMapper.xml

10
threecolor-modbus-collector/src/main/java/com/xujie/modbus/mapper/ThreeColorLampDownlogMapper.java

@ -28,6 +28,14 @@ public interface ThreeColorLampDownlogMapper extends BaseMapper<ThreeColorLampDo
@Param("orderNo") String orderNo, @Param("orderNo") String orderNo,
@Param("runTime") int runTime); @Param("runTime") int runTime);
ThreeColorLampDownlog selectThreeColorLampDownlogStartTime(String site, String resourceId, String seqNo);
/**
* seq 维度的 downlog 若传入 lamp 窗口内最早采集时间则只保留
* FORMAT(该时间,'yyyy-MM-dd HH:mm') &lt;= FORMAT(start_date,'yyyy-MM-dd HH:mm') 的记录
* 并取 start_date 最早的一条未传入时保持原逻辑 start_date 最晚一条
*/
ThreeColorLampDownlog selectThreeColorLampDownlogStartTime(@Param("site") String site,
@Param("resourceId") String resourceId,
@Param("seqNo") String seqNo,
@Param("lampEarliestCreateDate") Date lampEarliestCreateDate);
} }

35
threecolor-modbus-collector/src/main/java/com/xujie/modbus/service/impl/ModbusCollectServiceImpl.java

@ -84,6 +84,17 @@ public class ModbusCollectServiceImpl
}); });
} }
/** colorLampLisByTime 中非空 createDate 的最早值,供 downlog 按分钟对齐筛选。 */
private static Date earliestLampCreateDate(List<ThreeColorLamp> lamps) {
if (lamps == null || lamps.isEmpty()) {
return null;
}
return lamps.stream()
.map(ThreeColorLamp::getCreateDate)
.filter(Objects::nonNull)
.min(Date::compareTo)
.orElse(null);
}
@Override @Override
public void handleSignal(DeviceInfo deviceInfo) { public void handleSignal(DeviceInfo deviceInfo) {
@ -404,8 +415,8 @@ public class ModbusCollectServiceImpl
Date currentTime = new Date(); Date currentTime = new Date();
Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000); Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000);
//sfdcTimeHist.setEventTime(fiveMinutesAgo); //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.setEnteredBy(null);
sfdcTimeHist.setEventDesc(null); sfdcTimeHist.setEventDesc(null);
sfdcTimeHist.setDowntimeCode(null); sfdcTimeHist.setDowntimeCode(null);
@ -461,8 +472,8 @@ public class ModbusCollectServiceImpl
Date currentTime = new Date(); Date currentTime = new Date();
Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000); Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000);
//sfdcTimeHist.setEventTime(fiveMinutesAgo); //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.setEnteredBy(null);
sfdcTimeHist.setEventDesc(null); sfdcTimeHist.setEventDesc(null);
sfdcTimeHist.setDowntimeCode(null); sfdcTimeHist.setDowntimeCode(null);
@ -553,8 +564,8 @@ public class ModbusCollectServiceImpl
Date currentTime = new Date(); Date currentTime = new Date();
Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000); Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000);
//sfdcTimeHist.setEventTime(fiveMinutesAgo); //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.setEnteredBy(null);
sfdcTimeHist.setEventDesc(null); sfdcTimeHist.setEventDesc(null);
sfdcTimeHist.setDowntimeCode(null); sfdcTimeHist.setDowntimeCode(null);
@ -610,8 +621,8 @@ public class ModbusCollectServiceImpl
Date currentTime = new Date(); Date currentTime = new Date();
Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000); Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000);
//sfdcTimeHist.setEventTime(fiveMinutesAgo); //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.setEnteredBy(null);
sfdcTimeHist.setEventDesc(null); sfdcTimeHist.setEventDesc(null);
sfdcTimeHist.setDowntimeCode(null); sfdcTimeHist.setDowntimeCode(null);
@ -702,8 +713,8 @@ public class ModbusCollectServiceImpl
Date currentTime = new Date(); Date currentTime = new Date();
Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000); Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000);
//sfdcTimeHist.setEventTime(fiveMinutesAgo); //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.setEnteredBy(null);
sfdcTimeHist.setEventDesc(null); sfdcTimeHist.setEventDesc(null);
sfdcTimeHist.setDowntimeCode(null); sfdcTimeHist.setDowntimeCode(null);
@ -759,8 +770,8 @@ public class ModbusCollectServiceImpl
Date currentTime = new Date(); Date currentTime = new Date();
Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000); Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000);
// sfdcTimeHist.setEventTime(fiveMinutesAgo); // 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.setEnteredBy(null);
sfdcTimeHist.setEventDesc(null); sfdcTimeHist.setEventDesc(null);
sfdcTimeHist.setDowntimeCode(null); sfdcTimeHist.setDowntimeCode(null);

13
threecolor-modbus-collector/src/main/resources/dao/ThreeColorLampDownlogMapper.xml

@ -63,7 +63,16 @@
WHERE WHERE
site = #{site} and resource_id = #{resourceId} and seq_no = #{seqNo} site = #{site} and resource_id = #{resourceId} and seq_no = #{seqNo}
and start_date is not null and start_date is not null
and end_date is null
ORDER BY start_date DESC
<if test="lampEarliestCreateDate != null">
AND FORMAT(#{lampEarliestCreateDate}, 'yyyy-MM-dd HH:mm') &lt;= FORMAT(start_date, 'yyyy-MM-dd HH:mm')
</if>
<choose>
<when test="lampEarliestCreateDate != null">
ORDER BY start_date ASC
</when>
<otherwise>
ORDER BY start_date DESC
</otherwise>
</choose>
</select> </select>
</mapper> </mapper>
Loading…
Cancel
Save