Browse Source

1、压变水位读取更新sql修复;

dev
mh 7 months ago
parent
commit
7fc0d63d6f
  1. 58
      user-service/src/main/java/com/mh/user/mapper/NowDataMapper.java
  2. 2
      user-service/src/main/java/com/mh/user/serialport/SendAndReceiveByCom.java
  3. 64
      user-service/src/main/java/com/mh/user/service/impl/NowDataServiceImpl.java
  4. 16
      user-service/src/test/java/com/mh/user/UserServiceApplicationTests.java

58
user-service/src/main/java/com/mh/user/mapper/NowDataMapper.java

@ -23,16 +23,16 @@ public interface NowDataMapper {
//修改监控界面实时信息(热泵) //修改监控界面实时信息(热泵)
@Update("<script>" + @Update("<script>" +
" update now_data set cur_date=getDate()" + " update now_data set cur_date=getDate()" +
" <if test='buildingName!=null'> , building_name = #{buildingName} </if>" + " <if test='buildingName!=null and buildingName != \"\"'> , building_name = #{buildingName} </if>" +
" <if test='pumpName!=null'> , pump_name = #{pumpName} </if>" + " <if test='pumpName!=null and pumpName != \"\"'> , pump_name = #{pumpName} </if>" +
" <if test='tempSet!=null'> , temp_set = #{tempSet} </if>" + " <if test='tempSet!=null and tempSet != \"\"'> , temp_set = #{tempSet} </if>" +
" <if test='waterTemp!=null'> , water_temp = #{waterTemp} </if>" + " <if test='waterTemp!=null and waterTemp != \"\"'> , water_temp = #{waterTemp} </if>" +
" <if test='runState!=null'> , run_state = #{runState} </if>" + " <if test='runState!=null and runState != \"\"'> , run_state = #{runState} </if>" +
" <if test='isFault!=null'> , is_fault = #{isFault} </if>" + " <if test='isFault!=null and isFault != \"\"'> , is_fault = #{isFault} </if>" +
" <if test='levelSet!=null'> , level_set = #{levelSet} </if>" + " <if test='levelSet!=null and levelSet != \"\"'> , level_set = #{levelSet} </if>" +
" <if test='waterLevel!=null'> , water_level = #{waterLevel} </if>" + " <if test='waterLevel!=null and waterLevel != \"\"'> , water_level = #{waterLevel} </if>" +
" <if test='tankId!=null'> , tank_id = #{tankId} </if>" + " <if test='tankId!=null and tankId != \"\"'> , tank_id = #{tankId} </if>" +
" <if test='tankName!=null'> , tank_name = #{tankName} </if>" + " <if test='tankName!=null and tankName != \"\"'> , tank_name = #{tankName} </if>" +
" where building_id = #{buildingId} and pump_id = #{pumpId} " + " where building_id = #{buildingId} and pump_id = #{pumpId} " +
"</script>") "</script>")
void updateNowData(NowDataEntity nowDataEntity); void updateNowData(NowDataEntity nowDataEntity);
@ -40,17 +40,17 @@ public interface NowDataMapper {
//修改监控界面实时信息(不包含热泵) //修改监控界面实时信息(不包含热泵)
@Update("<script>" + @Update("<script>" +
" update now_data set cur_date=getDate()" + " update now_data set cur_date=getDate()" +
" <if test='buildingName!=null'> , building_name = #{buildingName} </if>" + " <if test='buildingName!=null and buildingName != \"\"'> , building_name = #{buildingName} </if>" +
" <if test='pumpId!=null'> , pump_id = #{pumpId} </if>" + " <if test='pumpId!=null and pumpId != \"\"'> , pump_id = #{pumpId} </if>" +
" <if test='pumpName!=null'> , pump_name = #{pumpName} </if>" + " <if test='pumpName!=null and pumpName != \"\"'> , pump_name = #{pumpName} </if>" +
" <if test='tempSet!=null'> , temp_set = #{tempSet} </if>" + " <if test='tempSet!=null and tempSet != \"\"'> , temp_set = #{tempSet} </if>" +
" <if test='waterTemp!=null'> , water_temp = #{waterTemp} </if>" + " <if test='waterTemp!=null and waterTemp != \"\"'> , water_temp = #{waterTemp} </if>" +
" <if test='runState!=null'> , run_state = #{runState} </if>" + " <if test='runState!=null and runState != \"\"'> , run_state = #{runState} </if>" +
" <if test='isFault!=null'> , is_fault = #{isFault} </if>" + " <if test='isFault!=null and isFault != \"\"'> , is_fault = #{isFault} </if>" +
" <if test='levelSet!=null'> , level_set = #{levelSet} </if>" + " <if test='levelSet!=null and levelSet != \"\"'> , level_set = #{levelSet} </if>" +
" <if test='waterLevel!=null'> , water_level = #{waterLevel} </if>" + " <if test='waterLevel!=null and waterLevel != \"\"'> , water_level = #{waterLevel} </if>" +
" <if test='tankId!=null'> , tank_id = #{tankId} </if>" + " <if test='tankId!=null and tankId != \"\"'> , tank_id = #{tankId} </if>" +
" <if test='tankName!=null'> , tank_name = #{tankName} </if>" + " <if test='tankName!=null and tankName != \"\"'> , tank_name = #{tankName} </if>" +
" where building_id = #{buildingId} " + " where building_id = #{buildingId} " +
"</script>") "</script>")
void updateNowData2(NowDataEntity nowDataEntity); void updateNowData2(NowDataEntity nowDataEntity);
@ -395,20 +395,26 @@ public interface NowDataMapper {
//按高低区更新water_Level //按高低区更新water_Level
@Update("update now_data SET now_data.water_Level=#{waterLevel} FROM device_install where now_data.pump_id =device_install.device_addr AND device_install.seat=#{seat} and now_data.building_id=#{buildingId} ") @Update("update now_data SET now_data.water_Level=#{waterLevel} FROM device_install " +
" where now_data.pump_id =device_install.device_addr AND device_install.seat=#{seat} and now_data.building_id=#{buildingId} " +
" and now_data.building_id = device_install.building_id ")
void nowDataWaterLevel(@Param("waterLevel") String waterLevel, void nowDataWaterLevel(@Param("waterLevel") String waterLevel,
@Param("seat") String seat, @Param("seat") String seat,
@Param("buildingId") String buildingId); @Param("buildingId") String buildingId);
//按高低区更新levelSet //按高低区更新levelSet
@Update("update now_data SET now_data.level_set=#{levelSet} FROM device_install where now_data.pump_id =device_install.device_addr AND device_install.seat=#{seat} and now_data.building_id=#{buildingId} ") @Update("update now_data SET now_data.level_set=#{levelSet} FROM device_install " +
" where now_data.pump_id =device_install.device_addr AND device_install.seat=#{seat} and now_data.building_id=#{buildingId} " +
" and now_data.building_id = device_install.building_id ")
void nowDataLevelSet(@Param("levelSet") String levelSet, void nowDataLevelSet(@Param("levelSet") String levelSet,
@Param("seat") String seat, @Param("seat") String seat,
@Param("buildingId") String buildingId); @Param("buildingId") String buildingId);
//按高低区更新water_Level //按高低区更新water_Level
@Update("update history_Data SET history_Data.water_Level=#{waterLevel} FROM device_install where history_Data.pump_id =device_install.device_addr AND device_install.seat=#{seat} " + @Update("update history_Data SET history_Data.water_Level=#{waterLevel} FROM device_install where history_Data.pump_id =device_install.device_addr AND device_install.seat=#{seat} " +
" and history_Data.building_id=#{buildingId} and convert(varchar(13),cur_date,121)=left(#{curDate},13) ") " and history_Data.building_id=#{buildingId} " +
" and convert(varchar(13),cur_date,121)=left(#{curDate},13)" +
" and history_Data.building_id = device_install.building_id ")
void historyDataWaterLevel(@Param("waterLevel") String waterLevel, void historyDataWaterLevel(@Param("waterLevel") String waterLevel,
@Param("seat") String seat, @Param("seat") String seat,
@Param("buildingId") String buildingId, @Param("buildingId") String buildingId,
@ -416,7 +422,9 @@ public interface NowDataMapper {
//按高低区更新levelSet //按高低区更新levelSet
@Update("update history_Data SET history_Data.level_set=#{levelSet} FROM device_install where history_Data.pump_id =device_install.device_addr AND device_install.seat=#{seat} " + @Update("update history_Data SET history_Data.level_set=#{levelSet} FROM device_install where history_Data.pump_id =device_install.device_addr AND device_install.seat=#{seat} " +
" and history_Data.building_id=#{buildingId} and convert(varchar(13),cur_date,121)=left(#{curDate},13) ") " and history_Data.building_id=#{buildingId} " +
" and convert(varchar(13),cur_date,121)=left(#{curDate},13) " +
" and history_Data.building_id = device_install.building_id ")
void historyDataLevelSet(@Param("levelSet") String levelSet, void historyDataLevelSet(@Param("levelSet") String levelSet,
@Param("seat") String seat, @Param("seat") String seat,
@Param("buildingId") String buildingId, @Param("buildingId") String buildingId,

2
user-service/src/main/java/com/mh/user/serialport/SendAndReceiveByCom.java

@ -184,7 +184,7 @@ public class SendAndReceiveByCom {
//去掉空格和null //去掉空格和null
receiveStr = receiveStr.replace("null", ""); receiveStr = receiveStr.replace("null", "");
receiveStr = receiveStr.replace(" ", ""); receiveStr = receiveStr.replace(" ", "");
log.info("串口" + serialPort + "接受第" + i + "数据:" + receiveStr + ",大小: " + receiveStr.length()); log.info("串口" + serialPort.getName() + "接受第" + i + "数据:" + receiveStr + ",大小: " + receiveStr.length());
//返回值全部变成大写 //返回值全部变成大写
String receiveData = receiveStr.toUpperCase(); String receiveData = receiveStr.toUpperCase();
//截取去掉FE //截取去掉FE

64
user-service/src/main/java/com/mh/user/service/impl/NowDataServiceImpl.java

@ -1,5 +1,6 @@
package com.mh.user.service.impl; package com.mh.user.service.impl;
import com.mh.common.utils.StringUtils;
import com.mh.user.entity.*; import com.mh.user.entity.*;
import com.mh.user.mapper.DeviceFloorMapper; import com.mh.user.mapper.DeviceFloorMapper;
import com.mh.user.mapper.DeviceInstallMapper; import com.mh.user.mapper.DeviceInstallMapper;
@ -142,18 +143,25 @@ public class NowDataServiceImpl implements NowDataService {
strDate=strDate.substring(0,13)+":00:00"; strDate=strDate.substring(0,13)+":00:00";
try{ try{
if (dataType.equals("tempSet")){ //温度设定 switch (dataType) {
case "tempSet": //温度设定
data.setTempSet(strData); data.setTempSet(strData);
}else if (dataType.equals("waterTemp")){ //水箱水温 break;
case "waterTemp": //水箱水温
data.setWaterTemp(strData); data.setWaterTemp(strData);
}else if (dataType.equals("runState")){ //运行状态 break;
case "runState": //运行状态
data.setRunState(strData); data.setRunState(strData);
}else if (dataType.equals("isFault")){ //是否故障 break;
case "isFault": //是否故障
data.setIsFault(strData); data.setIsFault(strData);
}else if (dataType.equals("levelSet")){ //水位设定 break;
case "levelSet": //水位设定
data.setLevelSet(strData); data.setLevelSet(strData);
}else if (dataType.equals("waterLevel")){//实际水位 break;
case "waterLevel": //实际水位
data.setWaterLevel(strData); data.setWaterLevel(strData);
break;
} }
//从安装表获取设备信息 //从安装表获取设备信息
DeviceInstallEntity deviceInstallEntity=deviceInstallMapper.selectDevice(deviceAddr,deviceType,buildingId); DeviceInstallEntity deviceInstallEntity=deviceInstallMapper.selectDevice(deviceAddr,deviceType,buildingId);
@ -188,15 +196,15 @@ public class NowDataServiceImpl implements NowDataService {
nowDataMapper.saveNowData(data); nowDataMapper.saveNowData(data);
}else { }else {
if (deviceType.equals("压变")) { if (deviceType.equals("压变")) {
String seat=deviceInstallService.selectSeat("压变",deviceAddr,buildingId); String seat=deviceInstallService.selectSeat(deviceType,deviceAddr,buildingId);
log.info("-------楼栋:"+buildingName+",类型:"+deviceType+",地址:"+deviceAddr+",区位:"+seat+",数值:"+strData+"------"); log.info("-------楼栋:"+buildingName+",类型:"+deviceType+",地址:"+deviceAddr+",区位:"+seat+",数值:"+strData+"------");
if (seat!=null){ if (!StringUtils.isBlank(seat)){
nowDataMapper.nowDataWaterLevel(strData,seat,buildingId); nowDataMapper.nowDataWaterLevel(strData,seat,buildingId);
}else{ }else{
nowDataMapper.updateNowData2(data); nowDataMapper.updateNowData2(data);
} }
}else if (deviceType.equals("水位开关")){ }else if (deviceType.equals("水位开关")){
String seat=deviceInstallService.selectSeat("水位开关",deviceAddr,buildingId); String seat=deviceInstallService.selectSeat(deviceType,deviceAddr,buildingId);
log.info("-------楼栋:"+buildingName+",类型:"+deviceType+",地址:"+deviceAddr+",区位:"+seat+",数值:"+strData+"------"); log.info("-------楼栋:"+buildingName+",类型:"+deviceType+",地址:"+deviceAddr+",区位:"+seat+",数值:"+strData+"------");
if (seat!=null){ if (seat!=null){
nowDataMapper.nowDataLevelSet(strData,seat,buildingId); nowDataMapper.nowDataLevelSet(strData,seat,buildingId);
@ -213,17 +221,17 @@ public class NowDataServiceImpl implements NowDataService {
nowDataMapper.saveHistoryData(data); nowDataMapper.saveHistoryData(data);
}else { }else {
if (deviceType.equals("压变")) { if (deviceType.equals("压变")) {
String seat=deviceInstallService.selectSeat("压变",deviceAddr,buildingId); String seat=deviceInstallService.selectSeat(deviceType,deviceAddr,buildingId);
if (seat!=null){ if (!StringUtils.isBlank(seat)){
nowDataMapper.historyDataWaterLevel(strData,seat,buildingId,""); nowDataMapper.historyDataWaterLevel(strData,seat,buildingId,strDate);
log.info("------楼栋:"+buildingName+",历史记录压变区位:"+seat+"------"); log.info("------楼栋:"+buildingName+",历史记录压变区位:"+seat+"------");
}else{ }else{
nowDataMapper.updateHistoryData2(data); nowDataMapper.updateHistoryData2(data);
} }
}else if (deviceType.equals("水位开关")){ }else if (deviceType.equals("水位开关")){
String seat=deviceInstallService.selectSeat("水位开关",deviceAddr,buildingId); String seat=deviceInstallService.selectSeat(deviceType,deviceAddr,buildingId);
if (seat!=null){ if (!StringUtils.isBlank(seat)){
nowDataMapper.historyDataLevelSet(strData,seat,buildingId,""); nowDataMapper.historyDataLevelSet(strData,seat,buildingId,strDate);
log.info("------楼栋:"+buildingName+",历史记录水位开关区位:"+seat+"------"); log.info("------楼栋:"+buildingName+",历史记录水位开关区位:"+seat+"------");
}else{ }else{
nowDataMapper.updateHistoryData2(data); nowDataMapper.updateHistoryData2(data);
@ -246,14 +254,19 @@ public class NowDataServiceImpl implements NowDataService {
strDate=strDate.substring(0,13)+":00:00"; strDate=strDate.substring(0,13)+":00:00";
NowDataEntity data=new NowDataEntity(); NowDataEntity data=new NowDataEntity();
try{ try{
if (dataType.equals("tempSet")){ //温度设定 switch (dataType) {
case "tempSet": //温度设定
data.setTempSet(strData); data.setTempSet(strData);
}else if (dataType.equals("waterTemp")){ //水箱水温 break;
case "waterTemp": //水箱水温
data.setWaterTemp(strData); data.setWaterTemp(strData);
}else if (dataType.equals("runState")){ //运行状态 break;
case "runState": //运行状态
data.setRunState(strData); data.setRunState(strData);
}else if (dataType.equals("isFault")){ //是否故障 break;
case "isFault": //是否故障
data.setIsFault(strData); data.setIsFault(strData);
break;
} }
String buildingName=buildingService.queryBuildingName(buildingId); String buildingName=buildingService.queryBuildingName(buildingId);
//判断实时表是否有记录 //判断实时表是否有记录
@ -297,14 +310,19 @@ public class NowDataServiceImpl implements NowDataService {
}else { }else {
NowDataEntity data2=nowDataMapper.selectHistoryData(strDate,buildingId,pumpId); NowDataEntity data2=nowDataMapper.selectHistoryData(strDate,buildingId,pumpId);
if (data2!=null){ if (data2!=null){
if (dataType.equals("tempSet")){ //温度设定 switch (dataType) {
case "tempSet": //温度设定
data2.setTempSet(strData); data2.setTempSet(strData);
}else if (dataType.equals("waterTemp")){ //水箱水温 break;
case "waterTemp": //水箱水温
data2.setWaterTemp(strData); data2.setWaterTemp(strData);
}else if (dataType.equals("runState")){ //运行状态 break;
case "runState": //运行状态
data2.setRunState(strData); data2.setRunState(strData);
}else if (dataType.equals("isFault")){ //是否故障 break;
case "isFault": //是否故障
data2.setIsFault(strData); data2.setIsFault(strData);
break;
} }
nowDataMapper.updateHistoryData(data2); nowDataMapper.updateHistoryData(data2);
} }

16
user-service/src/test/java/com/mh/user/UserServiceApplicationTests.java

@ -2,15 +2,18 @@ package com.mh.user;
import com.mh.user.entity.DeviceManageEntity; import com.mh.user.entity.DeviceManageEntity;
import com.mh.user.entity.GaugeEntity; import com.mh.user.entity.GaugeEntity;
import com.mh.user.factory.PressureTrans;
import com.mh.user.serialport.SerialPortThread; import com.mh.user.serialport.SerialPortThread;
import com.mh.user.service.DeviceManageService; import com.mh.user.service.DeviceManageService;
import com.mh.user.service.GaugeService; import com.mh.user.service.GaugeService;
import com.mh.user.strategy.PressureTransStrategy;
import com.mh.user.utils.*; import com.mh.user.utils.*;
import org.checkerframework.checker.units.qual.A; import org.checkerframework.checker.units.qual.A;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -108,4 +111,17 @@ class UserServiceApplicationTests {
AnalysisReceiveOrder485 analysisReceiveOrder485 = new AnalysisReceiveOrder485(); AnalysisReceiveOrder485 analysisReceiveOrder485 = new AnalysisReceiveOrder485();
analysisReceiveOrder485.analysisRelayOrder4852("26 03 10 00 00 00 00 00 01 00 01 00 01 00 01 00 00 00 00 FE 86 ".replace(" ", ""), "0018", "远向", "1", "1栋"); analysisReceiveOrder485.analysisRelayOrder4852("26 03 10 00 00 00 00 00 01 00 01 00 01 00 01 00 00 00 00 FE 86 ".replace(" ", ""), "0018", "远向", "1", "1栋");
} }
@Test
public void testPressure() {
PressureTransStrategy.getInstance().analysisReceiveData(
DateUtil.dateToString(new Date(), "yyyy-MM-dd HH:mm:ss"),
"压变",
"49",
"澳升",
"59",
"46栋",
"30030200E105C8"
);
}
} }

Loading…
Cancel
Save