From 30a1e8fe8c3c349f233ac695ca3a744d4acd9bf8 Mon Sep 17 00:00:00 2001 From: shenzhouyu Date: Fri, 3 Apr 2026 17:20:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=89=E8=89=B2=E7=81=AF=E9=87=87=E9=9B=86?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/ThreeColorLampDownlogMapper.java | 1 + .../impl/ModbusCollectServiceImpl.java | 151 +++++++++++++++++- .../dao/ThreeColorLampDownlogMapper.xml | 6 + 3 files changed, 156 insertions(+), 2 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 d53a063..5619a7b 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 @@ -9,4 +9,5 @@ import org.apache.ibatis.annotations.Param; public interface ThreeColorLampDownlogMapper extends BaseMapper { ThreeColorLampDownlog selectDownlogLast(@Param("site") String site, @Param("resourceId") String resourceId); + int updateDownLogEventDesc(String startTime, String endTime,String eventDesc); } diff --git a/threecolor-modbus-collector/src/main/java/com/xujie/modbus/service/impl/ModbusCollectServiceImpl.java b/threecolor-modbus-collector/src/main/java/com/xujie/modbus/service/impl/ModbusCollectServiceImpl.java index e32f06d..936d740 100644 --- a/threecolor-modbus-collector/src/main/java/com/xujie/modbus/service/impl/ModbusCollectServiceImpl.java +++ b/threecolor-modbus-collector/src/main/java/com/xujie/modbus/service/impl/ModbusCollectServiceImpl.java @@ -21,6 +21,7 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.math.BigDecimal; +import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -429,6 +430,142 @@ public class ModbusCollectServiceImpl } + //011的情况 + boolean yellowInsertHist = false; + if (colorLampLisByTime != null && colorLampLisByTime.size() > 0) { + // 只取最近 failureTime 条记录做判断 + yellowInsertHist = true; + for (ThreeColorLamp lamp3 : colorLampLisByTime) { + boolean isYellow = ("0".equals(lamp3.getGreen())) && + ("1".equals(lamp3.getOrange())) && + ("1".equals(lamp3.getRed())); + if (!isYellow) { + yellowInsertHist = false; + break; + } + } + } + + if (yellowInsertHist){ + if(!"X".equals(resourceScheduled.getIssend())){ + SfdcTimeHist timeHist = sfdcTimeHistMapper.selectSfdcTimeHistByNew(folderLocation.getSite(), resourceScheduled.getSeqNo(), "自动停机"); + if(timeHist == null){ + SoscheduledroutingVo soscheduled = threeColorLampMapper.getSoscheduled(resourceScheduled.getSeqNo()); + if(soscheduled != null){ + int histSeqno = threeColorLampMapper.selectHistSeqno(folderLocation.getSite(), resourceScheduled.getSeqNo()); + SfdcTimeHist sfdcTimeHist = new SfdcTimeHist(); + sfdcTimeHist.setSite(folderLocation.getSite()); + sfdcTimeHist.setOrderNo(soscheduled.getOrderno()); + sfdcTimeHist.setItemNo(Double.valueOf(soscheduled.getItemno())); + sfdcTimeHist.setSeqNo(soscheduled.getSeqno()); + sfdcTimeHist.setHistSeqno(histSeqno+1); + Date currentTime = new Date(); + Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000); + sfdcTimeHist.setEventTime(fiveMinutesAgo); + sfdcTimeHist.setEnteredBy(null); + sfdcTimeHist.setEventDesc(null); + sfdcTimeHist.setDowntimeCode(null); + sfdcTimeHist.setEventType("D"); + sfdcTimeHist.setLinkhistSeqno(null); + sfdcTimeHist.setTillenteredBy(null); + sfdcTimeHist.setCompletedFlag("N"); + if("T".equals(resourceScheduled.getStatus())){ + sfdcTimeHist.setDowntimePhasein("调机"); + }else{ + sfdcTimeHist.setDowntimePhasein("生产"); + } + + sfdcTimeHist.setRollNo(soscheduled.getRollNo()); + sfdcTimeHist.setCreatedDate(new Date()); + sfdcTimeHist.setCreatedBy("自动停机"); + sfdcTimeHist.setUpdatedDate(new Date()); + sfdcTimeHist.setDelflag("N"); + sfdcTimeHist.setVersion(1); + sfdcTimeHist.setReplaceFlag("0"); + sfdcTimeHist.setBatchNo(null); + sfdcTimeHist.setRemark(null); + int insert = sfdcTimeHistMapper.insert(sfdcTimeHist); + logger.info("停机红灯插入数据: {}", sfdcTimeHist); + if(insert >0){ + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("site", folderLocation.getSite()); + updateWrapper.eq("resource_id", folderLocation.getResourceId()); + updateWrapper.eq("seq_no", resourceScheduled.getSeqNo()); + updateWrapper.set("issend", "X"); + updateWrapper.set("sfdcid",sfdcTimeHist.getId()); + resourceScheduledMapper.update(updateWrapper); + logger.info("更新了中间表,变为X,sfdcid:{}",sfdcTimeHist.getId()); + } + + } + + }else{ + if( "Y".equals(timeHist.getCompletedFlag())){ + SoscheduledroutingVo soscheduled = threeColorLampMapper.getSoscheduled(resourceScheduled.getSeqNo()); + if(soscheduled != null){ + int histSeqno = threeColorLampMapper.selectHistSeqno(folderLocation.getSite(), resourceScheduled.getSeqNo()); + SfdcTimeHist sfdcTimeHist = new SfdcTimeHist(); + sfdcTimeHist.setSite(folderLocation.getSite()); + sfdcTimeHist.setOrderNo(soscheduled.getOrderno()); + sfdcTimeHist.setItemNo(Double.valueOf(soscheduled.getItemno())); + sfdcTimeHist.setSeqNo(soscheduled.getSeqno()); + sfdcTimeHist.setHistSeqno(histSeqno+1); + Date currentTime = new Date(); + Date fiveMinutesAgo = new Date(currentTime.getTime() - failureTime * 60 * 1000); + sfdcTimeHist.setEventTime(fiveMinutesAgo); + sfdcTimeHist.setEnteredBy(null); + sfdcTimeHist.setEventDesc(null); + sfdcTimeHist.setDowntimeCode(null); + sfdcTimeHist.setEventType("D"); + sfdcTimeHist.setLinkhistSeqno(null); + sfdcTimeHist.setTillenteredBy(null); + sfdcTimeHist.setCompletedFlag("N"); + if("T".equals(resourceScheduled.getStatus())){ + sfdcTimeHist.setDowntimePhasein("调机"); + }else{ + sfdcTimeHist.setDowntimePhasein("生产"); + } + + sfdcTimeHist.setRollNo(soscheduled.getRollNo()); + sfdcTimeHist.setCreatedDate(new Date()); + sfdcTimeHist.setCreatedBy("自动停机"); + sfdcTimeHist.setUpdatedDate(new Date()); + sfdcTimeHist.setDelflag("N"); + sfdcTimeHist.setVersion(1); + sfdcTimeHist.setReplaceFlag("0"); + sfdcTimeHist.setBatchNo(null); + sfdcTimeHist.setRemark(null); + int insert = sfdcTimeHistMapper.insert(sfdcTimeHist); + logger.info("停机红灯插入数据: {}", sfdcTimeHist); + if(insert >0){ + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("site", folderLocation.getSite()); + updateWrapper.eq("resource_id", folderLocation.getResourceId()); + updateWrapper.eq("seq_no", resourceScheduled.getSeqNo()); + updateWrapper.set("issend", "X"); + updateWrapper.set("sfdcid",sfdcTimeHist.getId()); + resourceScheduledMapper.update(updateWrapper); + logger.info("更新了中间表,变为X,sfdcid:{}",sfdcTimeHist.getId()); + } + + } + + } + } + + } + + }else{ + // 不满足连续 failureTime 条 0,0,1 的条件时,保持原有行为:将中间表发送状态置为 Y + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("site", folderLocation.getSite()); + updateWrapper.eq("resource_id", folderLocation.getResourceId()); + updateWrapper.eq("seq_no", resourceScheduled.getSeqNo()); + updateWrapper.set("issend", "Y"); + resourceScheduledMapper.update(updateWrapper); + + } + } }else{ @@ -460,7 +597,7 @@ public class ModbusCollectServiceImpl downlog.setSeqNo(soscheduled.getSeqno() == null ? null : soscheduled.getSeqno()); downlog.setSShiftno(soscheduled.getSShiftno() == null ? null : soscheduled.getSShiftno()); if(registerData.get(2) == 1){ - downlog.setEventDesc("设备故障"); + downlog.setEventDesc("短暂停"); } if(registerData.get(0) == 1){ downlog.setEventDesc("正常运作"); @@ -489,7 +626,17 @@ public class ModbusCollectServiceImpl sfdcTimeHist.setCompletedFlag("Y"); int i = sfdcTimeHistMapper.updatesfdcTimeHistById(sfdcTimeHist); logger.info("更新了sfdc表,completedFlaf变为{},id:{}",sfdcTimeHist.getCompletedFlag(),updateResourceScheduled.getSfdcid()); + SfdcTimeHist sfdcTimeHist1 = sfdcTimeHistMapper.selectById(sfdcTimeHist.getId()); + if(sfdcTimeHist1 != null){ + logger.info("获取的sfdc表数据{}",sfdcTimeHist1); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + if(StringUtils.isNotBlank(sfdcTimeHist1.getEventDesc())){ + String startTime = sdf.format(sfdcTimeHist1.getCreatedDate()); + String endTime = sdf.format(sfdcTimeHist1.getTillTime()); + threeColorLampDownlogMapper.updateDownLogEventDesc(startTime,endTime,sfdcTimeHist1.getEventDesc()); + } + } if(i >0){ UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.eq("site", folderLocation.getSite()); @@ -514,7 +661,7 @@ public class ModbusCollectServiceImpl downlog.setSeqNo(soscheduled.getSeqno()== null ? null : soscheduled.getSeqno()); downlog.setSShiftno(soscheduled.getSShiftno()== null ? null : soscheduled.getSShiftno()); if(registerData.get(2) == 1){ - downlog.setEventDesc("设备故障"); + downlog.setEventDesc("短暂停"); } if(registerData.get(0) == 1){ downlog.setEventDesc("正常运作"); diff --git a/threecolor-modbus-collector/src/main/resources/dao/ThreeColorLampDownlogMapper.xml b/threecolor-modbus-collector/src/main/resources/dao/ThreeColorLampDownlogMapper.xml index f91e500..5585876 100644 --- a/threecolor-modbus-collector/src/main/resources/dao/ThreeColorLampDownlogMapper.xml +++ b/threecolor-modbus-collector/src/main/resources/dao/ThreeColorLampDownlogMapper.xml @@ -1,6 +1,12 @@ + + update three_color_lamp_downlog + set event_desc = #{eventDesc} + where FORMAT(start_date, 'yyyy-MM-dd HH:mm') >= #{startTime} + and FORMAT(end_date, 'yyyy-MM-dd HH:mm') <= #{endTime} +