From 5344d21ea417a12a555eb14b5f29c357a6dbd6e8 Mon Sep 17 00:00:00 2001 From: mh Date: Mon, 14 Oct 2024 16:36:51 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=B7=BB=E5=8A=A0=E6=9F=90=E6=A0=8B?= =?UTF-8?q?=E6=A5=BC=E5=AD=98=E5=9C=A8=E9=AB=98=E4=BD=8E=E6=B0=B4=E4=BD=8D?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=8F=AF=E4=BB=A5=E5=9C=A8=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=9F=A5=E7=9C=8B=E5=88=B0=EF=BC=9B=202?= =?UTF-8?q?=E3=80=81=E7=9B=91=E6=8E=A7=E9=A1=B5=E9=9D=A2=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=A1=A5=E6=B0=B4=E3=80=81=E4=BE=9B=E6=B0=B4=E3=80=81=E5=9B=9E?= =?UTF-8?q?=E6=B0=B4=E7=8A=B6=E6=80=81=EF=BC=9B=203=E3=80=81=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E9=A1=B5=E9=9D=A2=E6=B7=BB=E5=8A=A0=E9=AB=98=E4=BD=8E?= =?UTF-8?q?=E6=B0=B4=E7=94=B5=E8=A1=A8=E8=AF=BB=E5=8F=96=EF=BC=8C=E8=A1=A5?= =?UTF-8?q?=E6=B0=B4=E7=BB=9F=E4=B8=80=E9=A1=B5=E9=9D=A2=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2024数据库脚本.sql | 8 ++++++ .../com/mh/user/entity/NowDataEntity.java | 6 +++++ .../com/mh/user/mapper/NowDataMapper.java | 16 +++++++++++ .../com/mh/user/service/NowDataService.java | 1 + .../user/service/impl/NowDataServiceImpl.java | 5 ++++ .../strategy/WaterLevelSwitchStrategy.java | 24 +++++++++++++---- .../mh/user/UserServiceApplicationTests.java | 9 +++++++ .../java/com/mh/user/socket/NIOServer.java | 27 +++++++++++++------ 8 files changed, 83 insertions(+), 13 deletions(-) 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 objects = new ArrayList<>(); + test1(dataStr, objects); + System.out.println(dataStr.toString()); + System.out.println(objects.get(0)); + } + public static String test1(StringBuilder dataStr, ArrayList objects) { + dataStr.append("12345678911111"); + objects.add(dataStr); + return "123456789"; + } // 缓冲区使用 public void BufferTest(){ // // 构建一个堆内字节缓冲区