Commit aefbd010 authored by 朱晨阳's avatar 朱晨阳

Merge remote-tracking branch 'origin/developer' into developer

parents 5328203c 3aaafd36
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
<artifactId>tyboot-component-emq</artifactId> <artifactId>tyboot-component-emq</artifactId>
<version>${tyboot-version}</version> <version>${tyboot-version}</version>
</dependency> </dependency>
<!--
<dependency> <dependency>
<groupId>org.typroject</groupId> <groupId>org.typroject</groupId>
<artifactId>tyboot-component-event</artifactId> <artifactId>tyboot-component-event</artifactId>
...@@ -69,6 +70,7 @@ ...@@ -69,6 +70,7 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
-->
<dependency> <dependency>
<groupId>org.typroject</groupId> <groupId>org.typroject</groupId>
<artifactId>tyboot-component-opendata</artifactId> <artifactId>tyboot-component-opendata</artifactId>
......
...@@ -5,23 +5,21 @@ import java.net.InetAddress; ...@@ -5,23 +5,21 @@ import java.net.InetAddress;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.typroject.tyboot.core.restful.exception.GlobalExceptionHandler; import org.typroject.tyboot.core.restful.exception.GlobalExceptionHandler;
/** /**
* *
* <pre> * <pre>
...@@ -41,10 +39,13 @@ import org.typroject.tyboot.core.restful.exception.GlobalExceptionHandler; ...@@ -41,10 +39,13 @@ import org.typroject.tyboot.core.restful.exception.GlobalExceptionHandler;
@EnableScheduling @EnableScheduling
@MapperScan(value = { "org.typroject.tyboot.*.*.face.orm.dao", "com.yeejoin.amos.api.*.face.orm.dao", @MapperScan(value = { "org.typroject.tyboot.*.*.face.orm.dao", "com.yeejoin.amos.api.*.face.orm.dao",
"org.typroject.tyboot.face.*.orm.dao*", "com.yeejoin.amos.boot.biz.common.dao.mapper" }) "org.typroject.tyboot.face.*.orm.dao*", "com.yeejoin.amos.boot.biz.common.dao.mapper" })
@ComponentScan({ "org.typroject", "com.yeejoin.amos" }) @ComponentScan(value = { "org.typroject",
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class}) "com.yeejoin.amos" }, excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.typroject.tyboot.component.event"))
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class })
public class HousevPVapiApplication { public class HousevPVapiApplication {
private static final Logger logger = LogManager.getLogger(HousevPVapiApplication.class); private static final Logger logger = LogManager.getLogger(HousevPVapiApplication.class);
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// 服务启动 // 服务启动
ConfigurableApplicationContext context = SpringApplication.run(HousevPVapiApplication.class, args); ConfigurableApplicationContext context = SpringApplication.run(HousevPVapiApplication.class, args);
......
...@@ -11,293 +11,307 @@ import com.yeejoin.amos.api.householdapi.constant.ImasterConstant; ...@@ -11,293 +11,307 @@ import com.yeejoin.amos.api.householdapi.constant.ImasterConstant;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HousepvapiRecords; import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HousepvapiRecords;
import com.yeejoin.amos.api.householdapi.face.orm.mapper.houseapi.HousepvapiRecordsMapper; import com.yeejoin.amos.api.householdapi.face.orm.mapper.houseapi.HousepvapiRecordsMapper;
import com.yeejoin.amos.api.householdapi.face.service.impl.GoodWeDataAcquisitionServiceImpl;
import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum; import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
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.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.*; import java.util.*;
@Component @Component
@Slf4j @Slf4j
public class ImasterUtils { public class ImasterUtils {
private String redisKey = "XSRF-TOKEN"; private String redisKey = "XSRF-TOKEN";
@Autowired
HousepvapiRecordsMapper housepvapiRecordsMapper;
@Autowired
RedisUtils redisUtils;
final static Logger logger = LoggerFactory.getLogger(ImasterUtils.class);
@Autowired /**
HousepvapiRecordsMapper housepvapiRecordsMapper; * @return HashMap<String, Object> 发送请求前的准备 准备header信息
@Autowired * @deprecated 根据厂商编码获取厂商的hearer
RedisUtils redisUtils; */
/** public static HashMap<String, String> getHeader() {
* @return HashMap<String, Object> 发送请求前的准备 准备header信息 HashMap<String, String> hashMap = new HashMap<>();
* @deprecated 根据厂商编码获取厂商的hearer String requestParam = "";
*/ HashMap<String, String> hashMaphead = new HashMap<>();
public static HashMap<String, String> getHeader() { try {
HashMap<String, String> hashMap = new HashMap<>(); requestParam = "{ \"userName\": \"" + ImasterConstant.account + "\", \"systemCode\": \""
String requestParam=""; + ImasterConstant.password + "\"}";
HashMap<String, String> hashMaphead = new HashMap<>(); } catch (Exception e) {
try { throw new RuntimeException(e);
requestParam = "{ \"userName\": \""+ImasterConstant.account+"\", \"systemCode\": \""+ImasterConstant.password+"\"}"; }
} catch (Exception e) { String url = ImasterConstant.baseurl + ImasterConstant.tokenUrl;
throw new RuntimeException(e); HttpResponse execute = HttpUtil.createRequest(Method.POST, url).body(requestParam).execute();
} String token = execute.header("xsrf-token");
String url = ImasterConstant.baseurl + ImasterConstant.tokenUrl;
HttpResponse execute = HttpUtil.createRequest(Method.POST, url).body(requestParam).execute();
String token = execute.header("xsrf-token");
hashMap.put("XSRF-TOKEN", token); hashMap.put("XSRF-TOKEN", token);
return hashMap; return hashMap;
} }
/** /**
* @param apiurl 请求url * @param apiurl 请求url
* @param requestMethod 请求方式 * @param requestMethod 请求方式
* @param requestParmInfo 请求参数mapper * @param requestParmInfo 请求参数mapper
* @param ResultResolveRule 请求的解析 * @param ResultResolveRule 请求的解析
* @param tClass 需要转换成的bean * @param tClass 需要转换成的bean
* @param <T> 泛型数据 * @param <T> 泛型数据
* @return List<T> list<Result> * @return List<T> list<Result>
* @desc 根据请求参数发送http请求并且对于返回的数据进行处理 * @desc 根据请求参数发送http请求并且对于返回的数据进行处理
*/ */
public <T> List<T> getResPonse(String apiurl, String requestMethod, String requestParmInfo, String ResultResolveRule, Class<T> tClass) { public <T> List<T> getResPonse(String apiurl, String requestMethod, String requestParmInfo,
String respone = ""; String ResultResolveRule, Class<T> tClass) {
String params = ""; String respone = "";
JSONArray jsonArray = null; String params = "";
List<T> result = new ArrayList<>(); JSONArray jsonArray = null;
try { List<T> result = new ArrayList<>();
Object o = redisUtils.get(redisKey); try {
if(o != null) { Object o = redisUtils.get(redisKey);
HashMap<String, String> headMap = new HashMap<>(); if (o != null) {
headMap.put("XSRF-TOKEN", o.toString()); HashMap<String, String> headMap = new HashMap<>();
String url = ImasterConstant.baseurl + apiurl; headMap.put("XSRF-TOKEN", o.toString());
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); String url = ImasterConstant.baseurl + apiurl;
JSONObject jsonObject = JSONObject.parseObject(respone); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
if(jsonObject.get("failCode").toString().equals("305")) { JSONObject jsonObject = JSONObject.parseObject(respone);
headMap = getHeader(); if (jsonObject.get("failCode").toString().equals("305")) {
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); headMap = getHeader();
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
if (!ObjectUtils.isEmpty(jsonArray)) { jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass); if (!ObjectUtils.isEmpty(jsonArray)) {
redisUtils.set(redisKey,headMap.get("XSRF-TOKEN")); result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
} redisUtils.set(redisKey, headMap.get("XSRF-TOKEN"));
} else { }
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone); } else {
if (!ObjectUtils.isEmpty(jsonArray)) { jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass); if (!ObjectUtils.isEmpty(jsonArray)) {
} result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
} }
} else { }
HashMap<String, String> headMap = getHeader(); } else {
String url = ImasterConstant.baseurl + apiurl; HashMap<String, String> headMap = getHeader();
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); String url = ImasterConstant.baseurl + apiurl;
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
if (!ObjectUtils.isEmpty(jsonArray)) { jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass); if (!ObjectUtils.isEmpty(jsonArray)) {
redisUtils.set(redisKey,headMap.get("XSRF-TOKEN")); result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
} redisUtils.set(redisKey, headMap.get("XSRF-TOKEN"));
} }
} catch (Exception exception) { }
return result; } catch (Exception exception) {
} return result;
return result; }
} return result;
}
/** /**
* @param apiurl 请求url * @param apiurl 请求url
* @param requestMethod 请求方式 * @param requestMethod 请求方式
* @param requestParmInfo 请求参数mapper * @param requestParmInfo 请求参数mapper
* @param ResultResolveRule 请求的解析 * @param ResultResolveRule 请求的解析
* @param tClass 需要转换成的bean * @param tClass 需要转换成的bean
* @param <T> 泛型数据 * @param <T> 泛型数据
* @return List<T> list<Result> * @return List<T> list<Result>
* @desc 根据请求参数发送http请求并且对于返回的数据进行处理 * @desc 根据请求参数发送http请求并且对于返回的数据进行处理
*/ */
public <T> List<T> getResPonseOther(String apiurl, String requestMethod, String requestParmInfo, String ResultResolveRule, Class<T> tClass) { public <T> List<T> getResPonseOther(String apiurl, String requestMethod, String requestParmInfo,
String respone = ""; String ResultResolveRule, Class<T> tClass) {
String params = ""; String respone = "";
JSONArray jsonArray = null; String params = "";
List<T> result = new ArrayList<>(); JSONArray jsonArray = null;
try { List<T> result = new ArrayList<>();
Object o = redisUtils.get(redisKey); try {
if(o != null) { Object o = redisUtils.get(redisKey);
HashMap<String, String> headMap = new HashMap<>(); if (o != null) {
headMap.put("XSRF-TOKEN", o.toString()); HashMap<String, String> headMap = new HashMap<>();
String url = ImasterConstant.baseurl + apiurl; headMap.put("XSRF-TOKEN", o.toString());
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); String url = ImasterConstant.baseurl + apiurl;
JSONObject jsonObject = JSONObject.parseObject(respone); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
if(jsonObject.get("failCode").toString().equals("305")) { JSONObject jsonObject = JSONObject.parseObject(respone);
headMap = getHeader(); if (jsonObject.get("failCode").toString().equals("305")) {
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); headMap = getHeader();
jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
if (!ObjectUtils.isEmpty(jsonArray)) { jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone);
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass); if (!ObjectUtils.isEmpty(jsonArray)) {
redisUtils.set(redisKey,headMap.get("XSRF-TOKEN")); result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
} redisUtils.set(redisKey, headMap.get("XSRF-TOKEN"));
} else { }
jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone); } else {
if (!ObjectUtils.isEmpty(jsonArray)) { jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone);
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass); if (!ObjectUtils.isEmpty(jsonArray)) {
} result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
} }
} else { }
HashMap<String, String> headMap = getHeader(); } else {
String url = ImasterConstant.baseurl + apiurl; HashMap<String, String> headMap = getHeader();
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); String url = ImasterConstant.baseurl + apiurl;
jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
if (!ObjectUtils.isEmpty(jsonArray)) { jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone);
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass); if (!ObjectUtils.isEmpty(jsonArray)) {
redisUtils.set(redisKey,headMap.get("XSRF-TOKEN")); result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
} redisUtils.set(redisKey, headMap.get("XSRF-TOKEN"));
} }
} catch (Exception exception) { }
exception.printStackTrace(); } catch (Exception exception) {
return result; exception.printStackTrace();
} return result;
return result; }
} return result;
}
/** /**
* @param resultResovle 请求返回的解析规则 来源与数据库 * @param resultResovle 请求返回的解析规则 来源与数据库
* @param response 请求返回的字符串 * @param response 请求返回的字符串
* @return 解析后的数据 * @return 解析后的数据
* @desc 根据解析规则解析请求返回数据 * @desc 根据解析规则解析请求返回数据
*/ */
public static JSONArray handlerResponseByResultResolverule(String resultResovle, String response) { public static JSONArray handlerResponseByResultResolverule(String resultResovle, String response) {
JSONObject jsonObject = JSONObject.parseObject(response); JSONObject jsonObject = JSONObject.parseObject(response);
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
if (ObjectUtil.isNotEmpty(resultResovle)) { if (ObjectUtil.isNotEmpty(resultResovle)) {
String[] rules = resultResovle.split(","); String[] rules = resultResovle.split(",");
if (rules.length > 0) { if (rules.length > 0) {
for (int i = 0; i < rules.length; i++) { for (int i = 0; i < rules.length; i++) {
try { try {
jsonObject = (JSONObject) jsonObject.get(rules[i]); jsonObject = (JSONObject) jsonObject.get(rules[i]);
if (jsonObject == null) { if (jsonObject == null) {
jsonArray = (JSONArray) jsonObject.get(rules[i]); jsonArray = (JSONArray) jsonObject.get(rules[i]);
} }
} catch (Exception exception) { } catch (Exception exception) {
jsonArray = (JSONArray) jsonObject.get(rules[i]); jsonArray = (JSONArray) jsonObject.get(rules[i]);
} }
} }
} }
if (jsonArray.size() == 0) { if (jsonArray.size() == 0) {
jsonArray.addAll((JSONArray)jsonObject.get("list")); jsonArray.addAll((JSONArray) jsonObject.get("list"));
} }
} }
return jsonArray; return jsonArray;
} }
/** /**
* @param resultResovle 请求返回的解析规则 来源与数据库 * @param resultResovle 请求返回的解析规则 来源与数据库
* @param response 请求返回的字符串 * @param response 请求返回的字符串
* @return 解析后的数据 * @return 解析后的数据
* @desc 根据解析规则解析请求返回数据 * @desc 根据解析规则解析请求返回数据
*/ */
public static JSONArray handlerResponseByResultResolveruleOther(String resultResovle, String response) { public static JSONArray handlerResponseByResultResolveruleOther(String resultResovle, String response) {
JSONObject jsonObject = JSONObject.parseObject(response); JSONObject jsonObject = JSONObject.parseObject(response);
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
JSONArray jsonArrayRet = new JSONArray(); JSONArray jsonArrayRet = new JSONArray();
if (ObjectUtil.isNotEmpty(resultResovle)) { if (ObjectUtil.isNotEmpty(resultResovle)) {
String[] rules = resultResovle.split(","); String[] rules = resultResovle.split(",");
if (rules.length > 0) { if (rules.length > 0) {
for (int i = 0; i < rules.length; i++) { for (int i = 0; i < rules.length; i++) {
try { try {
jsonObject = (JSONObject) jsonObject.get(rules[i]); jsonObject = (JSONObject) jsonObject.get(rules[i]);
if (jsonObject == null) { if (jsonObject == null) {
jsonArray = (JSONArray) jsonObject.get(rules[i]); jsonArray = (JSONArray) jsonObject.get(rules[i]);
} }
} catch (Exception exception) { } catch (Exception exception) {
jsonArray = (JSONArray) jsonObject.get(rules[i]); try {
} jsonArray = (JSONArray) jsonObject.get(rules[i]);
} } catch (Exception e) {
} e.printStackTrace();
if (jsonArray.size() != 0) { logger.error("华为数据解析错误:" + jsonObject.get(rules[i]));
for( int i=0; i<jsonArray.size();i++ ) { }
JSONObject jsonObject1 = (JSONObject) jsonArray.get(i); }
if(jsonObject1.get("dataItemMap") != null) { }
JSONObject jsonObject2 = (JSONObject)jsonObject1.get("dataItemMap"); }
if(jsonObject1.get("sn") != null) { if (jsonArray.size() != 0) {
jsonObject2.put("inverterId", jsonObject1.get("sn").toString()); for (int i = 0; i < jsonArray.size(); i++) {
} JSONObject jsonObject1 = (JSONObject) jsonArray.get(i);
if(jsonObject1.get("stationCode") != null) { if (jsonObject1.get("dataItemMap") != null) {
jsonObject2.put("stationCode", jsonObject1.get("stationCode").toString()); JSONObject jsonObject2 = (JSONObject) jsonObject1.get("dataItemMap");
} if (jsonObject1.get("sn") != null) {
if(jsonObject1.get("collectTime") != null) { jsonObject2.put("inverterId", jsonObject1.get("sn").toString());
jsonObject2.put("collectTime", jsonObject1.get("collectTime").toString()); }
} if (jsonObject1.get("stationCode") != null) {
jsonObject2.put("stationCode", jsonObject1.get("stationCode").toString());
}
if (jsonObject1.get("collectTime") != null) {
jsonObject2.put("collectTime", jsonObject1.get("collectTime").toString());
}
jsonArrayRet.add(jsonObject2); jsonArrayRet.add(jsonObject2);
} }
} }
} }
} }
return jsonArrayRet; return jsonArrayRet;
} }
public String sendRequest(String requestMethod, String url, String params, HashMap<String, String> headMap) { public String sendRequest(String requestMethod, String url, String params, HashMap<String, String> headMap) {
HousepvapiRecords housepvapiRecords = new HousepvapiRecords(); HousepvapiRecords housepvapiRecords = new HousepvapiRecords();
housepvapiRecords.setRecDate(new Date()); housepvapiRecords.setRecDate(new Date());
housepvapiRecords.setRequestUrl(url); housepvapiRecords.setRequestUrl(url);
housepvapiRecords.setRequestMothed(requestMethod); housepvapiRecords.setRequestMothed(requestMethod);
housepvapiRecords.setRequestHeaders(JSONObject.toJSONString(headMap)); housepvapiRecords.setRequestHeaders(JSONObject.toJSONString(headMap));
housepvapiRecords.setRequestParams(params); housepvapiRecords.setRequestParams(params);
housepvapiRecords.setThridCode(PVProducerInfoEnum.HUAWEI.getCode()); housepvapiRecords.setThridCode(PVProducerInfoEnum.HUAWEI.getCode());
String respone = ""; String respone = "";
if (requestMethod.equals("POST")) { if (requestMethod.equals("POST")) {
respone = HttpUtil.createPost(url).headerMap(headMap, false). respone = HttpUtil.createPost(url).headerMap(headMap, false).body(params).execute().body();
body(params).execute().body(); }
} if (requestMethod.equals("GET")) {
if (requestMethod.equals("GET")) { respone = HttpUtil.createGet(url).headerMap(headMap, true).body(params).execute().body();
respone = HttpUtil.createGet(url).headerMap(headMap, true). }
body(params).execute().body(); housepvapiRecords.setResponse(respone);
} // housepvapiRecordsMapper.insert(housepvapiRecords);
housepvapiRecords.setResponse(respone); // log.info("华为数据请求详情:"+JSONObject.toJSONString(housepvapiRecords));
// housepvapiRecordsMapper.insert(housepvapiRecords); return respone;
//log.info("华为数据请求详情:"+JSONObject.toJSONString(housepvapiRecords)); }
return respone;
}
/*** /***
* *
* @param params 参数字符窜 * @param params 参数字符窜
* @param headMap header头 * @param headMap header头
* @param orginalAuthorization 原始的orginalAuthorization * @param orginalAuthorization 原始的orginalAuthorization
* @param appsecret appsecret * @param appsecret appsecret
* @desc 锦浪云请求参数及head头处理 * @desc 锦浪云请求参数及head头处理
*/ */
public void JLYHeaderMapHandler(String params, HashMap<String, String> headMap, String orginalAuthorization, String appsecret, String apiurl) { public void JLYHeaderMapHandler(String params, HashMap<String, String> headMap, String orginalAuthorization,
String contentMD5 = GoLangHeaderUtils.getDigest(params); String appsecret, String apiurl) {
headMap.put("Date", GoLangHeaderUtils.getGMTTime()); String contentMD5 = GoLangHeaderUtils.getDigest(params);
String param = "POST" + "\n" + contentMD5 + "\n" + "application/json" + "\n" + headMap.get("Date") + "\n" + apiurl; headMap.put("Date", GoLangHeaderUtils.getGMTTime());
String sign = ""; String param = "POST" + "\n" + contentMD5 + "\n" + "application/json" + "\n" + headMap.get("Date") + "\n"
try { + apiurl;
sign = GoLangHeaderUtils.HmacSHA1Encrypt(param, appsecret); String sign = "";
} catch (Exception e) { try {
throw new RuntimeException(e); sign = GoLangHeaderUtils.HmacSHA1Encrypt(param, appsecret);
} } catch (Exception e) {
headMap.put("Content-MD5", contentMD5); throw new RuntimeException(e);
headMap.put("Authorization", orginalAuthorization + sign); }
} headMap.put("Content-MD5", contentMD5);
headMap.put("Authorization", orginalAuthorization + sign);
}
/** /**
* @param pageSizeResovle * @param pageSizeResovle
* @param response * @param response
* @return * @return
* @desc 根据分页规则 获取分页数 * @desc 根据分页规则 获取分页数
*/ */
public Integer getPagesize(String pageSizeResovle, String response) { public Integer getPagesize(String pageSizeResovle, String response) {
Integer pageSize = 0; Integer pageSize = 0;
String[] rules = pageSizeResovle.split(","); String[] rules = pageSizeResovle.split(",");
JSONObject jsonObject = JSONObject.parseObject(response); JSONObject jsonObject = JSONObject.parseObject(response);
if (rules.length > 0) { if (rules.length > 0) {
for (int i = 0; i < rules.length - 1; i++) { for (int i = 0; i < rules.length - 1; i++) {
jsonObject = (JSONObject) jsonObject.get(rules[i]); jsonObject = (JSONObject) jsonObject.get(rules[i]);
} }
} }
pageSize = (Integer) jsonObject.get(rules[rules.length - 1]); pageSize = (Integer) jsonObject.get(rules[rules.length - 1]);
return pageSize; return pageSize;
} }
// public static void main(String[] args) { // public static void main(String[] args) {
// HashMap<String, Object> requestInfo = new HashMap<>(); // HashMap<String, Object> requestInfo = new HashMap<>();
......
...@@ -70,7 +70,7 @@ public class KsolarRequestUtil { ...@@ -70,7 +70,7 @@ public class KsolarRequestUtil {
String url = KSolarConstant.baseurl + apiurl; String url = KSolarConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone); jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
log.info("原始数据:{}", jsonArray); //log.info("原始数据:{}", jsonArray);
if (!ObjectUtils.isEmpty(jsonArray)) { if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass); result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
} }
......
...@@ -320,7 +320,7 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe ...@@ -320,7 +320,7 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe
@Async @Async
public void stationDetail() { public void stationDetail() {
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
logger.info("-------固德威同步场站和告警开始" + ts + "------- " + sdf.format(new Date())); logger.info("-------固德威同步场站详情开始" + ts + "------- " + sdf.format(new Date()));
List<String> stationIds = goodWeStationMonitorListMapper.getStationIds(); List<String> stationIds = goodWeStationMonitorListMapper.getStationIds();
stationIds.forEach(stationId -> { stationIds.forEach(stationId -> {
HashMap<String, Object> requestInfo = new HashMap<>(); HashMap<String, Object> requestInfo = new HashMap<>();
...@@ -349,7 +349,7 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe ...@@ -349,7 +349,7 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe
}); });
} }
}); });
logger.info("-------固德威同步场站和告警结束" + ts + "------- " + sdf.format(new Date())); logger.info("-------固德威同步场站详情结束" + ts + "------- " + sdf.format(new Date()));
} }
@Override @Override
......
...@@ -495,10 +495,8 @@ public class SunlightServiceImpl implements SunlightService { ...@@ -495,10 +495,8 @@ public class SunlightServiceImpl implements SunlightService {
if (device != null) { if (device != null) {
// 获取逆变器信息存库 // 获取逆变器信息存库
JpInverter jpInverter = jpInverterMapper.selectOne( JpInverter jpInverter = jpInverterMapper.selectOne(
new QueryWrapper<JpInverter>().eq("third_station_id", device.getPs_id().toString()) new QueryWrapper<JpInverter>().eq("sn_code", device.getDevice_sn().toString())
.eq("third_code", PVProducerInfoEnum.YG.getCode()) .eq("third_code", PVProducerInfoEnum.YG.getCode()));
.eq("ID", device.getUuid().toString()));
if (ObjectUtils.isEmpty(jpInverter)) { if (ObjectUtils.isEmpty(jpInverter)) {
jpInverter = new JpInverter(); jpInverter = new JpInverter();
} }
...@@ -911,10 +909,17 @@ public class SunlightServiceImpl implements SunlightService { ...@@ -911,10 +909,17 @@ public class SunlightServiceImpl implements SunlightService {
jpCollector.setThirdStationId(jpStation.getThirdStationId()); jpCollector.setThirdStationId(jpStation.getThirdStationId());
// 第三方厂商标识 // 第三方厂商标识
jpCollector.setThirdCode(PVProducerInfoEnum.YG.getCode()); jpCollector.setThirdCode(PVProducerInfoEnum.YG.getCode());
if (device.getGetPs_fault_status() > 2) { if (device.getGetPs_fault_status() != null) {
jpCollector.setState(SunlightUtil.zt.get(device.getDev_status() + "")); if (device.getGetPs_fault_status() > 2) {
jpCollector.setState(SunlightUtil.zt.get(device.getDev_status() + ""));
} else {
jpCollector.setState("报警");// 电站状态
}
} else { } else {
jpCollector.setState("报警");// 电站状态 //如果获取不了逆变器状态 并且逆变器没状态就默认离线
if (jpCollector.getState() == null) {
jpCollector.setState("离线");
}
} }
jpCollector.setStationName(jpStation.getName()); jpCollector.setStationName(jpStation.getName());
// jpCollector.setVersion(imasterCollectorList.getSoftwareVersion()); // jpCollector.setVersion(imasterCollectorList.getSoftwareVersion());
......
package com.yeejoin.amos.config;
import java.lang.reflect.Method;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import com.yeejoin.amos.HousevPVapiApplication;
@EnableAsync
@Configuration
@Primary
public class ListenerAsyncConfiguration implements AsyncConfigurer {
private static final Logger logger = LogManager.getLogger(ListenerAsyncConfiguration.class);
/**
* 用于@Async注解获取默认线程连接池
*
* @return
*/
@Override
public Executor getAsyncExecutor() {
// 此类由Spring提供,org.springframework.scheduling.concurrent包下,是线程池的封装类
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
// 线程池中线程的名字前缀
taskExecutor.setThreadNamePrefix("taskThreadPool-async-");
// 线程池核心线程数量
taskExecutor.setCorePoolSize(20);
// 线程池最大线程数量
taskExecutor.setMaxPoolSize(50);
// 线程池空闲线程存活时间,单位秒
taskExecutor.setKeepAliveSeconds(100);
// 线程池拒绝策略
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy());
// 线程池任务队容量,如果不设置则默认 Integer.MAX_VALUE,
// 队列默认使用LinkedBlockingQueue 若queueCapacity的值 <= 0,则使用SynchronousQueue
taskExecutor.setQueueCapacity(1000);
// 线程池中核心线程是否允许超时,默认为false
taskExecutor.setAllowCoreThreadTimeOut(true);
// 线程池中的超时处理时间,单位秒,有一个对应方法为毫秒,默认为不超时
taskExecutor.setAwaitTerminationSeconds(60);
// 初始化线程池,不可以少,否者会抛出 线程池没有初始化
taskExecutor.initialize();
return taskExecutor;
}
/**
* 线程未处理异常的统一处理机制,即线程池异常处理器,简单示例
*
* @return
*/
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
// 异常处理器函数接口类
return new AsyncUncaughtExceptionHandler() {
@Override
public void handleUncaughtException(Throwable throwable, Method method, Object... objects) {
logger.error("============ " + throwable.getMessage() + " ===========", throwable);
logger.error("============ " + method.getName() + " ===========", objects);
}
};
}
}
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