Browse Source

三色灯采集修改

master
shenzhouyu 2 weeks ago
parent
commit
30a1e8fe8c
  1. 1
      threecolor-modbus-collector/src/main/java/com/xujie/modbus/mapper/ThreeColorLampDownlogMapper.java
  2. 151
      threecolor-modbus-collector/src/main/java/com/xujie/modbus/service/impl/ModbusCollectServiceImpl.java
  3. 6
      threecolor-modbus-collector/src/main/resources/dao/ThreeColorLampDownlogMapper.xml

1
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> { public interface ThreeColorLampDownlogMapper extends BaseMapper<ThreeColorLampDownlog> {
ThreeColorLampDownlog selectDownlogLast(@Param("site") String site, @Param("resourceId") String resourceId); ThreeColorLampDownlog selectDownlogLast(@Param("site") String site, @Param("resourceId") String resourceId);
int updateDownLogEventDesc(String startTime, String endTime,String eventDesc);
} }

151
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 org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; 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<ResourceScheduled> 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<ResourceScheduled> 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<ResourceScheduled> 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{ }else{
@ -460,7 +597,7 @@ public class ModbusCollectServiceImpl
downlog.setSeqNo(soscheduled.getSeqno() == null ? null : soscheduled.getSeqno()); downlog.setSeqNo(soscheduled.getSeqno() == null ? null : soscheduled.getSeqno());
downlog.setSShiftno(soscheduled.getSShiftno() == null ? null : soscheduled.getSShiftno()); downlog.setSShiftno(soscheduled.getSShiftno() == null ? null : soscheduled.getSShiftno());
if(registerData.get(2) == 1){ if(registerData.get(2) == 1){
downlog.setEventDesc("设备故障");
downlog.setEventDesc("短暂停");
} }
if(registerData.get(0) == 1){ if(registerData.get(0) == 1){
downlog.setEventDesc("正常运作"); downlog.setEventDesc("正常运作");
@ -489,7 +626,17 @@ public class ModbusCollectServiceImpl
sfdcTimeHist.setCompletedFlag("Y"); sfdcTimeHist.setCompletedFlag("Y");
int i = sfdcTimeHistMapper.updatesfdcTimeHistById(sfdcTimeHist); int i = sfdcTimeHistMapper.updatesfdcTimeHistById(sfdcTimeHist);
logger.info("更新了sfdc表,completedFlaf变为{},id:{}",sfdcTimeHist.getCompletedFlag(),updateResourceScheduled.getSfdcid()); 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){ if(i >0){
UpdateWrapper<ResourceScheduled> updateWrapper = new UpdateWrapper<>(); UpdateWrapper<ResourceScheduled> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("site", folderLocation.getSite()); updateWrapper.eq("site", folderLocation.getSite());
@ -514,7 +661,7 @@ public class ModbusCollectServiceImpl
downlog.setSeqNo(soscheduled.getSeqno()== null ? null : soscheduled.getSeqno()); downlog.setSeqNo(soscheduled.getSeqno()== null ? null : soscheduled.getSeqno());
downlog.setSShiftno(soscheduled.getSShiftno()== null ? null : soscheduled.getSShiftno()); downlog.setSShiftno(soscheduled.getSShiftno()== null ? null : soscheduled.getSShiftno());
if(registerData.get(2) == 1){ if(registerData.get(2) == 1){
downlog.setEventDesc("设备故障");
downlog.setEventDesc("短暂停");
} }
if(registerData.get(0) == 1){ if(registerData.get(0) == 1){
downlog.setEventDesc("正常运作"); downlog.setEventDesc("正常运作");

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

@ -1,6 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.xujie.modbus.mapper.ThreeColorLampDownlogMapper"> <mapper namespace="com.xujie.modbus.mapper.ThreeColorLampDownlogMapper">
<update id="updateDownLogEventDesc">
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') &lt;= #{endTime}
</update>
<select id="selectDownlogLast" resultType="com.xujie.modbus.entity.ThreeColorLampDownlog"> <select id="selectDownlogLast" resultType="com.xujie.modbus.entity.ThreeColorLampDownlog">
SELECT top 1 SELECT top 1

Loading…
Cancel
Save