|
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
+import org.jeecg.modules.base.entity.InterlockBase;
|
|
|
+import org.jeecg.modules.base.service.IInterlockBaseService;
|
|
|
import org.jeecg.modules.detail.entity.InterlockDetail;
|
|
|
import org.jeecg.modules.detail.service.IInterlockDetailService;
|
|
|
import org.jeecg.modules.history.convert.InterlockDetailHistoryConvert;
|
|
@@ -36,6 +38,7 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.nio.channels.SelectionKey;
|
|
|
import java.nio.channels.Selector;
|
|
|
import java.sql.*;
|
|
@@ -98,6 +101,10 @@ public class PostgreSQLClient implements ApplicationRunner {
|
|
|
@SuppressWarnings("all")
|
|
|
private IInterlockSummaryTempService summaryTempService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IInterlockBaseService baseService;
|
|
|
+
|
|
|
|
|
|
|
|
|
@Async
|
|
@@ -129,8 +136,9 @@ public class PostgreSQLClient implements ApplicationRunner {
|
|
|
System.out.println("变化的数据:"+name+"---"+parameter);
|
|
|
Map<String, Object> changeDataMap = JSONObject.parseObject(parameter, new TypeReference<Map<String, Object>>() {
|
|
|
});
|
|
|
+ String systemId = (String) changeDataMap.get("interlock_system_id"); // 联锁系统ID
|
|
|
String interlockCondition = (String) changeDataMap.get("interlock_condition"); // 联锁条件值
|
|
|
- String curronValue = (String) changeDataMap.get("current_value"); // 当前
|
|
|
+ String curronValue = (String) changeDataMap.get("interlock_condition"); // 当前值 -- 联锁条件点位对应的
|
|
|
String ybStatusTag = (String) changeDataMap.get("instrument_status_value"); // 仪表状态点位 值
|
|
|
String ybValueTag = (String) changeDataMap.get("ysmnl_value"); // 仪表原始模拟量点位 值
|
|
|
String plTag = (String) changeDataMap.get("bypass"); // 旁路点位 值
|
|
@@ -149,11 +157,25 @@ public class PostgreSQLClient implements ApplicationRunner {
|
|
|
lowerLimit = (String)changeDataMap.get("lower_limit");
|
|
|
}
|
|
|
String ifBypass = (String) changeDataMap.get("if_bypass"); // 是否旁路 (若 "是" 则 bypass 等于 点位值;若 "否" 则 bypass 等于 输入值)
|
|
|
-
|
|
|
String tagTime = (String) changeDataMap.get("tag_time"); // 点位时间
|
|
|
|
|
|
+ // 根据联锁系统ID查询出 每个正常状态 对应的值
|
|
|
+ InterlockBase base = baseService.getById(systemId);
|
|
|
+
|
|
|
+ String baseYbNormalStatus = base.getInstrumentStatusNormal(); // 用户定义的 仪表状态正常 所对应的值
|
|
|
+ String baseYbAbnormalStatus = inversionStatus(base.getInstrumentStatusNormal()); // 获取仪表状态异常所对应的值(取反)
|
|
|
+
|
|
|
+ String baseKzxtNormalStatus = base.getControlSystemStatusNormal(); // 用户定义的 控制系统状态正常 所对应的值
|
|
|
+ String baseKzxtAbnormalStatus = inversionStatus(base.getControlSystemStatusNormal()); // 获取控制系统状态异常所对应的值(取反)
|
|
|
+
|
|
|
+ String basePlNormalStatus = base.getBypassYes(); // 用户定义的 旁路状态是 所对应的值
|
|
|
+ String basePlAbnormalStatus = inversionStatus(base.getBypassYes()); // 获取旁路状态否 所对应的值
|
|
|
+
|
|
|
+ String baseLsNormalStatus = base.getInterlockStatusTy(); // 用户定义的 联锁状态投用 所对应的值
|
|
|
+ String baseLsAbnormalStatus = inversionStatus(base.getInterlockStatusTy()); // 获取联锁状态未投用所对应的值(取反)
|
|
|
+
|
|
|
// 仪表状态 (明细表)
|
|
|
- String ybStatus = "0"; // 0:正常 1:故障
|
|
|
+ String ybStatus = baseYbNormalStatus; // 用户定义仪表状态为正常的值
|
|
|
|
|
|
// 直接读取位号
|
|
|
if ("0".equals(ybIfFs) && ObjectUtil.isNotNull(ybStatusTag)){
|
|
@@ -164,14 +186,11 @@ public class PostgreSQLClient implements ApplicationRunner {
|
|
|
// 高低限判断
|
|
|
if ("1".equals(ybIfFs)){
|
|
|
// 如果 仪表值 大于上限 或者 小于下限 则状态为 异常;两种情况不会同时满足
|
|
|
- //if (Integer.parseInt(ybValueTag) > Integer.parseInt(upperLimit) || Integer.parseInt(ybValueTag) < Integer.parseInt(lowerLimit)){
|
|
|
- // ybStatus = "1";
|
|
|
- //}
|
|
|
BigDecimal ybValueTagDecimal = new BigDecimal(ybValueTag);
|
|
|
BigDecimal upperLimitDecimal = new BigDecimal(upperLimit);
|
|
|
BigDecimal lowerLimitDecimal = new BigDecimal(lowerLimit);
|
|
|
if ((ybValueTagDecimal.compareTo(upperLimitDecimal) > 0) || (ybValueTagDecimal.compareTo(lowerLimitDecimal) < 0)) {
|
|
|
- ybStatus = "1";
|
|
|
+ ybStatus = baseYbAbnormalStatus; // 仪表状态为异常
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -201,8 +220,9 @@ public class PostgreSQLClient implements ApplicationRunner {
|
|
|
BigDecimal lower = BigDecimal.valueOf(Double.parseDouble(lowerLimit));
|
|
|
BigDecimal number = up.subtract(lower);
|
|
|
BigDecimal newYz = number.multiply(BigDecimal.valueOf(Double.parseDouble(yz)));
|
|
|
- if ((num.divide(beginValue).compareTo(newYz)) > 0){
|
|
|
- ybStatus = "1";
|
|
|
+ BigDecimal nowNum = num.divide(beginValue,2, RoundingMode.HALF_UP);
|
|
|
+ if ((nowNum.compareTo(newYz)) > 0){
|
|
|
+ ybStatus = baseYbAbnormalStatus;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -215,9 +235,10 @@ public class PostgreSQLClient implements ApplicationRunner {
|
|
|
}
|
|
|
|
|
|
// 控制系统状态 (明细表)
|
|
|
- String kzxtStatus = "0"; // 0:正常 1:非正常
|
|
|
- if (Integer.parseInt(inputStatusTag) == 1 || Integer.parseInt(outputStatusTag) == 1 || Integer.parseInt(mpStatusTag) == 1){
|
|
|
- kzxtStatus = "1";
|
|
|
+ String kzxtStatus = baseKzxtNormalStatus; // 用户定义控制系统为正常时的值
|
|
|
+ // 由于 输出、输入卡件状态、MP状态 与控制系统状态相同 即 如果控制系统异常为1则三个状态异常也为1
|
|
|
+ if (baseKzxtAbnormalStatus.equals(inputStatusTag) || baseKzxtAbnormalStatus.equals(outputStatusTag) || baseKzxtAbnormalStatus.equals(mpStatusTag)){
|
|
|
+ kzxtStatus = baseKzxtAbnormalStatus; // 控制系统状态为异常
|
|
|
}
|
|
|
|
|
|
// todo 判断 控制系统状态 是否发生了改变;如果发生了变化就将变化之前的数据存入到历史数据表中
|
|
@@ -235,19 +256,19 @@ public class PostgreSQLClient implements ApplicationRunner {
|
|
|
|
|
|
// 根据总表id 查询数所有的联锁条件
|
|
|
String zdybzt = "0"; // 该联锁下 所有联锁条件的 (总)仪表状态
|
|
|
- String zdkzxtzt = "0"; // 该联锁下 所有联塑条件的 (总)控制系统状态
|
|
|
+ String zdkzxtzt = "0"; // 该联锁下 所有联锁条件的 (总)控制系统状态
|
|
|
int ybcount = 0; // 该联锁下 所有联锁条件 仪表状态为 异常(1) 的数量
|
|
|
int kzxtcount = 0; // 该联锁下 所有联锁条件 控制系统状态为 异常(1) 的数量
|
|
|
int plcount = 0; // 该联锁下 所有联锁条件 旁路为 是(1) 的数量
|
|
|
List<InterlockDetail> list = detailService.selectListBySummaryId(summaryId);
|
|
|
for (InterlockDetail detail:list) {
|
|
|
- if ("1".equals(detail.getInstrumentStatus())){
|
|
|
+ if (baseYbAbnormalStatus.equals(detail.getInstrumentStatus())){
|
|
|
ybcount++; // 如果仪表状态有一个是异常 则+1;
|
|
|
}
|
|
|
- if (Integer.parseInt(detail.getInputStatus()) == 1 || Integer.parseInt(detail.getOutputStatus()) == 1 || Integer.parseInt(detail.getMpStatus()) == 1) {
|
|
|
+ if (baseKzxtAbnormalStatus.equals(inputStatusTag) || baseKzxtAbnormalStatus.equals(outputStatusTag) || baseKzxtAbnormalStatus.equals(mpStatusTag)) {
|
|
|
kzxtcount++; // 如果控制系统状态有一个是异常 则+1;
|
|
|
}
|
|
|
- if ("1".equals(detail.getBypass())){
|
|
|
+ if (basePlNormalStatus.equals(detail.getBypass())){
|
|
|
plcount++; // 如果旁路有一个为 是 则+1;
|
|
|
}
|
|
|
}
|
|
@@ -258,9 +279,9 @@ public class PostgreSQLClient implements ApplicationRunner {
|
|
|
InterlockSummary interLock = summaryService.getOne(summaryQuery);
|
|
|
|
|
|
// 联锁状态 (总表)
|
|
|
- String lsStatus = "1"; // 0:未投用 1:投用
|
|
|
+ String lsStatus = baseLsNormalStatus; // 用户定义的联锁状态为投用时的值
|
|
|
if (plcount > 0){
|
|
|
- lsStatus = "0"; // 如果旁路有一个为 是 则联锁状态为 "未投用"
|
|
|
+ lsStatus = baseLsAbnormalStatus ; // 如果旁路有一个为 是 则联锁状态为 "未投用"
|
|
|
}
|
|
|
|
|
|
// todo 判断 联锁状态 是否发生了改变;如果发生了变化就将变化之前的数据存入到历史数据表中
|
|
@@ -279,8 +300,8 @@ public class PostgreSQLClient implements ApplicationRunner {
|
|
|
}
|
|
|
ArrayList<String> sList = new ArrayList<>();
|
|
|
sList.add(zdybzt); // 仪表状态
|
|
|
- if("1".equals(lsStatus)){
|
|
|
- sList.add("0"); // 暂时认为 联锁状态 1投用 为 正常
|
|
|
+ if(baseLsNormalStatus.equals(lsStatus)){
|
|
|
+ sList.add("0"); // 暂时认为 联锁状态 投用 为 正常
|
|
|
}else {
|
|
|
sList.add("1");
|
|
|
}
|
|
@@ -321,21 +342,26 @@ public class PostgreSQLClient implements ApplicationRunner {
|
|
|
|
|
|
// 只要有任意一个状态发生了变化 就将当前联锁、联锁条件记录到历史数据中 (可此时记录的状态确实是未改变之前的,但是点位值却是已经改变之后的)
|
|
|
if ("1".equals(ifYbStatus) || "1".equals(ifLsStatus) || "1".equals(ifKzxtStatus) || "1".equals(ifHljkjbStatus) || "1".equals(ifPlStatus)){
|
|
|
- // 需要判断一下 该时间(点位时间)是否已经有了历史记录了 (有可能 多个联锁条件的相应的状态都发生了变化,只存一次即可)
|
|
|
QueryWrapper<InterlockSummaryTemp> summaryTempQuery = new QueryWrapper<>();
|
|
|
summaryTempQuery.eq("id",summaryId);
|
|
|
InterlockSummaryTemp interlockTemp = summaryTempService.getOne(summaryTempQuery);
|
|
|
- QueryWrapper<InterlockSummaryHistory> summaryHistoryQuery = new QueryWrapper<>();
|
|
|
- summaryHistoryQuery.eq("tag_time",interlockTemp.getTagTime());
|
|
|
- long count1 = summaryHistoryService.count(summaryHistoryQuery);
|
|
|
+ //QueryWrapper<InterlockSummaryHistory> summaryHistoryQuery = new QueryWrapper<>();
|
|
|
+ //summaryHistoryQuery.eq("tag_time",interlockTemp.getTagTime());
|
|
|
+ //long count1 = summaryHistoryService.count(summaryHistoryQuery);
|
|
|
+ long count1 = 0;
|
|
|
if (count1 == 0){
|
|
|
List<InterlockDetailTemp> tempList = detailTempService.selectListBySummaryId(summaryId);
|
|
|
InterlockSummaryHistory interlockSummaryHistory = InterlockSummaryHistoryConvert.INSTANCE.toTempHistory(interlockTemp);
|
|
|
+ interlockSummaryHistory.setSummaryOriginId(interlockTemp.getId());
|
|
|
+ interlockSummaryHistory.setTagTime(tagTime);
|
|
|
summaryHistoryService.save(interlockSummaryHistory);
|
|
|
ArrayList<InterlockDetailHistory> historyList = new ArrayList<>();
|
|
|
for (InterlockDetailTemp item:tempList) {
|
|
|
item.setSummaryid(interlockSummaryHistory.getId());
|
|
|
- historyList.add(InterlockDetailHistoryConvert.INSTANCE.toTempHistory(item));
|
|
|
+ InterlockDetailHistory interlockDetailHistory = InterlockDetailHistoryConvert.INSTANCE.toTempHistory(item);
|
|
|
+ interlockDetailHistory.setSummaryOriginId(interlockTemp.getId());
|
|
|
+ interlockDetailHistory.setTagTime(tagTime);
|
|
|
+ historyList.add(interlockDetailHistory);
|
|
|
}
|
|
|
detailHistoryService.saveBatch(historyList);
|
|
|
}
|
|
@@ -348,7 +374,6 @@ public class PostgreSQLClient implements ApplicationRunner {
|
|
|
.set("interlock_condition",interlockCondition)
|
|
|
.set("instrument_status_value",ybStatusTag)
|
|
|
.set("ysmnl_value",ybValueTag)
|
|
|
- .set("current_value",curronValue)
|
|
|
.set("bypass",plTag)
|
|
|
.set("input_status",inputStatusTag)
|
|
|
.set("output_status",outputStatusTag)
|
|
@@ -370,7 +395,7 @@ public class PostgreSQLClient implements ApplicationRunner {
|
|
|
|
|
|
// TODO 不采用轮询的方式查询是否有新的通知产生
|
|
|
// 为了避免轮询的过于频繁 调用sleep方法 但是如果采集频率1s的话,调用sleep方法会对数据产生影响
|
|
|
- Thread.sleep(1000);
|
|
|
+ //Thread.sleep(1000);
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
@@ -380,5 +405,16 @@ public class PostgreSQLClient implements ApplicationRunner {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * author: dzc
|
|
|
+ * version: 1.0
|
|
|
+ * des: 取反
|
|
|
+ * date: 2024/6/25
|
|
|
+ */
|
|
|
+ private String inversionStatus(String str) {
|
|
|
+ if("0".equals(str)) return "1";
|
|
|
+ else return "0";
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|