diff --git a/user-service/src/main/java/com/mh/user/job/DealDataJob.java b/user-service/src/main/java/com/mh/user/job/DealDataJob.java index b7fdfbb..b36fea3 100644 --- a/user-service/src/main/java/com/mh/user/job/DealDataJob.java +++ b/user-service/src/main/java/com/mh/user/job/DealDataJob.java @@ -180,25 +180,25 @@ public class DealDataJob { } } - @Scheduled(cron = "0 0 0/1 * * ?") - public void preUseData() { - // 每小时预测一次数据 - SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); - Date date = new Date(); - String curDate = sdf1.format(date); - List 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); - } - } - } +// @Scheduled(cron = "0 0 0/1 * * ?") +// public void preUseData() { +// // 每小时预测一次数据 +// SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); +// Date date = new Date(); +// String curDate = sdf1.format(date); +// List 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); +// } +// } +// } /** * 定时删除历史流水记录(删除前三个月的记录) diff --git a/user-service/src/main/java/com/mh/user/service/impl/DeviceControlServiceImpl.java b/user-service/src/main/java/com/mh/user/service/impl/DeviceControlServiceImpl.java index db5b0d3..e1b6331 100644 --- a/user-service/src/main/java/com/mh/user/service/impl/DeviceControlServiceImpl.java +++ b/user-service/src/main/java/com/mh/user/service/impl/DeviceControlServiceImpl.java @@ -92,6 +92,10 @@ public class DeviceControlServiceImpl implements DeviceControlService { rtData = handleTimeControl(serialPortModel, deviceCodeParam, controlData, rtData, type, serialPortSingle); log.info("设备类型为时控==>{}", rtData); break; + case "温控": + rtData = handleTempControl(serialPortModel, deviceCodeParam, controlData, rtData, type, serialPortSingle); + log.info("设备类型为温控==>{}", rtData); + break; case "水位开关": rtData = handleWaterLevelSwitch(serialPortModel, deviceCodeParam, controlData, rtData, type, serialPortSingle); log.info("设备类型为水位开关==>{}", rtData); @@ -139,6 +143,57 @@ public class DeviceControlServiceImpl implements DeviceControlService { } } + private String handleTempControl(SerialPortModel serialPortModel, DeviceCodeParamEntity deviceCodeParam, ControlSetEntity controlData, String rtData, String type, SerialPortSingle2 serialPortSingle) { + switch (deviceCodeParam.getParam()) { + case "upperLimit": + // 上限 + deviceCodeParam.setRegisterAddr("0100"); + break; + case "lowerLimit": + // 下限 + deviceCodeParam.setRegisterAddr("0108"); + break; + case "upperUpperLimit": + // 上上限 + deviceCodeParam.setRegisterAddr("0110"); + break; + case "lowerLowerLimit": + // 下下限 + deviceCodeParam.setRegisterAddr("0118"); + break; + case "curTemp": + // 当前温度 + deviceCodeParam.setRegisterAddr("0000"); + break; + case "upperLimitDiff": + // 上限回差 + deviceCodeParam.setRegisterAddr("0104"); + break; + case "lowerLimitDiff": + // 下限回差 + deviceCodeParam.setRegisterAddr("010C"); + break; + case "upperUpperLimitDiff": + // 上上限回差 + deviceCodeParam.setRegisterAddr("0114"); + break; + case "lowerLowerLimitDiff": + // 下下限回差 + deviceCodeParam.setRegisterAddr("011C"); + break; + } + if (Constant.READ.equals(type)) { + deviceCodeParam.setFunCode("03"); //功能码读数据 + rtData = serialPortSingle.serialPortSend(deviceCodeParam);//生成并发送指令 + } else { + // 传入值,小数点保留一位,需要乘以10倍 + int setValue = new BigDecimal(serialPortModel.getDataValue()).multiply(new BigDecimal(10)).intValue(); + deviceCodeParam.setDataValue(String.valueOf(setValue)); + deviceCodeParam.setFunCode("10"); //功能码写数据 + } + return rtData; + } + private String handleElectricMeter(SerialPortModel serialPortModel, DeviceCodeParamEntity deviceCodeParam, ControlSetEntity controlData, String rtData, String type, SerialPortSingle2 serialPortSingle) { rtData = serialPortSingle.serialPortSend(deviceCodeParam); return rtData; diff --git a/user-service/src/main/java/com/mh/user/strategy/TempControlStrategy.java b/user-service/src/main/java/com/mh/user/strategy/TempControlStrategy.java index 696ccce..678fe55 100644 --- a/user-service/src/main/java/com/mh/user/strategy/TempControlStrategy.java +++ b/user-service/src/main/java/com/mh/user/strategy/TempControlStrategy.java @@ -64,7 +64,15 @@ public class TempControlStrategy implements DeviceStrategy { // }else if(registerAddr.equals("")){ // str=str+"0300000002"; // } - str = str + "0300000002"; + String funCode = ExchangeStringUtil.addZeroForNum(deviceCodeParamEntity.getFunCode(), 2); + if ("03".equals(funCode)) { + registerAddr = ExchangeStringUtil.addZeroForNum(registerAddr, 4); //寄存器地址 + str = str + funCode + registerAddr + "0002"; + } else if ("10".equals(funCode)) { + str = str + funCode + registerAddr + "0002" + "04" + + ExchangeStringUtil.addZeroForNum(ExchangeStringUtil.decToHex(deviceCodeParamEntity.getDataValue()), 4) + + "0001"; + } String checkWord = ExchangeStringUtil.getStrCRC16(str); //CRC16校验 str = str + checkWord; } catch (Exception e) { @@ -88,11 +96,11 @@ public class TempControlStrategy implements DeviceStrategy { if (checkStr.substring(2, 4).equalsIgnoreCase("03")) {// 读 data = ExchangeStringUtil.hexToDec(checkStr.substring(6, 10)); Double fdata = Double.parseDouble(data) / 10; - if (fdata <= 25) { - fdata = 25.0; - } else if (fdata >= 65) { - fdata = 65.0; - } +// if (fdata <= 25) { +// fdata = 25.0; +// } else if (fdata >= 65) { +// fdata = 65.0; +// } nowDataService.saveNowHistoryData2(addr, "温控", String.valueOf(fdata), "waterTemp", buildingId); nowDataService.proWaterTemp(dateStr, buildingId, "");//保存时间点温度 String avgTemp = nowDataService.selectAve(buildingId); @@ -104,6 +112,8 @@ public class TempControlStrategy implements DeviceStrategy { nowPublicDataService.saveNowHistoryPublicData(publicData); log.info("温控号:" + addr + ",温度值:" + fdata + ",保存数据库成功!楼栋名称:" + buildingName); return String.valueOf(fdata); + } else if (checkStr.substring(2, 4).equalsIgnoreCase("10")) {// 写 + result = Constant.SUCCESS; } return result; } diff --git a/user-service/src/main/resources/application-dev.yml b/user-service/src/main/resources/application-dev.yml index 13ccfb9..2f18bc0 100644 --- a/user-service/src/main/resources/application-dev.yml +++ b/user-service/src/main/resources/application-dev.yml @@ -8,7 +8,7 @@ spring: type: com.alibaba.druid.pool.DruidDataSource druid: #添加allowMultiQueries=true 在批量更新时才不会出错 - url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=chws_gsh;allowMultiQueries=true + url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=chws_hx;allowMultiQueries=true driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver username: sa password: mh@803 diff --git a/user-service/src/main/resources/application-prod.yml b/user-service/src/main/resources/application-prod.yml index f013158..02ba3b8 100644 --- a/user-service/src/main/resources/application-prod.yml +++ b/user-service/src/main/resources/application-prod.yml @@ -1,5 +1,5 @@ server: - port: 8763 #8761创新、8762广商、8763华厦、广州理工 + port: 8762 #8761创新、8762广商、8763华厦、广州理工,华粤8762 spring: application: name: user-service @@ -14,11 +14,11 @@ spring: # password: mh@803 ## url: jdbc:sqlserver://120.25.220.177:32012;DatabaseName=M_CHWS;allowMultiQueries=true #阿里云服务器-广州理工 - url: jdbc:sqlserver://111.230.50.186:32012;DatabaseName=CHWS;allowMultiQueries=true - driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver - username: test - password: minghan123456@ - #华厦云服务器 +# url: jdbc:sqlserver://111.230.50.186:32012;DatabaseName=CHWS;allowMultiQueries=true +# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver +# username: test +# password: minghan123456@ +# #华厦云服务器 # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=CHWS;allowMultiQueries=true # driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver # username: chws @@ -43,6 +43,11 @@ spring: # driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver # username: sa # password: mh@803 + #华粤服务器 + url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=chws_hy;allowMultiQueries=true + driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver + username: chws_hy + password: huayue@803 filters: stat,wall,config max-active: 100 diff --git a/user-service/src/main/resources/application.yml b/user-service/src/main/resources/application.yml index 3d7808a..9f96606 100644 --- a/user-service/src/main/resources/application.yml +++ b/user-service/src/main/resources/application.yml @@ -1,3 +1,3 @@ spring: profiles: - active: dev + active: prod diff --git a/user-service/src/test/java/com/mh/user/DealDataTest.java b/user-service/src/test/java/com/mh/user/DealDataTest.java index 3e636a9..3222152 100644 --- a/user-service/src/test/java/com/mh/user/DealDataTest.java +++ b/user-service/src/test/java/com/mh/user/DealDataTest.java @@ -3,8 +3,11 @@ package com.mh.user; import com.mh.user.entity.EnergyEntity; import com.mh.user.mapper.EnergyMapper; import com.mh.user.mapper.DealDataMapper; +import com.mh.user.model.BuildingModel; +import com.mh.user.service.BuildingService; import com.mh.user.service.HistoryDataPreService; import com.mh.user.service.NowDataService; +import com.mh.user.utils.ExchangeStringUtil; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -45,17 +48,39 @@ public class DealDataTest extends UserServiceApplicationTests { @Autowired private HistoryDataPreService historyDataPreService; + + @Autowired + private BuildingService buildingService; @Test public void testPre() { - try { - // 训练数据 - historyDataPreService.startTrainData("21"); - // 预测数据 - historyDataPreService.startPredictData("21", "2024-11-19"); - } catch (Exception e) { - e.printStackTrace(); - System.out.println(e.getMessage()); +// try { +// // 训练数据 +// historyDataPreService.startTrainData("21"); +// // 预测数据 +// historyDataPreService.startPredictData("21", "2024-11-19"); +// } catch (Exception e) { +// e.printStackTrace(); +// System.out.println(e.getMessage()); +// } + List buildingModels = buildingService.selectBuildingName(); + for (BuildingModel buildingModel : buildingModels) { + String buildingId = String.valueOf(buildingModel.getBuildingId()); + if ("21".equals(buildingId) || "24".equals(buildingId) || "25".equals(buildingId)) { + continue; + } + for (int i = 1; i < 20; i++) { + String curDate = "2024-11-" + ExchangeStringUtil.addZeroForNum(String.valueOf(i), 2); + try { + // 训练数据 + historyDataPreService.startTrainData(buildingId); + // 预测数据 + historyDataPreService.startPredictData(buildingId, curDate); + } catch (Exception e) { + e.printStackTrace(); + } + } + } } }