Commit e4c6a07c authored by chenzhao's avatar chenzhao

广固增加南瑞接口调用

parent bf2517d8
package com.yeejoin.equipmanage.controller; package com.yeejoin.equipmanage.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONArray;
import com.yeejoin.equipmanage.common.utils.CommonResponseUtil; import com.yeejoin.equipmanage.service.impl.NrApiInvocationImpl;
import com.yeejoin.equipmanage.service.impl.SyncDataServiceImpl; import com.yeejoin.equipmanage.service.impl.SyncDataServiceImpl;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -12,27 +14,32 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -12,27 +14,32 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation; import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
@RestController @RestController
@Api(tags = "南瑞Api调用") @Api(tags = "南瑞Api调用")
@RequestMapping(value = "/nrApi", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @RequestMapping(value = "/nrApi", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class NRApiInvocationController { public class NRApiInvocationController {
private final Logger logger = LoggerFactory.getLogger(NRApiInvocationController.class);
@Autowired @Autowired
private SyncDataServiceImpl syncDataService; private SyncDataServiceImpl syncDataService;
@Autowired
private NrApiInvocationImpl invocation;
@RequestMapping(value = "/getRealTimeData", method = RequestMethod.GET) @RequestMapping(value = "/getRealTimeData", method = RequestMethod.GET)
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(httpMethod = "get", value = "获取南瑞实时数据") @ApiOperation(httpMethod = "get", value = "获取南瑞实时数据")
public ResponseModel<JSONObject> getRealTimeData() { public JSONArray getRealTimeData() {
try { try {
return CommonResponseUtil.success( syncDataService.getNrRealTime());
} catch (InterruptedException e) { JSONArray nrRealTime = invocation.getNrRealTime();
e.printStackTrace(); logger.info("获取南瑞实时数据aaaaaaaaaa",nrRealTime);
return nrRealTime;
} catch (Exception e) {
logger.info("获取南瑞实时数据",e);
return new JSONArray();
} }
return CommonResponseUtil.failure();
} }
......
package com.yeejoin.equipmanage.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.equipmanage.common.datasync.vo.RequestVo;
import com.yeejoin.equipmanage.common.utils.HttpContentTypeUtil;
import com.yeejoin.equipmanage.utils.DcsUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class NrApiInvocationImpl {
@Value("${dcs.x.hw.id}")
private String xHwId;
@Value("${dcs.x.hw.appKey}")
private String xHwAppKey;
@Autowired
private DcsUtil dcsUtil;
@Value("${dcs.url.realtime.key}")
private String realtimeKey;
@Value("${dcs.url.yxfs.key}")
private String yxfsKey;
@Value("${operation.date}")
private String operationDate;
@Value("${dcs.url.realtime.datatype}")
private String datatype;
@Value("${dcs.url.realtime}")
private String realtimeUrl;
private final Logger logger = LoggerFactory.getLogger(NrApiInvocationImpl.class);
public JSONArray getNrRealTime() throws Exception {
String authorization = dcsUtil.getDcsToken();
JSONArray objects = new JSONArray();
Map<String, String> headerMap = new HashMap<>();
headerMap.put("Authorization", authorization);
headerMap.put("token", authorization.split(" ")[1]);
headerMap.put("X-HW-ID", xHwId);
headerMap.put("X-HW-APPKEY", xHwAppKey);
if (StringUtils.isNotBlank(authorization)) {
RequestVo requestVo = new RequestVo();
requestVo.setId(1L);
requestVo.setClientId("serv-x01");
Map<String, Object> bodyMap = new HashMap<>();
bodyMap.put("datatype",datatype);
bodyMap.put("keys", Arrays.asList(realtimeKey.split(",")));
// bodyMap.put("datatype","state");
// bodyMap.put("keys", Arrays.asList("3940656019406849",
// "3940656019472385",
// "3940656019537921",
// "3940656019144705",
// "3940656019210241",
// "3940656019275777",
// "3940656019341313"));
requestVo.setBody(bodyMap);
logger.info("===============告警存入header:" + JSON.toJSONString(headerMap) + ";\n==================告警存入body: " + JSON.toJSONString(requestVo));
String data = HttpContentTypeUtil.sendHttpPostJsonWithHeader(realtimeUrl, JSON.toJSONString(requestVo), headerMap);
bodyMap.put("keys",Arrays.asList(yxfsKey.split(",")));
requestVo.setBody(bodyMap);
//String s = "{\"code\":\"2023\",\"id\":1,\"message\":\"获取实时信号值成功\",\"body\":{\"values\":[{\"time_stamp\":\"2025-12-04 15:55:56.000\",\"value\":4417.724609375,\"key\":\"0000YC000101004B14\",\"quality\":0},{\"time_stamp\":\"2025-12-04 15:55:56.000\",\"value\":0.67138671875,\"key\":\"0000YC000101004623\",\"quality\":0},{\"time_stamp\":\"2025-12-04 15:55:41.000\",\"value\":0.79345703125,\"key\":\"0000YC000101004624\",\"quality\":0}]}}";
logger.info("===============告警推送联调返回数据:" + data);
logger.info("===============告警推送联调返回数据结果:" + JSONObject.parseObject(data));
JSONArray jsonArray = JSONObject.parseObject(data).getJSONObject("body").getJSONArray("values");
String yxfs = HttpContentTypeUtil.sendHttpPostJsonWithHeader(realtimeUrl, JSON.toJSONString(requestVo), headerMap);
logger.info("===============告警推送联调返回数据结果:" + yxfs);
JSONArray yxfsArr = JSONObject.parseObject(yxfs).getJSONObject("body").getJSONArray("values");
JSONArray filteredArr = new JSONArray(
yxfsArr.stream()
.filter(obj -> obj instanceof JSONObject)
.map(obj -> (JSONObject) obj)
.filter(obj -> {
Object v = obj.get("value");
if (v instanceof Number) {
return ((Number) v).doubleValue() == 1.0;
}
return false;
}).collect(Collectors.toList())
);
jsonArray.addAll(filteredArr);
JSONObject yxsj = new JSONObject();
yxsj.put("key","tyrq");
yxsj.put("value",operationDate);
JSONObject safeDay = new JSONObject();
safeDay.put("key","safeDay");
LocalDate opDate = LocalDate.parse(operationDate);
safeDay.put("value", ChronoUnit.DAYS.between(opDate, LocalDate.now()));
jsonArray.add(yxsj);
jsonArray.add(safeDay);
objects.addAll(jsonArray);
logger.info("===============告警推送联调返回数据结果1111111:" + jsonArray);
}
return objects;
}
}
...@@ -63,6 +63,8 @@ public class SyncDataServiceImpl implements ISyncDataService { ...@@ -63,6 +63,8 @@ public class SyncDataServiceImpl implements ISyncDataService {
@Value("${dcs.url.realtime}") @Value("${dcs.url.realtime}")
private String realtimeUrl; private String realtimeUrl;
@Value("${dcs.x.hw.id}") @Value("${dcs.x.hw.id}")
private String xHwId; private String xHwId;
...@@ -544,35 +546,5 @@ public class SyncDataServiceImpl implements ISyncDataService { ...@@ -544,35 +546,5 @@ public class SyncDataServiceImpl implements ISyncDataService {
public JSONObject getNrRealTime() throws InterruptedException {
try {
String authorization = dcsUtil.getDcsToken();
Map<String, String> headerMap = new HashMap<>();
headerMap.put("Authorization", authorization);
headerMap.put("token", authorization.split(" ")[1]);
headerMap.put("X-HW-ID", xHwId);
headerMap.put("X-HW-APPKEY", xHwAppKey);
if (StringUtils.isNotBlank(authorization)) {
RequestVo requestVo = new RequestVo();
requestVo.setId(1L);
requestVo.setClientId("serv-x01");
Map<String, Object> bodyMap = new HashMap<>();
bodyMap.put("datatype","analog");
bodyMap.put("keys", Arrays.asList("0000YC000101004B14","0000YC000101004623","0000YC000101004624"));
requestVo.setBody(bodyMap);
logger.info("===============告警存入header:" + JSON.toJSONString(headerMap) + ";\n==================告警存入body: " + JSON.toJSONString(requestVo));
String s = HttpContentTypeUtil.sendHttpPostJsonWithHeader(realtimeUrl, JSON.toJSONString(requestVo), headerMap);
logger.info("===============告警推送联调返回数据:" + JSON.toJSONString(s));
return JSONObject.parseObject(s);
}
} catch (Exception e) {
logger.error("getNrRealTime数据接口请求异常:" + e.getMessage());
}
return null;
}
} }
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql://172.16.10.216:3306/dl_business_v3.0.1.3?useUnicode=true&allowMultiQueries=true&characterEncoding=utf-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai spring.datasource.url = jdbc:mysql://39.100.71.139:3307/dl_business_v3.0.1.3?useUnicode=true&allowMultiQueries=true&characterEncoding=utf-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=ENC(ooSbV2vO5UUB3BuAVYjYxm4OVY4rCv275/HxXJNz+Nbf2I8EjuylP9tTh30s2j7g) spring.datasource.password=Yeejoin@2020
spring.datasource.type=com.zaxxer.hikari.HikariDataSource spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.pool-name=DatebookHikariCP spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.minimum-idle= 3 spring.datasource.hikari.minimum-idle= 3
...@@ -17,20 +17,20 @@ eureka.instance.prefer-ip-address = true ...@@ -17,20 +17,20 @@ eureka.instance.prefer-ip-address = true
#服务实例ip地址,若eureka.instance.prefer-ip-address=false,ip-address设置失效,一般情况不用设置。 #服务实例ip地址,若eureka.instance.prefer-ip-address=false,ip-address设置失效,一般情况不用设置。
#eureka.instance.ip-address= 172.16.3.135 #eureka.instance.ip-address= 172.16.3.135
#eureka服务ip配置,可填写固定ip地址 #eureka服务ip配置,可填写固定ip地址
eureka.instance.hostname=172.16.10.216 eureka.instance.hostname=39.100.71.139
#eureka服务配置的校验账号及密码,配置需和eureka服务后台配置文件中一致 #eureka服务配置的校验账号及密码,配置需和eureka服务后台配置文件中一致
#eureka????????????,????eureka??????????? #eureka????????????,????eureka???????????
spring.security.user.name=admin spring.security.user.name=admin
spring.security.user.password=ENC(8Avkl0Wjal6xBOWKXQ+X1QCbtDt3n1JZS7dHehmtYFTPYNd+6diNNogVGZCPVHjE) spring.security.user.password=a1234650
eureka.client.serviceUrl.defaultZone=http://${spring.security.user.name}:${spring.security.user.password}@${eureka.instance.hostname}:10001/eureka/ eureka.client.serviceUrl.defaultZone=http://${spring.security.user.name}:${spring.security.user.password}@${eureka.instance.hostname}:10001/eureka/
##########eureka配置信息############### ##########eureka配置信息###############
#redis #redis
spring.redis.database=1 spring.redis.database=1
spring.redis.host=172.16.10.216 spring.redis.host=39.100.71.139
spring.redis.port=6379 spring.redis.port=6379
spring.redis.password=ENC(/T7d22Zy0QgL+Ff1+FC81syDFAVOpo4CoWrDVUELyjR2XEXuk+gmNnzkyK3B5ibi) spring.redis.password=yeejoin@2020
spring.redis.lettuce.pool.max-active=200 spring.redis.lettuce.pool.max-active=200
spring.redis.lettuce.pool.max-wait=-1 spring.redis.lettuce.pool.max-wait=-1
spring.redis.lettuce.pool.max-idle=10 spring.redis.lettuce.pool.max-idle=10
...@@ -40,18 +40,18 @@ spring.redis.expire.time=30000 ...@@ -40,18 +40,18 @@ spring.redis.expire.time=30000
## emqx ## emqx
emqx.clean-session=true emqx.clean-session=true
emqx.client-id=${spring.application.name}-${security-random-int} emqx.client-id=${spring.application.name}-${security-random-int}
emqx.broker=tcp://172.16.10.216:1883 emqx.broker=tcp://39.100.71.139:1883
emqx.user-name=admin emqx.user-name=admin
emqx.password=ENC(GGQmxuyl6uOxAsDhjRo+USgUybWC8Ns4Q7mlnyq3JqJE9LsFgYBNK8gzJ7H/Znw+) emqx.password=public
emqx.client-user-name=admin emqx.client-user-name=admin
emqx.client-password=ENC(GGQmxuyl6uOxAsDhjRo+USgUybWC8Ns4Q7mlnyq3JqJE9LsFgYBNK8gzJ7H/Znw+) emqx.client-password=public
mqtt.scene.host=mqtt://172.16.10.216:8083/mqtt mqtt.scene.host=mqtt://39.100.71.139:8083/mqtt
mqtt.client.product.id=mqtt mqtt.client.product.id=mqtt
mqtt.topic=topic_mqtt mqtt.topic=topic_mqtt
spring.mqtt.completionTimeout=3000 spring.mqtt.completionTimeout=3000
# influxDB # influxDB
spring.influx.url=http://172.16.10.216:8086 spring.influx.url=http://172.16.11.201:8086
spring.influx.password=ENC(ooSbV2vO5UUB3BuAVYjYxm4OVY4rCv275/HxXJNz+Nbf2I8EjuylP9tTh30s2j7g) spring.influx.password=Yeejoin@2020
spring.influx.user=root spring.influx.user=root
spring.influx.database=iot_platform spring.influx.database=iot_platform
spring.influx.retention_policy=default spring.influx.retention_policy=default
...@@ -62,7 +62,7 @@ spring.influx.bufferLimit=20000 ...@@ -62,7 +62,7 @@ spring.influx.bufferLimit=20000
#系统机器人账号 #系统机器人账号
amos.system.user.user-name=gw_ys4 amos.system.user.user-name=gw_ys4
amos.system.user.password=ENC(7tDiqwjMIbE4TjngEimbmaXzvBC1/nlGrIDNPd1z6rBCr72XvCPcDzrIMkKQChuB) amos.system.user.password=a1234650
amos.system.user.app-key=studio_normalapp_3056965 amos.system.user.app-key=studio_normalapp_3056965
amos.system.user.product=STUDIO_APP_WEB amos.system.user.product=STUDIO_APP_WEB
security.productApp=STUDIO_APP_MOBILE security.productApp=STUDIO_APP_MOBILE
...@@ -103,11 +103,14 @@ dcs.source.type=\u9ad8\u7ea7\u5e94\u7528 ...@@ -103,11 +103,14 @@ dcs.source.type=\u9ad8\u7ea7\u5e94\u7528
dcs.url.sendalarm=http://172.21.101.101/v1/cs/alarm-service/appalarm/sendalarm dcs.url.sendalarm=http://172.21.101.101/v1/cs/alarm-service/appalarm/sendalarm
#南瑞实时查询数据接口调用 #南瑞实时查询数据接口调用
dcs.url.realtime=http://172.21.101.101/v1/cs/realdata-service/data/realtime dcs.url.realtime=http://172.21.101.101/v1/cs/realdata-service/data/realtime
dcs.url.realtime.key=0000YC0001010040A5,0000YC000101004099,0000YC000101004237,0000YC00010100422B
dcs.url.yxfs.key=0000YC0001010040A5,0000YC000101004099, 0000YC000101004237,0000YC00010100422B
dcs.url.realtime.datatype=state
################################################################################# #################################################################################
#\u7CFB\u7EDF\u4E0A\u7EBF\u65F6\u95F4 #\u7CFB\u7EDF\u4E0A\u7EBF\u65F6\u95F4
param.system.online.date = 2019-02-12 param.system.online.date = 2019-02-12
operation.date=2019-02-12
############数字1.0视频接入服务配置,其他版本不支持################################## ############数字1.0视频接入服务配置,其他版本不支持##################################
# 视频转码服务开关 hls(关)/flv(开),默认关闭,数字换流站1.0使用时开启 # 视频转码服务开关 hls(关)/flv(开),默认关闭,数字换流站1.0使用时开启
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment