Commit c6da4be4 authored by hezhuozhi's avatar hezhuozhi

添加日志

parent 1c31154b
...@@ -64,15 +64,18 @@ public class GolangRequestUtil { ...@@ -64,15 +64,18 @@ public class GolangRequestUtil {
JSONArray jsonArray = null; JSONArray jsonArray = null;
List<T> result = new ArrayList<>(); List<T> result = new ArrayList<>();
Integer pageNo = 1; Integer pageNo = 1;
String url ="";
HashMap<String, String> headMap = new HashMap<>();
String requestParmInfo ="";
try { try {
do { do {
requestInfo.put("pageNo", pageNo); requestInfo.put("pageNo", pageNo);
String requestParmInfo = JSON.toJSONString(requestInfo); requestParmInfo = JSON.toJSONString(requestInfo);
HashMap<String, Object> producerInfo = getHeaderOfGolang(); HashMap<String, Object> producerInfo = getHeaderOfGolang();
String baseurl = (String) producerInfo.get("apiurl"); String baseurl = (String) producerInfo.get("apiurl");
HashMap<String, String> headMap = (HashMap<String, String>) producerInfo.get("header"); headMap= (HashMap<String, String>) producerInfo.get("header");
String orginalAuthorization = headMap.get("Authorization") + ":"; String orginalAuthorization = headMap.get("Authorization") + ":";
String url = baseurl + apiurl; url = baseurl + apiurl;
String appsecret = (String) producerInfo.get("appsecret"); String appsecret = (String) producerInfo.get("appsecret");
JLYHeaderMapHandler(params, headMap, orginalAuthorization, appsecret, apiurl); JLYHeaderMapHandler(params, headMap, orginalAuthorization, appsecret, apiurl);
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
...@@ -99,7 +102,7 @@ public class GolangRequestUtil { ...@@ -99,7 +102,7 @@ public class GolangRequestUtil {
JSONObject page = data.getJSONObject("page"); JSONObject page = data.getJSONObject("page");
responePages = page.getInteger("pages"); responePages = page.getInteger("pages");
} }
if (responePages == pageNo){ if (responePages <= pageNo){
break; break;
} else { } else {
pageNo++; pageNo++;
...@@ -107,6 +110,15 @@ public class GolangRequestUtil { ...@@ -107,6 +110,15 @@ public class GolangRequestUtil {
}while (true); }while (true);
} catch (Exception exception) { } catch (Exception exception) {
log.error(exception.getMessage(),exception); log.error(exception.getMessage(),exception);
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.JLY.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
return result; return result;
} }
return result; return result;
...@@ -127,12 +139,14 @@ public class GolangRequestUtil { ...@@ -127,12 +139,14 @@ public class GolangRequestUtil {
String params = ""; String params = "";
JSONArray jsonArray = null; JSONArray jsonArray = null;
List<T> result = new ArrayList<>(); List<T> result = new ArrayList<>();
String url ="";
HashMap<String, String> headMap = new HashMap<>();
try { try {
HashMap<String, Object> producerInfo = getHeaderOfGolang(); HashMap<String, Object> producerInfo = getHeaderOfGolang();
String baseurl = (String) producerInfo.get("apiurl"); String baseurl = (String) producerInfo.get("apiurl");
HashMap<String, String> headMap = (HashMap<String, String>) producerInfo.get("header"); headMap = (HashMap<String, String>) producerInfo.get("header");
String orginalAuthorization = headMap.get("Authorization") + ":"; String orginalAuthorization = headMap.get("Authorization") + ":";
String url = baseurl + apiurl; url = baseurl + apiurl;
String appsecret = (String) producerInfo.get("appsecret"); String appsecret = (String) producerInfo.get("appsecret");
JLYHeaderMapHandler(params, headMap, orginalAuthorization, appsecret, apiurl); JLYHeaderMapHandler(params, headMap, orginalAuthorization, appsecret, apiurl);
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
...@@ -150,6 +164,15 @@ public class GolangRequestUtil { ...@@ -150,6 +164,15 @@ public class GolangRequestUtil {
hygfThirdStationLog.setResBody(respone); hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog); thirdStationLogService.saveLog(hygfThirdStationLog);
} catch (Exception exception) { } catch (Exception exception) {
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.JLY.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
return result; return result;
} }
return result; return result;
......
...@@ -65,12 +65,15 @@ public class GoodWeRequestUtil { ...@@ -65,12 +65,15 @@ public class GoodWeRequestUtil {
JSONArray jsonArray = null; JSONArray jsonArray = null;
List<T> result = new ArrayList<>(); List<T> result = new ArrayList<>();
Integer pageNo = 1; Integer pageNo = 1;
String url ="";
HashMap<String, String> headMap = new HashMap<>();
String requestParmInfo ="";
try { try {
do { do {
requestInfo.put("page_index", pageNo); requestInfo.put("page_index", pageNo);
String requestParmInfo = fastjson.JSON.toJSONString(requestInfo); requestParmInfo = fastjson.JSON.toJSONString(requestInfo);
HashMap<String, String> headMap = getHeaderOfGoodWE(); headMap = getHeaderOfGoodWE();
String url = GoodWeConstant.baseurl + apiurl; url = GoodWeConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
//token如果失效重新获取{"code":100002,"msg":"授权已失效,请重新登录","data":null} //token如果失效重新获取{"code":100002,"msg":"授权已失效,请重新登录","data":null}
if(JSONObject.parseObject(respone).getInteger("code") == 100002){ if(JSONObject.parseObject(respone).getInteger("code") == 100002){
...@@ -96,7 +99,7 @@ public class GoodWeRequestUtil { ...@@ -96,7 +99,7 @@ public class GoodWeRequestUtil {
Integer record = data.getInteger("record"); Integer record = data.getInteger("record");
Integer pageSize= requestInfo.get("page_size")==null || (Integer)requestInfo.get("page_size")==0? 1:(Integer)requestInfo.get("page_size"); Integer pageSize= requestInfo.get("page_size")==null || (Integer)requestInfo.get("page_size")==0? 1:(Integer)requestInfo.get("page_size");
Integer responePages=(record/pageSize)+1; Integer responePages=(record/pageSize)+1;
if (responePages == pageNo){ if (responePages <= pageNo){
break; break;
} else { } else {
pageNo++; pageNo++;
...@@ -104,6 +107,15 @@ public class GoodWeRequestUtil { ...@@ -104,6 +107,15 @@ public class GoodWeRequestUtil {
} while (true); } while (true);
} catch (Exception exception) { } catch (Exception exception) {
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.GDW.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
return result; return result;
} }
return result; return result;
...@@ -124,9 +136,11 @@ public class GoodWeRequestUtil { ...@@ -124,9 +136,11 @@ public class GoodWeRequestUtil {
String params = ""; String params = "";
JSONArray jsonArray = null; JSONArray jsonArray = null;
List<T> result = new ArrayList<>(); List<T> result = new ArrayList<>();
String url ="";
HashMap<String, String> headMap = new HashMap<>();
try { try {
HashMap<String, String> headMap = getHeaderOfGoodWE(); headMap = getHeaderOfGoodWE();
String url = GoodWeConstant.baseurl + apiurl; url = GoodWeConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
//token如果失效重新获取{"code":100002,"msg":"授权已失效,请重新登录","data":null} //token如果失效重新获取{"code":100002,"msg":"授权已失效,请重新登录","data":null}
if(JSONObject.parseObject(respone).getInteger("code") == 100002){ if(JSONObject.parseObject(respone).getInteger("code") == 100002){
...@@ -147,6 +161,15 @@ public class GoodWeRequestUtil { ...@@ -147,6 +161,15 @@ public class GoodWeRequestUtil {
hygfThirdStationLog.setResBody(respone); hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog); thirdStationLogService.saveLog(hygfThirdStationLog);
} catch (Exception exception) { } catch (Exception exception) {
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.GDW.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
return result; return result;
} }
return result; return result;
......
...@@ -77,10 +77,11 @@ public class ImasterUtils { ...@@ -77,10 +77,11 @@ public class ImasterUtils {
String params = ""; String params = "";
JSONArray jsonArray = null; JSONArray jsonArray = null;
List<T> result = new ArrayList<>(); List<T> result = new ArrayList<>();
HashMap<String, String> headMap =new HashMap<>();
try { try {
Object o = redisUtils.get(redisKey); Object o = redisUtils.get(redisKey);
if (o != null) { if (o != null) {
HashMap<String, String> headMap = new HashMap<>(); 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);
...@@ -109,7 +110,7 @@ public class ImasterUtils { ...@@ -109,7 +110,7 @@ public class ImasterUtils {
hygfThirdStationLog.setResBody(respone); hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog); thirdStationLogService.saveLog(hygfThirdStationLog);
} else { } else {
HashMap<String, String> headMap = getHeader(); headMap = getHeader();
String url = ImasterConstant.baseurl + apiurl; String url = ImasterConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone); jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
...@@ -128,6 +129,15 @@ public class ImasterUtils { ...@@ -128,6 +129,15 @@ public class ImasterUtils {
thirdStationLogService.saveLog(hygfThirdStationLog); thirdStationLogService.saveLog(hygfThirdStationLog);
} }
} catch (Exception exception) { } catch (Exception exception) {
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(ImasterConstant.baseurl + apiurl);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
return result; return result;
} }
return result; return result;
...@@ -149,10 +159,11 @@ public class ImasterUtils { ...@@ -149,10 +159,11 @@ public class ImasterUtils {
String params = ""; String params = "";
JSONArray jsonArray = null; JSONArray jsonArray = null;
List<T> result = new ArrayList<>(); List<T> result = new ArrayList<>();
HashMap<String, String> headMap = new HashMap<>();
try { try {
Object o = redisUtils.get(redisKey); Object o = redisUtils.get(redisKey);
if (o != null) { if (o != null) {
HashMap<String, String> headMap = new HashMap<>(); 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);
...@@ -186,7 +197,7 @@ public class ImasterUtils { ...@@ -186,7 +197,7 @@ public class ImasterUtils {
hygfThirdStationLog.setResBody(respone); hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog); thirdStationLogService.saveLog(hygfThirdStationLog);
} else { } else {
HashMap<String, String> headMap = getHeader(); headMap = getHeader();
String url = ImasterConstant.baseurl + apiurl; String url = ImasterConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone); jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone);
...@@ -206,6 +217,15 @@ public class ImasterUtils { ...@@ -206,6 +217,15 @@ public class ImasterUtils {
} }
} catch (Exception exception) { } catch (Exception exception) {
exception.printStackTrace(); exception.printStackTrace();
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(ImasterConstant.baseurl + apiurl);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
return result; return result;
} }
return result; return result;
......
...@@ -65,9 +65,11 @@ public class KsolarRequestUtil { ...@@ -65,9 +65,11 @@ public class KsolarRequestUtil {
String params = ""; String params = "";
JSONArray jsonArray = null; JSONArray jsonArray = null;
List<T> result = new ArrayList<>(); List<T> result = new ArrayList<>();
String url ="";
HashMap<String, String> headMap = new HashMap<>();
try { try {
HashMap<String, String> headMap = getHeader(); headMap = getHeader();
String url = KSolarConstant.baseurl + apiurl; 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);
...@@ -84,6 +86,15 @@ public class KsolarRequestUtil { ...@@ -84,6 +86,15 @@ public class KsolarRequestUtil {
hygfThirdStationLog.setResBody(respone); hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog); thirdStationLogService.saveLog(hygfThirdStationLog);
} catch (Exception exception) { } catch (Exception exception) {
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.KSOLAR.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
return result; return result;
} }
return result; return result;
......
...@@ -134,7 +134,7 @@ public class SofarRequestUtil { ...@@ -134,7 +134,7 @@ public class SofarRequestUtil {
Integer total = responeJSON.getInteger("total"); Integer total = responeJSON.getInteger("total");
Integer pageSize= requestInfo.get("size")==null || (Integer)requestInfo.get("size")==0? 1:(Integer)requestInfo.get("size"); Integer pageSize= requestInfo.get("size")==null || (Integer)requestInfo.get("size")==0? 1:(Integer)requestInfo.get("size");
Integer responePages=(total/pageSize)+1; Integer responePages=(total/pageSize)+1;
if (responePages == pageNo){ if (responePages <= pageNo){
break; break;
} else { } else {
pageNo++; pageNo++;
...@@ -160,10 +160,11 @@ public class SofarRequestUtil { ...@@ -160,10 +160,11 @@ public class SofarRequestUtil {
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 = "";
List<T> result = new ArrayList<>(); List<T> result = new ArrayList<>();
String url ="";
HashMap<String, String> headMap = new HashMap<>();
try { try {
HashMap<String, String> headMap = getHeaderOfSofar(); headMap = getHeaderOfSofar();
String url = SoFarConstant.baseurl + apiurl; url = SoFarConstant.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!=null&&jsonObject.get(ResultResolveRule)!=null){ if(jsonObject!=null&&jsonObject.get(ResultResolveRule)!=null){
...@@ -181,6 +182,15 @@ public class SofarRequestUtil { ...@@ -181,6 +182,15 @@ public class SofarRequestUtil {
thirdStationLogService.saveLog(hygfThirdStationLog); thirdStationLogService.saveLog(hygfThirdStationLog);
} catch (Exception exception) { } catch (Exception exception) {
exception.printStackTrace(); exception.printStackTrace();
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.SH.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
return result; return result;
} }
return result; return result;
...@@ -190,9 +200,11 @@ public class SofarRequestUtil { ...@@ -190,9 +200,11 @@ public class SofarRequestUtil {
public JSONObject getResPonseobj(String apiurl, String requestMethod, String requestParmInfo, String ResultResolveRule) { public JSONObject getResPonseobj(String apiurl, String requestMethod, String requestParmInfo, String ResultResolveRule) {
String respone = ""; String respone = "";
JSONObject jsonObject = null; JSONObject jsonObject = null;
String url ="";
HashMap<String, String> headMap = new HashMap<>();
try { try {
HashMap<String, String> headMap = getHeaderOfSofar(); headMap = getHeaderOfSofar();
String url = SoFarConstant.baseurl + apiurl; url = SoFarConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
if(respone!=null&&JSONObject.parseObject(respone).get(ResultResolveRule)!=null&&ResultResolveRule!=null){ if(respone!=null&&JSONObject.parseObject(respone).get(ResultResolveRule)!=null&&ResultResolveRule!=null){
jsonObject = JSONObject.parseObject(JSONObject.parseObject(respone).get(ResultResolveRule).toString()); jsonObject = JSONObject.parseObject(JSONObject.parseObject(respone).get(ResultResolveRule).toString());
...@@ -209,6 +221,15 @@ public class SofarRequestUtil { ...@@ -209,6 +221,15 @@ public class SofarRequestUtil {
hygfThirdStationLog.setResBody(respone); hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog); thirdStationLogService.saveLog(hygfThirdStationLog);
} catch (Exception exception) { } catch (Exception exception) {
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.SH.getCode());
hygfThirdStationLog.setReqMethod(requestMethod);
hygfThirdStationLog.setReqHeaders(headMap.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(requestParmInfo);
hygfThirdStationLog.setResBody(respone);
thirdStationLogService.saveLog(hygfThirdStationLog);
exception.printStackTrace(); exception.printStackTrace();
} }
return jsonObject; return jsonObject;
......
...@@ -18,6 +18,7 @@ import org.springframework.stereotype.Component; ...@@ -18,6 +18,7 @@ import org.springframework.stereotype.Component;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** /**
* @description: * @description:
...@@ -212,11 +213,14 @@ public class SunlightUtil { ...@@ -212,11 +213,14 @@ public class SunlightUtil {
JSONObject resultData = new JSONObject(); JSONObject resultData = new JSONObject();
JSONArray pageList = new JSONArray(); JSONArray pageList = new JSONArray();
Integer pageNo = 1; Integer pageNo = 1;
HttpRequest request = null;
String body="";
String res="";
try { try {
do { do {
bodyparam.put("curPage", pageNo); bodyparam.put("curPage", pageNo);
//请求头 //请求头
HttpRequest request = HttpUtil.createPost(dfurl+url); request = HttpUtil.createPost(dfurl+url);
request.header("Content-Type", "application/json;charset=UTF-8"); request.header("Content-Type", "application/json;charset=UTF-8");
request.header("sys_code", "901"); request.header("sys_code", "901");
request.header("x-access-key", access_key); request.header("x-access-key", access_key);
...@@ -225,13 +229,13 @@ public class SunlightUtil { ...@@ -225,13 +229,13 @@ public class SunlightUtil {
bodyparam.put("token", this.getSunlightToken()); bodyparam.put("token", this.getSunlightToken());
Gson gson = new Gson(); Gson gson = new Gson();
String body = gson.toJson(bodyparam); body = gson.toJson(bodyparam);
request.body(body); request.body(body);
HttpResponse execute = request.execute(); HttpResponse execute = request.execute();
if (!execute.isOk()) { if (!execute.isOk()) {
throw new RuntimeException(execute.body()); throw new RuntimeException(execute.body());
} }
String res = UnicodeUtil.toString(execute.body()); res = UnicodeUtil.toString(execute.body());
JSONObject jsonObject = JSONUtil.parseObj(res, true); JSONObject jsonObject = JSONUtil.parseObj(res, true);
resultData = JSONUtil.parseObj(jsonObject.get("result_data"), true); resultData = JSONUtil.parseObj(jsonObject.get("result_data"), true);
...@@ -252,7 +256,7 @@ public class SunlightUtil { ...@@ -252,7 +256,7 @@ public class SunlightUtil {
Integer rowCount = resultData.getInt("rowCount"); Integer rowCount = resultData.getInt("rowCount");
Integer pageSize= bodyparam.get("size")==null || (Integer)bodyparam.get("size")==0? 1:(Integer)bodyparam.get("size"); Integer pageSize= bodyparam.get("size")==null || (Integer)bodyparam.get("size")==0? 1:(Integer)bodyparam.get("size");
Integer responePages=(rowCount/pageSize)+1; Integer responePages=(rowCount/pageSize)+1;
if (responePages == pageNo){ if (responePages <= pageNo){
break; break;
} else { } else {
pageNo++; pageNo++;
...@@ -260,6 +264,17 @@ public class SunlightUtil { ...@@ -260,6 +264,17 @@ public class SunlightUtil {
} while (true); } while (true);
} catch (Exception e) { } catch (Exception e) {
log.error("失败,msg["+e.getMessage()+"]", e); log.error("失败,msg["+e.getMessage()+"]", e);
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.YG.getCode());
if(Objects.nonNull(request)){
hygfThirdStationLog.setReqMethod(request.getMethod().toString());
hygfThirdStationLog.setReqHeaders(request.headers().toString());
}
hygfThirdStationLog.setReqPath(dfurl+url);
hygfThirdStationLog.setReqBody(body);
hygfThirdStationLog.setResBody(res);
thirdStationLogService.saveLog(hygfThirdStationLog);
return resultData; return resultData;
} }
return resultData; return resultData;
...@@ -271,10 +286,12 @@ public class SunlightUtil { ...@@ -271,10 +286,12 @@ public class SunlightUtil {
public JSONObject getdata(String url,Map<String, Object> bodyparam ){ public JSONObject getdata(String url,Map<String, Object> bodyparam ){
String data=null; String data=null;
HttpRequest request = null;
String body="";
String res="";
try { try {
//请求头 //请求头
HttpRequest request = HttpUtil.createPost(dfurl+url); request = HttpUtil.createPost(dfurl+url);
request.header("Content-Type", "application/json;charset=UTF-8"); request.header("Content-Type", "application/json;charset=UTF-8");
request.header("sys_code", "901"); request.header("sys_code", "901");
request.header("x-access-key", access_key); request.header("x-access-key", access_key);
...@@ -283,13 +300,13 @@ public class SunlightUtil { ...@@ -283,13 +300,13 @@ public class SunlightUtil {
bodyparam.put("token", this.getSunlightToken()); bodyparam.put("token", this.getSunlightToken());
Gson gson = new Gson(); Gson gson = new Gson();
String body = gson.toJson(bodyparam); body = gson.toJson(bodyparam);
request.body(body); request.body(body);
HttpResponse execute = request.execute(); HttpResponse execute = request.execute();
if (!execute.isOk()) { if (!execute.isOk()) {
throw new RuntimeException(execute.body()); throw new RuntimeException(execute.body());
} }
String res = UnicodeUtil.toString(execute.body()); res = UnicodeUtil.toString(execute.body());
JSONObject jsonObject = JSONUtil.parseObj(res, true); JSONObject jsonObject = JSONUtil.parseObj(res, true);
JSONObject resultData = JSONUtil.parseObj(jsonObject.get("result_data"), true); JSONObject resultData = JSONUtil.parseObj(jsonObject.get("result_data"), true);
...@@ -306,6 +323,17 @@ public class SunlightUtil { ...@@ -306,6 +323,17 @@ public class SunlightUtil {
return resultData; return resultData;
} catch (Exception e) { } catch (Exception e) {
log.error("失败,msg["+e.getMessage()+"]", e); log.error("失败,msg["+e.getMessage()+"]", e);
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.YG.getCode());
if(Objects.nonNull(request)){
hygfThirdStationLog.setReqMethod(request.getMethod().toString());
hygfThirdStationLog.setReqHeaders(request.headers().toString());
}
hygfThirdStationLog.setReqPath(dfurl+url);
hygfThirdStationLog.setReqBody(body);
hygfThirdStationLog.setResBody(res);
thirdStationLogService.saveLog(hygfThirdStationLog);
return new JSONObject(); return new JSONObject();
} }
......
...@@ -120,7 +120,7 @@ public class TanYinApiUtils { ...@@ -120,7 +120,7 @@ public class TanYinApiUtils {
// 记录请求开始的日志信息。 // 记录请求开始的日志信息。
log.debug("请求 => 碳银{}接口,url:{}", desc, url); log.debug("请求 => 碳银{}接口,url:{}", desc, url);
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
HttpResponse response; HttpResponse response =null;
try { try {
// 添加Authorization头,使用Bearer令牌模式。 // 添加Authorization头,使用Bearer令牌模式。
headers.put("Authorization", "Bearer " + getAccessToken(clientKey, clientSecret)); headers.put("Authorization", "Bearer " + getAccessToken(clientKey, clientSecret));
...@@ -144,6 +144,17 @@ public class TanYinApiUtils { ...@@ -144,6 +144,17 @@ public class TanYinApiUtils {
response = HttpUtil.createGet(url).execute(); response = HttpUtil.createGet(url).execute();
return parseResponse(desc, response, resultClass); return parseResponse(desc, response, resultClass);
} catch (Exception e) { } catch (Exception e) {
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.TANYIN.getCode());
hygfThirdStationLog.setReqMethod(HttpMethod.GET.name());
hygfThirdStationLog.setReqHeaders(headers.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(null);
if(Objects.nonNull(response)){
hygfThirdStationLog.setResBody(response.toString());
}
thirdStationLogService.saveLog(hygfThirdStationLog);
// 记录未预期异常的日志信息。 // 记录未预期异常的日志信息。
log.warn(String.format("异常 => 碳银%s接口", desc), e); log.warn(String.format("异常 => 碳银%s接口", desc), e);
return null; return null;
...@@ -206,6 +217,17 @@ public class TanYinApiUtils { ...@@ -206,6 +217,17 @@ public class TanYinApiUtils {
log.warn(String.format("异常 => 碳银%s接口,参数: %s,响应: %s", desc, paramsJsonStr, response != null ? response.body() : businessException.getMessage())); log.warn(String.format("异常 => 碳银%s接口,参数: %s,响应: %s", desc, paramsJsonStr, response != null ? response.body() : businessException.getMessage()));
return null; return null;
} catch (Exception e) { } catch (Exception e) {
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.TANYIN.getCode());
hygfThirdStationLog.setReqMethod(HttpMethod.GET.name());
hygfThirdStationLog.setReqHeaders(headers.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(null);
if(Objects.nonNull(response)){
hygfThirdStationLog.setResBody(response.toString());
}
thirdStationLogService.saveLog(hygfThirdStationLog);
// 记录未预期的异常日志。 // 记录未预期的异常日志。
log.warn(String.format("异常 => 碳银%s接口,参数: %s", desc, paramsJsonStr), e); log.warn(String.format("异常 => 碳银%s接口,参数: %s", desc, paramsJsonStr), e);
return null; return null;
...@@ -267,6 +289,17 @@ public class TanYinApiUtils { ...@@ -267,6 +289,17 @@ public class TanYinApiUtils {
log.warn(String.format("异常 => 碳银%s接口,参数: %s,响应: %s", desc, paramsJsonStr, response != null ? response.body() : businessException.getMessage())); log.warn(String.format("异常 => 碳银%s接口,参数: %s,响应: %s", desc, paramsJsonStr, response != null ? response.body() : businessException.getMessage()));
return null; return null;
} catch (Exception e) { } catch (Exception e) {
//存储日志
HYGFThirdStationLog hygfThirdStationLog = new HYGFThirdStationLog();
hygfThirdStationLog.setThirdCode(PVProducerInfoEnum.TANYIN.getCode());
hygfThirdStationLog.setReqMethod(HttpMethod.GET.name());
hygfThirdStationLog.setReqHeaders(headers.toString());
hygfThirdStationLog.setReqPath(url);
hygfThirdStationLog.setReqBody(null);
if(Objects.nonNull(response)){
hygfThirdStationLog.setResBody(response.toString());
}
thirdStationLogService.saveLog(hygfThirdStationLog);
// 记录异常日志 // 记录异常日志
log.warn(String.format("异常 => 碳银%s接口,参数: %s", desc, paramsJsonStr), e); log.warn(String.format("异常 => 碳银%s接口,参数: %s", desc, paramsJsonStr), e);
return null; return null;
......
package com.yeejoin.amos.api.householdapi.face.service.impl; package com.yeejoin.amos.api.householdapi.face.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.api.householdapi.Utils.CalendarAdjust; import com.yeejoin.amos.api.householdapi.Utils.CalendarAdjust;
...@@ -33,6 +35,9 @@ import org.springframework.stereotype.Service; ...@@ -33,6 +35,9 @@ import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -1035,7 +1040,6 @@ public class ImasterDataServiceImpl implements ImasterDataService { ...@@ -1035,7 +1040,6 @@ public class ImasterDataServiceImpl implements ImasterDataService {
// jpStationMapper.updateById(jpStation1); // jpStationMapper.updateById(jpStation1);
} }
@Scheduled(cron = "${dataRequstScheduled.huawei}") @Scheduled(cron = "${dataRequstScheduled.huawei}")
@Override @Override
@Async @Async
...@@ -1043,6 +1047,10 @@ public class ImasterDataServiceImpl implements ImasterDataService { ...@@ -1043,6 +1047,10 @@ public class ImasterDataServiceImpl implements ImasterDataService {
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
logger.info("-------华为同步告警开始" + ts + "------- " + sdf.format(new Date())); logger.info("-------华为同步告警开始" + ts + "------- " + sdf.format(new Date()));
List<String> inverterSns = imasterInverterListMapper.getCollectIds(); List<String> inverterSns = imasterInverterListMapper.getCollectIds();
if (CollectionUtil.isEmpty(inverterSns)){
logger.warn("-------没有逆变器,跳过告警-------");
return;
}
// for (int i = 0; i < inverterSns.size(); i++) { // for (int i = 0; i < inverterSns.size(); i++) {
// try { // try {
// TimeUnit.MINUTES.sleep(3); // TimeUnit.MINUTES.sleep(3);
...@@ -1050,12 +1058,20 @@ public class ImasterDataServiceImpl implements ImasterDataService { ...@@ -1050,12 +1058,20 @@ public class ImasterDataServiceImpl implements ImasterDataService {
// throw new RuntimeException(e); // throw new RuntimeException(e);
// } // }
HashMap<String, Object> requestInfo = new HashMap<>(); HashMap<String, Object> requestInfo = new HashMap<>();
// 获取今天的日期
LocalDate today = LocalDate.now();
// 将 LocalDate 转换为 LocalDateTime,设置时间为零点
LocalDateTime midnight = today.atStartOfDay();
// 将 LocalDateTime 转换为 Date
Date date = Date.from(midnight.atZone(ZoneId.systemDefault()).toInstant());
// 获取今天零点的时间戳(毫秒)
long todayTimestamp = date.getTime();
requestInfo.put("sns", inverterSns.stream().collect(Collectors.joining(","))); requestInfo.put("sns", inverterSns.stream().collect(Collectors.joining(",")));
requestInfo.put("language", "zh_CN "); requestInfo.put("language", "zh_CN");
requestInfo.put("devTypes", 1); requestInfo.put("devTypes", "1");
requestInfo.put("beginTime", DateUtil.today()); requestInfo.put("beginTime", todayTimestamp);
requestInfo.put("endTime", DateUtil.today()); requestInfo.put("endTime", System.currentTimeMillis());
String requestParaminfo = JSON.toJSONString(requestInfo); String requestParaminfo = JSON.toJSONString(requestInfo);
List<ImasterAlarmDto> result = imasterUtils.getResPonse(ImasterConstant.alarmListUrl, List<ImasterAlarmDto> result = imasterUtils.getResPonse(ImasterConstant.alarmListUrl,
GoLangConstant.requestPost, GoLangConstant.requestPost,
......
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