|
@@ -171,7 +171,8 @@ public class InterlockAvoidCircularServiceImpl implements InterlockAvoidCircular
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 修改系统时,修改联锁总表的联锁状态和回路健康等级
|
|
|
|
|
|
+ * 修改系统时,修改联锁的各个状态和值
|
|
|
|
+ * 如果系统状态修改了,更新点位时间
|
|
*
|
|
*
|
|
* @param base
|
|
* @param base
|
|
*/
|
|
*/
|
|
@@ -234,6 +235,219 @@ public class InterlockAvoidCircularServiceImpl implements InterlockAvoidCircular
|
|
List<InterlockSummary> interlockSummaryList = interlockAvoidCircularMapper.getInterlockSummaryListBySystemId(base.getId());
|
|
List<InterlockSummary> interlockSummaryList = interlockAvoidCircularMapper.getInterlockSummaryListBySystemId(base.getId());
|
|
|
|
|
|
for(InterlockSummary interlockSummary:interlockSummaryList){
|
|
for(InterlockSummary interlockSummary:interlockSummaryList){
|
|
|
|
+ //联锁总表更新点位时间
|
|
|
|
+ interlockSummary.setTagTime(formattedDateTime);
|
|
|
|
+ //设置各状态默认值
|
|
|
|
+ String interlockStatus = interlockStatusTy;;// 先设置为 联锁状态-投用
|
|
|
|
+ String loopHealthLevel = "A";// 回路健康级别
|
|
|
|
+ String controlSystemStatus = controlSystemStatusNormal;// 总体 先设置为 控制系统状态-正常
|
|
|
|
+ String instrumentStatus = instrumentStatusNormal;// 总体 先设置为 仪表状态-正常
|
|
|
|
+ String bypass = bypassYes;// 总体 先设置为 旁路状态-非旁路
|
|
|
|
+ //根据总表id查找联锁详细表信息并进行处理
|
|
|
|
+ List<InterlockDetail> interlockDetailList = interlockAvoidCircularMapper.getInterlockDetailListBySummaryId(interlockSummary.getId());
|
|
|
|
+
|
|
|
|
+ for(InterlockDetail interlockDetail:interlockDetailList){
|
|
|
|
+ //联锁详细表更新点位时间
|
|
|
|
+ interlockDetail.setTagTime(formattedDateTime);
|
|
|
|
+ //旁路状态更新:如果是直接读取位号,则值不变;如果默认正常或者现场旁路,需要改变旁路状态的值
|
|
|
|
+ if(isChangeBypass){
|
|
|
|
+ if(InterlockAllStatus.IF_BY_PASS_NO.equals(interlockDetail.getIfBypass())){
|
|
|
|
+ interlockDetail.setBypass(bypassYes);//如果是默认正常,将旁路状态设为正常状态
|
|
|
|
+ }else if(InterlockAllStatus.IF_BY_PASS_spot.equals(interlockDetail.getIfBypass())){
|
|
|
|
+ //先判断现在旁路状态是正常还是故障
|
|
|
|
+ if(interlockBaseOrg.getBypassYes().equals(interlockDetail.getBypass())){
|
|
|
|
+ interlockDetail.setBypass(bypassYes);//原来是正常状态,现在也设置成正常状态对应的值
|
|
|
|
+ }else {
|
|
|
|
+ interlockDetail.setBypass(bypassNo);//原来是故障状态,现在也设置成故障状态对应的值
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //联锁状态:旁路状态多个的话,任何一个旁路状态是故障状态,则联锁状态是故障状态,如果旁路状态都是正常状态,则联锁状态是正常状态
|
|
|
|
+ if(interlockDetail.getBypass()!=null && bypassNo.equals(interlockDetail.getBypass())) interlockStatus = interlockStatusWty;
|
|
|
|
+
|
|
|
|
+ //仪表状态 有通过原始量判断出来的值,所以不管变不变,都要判断一下当前仪表状态是正常还是故障
|
|
|
|
+ if(interlockDetail.getInstrumentStatusJuge()!=null){
|
|
|
|
+ if(InterlockAllStatus.INSTRUMENT_STATUS_JUDGE0.equals(interlockDetail.getInstrumentStatusJuge())){
|
|
|
|
+ //0直接读取位号
|
|
|
|
+ interlockDetail.setInstrumentStatus(interlockDetail.getInstrumentStatusValue());
|
|
|
|
+ } else if(InterlockAllStatus.INSTRUMENT_STATUS_JUDGE1.equals(interlockDetail.getInstrumentStatusJuge())){
|
|
|
|
+ //1高低限判断
|
|
|
|
+ BigDecimal ysmnlValue = new BigDecimal(interlockDetail.getYsmnlValue());
|
|
|
|
+ BigDecimal lowerLimit = new BigDecimal(interlockDetail.getLowerLimit());
|
|
|
|
+ BigDecimal upperLimit = new BigDecimal(interlockDetail.getUpperLimit());
|
|
|
|
+ if(ysmnlValue.compareTo(lowerLimit) >= 0 && ysmnlValue.compareTo(upperLimit) <= 0) interlockDetail.setInstrumentStatus(instrumentStatusNormal); // 正常
|
|
|
|
+ else interlockDetail.setInstrumentStatus(instrumentStatusAbnormal); // 故障
|
|
|
|
+
|
|
|
|
+ } else if(InterlockAllStatus.INSTRUMENT_STATUS_JUDGE2.equals(interlockDetail.getInstrumentStatusJuge())){ //2突变超限判断
|
|
|
|
+ //通过判断原始模拟量位号突变(与iotedge_collect_data表的数据进行比较)超过某阈值得出值
|
|
|
|
+ // 去采集数据表中根据 设备id+模块名称+点位名称 查询设置的s之前的数据
|
|
|
|
+ String yz = interlockDetail.getThresholdValue(); // 阈值
|
|
|
|
+ String time = interlockDetail.getThresholdTime(); // 规定的时间
|
|
|
|
+ String dw = interlockDetail.getThresholdTimeUnit(); // 时间单位
|
|
|
|
+
|
|
|
|
+ if ("s".equals(dw)){
|
|
|
|
+ // 本次原始模拟量值
|
|
|
|
+ BigDecimal ysmnlValue = new BigDecimal(interlockDetail.getYsmnlValue());
|
|
|
|
+
|
|
|
|
+ // 查询上一次原始模拟量值
|
|
|
|
+ String endDate = DateUtils.getDate("yyyy-MM-dd HH:mm:ss"); // 当前时间 规定时间的结束时间
|
|
|
|
+ LocalDateTime endDateTime = LocalDateTime.parse(endDate, formatter);
|
|
|
|
+ LocalDateTime beginDateTime = endDateTime.minus(Duration.ofSeconds(Long.parseLong(time)));
|
|
|
|
+ String beginDate = beginDateTime.format(formatter); // 开始时间 规定时间的开始时间
|
|
|
|
+
|
|
|
|
+ IotedgeCollectData iotedgeData = iotedgeCollectDataService.getOneInfo(interlockDetail.getYsmnlDeviceId(),interlockDetail.getYsmnlModuleName(),interlockDetail.getYsmnlTag(),beginDate);
|
|
|
|
+ BigDecimal beginValue = new BigDecimal("0");
|
|
|
|
+ if(iotedgeData != null){
|
|
|
|
+ beginValue = new BigDecimal(iotedgeData.getValue());
|
|
|
|
+ }
|
|
|
|
+// BigDecimal beginValue = new BigDecimal(iotedgeData.getValue());
|
|
|
|
+// //如果原来的模拟量是0的话
|
|
|
|
+// if(beginValue.equals(BigDecimal.ZERO)){
|
|
|
|
+// beginValue=BigDecimal.valueOf(0.001);
|
|
|
|
+// if(ysmnlValue.equals(BigDecimal.ZERO)){
|
|
|
|
+// ysmnlValue=BigDecimal.valueOf(0.001);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// System.out.println("beginValue:" + beginValue);
|
|
|
|
+ BigDecimal num = ysmnlValue.subtract(beginValue);
|
|
|
|
+
|
|
|
|
+ // (高限-底限) * 阈值 (数据库中的阈值是去掉百分比的直接乘即可)
|
|
|
|
+ BigDecimal lowerLimit = new BigDecimal(interlockDetail.getLowerLimit());
|
|
|
|
+ BigDecimal upperLimit = new BigDecimal(interlockDetail.getUpperLimit());
|
|
|
|
+
|
|
|
|
+ BigDecimal number = upperLimit.subtract(lowerLimit);
|
|
|
|
+ BigDecimal newYz = number.multiply(new BigDecimal(yz));
|
|
|
|
+// if ((num.divide(beginValue).compareTo(newYz)) > 0){
|
|
|
|
+// dto.setInstrumentStatus(instrumentStatusAbnormal); // 故障
|
|
|
|
+// }else dto.setInstrumentStatus(instrumentStatusNormal); // 正常
|
|
|
|
+ //有可能出现无限循环小数,保留三位小数
|
|
|
|
+ BigDecimal orgYz = new BigDecimal(100);//默认增量百分比为百分百
|
|
|
|
+ if(!beginValue.equals(new BigDecimal("0"))){
|
|
|
|
+ orgYz = num.divide(beginValue,2,RoundingMode.HALF_UP);
|
|
|
|
+ }
|
|
|
|
+ if ((orgYz.compareTo(newYz)) > 0){
|
|
|
|
+ interlockDetail.setInstrumentStatus(instrumentStatusAbnormal); // 故障
|
|
|
|
+ }else interlockDetail.setInstrumentStatus(instrumentStatusNormal); // 正常
|
|
|
|
+
|
|
|
|
+// if ((num.divide(beginValue,2, RoundingMode.HALF_UP).compareTo(newYz)) > 0){
|
|
|
|
+// interlockDetail.setInstrumentStatus(instrumentStatusAbnormal); // 故障
|
|
|
|
+// }else interlockDetail.setInstrumentStatus(instrumentStatusNormal); // 正常
|
|
|
|
+ }
|
|
|
|
+ } else if(InterlockAllStatus.INSTRUMENT_STATUS_JUDGE3.equals(interlockDetail.getInstrumentStatusJuge())){
|
|
|
|
+ //3默认正常
|
|
|
|
+ interlockDetail.setInstrumentStatus(instrumentStatusNormal);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(interlockDetail.getInstrumentStatus()!=null && interlockDetail.getInstrumentStatus().equals(instrumentStatusAbnormal)) instrumentStatus = instrumentStatusAbnormal;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(isChangeControlSystemStatus){
|
|
|
|
+ //MP状态、输入卡件状态、输出卡件状态如果设置的是默认正常,需要更改默认正常的值
|
|
|
|
+ if(interlockDetail.getMpStatusTag() == null){
|
|
|
|
+ interlockDetail.setMpStatus(controlSystemStatusNormal);
|
|
|
|
+ }
|
|
|
|
+ if(interlockDetail.getInputStatusTag() == null){
|
|
|
|
+ interlockDetail.setInputStatus(controlSystemStatusNormal);
|
|
|
|
+ }
|
|
|
|
+ if(interlockDetail.getOutputStatusTag() == null){
|
|
|
|
+ interlockDetail.setOutputStatus(controlSystemStatusNormal);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //控制系统状态 —— MP状态、输入卡件状态、输出卡件状态任何一个非正常则控制系统状态非正常。
|
|
|
|
+ if(controlSystemStatusAbnormal.equals(interlockDetail.getMpStatus()) || controlSystemStatusAbnormal.equals(interlockDetail.getInputStatus()) || controlSystemStatusAbnormal.equals(interlockDetail.getOutputStatus())) {
|
|
|
|
+ interlockDetail.setControlSystemStatus(controlSystemStatusAbnormal); // 非正常
|
|
|
|
+ controlSystemStatus = controlSystemStatusAbnormal;
|
|
|
|
+ } else interlockDetail.setControlSystemStatus(controlSystemStatusNormal); // 正常
|
|
|
|
+ interlockDetailNewList.add(interlockDetail);
|
|
|
|
+ //新增联锁详细信息表临时表数据
|
|
|
|
+ InterlockDetailTemp detailTemp = TempConvert.INSTANCE.toInterlockDetailTemp(interlockDetail);
|
|
|
|
+ interlockDetailTempList.add(detailTemp);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //联锁状态
|
|
|
|
+ interlockSummary.setInterlockStatus(interlockStatus);
|
|
|
|
+ //回路健康等级
|
|
|
|
+ loopHealthLevel = getLHL(instrumentStatus, instrumentStatusAbnormal,interlockStatus, interlockStatusWty, controlSystemStatus, controlSystemStatusAbnormal);
|
|
|
|
+ interlockSummary.setLoopHealthLevel(loopHealthLevel);
|
|
|
|
+ interlockSummaryNewList.add(interlockSummary);
|
|
|
|
+ //修改联锁总表临时表数据
|
|
|
|
+ InterlockSummaryTemp interlockSummaryTemp = TempConvert.INSTANCE.toInterlockSummaryTemp(interlockSummary);
|
|
|
|
+ interlockSummaryTempList.add(interlockSummaryTemp);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //4.将联锁总表和详细表信息更新到数据库
|
|
|
|
+ interlockSummaryService.updateBatchById(interlockSummaryNewList);
|
|
|
|
+ interlockDetailService.updateBatchById(interlockDetailNewList);
|
|
|
|
+ interlockSummaryTempService.updateBatchById(interlockSummaryTempList);
|
|
|
|
+ interlockDetailTempService.updateBatchById(interlockDetailTempList);
|
|
|
|
+
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改系统时,修改联锁总表的联锁状态和回路健康等级 备份之前的,没有修改点位时间
|
|
|
|
+ *
|
|
|
|
+ * @param base
|
|
|
|
+ */
|
|
|
|
+ public void updateInterlockSummaryStatus1(InterlockBase base, InterlockBase interlockBaseOrg){
|
|
|
|
+
|
|
|
|
+ //设置默认值,默认状态未改变,看系统状态是否发生变化
|
|
|
|
+ boolean isChangeControlSystemStatus = false;
|
|
|
|
+ boolean isChangeBypass = false;
|
|
|
|
+ boolean isChangeInstrumentStatus = false;
|
|
|
|
+ boolean isChangeInterlockStatus = false;
|
|
|
|
+
|
|
|
|
+ //1.获取原来的含义表,先查看系统状态含义是否发生了变化
|
|
|
|
+ if(!base.getControlSystemStatusNormal().equals(interlockBaseOrg.getControlSystemStatusNormal())){
|
|
|
|
+ isChangeControlSystemStatus = true;
|
|
|
|
+ }
|
|
|
|
+ if(!base.getBypassYes().equals(interlockBaseOrg.getBypassYes())){
|
|
|
|
+ isChangeBypass = true;
|
|
|
|
+ }
|
|
|
|
+ if(!base.getInstrumentStatusNormal().equals(interlockBaseOrg.getInstrumentStatusNormal())){
|
|
|
|
+ isChangeInstrumentStatus = true;
|
|
|
|
+ }
|
|
|
|
+ if(!base.getInterlockStatusTy().equals(interlockBaseOrg.getInterlockStatusTy())){
|
|
|
|
+ isChangeInterlockStatus = true;
|
|
|
|
+ }
|
|
|
|
+ //如果全部状态都未改变,不需要进行状态变化
|
|
|
|
+ if((!isChangeControlSystemStatus)&&(!isChangeBypass)&&(!isChangeInstrumentStatus)&&(!isChangeInterlockStatus)){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 系统设置的各状态
|
|
|
|
+ // 控制系统状态(输入卡件状态、输出卡件状态、MP状态)
|
|
|
|
+ String controlSystemStatusNormal = base.getControlSystemStatusNormal(); //正常状态: 如正常
|
|
|
|
+ String controlSystemStatusAbnormal = editStatus(base.getControlSystemStatusNormal()); //故障状态:如非正常
|
|
|
|
+ // 旁路状态
|
|
|
|
+ String bypassYes = base.getBypassYes(); //正常状态: 如否、非旁路
|
|
|
|
+ String bypassNo = editStatus(base.getBypassYes()); //故障状态:如是、旁路
|
|
|
|
+ // 仪表状态
|
|
|
|
+ String instrumentStatusNormal = base.getInstrumentStatusNormal(); //正常状态:如正常
|
|
|
|
+ String instrumentStatusAbnormal = editStatus(base.getInstrumentStatusNormal()); //故障状态:如非正常
|
|
|
|
+ // 联锁状态
|
|
|
|
+ String interlockStatusTy = base.getInterlockStatusTy(); //正常状态: 如投用
|
|
|
|
+ String interlockStatusWty = editStatus(base.getInterlockStatusTy()); //故障状态:如未投用
|
|
|
|
+
|
|
|
|
+ // 获取当前日期时间
|
|
|
|
+ LocalDateTime currentDateTime = LocalDateTime.now();
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ String formattedDateTime = currentDateTime.format(formatter);
|
|
|
|
+
|
|
|
|
+ //先查找该系统下的联锁总表信息
|
|
|
|
+ //需要更新的联锁总表信息
|
|
|
|
+ List<InterlockSummary> interlockSummaryNewList = new ArrayList<>();
|
|
|
|
+ //需要更新的联锁详细表信息
|
|
|
|
+ List<InterlockDetail> interlockDetailNewList = new ArrayList<>();
|
|
|
|
+ //需要更新的联锁总表临时表信息
|
|
|
|
+ List<InterlockSummaryTemp> interlockSummaryTempList = new ArrayList<>();
|
|
|
|
+ //需要更新的联锁详细数据临时表信息
|
|
|
|
+ List<InterlockDetailTemp> interlockDetailTempList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ //根据系统id查找所有联锁总表信息
|
|
|
|
+ List<InterlockSummary> interlockSummaryList = interlockAvoidCircularMapper.getInterlockSummaryListBySystemId(base.getId());
|
|
|
|
+
|
|
|
|
+ for(InterlockSummary interlockSummary:interlockSummaryList){
|
|
//设置各状态默认值
|
|
//设置各状态默认值
|
|
String interlockStatus = interlockStatusTy;;// 先设置为 联锁状态-投用
|
|
String interlockStatus = interlockStatusTy;;// 先设置为 联锁状态-投用
|
|
String loopHealthLevel = "A";// 回路健康级别
|
|
String loopHealthLevel = "A";// 回路健康级别
|