Commit 2fce7232 authored by caotao's avatar caotao

优化调整户用光伏数据采集

parent f937b12d
package com.yeejoin.amos.api.householdapi.Utils;
import com.yeejoin.amos.api.householdapi.face.model.HouseholdPvApiDto;
import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Mac;
......@@ -11,40 +13,6 @@ import java.text.SimpleDateFormat;
import java.util.*;
//锦浪云 header处理类
public class GoLangHeaderUtils {
// public static void main(String[] args) {
// try {
// String key = "";
// String keySecret = "";
// Map<String,Object> map = new HashMap();
// map.put("pageNo",1);
// map.put("pageSize",10);
// String body = JSON.toJSONString(map);
// String ContentMd5 = getDigest(body);
// String Date = getGMTTime();
// String path = "/v1/api/userStationList";
// String param = "POST" + "\n" + ContentMd5 + "\n" + "application/json" + "\n" + Date + "\n" + path;
// String sign = HmacSHA1Encrypt(param, keySecret);
// String url = "url" + path ;
// OkHttpClient client = new OkHttpClient();
// MediaType xmlType = MediaType.parse("application/json;charset=UTF-8");
// okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(xmlType,body);
// okhttp3.Request request = new okhttp3.Request.Builder()
// .url(url)
// .addHeader("Content-type", "application/json;charset=UTF-8")
// .addHeader("Authorization","API "+key+":"+sign)
// .addHeader("Content-MD5",ContentMd5)
// .addHeader("Date",Date)
// .post(requestBody)
// .build();
// Response response = client.newCall(request).execute();
// String string = response.body().string();
// System.out.println(string);
//
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
public static String HmacSHA1Encrypt(String encryptText, String KeySecret) throws Exception
{
byte[] data=KeySecret.getBytes("UTF-8");
......@@ -77,5 +45,29 @@ public class GoLangHeaderUtils {
}
return result;
}
/***
*
* @param params 参数字符窜
* @param householdPvApiDto apidto
* @param headMap header头
* @param orginalAuthorization 原始的orginalAuthorization
* @param appsecret appsecret
* @param cacheParams 缓存的参数值
* @desc 锦浪云请求参数及head头处理
*/
public void JLYHeaderMapHandler(String params, HouseholdPvApiDto householdPvApiDto, HashMap<String, String> headMap, String orginalAuthorization, String appsecret, String cacheParams) {
if (PVProducerInfoEnum.JLY.getCode().equals(householdPvApiDto.getProducerId())) {
String contentMD5 = GoLangHeaderUtils.getDigest(params);
headMap.put("Date", GoLangHeaderUtils.getGMTTime());
String param = "POST" + "\n" + contentMD5 + "\n" + "application/json" + "\n" + headMap.get("Date") + "\n" + householdPvApiDto.getApiUrl();
String sign = "";
try {
sign = GoLangHeaderUtils.HmacSHA1Encrypt(param, appsecret);
} catch (Exception e) {
throw new RuntimeException(e);
}
headMap.put("Content-MD5", contentMD5);
headMap.put("Authorization", orginalAuthorization + sign);
}
}
}
......@@ -19,6 +19,7 @@ import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.component.cache.Redis;
import java.util.*;
......@@ -54,7 +55,7 @@ public class HouseholdPvUtils {
String body = JSON.toJSONString(map);
String response = HttpUtil.createPost(url).body(body).execute().body();
JSONObject jsonObject = JSON.parseObject(response);
if (jsonObject.get("data") != null) {
if (!ObjectUtils.isEmpty(jsonObject.get("data"))) {
JSONObject jsonObject1 = (JSONObject) jsonObject.get("data");
hashMaphead.put("token", (String) jsonObject1.get("token"));
hashMap.put("header", hashMaphead);
......@@ -196,20 +197,20 @@ public class HouseholdPvUtils {
Map<String, Object> maps1 = (Map<String, Object>) o;
Set<String> keys = maps1.keySet();
keys.forEach((key) -> {
maps1.put(key, maps1.get(key).toString());
maps1.put(key,ObjectUtils.isEmpty(maps1.get(key))?"" :maps1.get(key).toString());
});
if (cacheField != null) {
if (!ObjectUtils.isEmpty("cacheField")) {
list.add(maps1.get(cacheField));
}
Map<String, String> maps2 = new HashMap<>();
maps2.put("key", UUID.randomUUID().toString());
if (measurement != null) {
if (!ObjectUtils.isEmpty(measurement)) {
influxDbConnection.insert(measurement, maps2, maps1);
}
}
}
if (cacheField != null) {
if ( !ObjectUtils.isEmpty(cacheField)) {
saveList = Redis.getRedisTemplate().opsForList().range(apiID, 0, -1);
if (saveList.size() == 0) {
Redis.getRedisTemplate().opsForList().leftPushAll(apiID, list);
......
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