Browse Source

三色灯改动

master
shenzhouyu 2 months ago
parent
commit
26afc63cc4
  1. 2
      threecolor-modbus-collector/src/main/java/com/xujie/modbus/mapper/SfdcTimeHistMapper.java
  2. 195
      threecolor-modbus-collector/src/main/java/com/xujie/modbus/service/impl/ModbusCollectServiceImpl.java
  3. 3
      threecolor-modbus-collector/src/main/resources/dao/SfdcTimeHistMapper.xml

2
threecolor-modbus-collector/src/main/java/com/xujie/modbus/mapper/SfdcTimeHistMapper.java

@ -10,4 +10,6 @@ import org.apache.ibatis.annotations.Param;
public interface SfdcTimeHistMapper extends BaseMapper<SfdcTimeHist> {
int updatesfdcTimeHistById(@Param("sfdcTimeHist") SfdcTimeHist sfdcTimeHist);
SfdcTimeHist selectSfdcTimeHistByNew(@Param("site") String site, @Param("seqNo") String seqNo, @Param("createdBy") String createdBy);
}

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

@ -234,90 +234,137 @@ public class ModbusCollectServiceImpl
System.out.println("寄存器数据:"+ registerData);
logger.info("寄存器数据: {}", registerData);
//site+equipmentNo查询前5分钟如果5条都是001就往sfdc_time_hist插入数据先要确认中间表有工单号
//site+equipmentNo查询前failureTime分钟如果failureTime条都是001就往sfdc_time_hist插入数据先要确认中间表有工单号
List<ThreeColorLamp> colorLampLisByTime = threeColorLampMapper.getThreeColorLampLisByTime(folderLocation.getSite(), folderLocation.getResourceId(), failureTime);
QueryWrapper<ResourceScheduled> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("site", folderLocation.getSite());
queryWrapper.eq("resource_id", folderLocation.getResourceId());
queryWrapper.isNotNull("seq_no");
List<ResourceScheduled> resourceScheduleds = resourceScheduledMapper.selectList(queryWrapper);
if (resourceScheduleds != null && resourceScheduleds.size()>0){
for(ResourceScheduled resourceScheduled:resourceScheduleds){
Map<String, Integer> map = new HashMap<>();
for (ThreeColorLamp lamp1 : colorLampLisByTime) {
String key = lamp1.getGreen() + "," + lamp1.getOrange() + "," + lamp1.getRed();
map.put(key, map.getOrDefault(key, 0) + 1);
}
boolean hasDuplicateFlag = true;
for (int i = 0; i < colorLampLisByTime.size(); i++) {
ThreeColorLamp lamp2 = colorLampLisByTime.get(i);
String key = lamp2.getGreen() + "," + lamp2.getOrange() + "," + lamp2.getRed();
boolean hasDuplicate = map.get(key) > 1;
if (!hasDuplicate) {
hasDuplicateFlag = false ;
break;
}
}
if (hasDuplicateFlag){
boolean red = false;
for (ThreeColorLamp lamp3 : colorLampLisByTime) {
red = ("0".equals(lamp3.getGreen())) &&
("0".equals(lamp3.getOrange()))&&
("1".equals(lamp3.getRed()));
if (!red){
break;
// site+equipmentNo 查询前 failureTime 分钟如果 **failureTime 条记录全部为 0,0,1**才插入 sfdc_time_hist
boolean shouldInsertHist = false;
if (colorLampLisByTime != null && colorLampLisByTime.size() >= failureTime) {
// 只取最近 failureTime 条记录做判断
int size = colorLampLisByTime.size();
List<ThreeColorLamp> lastN = colorLampLisByTime.subList(size - failureTime, size);
// 要求条数刚好为 failureTime且每条都是 0,0,1
if (lastN.size() == failureTime) {
shouldInsertHist = true;
for (ThreeColorLamp lamp3 : lastN) {
boolean isRed = ("0".equals(lamp3.getGreen())) &&
("0".equals(lamp3.getOrange())) &&
("1".equals(lamp3.getRed()));
if (!isRed) {
shouldInsertHist = false;
break;
}
}
}
}
if (red){
if (shouldInsertHist){
if(!"X".equals(resourceScheduled.getIssend())){
SoscheduledroutingVo soscheduled = threeColorLampMapper.getSoscheduled(resourceScheduled.getSeqNo());
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("调机");
SfdcTimeHist timeHist = sfdcTimeHistMapper.selectSfdcTimeHistByNew(folderLocation.getSite(), resourceScheduled.getSeqNo(), "自动停机");
if(timeHist == null){
SoscheduledroutingVo soscheduled = threeColorLampMapper.getSoscheduled(resourceScheduled.getSeqNo());
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);
sfdcTimeHistMapper.insert(sfdcTimeHist);
logger.info("停机红灯插入数据: {}", sfdcTimeHist);
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{
sfdcTimeHist.setDowntimePhasein("生产");
if( "Y".equals(timeHist.getCompletedFlag())){
SoscheduledroutingVo soscheduled = threeColorLampMapper.getSoscheduled(resourceScheduled.getSeqNo());
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);
sfdcTimeHistMapper.insert(sfdcTimeHist);
logger.info("停机红灯插入数据: {}", sfdcTimeHist);
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());
}
}
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);
sfdcTimeHistMapper.insert(sfdcTimeHist);
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);
}
}
}else{
}else{
// 不满足连续 failureTime 0,0,1 的条件时保持原有行为将中间表发送状态置为 Y
UpdateWrapper<ResourceScheduled> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("site", folderLocation.getSite());
updateWrapper.eq("resource_id", folderLocation.getResourceId());
@ -326,6 +373,7 @@ public class ModbusCollectServiceImpl
resourceScheduledMapper.update(updateWrapper);
}
}
}else{
@ -368,8 +416,13 @@ public class ModbusCollectServiceImpl
String nowlamp = registerData.get(0)+"" + registerData.get(1) + ""+registerData.get(2);
downlog.setLamp(nowlamp);
threeColorLampDownlogMapper.insert(downlog);
logger.info("获取数据不同后统计插入数据: {}", downlog);
logger.info("获取到的亮灯: {}", 1 == registerData.get(0) && 0 == registerData.get(1) && 0 == registerData.get(2));
if(1 == registerData.get(0) && 0 == registerData.get(1) && 0 == registerData.get(2)){
if(StringUtils.isNotBlank(resourceScheduled.getIssend()) && resourceScheduled.getSfdcid() != null){
ResourceScheduled updateResourceScheduled = resourceScheduledMapper.selectById(resourceScheduled.getId());
logger.info("正常中间表发送状态{},sfdcid{}", resourceScheduled.getIssend(),resourceScheduled.getSfdcid());
if(StringUtils.isNotBlank(resourceScheduled.getIssend()) && updateResourceScheduled.getSfdcid() != null){
SfdcTimeHist sfdcTimeHist = new SfdcTimeHist();
sfdcTimeHist.setId(resourceScheduled.getSfdcid());
sfdcTimeHist.setSite(folderLocation.getSite());
@ -377,6 +430,7 @@ public class ModbusCollectServiceImpl
sfdcTimeHist.setTillenteredTime(new Date());
sfdcTimeHist.setCompletedFlag("Y");
sfdcTimeHistMapper.updatesfdcTimeHistById(sfdcTimeHist);
logger.info("更新了sfdc表,变为Y,id:{}",resourceScheduled.getSfdcid());
UpdateWrapper<ResourceScheduled> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("site", folderLocation.getSite());
@ -385,6 +439,7 @@ public class ModbusCollectServiceImpl
updateWrapper.set("issend", null);
updateWrapper.set("sfdcid",null);
resourceScheduledMapper.update(updateWrapper);
logger.info("更新了中间表,变为null,id:{}",resourceScheduled.getId());
}
}
}else{
@ -432,6 +487,7 @@ public class ModbusCollectServiceImpl
ThreeColorLampDownlog downlog = new ThreeColorLampDownlog();
downlog.setSite(folderLocation.getSite());
downlog.setResourceId(folderLocation.getResourceId());
downlog.setEventDesc("计划停机");
downlog.setStartDate(new Date());
downlog.setCreateDate(new Date());
@ -442,6 +498,7 @@ public class ModbusCollectServiceImpl
if(downlogChangeLast == null){
ThreeColorLampDownlog downlog = new ThreeColorLampDownlog();
downlog.setSite(folderLocation.getSite());
downlog.setResourceId(folderLocation.getResourceId());
downlog.setEventDesc("计划停机");
downlog.setStartDate(new Date());
downlog.setCreateDate(new Date());

3
threecolor-modbus-collector/src/main/resources/dao/SfdcTimeHistMapper.xml

@ -6,4 +6,7 @@
UPDATE sfdc_time_hist SET till_time = #{sfdcTimeHist.tillTime}, tillentered_time = #{sfdcTimeHist.tillenteredTime},
completed_flag = #{sfdcTimeHist.completedFlag},total_time = DATEDIFF(MINUTE, event_time, #{sfdcTimeHist.tillTime}) WHERE id = #{sfdcTimeHist.id};
</update>
<select id="selectSfdcTimeHistByNew" resultType="com.xujie.modbus.entity.SfdcTimeHist">
select top 1 id,site,order_no,item_no,seq_no,hist_seqno,event_time,entered_by,event_desc,downtime_code,event_type,linkhist_seqno,till_time,tillentered_time,tillentered_by,completed_flag,total_time,downtime_phasein,roll_no,created_date,created_by,updated_date,updated from sfdc_time_hist where site = #{site} and seq_no=#{seqNo} and created_by = #{createdBy} order by id
</select>
</mapper>
Loading…
Cancel
Save