|
@@ -0,0 +1,290 @@
|
|
|
+package org.jeecg.modules.interlockAvoidCircular.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
+import org.jeecg.modules.base.convert.InterlockBaseConvert;
|
|
|
+import org.jeecg.modules.base.entity.InterlockBase;
|
|
|
+import org.jeecg.modules.base.mapper.InterlockBaseMapper;
|
|
|
+import org.jeecg.modules.base.service.IInterlockBaseService;
|
|
|
+import org.jeecg.modules.base.vo.InterlockBaseVo;
|
|
|
+import org.jeecg.modules.detail.entity.InterlockDetail;
|
|
|
+import org.jeecg.modules.detail.service.IInterlockDetailService;
|
|
|
+import org.jeecg.modules.interlockAvoidCircular.entity.InterlockSumSystemDetailList;
|
|
|
+import org.jeecg.modules.interlockAvoidCircular.mapper.InterlockAvoidCircularMapper;
|
|
|
+import org.jeecg.modules.interlockAvoidCircular.service.InterlockAvoidCircularService;
|
|
|
+import org.jeecg.modules.iotedgeCollectData.entity.IotedgeCollectData;
|
|
|
+import org.jeecg.modules.iotedgeCollectData.service.IIotedgeCollectDataService;
|
|
|
+import org.jeecg.modules.iotedgeCollectData.service.RestClientService;
|
|
|
+import org.jeecg.modules.summary.constants.InterlockAllStatus;
|
|
|
+import org.jeecg.modules.summary.entity.InterlockSummary;
|
|
|
+import org.jeecg.modules.summary.service.IInterlockSummaryService;
|
|
|
+import org.jeecg.modules.temp.convert.TempConvert;
|
|
|
+import org.jeecg.modules.temp.entity.InterlockDetailTemp;
|
|
|
+import org.jeecg.modules.temp.entity.InterlockSummaryTemp;
|
|
|
+import org.jeecg.modules.temp.service.IInterlockDetailTempService;
|
|
|
+import org.jeecg.modules.temp.service.IInterlockSummaryTempService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.servlet.http.Cookie;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+
|
|
|
+/**
|
|
|
+ * ClassName: InterlockAvoidCircularServiceImpl
|
|
|
+ * Package: org.jeecg.modules.interlockAvoidCircular.service.impl
|
|
|
+ * Description:
|
|
|
+ *
|
|
|
+ * @Author sl
|
|
|
+ * @Create 2024/8/28 10:14
|
|
|
+ * @Version 1.0
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class InterlockAvoidCircularServiceImpl implements InterlockAvoidCircularService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RestClientService restClientService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IInterlockBaseService baseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IInterlockSummaryService interlockSummaryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IInterlockDetailService interlockDetailService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IInterlockSummaryTempService interlockSummaryTempService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IInterlockDetailTempService interlockDetailTempService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InterlockAvoidCircularMapper interlockAvoidCircularMapper;
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IIotedgeCollectDataService iotedgeCollectDataService;
|
|
|
+
|
|
|
+ private static final String SUCCESS_CODE = "200";
|
|
|
+ private static final String ERROR_CODE_ONE = "400";
|
|
|
+ private static final String ERROR_CODE_TWO = "500";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改系统配置
|
|
|
+ **/
|
|
|
+ @Override
|
|
|
+ public String updateGroup(InterlockBaseVo interlockBaseVo, HttpServletRequest request){
|
|
|
+ String resultCode = SUCCESS_CODE;
|
|
|
+
|
|
|
+ String groupName = interlockBaseVo.getGroupName();
|
|
|
+
|
|
|
+ InterlockBase interlockBase = InterlockBaseConvert.INSTANCE.toInterlockBase(interlockBaseVo);
|
|
|
+
|
|
|
+ InterlockBase base = baseService.getById(interlockBase);
|
|
|
+
|
|
|
+ baseService.updateInterlockBase(interlockBase);
|
|
|
+
|
|
|
+ updateInterlockSummaryStatus(interlockBase);//更新该系统下的所有联锁的联锁状态以及回路健康等级
|
|
|
+
|
|
|
+ if ("1".equals(interlockBase.getInterlockType())){
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = restClientService.updateGroup(groupName, base.getIotedgeGroupId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("修改系统名称时,修改IoTEdge中对应组织的名称失败");
|
|
|
+ resultCode = ERROR_CODE_TWO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("0".equals(interlockBase.getInterlockType())){
|
|
|
+ int count = 0;
|
|
|
+ List<InterlockBase> list = baseService.getListByPId(interlockBase.getId());
|
|
|
+ for (InterlockBase item : list) {
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = restClientService.updateGroup(interlockBase.getInterlockName() + "_" + item.getInterlockName(), item.getIotedgeGroupId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("修改装置名称时,遍历修改IoTEdge中相关组织的名称失败");
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (count > 0){
|
|
|
+ resultCode = ERROR_CODE_TWO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改系统时,修改联锁总表的联锁状态和回路健康等级
|
|
|
+ *
|
|
|
+ * @param base
|
|
|
+ */
|
|
|
+ public void updateInterlockSummaryStatus(InterlockBase base){
|
|
|
+ // 获取当前日期时间
|
|
|
+ LocalDateTime currentDateTime = LocalDateTime.now();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String formattedDateTime = currentDateTime.format(formatter);
|
|
|
+
|
|
|
+ // 1.系统设置的各状态
|
|
|
+ // 控制系统状态(输入卡件状态、输出卡件状态、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()); //故障状态:如未投用
|
|
|
+
|
|
|
+
|
|
|
+ //3.先查找该系统下的联锁总表信息
|
|
|
+ //需要更新的联锁总表信息
|
|
|
+ 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){
|
|
|
+ //2.设置各状态默认值
|
|
|
+ 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){
|
|
|
+ //联锁状态:旁路状态多个的话,任何一个旁路状态是故障状态,则联锁状态是故障状态,如果旁路状态都是正常状态,则联锁状态是正常状态
|
|
|
+ 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(iotedgeData.getValue());
|
|
|
+ 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); // 正常
|
|
|
+ //有可能出现无限循环小数,保留三位小数
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ //控制系统状态 —— 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);
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 改状态
|
|
|
+ */
|
|
|
+ private String editStatus(String status){
|
|
|
+ if("0".equals(status)) return "1";
|
|
|
+ else return "0";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断回路健康等级
|
|
|
+ */
|
|
|
+ private String getLHL(String instrumentStatus, String instrumentStatusAbnormal, String interlockStatus, String interlockStatusWty, String controlSystemStatus, String controlSystemStatusAbnormal){
|
|
|
+ int i = 0;
|
|
|
+ if(instrumentStatusAbnormal.equals(instrumentStatus)) i++; // 仪表状态-故障
|
|
|
+ if(interlockStatusWty.equals(interlockStatus)) i++; // TODO 联锁状态 未投用、投用 哪个算不正常状态 先按0未投用不正常算
|
|
|
+ if(controlSystemStatusAbnormal.equals(controlSystemStatus)) i++; // 控制系统状态-非正常
|
|
|
+ if(i==0) return "A";
|
|
|
+ else if(i==1) return "B";
|
|
|
+ else if(i==2) return "C";
|
|
|
+ else return "D";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|