|
@@ -1,16 +1,20 @@
|
|
package com.huimv.admin.server;
|
|
package com.huimv.admin.server;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.huimv.admin.entity.ProtData;
|
|
|
|
+import com.huimv.admin.mapper.ProtDataMapper;
|
|
import io.netty.buffer.ByteBuf;
|
|
import io.netty.buffer.ByteBuf;
|
|
import io.netty.channel.ChannelHandler;
|
|
import io.netty.channel.ChannelHandler;
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
|
import io.netty.util.CharsetUtil;
|
|
import io.netty.util.CharsetUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
|
|
+import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
@@ -30,6 +34,8 @@ import java.util.regex.Pattern;
|
|
@Slf4j
|
|
@Slf4j
|
|
public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
private StringBuilder askTextSb = null;
|
|
private StringBuilder askTextSb = null;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProtDataMapper protDataMapper;
|
|
|
|
|
|
//
|
|
//
|
|
public void appendClientAsk(String text) {
|
|
public void appendClientAsk(String text) {
|
|
@@ -82,9 +88,54 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
private void handleClientAskCmd(String clientAskText, ChannelHandlerContext ctx) throws ParseException, IOException {
|
|
private void handleClientAskCmd(String clientAskText, ChannelHandlerContext ctx) throws ParseException, IOException {
|
|
|
|
|
|
System.out.println("接收到消息: " + clientAskText + " 时间: " + System.currentTimeMillis());
|
|
System.out.println("接收到消息: " + clientAskText + " 时间: " + System.currentTimeMillis());
|
|
|
|
+ EnvironmentalData parse = HJ212Parser.parse(clientAskText.replace("##", ""));
|
|
|
|
+ ProtData protData = new ProtData();
|
|
|
|
+ protData.setPh(parse.getCpData().getParameters().get("w01001").getAvg());
|
|
|
|
+ protData.setOther1(parse.getCpData().getParameters().get("w01010").getAvg());
|
|
|
|
+ protData.setCod(parse.getCpData().getParameters().get("w01018").getAvg());
|
|
|
|
+ protData.setNh3n(parse.getCpData().getParameters().get("w21003").getAvg());
|
|
|
|
+ protData.setOther2(parse.getCpData().getParameters().get("w00000").getAvg());
|
|
|
|
+ protData.setLoctionType(1);
|
|
|
|
+ String mn = parse.getHeader().getMn();
|
|
|
|
+ if ("01523162079470".equals(mn)){
|
|
|
|
+ protData.setFarmId(30);
|
|
|
|
+ }else {
|
|
|
|
+ protData.setFarmId(28);
|
|
|
|
+ }
|
|
|
|
+ protData.setOther3(clientAskText);
|
|
|
|
+ protData.setCreateDate(new Date());
|
|
|
|
|
|
|
|
+ protDataMapper.insert(protData);
|
|
askTextSb.delete(0, askTextSb.length());
|
|
askTextSb.delete(0, askTextSb.length());
|
|
}
|
|
}
|
|
|
|
+ //QN 20250412142007184 请求编号(21位时间戳:2025-04-12 14:20:07.184)
|
|
|
|
+ //ST 32 系统类型(32表示污水处理设施)
|
|
|
|
+ //CN 2051 命令编号(2051表示实时数据上报)
|
|
|
|
+ //PW 123456 密码(默认密码)
|
|
|
|
+ //MN 01523162079470 设备唯一标识(015为厂商代码,后续为设备编号)
|
|
|
|
+ //Flag 4 数据包标志位(4表示数据需要应答)
|
|
|
|
+ //w01001 pH值 - 水质酸碱度指标
|
|
|
|
+ //w01010 水温 ℃ 水体温度
|
|
|
|
+ //w01018 溶解氧 mg/L 水体中氧气含量
|
|
|
|
+ //w21003 总磷 mg/L 水体富营养化指标
|
|
|
|
+ //w00000 自定义/扩展参数 - 需结合具体设备文档确认含义
|
|
|
|
+ //Min:周期内最小值
|
|
|
|
+ //Max:周期内最大值
|
|
|
|
+ //Avg:周期内平均值
|
|
|
|
+ //Cou:累计值(如流量累计)
|
|
|
|
+
|
|
|
|
+// public static void main(String[] args) {
|
|
|
|
+// String rawData = "##QN=20250412142007184;ST=32;CN=2051;PW=123456;MN=01523162079470;Flag=4;" +
|
|
|
|
+// "CP=&&DataTime=20250412141900;w01018-Min=78.9,w01018-Max=78.9,w01018-Avg=78.9," +
|
|
|
|
+// "w01018-Cou=0.026,w01018-Flag=N;w00000-Min=5.497,w00000-Max=5.728,w00000-Avg=5.597," +
|
|
|
|
+// "w00000-Cou=0.336,w00000-Flag=N;w01001-Min=7.33,w01001-Max=7.34,w01001-Avg=7.336," +
|
|
|
|
+// "w01001-Flag=N;w01010-Min=23,w01010-Max=23,w01010-Avg=23,w01010-Flag=N;" +
|
|
|
|
+// "w21003-Min=0.455,w21003-Max=0.455,w21003-Avg=0.455,w21003-Cou=0,w21003-Flag=N&&7200";
|
|
|
|
+//
|
|
|
|
+// EnvironmentalData data = HJ212Parser.parse(rawData.replace("##",""));
|
|
|
|
+// System.out.println("DataTime: " + data.getCpData().getDataTime());
|
|
|
|
+// System.out.println("pH值: " + data.getCpData().getParameters().get("w01001").getAvg());
|
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Method : askCmdActuator
|
|
* @Method : askCmdActuator
|