Commit 9bfb81c7 authored by wujiang's avatar wujiang

修改采集问题

parent 8f3f8ec6
...@@ -11,13 +11,16 @@ import com.yeejoin.amos.api.householdapi.constant.ImasterConstant; ...@@ -11,13 +11,16 @@ 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
...@@ -30,16 +33,20 @@ public class ImasterUtils { ...@@ -30,16 +33,20 @@ public class ImasterUtils {
HousepvapiRecordsMapper housepvapiRecordsMapper; HousepvapiRecordsMapper housepvapiRecordsMapper;
@Autowired @Autowired
RedisUtils redisUtils; RedisUtils redisUtils;
final static Logger logger = LoggerFactory.getLogger(ImasterUtils.class);
/** /**
* @return HashMap<String, Object> 发送请求前的准备 准备header信息 * @return HashMap<String, Object> 发送请求前的准备 准备header信息
* @deprecated 根据厂商编码获取厂商的hearer * @deprecated 根据厂商编码获取厂商的hearer
*/ */
public static HashMap<String, String> getHeader() { public static HashMap<String, String> getHeader() {
HashMap<String, String> hashMap = new HashMap<>(); HashMap<String, String> hashMap = new HashMap<>();
String requestParam=""; String requestParam = "";
HashMap<String, String> hashMaphead = new HashMap<>(); HashMap<String, String> hashMaphead = new HashMap<>();
try { try {
requestParam = "{ \"userName\": \""+ImasterConstant.account+"\", \"systemCode\": \""+ImasterConstant.password+"\"}"; requestParam = "{ \"userName\": \"" + ImasterConstant.account + "\", \"systemCode\": \""
+ ImasterConstant.password + "\"}";
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -61,26 +68,27 @@ public class ImasterUtils { ...@@ -61,26 +68,27 @@ public class ImasterUtils {
* @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 ResultResolveRule, Class<T> tClass) {
String respone = ""; String respone = "";
String params = ""; String params = "";
JSONArray jsonArray = null; JSONArray jsonArray = null;
List<T> result = new ArrayList<>(); List<T> result = new ArrayList<>();
try { try {
Object o = redisUtils.get(redisKey); Object o = redisUtils.get(redisKey);
if(o != null) { if (o != null) {
HashMap<String, String> headMap = new HashMap<>(); HashMap<String, String> headMap = new HashMap<>();
headMap.put("XSRF-TOKEN", o.toString()); headMap.put("XSRF-TOKEN", o.toString());
String url = ImasterConstant.baseurl + apiurl; String url = ImasterConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
JSONObject jsonObject = JSONObject.parseObject(respone); JSONObject jsonObject = JSONObject.parseObject(respone);
if(jsonObject.get("failCode").toString().equals("305")) { if (jsonObject.get("failCode").toString().equals("305")) {
headMap = getHeader(); headMap = getHeader();
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone); jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
if (!ObjectUtils.isEmpty(jsonArray)) { if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass); result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
redisUtils.set(redisKey,headMap.get("XSRF-TOKEN")); redisUtils.set(redisKey, headMap.get("XSRF-TOKEN"));
} }
} else { } else {
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone); jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
...@@ -95,7 +103,7 @@ public class ImasterUtils { ...@@ -95,7 +103,7 @@ public class ImasterUtils {
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone); jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
if (!ObjectUtils.isEmpty(jsonArray)) { if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass); result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
redisUtils.set(redisKey,headMap.get("XSRF-TOKEN")); redisUtils.set(redisKey, headMap.get("XSRF-TOKEN"));
} }
} }
} catch (Exception exception) { } catch (Exception exception) {
...@@ -114,26 +122,27 @@ public class ImasterUtils { ...@@ -114,26 +122,27 @@ public class ImasterUtils {
* @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 ResultResolveRule, Class<T> tClass) {
String respone = ""; String respone = "";
String params = ""; String params = "";
JSONArray jsonArray = null; JSONArray jsonArray = null;
List<T> result = new ArrayList<>(); List<T> result = new ArrayList<>();
try { try {
Object o = redisUtils.get(redisKey); Object o = redisUtils.get(redisKey);
if(o != null) { if (o != null) {
HashMap<String, String> headMap = new HashMap<>(); HashMap<String, String> headMap = new HashMap<>();
headMap.put("XSRF-TOKEN", o.toString()); headMap.put("XSRF-TOKEN", o.toString());
String url = ImasterConstant.baseurl + apiurl; String url = ImasterConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
JSONObject jsonObject = JSONObject.parseObject(respone); JSONObject jsonObject = JSONObject.parseObject(respone);
if(jsonObject.get("failCode").toString().equals("305")) { if (jsonObject.get("failCode").toString().equals("305")) {
headMap = getHeader(); headMap = getHeader();
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone); jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone);
if (!ObjectUtils.isEmpty(jsonArray)) { if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass); result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
redisUtils.set(redisKey,headMap.get("XSRF-TOKEN")); redisUtils.set(redisKey, headMap.get("XSRF-TOKEN"));
} }
} else { } else {
jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone); jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone);
...@@ -148,7 +157,7 @@ public class ImasterUtils { ...@@ -148,7 +157,7 @@ public class ImasterUtils {
jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone); jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone);
if (!ObjectUtils.isEmpty(jsonArray)) { if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass); result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
redisUtils.set(redisKey,headMap.get("XSRF-TOKEN")); redisUtils.set(redisKey, headMap.get("XSRF-TOKEN"));
} }
} }
} catch (Exception exception) { } catch (Exception exception) {
...@@ -182,7 +191,7 @@ public class ImasterUtils { ...@@ -182,7 +191,7 @@ public class ImasterUtils {
} }
} }
if (jsonArray.size() == 0) { if (jsonArray.size() == 0) {
jsonArray.addAll((JSONArray)jsonObject.get("list")); jsonArray.addAll((JSONArray) jsonObject.get("list"));
} }
} }
return jsonArray; return jsonArray;
...@@ -208,22 +217,27 @@ public class ImasterUtils { ...@@ -208,22 +217,27 @@ public class ImasterUtils {
jsonArray = (JSONArray) jsonObject.get(rules[i]); jsonArray = (JSONArray) jsonObject.get(rules[i]);
} }
} catch (Exception exception) { } catch (Exception exception) {
try {
jsonArray = (JSONArray) jsonObject.get(rules[i]); jsonArray = (JSONArray) jsonObject.get(rules[i]);
} catch (Exception e) {
e.printStackTrace();
logger.error("华为数据解析错误:" + jsonObject.get(rules[i]));
}
} }
} }
} }
if (jsonArray.size() != 0) { if (jsonArray.size() != 0) {
for( int i=0; i<jsonArray.size();i++ ) { for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject1 = (JSONObject) jsonArray.get(i); JSONObject jsonObject1 = (JSONObject) jsonArray.get(i);
if(jsonObject1.get("dataItemMap") != null) { if (jsonObject1.get("dataItemMap") != null) {
JSONObject jsonObject2 = (JSONObject)jsonObject1.get("dataItemMap"); JSONObject jsonObject2 = (JSONObject) jsonObject1.get("dataItemMap");
if(jsonObject1.get("sn") != null) { if (jsonObject1.get("sn") != null) {
jsonObject2.put("inverterId", jsonObject1.get("sn").toString()); jsonObject2.put("inverterId", jsonObject1.get("sn").toString());
} }
if(jsonObject1.get("stationCode") != null) { if (jsonObject1.get("stationCode") != null) {
jsonObject2.put("stationCode", jsonObject1.get("stationCode").toString()); jsonObject2.put("stationCode", jsonObject1.get("stationCode").toString());
} }
if(jsonObject1.get("collectTime") != null) { if (jsonObject1.get("collectTime") != null) {
jsonObject2.put("collectTime", jsonObject1.get("collectTime").toString()); jsonObject2.put("collectTime", jsonObject1.get("collectTime").toString());
} }
...@@ -245,16 +259,14 @@ public class ImasterUtils { ...@@ -245,16 +259,14 @@ public class ImasterUtils {
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). respone = HttpUtil.createGet(url).headerMap(headMap, true).body(params).execute().body();
body(params).execute().body();
} }
housepvapiRecords.setResponse(respone); housepvapiRecords.setResponse(respone);
// housepvapiRecordsMapper.insert(housepvapiRecords); // housepvapiRecordsMapper.insert(housepvapiRecords);
//log.info("华为数据请求详情:"+JSONObject.toJSONString(housepvapiRecords)); // log.info("华为数据请求详情:"+JSONObject.toJSONString(housepvapiRecords));
return respone; return respone;
} }
...@@ -266,10 +278,12 @@ public class ImasterUtils { ...@@ -266,10 +278,12 @@ public class ImasterUtils {
* @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 appsecret, String apiurl) {
String contentMD5 = GoLangHeaderUtils.getDigest(params); String contentMD5 = GoLangHeaderUtils.getDigest(params);
headMap.put("Date", GoLangHeaderUtils.getGMTTime()); headMap.put("Date", GoLangHeaderUtils.getGMTTime());
String param = "POST" + "\n" + contentMD5 + "\n" + "application/json" + "\n" + headMap.get("Date") + "\n" + apiurl; String param = "POST" + "\n" + contentMD5 + "\n" + "application/json" + "\n" + headMap.get("Date") + "\n"
+ apiurl;
String sign = ""; String sign = "";
try { try {
sign = GoLangHeaderUtils.HmacSHA1Encrypt(param, appsecret); sign = GoLangHeaderUtils.HmacSHA1Encrypt(param, appsecret);
......
...@@ -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();
} }
......
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