diff --git a/pom.xml b/pom.xml index ef44f4f43..c09f7af58 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,16 @@ + + + rk.netDevice.sdk + p2 + + system + 2.2.7 + + ${project.basedir}/src/main/resources/lib/netdevice/NetDeviceSDKP2_V2_2_7.jar + javax.json.bind javax.json.bind-api diff --git a/src/main/java/com/zhgd/xmgl/config/AsyncConfig.java b/src/main/java/com/zhgd/xmgl/config/AsyncConfig.java index 59f45d2b2..6cec1cb73 100644 --- a/src/main/java/com/zhgd/xmgl/config/AsyncConfig.java +++ b/src/main/java/com/zhgd/xmgl/config/AsyncConfig.java @@ -71,9 +71,9 @@ public class AsyncConfig { public ThreadPoolTaskExecutor doubleCarbonExecutor() { MdcThreadPoolTaskExecutor executor = new MdcThreadPoolTaskExecutor(); /** 核心线程数(默认线程数) */ - executor.setCorePoolSize(corePoolSize); + executor.setCorePoolSize(corePoolSize * 9); /** 最大线程数 */ - executor.setMaxPoolSize(maxPoolSize); + executor.setMaxPoolSize(maxPoolSize * 9); executor.setQueueCapacity(queueCapacity); /** 允许线程空闲时间(单位:默认为秒) */ executor.setKeepAliveSeconds(60); diff --git a/src/main/java/com/zhgd/xmgl/modules/environment/service/impl/DustNoiseDataServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/environment/service/impl/DustNoiseDataServiceImpl.java index eac8fe5ae..b4c6543d6 100644 --- a/src/main/java/com/zhgd/xmgl/modules/environment/service/impl/DustNoiseDataServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/environment/service/impl/DustNoiseDataServiceImpl.java @@ -1,5 +1,7 @@ package com.zhgd.xmgl.modules.environment.service.impl; +import cn.hutool.core.bean.BeanUtil; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -18,14 +20,21 @@ import com.zhgd.xmgl.modules.environment.service.IEnvironmentAlarmService; import com.zhgd.xmgl.util.DateUtils; import com.zhgd.xmgl.util.MessageUtil; import com.zhgd.xmgl.util.WindDirectionUtils; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Service; +import rk.netDevice.sdk.p2.*; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.function.Function; import java.util.stream.Collectors; @@ -35,8 +44,9 @@ import java.util.stream.Collectors; * @date: 2020-09-27 * @version: V1.0 */ +@Slf4j @Service -public class DustNoiseDataServiceImpl extends ServiceImpl implements IDustNoiseDataService { +public class DustNoiseDataServiceImpl extends ServiceImpl implements IDustNoiseDataService, CommandLineRunner { @Autowired private DustNoiseDataMapper dustNoiseDataMapper; @Autowired @@ -47,7 +57,35 @@ public class DustNoiseDataServiceImpl extends ServiceImpl selectDustNoiseData(Map map) { @@ -134,7 +172,6 @@ public class DustNoiseDataServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); @@ -210,4 +247,228 @@ public class DustNoiseDataServiceImpl extends ServiceImpl { + try { + rzckStartHj212(); + } catch (InterruptedException e) { + log.error("仁智测控转发扬尘错误:", e); + } + }, threadPoolTaskExecutor); + } + + /** + * 仁智测控转发扬尘 + */ + private void rzckStartHj212() throws InterruptedException { + RSServer rsServer = RSServer.Initiate(rengzhicekongHj212Port);// 初始化 + rsServer.addDataListener(new IDataListener() {// 添加监听 + @Override + public void receiveTimmingAck(TimmingAck data) {// 校时指令应答处理 + log.info("校时应答->设备编号:" + data.getDeviceId() + + "\t执行结果:" + data.getStatus()); + } + + @Override + public void receiveTelecontrolAck(TelecontrolAck data) {// 遥控指令应答处理 + log.info("遥控应答->设备编号:" + data.getDeviceId() + + "\t继电器编号:" + data.getRelayId() + "\t执行结果:" + + data.getStatus()); + } + + @Override + public void receiveStoreData(StoreData data) {// 已存储数据接收处理 + // 遍历节点数据。数据包括网络设备的数据以及各个节点数据。温湿度数据存放在节点数据中 + for (NodeData nd : data.getNodeList()) { + SimpleDateFormat sdf = new SimpleDateFormat( + "yy-MM-dd HH:mm:ss"); + String str = sdf.format(nd.getRecordTime()); + log.info("存储数据->设备地址:" + data.getDeviceId() + + "\t节点:" + nd.getNodeId() + "\t温度:" + nd.getTem() + + "\t湿度:" + nd.getHum() + "\t存储时间:" + str); + } + + } + + @Override + public void receiveRealtimeData(RealTimeData data) {// 实时数据接收处理 + JSONObject joData = new JSONObject(); + // 遍历节点数据。数据包括网络设备的数据以及各个节点数据。温湿度数据存放在节点数据中 + for (NodeData nd : data.getNodeList()) { + int deviceId = data.getDeviceId(); + int nodeId = nd.getNodeId(); + float tem = nd.getTem(); + float hum = nd.getHum(); + String printData = "实时数据->设备地址:" + deviceId + + "\t节点:" + nodeId + "\t温度:" + tem + + "\t湿度:" + hum + "\t经度:" + data.getLng() + + "\t纬度:" + data.getLat() + "\t坐标类型:" + + data.getCoordinateType() + "\t继电器状态:" + + data.getRelayStatus(); + log.info(printData); + /* + { + "deviceId": "", + "humidity": 0, + "humidityAlarmType": 0, + "noise": 0, + "noiseAlarmType": 0, + "plateHumidity": 0, + "plateTemperature": 0, + "pm10": 0, + "pm10AlarmType": 0, + "pm25": 0, + "pm25AlarmType": 0, + "pressure": 0, + "temperature": 0, + "temperatureAlarmType": 0, + "tsp": 0, + "tspAlarmType": 0, + "voltage": 0, + "windSpeedAlarmType": 0, + "winddirection": "", + "winddirectionName": "", + "windspeed": 0 + } + */ + /* + 节点1 + 温度=PM10,数值*10使用,单位 ug/m3 + 湿度=PM2.5,数值*10使用,单位 ug/m3 + + 节点2 + 湿度=噪声,数值直接用,单位 dB + + 节点3 + 温度,数值直接用,单位 ℃ + 湿度,数值直接用,单位 %RH + + 节点4 + 温度=风力,数值*10使用,单位 级 + 湿度=风速,数值直接用,单位 m/s + + 节点5 + 温度=风向,数值*10使用,0-7代表8方位, + + 节点7 + 湿度=tsp,数值*10使用,单位 ug/m3 + + 节点8 + 湿度=大气压,数值直接用,单位 Kpa + + 风向对照关系 + 0 北风 + 1 东北风 + 2 东风 + 3 东南风 + 4 南风 + 5 西南风 + 6 西风 + 7 西北风 + */ + if (nodeId == 1) { + joData.put("pm10", tem * 10); + joData.put("pm25", hum * 10); + joData.put("pm10AlarmType", 1); + joData.put("pm25AlarmType", 1); + } else if (nodeId == 2) { + joData.put("noise", hum); + joData.put("noiseAlarmType", 1); + } else if (nodeId == 3) { + joData.put("temperature", tem); + joData.put("humidity", hum); + joData.put("temperatureAlarmType", 1); + joData.put("humidityAlarmType", 1); + } else if (nodeId == 4) { + joData.put("windspeed", hum); + joData.put("windSpeedAlarmType", 1); + } else if (nodeId == 5) { + joData.put("winddirection", getWinddirection(tem)); + } else if (nodeId == 7) { + joData.put("tsp", hum * 10); + joData.put("tspAlarmType", 1); + } else if (nodeId == 8) { + joData.put("pressure", hum); + } + joData.put("deviceId", deviceId); +// joData.put("plateHumidity", 0); +// joData.put("plateTemperature", 0); +// joData.put("voltage", 0); + } + saveDustData(joData); + } + + @Override + public void receiveLoginData(LoginData data) {// 登录数据接收处理 + log.info("登录->设备地址:" + data.getDeviceId()); + + } + + @Override + public void receiveParamIds(ParamIdsData data) { + String str = "设备参数编号列表->设备编号:" + data.getDeviceId() + + "\t参数总数量:" + data.getTotalCount() + "\t本帧参数数量:" + + data.getCount() + "\r\n"; + for (int paramId : data.getPararmIdList())// 遍历设备中参数id编号 + { + str += paramId + ","; + } + log.info(str); + + } + + @Override + public void receiveParam(ParamData data) { + String str = "设备参数->设备编号:" + data.getDeviceId() + "\r\n"; + + for (ParamItem pararm : data.getParameterList()) { + str += "参数编号:" + + pararm.getParamId() + + "\t参数描述:" + + pararm.getDescription() + + "\t参数值:" + + (pararm.getValueDescription() == null ? pararm + .getValue() : pararm.getValueDescription() + .get(pararm.getValue())) + "\r\n"; + } + log.info(str); + + } + + @Override + public void receiveWriteParamAck(WriteParamAck data) { + String str = "下载设备参数->设备编号:" + data.getDeviceId() + "\t参数数量:" + + data.getCount() + "\t" + + (data.isSuccess() ? "下载成功" : "下载失败"); + log.info(str); + + } + + @Override + public void receiveTransDataAck(TransDataAck data) { + String str = "数据透传->设备编号:" + data.getDeviceId() + "\t响应结果:" + + data.getData() + "\r\n字节数:" + data.getTransDataLen(); + log.info(str); + + } + + @Override + public void receiveHeartbeatData(HeartbeatData heartbeatData) { + + } + }); + rsServer.start(); + } + + private void saveDustData(JSONObject joData) { + String json = joData.toJSONString(); + log.info("仁智测控转发扬尘:{}", json); + try { + this.saveDustNoiseData(BeanUtil.toBean(joData, DustNoiseData.class)); + } catch (Exception e) { + log.error("仁智测控转发扬尘错误:", e); + } + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index d6977110f..f7907d6e5 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -216,3 +216,5 @@ tenant.tables[9]=wflow_sub_groups tenant.tables[10]=wflow_sub_process sada.host=http://api.e.v1.i-sada.net +# 仁智测控的扬尘上传端口 +rengzhicekong.hj212.port=24041 diff --git a/src/main/resources/lib/netdevice/NetDeviceSDKP2_V2_2_7.jar b/src/main/resources/lib/netdevice/NetDeviceSDKP2_V2_2_7.jar new file mode 100644 index 000000000..3131ec01c Binary files /dev/null and b/src/main/resources/lib/netdevice/NetDeviceSDKP2_V2_2_7.jar differ diff --git a/src/main/resources/lib/netdevice/param.dat b/src/main/resources/lib/netdevice/param.dat new file mode 100644 index 000000000..9cd5505ba Binary files /dev/null and b/src/main/resources/lib/netdevice/param.dat differ