|
|
@ -7,11 +7,13 @@ import com.mh.user.entity.NowPublicDataEntity; |
|
|
|
import com.mh.user.service.BuildingService; |
|
|
|
import com.mh.user.service.BuildingService; |
|
|
|
import com.mh.user.service.NowDataService; |
|
|
|
import com.mh.user.service.NowDataService; |
|
|
|
import com.mh.user.service.NowPublicDataService; |
|
|
|
import com.mh.user.service.NowPublicDataService; |
|
|
|
|
|
|
|
import com.mh.user.utils.DateUtil; |
|
|
|
import com.mh.user.utils.ExchangeStringUtil; |
|
|
|
import com.mh.user.utils.ExchangeStringUtil; |
|
|
|
import com.mh.user.utils.SpringBeanUtil; |
|
|
|
import com.mh.user.utils.SpringBeanUtil; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
@ -75,54 +77,33 @@ public class TempControlStrategy implements DeviceStrategy { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String analysisReceiveData(String dateStr, String deviceType, String registerAddr, String brand, String buildingId, String buildingName, String dataStr) { |
|
|
|
public String analysisReceiveData(String dateStr, String deviceType, String registerAddr, String brand, String buildingId, String buildingName, String dataStr) { |
|
|
|
String result = Constant.FAIL; |
|
|
|
String result = Constant.FAIL; |
|
|
|
String checkStr = dataStr.substring(0, dataStr.length() - 4);// 检验报文
|
|
|
|
String checkStr = dataStr.substring(0, dataStr.length() - 4); |
|
|
|
String checkWord = ExchangeStringUtil.getStrCRC16(checkStr);//生成校验码
|
|
|
|
String checkWord = ExchangeStringUtil.getStrCRC16(checkStr);//生成校验码
|
|
|
|
if (!checkWord.equalsIgnoreCase(dataStr.substring(dataStr.length() - 4))) { |
|
|
|
if (!checkWord.equalsIgnoreCase(dataStr.substring(dataStr.length() - 4))) { |
|
|
|
log.info("温度变送器报文检验失败: " + dataStr); |
|
|
|
log.info("温控报文检验失败: " + dataStr); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
//log.info("温度变送器报文检验成功: " + receiveData);
|
|
|
|
|
|
|
|
String addr = ExchangeStringUtil.hexToDec(checkStr.substring(0, 2));//地址
|
|
|
|
String addr = ExchangeStringUtil.hexToDec(checkStr.substring(0, 2));//地址
|
|
|
|
//log.info("温度变送器:" + addr);
|
|
|
|
|
|
|
|
String data = ""; |
|
|
|
String data = ""; |
|
|
|
if (checkStr.substring(2, 4).equalsIgnoreCase("03")) {// 读
|
|
|
|
if (checkStr.substring(2, 4).equalsIgnoreCase("03")) {// 读
|
|
|
|
Map<String, String> map = new HashMap<>(); |
|
|
|
data = ExchangeStringUtil.hexToDec(checkStr.substring(6, 10)); |
|
|
|
String L1 = checkStr.substring(6, 10); //1路
|
|
|
|
Double fdata = Double.parseDouble(data) / 10; |
|
|
|
map.put("1", String.valueOf(ExchangeStringUtil.parseHex4(L1) / 10)); |
|
|
|
if (fdata <= 25) { |
|
|
|
String L2 = checkStr.substring(10, 14); //2路
|
|
|
|
fdata = 25.0; |
|
|
|
map.put("2", String.valueOf(ExchangeStringUtil.parseHex4(L2) / 10)); |
|
|
|
} else if (fdata >= 65) { |
|
|
|
String L3 = checkStr.substring(14, 18); //3路
|
|
|
|
fdata = 65.0; |
|
|
|
map.put("3", String.valueOf(ExchangeStringUtil.parseHex4(L3) / 10)); |
|
|
|
|
|
|
|
String L4 = checkStr.substring(18, 22); //4路
|
|
|
|
|
|
|
|
map.put("4", String.valueOf(ExchangeStringUtil.parseHex4(L4) / 10)); |
|
|
|
|
|
|
|
String L5 = checkStr.substring(22, 26); //5路
|
|
|
|
|
|
|
|
map.put("5", String.valueOf(ExchangeStringUtil.parseHex4(L5) / 10)); |
|
|
|
|
|
|
|
String L6 = checkStr.substring(26, 30); //6路
|
|
|
|
|
|
|
|
map.put("6", String.valueOf(ExchangeStringUtil.parseHex4(L6) / 10)); |
|
|
|
|
|
|
|
String L7 = checkStr.substring(30, 34); //7路
|
|
|
|
|
|
|
|
map.put("7", String.valueOf(ExchangeStringUtil.parseHex4(L7) / 10)); |
|
|
|
|
|
|
|
String L8 = checkStr.substring(34, 38); //8路
|
|
|
|
|
|
|
|
map.put("8", String.valueOf(ExchangeStringUtil.parseHex4(L8) / 10)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int count = buildingService.selectPumpCount(buildingId); //楼栋热泵数
|
|
|
|
|
|
|
|
if (count > 0) { |
|
|
|
|
|
|
|
for (Map.Entry<String, String> entry : map.entrySet()) { |
|
|
|
|
|
|
|
addr = entry.getKey(); |
|
|
|
|
|
|
|
data = entry.getValue(); |
|
|
|
|
|
|
|
if (addr != null && Integer.parseInt(addr) <= count) { |
|
|
|
|
|
|
|
nowDataService.saveNowHistoryData3(addr, "温度变送器", data, "waterTemp", buildingId); |
|
|
|
|
|
|
|
nowDataService.proWaterTemp(dateStr, buildingId, addr); //保存时间点温度
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
log.info("温度变送器:" + addr + ",保存数据库成功!楼栋名称:" + buildingName); |
|
|
|
nowDataService.saveNowHistoryData2(addr, "温控", String.valueOf(fdata), "waterTemp", buildingId); |
|
|
|
|
|
|
|
nowDataService.proWaterTemp(dateStr, buildingId, "");//保存时间点温度
|
|
|
|
String avgTemp = nowDataService.selectAve(buildingId); |
|
|
|
String avgTemp = nowDataService.selectAve(buildingId); |
|
|
|
NowPublicDataEntity publicData = new NowPublicDataEntity(); |
|
|
|
NowPublicDataEntity publicData = new NowPublicDataEntity(); |
|
|
|
publicData.setBuildingId(buildingId); |
|
|
|
publicData.setBuildingId(buildingId); |
|
|
|
publicData.setUseWaterTemp(avgTemp); |
|
|
|
publicData.setUseWaterTemp(avgTemp); |
|
|
|
publicData.setBackWaterTemp(avgTemp); |
|
|
|
publicData.setBackWaterTemp(avgTemp); |
|
|
|
|
|
|
|
publicData.setSingleTemp(String.valueOf(fdata));//单箱温度
|
|
|
|
nowPublicDataService.saveNowHistoryPublicData(publicData); |
|
|
|
nowPublicDataService.saveNowHistoryPublicData(publicData); |
|
|
|
result = JSON.toJSONString(map); //map转json字符串
|
|
|
|
log.info("温控号:" + addr + ",温度值:" + fdata + ",保存数据库成功!楼栋名称:" + buildingName); |
|
|
|
} |
|
|
|
return String.valueOf(fdata); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|