Commit dd8b45e3 authored by caotao's avatar caotao

锦浪云-日发电量增加格式转换、入库代码调整

parent 00742ab1
......@@ -14,16 +14,17 @@ import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.component.cache.Redis;
import java.util.*;
@Component
public class GolangRequestUtil {
private final static String API_REDIS_PREFIX = "HOUSEHOLD_API_CACHE_";
@Autowired
private HouseholdPvProducerInfoServiceImpl householdPvProducerInfoServiceImpl;
@Autowired
private GolangStationMapper golangStationMapper;
/**
* @return HashMap<String, Object> 发送请求前的准备 准备header信息
* @deprecated 根据厂商编码获取厂商的hearer
......@@ -43,9 +44,16 @@ public class GolangRequestUtil {
}
/**
* @return String 请求返回的response字符串
* @desc 根据请求参数发送http请求并且对于返回的数据进行处理
* @param apiurl 请求url
* @param requestMethod 请求方式
* @param requestParmInfo 请求参数mapper
* @param ResultResolveRule 请求的解析
* @param tClass 需要转换成的bean
* @return List<T> list<Result>
* @param <T> 泛型数据
*/
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 params = "";
JSONArray jsonArray = null;
......@@ -55,29 +63,15 @@ public class GolangRequestUtil {
String orginalAuthorization = headMap.get("Authorization") + ":";
String url = baseurl + apiurl;
String appsecret = (String) producerInfo.get("appsecret");
JLYHeaderMapHandler(params, headMap, orginalAuthorization, appsecret,apiurl);
respone = sendRequest(requestMethod, url,requestParmInfo, headMap);
JLYHeaderMapHandler(params, headMap, orginalAuthorization, appsecret, apiurl);
respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
List<T> result = JSONArray.parseArray(jsonArray.toJSONString(),tClass);
List<T> result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
return result;
}
// public JSONArray getResPonse(String apiurl,String requestMethod,String requestParmInfo,String ResultResolveRule) {
// String respone = "";
// String params = "";
// JSONArray jsonArray = null;
// HashMap<String, Object> producerInfo = getHeaderOfGolang();
// String baseurl = (String) producerInfo.get("apiurl");
// HashMap<String, String> headMap = (HashMap<String, String>) producerInfo.get("header");
// String orginalAuthorization = headMap.get("Authorization") + ":";
// String url = baseurl + apiurl;
// String appsecret = (String) producerInfo.get("appsecret");
// JLYHeaderMapHandler(params, headMap, orginalAuthorization, appsecret,apiurl);
// respone = sendRequest(requestMethod, url,requestParmInfo, headMap);
// jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
// return jsonArray;
// }
/**
* @desc 根据解析规则解析请求返回数据
* @param resultResovle 请求返回的解析规则 来源与数据库
* @param response 请求返回的字符串
* @return 解析后的数据
......@@ -106,57 +100,6 @@ public class GolangRequestUtil {
return jsonArray;
}
/**
* @param seq apiID
* @param cacheField 要缓存的字段
* @param jsonArray 处理后的数据请求
* @param measurement 要在influxdb中存储的数
* @describe 该方法用于缓存需要缓存的字段 且将需要入库的数据进行入库
*/
public void handleResponseAndCacheData(String seq, String cacheField, JSONArray jsonArray, String measurement, String produceID) {
String apiID = API_REDIS_PREFIX + seq;
List list = new ArrayList();
List saveList = new ArrayList();
if (jsonArray.size() > 0) {
for (Object o : jsonArray) {
List<Map<String, Object>> lines = new ArrayList<>();
Map<String, Object> maps1 = (Map<String, Object>) o;
LinkedHashMap<String, Object> sortHashMap = new LinkedHashMap<>();
sortHashMap.put("station_list", "station_list." + measurement);
sortHashMap.put("timestamp", System.currentTimeMillis());
sortHashMap.put("value", 10.1);
Set<String> keys = maps1.keySet();
keys.forEach((key) -> {
maps1.put(key, ObjectUtils.isEmpty(maps1.get(key)) ? "null" : maps1.get(key).toString());
});
if (!ObjectUtils.isEmpty("cacheField")) {
list.add(maps1.get(cacheField));
}
sortHashMap.put("tags", maps1);
lines.add(sortHashMap);
// Map<String, String> maps2 = new HashMap<>();
// maps2.put("key", UUID.randomUUID().toString());
if (!ObjectUtils.isEmpty(measurement)) {
// influxDbConnection.insert(measurement, maps2, maps1);
// log.error(JSONObject.toJSONString(lines));
// tdEngineUtils.writeDataIntoTdEngine(JSONObject.toJSONString(lines));
}
}
}
// tdEngineUtils.writeDataIntoTdEngine(lines.stream().map(s -> String.valueOf(s)).toArray(String[]::new));
if (!ObjectUtils.isEmpty(cacheField)) {
saveList = Redis.getRedisTemplate().opsForList().range(apiID, 0, -1);
if (saveList.size() == 0) {
Redis.getRedisTemplate().opsForList().leftPushAll(apiID, list);
}
saveList = Redis.getRedisTemplate().opsForList().range(apiID, 0, -1);
if (saveList.size() != list.size()) {
Redis.getRedisTemplate().delete(apiID);
Redis.getRedisTemplate().opsForList().leftPushAll(apiID, list);
}
}
}
public String sendRequest(String requestMethod, String url, String params, HashMap<String, String> headMap) {
String respone = "";
if (requestMethod.equals("POST")) {
......@@ -179,19 +122,25 @@ public class GolangRequestUtil {
* @desc 锦浪云请求参数及head头处理
*/
public void JLYHeaderMapHandler(String params, HashMap<String, String> headMap, String orginalAuthorization, String appsecret, String apiurl) {
String contentMD5 = GoLangHeaderUtils.getDigest(params);
headMap.put("Date", GoLangHeaderUtils.getGMTTime());
String param = "POST" + "\n" + contentMD5 + "\n" + "application/json" + "\n" + headMap.get("Date") + "\n" + apiurl;
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);
String contentMD5 = GoLangHeaderUtils.getDigest(params);
headMap.put("Date", GoLangHeaderUtils.getGMTTime());
String param = "POST" + "\n" + contentMD5 + "\n" + "application/json" + "\n" + headMap.get("Date") + "\n" + apiurl;
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);
}
/**
* @desc 根据分页规则 获取分页数
* @param pageSizeResovle
* @param response
* @return
*/
public Integer getPagesize(String pageSizeResovle, String response) {
Integer pageSize = 0;
String[] rules = pageSizeResovle.split(",");
......
package com.yeejoin.amos.api.householdapi.face.service;
public interface GoLangDataAcquisitionService {
/**
* @descrption 场站列表数据入库
*/
void stationList();
/**
* @descrption 场站详情数据入库
*/
void stationDetail();
/**
* @descrption 采集器列表数据入库
*/
void collectorList();
/**
* @descrption 采集器详情数据入库
*/
void collectorDetail();
/**
* @descrption 逆变器列表数据入库
*/
void inverterList();
/**
* @descrption 逆变器详情数据入库
*/
void inverterDetail();
/**
* @descrption 采集器告警列表数据入库
*/
void inverAlramInfo();
}
......@@ -22,14 +22,11 @@ import com.yeejoin.amos.api.householdapi.face.service.GoLangDataAcquisitionServi
import com.yeejoin.amos.api.householdapi.face.orm.mapper.hygf.JpStationMapper;
import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum;
import fastjson.JSON;
import org.bouncycastle.crypto.engines.AESLightEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
......@@ -39,44 +36,59 @@ import java.util.concurrent.TimeUnit;
@Async
@Service
public class GoLangDataAcquisitionServiceImpl implements GoLangDataAcquisitionService {
//定时任务执行频率 当前为10分钟一次
private final String dataRequstScheduled = "0 0/10 * * * *";
//锦浪云请求工具封装
@Autowired
private GolangRequestUtil golangRequestUtil;
//锦浪云场站mapper
@Autowired
private GolangStationMapper golangStationMapper;
//监盘场站mapper
@Autowired
private JpStationMapper jpStationMapper;
//监盘采集器mapper
@Autowired
private JpCollectorMapper jpCollectorMapper;
//监盘逆变器mapper
@Autowired
private JpInverterMapper jpInverterMapper;
//监盘逆变器电量mapper
@Autowired
private JpInverterElectricityMapper jpInverterElectricityMapper;
//锦浪云场站详情mapper
@Autowired
private GolangStationDetailMapper golangStationDetailMapper;
//锦浪云采集器列表mapper
@Autowired
private GolangCollectorListMapper golangCollectorListMapper;
//锦浪云逆变器列表
@Autowired
private GolangInverterListMapper golangInverterListMapper;
//户用光伏 场站历史
//户用光伏场站历史mapper
@Autowired
private HYGFJPStationPowerHistoryMapper hygfjpStationPowerHistoryMapper;
//
//户用光伏逆变器历史mapper
@Autowired
private HYGFJPInverterHistoryMapper hygfjpInverterHistoryMapper;
//户用光伏采集器历史mapper
@Autowired
private HYGFJPCollectorHistoryMapper hygfjpCollectorHistoryMapper;
//户用光伏逆变器告警
@Autowired
private HYGFJPInverterWarnMapper hygfjpInverterWarnMapper;
//户用光伏逆变器历史mapper
@Autowired
private HYGFJPInverterElecHistoryMapper hygfjpInverterElecHistoryMapper;
//户用光伏日发电量
@Autowired
private HYGFJPDayPowerMapper hygfjpDayPowerMapper;
@Scheduled(cron = dataRequstScheduled)
@Override
public void stationList() {
HashMap<String, Object> requestInfo = new HashMap<>();
requestInfo.put("pageNo", 1);
requestInfo.put("pageSize", 100);
......
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