Browse Source

1、对接海尔热泵

dev
mh 1 week ago
parent
commit
f5a1d1b698
  1. 2
      user-service/src/main/java/com/mh/user/constants/Constant.java
  2. 26
      user-service/src/main/java/com/mh/user/job/DealDataJob.java
  3. 13
      user-service/src/main/java/com/mh/user/service/impl/DeviceControlServiceImpl.java
  4. 21
      user-service/src/main/java/com/mh/user/service/impl/DeviceInstallServiceImpl.java
  5. 544
      user-service/src/main/java/com/mh/user/strategy/HeatPumpStrategy.java
  6. 60
      user-service/src/main/java/com/mh/user/utils/GetReadOrder485.java

2
user-service/src/main/java/com/mh/user/constants/Constant.java

@ -43,6 +43,8 @@ public class Constant {
public static final String BRAND_RUI_XING = "瑞星";
public static final String BRAND_HAI_ER = "海尔";
public static final String BRAND_YUAN_XIANG = "远向";
public static final String BRAND_DING_WEI = "顶威";

26
user-service/src/main/java/com/mh/user/job/DealDataJob.java

@ -173,19 +173,19 @@ public class DealDataJob {
dealDataService.proTotalPumpMinutes(curDate); //统计周\月热泵运行时长
log.info("进入定时调试数据库过程汇总数据!yyyy-MM-dd");
// 开始预测数据
List<BuildingModel> buildingModels = buildingService.selectBuildingName();
for (BuildingModel buildingModel : buildingModels) {
String buildingId = String.valueOf(buildingModel.getBuildingId());
try {
// 训练数据
historyDataPreService.startTrainData(buildingId);
// 预测数据
historyDataPreService.startPredictData(buildingId, curDate);
} catch (Exception e) {
log.error("定时处理数据以及预测数据异常==>", e);
}
}
// // 开始预测数据
// List<BuildingModel> buildingModels = buildingService.selectBuildingName();
// for (BuildingModel buildingModel : buildingModels) {
// String buildingId = String.valueOf(buildingModel.getBuildingId());
// try {
// // 训练数据
// historyDataPreService.startTrainData(buildingId);
// // 预测数据
// historyDataPreService.startPredictData(buildingId, curDate);
// } catch (Exception e) {
// log.error("定时处理数据以及预测数据异常==>", e);
// }
// }
stopWatch.stop();
log.info("定时处理数据以及预测数据结束!耗时:" + stopWatch.getTotalTimeSeconds() + "秒");
} catch (Exception e) {

13
user-service/src/main/java/com/mh/user/service/impl/DeviceControlServiceImpl.java

@ -287,7 +287,9 @@ public class DeviceControlServiceImpl implements DeviceControlService {
deviceCodeParam.setRegisterAddr("0642"); //寄存器地址
} else if ("瑞星".equals(deviceCodeParam.getBrand())) {
deviceCodeParam.setRegisterAddr("000A"); //寄存器地址
} else {
} else if ("海尔".equals(deviceCodeParam.getBrand())) {
deviceCodeParam.setRegisterAddr(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20003"), 4));
} else {
deviceCodeParam.setRegisterAddr("0003"); //寄存器地址
}
rtData = serialPortSingle.serialPortSend(deviceCodeParam);//生成并发送指令
@ -304,6 +306,9 @@ public class DeviceControlServiceImpl implements DeviceControlService {
} else if (deviceCodeParam.getBrand().equals("瑞星")) {
deviceCodeParam.setRegisterAddr("000A"); //寄存器地址
deviceCodeParam.setFunCode("10"); //功能码写数据
} else if ("海尔".equals(deviceCodeParam.getBrand())) {
deviceCodeParam.setRegisterAddr(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20003"), 4)); //寄存器地址
deviceCodeParam.setFunCode("06"); //功能码写数据
} else {
deviceCodeParam.setRegisterAddr("0003"); //寄存器地址
deviceCodeParam.setFunCode("06"); //功能码写数据
@ -358,6 +363,8 @@ public class DeviceControlServiceImpl implements DeviceControlService {
deviceCodeParam.setRegisterAddr("0007"); //寄存器地址
} else if ("瑞星".equals(deviceCodeParam.getBrand())) {
deviceCodeParam.setRegisterAddr("0046"); //寄存器地址
} else if ("海尔".equals(deviceCodeParam.getBrand())) {
deviceCodeParam.setRegisterAddr(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20026"), 4));
} else {
deviceCodeParam.setRegisterAddr("0064"); //寄存器地址
}
@ -373,6 +380,8 @@ public class DeviceControlServiceImpl implements DeviceControlService {
deviceCodeParam.setRegisterAddr("0641"); //寄存器地址
} else if ("瑞星".equals(deviceCodeParam.getBrand())) {
deviceCodeParam.setRegisterAddr("0001");
} else if ("海尔".equals(deviceCodeParam.getBrand())) {
deviceCodeParam.setRegisterAddr(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20001"), 4));
} else {
deviceCodeParam.setRegisterAddr("0BBD"); //寄存器地址
}
@ -390,6 +399,8 @@ public class DeviceControlServiceImpl implements DeviceControlService {
deviceCodeParam.setFunCode("06"); //功能码读数据
if ("瑞星".equals(deviceCodeParam.getBrand())) {
deviceCodeParam.setRegisterAddr("0001"+ ExchangeStringUtil.addZeroForNum(deviceCodeParam.getDataValue(), 4));
} else if ("海尔".equals(deviceCodeParam.getBrand())) {
deviceCodeParam.setRegisterAddr(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20001"), 4)+ ExchangeStringUtil.addZeroForNum(deviceCodeParam.getDataValue(), 4));
}
}
return rtData;

21
user-service/src/main/java/com/mh/user/service/impl/DeviceInstallServiceImpl.java

@ -161,6 +161,27 @@ public class DeviceInstallServiceImpl implements DeviceInstallService {
deviceCodeParamEntity.setFunCode("03");
deviceCodeParamMapper.insertDeviceCodeParamList(Collections.singletonList(deviceCodeParamEntity));
break;
case "海尔":
// 插入device_code_param表
deviceCodeParamEntity.setRegisterAddr(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.IntToHex(20026), 4)); //实际水温
deviceCodeParamEntity.setFunCode("03");
deviceCodeParamMapper.insertDeviceCodeParamList(Collections.singletonList(deviceCodeParamEntity));
// 插入device_code_param1表
deviceCodeParamEntity.setRegisterAddr(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.IntToHex(20001), 4)); //运行状态
deviceCodeParamEntity.setFunCode("03");
deviceCodeParamMapper.insertDeviceCodeParamList2(Collections.singletonList(deviceCodeParamEntity));
// 插入device_code_param2表
deviceCodeParamEntity.setRegisterAddr(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.IntToHex(20003), 4)); //设定温度
deviceCodeParamEntity.setFunCode("03");
deviceCodeParamMapper.insertDeviceCodeParamList(Collections.singletonList(deviceCodeParamEntity));
// 插入device_code_param2表
deviceCodeParamEntity.setRegisterAddr(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.IntToHex(20041), 4)); //故障状态
deviceCodeParamEntity.setFunCode("03");
deviceCodeParamMapper.insertDeviceCodeParamList(Collections.singletonList(deviceCodeParamEntity));
break;
default:
break;
}

544
user-service/src/main/java/com/mh/user/strategy/HeatPumpStrategy.java

@ -10,6 +10,8 @@ import com.mh.user.utils.SpringBeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import java.math.BigDecimal;
/**
* @author LJF
* @version 1.0
@ -156,6 +158,29 @@ public class HeatPumpStrategy implements DeviceStrategy {
}
}
}
} else if (Constant.BRAND_HAI_ER.equals(brand)) {
if (StringUtils.isBlank(funCode) || funCode.equals("03")) {
if (StringUtils.isBlank(registerAddr)
|| registerAddr.equalsIgnoreCase(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20001"),4))) { // 运行状态
str = str + "03"+registerAddr+"0001";
param = "运行状态";
} else if (registerAddr.equalsIgnoreCase(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20026"),4))) { // 水温
str = str + "03"+registerAddr+"0001";
param = "实际温度";
} else if (registerAddr.equalsIgnoreCase(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20041"),4))) { // 故障状态,100*N+11
str = str + "03"+registerAddr+"0001";
param = "故障状态";
} else if (registerAddr.equalsIgnoreCase(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20003"),4))) { // 读温度设定
str = str + "03"+registerAddr+"0001";
param = "设定温度";
}
} else if ("06".equals(funCode)) {
if (registerAddr.equalsIgnoreCase(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20003"), 4))) {
dataValue = (new BigDecimal(dataValue)).multiply(new BigDecimal("10")).toString();
}
String dataStr = ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex(String.valueOf(dataValue)), 4);
str = str + funCode + registerAddr + dataStr;
}
}
String checkWord = ExchangeStringUtil.getStrCRC16(str); //CRC16校验
str = str + checkWord;
@ -172,7 +197,7 @@ public class HeatPumpStrategy implements DeviceStrategy {
String checkStr = dataStr.substring(0, dataStr.length() - 4);//检验报文
String checkWord = ExchangeStringUtil.getStrCRC16(checkStr);//生成校验码
String sValue = null;
String dataType = null;
StringBuffer dataType = new StringBuffer();
String rtData = Constant.FAIL;
if (!checkWord.equalsIgnoreCase(dataStr.substring(dataStr.length() - 4))) {
log.info("热泵报文检验失败: " + dataStr);
@ -182,231 +207,334 @@ public class HeatPumpStrategy implements DeviceStrategy {
String data = "";
if (StringUtils.isBlank(brand) || Constant.BRAND_MEI_DI.equals(brand)) {
if (checkStr.substring(2, 4).equalsIgnoreCase("03")) {//读
if (registerAddr.equalsIgnoreCase("0641")) { //运行状态
dataType = "runState";
data = checkStr.substring(8, 10);
log.info("------------美的热泵状态值-----------" + data);
if (data.equalsIgnoreCase("08")) {
sValue = "不运行"; //关机模式
} else if (data.equalsIgnoreCase("01")) {
sValue = "运行"; //制冷模式
} else if (data.equalsIgnoreCase("02")) {
sValue = "运行"; //制热模式
} else if (data.equalsIgnoreCase("04")) {
sValue = "运行"; //水泵模式
} else if (data.equalsIgnoreCase("10")) {
sValue = "运行"; //制热水模式
}
//计算热泵运行时间,按分钟
nowDataService.proPumpMinutes(buildingId, addr, sValue);
log.info("计算热泵运行时长,楼栋名称:" + buildingName + ",热泵编号:" + addr + ",状态:" + sValue);
} else if (registerAddr.equalsIgnoreCase("0642") || registerAddr.equalsIgnoreCase("0007")) {
//0642设定温度,0007水箱水温
if (registerAddr.equalsIgnoreCase("0642")) {
dataType = "tempSet";
} else {
dataType = "waterTemp";
}
//读数
sValue = ExchangeStringUtil.hexToDec(checkStr.substring(6, 10));
if (dataType.equals("waterTemp")) {
String avgTemp = nowDataService.selectAve(buildingId);
NowPublicDataEntity publicData = new NowPublicDataEntity();
publicData.setBuildingId(buildingId);
publicData.setUseWaterTemp(avgTemp);
publicData.setBackWaterTemp(avgTemp);
String pumpId = nowDataService.selectMinPumpId(buildingId);
if (addr.equals(pumpId)) { //取ID最小的热泵为单箱温度
publicData.setSingleTemp(sValue);
log.info("---------------单箱温度:" + sValue + "---------------");
}
nowPublicDataService.saveNowHistoryPublicData(publicData);
log.info("楼栋名称:" + buildingName + ",热泵编号:" + addr);
} else if (dataType.equals("tempSet")) {
pumpSetService.updatePumpSetTemp(sValue, buildingId, addr); //更新设定温度
}
} else if (registerAddr.equalsIgnoreCase("000B")) { //故障状态
dataType = "isFault";
String sData = ExchangeStringUtil.hexString2binaryString(checkStr.substring(8, 10));
sData = ExchangeStringUtil.addZeroForNum(sData, 8);
if (sData.substring(7, 8).equalsIgnoreCase("0")) {
sValue = "无故障";
deviceInstallService.updateDeviceFault("0", addr, "热泵");
} else if (sData.substring(7, 8).equalsIgnoreCase("1")) {
sValue = "有故障";
deviceInstallService.updateDeviceFault("1", addr, "热泵");
}
} else if (registerAddr.equalsIgnoreCase("0656")
|| registerAddr.equalsIgnoreCase("065A")
|| registerAddr.equalsIgnoreCase("065E")) { //读定时设置值
String startTime = checkStr.substring(8, 10) + checkStr.substring(12, 14);
String closetTime = checkStr.substring(16, 18) + checkStr.substring(20, 22);
sValue = startTime + closetTime;
}
rtData = sValue;
rtData = getMeiDi(registerAddr, buildingId, buildingName, checkStr, sValue, addr, dataType);
} else if (checkStr.substring(2, 4).equalsIgnoreCase("10")) {
log.info("时间: " + dateStr + ",热泵ID: " + addr + ",操作成功! ");
return Constant.SUCCESS;
}
} else if (Constant.BRAND_MEI_DI_TWO.equals(brand)) {
if (checkStr.substring(2, 4).equalsIgnoreCase("03")) {// 读
if (registerAddr.equalsIgnoreCase("0BBD")) { //运行状态
dataType = "runState";
data = ExchangeStringUtil.hexString2binaryString(checkStr.substring(8, 10));
data = ExchangeStringUtil.addZeroForNum(data, 8);//二进制数,补够8位
data = data.substring(4, 8); //截取后四位
log.info("------------美的2热泵状态值-----------" + data);
if (data.equalsIgnoreCase("0000")) { //0
sValue = "不运行"; //关机
} else if (data.equalsIgnoreCase("0001")) {//1
sValue = "运行"; //水泵
} else if (data.equalsIgnoreCase("0010")) {//2
sValue = "运行"; //制冷
} else if (data.equalsIgnoreCase("0011")) {//3
sValue = "运行"; //制热
} else if (data.equalsIgnoreCase("0100")) {//4
sValue = "运行"; //热水
} else if (data.equalsIgnoreCase("0101")) {//5
sValue = "运行"; //采暖
} else if (data.equalsIgnoreCase("0110")) {//6
sValue = "运行"; //电热模式
}
//计算热泵运行时间,按分钟
nowDataService.proPumpMinutes(buildingId, addr, sValue);
log.info("计算热泵运行时长,楼栋名称:" + buildingName + ",热泵编号:" + addr + ",状态:" + sValue);
} else if (registerAddr.equalsIgnoreCase("0003") || registerAddr.equalsIgnoreCase("0064")) {
//0003设定温度,0064水箱水温
if (registerAddr.equalsIgnoreCase("0003")) {
dataType = "tempSet";
} else {
dataType = "waterTemp";
}
//读数
sValue = ExchangeStringUtil.hexToDec(checkStr.substring(6, 10));
if (dataType.equals("waterTemp")) {
String avgTemp = nowDataService.selectAve(buildingId);
NowPublicDataEntity publicData = new NowPublicDataEntity();
publicData.setBuildingId(buildingId);
publicData.setUseWaterTemp(avgTemp);
publicData.setBackWaterTemp(avgTemp);
String pumpId = nowDataService.selectMinPumpId(buildingId);
log.info("---------------addr:" + addr + ",pumpId:" + pumpId + " ---------------");
if (addr.equals(pumpId)) { //取ID最小的热泵为单箱温度
publicData.setSingleTemp(sValue);
log.info("---------------单箱温度:" + sValue + "---------------");
}
nowPublicDataService.saveNowHistoryPublicData(publicData);
log.info("楼栋名称:" + buildingName + ",热泵编号:" + addr);
} else if (dataType.equals("tempSet")) {
pumpSetService.updatePumpSetTemp(sValue, buildingId, addr); //更新设定温度
}
} else if (registerAddr.equalsIgnoreCase("0BBB")) { //故障状态
dataType = "isFault";
String sData = ExchangeStringUtil.hexString2binaryString(checkStr.substring(8, 10));
sData = ExchangeStringUtil.addZeroForNum(sData, 8);
if (sData.substring(7, 8).equalsIgnoreCase("0")) {
sValue = "无故障";
} else if (sData.substring(7, 8).equalsIgnoreCase("1")) {
sValue = "有故障";
}
} else if (registerAddr.equalsIgnoreCase("0656")
|| registerAddr.equalsIgnoreCase("065A")
|| registerAddr.equalsIgnoreCase("065E")) { //定时设置值
String startTime = ExchangeStringUtil.hexToDec(checkStr.substring(8, 10)) + ExchangeStringUtil.hexToDec(checkStr.substring(12, 14));
String closetTime = ExchangeStringUtil.hexToDec(checkStr.substring(16, 18)) + ExchangeStringUtil.hexToDec(checkStr.substring(20, 22));
sValue = startTime + closetTime;
}
rtData = sValue;
rtData = getMeiDiTwo(registerAddr, buildingId, buildingName, checkStr, sValue, addr, dataType);
} else if (checkStr.substring(2, 4).equalsIgnoreCase("06")) {
log.info("时间: " + dateStr + ",热泵ID: " + addr + ",操作成功! ");
return Constant.SUCCESS;
}
} else if (Constant.BRAND_RUI_XING.equals(brand)) {
if (checkStr.substring(2, 4).equalsIgnoreCase("03")) {//读
if (registerAddr.equalsIgnoreCase("0001")) { //运行状态
dataType = "runState";
data = checkStr.substring(8, 10);
if (data.equalsIgnoreCase("00")) {
sValue = "不运行"; //关机模式
} else if (data.equalsIgnoreCase("01")) {
sValue = "运行"; //制热模式
}
//计算热泵运行时间,按分钟
nowDataService.proPumpMinutes(buildingId, addr, sValue);
log.info("计算热泵运行时长,楼栋名称:" + buildingName + ",热泵编号:" + addr + ",状态:" + sValue);
} else if (registerAddr.equalsIgnoreCase("000A") || registerAddr.equalsIgnoreCase("0046")) {
//000A设定温度,0046水箱水温
if (registerAddr.equalsIgnoreCase("000A")) {
dataType = "tempSet";
} else {
dataType = "waterTemp";
}
//读数
sValue = ExchangeStringUtil.hexToDec(checkStr.substring(6, 10));
if (dataType.equals("waterTemp")) {
sValue = String.valueOf(Double.parseDouble(sValue)/10);
String avgTemp = nowDataService.selectAve(buildingId);
NowPublicDataEntity publicData = new NowPublicDataEntity();
publicData.setBuildingId(buildingId);
publicData.setUseWaterTemp(avgTemp);
publicData.setBackWaterTemp(avgTemp);
String pumpId = nowDataService.selectMinPumpId(buildingId);
log.info("---------------addr:" + addr + ",pumpId:" + pumpId + " ---------------");
if (addr.equals(pumpId)) { //取ID最小的热泵为单箱温度
publicData.setSingleTemp(sValue);
log.info("---------------单箱温度:" + sValue + "---------------");
}
nowPublicDataService.saveNowHistoryPublicData(publicData);
log.info("楼栋名称:" + buildingName + ",热泵编号:" + addr);
} else if (dataType.equals("tempSet")) {
pumpSetService.updatePumpSetTemp(sValue, buildingId, addr); //更新设定温度
}
} else if (registerAddr.equalsIgnoreCase("0050")) { //故障状态
dataType = "isFault";
String sData = ExchangeStringUtil.hexString2binaryString(checkStr.substring(8, 10));
sData = ExchangeStringUtil.addZeroForNum(sData, 8);
if (sData.substring(7, 8).equalsIgnoreCase("0")) {
sValue = "无故障";
deviceInstallService.updateDeviceFault("0", addr, "热泵");
} else if (sData.substring(7, 8).equalsIgnoreCase("1")) {
sValue = "有故障";
deviceInstallService.updateDeviceFault("1", addr, "热泵");
rtData = getRuiXing(dateStr, registerAddr, buildingId, buildingName, checkStr, sValue, addr, dataType);
} else if (Constant.BRAND_HAI_ER.equals(brand)) {
rtData = getHaiEr(dateStr, registerAddr, buildingId, buildingName, checkStr, sValue, addr, dataType);
}
if (!StringUtils.isBlank(rtData)) {
nowDataService.saveNowHistoryData(addr, "热泵", rtData, dataType.toString(), buildingId);
log.info("时间: " + dateStr + "热泵ID:" + addr + ",数据: " + rtData + ",保存数据库成功!楼栋名称:" + buildingName);
}
nowDataService.proWaterTemp(dateStr, buildingId, addr); //保存楼栋时间点温度变化
log.info("----------------保存楼栋时间点温度变化值!----------------");
return rtData;
}
private String getHaiEr(String dateStr, String registerAddr, String buildingId, String buildingName, String checkStr, String sValue, String addr, StringBuffer stringBuffer) {
String data;
stringBuffer.setLength(0);
String dataType = "";
if (checkStr.substring(2, 4).equalsIgnoreCase("03")) {//读
if (registerAddr.equalsIgnoreCase(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20001"), 4))) { //运行状态
dataType = "runState";
data = checkStr.substring(8, 10);
if (data.equalsIgnoreCase("00")) {
sValue = "不运行"; //关机模式
} else if (data.equalsIgnoreCase("01")) {
sValue = "运行"; // 开机模式
}
//计算热泵运行时间,按分钟
nowDataService.proPumpMinutes(buildingId, addr, sValue);
log.info("计算热泵运行时长,楼栋名称:" + buildingName + ",热泵编号:" + addr + ",状态:" + sValue);
} else if (registerAddr.equalsIgnoreCase(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20003"), 4))
|| registerAddr.equalsIgnoreCase(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20026"), 4)) ) {
//20003设定温度,20026水箱水温
if (registerAddr.equalsIgnoreCase(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20003"), 4))) {
dataType = "tempSet";
} else {
dataType = "waterTemp";
}
//读数
sValue = ExchangeStringUtil.hexToDec(checkStr.substring(6, 10));
sValue = String.valueOf(Double.parseDouble(sValue)/10);
if (dataType.equals("waterTemp")) {
String avgTemp = nowDataService.selectAve(buildingId);
NowPublicDataEntity publicData = new NowPublicDataEntity();
publicData.setBuildingId(buildingId);
publicData.setUseWaterTemp(avgTemp);
publicData.setBackWaterTemp(avgTemp);
String pumpId = nowDataService.selectMinPumpId(buildingId);
log.info("---------------addr:" + addr + ",pumpId:" + pumpId + " ---------------");
if (addr.equals(pumpId)) { //取ID最小的热泵为单箱温度
publicData.setSingleTemp(sValue);
log.info("---------------单箱温度:" + sValue + "---------------");
}
} else if (registerAddr.equalsIgnoreCase("0028")
|| registerAddr.equalsIgnoreCase("002C")
|| registerAddr.equalsIgnoreCase("0030")) { //读定时设置值
// 01 03 08 0003 0000 0016 0000 4713
String startTime = ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.hexToDec(checkStr.substring(6, 10)), 2)
+ ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.hexToDec(checkStr.substring(10, 14)), 2);
String closetTime = ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.hexToDec(checkStr.substring(14, 18)), 2)
+ ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.hexToDec(checkStr.substring(18, 22)), 2);
sValue = startTime + closetTime;
nowPublicDataService.saveNowHistoryPublicData(publicData);
log.info("楼栋名称:" + buildingName + ",热泵编号:" + addr);
} else if (dataType.equals("tempSet")) {
pumpSetService.updatePumpSetTemp(sValue, buildingId, addr); //更新设定温度
}
} else if (checkStr.substring(2, 4).equalsIgnoreCase("06")) {
if (registerAddr.equalsIgnoreCase("0001")) { //运行状态
dataType = "runState";
data = checkStr.substring(10, 12);
if (data.equalsIgnoreCase("00")) {
sValue = "不运行"; //关机模式
} else if (data.equalsIgnoreCase("01")) {
sValue = "运行"; //制热模式
} else if (registerAddr.equalsIgnoreCase(ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20041"), 4))) { //故障状态
dataType = "isFault";
String sData = ExchangeStringUtil.hexString2binaryString(checkStr.substring(8, 10));
sData = ExchangeStringUtil.addZeroForNum(sData, 8);
if (sData.substring(7, 8).equalsIgnoreCase("0")) {
sValue = "无故障";
deviceInstallService.updateDeviceFault("0", addr, "热泵");
} else if (sData.substring(7, 8).equalsIgnoreCase("1")) {
sValue = "有故障";
deviceInstallService.updateDeviceFault("1", addr, "热泵");
}
}
} else if (checkStr.substring(2, 4).equalsIgnoreCase("06")) {
if (registerAddr.equalsIgnoreCase("0001")) { //运行状态
dataType = "runState";
data = checkStr.substring(10, 12);
if (data.equalsIgnoreCase("00")) {
sValue = "不运行"; //开机模式
} else if (data.equalsIgnoreCase("01")) {
sValue = "运行"; // 开机模式
}
//计算热泵运行时间,按分钟
nowDataService.proPumpMinutes(buildingId, addr, sValue);
log.info("计算热泵运行时长,楼栋名称:" + buildingName + ",热泵编号:" + addr + ",状态:" + sValue);
}
} else if (checkStr.substring(2, 4).equalsIgnoreCase("10")) {
log.info("时间: " + dateStr + ",热泵ID: " + addr + ",操作成功! ");
sValue = Constant.SUCCESS;
}
stringBuffer.append(dataType);
return sValue;
}
private String getRuiXing(String dateStr, String registerAddr, String buildingId, String buildingName, String checkStr, String sValue, String addr, StringBuffer stringBuffer) {
String data;
String dataType = "";
stringBuffer.setLength(0);
if (checkStr.substring(2, 4).equalsIgnoreCase("03")) {//读
if (registerAddr.equalsIgnoreCase("0001")) { //运行状态
dataType = "runState";
data = checkStr.substring(8, 10);
if (data.equalsIgnoreCase("00")) {
sValue = "不运行"; //关机模式
} else if (data.equalsIgnoreCase("01")) {
sValue = "运行"; //制热模式
}
//计算热泵运行时间,按分钟
nowDataService.proPumpMinutes(buildingId, addr, sValue);
log.info("计算热泵运行时长,楼栋名称:" + buildingName + ",热泵编号:" + addr + ",状态:" + sValue);
} else if (registerAddr.equalsIgnoreCase("000A") || registerAddr.equalsIgnoreCase("0046")) {
//000A设定温度,0046水箱水温
if (registerAddr.equalsIgnoreCase("000A")) {
dataType = "tempSet";
} else {
dataType = "waterTemp";
}
//读数
sValue = ExchangeStringUtil.hexToDec(checkStr.substring(6, 10));
if (dataType.equals("waterTemp")) {
sValue = String.valueOf(Double.parseDouble(sValue)/10);
String avgTemp = nowDataService.selectAve(buildingId);
NowPublicDataEntity publicData = new NowPublicDataEntity();
publicData.setBuildingId(buildingId);
publicData.setUseWaterTemp(avgTemp);
publicData.setBackWaterTemp(avgTemp);
String pumpId = nowDataService.selectMinPumpId(buildingId);
log.info("---------------addr:" + addr + ",pumpId:" + pumpId + " ---------------");
if (addr.equals(pumpId)) { //取ID最小的热泵为单箱温度
publicData.setSingleTemp(sValue);
log.info("---------------单箱温度:" + sValue + "---------------");
}
//计算热泵运行时间,按分钟
nowDataService.proPumpMinutes(buildingId, addr, sValue);
log.info("计算热泵运行时长,楼栋名称:" + buildingName + ",热泵编号:" + addr + ",状态:" + sValue);
nowPublicDataService.saveNowHistoryPublicData(publicData);
log.info("楼栋名称:" + buildingName + ",热泵编号:" + addr);
} else if (dataType.equals("tempSet")) {
pumpSetService.updatePumpSetTemp(sValue, buildingId, addr); //更新设定温度
}
} else if (checkStr.substring(2, 4).equalsIgnoreCase("10")) {
} else if (registerAddr.equalsIgnoreCase("0050")) { //故障状态
dataType = "isFault";
String sData = ExchangeStringUtil.hexString2binaryString(checkStr.substring(8, 10));
sData = ExchangeStringUtil.addZeroForNum(sData, 8);
if (sData.substring(7, 8).equalsIgnoreCase("0")) {
sValue = "无故障";
deviceInstallService.updateDeviceFault("0", addr, "热泵");
} else if (sData.substring(7, 8).equalsIgnoreCase("1")) {
sValue = "有故障";
deviceInstallService.updateDeviceFault("1", addr, "热泵");
}
} else if (registerAddr.equalsIgnoreCase("0028")
|| registerAddr.equalsIgnoreCase("002C")
|| registerAddr.equalsIgnoreCase("0030")) { //读定时设置值
// 01 03 08 0003 0000 0016 0000 4713
String startTime = ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.hexToDec(checkStr.substring(6, 10)), 2)
+ ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.hexToDec(checkStr.substring(10, 14)), 2);
String closetTime = ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.hexToDec(checkStr.substring(14, 18)), 2)
+ ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.hexToDec(checkStr.substring(18, 22)), 2);
sValue = startTime + closetTime;
}
} else if (checkStr.substring(2, 4).equalsIgnoreCase("06")) {
if (registerAddr.equalsIgnoreCase("0001")) { //运行状态
dataType = "runState";
data = checkStr.substring(10, 12);
if (data.equalsIgnoreCase("00")) {
sValue = "不运行"; //关机模式
} else if (data.equalsIgnoreCase("01")) {
sValue = "运行"; //制热模式
}
//计算热泵运行时间,按分钟
nowDataService.proPumpMinutes(buildingId, addr, sValue);
log.info("计算热泵运行时长,楼栋名称:" + buildingName + ",热泵编号:" + addr + ",状态:" + sValue);
} else {
log.info("时间: " + dateStr + ",热泵ID: " + addr + ",操作成功! ");
return Constant.SUCCESS;
sValue = Constant.SUCCESS;
}
}
stringBuffer.append(dataType);
return sValue;
}
private String getMeiDi(String registerAddr, String buildingId, String buildingName, String checkStr, String sValue, String addr, StringBuffer stringBuffer) {
String data;
String dataType = "";
stringBuffer.setLength(0);
if (registerAddr.equalsIgnoreCase("0641")) { //运行状态
dataType = "runState";
data = checkStr.substring(8, 10);
log.info("------------美的热泵状态值-----------" + data);
if (data.equalsIgnoreCase("08")) {
sValue = "不运行"; //关机模式
} else if (data.equalsIgnoreCase("01")) {
sValue = "运行"; //制冷模式
} else if (data.equalsIgnoreCase("02")) {
sValue = "运行"; //制热模式
} else if (data.equalsIgnoreCase("04")) {
sValue = "运行"; //水泵模式
} else if (data.equalsIgnoreCase("10")) {
sValue = "运行"; //制热水模式
}
rtData = sValue;
//计算热泵运行时间,按分钟
nowDataService.proPumpMinutes(buildingId, addr, sValue);
log.info("计算热泵运行时长,楼栋名称:" + buildingName + ",热泵编号:" + addr + ",状态:" + sValue);
} else if (registerAddr.equalsIgnoreCase("0642") || registerAddr.equalsIgnoreCase("0007")) {
//0642设定温度,0007水箱水温
if (registerAddr.equalsIgnoreCase("0642")) {
dataType = "tempSet";
} else {
dataType = "waterTemp";
}
//读数
sValue = ExchangeStringUtil.hexToDec(checkStr.substring(6, 10));
if (dataType.equals("waterTemp")) {
String avgTemp = nowDataService.selectAve(buildingId);
NowPublicDataEntity publicData = new NowPublicDataEntity();
publicData.setBuildingId(buildingId);
publicData.setUseWaterTemp(avgTemp);
publicData.setBackWaterTemp(avgTemp);
String pumpId = nowDataService.selectMinPumpId(buildingId);
if (addr.equals(pumpId)) { //取ID最小的热泵为单箱温度
publicData.setSingleTemp(sValue);
log.info("---------------单箱温度:" + sValue + "---------------");
}
nowPublicDataService.saveNowHistoryPublicData(publicData);
log.info("楼栋名称:" + buildingName + ",热泵编号:" + addr);
} else if (dataType.equals("tempSet")) {
pumpSetService.updatePumpSetTemp(sValue, buildingId, addr); //更新设定温度
}
} else if (registerAddr.equalsIgnoreCase("000B")) { //故障状态
dataType = "isFault";
String sData = ExchangeStringUtil.hexString2binaryString(checkStr.substring(8, 10));
sData = ExchangeStringUtil.addZeroForNum(sData, 8);
if (sData.substring(7, 8).equalsIgnoreCase("0")) {
sValue = "无故障";
deviceInstallService.updateDeviceFault("0", addr, "热泵");
} else if (sData.substring(7, 8).equalsIgnoreCase("1")) {
sValue = "有故障";
deviceInstallService.updateDeviceFault("1", addr, "热泵");
}
} else if (registerAddr.equalsIgnoreCase("0656")
|| registerAddr.equalsIgnoreCase("065A")
|| registerAddr.equalsIgnoreCase("065E")) { //读定时设置值
String startTime = checkStr.substring(8, 10) + checkStr.substring(12, 14);
String closetTime = checkStr.substring(16, 18) + checkStr.substring(20, 22);
sValue = startTime + closetTime;
}
if (!StringUtils.isBlank(sValue)) {
nowDataService.saveNowHistoryData(addr, "热泵", sValue, dataType, buildingId);
log.info("时间: " + dateStr + "热泵ID:" + addr + ",数据: " + sValue + ",保存数据库成功!楼栋名称:" + buildingName);
stringBuffer.append(dataType);
return sValue;
}
private String getMeiDiTwo(String registerAddr, String buildingId, String buildingName, String checkStr, String sValue, String addr, StringBuffer stringBuffer) {
String data;
String dataType = "";
stringBuffer.setLength(0);
if (registerAddr.equalsIgnoreCase("0BBD")) { //运行状态
dataType = "runState";
data = ExchangeStringUtil.hexString2binaryString(checkStr.substring(8, 10));
data = ExchangeStringUtil.addZeroForNum(data, 8);//二进制数,补够8位
data = data.substring(4, 8); //截取后四位
log.info("------------美的2热泵状态值-----------" + data);
if (data.equalsIgnoreCase("0000")) { //0
sValue = "不运行"; //关机
} else if (data.equalsIgnoreCase("0001")) {//1
sValue = "运行"; //水泵
} else if (data.equalsIgnoreCase("0010")) {//2
sValue = "运行"; //制冷
} else if (data.equalsIgnoreCase("0011")) {//3
sValue = "运行"; //制热
} else if (data.equalsIgnoreCase("0100")) {//4
sValue = "运行"; //热水
} else if (data.equalsIgnoreCase("0101")) {//5
sValue = "运行"; //采暖
} else if (data.equalsIgnoreCase("0110")) {//6
sValue = "运行"; //电热模式
}
//计算热泵运行时间,按分钟
nowDataService.proPumpMinutes(buildingId, addr, sValue);
log.info("计算热泵运行时长,楼栋名称:" + buildingName + ",热泵编号:" + addr + ",状态:" + sValue);
} else if (registerAddr.equalsIgnoreCase("0003") || registerAddr.equalsIgnoreCase("0064")) {
//0003设定温度,0064水箱水温
if (registerAddr.equalsIgnoreCase("0003")) {
dataType = "tempSet";
} else {
dataType = "waterTemp";
}
//读数
sValue = ExchangeStringUtil.hexToDec(checkStr.substring(6, 10));
if (dataType.equals("waterTemp")) {
String avgTemp = nowDataService.selectAve(buildingId);
NowPublicDataEntity publicData = new NowPublicDataEntity();
publicData.setBuildingId(buildingId);
publicData.setUseWaterTemp(avgTemp);
publicData.setBackWaterTemp(avgTemp);
String pumpId = nowDataService.selectMinPumpId(buildingId);
log.info("---------------addr:" + addr + ",pumpId:" + pumpId + " ---------------");
if (addr.equals(pumpId)) { //取ID最小的热泵为单箱温度
publicData.setSingleTemp(sValue);
log.info("---------------单箱温度:" + sValue + "---------------");
}
nowPublicDataService.saveNowHistoryPublicData(publicData);
log.info("楼栋名称:" + buildingName + ",热泵编号:" + addr);
} else if (dataType.equals("tempSet")) {
pumpSetService.updatePumpSetTemp(sValue, buildingId, addr); //更新设定温度
}
} else if (registerAddr.equalsIgnoreCase("0BBB")) { //故障状态
dataType = "isFault";
String sData = ExchangeStringUtil.hexString2binaryString(checkStr.substring(8, 10));
sData = ExchangeStringUtil.addZeroForNum(sData, 8);
if (sData.substring(7, 8).equalsIgnoreCase("0")) {
sValue = "无故障";
} else if (sData.substring(7, 8).equalsIgnoreCase("1")) {
sValue = "有故障";
}
} else if (registerAddr.equalsIgnoreCase("0656")
|| registerAddr.equalsIgnoreCase("065A")
|| registerAddr.equalsIgnoreCase("065E")) { //定时设置值
String startTime = ExchangeStringUtil.hexToDec(checkStr.substring(8, 10)) + ExchangeStringUtil.hexToDec(checkStr.substring(12, 14));
String closetTime = ExchangeStringUtil.hexToDec(checkStr.substring(16, 18)) + ExchangeStringUtil.hexToDec(checkStr.substring(20, 22));
sValue = startTime + closetTime;
}
nowDataService.proWaterTemp(dateStr, buildingId, addr); //保存楼栋时间点温度变化
log.info("----------------保存楼栋时间点温度变化值!----------------");
return rtData;
stringBuffer.append(dataType);
return sValue;
}
}

60
user-service/src/main/java/com/mh/user/utils/GetReadOrder485.java

@ -679,11 +679,26 @@ public class GetReadOrder485 {
deviceCodeParamEntity3.setParity(devices.getParity());
deviceCodeParamEntityList.add(deviceCodeParamEntity3);
break;
case "海尔":
// 多联机模式
String registerAddr = ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20026"), 4);
deviceCodeParamEntity3.setRegisterAddr(registerAddr);//实际水温
deviceCodeParamEntity3.setFunCode("03");
deviceCodeParamEntity3.setDeviceAddr(devices.getDeviceAddr());
deviceCodeParamEntity3.setDeviceName(devices.getDeviceName());
deviceCodeParamEntity3.setDeviceType(devices.getDeviceType());
deviceCodeParamEntity3.setBaudrate(devices.getBaudRate());
deviceCodeParamEntity3.setBrand(devices.getBrand());
deviceCodeParamEntity3.setDataCom(devices.getDataCom());
deviceCodeParamEntity3.setBuildingId(devices.getBuildingId());
deviceCodeParamEntity3.setParity(devices.getParity());
deviceCodeParamEntityList.add(deviceCodeParamEntity3);
break;
default:
break;
}
// if (devices.getBrand().equals("美的")) {
// DeviceCodeParamEntity deviceCodeParamEntity3 = new DeviceCodeParamEntity();
// DeviceCodeParamEntity deviceCodeParamEntity3 = new DeviceCodeParamEntity();·
// deviceCodeParamEntity3.setRegisterAddr("0007");//水温
// deviceCodeParamEntity3.setFunCode("03");
// deviceCodeParamEntity3.setDeviceAddr(devices.getDeviceAddr());
@ -767,6 +782,21 @@ public class GetReadOrder485 {
deviceCodeParamEntity1.setParity(devices.getParity());
deviceCodeParamEntityList.add(deviceCodeParamEntity1);//添加到列表
break;
case "海尔":
// 多联机模式
String registerAddr = ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20001"), 4);
deviceCodeParamEntity1.setRegisterAddr(registerAddr);//运行状态
deviceCodeParamEntity1.setFunCode("03");
deviceCodeParamEntity1.setDeviceAddr(devices.getDeviceAddr());
deviceCodeParamEntity1.setDeviceName(devices.getDeviceName());
deviceCodeParamEntity1.setDeviceType(devices.getDeviceType());
deviceCodeParamEntity1.setBaudrate(devices.getBaudRate());
deviceCodeParamEntity1.setBrand(devices.getBrand());
deviceCodeParamEntity1.setDataCom(devices.getDataCom());
deviceCodeParamEntity1.setBuildingId(devices.getBuildingId());
deviceCodeParamEntity1.setParity(devices.getParity());
deviceCodeParamEntityList.add(deviceCodeParamEntity1);//添加到列表
break;
default:
break;
@ -891,6 +921,34 @@ public class GetReadOrder485 {
deviceCodeParamEntity4.setParity(devices.getParity());
deviceCodeParamEntityList.add(deviceCodeParamEntity4);
break;
case "海尔":
// 多联机模式
String registerAddr = ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20003"), 4);
deviceCodeParamEntity2.setRegisterAddr(registerAddr);//设定温度
deviceCodeParamEntity2.setFunCode("03");
deviceCodeParamEntity2.setDeviceAddr(devices.getDeviceAddr());
deviceCodeParamEntity2.setDeviceName(devices.getDeviceName());
deviceCodeParamEntity2.setDeviceType(devices.getDeviceType());
deviceCodeParamEntity2.setBaudrate(devices.getBaudRate());
deviceCodeParamEntity2.setBrand(devices.getBrand());
deviceCodeParamEntity2.setDataCom(devices.getDataCom());
deviceCodeParamEntity2.setBuildingId(devices.getBuildingId());
deviceCodeParamEntity2.setParity(devices.getParity());
deviceCodeParamEntityList.add(deviceCodeParamEntity2);
registerAddr = ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex("20041"), 4);
deviceCodeParamEntity2.setRegisterAddr(registerAddr);//故障状态
deviceCodeParamEntity4.setFunCode("03");
deviceCodeParamEntity4.setDeviceAddr(devices.getDeviceAddr());
deviceCodeParamEntity4.setDeviceName(devices.getDeviceName());
deviceCodeParamEntity4.setDeviceType(devices.getDeviceType());
deviceCodeParamEntity4.setBaudrate(devices.getBaudRate());
deviceCodeParamEntity4.setBrand(devices.getBrand());
deviceCodeParamEntity4.setDataCom(devices.getDataCom());
deviceCodeParamEntity4.setBuildingId(devices.getBuildingId());
deviceCodeParamEntity4.setParity(devices.getParity());
deviceCodeParamEntityList.add(deviceCodeParamEntity4);
break;
}
// if (devices.getBrand().equals("美的")) {
// DeviceCodeParamEntity deviceCodeParamEntity2 = new DeviceCodeParamEntity();

Loading…
Cancel
Save