From 89728921baba1ed33418db01e298c6d89f36771d Mon Sep 17 00:00:00 2001 From: mh Date: Tue, 15 Oct 2024 09:51:08 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E7=9B=91=E6=8E=A7=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E8=BF=90=E8=A1=8C=E7=8A=B6=E6=80=81=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mh/user/mapper/NowDataMapper.java | 43 +++++++++++++++++++ .../impl/NowPublicDataServiceImpl.java | 11 +++++ .../strategy/WaterLevelSwitchStrategy.java | 8 ++-- 3 files changed, 58 insertions(+), 4 deletions(-) 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 d0fe835..281ef2b 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 @@ -10,6 +10,7 @@ import org.apache.ibatis.annotations.*; import org.apache.ibatis.mapping.StatementType; import java.util.List; +import java.util.Map; @Mapper @@ -448,4 +449,46 @@ public interface NowDataMapper { @Param("useWater") String useWater, @Param("backWater") String backWater, @Param("upWater") String upWater); + + /** + * 查询对应的钱 + * @return + */ + @Select("SELECT " + + " TOP 1 " + + " CASE " + + " WHEN EXISTS ( " + + " SELECT " + + " 1 " + + " FROM " + + " now_data " + + " WHERE " + + " up_water_state = '运行') THEN '运行' " + + " ELSE '不运行' " + + " END AS up_water_state, " + + " CASE " + + " WHEN EXISTS ( " + + " SELECT " + + " 1 " + + " FROM " + + " now_data " + + " WHERE " + + " use_water_state = '运行') THEN '运行' " + + " ELSE '不运行' " + + " END AS use_water_state, " + + " CASE " + + " WHEN EXISTS ( " + + " SELECT " + + " 1 " + + " FROM " + + " now_data " + + " WHERE " + + " back_water_state = '运行') THEN '运行' " + + " ELSE '不运行' " + + " END AS back_water_state " + + "FROM " + + " now_data " + + "where " + + " building_id = #{buildingId} and convert(varchar(10), cur_date, 120) = convert(varchar(10), getdate(), 120) ") + Map selectTopOneState(@Param("buildingId") String buildingId); } diff --git a/user-service/src/main/java/com/mh/user/service/impl/NowPublicDataServiceImpl.java b/user-service/src/main/java/com/mh/user/service/impl/NowPublicDataServiceImpl.java index be2166a..e56a57f 100644 --- a/user-service/src/main/java/com/mh/user/service/impl/NowPublicDataServiceImpl.java +++ b/user-service/src/main/java/com/mh/user/service/impl/NowPublicDataServiceImpl.java @@ -3,6 +3,7 @@ package com.mh.user.service.impl; import com.mh.user.entity.NowPublicDataEntity; import com.mh.user.mapper.BuildingMapper; import com.mh.user.mapper.DeviceInstallMapper; +import com.mh.user.mapper.NowDataMapper; import com.mh.user.mapper.NowPublicDataMapper; import com.mh.user.model.TempModel; import com.mh.user.service.NowPublicDataService; @@ -14,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import java.util.Map; @Slf4j @Service @@ -29,6 +31,8 @@ public class NowPublicDataServiceImpl implements NowPublicDataService { BuildingMapper buildingMapper; private final SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + @Autowired + private NowDataMapper nowDataMapper; @Override public void saveNowPublicData(NowPublicDataEntity nowPublicDataEntity) { @@ -84,6 +88,13 @@ public class NowPublicDataServiceImpl implements NowPublicDataService { if (r1==0){ nowPublicDataMapper.saveNowPublicData(nowPublicDataEntity); } else { + // 判断今天的记录是否存在多个补水,供水,回水状态值 + Map states = nowDataMapper.selectTopOneState(buildingId); + if (states != null && !states.isEmpty()) { + nowPublicDataEntity.setUpWater(String.valueOf(states.get("up_water_state"))); + nowPublicDataEntity.setUseWater(String.valueOf(states.get("use_water_state"))); + nowPublicDataEntity.setBackWater(String.valueOf(states.get("back_water_state"))); + } nowPublicDataMapper.updateNowPublicData(nowPublicDataEntity); } //判断历史表是否有记录 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 7ad2e66..d00884b 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 @@ -509,20 +509,20 @@ public class WaterLevelSwitchStrategy implements DeviceStrategy { } log.info("-----------------供水/回水状态:" + l8 + "-----------------"); } else { - if (l1.equals("0001")) { //l路,0000表示有输入,0001表示无输入 + if (l2.equals("0001")) { //l路,0000表示有输入,0001表示无输入 publicData.setUseWater("运行"); //供水 publicData.setBackWater("运行");//回水 } else { publicData.setUseWater("不运行"); publicData.setBackWater("不运行"); } - log.info("-----------------供水/回水状态:" + l1 + "-----------------"); - if (l2.equals("0001")) { //2路 //补水 + log.info("-----------------供水/回水状态:" + l2 + "-----------------"); + if (l1.equals("0001")) { //2路 //补水 publicData.setUpWater("运行"); } else { publicData.setUpWater("不运行"); } - log.info("-----------------补水状态:" + l2 + "-----------------"); + log.info("-----------------补水状态:" + l1 + "-----------------"); } nowPublicDataService.saveNowHistoryPublicData(publicData); log.info("地址:{},供回补水状态保存数据库成功!楼栋ID:{},名称:{}" ,addr, buildingId, buildingName);