|
|
|
|
@ -2,16 +2,16 @@ package com.mh.user.strategy;
|
|
|
|
|
|
|
|
|
|
import com.mh.common.utils.StringUtils; |
|
|
|
|
import com.mh.user.constants.Constant; |
|
|
|
|
import com.mh.user.entity.DeviceCodeParamEntity; |
|
|
|
|
import com.mh.user.entity.DeviceInstallEntity; |
|
|
|
|
import com.mh.user.entity.NowPublicDataEntity; |
|
|
|
|
import com.mh.user.entity.SysParamEntity; |
|
|
|
|
import com.mh.user.entity.*; |
|
|
|
|
import com.mh.user.service.*; |
|
|
|
|
import com.mh.user.utils.ExchangeStringUtil; |
|
|
|
|
import com.mh.user.utils.SpringBeanUtil; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -59,6 +59,14 @@ public class MultiControlStrategy implements DeviceStrategy {
|
|
|
|
|
// 设备参数
|
|
|
|
|
String param = deviceCodeParamEntity.getParam(); |
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(param)) { |
|
|
|
|
if ("0010".equals(registerAddr)) { |
|
|
|
|
param = "DO_ALL"; |
|
|
|
|
} else if ("0018".equals(registerAddr)) { |
|
|
|
|
param = "DI_ALL"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 设备值
|
|
|
|
|
String dataValue = deviceCodeParamEntity.getDataValue(); |
|
|
|
|
|
|
|
|
|
@ -73,6 +81,7 @@ public class MultiControlStrategy implements DeviceStrategy {
|
|
|
|
|
if (!StringUtils.isBlank(param)) { |
|
|
|
|
switch (param) { |
|
|
|
|
case "DO_ALL": |
|
|
|
|
deviceCodeParamEntity.setRegisterAddr("0018"); |
|
|
|
|
registerAddr = "00180008"; |
|
|
|
|
break; |
|
|
|
|
case "DO1": |
|
|
|
|
@ -100,6 +109,7 @@ public class MultiControlStrategy implements DeviceStrategy {
|
|
|
|
|
registerAddr = "001F0001"; |
|
|
|
|
break; |
|
|
|
|
case "DI_ALL": |
|
|
|
|
deviceCodeParamEntity.setRegisterAddr("0010"); |
|
|
|
|
registerAddr = "00100008"; |
|
|
|
|
break; |
|
|
|
|
case "DI1": |
|
|
|
|
@ -213,7 +223,7 @@ public class MultiControlStrategy implements DeviceStrategy {
|
|
|
|
|
|
|
|
|
|
// 多路控制,长度42,128
|
|
|
|
|
public String analysisRelayOrder485(final String dateStr, |
|
|
|
|
final String receiveData, |
|
|
|
|
final String receiveData1, |
|
|
|
|
final String registerAddr, |
|
|
|
|
final String brand, |
|
|
|
|
String buildingId, |
|
|
|
|
@ -231,12 +241,27 @@ public class MultiControlStrategy implements DeviceStrategy {
|
|
|
|
|
String waterLevelSet = ""; |
|
|
|
|
String addr = ""; |
|
|
|
|
String param = deviceCodeParamEntity.getParam(); |
|
|
|
|
String receiveData = receiveData1; |
|
|
|
|
if (receiveData1.length() > 42) { |
|
|
|
|
receiveData = receiveData1.substring(0, 42); |
|
|
|
|
} |
|
|
|
|
if (Constant.BRAND_YUAN_XIANG.equals(brand)) { |
|
|
|
|
String checkStr = receiveData.substring(0, receiveData.length() - 4);// 检验报文
|
|
|
|
|
String checkWord = ExchangeStringUtil.getStrCRC16(checkStr); |
|
|
|
|
if (checkWord.equalsIgnoreCase(receiveData.substring(receiveData.length() - 4))) { |
|
|
|
|
addr = ExchangeStringUtil.hexToDec(checkStr.substring(0, 2));//地址
|
|
|
|
|
if (checkStr.startsWith("03", 2)) { |
|
|
|
|
// 判断响应的长度有多长
|
|
|
|
|
int length = receiveData.length(); |
|
|
|
|
if (length == 42) { |
|
|
|
|
if (deviceCodeParamEntity.getRegisterAddr().equals("0010")) { |
|
|
|
|
param = "DI_ALL"; |
|
|
|
|
} else if (deviceCodeParamEntity.getRegisterAddr().equals("0018")) { |
|
|
|
|
param = "DO_ALL"; |
|
|
|
|
} else { |
|
|
|
|
param = "DI_ALL"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 根据请求的param参数进行数据截取
|
|
|
|
|
switch (param) { |
|
|
|
|
case "DI_ALL": |
|
|
|
|
@ -269,11 +294,6 @@ public class MultiControlStrategy implements DeviceStrategy {
|
|
|
|
|
l1 = checkStr.substring(6, 10); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if (!param.contains("ALL")) { |
|
|
|
|
return l1; |
|
|
|
|
} else { |
|
|
|
|
return l1 + l2 + l3 + l4 + l5 + l6 + l7 + l8; |
|
|
|
|
} |
|
|
|
|
} else if (checkStr.startsWith("06", 2) || checkStr.startsWith("04", 2) || checkStr.startsWith("10", 2)) { |
|
|
|
|
log.info("时间:{},多路控制地址:{},DO操作成功! ", dateStr, addr); |
|
|
|
|
return Constant.SUCCESS; |
|
|
|
|
@ -303,9 +323,10 @@ public class MultiControlStrategy implements DeviceStrategy {
|
|
|
|
|
nowPublicDataService.saveNowHistoryPublicData(publicData); |
|
|
|
|
log.info("地址:{},供回补水状态保存数据库成功!楼栋ID:{},名称:{}", addr, buildingId, buildingName); |
|
|
|
|
// 更新now_data表中对应的供水、回水、补水状态
|
|
|
|
|
DeviceInstallEntity deviceInstallEntity = deviceInstallService.selectDevice(addr, "多路控制", buildingId); |
|
|
|
|
DeviceInstallEntity deviceInstallEntity = deviceInstallService.selectDevice(addr, "水位开关", buildingId); |
|
|
|
|
if (deviceInstallEntity != null |
|
|
|
|
&& !StringUtils.isBlank(deviceInstallEntity.getDeviceName())) { |
|
|
|
|
// 判断设备类型是什么类型数据
|
|
|
|
|
if (deviceInstallEntity.getDeviceName().contains("低")) { |
|
|
|
|
log.info("更新now_data表中低区对应的供水、回水、补水状态,楼栋ID:{},供水状态:{},回水状态:{},补水状态:{}", buildingId, publicData.getUseWater(), publicData.getBackWater(), publicData.getUpWater()); |
|
|
|
|
nowDataService.updateNowDataByPumpName("低", buildingId, publicData.getUseWater(), publicData.getBackWater(), publicData.getUpWater()); |
|
|
|
|
@ -324,9 +345,48 @@ public class MultiControlStrategy implements DeviceStrategy {
|
|
|
|
|
} |
|
|
|
|
nowDataService.updateNowPublicData(publicData); |
|
|
|
|
} |
|
|
|
|
deviceInstallEntity = deviceInstallService.selectDevice(addr, "多路控制", buildingId); |
|
|
|
|
if (deviceInstallEntity != null |
|
|
|
|
&& !StringUtils.isBlank(deviceInstallEntity.getDeviceName())) { |
|
|
|
|
// 查看是否存在1号供水泵、2号供水泵、1号抽水泵、2号抽水泵、补水电磁阀
|
|
|
|
|
NowDataEntity nowDataEntity = nowDataService.queryNowDataByPumpName(buildingId, buildingName, deviceInstallEntity.getDeviceAddr(), "1号供水泵"); |
|
|
|
|
// 多路控制,分别插入或者更新DI点和DO点值
|
|
|
|
|
if (receiveData.length() == 42) { |
|
|
|
|
// l1 l2 l3 l4 l5 l6 l7 l8形成一个key,value
|
|
|
|
|
if (param.equals("DI_ALL")) { |
|
|
|
|
nowDataEntity.setRunState(l1); |
|
|
|
|
nowDataEntity.setIsFault(l3); |
|
|
|
|
nowDataService.updateMultiNowData(nowDataEntity); |
|
|
|
|
nowDataEntity = nowDataService.queryNowDataByPumpName(buildingId, buildingName, deviceInstallEntity.getDeviceAddr(), "2号供水泵"); |
|
|
|
|
nowDataEntity.setRunState(l2); |
|
|
|
|
nowDataEntity.setIsFault(l4); |
|
|
|
|
nowDataService.updateMultiNowData(nowDataEntity); |
|
|
|
|
nowDataEntity = nowDataService.queryNowDataByPumpName(buildingId, buildingName, deviceInstallEntity.getDeviceAddr(), "1号抽水泵"); |
|
|
|
|
nowDataEntity.setRunState(l5); |
|
|
|
|
nowDataService.updateMultiNowData(nowDataEntity); |
|
|
|
|
nowDataEntity = nowDataService.queryNowDataByPumpName(buildingId, buildingName, deviceInstallEntity.getDeviceAddr(), "2号抽水泵"); |
|
|
|
|
nowDataEntity.setRunState(l6); |
|
|
|
|
nowDataEntity.setIsFault(l8); |
|
|
|
|
nowDataService.updateMultiNowData(nowDataEntity); |
|
|
|
|
nowDataEntity = nowDataService.queryNowDataByPumpName(buildingId, buildingName, deviceInstallEntity.getDeviceAddr(), "补水电磁阀"); |
|
|
|
|
nowDataEntity.setRunState(l7); |
|
|
|
|
nowDataService.updateMultiNowData(nowDataEntity); |
|
|
|
|
} |
|
|
|
|
// if (param.equals("DO_ALL")) {
|
|
|
|
|
// nowDataEntity = nowDataService.queryNowDataByPumpName(buildingId, buildingName, deviceInstallEntity.getDeviceAddr(), "补水电磁阀");
|
|
|
|
|
// nowDataEntity.setRunState(l5);
|
|
|
|
|
// nowDataService.updateMultiNowData(nowDataEntity);
|
|
|
|
|
// }
|
|
|
|
|
} |
|
|
|
|
nowDataService.updateNowPublicData(publicData); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return Constant.FAIL; |
|
|
|
|
if (!param.contains("ALL")) { |
|
|
|
|
return l1; |
|
|
|
|
} else { |
|
|
|
|
return l1 + l2 + l3 + l4 + l5 + l6 + l7 + l8; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return l1; |
|
|
|
|
} |
|
|
|
|
|