|
@@ -2,18 +2,17 @@ package com.jiayue.biz.conf;
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.thread.ThreadFactoryBuilder;
|
|
|
+import com.jiayue.biz.domain.EnvironmentalData;
|
|
|
import com.jiayue.biz.domain.PointAttribute;
|
|
|
import com.jiayue.biz.domain.TunnelInfo;
|
|
|
+import com.jiayue.biz.domain.WeatherLook;
|
|
|
+import com.jiayue.biz.service.EnvironmentalDataService;
|
|
|
import com.jiayue.biz.service.PointAttributeService;
|
|
|
import com.jiayue.biz.service.TunnelInfoService;
|
|
|
-import com.jiayue.biz.service.impl.PointAttributeServiceImpl;
|
|
|
-import com.jiayue.biz.util.CalculationUtil;
|
|
|
-import com.jiayue.common.annotation.Log;
|
|
|
+import com.jiayue.biz.service.WeatherLookService;
|
|
|
import com.jiayue.common.utils.DateUtil;
|
|
|
-import io.netty.channel.ChannelFuture;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
@@ -27,6 +26,7 @@ import wei.yigulu.modbus.netty.ModbusTcpMasterBuilder;
|
|
|
import wei.yigulu.modbus.utils.ModbusRequestDataUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.sql.Timestamp;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.SynchronousQueue;
|
|
@@ -34,7 +34,7 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-//@Configuration
|
|
|
+@Configuration
|
|
|
@AllArgsConstructor
|
|
|
@Slf4j
|
|
|
public class Channel {
|
|
@@ -44,6 +44,10 @@ public class Channel {
|
|
|
private final
|
|
|
PointAttributeService pointAttributeService;
|
|
|
|
|
|
+ private final WeatherLookService weatherLookService;
|
|
|
+
|
|
|
+ private final EnvironmentalDataService environmentalDataService;
|
|
|
+
|
|
|
|
|
|
private final ExecutorService calculatorThread = new ThreadPoolExecutor(15, 1000,
|
|
|
60L, TimeUnit.SECONDS, new SynchronousQueue<>(), new ThreadFactoryBuilder().setNamePrefix("MyRecurringTaskThread-").build());
|
|
@@ -51,29 +55,18 @@ public class Channel {
|
|
|
|
|
|
private HashMap<String, ModbusTcpMasterBuilder> masterMap;
|
|
|
|
|
|
+ private List<EnvironmentalData> environmentalDataList;
|
|
|
+
|
|
|
+
|
|
|
+ //获取数据
|
|
|
+ public List<EnvironmentalData> getEnvironmentalDataList() {
|
|
|
+ return this.environmentalDataList;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
-// @Bean
|
|
|
+ @Bean
|
|
|
public void timingTunnel() {
|
|
|
List<TunnelInfo> tunnelInfoList = tunnelInfoService.list();
|
|
|
- tunnelInfoList.clear();
|
|
|
- TunnelInfo tunnelInfo1 = new TunnelInfo();
|
|
|
- TunnelInfo tunnelInfo2 = new TunnelInfo();
|
|
|
- tunnelInfo1.setDataFormat("CDAB");
|
|
|
-// tunnelInfo1.setIp("192.168.10.75");
|
|
|
- tunnelInfo1.setIp("192.168.1.206");
|
|
|
- tunnelInfo1.setPort(502);
|
|
|
- tunnelInfo1.setStationId("七台河3005");
|
|
|
- tunnelInfo1.setEquipmentNo("3005");
|
|
|
-// tunnelInfo1.setStationId("虎林15244");
|
|
|
-// tunnelInfo1.setEquipmentNo("15244");
|
|
|
-
|
|
|
- tunnelInfo2.setDataFormat("CDAB");
|
|
|
- tunnelInfo2.setIp("192.168.10.75");
|
|
|
- tunnelInfo2.setPort(502);
|
|
|
- tunnelInfo2.setStationId("虎林15244");
|
|
|
- tunnelInfo2.setEquipmentNo("15244");
|
|
|
- tunnelInfoList.add(tunnelInfo1);
|
|
|
- tunnelInfoList.add(tunnelInfo2);
|
|
|
for (TunnelInfo tunnelInfo : tunnelInfoList) {
|
|
|
ModbusTcpMasterBuilder master = start(tunnelInfo);
|
|
|
masterMap.put(tunnelInfo.getStationId(), master);
|
|
@@ -101,18 +94,15 @@ public class Channel {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// @Scheduled(cron = "0 0/5 * * * ? ")
|
|
|
+ @Scheduled(cron = "0 0/10 * * * ? ")
|
|
|
+// @Scheduled(fixedDelay = 60000)
|
|
|
public void tunnel() {
|
|
|
List<TunnelInfo> tunnelInfoList = tunnelInfoService.list();
|
|
|
List<PointAttribute> attributeList = pointAttributeService.list();
|
|
|
- String time = DateUtil.format(DateUtil.date(), "yyyy-MM-dd HH:mm");
|
|
|
+ DateTime dateTime = DateUtil.beginOfMinute(new Date());
|
|
|
for (Map.Entry<String, ModbusTcpMasterBuilder> masterBuilderEntry : masterMap.entrySet()) {
|
|
|
//获取通道map中的key
|
|
|
String stationId = masterBuilderEntry.getKey();
|
|
|
- //风速层高
|
|
|
- HashSet<Integer> wsHeightSet = new HashSet<>();
|
|
|
- //风向层高
|
|
|
- HashSet<Integer> wdHeightSet = new HashSet<>();
|
|
|
//根据通道key获取ip端口号等数据
|
|
|
List<TunnelInfo> tunnelist = tunnelInfoList.stream().filter(t -> t.getStationId().equals(stationId)).collect(Collectors.toList());
|
|
|
TunnelInfo tunnelInfo;
|
|
@@ -136,36 +126,13 @@ public class Channel {
|
|
|
//获取连接
|
|
|
ModbusTcpMasterBuilder master = masterBuilderEntry.getValue();
|
|
|
//获取点位信息map
|
|
|
- Map<String, Integer> stringStringBuilderMap = savePoints(pointAttributeList, wsHeightSet, wdHeightSet);
|
|
|
-// WindTowerInfo windTowerInfo = new WindTowerInfo();
|
|
|
- //判断是否存在此塔
|
|
|
-// boolean emptyOfEntity = windTowerInfoService.lambdaQuery().eq(WindTowerInfo::getEquipmentNo, tunnelInfo.getEquipmentNo()).list().isEmpty();
|
|
|
-// if (emptyOfEntity) {
|
|
|
-// StringBuilder wsHeightStr = new StringBuilder();
|
|
|
-// for (Integer height : wsHeightSet) {
|
|
|
-// wsHeightStr = wsHeightStr.append(height + ",");
|
|
|
-// }
|
|
|
-// String wsHeight = null;
|
|
|
-// if (wsHeightStr.length() > 0) {
|
|
|
-// wsHeight = wsHeightStr.substring(0, wsHeightStr.length() - 1);
|
|
|
-// }
|
|
|
-//
|
|
|
-// StringBuilder wdHeightStr = new StringBuilder();
|
|
|
-// for (Integer height : wsHeightSet) {
|
|
|
-// wdHeightStr = wdHeightStr.append(height + ",");
|
|
|
-// }
|
|
|
-// String wdHeight = null;
|
|
|
-// if (wdHeightStr.length() > 0) {
|
|
|
-// wdHeight = wdHeightStr.substring(0, wdHeightStr.length() - 1);
|
|
|
-// }
|
|
|
-// //存储测风塔信息
|
|
|
-// windTowerInfo.setEquipmentNo(tunnelist.get(0).getEquipmentNo());
|
|
|
-// windTowerInfo.setName(tunnelist.get(0).getStationId());
|
|
|
-// windTowerInfo.setHeights(wsHeight);
|
|
|
-// windTowerInfo.setWdHeights(wdHeight);
|
|
|
-// windTowerInfo.setType("2");
|
|
|
-// windTowerInfoService.save(windTowerInfo);
|
|
|
-// }
|
|
|
+ Map<String, Integer> stringStringBuilderMap = savePoints(pointAttributeList);
|
|
|
+// 判断是否存在此塔
|
|
|
+ List<WeatherLook> weatherLookList = weatherLookService.lambdaQuery().eq(WeatherLook::getWeatherLookNo, tunnelInfo.getWeatherLookNo()).list();
|
|
|
+ if (weatherLookList.isEmpty()) {
|
|
|
+ log.info("此环境监测仪不存在");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
// 例如: key:wsAve val:数据
|
|
|
HashMap<String, BigDecimal> pointMap = new HashMap<>();
|
|
|
//分解成Obj4RequestCoil
|
|
@@ -174,13 +141,13 @@ public class Channel {
|
|
|
obj4RequestRegisters = ModbusRequestDataUtils.splitModbusRequest(pointTypeMap, 1, FunctionCode.READ_HOLDING_REGISTERS);
|
|
|
for (Obj4RequestRegister obj4RequestRegister : obj4RequestRegisters) {
|
|
|
Map<Integer, IModbusDataType> registerData = ModbusRequestDataUtils.getRegisterData(master, obj4RequestRegister);
|
|
|
- if(!registerData.isEmpty()){
|
|
|
+ if (!registerData.isEmpty()) {
|
|
|
for (Map.Entry<Integer, IModbusDataType> typeEntry : registerData.entrySet()) {
|
|
|
for (Map.Entry<String, Integer> entry : stringStringBuilderMap.entrySet()) {
|
|
|
if (typeEntry.getKey().equals(entry.getValue())) {
|
|
|
- log.info("点位:{}-----数值:{}",typeEntry.getKey(),((NumericModbusData) typeEntry.getValue()).getValue());
|
|
|
+ log.info("点位:{}-----数值:{}", typeEntry.getKey(), multiplying(((NumericModbusData) typeEntry.getValue()).getValue(), pointAttributeList, typeEntry.getKey()));
|
|
|
//点位一致 置换value
|
|
|
- pointMap.put(entry.getKey(), ((NumericModbusData) typeEntry.getValue()).getValue());
|
|
|
+ pointMap.put(entry.getKey(), multiplying(((NumericModbusData) typeEntry.getValue()).getValue(), pointAttributeList, typeEntry.getKey()));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -191,44 +158,49 @@ public class Channel {
|
|
|
log.info(e.getMsg());
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
- wsHeightSet.addAll(wdHeightSet);
|
|
|
-// windTowerDataParentTableService.saveDataForTunnel(pointMap, wsHeightSet,tunnelInfo.getEquipmentNo(),time);
|
|
|
+ environmentalDataService.insertOne(packageData(weatherLookList.get(0).getWeatherLookNo(), pointMap,dateTime));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //倍率转换
|
|
|
+ public BigDecimal multiplying(BigDecimal num, List<PointAttribute> pointAttributeList, Integer point) {
|
|
|
+
|
|
|
+ List<PointAttribute> pointAttributes = pointAttributeList.stream().filter(p -> Objects.equals(p.getPoint(), point)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return num.multiply(BigDecimal.valueOf(pointAttributes.get(0).getMultiplying()));
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public EnvironmentalData packageData(String weatherNo, HashMap<String, BigDecimal> pointMap,DateTime dateTime) {
|
|
|
+ EnvironmentalData environmentalData = new EnvironmentalData();
|
|
|
+ environmentalData.setTs(new Timestamp(dateTime.getTime()));
|
|
|
+ environmentalData.setWeatherLookNo(weatherNo);
|
|
|
+ environmentalData.setWs(pointMap.get("ws").floatValue());
|
|
|
+ environmentalData.setWd(pointMap.get("wd").floatValue());
|
|
|
+ environmentalData.setT(pointMap.get("t").floatValue());
|
|
|
+ environmentalData.setRh(pointMap.get("rh").floatValue());
|
|
|
+ environmentalData.setPa(pointMap.get("pa").floatValue());
|
|
|
+ return environmentalData;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//获取点表所对应数据
|
|
|
- public Map<String, Integer> savePoints(List<PointAttribute> channelPoints, HashSet<Integer> wsHeightSet, HashSet<Integer> wdHeightSet) {
|
|
|
+ public Map<String, Integer> savePoints(List<PointAttribute> channelPoints) {
|
|
|
//如果数据库没有此测风塔 读取点表信息增加塔表
|
|
|
HashMap<String, Integer> dataMap = new HashMap<>();
|
|
|
for (PointAttribute channelPoint : channelPoints) {
|
|
|
- if(channelPoint.getUnit() == null){
|
|
|
- channelPoint.setUnit("");
|
|
|
- }
|
|
|
- if ((channelPoint.getUnit().equals("y") || channelPoint.getUnit().equals("Y")) && channelPoint.getMeaning().contains("年")) {
|
|
|
- dataMap.put("yyyy", channelPoint.getPoint());
|
|
|
- } else if ((channelPoint.getUnit().equals("y") || channelPoint.getMeaning().equals("Y")) && channelPoint.getMeaning().contains("月")) {
|
|
|
- dataMap.put("MM", channelPoint.getPoint());
|
|
|
- } else if (channelPoint.getUnit().equals("d") && channelPoint.getMeaning().contains("日")) {
|
|
|
- dataMap.put("dd", channelPoint.getPoint());
|
|
|
- } else if (channelPoint.getUnit().equals("h") && channelPoint.getMeaning().contains("时")) {
|
|
|
- dataMap.put("HH", channelPoint.getPoint());
|
|
|
- } else if (channelPoint.getUnit().equals("m") && channelPoint.getMeaning().contains("分")) {
|
|
|
- dataMap.put("mm", channelPoint.getPoint());
|
|
|
- } else if (channelPoint.getMeaning().contains("纬")) {
|
|
|
- dataMap.put("latitude", channelPoint.getPoint());
|
|
|
- } else if (channelPoint.getMeaning().contains("经")) {
|
|
|
- dataMap.put("longitude", channelPoint.getPoint());
|
|
|
- } else if (channelPoint.getMeaning().contains("海拔")) {
|
|
|
- dataMap.put("elevation", channelPoint.getPoint());
|
|
|
- } else if (channelPoint.getMeaning().contains("电压")) {
|
|
|
- String status = status(channelPoint.getMeaning());
|
|
|
- dataMap.put("v" + status, channelPoint.getPoint());
|
|
|
- } else {
|
|
|
- String dataType = dataType(channelPoint.getMeaning(), wsHeightSet, wdHeightSet);
|
|
|
- if (!dataType.equals("")) {
|
|
|
- dataMap.put(dataType, channelPoint.getPoint());
|
|
|
- }
|
|
|
+ if (channelPoint.getMeaning().contains("风速")) {
|
|
|
+ dataMap.put("ws", channelPoint.getPoint());
|
|
|
+ } else if (channelPoint.getMeaning().contains("风向")) {
|
|
|
+ dataMap.put("wd", channelPoint.getPoint());
|
|
|
+ } else if (channelPoint.getMeaning().contains("温度")) {
|
|
|
+ dataMap.put("t", channelPoint.getPoint());
|
|
|
+ } else if (channelPoint.getMeaning().contains("湿度")) {
|
|
|
+ dataMap.put("rh", channelPoint.getPoint());
|
|
|
+ } else if (channelPoint.getMeaning().contains("气压")) {
|
|
|
+ dataMap.put("pa", channelPoint.getPoint());
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -236,65 +208,4 @@ public class Channel {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public String dataType(String str, HashSet<Integer> wsHeightSet, HashSet<Integer> wdHeightSet) {
|
|
|
- String typeStr = "";
|
|
|
- int index;
|
|
|
- if (!str.contains("米") && !str.contains("m")) {
|
|
|
- return "";
|
|
|
- }
|
|
|
- if (str.contains("米")) {
|
|
|
- index = str.indexOf("米");
|
|
|
- } else {
|
|
|
- index = str.indexOf("m");
|
|
|
- }
|
|
|
- //截取风速
|
|
|
- String dataStr = str.substring(0, index);
|
|
|
- Integer height = Integer.valueOf(CalculationUtil.getNumberFromString(dataStr));
|
|
|
- String dataType = "";
|
|
|
- typeStr = status(str);
|
|
|
-
|
|
|
- if (str.contains("风速") && !str.contains("风向")) {
|
|
|
- dataType = "ws";
|
|
|
- wsHeightSet.add(height);
|
|
|
- } else if (str.contains("风向")) {
|
|
|
- dataType = "wd";
|
|
|
- wdHeightSet.add(height);
|
|
|
- } else if (str.contains("湿度")) {
|
|
|
- dataType = "rh";
|
|
|
- return dataType + typeStr;
|
|
|
- } else if (str.contains("温度")) {
|
|
|
- dataType = "t";
|
|
|
- return dataType + typeStr;
|
|
|
- } else if (str.contains("气压") || str.contains("压力")) {
|
|
|
- dataType = "pa";
|
|
|
- return dataType + typeStr;
|
|
|
- }
|
|
|
- return dataType + typeStr + height;
|
|
|
- }
|
|
|
-
|
|
|
- public String status(String str) {
|
|
|
- String typeStr = "";
|
|
|
- if (str.contains("平均值") && !str.contains("G")) {
|
|
|
- typeStr = "Ave";
|
|
|
- } else if (str.contains("方差") || str.contains("标准偏差") || str.contains("标准差")) {
|
|
|
- typeStr = "Sta";
|
|
|
- } else if (str.contains("最大值") && !str.contains("极大")) {
|
|
|
- typeStr = "Max";
|
|
|
- } else if (str.contains("最小值")) {
|
|
|
- typeStr = "Min";
|
|
|
- } else if (str.contains("瞬时")) {
|
|
|
- typeStr = "Inst";
|
|
|
- } else if (str.contains("极大")) {
|
|
|
- typeStr = "Great";
|
|
|
- } else if (str.contains("Gust") || str.contains("GUST")) {
|
|
|
- typeStr = "Gust";
|
|
|
- } else if (str.contains("风速") && str.contains("风向")) {
|
|
|
- typeStr = "OnWs";
|
|
|
- } else if (str.contains("实时")) {
|
|
|
- typeStr = "Now";
|
|
|
- }
|
|
|
- return typeStr;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
}
|