新增模拟数据方法

This commit is contained in:
wanggeng 2021-08-06 18:02:25 +08:00
parent b9e3f6d48f
commit d80ee39789
5 changed files with 60 additions and 27 deletions

View File

@ -207,6 +207,26 @@ public class HJ212DataUtil {
return dataCpSB.toString();
}
/**
* realData to string
*/
public static String requestRealData(List<RealDataCp> realDataCps) {
StringBuilder sb = new StringBuilder();
sb.append("DataTime=").append(realDataCps.get(0).getDataTime());
for (RealDataCp realDataCp : realDataCps) {
sb.append(";");
sb.append(realDataCp.getPollId()).append("-SampleTime=").append(realDataCp.getSampleTime());
sb.append(",").append(realDataCp.getPollId()).append("-Rtd=").append(realDataCp.getRtd());
if (StringUtils.isNotBlank(realDataCp.getFlag())) {
sb.append(",").append(realDataCp.getPollId()).append("-Flag=").append(realDataCp.getFlag());
}
if (StringUtils.isNotBlank(realDataCp.getEFlag())) {
sb.append(",").append(realDataCp.getPollId()).append("-EFlag").append(realDataCp.getEFlag());
}
}
return sb.toString();
}
/**
* 解析数据
*

View File

@ -1,6 +1,6 @@
server:
port: 7004
url: http://192.168.0.101:7004/pollutant
url: http://192.168.0.103:7004/pollutant
title: 污染物上报系统
servlet:
context-path: /pollutant
@ -22,7 +22,7 @@ spring:
max-request-size: 1GB
datasource:
druid:
url: jdbc:mysql://localhost:3306/db_pollutant_data?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC
url: jdbc:mysql://192.168.0.151:3306/db_pollutant_data?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC
db-type: mysql
driver-class-name: com.mysql.jdbc.Driver
username: root
@ -57,11 +57,11 @@ spring:
# 安全
security:
oauth2:
oauth-server: http://124.67.110.246:8081/usercenter
oauth-server: http://192.168.0.152:7001/usercenter
oauth-logout: ${security.oauth2.oauth-server}/logout?redirect_uri=${server.url}
client:
client-id: 9bbf141d41aa41c981dfb7468a52937e
client-secret: b3QySk1qc0F3TXFTeFNHMG5sS1hiM0tpaWdnQzl0amFhU0Rtc3ptbU45VW1ac2wwZTJHWk5NbXh3L3h3U2c4Rg==
client-id: 2a347bba1dc54def83a47493c7578ae2
client-secret: TEdsOHlnTnc4T2JwTXM3alZldzRSM1ROKzhaQkZaQ24vSWJxREd0TWVLMG1ac2wwZTJHWk5NbXh3L3h3U2c4Rg==
user-authorization-uri: ${security.oauth2.oauth-server}/oauth_client/authorize
access-token-uri: ${security.oauth2.oauth-server}/oauth_client/token
grant-type: authorization_code
@ -75,7 +75,7 @@ security:
api-path:
user-center: ${security.oauth2.oauth-server}
inspection: http://124.67.110.246:8081/inspection
inspection: http://192.168.0.103:7006/inspection
system:
# 预警通知上限
alarm-notice-limit: 5
@ -95,7 +95,7 @@ logging:
swagger:
title: 接口文档
description: 隐患排查系统接口文档
service-url: http://106.12.218.237:8001/pollutant
service-url: http://192.168.0.103:7004/pollutant
version: 1.0
swagger-base-package: com.cm

View File

@ -85,7 +85,7 @@ public class ConnectRunner implements Runnable {
});
}
});
ChannelFuture channelFuture = bootstrap.connect("124.67.110.246", 1991).sync();
ChannelFuture channelFuture = bootstrap.connect("192.168.0.103", 1991).sync();
channelFuture.addListener((ChannelFutureListener) future -> {
if (!future.isSuccess()) {
future.channel().pipeline().fireChannelInactive();

View File

@ -6,9 +6,11 @@ import com.cm.tenlion.pollutantdata.enums.DataCpFlagEnum;
import com.cm.tenlion.pollutantdata.enums.DataFlagEnum;
import com.cm.tenlion.pollutantdata.enums.StEnum;
import com.cm.tenlion.pollutantdata.utils.HJ212DataUtil;
import com.cm.tenlion.pollutantdata.utils.core.T212Parser;
import io.netty.channel.ChannelFuture;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@ -55,23 +57,34 @@ public class DemoRunner implements Runnable {
// 采集器编号
data.setMn(mn);
data.setFlag(DataFlagEnum.HAS_PNUM_ANSWER_V2017.getValue());
HJ212DataUtil.DataCp dataCp = new HJ212DataUtil.DataCp();
Random random = new Random();
// 实时值
dataCp.setRtd((double) random.nextInt(20));
// 折算实时值
dataCp.setZsRtd((double) random.nextInt(20));
// 污染因子
dataCp.setPollId(pollId);
dataCp.setSn(sn);
dataCp.setSampleTime(DateUtil.formatDate(System.currentTimeMillis(), "yyyyMMddHHmmssSSS"));
dataCp.setFlag(DataCpFlagEnum.N.getValue());
data.setDataCp(dataCp);
List<String> datas = HJ212DataUtil.respData(data);
datas.forEach(dataStr -> {
System.out.println(dataStr);
channelFuture.channel().writeAndFlush(dataStr.getBytes(StandardCharsets.UTF_8));
});
Random random = new Random();
String[] pollIdArray = new String[]{"a00000", "w01001", "w01002", "w01006", "w01009"};
List<HJ212DataUtil.RealDataCp> realDataCps = new ArrayList<>();
for (int i = 0; i < 5; i++) {
HJ212DataUtil.RealDataCp realDataCp = new HJ212DataUtil.RealDataCp();
realDataCp.setDataTime(DateUtil.formatDate(System.currentTimeMillis(), "yyyyMMddHHmmss"));
realDataCp.setRtd((double) random.nextInt(20));
realDataCp.setSampleTime(DateUtil.formatDate(System.currentTimeMillis(), "yyyyMMddHHmmssSSS"));
realDataCp.setFlag(DataCpFlagEnum.N.getValue());
realDataCp.setPollId(pollIdArray[i]);
realDataCps.add(realDataCp);
}
data.setRealDataCps(realDataCps);
String respData = String.format("QN=%s;ST=%d;CN=%d;PW=%s;MN=%s;Flag=%d;CP=&&%s&&",
data.getQn(), data.getSt(), data.getCn(), data.getPw(), data.getMn(), data.getFlag(), HJ212DataUtil.requestRealData(realDataCps));
char[] respDataChar = respData.toCharArray();
StringBuilder respSB = new StringBuilder("##");
respSB.append(String.format("%04d", respData.length()));
respSB.append(respData);
respSB.append(Integer.toHexString(T212Parser.crc16Checkout(respDataChar, respDataChar.length)));
System.out.println(">>>>" + respSB);
channelFuture.channel().writeAndFlush(respSB.toString().getBytes(StandardCharsets.UTF_8));
}
}

View File

@ -100,7 +100,7 @@ public class HJ212Test {
});
}
});
ChannelFuture channelFuture = bootstrap.connect("106.12.218.237", 1991).sync();
ChannelFuture channelFuture = bootstrap.connect("192.168.0.120", 1991).sync();
channelFuture.addListener((ChannelFutureListener) future -> {
if (!future.isSuccess()) {
future.channel().pipeline().fireChannelInactive();
@ -136,7 +136,7 @@ public class HJ212Test {
new Thread(new ConnectRunner(StEnum.AIR, "CJY001003", "CJQ001003002", "a20057")).start();
**/
// 2.乌兰察布市集宁区富磊热力有限责任公司
new Thread(new ConnectRunner(StEnum.ST_22, "CJY002001", "CJQ002001001", "a00000")).start();
new Thread(new ConnectRunner(StEnum.ST_22, "CJY001002", "CJQ002001001", "a00000")).start();
/**
new Thread(new ConnectRunner(StEnum.AIR, "CJY002001", "CJQ002001002", "a05001")).start();
new Thread(new ConnectRunner(StEnum.AIR, "CJY002002", "CJQ002002001", "a05002")).start();