省平台数据推送正式数据
parent
95b64732f7
commit
c6229f43b2
11
pom.xml
11
pom.xml
|
@ -119,6 +119,17 @@
|
||||||
<artifactId>jna</artifactId>
|
<artifactId>jna</artifactId>
|
||||||
<version>${jna.version}</version>
|
<version>${jna.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bytedeco</groupId>
|
||||||
|
<artifactId>javacv-platform</artifactId>
|
||||||
|
<version>1.5.9</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -3,7 +3,10 @@ package com.netsdk.utils;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.netsdk.entity.PageData;
|
import com.netsdk.entity.PageData;
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
@ -11,7 +14,10 @@ import org.springframework.web.client.RestTemplate;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将Redis中存储的MES平台数据推送至省平台。
|
* 将Redis中存储的MES平台数据推送至省平台。
|
||||||
|
@ -30,6 +36,15 @@ public class ProvincialPlatformDataPushScheduled {
|
||||||
|
|
||||||
@Scheduled(cron = "*/5 * * * * ?")
|
@Scheduled(cron = "*/5 * * * * ?")
|
||||||
public void scheduled() throws Exception {
|
public void scheduled() throws Exception {
|
||||||
|
// 推送实时数据
|
||||||
|
pushRealTimeData();
|
||||||
|
|
||||||
|
// 推送报警数据
|
||||||
|
pushAlarmData();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void pushRealTimeData() {
|
||||||
// 先填写基础报文 数据上报报文格式如下: appId、serviceId、dataId、data
|
// 先填写基础报文 数据上报报文格式如下: appId、serviceId、dataId、data
|
||||||
// 实时数据和报警数据的报文格式、appId、serviceId等信息不同。
|
// 实时数据和报警数据的报文格式、appId、serviceId等信息不同。
|
||||||
HashMap<String, Object> baseMap = new HashMap<>();
|
HashMap<String, Object> baseMap = new HashMap<>();
|
||||||
|
@ -40,7 +55,7 @@ public class ProvincialPlatformDataPushScheduled {
|
||||||
baseMap.put("dataId", dataId);
|
baseMap.put("dataId", dataId);
|
||||||
|
|
||||||
// 接下来定义data,也就是需要向省平台推送的数据
|
// 接下来定义data,也就是需要向省平台推送的数据
|
||||||
Map<String, Object> dataMap = new HashMap<String, Object>();
|
HashMap<String, Object> dataMap = new HashMap<String, Object>();
|
||||||
dataMap.put("dataId", dataId);
|
dataMap.put("dataId", dataId);
|
||||||
dataMap.put("areaCode", "14"); //企业所属省份的行政区划
|
dataMap.put("areaCode", "14"); //企业所属省份的行政区划
|
||||||
dataMap.put("enterpriseId", "GT1407810001"); //企业数据接入标识
|
dataMap.put("enterpriseId", "GT1407810001"); //企业数据接入标识
|
||||||
|
@ -53,27 +68,99 @@ public class ProvincialPlatformDataPushScheduled {
|
||||||
// 格式化时间
|
// 格式化时间
|
||||||
String collectTime = now.format(formatter);
|
String collectTime = now.format(formatter);
|
||||||
dataMap.put("collectTime", collectTime); //时间戳,格式YYYYMMDDHHmmss
|
dataMap.put("collectTime", collectTime); //时间戳,格式YYYYMMDDHHmmss
|
||||||
dataMap.put("isConnectDataSource", false); //数据源连通性
|
dataMap.put("isConnectDataSource", true); //数据源连通性
|
||||||
dataMap.put("reportType", "report"); //报文类型,report表示实时报文
|
dataMap.put("reportType", "report"); //报文类型,report表示实时报文
|
||||||
|
|
||||||
//定义datas指标数据集合
|
//定义datas指标数据集合
|
||||||
List<Map<String, Object>> dataList = new ArrayList<>();
|
List<Map<String, Object>> dataList = new ArrayList<>();
|
||||||
|
//取出存储在Redis中的数据
|
||||||
|
ArrayList<PageData> allDataList = new ArrayList<>();
|
||||||
|
if (!Tools.isEmpty(redisUtil.get("MES_DATA_LIST"))) {
|
||||||
|
allDataList.addAll(JSONArray.parseArray(redisUtil.get("MES_DATA_LIST").toString(), PageData.class));
|
||||||
|
}
|
||||||
|
if (!Tools.isEmpty(redisUtil.get("WMK_DATA_LIST"))) {
|
||||||
|
allDataList.addAll(JSONArray.parseArray(redisUtil.get("WMK_DATA_LIST").toString(), PageData.class));
|
||||||
|
}
|
||||||
|
for (PageData dataPd : allDataList) {
|
||||||
|
if (dataPd.containsKey("REPORT_ID") && !Tools.isEmpty(dataPd.getString("REPORT_ID"))) {
|
||||||
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
|
data.put("quotaId", dataPd.get("REPORT_ID")); // 传感编码
|
||||||
|
data.put("value", dataPd.get("CURRENT_VALUE")); // 指标当前采集值
|
||||||
|
data.put("datas", true); // 质量戳
|
||||||
|
dataList.add(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dataMap.put("datas", dataList);
|
||||||
|
|
||||||
|
//使用AES加密dataMap
|
||||||
|
String encrypt = null;
|
||||||
|
try {
|
||||||
|
encrypt = AESUtil.encrypt(JSON.toJSONString(dataMap));
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("实时数据AES加密出现错误!");
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
baseMap.put("data", encrypt);
|
||||||
|
|
||||||
|
//发送HTTP请求到平台
|
||||||
|
sendDataToPlatform(baseMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pushAlarmData() {
|
||||||
|
// 先填写基础报文 数据上报报文格式如下: appId、serviceId、dataId、data
|
||||||
|
// 实时数据和报警数据的报文格式、appId、serviceId等信息不同。
|
||||||
|
HashMap<String, Object> baseMap = new HashMap<>();
|
||||||
|
// 定义一个本次消息公用dataId(UUID) 调用方生成,证明单次数据的身份,相同dataId的数据省平台只接收一次。
|
||||||
|
String dataId = UuidUtil.get32UUID();
|
||||||
|
baseMap.put("appId", "1ae355c6-4440-4579-823b-c0b9758171f6");
|
||||||
|
baseMap.put("serviceId", "2442c212da9549c68f76d008919d679d");
|
||||||
|
baseMap.put("dataId", dataId);
|
||||||
|
|
||||||
|
// 接下来定义data,也就是需要向省平台推送的数据
|
||||||
|
HashMap<String, Object> alarmMap = new HashMap<String, Object>();
|
||||||
|
alarmMap.put("dataId", dataId);
|
||||||
|
alarmMap.put("areaCode", "14"); //企业所属省份的行政区划
|
||||||
|
alarmMap.put("enterpriseId", "GT1407810001"); //企业数据接入标识
|
||||||
|
alarmMap.put("gatewayId", "GT140781000101"); //网关编码:企业数据接入标识+01
|
||||||
|
|
||||||
|
//初始化报文当前时间戳 定义格式化模板:年月日时分秒(24小时制)
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
||||||
|
// 获取当前时间
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
// 格式化时间
|
||||||
|
String collectTime = now.format(formatter);
|
||||||
|
alarmMap.put("collectTime", collectTime); //时间戳,格式YYYYMMDDHHmmss
|
||||||
|
alarmMap.put("isConnectDataSource", true); //数据源连通性
|
||||||
|
alarmMap.put("reportType", "report"); //报文类型,report表示实时报文
|
||||||
|
//定义datas指标数据集合
|
||||||
|
List<Map<String, Object>> alarmList = new ArrayList<>();
|
||||||
//--------------------------定义测试数据----------------------------------
|
//--------------------------定义测试数据----------------------------------
|
||||||
HashMap<String, Object> data = new HashMap<>();
|
HashMap<String, Object> alarm = new HashMap<>();
|
||||||
data.put("quotaId", 11); // 指标编码
|
alarm.put("quotaId", "GT1407810001010000001"); // 传感器传感编码(IOT平台取)
|
||||||
data.put("value", 66); // 指标当前采集值
|
// alarm.put("value", value); // 指标当前采集值
|
||||||
data.put("datas", false); // 质量戳
|
alarm.put("alarmType", "alarmhi:alarm"); // 报警类型:alarm hi:alarm 表示超上限报警;alarm hh:alarm 表示超上上限报警;alarm lo:alarm 表示超下限报警;alarm ll:alarm 表示超下下限报警;normal:alarm 表示消警;alarmsignal 表示变化报警,即开关量报警
|
||||||
dataList.add(data);
|
alarm.put("threshold", 99); // 当前报警阈值/消警阈值
|
||||||
|
// 获取当前时间
|
||||||
|
LocalDateTime alarmTime = LocalDateTime.now();
|
||||||
|
// 格式化时间
|
||||||
|
String alarmFormatTime = alarmTime.format(formatter);
|
||||||
|
alarm.put("alarmTime", alarmFormatTime); // 报警时间
|
||||||
|
alarmList.add(alarm);
|
||||||
//--------------------------测试数据结束----------------------------------
|
//--------------------------测试数据结束----------------------------------
|
||||||
|
|
||||||
//真实数据逻辑(注释部分)
|
//真实数据逻辑(注释部分)
|
||||||
//取出存储在Redis中的数据
|
//取出存储在Redis中的数据
|
||||||
//List<PageData> mesDataList = JSONArray.parseArray(redisUtil.get("MES_DATA_LIST").toString(), PageData.class);
|
//List<PageData> mesDataList = JSONArray.parseArray(redisUtil.get("MES_DATA_LIST").toString(), PageData.class);
|
||||||
|
|
||||||
dataMap.put("datas", dataList);
|
alarmMap.put("alarms", alarmList);
|
||||||
|
|
||||||
//使用AES加密dataMap
|
//使用AES加密dataMap
|
||||||
String encrypt = AESUtil.encrypt(JSON.toJSONString(dataMap));
|
String encrypt = null;
|
||||||
|
try {
|
||||||
|
encrypt = AESUtil.encrypt(JSON.toJSONString(alarmMap));
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("实时数据AES加密出现错误!");
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
baseMap.put("data", encrypt);
|
baseMap.put("data", encrypt);
|
||||||
|
|
||||||
//发送HTTP请求到平台
|
//发送HTTP请求到平台
|
||||||
|
|
|
@ -0,0 +1,192 @@
|
||||||
|
package com.netsdk.utils;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 说明:常用工具
|
||||||
|
* 作者:luoxiaobao
|
||||||
|
* 官网:www.qdkjchina.com
|
||||||
|
*/
|
||||||
|
public class Tools {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机生成六位数验证码
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int getRandomNum(){
|
||||||
|
Random r = new Random();
|
||||||
|
return r.nextInt(900000)+100000;//(Math.random()*(999999-100000)+100000)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机生成四位数验证码
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int getRandomNum4(){
|
||||||
|
Random r = new Random();
|
||||||
|
return r.nextInt(9000)+1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测字符串是否不为空(null,"","null")
|
||||||
|
* @param s
|
||||||
|
* @return 不为空则返回true,否则返回false
|
||||||
|
*/
|
||||||
|
public static boolean notEmpty(String s){
|
||||||
|
return s!=null && !"".equals(s) && !"null".equals(s)&& !"undefined".equals(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测字符串是否为空(null,"","null")
|
||||||
|
* @param s
|
||||||
|
* @return 为空则返回true,不否则返回false
|
||||||
|
*/
|
||||||
|
public static boolean isEmpty(String s){
|
||||||
|
return s==null || s.isEmpty() || "null".equals(s) || "undefined".equals(s);
|
||||||
|
}
|
||||||
|
public static boolean isEmpty (Object obj) {
|
||||||
|
return obj ==null || "".equals(obj);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 字符串转换为字符串数组
|
||||||
|
* @param str 字符串
|
||||||
|
* @param splitRegex 分隔符
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String[] str2StrArray(String str,String splitRegex){
|
||||||
|
if(isEmpty(str)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return str.split(splitRegex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用默认的分隔符(,)将字符串转换为字符串数组
|
||||||
|
* @param str 字符串
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String[] str2StrArray(String str){
|
||||||
|
return str2StrArray(str,",\\s*");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证邮箱
|
||||||
|
* @param email
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean checkEmail(String email){
|
||||||
|
boolean flag = false;
|
||||||
|
try{
|
||||||
|
String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
|
||||||
|
Pattern regex = Pattern.compile(check);
|
||||||
|
Matcher matcher = regex.matcher(email);
|
||||||
|
flag = matcher.matches();
|
||||||
|
}catch(Exception e){
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证手机号码
|
||||||
|
* @param mobiles
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean checkMobileNumber(String mobileNumber){
|
||||||
|
boolean flag = false;
|
||||||
|
try{
|
||||||
|
Pattern regex = Pattern.compile("^(((13[0-9])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8})|(0\\d{2}-\\d{8})|(0\\d{3}-\\d{7})$");
|
||||||
|
Matcher matcher = regex.matcher(mobileNumber);
|
||||||
|
flag = matcher.matches();
|
||||||
|
}catch(Exception e){
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
转半角的函数(DBC case)<br/><br/>
|
||||||
|
全角空格为12288,半角空格为32
|
||||||
|
其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248
|
||||||
|
* @param input 任意字符串
|
||||||
|
* @return 半角字符串
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static String ToDBC(String input) {
|
||||||
|
char[] c = input.toCharArray();
|
||||||
|
for (int i = 0; i < c.length; i++) {
|
||||||
|
if (c[i] == 12288) {
|
||||||
|
//全角空格为12288,半角空格为32
|
||||||
|
c[i] = (char) 32;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (c[i] > 65280 && c[i] < 65375)
|
||||||
|
//其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248
|
||||||
|
c[i] = (char) (c[i] - 65248);
|
||||||
|
}
|
||||||
|
return new String(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String replaceBlank(String str) {
|
||||||
|
String dest = "";
|
||||||
|
if (str != null) {
|
||||||
|
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
|
||||||
|
Matcher m = p.matcher(str);
|
||||||
|
dest = m.replaceAll("");
|
||||||
|
}
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
public static String excelHandle (String string) {
|
||||||
|
String aString = string.replaceAll(" ", "");
|
||||||
|
aString = ToDBC(aString);
|
||||||
|
aString = replaceBlank(aString);
|
||||||
|
return aString;
|
||||||
|
}
|
||||||
|
public static String excelHandle (Object object) {
|
||||||
|
String aString = object.toString().replaceAll(" ", "");
|
||||||
|
aString = ToDBC(aString);
|
||||||
|
aString = replaceBlank(aString);
|
||||||
|
return aString;
|
||||||
|
}
|
||||||
|
private static final String INTEGER_REGEX = "^-?\\d+$";
|
||||||
|
|
||||||
|
public static boolean isInteger(String input) {
|
||||||
|
Pattern pattern = Pattern.compile(INTEGER_REGEX);
|
||||||
|
Matcher matcher = pattern.matcher(input);
|
||||||
|
return matcher.matches();
|
||||||
|
}
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
String aString = " afjaisjfasjfasij ";
|
||||||
|
String bString = "";
|
||||||
|
bString= excelHandle(aString);
|
||||||
|
System.out.println("bString:"+bString+".");
|
||||||
|
System.out.println("aString:"+aString+".");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean contains(String[] array, String target) {
|
||||||
|
for (int i = 0; i < array.length; i++) {
|
||||||
|
if (array[i].equals(target)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer convertInteger(Object o) {
|
||||||
|
if (o == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return Integer.parseInt(o.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String convertString(Object o) {
|
||||||
|
if (o == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return o.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,13 +5,13 @@ spring:
|
||||||
name: integrated_yjb_dataDocking
|
name: integrated_yjb_dataDocking
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
url: jdbc:postgresql://10.199.64.30:15431/postgres?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=UTC
|
url: jdbc:postgresql://172.16.70.228:15431/postgres?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=UTC
|
||||||
password: rT)?DjIGYM8k0h!
|
password: Mysql@zcloud15431
|
||||||
username: postgres
|
username: postgres
|
||||||
redis:
|
redis:
|
||||||
host: 10.199.64.30
|
host: 172.16.70.226
|
||||||
password: 5.5pYdZqHxpR#9%W.
|
password: Zcloud@redis16379
|
||||||
database: 1
|
database: 10
|
||||||
port: 16379
|
port: 16379
|
||||||
modbus:
|
modbus:
|
||||||
port: 18888
|
port: 18888
|
||||||
|
|
Loading…
Reference in New Issue