Commit 9247233c authored by litengwei's avatar litengwei

对接第三方北向数据

parent 048ede6f
package com.yeejoin.amos.api.householdapi.Utils;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.api.householdapi.constant.ImasterConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import java.util.*;
@Component
public class ImasterUtils {
private String redisKey = "XSRF-TOKEN";
@Autowired
RedisUtils redisUtils;
/**
* @return HashMap<String, Object> 发送请求前的准备 准备header信息
* @deprecated 根据厂商编码获取厂商的hearer
*/
public static HashMap<String, String> getHeader() {
HashMap<String, String> hashMap = new HashMap<>();
String requestParam="";
HashMap<String, String> hashMaphead = new HashMap<>();
try {
requestParam = "{ \"userName\": \""+ImasterConstant.account+"\", \"systemCode\": \""+ImasterConstant.password+"\"}";
} catch (Exception e) {
throw new RuntimeException(e);
}
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);
return hashMap;
}
/**
* @param apiurl 请求url
* @param requestMethod 请求方式
* @param requestParmInfo 请求参数mapper
* @param ResultResolveRule 请求的解析
* @param tClass 需要转换成的bean
* @param <T> 泛型数据
* @return List<T> list<Result>
* @desc 根据请求参数发送http请求并且对于返回的数据进行处理
*/
public <T> List<T> getResPonse(String apiurl, String requestMethod, String requestParmInfo, String ResultResolveRule, Class<T> tClass) {
String respone = "";
String params = "";
JSONArray jsonArray = null;
List<T> result = new ArrayList<>();
try {
Object o = redisUtils.get(redisKey);
if(o != null) {
HashMap<String, String> headMap = new HashMap<>();
headMap.put("XSRF-TOKEN", o.toString());
String url = ImasterConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
JSONObject jsonObject = JSONObject.parseObject(respone);
if(jsonObject.get("failCode").toString().equals("305")) {
headMap = getHeader();
respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
redisUtils.set(redisKey,headMap.get("XSRF-TOKEN"));
}
} else {
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
}
}
} else {
HashMap<String, String> headMap = getHeader();
String url = ImasterConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
redisUtils.set(redisKey,headMap.get("XSRF-TOKEN"));
}
}
} catch (Exception exception) {
return result;
}
return result;
}
/**
* @param apiurl 请求url
* @param requestMethod 请求方式
* @param requestParmInfo 请求参数mapper
* @param ResultResolveRule 请求的解析
* @param tClass 需要转换成的bean
* @param <T> 泛型数据
* @return List<T> list<Result>
* @desc 根据请求参数发送http请求并且对于返回的数据进行处理
*/
public <T> List<T> getResPonseOther(String apiurl, String requestMethod, String requestParmInfo, String ResultResolveRule, Class<T> tClass) {
String respone = "";
String params = "";
JSONArray jsonArray = null;
List<T> result = new ArrayList<>();
try {
Object o = redisUtils.get(redisKey);
if(o != null) {
HashMap<String, String> headMap = new HashMap<>();
headMap.put("XSRF-TOKEN", o.toString());
String url = ImasterConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
JSONObject jsonObject = JSONObject.parseObject(respone);
if(jsonObject.get("failCode").toString().equals("305")) {
headMap = getHeader();
respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone);
if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
redisUtils.set(redisKey,headMap.get("XSRF-TOKEN"));
}
} else {
jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone);
if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
}
}
} else {
HashMap<String, String> headMap = getHeader();
String url = ImasterConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
jsonArray = handlerResponseByResultResolveruleOther(ResultResolveRule, respone);
if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
redisUtils.set(redisKey,headMap.get("XSRF-TOKEN"));
}
}
} catch (Exception exception) {
return result;
}
return result;
}
/**
* @param resultResovle 请求返回的解析规则 来源与数据库
* @param response 请求返回的字符串
* @return 解析后的数据
* @desc 根据解析规则解析请求返回数据
*/
public static JSONArray handlerResponseByResultResolverule(String resultResovle, String response) {
JSONObject jsonObject = JSONObject.parseObject(response);
JSONArray jsonArray = new JSONArray();
if (ObjectUtil.isNotEmpty(resultResovle)) {
String[] rules = resultResovle.split(",");
if (rules.length > 0) {
for (int i = 0; i < rules.length; i++) {
try {
jsonObject = (JSONObject) jsonObject.get(rules[i]);
if (jsonObject == null) {
jsonArray = (JSONArray) jsonObject.get(rules[i]);
}
} catch (Exception exception) {
jsonArray = (JSONArray) jsonObject.get(rules[i]);
}
}
}
if (jsonArray.size() == 0) {
jsonArray.addAll((JSONArray)jsonObject.get("list"));
}
}
return jsonArray;
}
/**
* @param resultResovle 请求返回的解析规则 来源与数据库
* @param response 请求返回的字符串
* @return 解析后的数据
* @desc 根据解析规则解析请求返回数据
*/
public static JSONArray handlerResponseByResultResolveruleOther(String resultResovle, String response) {
JSONObject jsonObject = JSONObject.parseObject(response);
JSONArray jsonArray = new JSONArray();
JSONArray jsonArrayRet = new JSONArray();
if (ObjectUtil.isNotEmpty(resultResovle)) {
String[] rules = resultResovle.split(",");
if (rules.length > 0) {
for (int i = 0; i < rules.length; i++) {
try {
jsonObject = (JSONObject) jsonObject.get(rules[i]);
if (jsonObject == null) {
jsonArray = (JSONArray) jsonObject.get(rules[i]);
}
} catch (Exception exception) {
jsonArray = (JSONArray) jsonObject.get(rules[i]);
}
}
}
if (jsonArray.size() != 0) {
for( int i=0; i<jsonArray.size();i++ ) {
JSONObject jsonObject1 = (JSONObject) jsonArray.get(i);
JSONObject jsonObject2 = (JSONObject)jsonObject1.get("dataItemMap");
if(jsonObject1.get("sn") != null) {
jsonObject2.put("inverterId", jsonObject1.get("sn").toString());
}
if(jsonObject1.get("stationCode") != null) {
jsonObject2.put("stationCode", jsonObject1.get("stationCode").toString());
}
jsonArrayRet.add(jsonObject2);
}
}
}
return jsonArrayRet;
}
public static String sendRequest(String requestMethod, String url, String params, HashMap<String, String> headMap) {
String respone = "";
if (requestMethod.equals("POST")) {
respone = HttpUtil.createPost(url).headerMap(headMap, false).
body(params).execute().body();
}
if (requestMethod.equals("GET")) {
respone = HttpUtil.createGet(url).headerMap(headMap, true).
body(params).execute().body();
}
return respone;
}
/***
*
* @param params 参数字符窜
* @param headMap header头
* @param orginalAuthorization 原始的orginalAuthorization
* @param appsecret appsecret
* @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);
}
/**
* @param pageSizeResovle
* @param response
* @return
* @desc 根据分页规则 获取分页数
*/
public Integer getPagesize(String pageSizeResovle, String response) {
Integer pageSize = 0;
String[] rules = pageSizeResovle.split(",");
JSONObject jsonObject = JSONObject.parseObject(response);
if (rules.length > 0) {
for (int i = 0; i < rules.length - 1; i++) {
jsonObject = (JSONObject) jsonObject.get(rules[i]);
}
}
pageSize = (Integer) jsonObject.get(rules[rules.length - 1]);
return pageSize;
}
// public static void main(String[] args) {
// HashMap<String, Object> requestInfo = new HashMap<>();
// requestInfo.put("pageNo", 1);
// String requestParaminfo = JSON.toJSONString(requestInfo);
// getResPonse(ImasterConstant.stationListUrl,
// GoLangConstant.requestPost,
// requestParaminfo,
// ImasterConstant.resovleRule_data_page_records,
// ImasterStationList.class
// );
//
// }
}
package com.yeejoin.amos.api.householdapi.Utils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.typroject.tyboot.component.cache.enumeration.CacheType;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* @author DELL
*/
@Component
public class RedisUtils {
public static String VAR_SPLITOR = ":";
public static Long DEFAULT_SESSION_EXPIRATION = 2592000L;
@Autowired
private RedisTemplate redisTemplate;
/**
* 指定缓存失效时间
*
* @param key 键
* @param time 时间(秒)
* @return
*/
public boolean expire(String key, long time) {
if (time > 0) {
redisTemplate.expire(key, time, TimeUnit.SECONDS);
return true;
} else {
throw new RuntimeException("超时时间小于0");
}
}
/**
* 根据key 获取过期时间
*
* @param key 键 不能为null
* @return 时间(秒) 返回0代表为永久有效
*/
public long getExpire(String key) {
return redisTemplate.getExpire(key, TimeUnit.SECONDS);
}
/**
* 判断key是否存在
*
* @param key 键
* @return true 存在 false不存在
*/
public boolean hasKey(String key) {
return redisTemplate.hasKey(key);
}
/**
* 删除缓存
*
* @param key 可以传一个值 或多个
*/
@SuppressWarnings("unchecked")
public void del(String... key) {
if (key != null && key.length > 0) {
if (key.length == 1) {
redisTemplate.delete(key[0]);
} else {
redisTemplate.delete(CollectionUtils.arrayToList(key));
}
}
}
// ============================String=============================
/**
* 普通缓存获取
*
* @param key 键
* @return 值
*/
public Object get(String key) {
Object object = redisTemplate.opsForValue().get(key);
return key == null ? null : object;
}
/**
* 普通缓存放入
*
* @param key 键
* @param value 值
* @return true成功 false失败
*/
public boolean set(String key, Object value) {
redisTemplate.opsForValue().set(key, value);
return true;
}
/**
* 普通缓存放入并设置时间
*
* @param key 键
* @param value 值
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
* @return true成功 false 失败
*/
public boolean set(String key, Object value, long time) {
if (time > 0) {
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
} else {
this.set(key, value);
}
return true;
}
/**
* 递增
*
* @param key 键
* @param by 要增加几(大于0)
* @return
*/
public long incr(String key, long delta) {
if (delta < 0) {
throw new RuntimeException("递增因子必须大于0");
}
return redisTemplate.opsForValue().increment(key, delta);
}
/**
* 递减
*
* @param key 键
* @param by 要减少几(小于0)
* @return
*/
public long decr(String key, long delta) {
if (delta < 0) {
throw new RuntimeException("递减因子必须大于0");
}
return redisTemplate.opsForValue().increment(key, -delta);
}
// ================================Map=================================
/**
* HashGet
*
* @param key 键 不能为null
* @param item 项 不能为null
* @return 值
*/
public Object hget(String key, String item) {
return redisTemplate.opsForHash().get(key, item);
}
/**
* 获取hashKey对应的所有键值
*
* @param key 键
* @return 对应的多个键值
*/
public Map<Object, Object> hmget(String key) {
return redisTemplate.opsForHash().entries(key);
}
/**
* HashSet
*
* @param key 键
* @param map 对应多个键值
* @return true 成功 false 失败
*/
public boolean hmset(String key, Map<String, Object> map) {
redisTemplate.opsForHash().putAll(key, map);
return true;
}
/**
* HashSet 并设置时间
*
* @param key 键
* @param map 对应多个键值
* @param time 时间(秒)
* @return true成功 false失败
*/
public boolean hmset(String key, Map<String, Object> map, long time) {
redisTemplate.opsForHash().putAll(key, map);
if (time > 0) {
expire(key, time);
}
return true;
}
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @return true 成功 false失败
*/
public boolean hset(String key, String item, Object value) {
redisTemplate.opsForHash().put(key, item, value);
return true;
}
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
* @return true 成功 false失败
*/
public boolean hset(String key, String item, Object value, long time) {
redisTemplate.opsForHash().put(key, item, value);
if (time > 0) {
expire(key, time);
}
return true;
}
/**
* 删除hash表中的值
*
* @param key 键 不能为null
* @param item 项 可以使多个 不能为null
*/
public void hdel(String key, Object... item) {
redisTemplate.opsForHash().delete(key, item);
}
/**
* 判断hash表中是否有该项的值
*
* @param key 键 不能为null
* @param item 项 不能为null
* @return true 存在 false不存在
*/
public boolean hHasKey(String key, String item) {
return redisTemplate.opsForHash().hasKey(key, item);
}
/**
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
*
* @param key 键
* @param item 项
* @param by 要增加几(大于0)
* @return
*/
public double hincr(String key, String item, double by) {
return redisTemplate.opsForHash().increment(key, item, by);
}
/**
* hash递减
*
* @param key 键
* @param item 项
* @param by 要减少记(小于0)
* @return
*/
public double hdecr(String key, String item, double by) {
return redisTemplate.opsForHash().increment(key, item, -by);
}
// ============================set=============================
/**
* 根据key获取Set中的所有值
*
* @param key 键
* @return
*/
public Set<Object> sGet(String key) {
return redisTemplate.opsForSet().members(key);
}
/**
* 根据value从一个set中查询,是否存在
*
* @param key 键
* @param value 值
* @return true 存在 false不存在
*/
public boolean sHasKey(String key, Object value) {
return redisTemplate.opsForSet().isMember(key, value);
}
/**
* 将数据放入set缓存
*
* @param key 键
* @param values 值 可以是多个
* @return 成功个数
*/
public long sSet(String key, Object... values) {
return redisTemplate.opsForSet().add(key, values);
}
/**
* 将set数据放入缓存
*
* @param key 键
* @param time 时间(秒)
* @param values 值 可以是多个
* @return 成功个数
*/
public long sSetAndTime(String key, long time, Object... values) {
final Long count = redisTemplate.opsForSet().add(key, values);
if (time > 0) {
expire(key, time);
}
return count;
}
/**
* 获取set缓存的长度
*
* @param key 键
* @return
*/
public long sGetSetSize(String key) {
return redisTemplate.opsForSet().size(key);
}
/**
* 移除值为value的
*
* @param key 键
* @param values 值 可以是多个
* @return 移除的个数
*/
public long setRemove(String key, Object... values) {
final Long count = redisTemplate.opsForSet().remove(key, values);
return count;
}
// ===============================list=================================
/**
* 获取list缓存的内容
*
* @param key 键
* @param start 开始
* @param end 结束 0 到 -1代表所有值
* @return
*/
public List<Object> lGet(String key, long start, long end) {
return redisTemplate.opsForList().range(key, start, end);
}
/**
* 获取list缓存的长度
*
* @param key 键
* @return
*/
public long lGetListSize(String key) {
return redisTemplate.opsForList().size(key);
}
/**
* 通过索引 获取list中的值
*
* @param key 键
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
* @return
*/
public Object lGetIndex(String key, long index) {
return redisTemplate.opsForList().index(key, index);
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @return
*/
public boolean lSet(String key, Object value) {
redisTemplate.opsForList().rightPush(key, value);
return true;
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public boolean lSet(String key, Object value, long time) {
redisTemplate.opsForList().rightPush(key, value);
if (time > 0) {
expire(key, time);
}
return true;
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @return
*/
public boolean lSet(String key, List<Object> value) {
redisTemplate.opsForList().rightPushAll(key, value);
return true;
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public boolean lSet(String key, List<Object> value, long time) {
redisTemplate.opsForList().rightPushAll(key, value);
if (time > 0) {
expire(key, time);
}
return true;
}
/**
* 根据索引修改list中的某条数据
*
* @param key 键
* @param index 索引
* @param value 值
* @return
*/
public boolean lUpdateIndex(String key, long index, Object value) {
redisTemplate.opsForList().set(key, index, value);
return true;
}
public Long getAndDeletePatternKeys(String pattern) {
Set<String> keys = redisTemplate.keys(pattern);
if (!CollectionUtils.isEmpty(keys)) {
return redisTemplate.delete(keys);
}
return null;
}
public Set<String> getPatternKeys(String pattern) {
return redisTemplate.keys(pattern);
}
/**
* 获取指定前缀key列表
*
* @return
*/
public Set<String> getKeys(String prefix) {
return redisTemplate.keys(prefix.concat("*"));
}
public Boolean refresh(String token) {
String cacheKey = genKey(new String[]{CacheType.ERASABLE.name(), "SESSION_TOKEN", RequestContext.getProduct(), token});
boolean hasKey = redisTemplate.hasKey(cacheKey);
if (hasKey) {
redisTemplate.expire(cacheKey, DEFAULT_SESSION_EXPIRATION, TimeUnit.SECONDS);
}
return hasKey;
}
public static String genKey(String... keyMembers) {
return StringUtils.join(keyMembers, VAR_SPLITOR).toUpperCase();
}
}
package com.yeejoin.amos.api.householdapi.constant;
import java.util.HashMap;
/**
* 北向-华为常量
*/
public class ImasterConstant {
public static final HashMap<String, String> stationStaus = new HashMap<String, String>() {
{
put("1", "离线");
put("2", "告警");
put("3", "在线");
}
};
public static final HashMap<String, String> alarmstatus = new HashMap<String, String>() {
{
put("1", "未处理");
}
};
public static final HashMap<String, String> alarmLevel = new HashMap<String, String>() {
{
put("1", "严重");
put("2", "重要");
put("3", "次要");
put("4", "提示");
}
};
public static String baseurl ="https://cn.fusionsolar.huawei.com";
public static String account ="ahsjmg-API";
public static String password ="huawei123";
public static String tokenUrl ="/thirdData/login";
public static String requestPOST="POST";
public static String requestGET="GET";
public static String stationListUrl="/thirdData/stations";
public static String stationDetailUrl = "/thirdData/getStationRealKpi";
public static String collectorListUrl = "/thirdData/getDevList";
public static String collectorDetailUrl = "/thirdData/getDevRealKpi";
public static String alarmListUrl = "/thirdData/getAlarmList";
public static String resovleRule_data_page_records = "data";
public static String resovle_rows="rows";
public static int devTypeC=62;
public static int devTypeI=1;
}
......@@ -2,7 +2,10 @@ package com.yeejoin.amos.api.householdapi.controller;
import com.yeejoin.amos.api.householdapi.Utils.HouseholdPvUtils;
import com.yeejoin.amos.api.householdapi.face.service.GoLangDataAcquisitionService;
import com.yeejoin.amos.api.householdapi.face.service.ImasterDataService;
import com.yeejoin.amos.api.householdapi.face.service.KSolarDataAcquisitionService;
import com.yeejoin.amos.api.householdapi.face.service.impl.ImasterDataServiceImpl;
import fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -31,6 +34,8 @@ public class HouseholdTestController {
private GoLangDataAcquisitionService goLangDataAcquisitionService;
@Autowired
private KSolarDataAcquisitionService kSolarDataAcquisitionService;
@Autowired
private ImasterDataService imasterDataService;
/**
......@@ -119,4 +124,27 @@ public class HouseholdTestController {
// goLangDataAcquisitionService.inverAlramInfo();
}
/**
* 新增户用光伏-厂商API haders
*
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@PostMapping(value = "/imasterNew")
@ApiOperation(httpMethod = "POST", value = "北向", notes = "北向")
public void imasterNew() throws IOException {
// imasterDataService.stationList();
// imasterDataService.stationDetail();
// imasterDataService.collectorList();
// imasterDataService.inverterList();
imasterDataService.inverterDetail();
// goLangDataAcquisitionService.collectorList();
//// goLangDataAcquisitionService.inverterList();
// goLangDataAcquisitionService.collectorDetail();
// goLangDataAcquisitionService.inverterDetail();
// goLangDataAcquisitionService.inverAlramInfo();
}
}
package com.yeejoin.amos.api.householdapi.face.dto;
import lombok.Data;
@Data
public class ImasterAlarmDto {
private Integer alarmId;
private Integer alarmType;
private Long raiseTime;
private String stationName;
private Integer lev;
private Integer devTypeId;
private String stationCode;
private String alarmName;
private String alarmCause;
private String devName;
private String repairSuggestion;
private String esnCode;
private Integer status;
}
......@@ -16,7 +16,7 @@ import java.util.Date;
@Data
@Accessors(chain = true)
@TableName("hygf_jp_inverter")
public class JpInverter implements Serializable {
public class JpInverter implements Serializable {
private static final long serialVersionUID = 1L;
......
package com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName(value = "imaster_collector_list", autoResultMap = true)
public class ImasterCollectorList {
private Long createdTime;
private Long id;
private String stationCode;
private String stationName;
private String devName;
private String esnCode;
private Integer devTypeId;
private String softwareVersion;
private String invType;
private Double longitude;
private Double latitude;
}
package com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName(value = "imaster_inverter_list", autoResultMap = true)
public class ImasterInverterList {
private Long createdTime;
private Long id;
private String stationCode;
private String stationName;
private String collectorSnCode;
private String devName;
private String esnCode;
private Integer devTypeId;
private String softwareVersion;
private String invType;
private Double longitude;
private Double latitude;
}
package com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName(value = "imaster_inverter_list_details", autoResultMap = true)
public class ImasterInverterListDetails {
private Long createdTime;
private String inverterId;
Double pv26_i ;
Double pv2_u ;
Double pv28_i ;
Double pv4_u ;
Double pv22_i ;
Double power_factor ;
Double pv6_u ;
Double mppt_total_cap ;
Double pv24_i ;
Double pv8_u ;
Double open_time ;
Double pv22_u ;
Double a_i ;
Double pv24_u ;
Double mppt_9_cap ;
Double c_i ;
Double pv20_u ;
Double pv19_u ;
Double pv15_u ;
Double reactive_power ;
Double a_u ;
Double pv17_u ;
Double c_u ;
Double mppt_8_cap ;
Double pv20_i ;
Double pv15_i ;
Double efficiency ;
Double pv17_i ;
Double pv11_i ;
Double pv13_i ;
Double pv11_u ;
Double mppt_power ;
Double pv13_u ;
Double run_state ;
Double close_time ;
Double pv19_i ;
Double mppt_7_cap ;
Double mppt_5_cap ;
Double pv27_u ;
Double pv2_i ;
Double active_power ;
Double pv4_i ;
Double pv6_i ;
Double pv8_i ;
Double mppt_6_cap ;
Double pv27_i ;
Double pv1_u ;
Double pv3_u ;
Double pv23_i ;
Double pv5_u ;
Double pv25_i ;
Double pv7_u ;
Double pv23_u ;
Double inverter_state ;
Double pv9_u ;
Double pv25_u ;
Double total_cap ;
Double mppt_3_cap ;
Double b_i ;
Double pv21_u ;
Double mppt_10_cap ;
Double pv16_u ;
Double pv18_u ;
Double temperature ;
Double bc_u ;
Double b_u ;
Double pv21_i ;
Double elec_freq ;
Double mppt_4_cap ;
Double pv16_i ;
Double pv18_i ;
Double day_cap ;
Double pv12_i ;
Double pv14_i ;
Double pv12_u ;
Double mppt_1_cap ;
Double pv14_u ;
Double pv10_u ;
Double pv26_u ;
Double pv1_i ;
Double pv28_u ;
Double pv3_i ;
Double mppt_2_cap ;
Double pv5_i ;
Double ab_u ;
Double ca_u ;
Double pv7_i ;
Double pv10_i ;
Double pv9_i ;
}
package com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName(value = "imaster_station_details" ,autoResultMap = true)
public class ImasterStationDetail {
private Long createdTime;
private String stationCode ;
private Double day_power ;
private Double month_power;
private Double total_power;
private Double day_income ;
private Double total_income ;
private Integer real_health_state;
}
package com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName(value = "imaster_station_details_day" ,autoResultMap = true)
public class ImasterStationDetailsDay {
private Long createdTime;
private String stationCode ;
private Double installedCapacity ;
private Double radiationIntensity;
private Double theoryPower ;
private Double performanceRatio ;
private Double inverterPower ;
private Double ongridPower ;
private Double usePower ;
private Double powerProfit ;
private Double perpowerRatio;
private Double reductionTotalCo2 ;
private Double reductionTotalCoal ;
private Double reductionTotalTree;
}
package com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName(value = "imaster_station_details_month" ,autoResultMap = true)
public class ImasterStationDetailsMonth {
private Long createdTime;
private String stationCode ;
private Double installedCapacity ;
private Double radiationIntensity;
private Double theoryPower ;
private Double performanceRatio ;
private Double inverterPower ;
private Double ongridPower ;
private Double usePower ;
private Double powerProfit ;
private Double perpowerRatio;
private Double reductionTotalCo2 ;
private Double reductionTotalCoal ;
private Double reductionTotalTree;
}
package com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName(value = "imaster_station_details_year" ,autoResultMap = true)
public class ImasterStationDetailsYear {
private Long createdTime;
private String stationCode ;
private Double installedCapacity ;
private Double radiationIntensity;
private Double theoryPower ;
private Double performanceRatio ;
private Double inverterPower ;
private Double ongridPower ;
private Double usePower ;
private Double powerProfit ;
private Double perpowerRatio;
private Double reductionTotalCo2 ;
private Double reductionTotalCoal ;
private Double reductionTotalTree;
}
package com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@TableName(value = "imaster_station_list" ,autoResultMap = true)
public class ImasterStationList implements Serializable {
private Long createdTime;
private String latitude;
private String longitude;
private String plantAddress;
private String plantName;
private String plantCode;
private String contactPerson;
private String contactMethod;
private String gridConnectionDate;
private Double capacity;
}
package com.yeejoin.amos.api.householdapi.face.orm.mapper.tdengine;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine.ImasterCollectorList;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface ImasterCollectorListMapper extends BaseMapper<ImasterCollectorList> {
@Select("select id from imaster_collector_list where esn_code is not null group by id")
List<Long> getCollectIds();
}
package com.yeejoin.amos.api.householdapi.face.orm.mapper.tdengine;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine.ImasterInverterListDetails;
public interface ImasterInverterListDetailsMapper extends BaseMapper<ImasterInverterListDetails> {
}
package com.yeejoin.amos.api.householdapi.face.orm.mapper.tdengine;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine.ImasterInverterList;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface ImasterInverterListMapper extends BaseMapper<ImasterInverterList> {
@Select("select esn_code from imaster_inverter_list where esn_code is not null group by esn_code")
List<String> getCollectIds();
}
package com.yeejoin.amos.api.householdapi.face.orm.mapper.tdengine;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine.ImasterInverterListDetails;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine.ImasterStationDetail;
public interface ImasterStationDetailsMapper extends BaseMapper<ImasterStationDetail> {
}
package com.yeejoin.amos.api.householdapi.face.orm.mapper.tdengine;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine.ImasterStationList;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;
import java.util.List;
public interface ImasterStationMapper extends BaseMapper<ImasterStationList> {
@Select("select * from imaster_station_list")
List<ImasterStationList> getStationInfo();
@Select("select plant_code as plantCode from imaster_station_list group by plant_code")
List<String> getStationIds();
}
package com.yeejoin.amos.api.householdapi.face.service;
public interface ImasterDataService {
/**
* @descrption 场站列表数据入库
*/
void stationList();
/**
* @descrption 场站详情数据入库
*/
void stationDetail();
/**
* @descrption 采集器列表数据入库
*/
void collectorList();
/**
* @descrption 采集器详情数据入库
*/
void collectorDetail();
/**
* @descrption 逆变器列表数据入库
*/
void inverterList();
/**
* @descrption 逆变器详情数据入库
*/
void inverterDetail();
/**
* @descrption 采集器告警列表数据入库
*/
void inverAlramInfo();
}
package com.yeejoin.amos.api.householdapi.face.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.api.householdapi.Utils.ImasterUtils;
import com.yeejoin.amos.api.householdapi.constant.GoLangConstant;
import com.yeejoin.amos.api.householdapi.constant.ImasterConstant;
import com.yeejoin.amos.api.householdapi.face.dto.AlarmDto;
import com.yeejoin.amos.api.householdapi.face.dto.CollectorDetailDto;
import com.yeejoin.amos.api.householdapi.face.dto.ImasterAlarmDto;
import com.yeejoin.amos.api.householdapi.face.dto.InverterDetailDto;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.hygf.JpCollector;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.hygf.JpInverter;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.hygf.JpInverterElectricity;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.hygf.JpStation;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine.*;
import com.yeejoin.amos.api.householdapi.face.orm.mapper.hygf.JpCollectorMapper;
import com.yeejoin.amos.api.householdapi.face.orm.mapper.hygf.JpInverterElectricityMapper;
import com.yeejoin.amos.api.householdapi.face.orm.mapper.hygf.JpInverterMapper;
import com.yeejoin.amos.api.householdapi.face.orm.mapper.hygf.JpStationMapper;
import com.yeejoin.amos.api.householdapi.face.orm.mapper.tdengine.*;
import com.yeejoin.amos.api.householdapi.face.service.ImasterDataService;
import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum;
import fastjson.JSON;
import org.apache.commons.lang.time.DateUtils;
import org.joda.time.DateTimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Service
public class ImasterDataServiceImpl implements ImasterDataService {
//北向请求工具封装
@Autowired
private ImasterUtils imasterUtils;
//北向mapper
@Autowired
private ImasterStationMapper imasterStationMapper;
//北向mapper
@Autowired
private ImasterCollectorListMapper imasterCollectorListMapper;
//北向mapper
@Autowired
private ImasterInverterListMapper imasterInverterListMapper;
//北向mapper
@Autowired
private ImasterInverterListDetailsMapper imasterInverterListDetailsMapper;
//北向mapper
@Autowired
private ImasterStationDetailsMapper imasterStationDetailsMapper;
//定时任务执行频率 当前为10分钟一次
private final String dataRequstScheduled = "0 0/60 * * * *";
//监盘场站mapper
@Autowired
private JpStationMapper jpStationMapper;
//监盘采集器mapper
@Autowired
private JpCollectorMapper jpCollectorMapper;
//监盘逆变器mapper
@Autowired
private JpInverterMapper jpInverterMapper;
//户用光伏场站历史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;
//户用光伏日发电量
@Autowired
JpInverterElectricityMapper jpInverterElectricityMapper;
@Scheduled(cron = dataRequstScheduled)
@Override
public void stationList() {
HashMap<String, Object> requestInfo = new HashMap<>();
requestInfo.put("pageNo", 1);
String requestParaminfo = JSON.toJSONString(requestInfo);
List<ImasterStationList> result = imasterUtils.getResPonse(ImasterConstant.stationListUrl,
GoLangConstant.requestPost,
requestParaminfo,
ImasterConstant.resovleRule_data_page_records,
ImasterStationList.class
);
for (int i = 0; i < result.size(); i++) {
ImasterStationList imasterStationList = result.get(i);
imasterStationList.setCreatedTime(System.currentTimeMillis());
imasterStationMapper.insert(imasterStationList);
}
}
@Scheduled(cron = dataRequstScheduled)
@Override
public void stationDetail() {
List<String> stationList = imasterStationMapper.getStationIds();
String today = DateUtil.today();
String hour = new Date().getHours() + ":00";
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
HashMap<String, Object> requestInfo = new HashMap<>();
requestInfo.put("stationCodes", stationList.stream().collect(Collectors.joining(",")));
String requestParaminfo = JSON.toJSONString(requestInfo);
List<ImasterStationDetail> result = imasterUtils.getResPonseOther(ImasterConstant.stationDetailUrl,
GoLangConstant.requestPost,
requestParaminfo,
ImasterConstant.resovleRule_data_page_records,
ImasterStationDetail.class
);
// List<ImasterStationDetail> result1 = imasterUtils.getResPonse(ImasterConstant.stationDetailUrl,
// GoLangConstant.requestPost,
// requestParaminfo,
// ImasterConstant.resovleRule_data_page_records,
// ImasterStationDetail.class
// );
// List<ImasterStationDetail> result2 = imasterUtils.getResPonse(ImasterConstant.stationDetailUrl,
// GoLangConstant.requestPost,
// requestParaminfo,
// ImasterConstant.resovleRule_data_page_records,
// ImasterStationDetail.class
// );
// List<ImasterStationDetail> result3 = imasterUtils.getResPonse(ImasterConstant.stationDetailUrl,
// GoLangConstant.requestPost,
// requestParaminfo,
// ImasterConstant.resovleRule_data_page_records,
// ImasterStationDetail.class
// );
for (int j = 0; j < result.size(); j++) {
QueryWrapper<ImasterStationList> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("plant_code", result.get(j).getStationCode());
queryWrapper.orderByDesc("created_time");
List<ImasterStationList> imasterStationListAll = imasterStationMapper.selectList(queryWrapper);
ImasterStationList imasterStationList = imasterStationListAll.get(0);
ImasterStationDetail imasterStationDetail = result.get(j);
imasterStationDetail.setStationCode(imasterStationList.getPlantCode());
imasterStationDetail.setCreatedTime(System.currentTimeMillis());
imasterStationDetailsMapper.insert(imasterStationDetail);
JpStation jpStation = jpStationMapper.selectOne(new QueryWrapper<JpStation>().
eq("third_code", PVProducerInfoEnum.HUAWEI.getCode()).
eq("third_station_id", imasterStationList.getPlantCode()));
//给户用光伏存储的数据赋值
if (ObjectUtils.isEmpty(jpStation)) {
jpStation = new JpStation();
}
// jpStation.setSnCode(imasterStationDetail.getNmicode());
jpStation.setCapacity(Double.valueOf(imasterStationList.getCapacity()));
jpStation.setName(imasterStationList.getPlantName());
// jpStation.setPrice(Double.valueOf(imasterStationDetail.getPrice()));
jpStation.setAddress(imasterStationList.getPlantAddress());
jpStation.setLongitude(imasterStationList.getLongitude());
jpStation.setLatitude(imasterStationList.getLatitude());
// jpStation.setUserName(imasterStationDetail.getUsername());
// jpStation.setUserPhone(String.valueOf(imasterStationDetail.getUsermobile()));
jpStation.setStationContact(imasterStationList.getContactPerson());
// jpStation.setModuleCount(ObjectUtils.isEmpty(Math.toIntExact(imasterStationDetail.getModule()))?0:Math.toIntExact(imasterStationDetail.getModule()));
//并网类型
// jpStation.setState(ImasterConstant.stationStaus.get(String.valueOf(imasterStationDetail.getRealHealthState())));
jpStation.setThirdStationId(imasterStationList.getPlantCode());
jpStation.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
// jpStation.setRealTimePower(imasterStationDetail.getPower());
// jpStation.setOnGridType(GoLangConstant.intoNetWorkStatus.get(String.valueOf(imasterStationDetail.getStationtypenew())));
jpStation.setDayGenerate(imasterStationDetail.getDay_power());
jpStation.setMonthGenerate(imasterStationDetail.getMonth_power());
// jpStation.setMonthGenerate(imasterStationDetail.getMonthPower());
// jpStation.setYearGenerate(imasterStationDetail.getYearenergy());
jpStation.setAccumulatedPower(imasterStationDetail.getTotal_power());
jpStation.setDayIncome(imasterStationDetail.getDay_income());
jpStation.setCumulativeIncome(imasterStationDetail.getTotal_income());
jpStation.setState(ImasterConstant.stationStaus.get(String.valueOf(imasterStationDetail.getReal_health_state())));
// jpStation.setDayIncome(imasterStationDetail.getDayIncome());
// jpStation.setMonthIncome(imasterStationDetail.getMonthincome());
// jpStation.setYearIncome(imasterStationDetail.getYearincome());
// jpStation.setCumulativeIncome(imasterStationDetail.getTotalIncome());
// jpStation.setArea(imasterStationDetail.getRegionstr());
// jpStation.setEmail(imasterStationDetail.getUseremail());
// jpStation.setOnGridTime(new Date(imasterStationDetail.getFispowertime()));
// jpStation.setAccessTime(new Date(imasterStationDetail.getFisgeneratetime()));
// jpStation.setCreateTime(new Date(imasterStationDetail.getCreatedate()));
// jpStation.setRatedPower(Double.valueOf(imasterStationDetail.getInverterpower()));
if (!ObjectUtils.isEmpty(jpStation.getSequenceNbr())) {
jpStationMapper.updateById(jpStation);
} else {
jpStationMapper.insert(jpStation);
}
HYGFJPStationPowerHistory hygfjpStationPowerHistory = new HYGFJPStationPowerHistory();
hygfjpStationPowerHistory.setCreatedTime(System.currentTimeMillis());
hygfjpStationPowerHistory.setThirdStationId(jpStation.getThirdStationId());
// hygfjpStationPowerHistory.setPower(imasterStationDetail.getPower());
hygfjpStationPowerHistory.setThirdCode(jpStation.getThirdCode());
hygfjpStationPowerHistory.setTime(System.currentTimeMillis());
hygfjpStationPowerHistoryMapper.insert(hygfjpStationPowerHistory);
HYGFJPDayPower hygfjpDayPower = hygfjpDayPowerMapper.selectOne(
new QueryWrapper<HYGFJPDayPower>().
eq("tation_id", imasterStationList.getPlantCode()).
eq("year_month_day", today).
eq("hour", hour)
);
if (ObjectUtils.isEmpty(hygfjpDayPower)) {
hygfjpDayPower = new HYGFJPDayPower();
}
hygfjpDayPower.setTationId(imasterStationList.getPlantCode());
hygfjpDayPower.setHour(hour);
hygfjpDayPower.setYearMonthDay(today);
// hygfjpDayPower.setPower(imasterStationDetail.getPower());
if (ObjectUtils.isEmpty(hygfjpDayPower.getCreatedTime())) {
hygfjpDayPower.setCreatedTime(System.currentTimeMillis());
hygfjpDayPowerMapper.insert(hygfjpDayPower);
} else {
hygfjpDayPowerMapper.insert(hygfjpDayPower);
}
}
}
@Scheduled(cron = dataRequstScheduled)
@Override
public void collectorList() {
List<String> stationIds = imasterStationMapper.getStationIds();
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
HashMap<String, Object> requestInfo = new HashMap<>();
requestInfo.put("stationCodes", stationIds.stream().collect(Collectors.joining(",")));
String requestParaminfo = JSON.toJSONString(requestInfo);
List<ImasterCollectorList> result = imasterUtils.getResPonse(ImasterConstant.collectorListUrl,
GoLangConstant.requestPost,
requestParaminfo,
ImasterConstant.resovleRule_data_page_records,
ImasterCollectorList.class
);
for (int j = 0; j < result.size(); j++) {
QueryWrapper<ImasterStationList> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("plant_code", result.get(j).getStationCode());
queryWrapper.orderByDesc("created_time");
List<ImasterStationList> imasterStationListAll = imasterStationMapper.selectList(queryWrapper);
ImasterStationList imasterStationList = imasterStationListAll.get(0);
ImasterCollectorList imasterCollectorList = result.get(j);
imasterCollectorList.setStationName(imasterStationList.getPlantName());
imasterCollectorList.setCreatedTime(System.currentTimeMillis());
if(imasterCollectorList.getDevTypeId() == ImasterConstant.devTypeC) {
imasterCollectorListMapper.insert(imasterCollectorList);
JpCollector jpCollector = jpCollectorMapper.selectOne(new QueryWrapper<JpCollector>().
eq("third_station_id", imasterCollectorList.getStationCode()).
eq("third_code", PVProducerInfoEnum.HUAWEI.getCode()).
eq("sn_code", imasterCollectorList.getEsnCode()));
if (ObjectUtils.isEmpty(jpCollector)) {
jpCollector = new JpCollector();
}
//sn编码
jpCollector.setSnCode(imasterCollectorList.getEsnCode());
//类型
// jpCollector.setType(collectorDetailDto.getModel());
//更新时间
jpCollector.setUpdateTime(new Date());
//出场日期
// jpCollector.setDischargeDate(new Date(collectorDetailDto.getFactoryTime()));
// //生产日期
// jpCollector.setProductDate(new Date(collectorDetailDto.getFactoryTime()));
// //数据上传间隔
// jpCollector.setDataPeriod(collectorDetailDto.getDataUploadCycle());
// //本次上电时间
// jpCollector.setThisWorkTime(new DateTime(collectorDetailDto.getCurrentWorkingTime()));
// //累计工作时间
// jpCollector.setTotalWorkTime(new DateTime(collectorDetailDto.getTotalWorkingTime()));
//第三方电站id
jpCollector.setThirdStationId(imasterCollectorList.getStationCode());
//第三方厂商标识
jpCollector.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
//第三方厂商标识
// jpCollector.setState(GoLangConstant.stationStaus.get(collectorDetailDto.getState()));
jpCollector.setStationName(imasterStationList.getPlantName());
jpCollector.setVersion(imasterCollectorList.getSoftwareVersion());
// jpCollector.setAddr(collectorDetailDto.getAddr());
// jpCollector.setName(collectorDetailDto.getName());
if (ObjectUtils.isEmpty(jpCollector.getSequenceNbr())) {
jpCollectorMapper.insert(jpCollector);
} else {
jpCollectorMapper.updateById(jpCollector);
}
// td-collector-history
HYGFJPCollectorHistory hygfjpCollectorHistory = new HYGFJPCollectorHistory();
hygfjpCollectorHistory.setTime(System.currentTimeMillis());
hygfjpCollectorHistory.setCreatedTime(System.currentTimeMillis());
hygfjpCollectorHistory.setSnCode(imasterCollectorList.getEsnCode());
// hygfjpCollectorHistory.setSignalStrength(Double.valueOf(collectorDetailDto.getRssiLevel()));
hygfjpCollectorHistory.setThirdStationId(imasterCollectorList.getStationCode());
hygfjpCollectorHistory.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
hygfjpCollectorHistoryMapper.insert(hygfjpCollectorHistory);
}
}
}
@Override
public void collectorDetail() {
}
@Scheduled(cron = dataRequstScheduled)
@Override
public void inverterList() {
List<String> stationIds = imasterStationMapper.getStationIds();
for (int i = 0; i < stationIds.size(); i++) {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
HashMap<String, Object> requestInfo = new HashMap<>();
requestInfo.put("stationCodes", stationIds.stream().collect(Collectors.joining(",")));
String requestParaminfo = JSON.toJSONString(requestInfo);
List<ImasterInverterList> result = imasterUtils.getResPonse(ImasterConstant.collectorListUrl,
GoLangConstant.requestPost,
requestParaminfo,
ImasterConstant.resovleRule_data_page_records,
ImasterInverterList.class
);
for (int j = 0; j < result.size(); j++) {
QueryWrapper<ImasterStationList> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("plant_code", result.get(j).getStationCode());
queryWrapper.orderByDesc("created_time");
List<ImasterStationList> imasterStationListAll = imasterStationMapper.selectList(queryWrapper);
ImasterStationList imasterStationList = imasterStationListAll.get(0);
ImasterInverterList imasterInverterList = result.get(j);
imasterInverterList.setStationName(imasterStationList.getPlantName());
imasterInverterList.setCreatedTime(System.currentTimeMillis());
if(imasterInverterList.getDevTypeId() == ImasterConstant.devTypeI) {
imasterInverterListMapper.insert(imasterInverterList);
}
}
}
}
@Scheduled(cron = dataRequstScheduled)
@Override
public void inverterDetail() {
List<String> inverterSns = imasterInverterListMapper.getCollectIds();
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
HashMap<String, Object> requestInfo = new HashMap<>();
String collect = inverterSns.stream().collect(Collectors.joining(","));
requestInfo.put("sns", collect);
requestInfo.put("devTypeId", 1);
String requestParaminfo = JSON.toJSONString(requestInfo);
List<ImasterInverterListDetails> result = imasterUtils.getResPonseOther(ImasterConstant.collectorDetailUrl,
GoLangConstant.requestPost,
requestParaminfo,
ImasterConstant.resovleRule_data_page_records,
ImasterInverterListDetails.class
);
for (int j = 0; j < result.size(); j++) {
ImasterInverterListDetails inverterDetailDto = result.get(j);
inverterDetailDto.setCreatedTime((System.currentTimeMillis()));
imasterInverterListDetailsMapper.insert(result.get(j));
QueryWrapper<ImasterInverterList> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("esn_code", result.get(j).getInverterId());
queryWrapper.orderByDesc("created_time");
List<ImasterInverterList> imasterInverterLists = imasterInverterListMapper.selectList(queryWrapper);
ImasterInverterList imasterInverterList = imasterInverterLists.get(0);
QueryWrapper<ImasterCollectorList> queryWrapper1 = new QueryWrapper<>();
queryWrapper1.eq("dev_name", imasterInverterList.getDevName());
queryWrapper1.orderByDesc("created_time");
List<ImasterCollectorList> collectorLists = imasterCollectorListMapper.selectList(queryWrapper1);
ImasterCollectorList collectorList = collectorLists.get(0);
JpInverter jpInverter = jpInverterMapper.selectOne(new QueryWrapper<JpInverter>().
eq("third_station_id", imasterInverterList.getStationCode()).
eq("third_code", PVProducerInfoEnum.HUAWEI.getCode()).
eq("sn_code", imasterInverterList.getEsnCode()));
if (ObjectUtils.isEmpty(jpInverter)) {
jpInverter = new JpInverter();
}
jpInverter.setSnCode(imasterInverterList.getEsnCode());
jpInverter.setCollectorSnCode(collectorList.getEsnCode());
jpInverter.setCollectorId(String.valueOf(collectorList.getId()));
jpInverter.setDayPowerGeneration(inverterDetailDto.getDay_cap());
// jpInverter.setState(GoLangConstant.stationStaus.get(inverterDetailDto.getCurrentState()));
// jpInverter.setCollectorId(inverterDetailDto.getCollectorId());
// jpInverter.setCollectorSnCode(inverterDetailDto.getCollectorsn());
jpInverter.setUpdateTime(new Date());
// jpInverter.setCurrentPower(inverterDetailDto.getPac());
// jpInverter.setDayPowerGeneration(inverterDetailDto.getEToday());
// jpInverter.setMonthPowerGeneration(inverterDetailDto.getEMonth() * GoLangConstant.mwhTokwh);
// jpInverter.setYearPowerGeneration(inverterDetailDto.getEYear() * GoLangConstant.mwhTokwh);
// jpInverter.setTotalPowerGeneration(inverterDetailDto.getETotal() * GoLangConstant.mwhTokwh);
// jpInverter.setBrand(inverterDetailDto.getName());
// jpInverter.setModel(inverterDetailDto.getProductModel());
// jpInverter.setNationalStandard(inverterDetailDto.getNationalStandards());
jpInverter.setVersion(imasterInverterList.getSoftwareVersion());
// jpInverter.setGenerationHours(String.valueOf(inverterDetailDto.getFullHour()));
jpInverter.setId(imasterInverterList.getId());
// jpInverter.setCapacity(inverterDetailDto.getPower().intValue());
jpInverter.setThirdStationId(String.valueOf(imasterInverterList.getStationCode()));
jpInverter.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
jpInverter.setStationName(imasterInverterList.getStationName());
if (!ObjectUtils.isEmpty(jpInverter.getSequenceNbr())) {
jpInverterMapper.updateById(jpInverter);
} else {
jpInverterMapper.insert(jpInverter);
}
String jsonString = JSON.toJSONString(inverterDetailDto);
Map<String, Object> hanlderResult = JSON.parseObject(jsonString, Map.class);
JpInverterElectricity jpInverterElectricityR = jpInverterElectricityMapper.selectOne(new QueryWrapper<JpInverterElectricity>().
eq("sn_code", imasterInverterList.getEsnCode()).
eq("type", "交流").
eq("name", "A")
);
if (ObjectUtils.isEmpty(jpInverterElectricityR)) {
jpInverterElectricityR = new JpInverterElectricity();
}
jpInverterElectricityR.setInverterId(String.valueOf(imasterInverterList.getId()));
jpInverterElectricityR.setSnCode(imasterInverterList.getEsnCode());
jpInverterElectricityR.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
jpInverterElectricityR.setThirdStationId(imasterInverterList.getStationCode());
jpInverterElectricityR.setType("交流");
jpInverterElectricityR.setName("A");
jpInverterElectricityR.setVoltage(inverterDetailDto.getA_u());
jpInverterElectricityR.setCurrent(inverterDetailDto.getA_i());
if (ObjectUtils.isEmpty(jpInverterElectricityR.getSequenceNbr())) {
jpInverterElectricityMapper.insert(jpInverterElectricityR);
} else {
jpInverterElectricityMapper.updateById(jpInverterElectricityR);
}
JpInverterElectricity jpInverterElectricityB = jpInverterElectricityMapper.selectOne(new QueryWrapper<JpInverterElectricity>().
eq("sn_code", imasterInverterList.getEsnCode()).
eq("type", "交流").
eq("name", "B")
);
if (ObjectUtils.isEmpty(jpInverterElectricityB)) {
jpInverterElectricityB = new JpInverterElectricity();
}
jpInverterElectricityB.setInverterId(String.valueOf(imasterInverterList.getId()));
jpInverterElectricityB.setSnCode(imasterInverterList.getEsnCode());
jpInverterElectricityB.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
jpInverterElectricityB.setThirdStationId(imasterInverterList.getStationCode());
jpInverterElectricityB.setType("交流");
jpInverterElectricityB.setName("B");
jpInverterElectricityB.setVoltage(inverterDetailDto.getB_u());
jpInverterElectricityB.setCurrent(inverterDetailDto.getB_i());
if (ObjectUtils.isEmpty(jpInverterElectricityB.getSequenceNbr())) {
jpInverterElectricityMapper.insert(jpInverterElectricityB);
} else {
jpInverterElectricityMapper.updateById(jpInverterElectricityB);
}
JpInverterElectricity jpInverterElectricityC = jpInverterElectricityMapper.selectOne(new QueryWrapper<JpInverterElectricity>().
eq("sn_code", imasterInverterList.getEsnCode()).
eq("type", "交流").
eq("name", "C")
);
if (ObjectUtils.isEmpty(jpInverterElectricityC)) {
jpInverterElectricityC = new JpInverterElectricity();
}
jpInverterElectricityC.setInverterId(String.valueOf(imasterInverterList.getId()));
jpInverterElectricityC.setSnCode(imasterInverterList.getEsnCode());
jpInverterElectricityC.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
jpInverterElectricityC.setThirdStationId(imasterInverterList.getStationCode());
jpInverterElectricityC.setType("交流");
jpInverterElectricityC.setName("C");
jpInverterElectricityC.setVoltage(inverterDetailDto.getC_u());
jpInverterElectricityC.setCurrent(inverterDetailDto.getC_i());
if (ObjectUtils.isEmpty(jpInverterElectricityC.getSequenceNbr())) {
jpInverterElectricityMapper.insert(jpInverterElectricityC);
} else {
jpInverterElectricityMapper.updateById(jpInverterElectricityC);
}
for (int k1 = 1; k1 < 29; k1++) {
JpInverterElectricity jpInverterElectricity = jpInverterElectricityMapper.selectOne(new QueryWrapper<JpInverterElectricity>().
eq("sn_code", imasterInverterList.getEsnCode()).
eq("type", "直流").
eq("name", "PV" + k1)
);
if (ObjectUtils.isEmpty(jpInverterElectricity)) {
jpInverterElectricity = new JpInverterElectricity();
}
jpInverterElectricity.setInverterId(String.valueOf(imasterInverterList.getId()));
jpInverterElectricity.setSnCode(imasterInverterList.getEsnCode());
jpInverterElectricity.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
jpInverterElectricity.setThirdStationId(String.valueOf(imasterInverterList.getStationCode()));
jpInverterElectricity.setType("直流");
jpInverterElectricity.setName("PV" + k1);
jpInverterElectricity.setVoltage(Double.valueOf(hanlderResult.get("pv" + k1 + "_u").toString()));
jpInverterElectricity.setCurrent(Double.valueOf(hanlderResult.get("pv" + k1 + "_i").toString()));
// jpInverterElectricity.setPower(Double.valueOf(hanlderResult.get("pow" + k1).toString()));
if (ObjectUtils.isEmpty(jpInverterElectricity.getSequenceNbr())) {
jpInverterElectricityMapper.insert(jpInverterElectricity);
} else {
jpInverterElectricityMapper.updateById(jpInverterElectricity);
}
}
HYGFJPInverterElecHistory hygfjpInverterElecHistory = new HYGFJPInverterElecHistory();
hygfjpInverterElecHistory.setThirdStationId(String.valueOf(imasterInverterList.getStationCode()));
hygfjpInverterElecHistory.setCreatedTime(System.currentTimeMillis());
hygfjpInverterElecHistory.setSnCode(imasterInverterList.getEsnCode());
hygfjpInverterElecHistory.setUAcCurrent(inverterDetailDto.getA_i());
hygfjpInverterElecHistory.setVAcCurrent(inverterDetailDto.getB_i());
hygfjpInverterElecHistory.setWAcCurrent(inverterDetailDto.getC_i());
hygfjpInverterElecHistory.setUAcVoltage(inverterDetailDto.getA_u());
hygfjpInverterElecHistory.setVAcVoltage(inverterDetailDto.getB_u());
hygfjpInverterElecHistory.setWAcVoltage(inverterDetailDto.getC_u());
hygfjpInverterElecHistory.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
hygfjpInverterElecHistory.setTime(System.currentTimeMillis());
hygfjpInverterElecHistoryMapper.insert(hygfjpInverterElecHistory);
// 逆变器历史
String today = DateUtil.today();
HYGFJPInverterHistory hygfjpInverterHistory = hygfjpInverterHistoryMapper.selectOne(new QueryWrapper<HYGFJPInverterHistory>().eq("sn_code", imasterInverterList.getEsnCode()).eq("date", today));
if (ObjectUtils.isEmpty(hygfjpInverterHistory)) {
hygfjpInverterHistory = new HYGFJPInverterHistory();
}
hygfjpInverterHistory.setDate(today);
hygfjpInverterHistory.setThirdStationId(String.valueOf(imasterInverterList.getStationCode()));
hygfjpInverterHistory.setInverterId(String.valueOf(imasterInverterList.getId()));
hygfjpInverterHistory.setSnCode(imasterInverterList.getEsnCode());
hygfjpInverterHistory.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
// hygfjpInverterHistory.setGenerationHours(inverterDetailDto.getFullHour());
// hygfjpInverterHistory.setPowerGeneration(inverterDetailDto.getEToday());
if (ObjectUtils.isEmpty(hygfjpInverterHistory.getCreatedTime())) {
hygfjpInverterHistory.setCreatedTime(System.currentTimeMillis());
hygfjpInverterHistoryMapper.insert(hygfjpInverterHistory);
} else {
hygfjpInverterHistoryMapper.insert(hygfjpInverterHistory);
}
}
}
@Scheduled(cron = dataRequstScheduled)
@Override
public void inverAlramInfo() {
List<String> inverterSns = imasterInverterListMapper.getCollectIds();
for (int i = 0; i < inverterSns.size(); i++) {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
HashMap<String, Object> requestInfo = new HashMap<>();
requestInfo.put("sns", inverterSns.stream().collect(Collectors.joining(",")));
requestInfo.put("language", "zh_CN ");
requestInfo.put("devTypes", 1);
requestInfo.put("beginTime", DateUtil.today());
requestInfo.put("endTime", DateUtil.today());
String requestParaminfo = JSON.toJSONString(requestInfo);
List<ImasterAlarmDto> result = imasterUtils.getResPonse(ImasterConstant.alarmListUrl,
GoLangConstant.requestPost,
requestParaminfo,
ImasterConstant.resovleRule_data_page_records,
ImasterAlarmDto.class
);
for (int j = 0; j < result.size(); j++) {
ImasterAlarmDto alarmDto = result.get(j);
if (!ObjectUtils.isEmpty(alarmDto.getEsnCode())) {
HYGFJPInverterWarn hygfjpInverterWarn = hygfjpInverterWarnMapper.selectOne(new QueryWrapper<HYGFJPInverterWarn>()
.eq("sn_code", alarmDto.getEsnCode())
.eq("start_time", alarmDto.getRaiseTime())
.eq("third_station_id", String.valueOf(alarmDto.getStationCode()))
);
if (ObjectUtils.isEmpty(hygfjpInverterWarn)) {
hygfjpInverterWarn = new HYGFJPInverterWarn();
}
hygfjpInverterWarn.setTime(System.currentTimeMillis());
hygfjpInverterWarn.setTimeLong(System.currentTimeMillis());
hygfjpInverterWarn.setSnCode(alarmDto.getEsnCode());
hygfjpInverterWarn.setThirdStationId(String.valueOf(alarmDto.getStationCode()));
hygfjpInverterWarn.setLevel(ImasterConstant.alarmLevel.get(alarmDto.getLev().toString()));
hygfjpInverterWarn.setContent(alarmDto.getAlarmName());
hygfjpInverterWarn.setThirdCode(PVProducerInfoEnum.HUAWEI.getCode());
hygfjpInverterWarn.setTreatment(alarmDto.getDevName());
hygfjpInverterWarn.setStartTime(alarmDto.getRaiseTime());
hygfjpInverterWarn.setState(ImasterConstant.alarmstatus.get(alarmDto.getStatus().toString()));
if (ObjectUtils.isEmpty(hygfjpInverterWarn.getCreatedTime())) {
hygfjpInverterWarn.setCreatedTime(System.currentTimeMillis());
hygfjpInverterWarnMapper.insert(hygfjpInverterWarn);
} else {
hygfjpInverterWarnMapper.insert(hygfjpInverterWarn);
}
}
}
}
}
}
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