diff --git a/2024数据库脚本.sql b/2024数据库脚本.sql
index e60e2ef..1749784 100644
--- a/2024数据库脚本.sql
+++ b/2024数据库脚本.sql
@@ -197,3 +197,11 @@ EXEC chws_gsh.sys.sp_addextendedproperty 'MS_Description', N'14点水位', 'sche
ALTER TABLE chws_gsh.dbo.building ADD low_tank_height numeric(24,2) NULL;
EXEC chws_gsh.sys.sp_addextendedproperty 'MS_Description', N'低区域水箱高度', 'schema', N'dbo', 'table', N'building', 'column', N'low_tank_height';
+-- 2024-10-11 添加供水,补水,回水状态
+ALTER TABLE now_data ADD up_water_state varchar(50) NULL;
+EXEC sp_addextendedproperty 'MS_Description', N'供水状态', 'schema', N'dbo', 'table', N'now_data', 'column', N'up_water_state';
+ALTER TABLE now_data ADD use_water_state varchar(50) NULL;
+EXEC sp_addextendedproperty 'MS_Description', N'补水状态', 'schema', N'dbo', 'table', N'now_data', 'column', N'use_water_state';
+ALTER TABLE now_data ADD back_water_state varchar(50) NULL;
+EXEC sp_addextendedproperty 'MS_Description', N'回水状态', 'schema', N'dbo', 'table', N'now_data', 'column', N'back_water_state';
+
diff --git a/user-service/src/main/java/com/mh/user/entity/NowDataEntity.java b/user-service/src/main/java/com/mh/user/entity/NowDataEntity.java
index 23242ae..9218fd3 100644
--- a/user-service/src/main/java/com/mh/user/entity/NowDataEntity.java
+++ b/user-service/src/main/java/com/mh/user/entity/NowDataEntity.java
@@ -23,4 +23,10 @@ public class NowDataEntity {
private String tankName; //水箱名称
private String envTemp; //环境温度
+ private String upWaterState; // 供水状态
+
+ private String useWaterState; // 补水状态
+
+ private String backWaterState; // 回水状态
+
}
diff --git a/user-service/src/main/java/com/mh/user/mapper/NowDataMapper.java b/user-service/src/main/java/com/mh/user/mapper/NowDataMapper.java
index 72781b3..d0fe835 100644
--- a/user-service/src/main/java/com/mh/user/mapper/NowDataMapper.java
+++ b/user-service/src/main/java/com/mh/user/mapper/NowDataMapper.java
@@ -65,6 +65,9 @@ public interface NowDataMapper {
@Result(property ="tempSet",column ="temp_set"),
@Result(property="waterTemp",column="water_temp"),
@Result(property ="runState",column ="run_state"),
+ @Result(property ="upWaterState",column ="up_water_state"),
+ @Result(property ="useWaterState",column ="use_water_state"),
+ @Result(property ="backWaterState",column ="back_water_state"),
@Result(property ="isFault",column ="is_fault"),
@Result(property ="levelSet",column ="level_set"),
@Result(property ="waterLevel",column ="water_level"),
@@ -432,4 +435,17 @@ public interface NowDataMapper {
@Select("select count(1) from now_data where pump_name like '%热泵%' ")
int selectPumpCount(@Param("buildingId") String buildingId);
+
+ @Update("")
+ void updateNowDataByPumpName(@Param("pumpName") String pumpName,
+ @Param("buildingId") String buildingId,
+ @Param("useWater") String useWater,
+ @Param("backWater") String backWater,
+ @Param("upWater") String upWater);
}
diff --git a/user-service/src/main/java/com/mh/user/service/NowDataService.java b/user-service/src/main/java/com/mh/user/service/NowDataService.java
index 770de6d..be37fac 100644
--- a/user-service/src/main/java/com/mh/user/service/NowDataService.java
+++ b/user-service/src/main/java/com/mh/user/service/NowDataService.java
@@ -135,5 +135,6 @@ public interface NowDataService {
//通过楼栋编号获取最小热泵id号,规定最小热泵号为单箱
String selectMinPumpId(String buildingId);
+ void updateNowDataByPumpName(String pumpName, String buildingId, String useWater, String backWater, String upWater);
}
diff --git a/user-service/src/main/java/com/mh/user/service/impl/NowDataServiceImpl.java b/user-service/src/main/java/com/mh/user/service/impl/NowDataServiceImpl.java
index a5b5029..7568d9e 100644
--- a/user-service/src/main/java/com/mh/user/service/impl/NowDataServiceImpl.java
+++ b/user-service/src/main/java/com/mh/user/service/impl/NowDataServiceImpl.java
@@ -545,4 +545,9 @@ public class NowDataServiceImpl implements NowDataService {
public String selectMinPumpId(String buildingId) {
return nowDataMapper.selectMinPumpId(buildingId);
}
+
+ @Override
+ public void updateNowDataByPumpName(String pumpName, String buildingId, String useWater, String backWater, String upWater) {
+ nowDataMapper.updateNowDataByPumpName(pumpName, buildingId, useWater, backWater, upWater);
+ }
}
diff --git a/user-service/src/main/java/com/mh/user/strategy/WaterLevelSwitchStrategy.java b/user-service/src/main/java/com/mh/user/strategy/WaterLevelSwitchStrategy.java
index a78c7aa..7ad2e66 100644
--- a/user-service/src/main/java/com/mh/user/strategy/WaterLevelSwitchStrategy.java
+++ b/user-service/src/main/java/com/mh/user/strategy/WaterLevelSwitchStrategy.java
@@ -4,12 +4,10 @@ import com.alibaba.fastjson2.JSON;
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.service.BuildingService;
-import com.mh.user.service.NowDataService;
-import com.mh.user.service.NowPublicDataService;
-import com.mh.user.service.SysParamService;
+import com.mh.user.service.*;
import com.mh.user.utils.ExchangeStringUtil;
import com.mh.user.utils.SpringBeanUtil;
import lombok.extern.slf4j.Slf4j;
@@ -39,6 +37,8 @@ public class WaterLevelSwitchStrategy implements DeviceStrategy {
BuildingService buildingService = context.getBean(BuildingService.class);
+ DeviceInstallService deviceInstallService = context.getBean(DeviceInstallService.class);
+
private static class SingletonHolder {
private static final WaterLevelSwitchStrategy INSTANCE = new WaterLevelSwitchStrategy();
}
@@ -525,7 +525,21 @@ public class WaterLevelSwitchStrategy implements DeviceStrategy {
log.info("-----------------补水状态:" + l2 + "-----------------");
}
nowPublicDataService.saveNowHistoryPublicData(publicData);
- log.info("-----------------状态保存数据库成功!楼栋名称:" + buildingName + "-----------------");
+ log.info("地址:{},供回补水状态保存数据库成功!楼栋ID:{},名称:{}" ,addr, buildingId, buildingName);
+ // 更新now_data表中对应的供水、回水、补水状态
+ 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());
+ } else 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());
+ } else {
+ nowDataService.updateNowDataByPumpName(null, buildingId, publicData.getUseWater(), publicData.getBackWater(), publicData.getUpWater());
+ }
+ }
}
}
return Constant.FAIL;
diff --git a/user-service/src/test/java/com/mh/user/UserServiceApplicationTests.java b/user-service/src/test/java/com/mh/user/UserServiceApplicationTests.java
index 2353e64..577e264 100644
--- a/user-service/src/test/java/com/mh/user/UserServiceApplicationTests.java
+++ b/user-service/src/test/java/com/mh/user/UserServiceApplicationTests.java
@@ -8,6 +8,7 @@ import com.mh.user.serialport.SerialPortThread;
import com.mh.user.service.DeviceManageService;
import com.mh.user.service.GaugeService;
import com.mh.user.service.HistoryDataPreService;
+import com.mh.user.service.NowDataService;
import com.mh.user.strategy.PressureTransStrategy;
import com.mh.user.utils.*;
import org.checkerframework.checker.units.qual.A;
@@ -145,4 +146,12 @@ class UserServiceApplicationTests {
System.out.println(energyPre);
}
+ @Autowired
+ private NowDataService nowDataService;
+
+ @Test
+ public void testNowData() {
+ nowDataService.updateNowDataByPumpName(null, "21", "1", "2", "3");
+ }
+
}
diff --git a/user-service/src/test/java/com/mh/user/socket/NIOServer.java b/user-service/src/test/java/com/mh/user/socket/NIOServer.java
index 06dc293..4e8dfa1 100644
--- a/user-service/src/test/java/com/mh/user/socket/NIOServer.java
+++ b/user-service/src/test/java/com/mh/user/socket/NIOServer.java
@@ -29,16 +29,27 @@ public class NIOServer {
private static ArrayList channels = new ArrayList<>();
public static void main(String[] args) throws IOException {
- log.info("test");
- NIOServer nioServer = new NIOServer();
- // 缓冲测试
-// nioServer.BufferTest();
- // 通道测试
-// nioServer.ChannelTest();
- // Selector单线程操作
- nioServer.SelectorSingleTest();
+// log.info("test");
+// NIOServer nioServer = new NIOServer();
+// // 缓冲测试
+//// nioServer.BufferTest();
+// // 通道测试
+//// nioServer.ChannelTest();
+// // Selector单线程操作
+// nioServer.SelectorSingleTest();
+ StringBuilder dataStr = new StringBuilder();
+ ArrayList