diff --git a/src/main/java/com/cm/tenlion/pollutantdata/utils/HJ212DataUtil.java b/src/main/java/com/cm/tenlion/pollutantdata/utils/HJ212DataUtil.java index b90b329..1ef8cfd 100644 --- a/src/main/java/com/cm/tenlion/pollutantdata/utils/HJ212DataUtil.java +++ b/src/main/java/com/cm/tenlion/pollutantdata/utils/HJ212DataUtil.java @@ -207,6 +207,26 @@ public class HJ212DataUtil { return dataCpSB.toString(); } + /** + * realData to string + */ + public static String requestRealData(List 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(); + } + /** * 解析数据 * diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index eb6fd0f..59631fb 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -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 diff --git a/src/test/java/cn/com/tenlion/pollutantdata/ConnectRunner.java b/src/test/java/cn/com/tenlion/pollutantdata/ConnectRunner.java index d712b0e..717d166 100644 --- a/src/test/java/cn/com/tenlion/pollutantdata/ConnectRunner.java +++ b/src/test/java/cn/com/tenlion/pollutantdata/ConnectRunner.java @@ -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(); diff --git a/src/test/java/cn/com/tenlion/pollutantdata/DemoRunner.java b/src/test/java/cn/com/tenlion/pollutantdata/DemoRunner.java index 62c72a9..3a6dfd2 100644 --- a/src/test/java/cn/com/tenlion/pollutantdata/DemoRunner.java +++ b/src/test/java/cn/com/tenlion/pollutantdata/DemoRunner.java @@ -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 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 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)); } } diff --git a/src/test/java/cn/com/tenlion/pollutantdata/HJ212Test.java b/src/test/java/cn/com/tenlion/pollutantdata/HJ212Test.java index f51436f..454914a 100644 --- a/src/test/java/cn/com/tenlion/pollutantdata/HJ212Test.java +++ b/src/test/java/cn/com/tenlion/pollutantdata/HJ212Test.java @@ -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();