Commit d7721b58 authored by hezhuozhi's avatar hezhuozhi

修改电站监控数据不一致问题

parent ca0b7ae1
...@@ -3,6 +3,7 @@ package com.yeejoin.amos.api.householdapi.Utils; ...@@ -3,6 +3,7 @@ package com.yeejoin.amos.api.householdapi.Utils;
import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.log.Log; import cn.hutool.log.Log;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
...@@ -11,6 +12,7 @@ import com.yeejoin.amos.api.householdapi.constant.GoLangConstant; ...@@ -11,6 +12,7 @@ import com.yeejoin.amos.api.householdapi.constant.GoLangConstant;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HousepvapiRecords; import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HousepvapiRecords;
import com.yeejoin.amos.api.householdapi.face.orm.mapper.houseapi.HousepvapiRecordsMapper; import com.yeejoin.amos.api.householdapi.face.orm.mapper.houseapi.HousepvapiRecordsMapper;
import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum; import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum;
import fastjson.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -43,6 +45,63 @@ public class GolangRequestUtil { ...@@ -43,6 +45,63 @@ public class GolangRequestUtil {
return hashMap; return hashMap;
} }
/**
* 这个方法是为了查出全部的数据
* @param apiurl 请求url
* @param requestMethod 请求方式
* @param requestInfo 请求信息
* @param ResultResolveRule 请求的解析
* @param tClass 需要转换成的bean
* @param <T> 泛型数据
* @return List<T> list<Result>
* @desc 根据请求参数发送http请求并且对于返回的数据进行处理
*/
public <T> List<T> getResPonseList(String apiurl, String requestMethod, HashMap<String, Object> requestInfo, String ResultResolveRule, Class<T> tClass) {
String respone = "";
String params = "";
JSONArray jsonArray = null;
List<T> result = new ArrayList<>();
Integer pageNo = 1;
try {
do {
requestInfo.put("pageNo", pageNo);
String requestParmInfo = JSON.toJSONString(requestInfo);
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);
if (!ObjectUtils.isEmpty(jsonArray)) {
result.addAll(JSONArray.parseArray(jsonArray.toJSONString(), tClass));
}
//处理其他页数的数据
JSONObject responeJSON = JSONObject.parseObject(respone);
JSONObject data = responeJSON.getJSONObject("data");
Integer responePages = 0;
if (data.containsKey("pages")){
responePages = data.getInteger("pages");
} else {
JSONObject page = data.getJSONObject("page");
responePages = page.getInteger("pages");
}
if (responePages == pageNo){
break;
} else {
pageNo++;
}
}while (true);
} catch (Exception exception) {
log.error(exception.getMessage(),exception);
return result;
}
return result;
}
/** /**
* @param apiurl 请求url * @param apiurl 请求url
* @param requestMethod 请求方式 * @param requestMethod 请求方式
......
...@@ -46,6 +46,55 @@ public class GoodWeRequestUtil { ...@@ -46,6 +46,55 @@ public class GoodWeRequestUtil {
} }
return hashMap; return hashMap;
} }
/**
* @param apiurl 请求url
* @param requestMethod 请求方式
* @param requestInfo 请求参数mapper
* @param ResultResolveRule 请求的解析
* @param tClass 需要转换成的bean
* @param <T> 泛型数据
* @return List<T> list<Result>
* @desc 根据请求参数发送http请求并且对于返回的数据进行处理
*/
public <T> List<T> getResPonseList(String apiurl, String requestMethod, HashMap<String, Object> requestInfo, String ResultResolveRule, Class<T> tClass) {
String respone = "";
JSONArray jsonArray = null;
List<T> result = new ArrayList<>();
Integer pageNo = 1;
try {
do {
requestInfo.put("page_index", pageNo);
String requestParmInfo = fastjson.JSON.toJSONString(requestInfo);
HashMap<String, String> headMap = getHeaderOfGoodWE();
String url = GoodWeConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
//token如果失效重新获取{"code":100002,"msg":"授权已失效,请重新登录","data":null}
if(JSONObject.parseObject(respone).getInteger("code") == 100002){
redisUtils.del(redisKey);
respone = sendRequest(requestMethod, url, requestParmInfo, getHeaderOfGoodWE());
}
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
if (!ObjectUtils.isEmpty(jsonArray)) {
result.addAll(JSONArray.parseArray(jsonArray.toJSONString(), tClass));
}
//处理其他页数的数据
JSONObject responeJSON = JSONObject.parseObject(respone);
JSONObject data = responeJSON.getJSONObject("data");
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 responePages=(record/pageSize)+1;
if (responePages == pageNo){
break;
} else {
pageNo++;
}
} while (true);
} catch (Exception exception) {
return result;
}
return result;
}
/** /**
* @param apiurl 请求url * @param apiurl 请求url
...@@ -66,6 +115,11 @@ public class GoodWeRequestUtil { ...@@ -66,6 +115,11 @@ public class GoodWeRequestUtil {
HashMap<String, String> headMap = getHeaderOfGoodWE(); HashMap<String, String> headMap = getHeaderOfGoodWE();
String url = GoodWeConstant.baseurl + apiurl; String url = GoodWeConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap); respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
//token如果失效重新获取{"code":100002,"msg":"授权已失效,请重新登录","data":null}
if(JSONObject.parseObject(respone).getInteger("code") == 100002){
redisUtils.del(redisKey);
respone = sendRequest(requestMethod, url, requestParmInfo, getHeaderOfGoodWE());
}
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone); jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
if (!ObjectUtils.isEmpty(jsonArray)) { if (!ObjectUtils.isEmpty(jsonArray)) {
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass); result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
......
...@@ -5,16 +5,14 @@ import cn.hutool.http.HttpUtil; ...@@ -5,16 +5,14 @@ import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.api.householdapi.constant.GoodWeConstant;
import com.yeejoin.amos.api.householdapi.constant.SoFarConstant; import com.yeejoin.amos.api.householdapi.constant.SoFarConstant;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine.Sunlight;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
@Component @Component
...@@ -86,6 +84,53 @@ public class SofarRequestUtil { ...@@ -86,6 +84,53 @@ public class SofarRequestUtil {
return requestHeader; return requestHeader;
} }
/**
* @param apiurl 请求url
* @param requestMethod 请求方式
* @param requestInfo 请求参数mapper
* @param ResultResolveRule 请求的解析
* @param tClass 需要转换成的bean
* @param <T> 泛型数据
* @return List<T> list<Result>
* @desc 根据请求参数发送http请求并且对于返回的数据进行处理
*/
public <T> List<T> getResPonseList(String apiurl, String requestMethod, Map<String, Object> requestInfo, String ResultResolveRule, Class<T> tClass) {
String respone = "";
List<T> result = new ArrayList<>();
Integer pageNo = 1;
try {
do {
requestInfo.put("page", pageNo);
String requestParmInfo = JSON.toJSONString(requestInfo);
HashMap<String, String> headMap = getHeaderOfSofar();
String url = SoFarConstant.baseurl + apiurl;
respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
//token如果失效重新获取{"code": 500,"msg": "Login status has expired","success": false}
if(JSONObject.parseObject(respone).getInteger("code") == 500){
redisUtils.del(redisKey);
respone = sendRequest(requestMethod, url, requestParmInfo, headMap);
}
JSONObject jsonObject = JSONObject.parseObject(respone);
if(jsonObject!=null&&jsonObject.get(ResultResolveRule)!=null){
result.addAll(JSONArray.parseArray(fastjson.JSON.toJSONString(jsonObject.get(ResultResolveRule)), tClass));
}
//处理其他页数的数据
JSONObject responeJSON = JSONObject.parseObject(respone);
Integer total = responeJSON.getInteger("total");
Integer pageSize= requestInfo.get("size")==null || (Integer)requestInfo.get("size")==0? 1:(Integer)requestInfo.get("size");
Integer responePages=(total/pageSize)+1;
if (responePages == pageNo){
break;
} else {
pageNo++;
}
} while (true);
} catch (Exception exception) {
exception.printStackTrace();
}
return result;
}
/** /**
* @param apiurl 请求url * @param apiurl 请求url
......
...@@ -6,9 +6,12 @@ import cn.hutool.http.HttpResponse; ...@@ -6,9 +6,12 @@ import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.yeejoin.amos.api.householdapi.face.dto.SunlightDto; import com.yeejoin.amos.api.householdapi.face.dto.SunlightDto;
import com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.tdeingine.Sunlight;
import com.yeejoin.amos.api.householdapi.face.orm.mapper.houseapi.HousepvapiRecordsMapper; import com.yeejoin.amos.api.householdapi.face.orm.mapper.houseapi.HousepvapiRecordsMapper;
import fastjson.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
...@@ -23,7 +26,9 @@ import javax.naming.Name; ...@@ -23,7 +26,9 @@ import javax.naming.Name;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -207,6 +212,61 @@ public class SunlightUtil { ...@@ -207,6 +212,61 @@ public class SunlightUtil {
} }
} }
/**
* 获取全部的数据
* @param url
* @param bodyparam
* @return
*/
public JSONObject getDataList(String url, Map<String, Object> bodyparam){
JSONObject resultData = new JSONObject();
JSONArray pageList = new JSONArray();
Integer pageNo = 1;
try {
do {
bodyparam.put("curPage", pageNo);
//请求头
HttpRequest request = HttpUtil.createPost(dfurl+url);
request.header("Content-Type", "application/json;charset=UTF-8");
request.header("sys_code", "901");
request.header("x-access-key", access_key);
//请求body
bodyparam.put("appkey", appkey);
bodyparam.put("token", this.getSunlightToken());
Gson gson = new Gson();
String body = gson.toJson(bodyparam);
request.body(body);
HttpResponse execute = request.execute();
if (!execute.isOk()) {
throw new RuntimeException(execute.body());
}
String res = UnicodeUtil.toString(execute.body());
JSONObject jsonObject = JSONUtil.parseObj(res, true);
resultData = JSONUtil.parseObj(jsonObject.get("result_data"), true);
if(resultData!=null && resultData.get("pageList")!=null){
pageList.addAll(JSONArray.parseArray(JSON.toJSONString(resultData.get("pageList"))));
resultData.putOpt("pageList",pageList);
}
//处理其他页数的数据
Integer rowCount = resultData.getInt("rowCount");
Integer pageSize= bodyparam.get("size")==null || (Integer)bodyparam.get("size")==0? 1:(Integer)bodyparam.get("size");
Integer responePages=(rowCount/pageSize)+1;
if (responePages == pageNo){
break;
} else {
pageNo++;
}
} while (true);
} catch (Exception e) {
log.error("失败,msg={}", e.getMessage());
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
return resultData;
}
//获取接口数据 //获取接口数据
......
package com.yeejoin.amos.api.householdapi.face.service.impl; package com.yeejoin.amos.api.householdapi.face.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
...@@ -35,10 +36,7 @@ import org.springframework.scheduling.annotation.Scheduled; ...@@ -35,10 +36,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
...@@ -109,12 +107,13 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe ...@@ -109,12 +107,13 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe
requestInfo.put("page_index", 1); requestInfo.put("page_index", 1);
requestInfo.put("page_size", 200); requestInfo.put("page_size", 200);
// requestInfo.put("key", "龙虎山北区"); // requestInfo.put("key", "龙虎山北区");
String requstParam = JSON.toJSONString(requestInfo);
String today = DateUtil.today(); String today = DateUtil.today();
String hour = new Date().getHours() + ":00"; String hour = new Date().getHours() + ":00";
List<GoodWeStationMonitorDto> goodWeStationLists = goodWeRequestUtil.getResPonse( List<GoodWeStationMonitorDto> goodWeStationLists = goodWeRequestUtil.getResPonseList(
GoodWeConstant.stationListStatusUrl, GoodWeConstant.requestPost, requstParam, GoodWeConstant.stationListStatusUrl, GoodWeConstant.requestPost, requestInfo,
GoodWeConstant.resovleRule_data_list, GoodWeStationMonitorDto.class); GoodWeConstant.resovleRule_data_list, GoodWeStationMonitorDto.class);
//删除多余的场站
deleteBDWStation(goodWeStationLists);
if (goodWeStationLists.size() > 0) { if (goodWeStationLists.size() > 0) {
goodWeStationLists.forEach(goodWeStationMonitorDto -> { goodWeStationLists.forEach(goodWeStationMonitorDto -> {
GoodWeStationMonitorList goodWeStationList = new GoodWeStationMonitorList(); GoodWeStationMonitorList goodWeStationList = new GoodWeStationMonitorList();
...@@ -296,7 +295,9 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe ...@@ -296,7 +295,9 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe
TdHYGFStationAllGenerate.setYearTime(DateUtil.format(today1, "yyyy")); TdHYGFStationAllGenerate.setYearTime(DateUtil.format(today1, "yyyy"));
TdHYGFStationAllGenerate.setYear(DateUtil.format(today1, "yyyy")); TdHYGFStationAllGenerate.setYear(DateUtil.format(today1, "yyyy"));
TdHYGFStationAllGenerate.setGenerate(jpStation.getYearGenerate()); TdHYGFStationAllGenerate.setGenerate(jpStation.getYearGenerate());
TdHYGFStationAllGenerate.setFullhour(jpStation.getYearGenerate() / jpStation.getCapacity()); if (ObjectUtils.isNotEmpty(jpStation.getYearGenerate())) {
TdHYGFStationAllGenerate.setFullhour(jpStation.getYearGenerate() / jpStation.getCapacity());
}
TdHYGFStationAllGenerate.setIncome(jpStation.getYearIncome()); TdHYGFStationAllGenerate.setIncome(jpStation.getYearIncome());
// 新加 // 新加
TdHYGFStationAllGenerate.setAmosCompanyCode(jpStation.getAmosCompanyCode()); TdHYGFStationAllGenerate.setAmosCompanyCode(jpStation.getAmosCompanyCode());
...@@ -315,13 +316,37 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe ...@@ -315,13 +316,37 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe
logger.info("-------固德威同步场站和告警结束" + ts + "------- " + sdf.format(new Date())); logger.info("-------固德威同步场站和告警结束" + ts + "------- " + sdf.format(new Date()));
} }
/**
* 删除多余的场站
* @param goodWeStationLists
*/
private void deleteBDWStation(List<GoodWeStationMonitorDto> goodWeStationLists) {
if(CollectionUtil.isNotEmpty(goodWeStationLists)){
List<String> stationIds = new ArrayList<>();
for (GoodWeStationMonitorDto goodWeStationMonitorDto : goodWeStationLists) {
stationIds.add(goodWeStationMonitorDto.getPowerstation_id());
}
QueryWrapper<JpStation> wrapper = new QueryWrapper<JpStation>().eq("third_code", PVProducerInfoEnum.GDW.getCode());
List<JpStation> jpStations = jpStationMapper.selectList(wrapper);
if(CollectionUtil.isNotEmpty(jpStations)){
for (JpStation jpStation : jpStations) {
if(!stationIds.contains(jpStation.getThirdStationId())){
//删除多余数据
jpStationMapper.deleteById(jpStation.getSequenceNbr());
}
}
}
}
}
@Override @Override
@Scheduled(cron = "${dataRequstScheduled.GoodWe}") @Scheduled(cron = "${dataRequstScheduled.GoodWe}")
@Async @Async
public void stationDetail() { public void stationDetail() {
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
logger.info("-------固德威同步场站详情开始" + ts + "------- " + sdf.format(new Date())); logger.info("-------固德威同步场站详情开始" + ts + "------- " + sdf.format(new Date()));
List<String> stationIds = goodWeStationMonitorListMapper.getStationIds(); // List<String> stationIds = goodWeStationMonitorListMapper.getStationIds();
List<String> stationIds = getStationIds();
stationIds.forEach(stationId -> { stationIds.forEach(stationId -> {
HashMap<String, Object> requestInfo = new HashMap<>(); HashMap<String, Object> requestInfo = new HashMap<>();
String requstParam = JSON.toJSONString(requestInfo); String requstParam = JSON.toJSONString(requestInfo);
...@@ -352,13 +377,34 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe ...@@ -352,13 +377,34 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe
logger.info("-------固德威同步场站详情结束" + ts + "------- " + sdf.format(new Date())); logger.info("-------固德威同步场站详情结束" + ts + "------- " + sdf.format(new Date()));
} }
/**
* 获取场站id
* @return
*/
private List<String> getStationIds() {
HashMap<String, Object> requestInfo = new HashMap<>();
requestInfo.put("page_index", 1);
requestInfo.put("page_size", 200);
List<GoodWeStationMonitorDto> goodWeStationLists = goodWeRequestUtil.getResPonseList(
GoodWeConstant.stationListStatusUrl, GoodWeConstant.requestPost, requestInfo,
GoodWeConstant.resovleRule_data_list, GoodWeStationMonitorDto.class);
List<String> stationIds = new ArrayList<>();
if(CollectionUtil.isNotEmpty(goodWeStationLists)){
for (GoodWeStationMonitorDto goodWeStationMonitorDto : goodWeStationLists) {
stationIds.add(goodWeStationMonitorDto.getPowerstation_id());
}
}
return stationIds;
}
@Override @Override
@Scheduled(cron = "${dataRequstScheduled.GoodWe}") @Scheduled(cron = "${dataRequstScheduled.GoodWe}")
@Async @Async
public void stationMonthGen() { public void stationMonthGen() {
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
logger.info("-------固德威同步场站月发电量开始" + ts + "------- " + sdf.format(new Date())); logger.info("-------固德威同步场站月发电量开始" + ts + "------- " + sdf.format(new Date()));
List<String> stationIds = goodWeStationMonitorListMapper.getStationIds(); // List<String> stationIds = goodWeStationMonitorListMapper.getStationIds();
List<String> stationIds = getStationIds();
stationIds.forEach(stationId -> { stationIds.forEach(stationId -> {
String currentMonth = DateUtil.format(new Date(), "yyyyMM"); String currentMonth = DateUtil.format(new Date(), "yyyyMM");
HashMap<String, Object> requestInfo = new HashMap<>(); HashMap<String, Object> requestInfo = new HashMap<>();
...@@ -395,7 +441,8 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe ...@@ -395,7 +441,8 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe
public void stationYearGen() { public void stationYearGen() {
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
logger.info("-------固德威同步场站年发电量开始" + ts + "------- " + sdf.format(new Date())); logger.info("-------固德威同步场站年发电量开始" + ts + "------- " + sdf.format(new Date()));
List<String> stationIds = goodWeStationMonitorListMapper.getStationIds(); // List<String> stationIds = goodWeStationMonitorListMapper.getStationIds();
List<String> stationIds = getStationIds();
stationIds.forEach(stationId -> { stationIds.forEach(stationId -> {
String currentYear = DateUtil.format(new Date(), "yyyy"); String currentYear = DateUtil.format(new Date(), "yyyy");
HashMap<String, Object> requestInfo = new HashMap<>(); HashMap<String, Object> requestInfo = new HashMap<>();
...@@ -438,7 +485,10 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe ...@@ -438,7 +485,10 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe
public void inverterList() { public void inverterList() {
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
logger.info("-------固德威同步逆变器开始" + ts + "------- " + sdf.format(new Date())); logger.info("-------固德威同步逆变器开始" + ts + "------- " + sdf.format(new Date()));
List<String> stationIds = goodWeStationMonitorListMapper.getStationIds(); // List<String> stationIds = goodWeStationMonitorListMapper.getStationIds();
List<String> stationIds = getStationIds();
//删除多余的逆变器
deleteGDWInverter(stationIds);
stationIds.stream().forEach(stationId -> { stationIds.stream().forEach(stationId -> {
HashMap<String, Object> requestInfo = new HashMap<>(); HashMap<String, Object> requestInfo = new HashMap<>();
requestInfo.put("page_index", 1); requestInfo.put("page_index", 1);
...@@ -446,9 +496,8 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe ...@@ -446,9 +496,8 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe
requestInfo.put("pw_id", stationId); requestInfo.put("pw_id", stationId);
JpStation jpStation = jpStationMapper.selectOne( JpStation jpStation = jpStationMapper.selectOne(
new QueryWrapper<JpStation>().eq("third_station_id", stationId).orderByDesc("create_time")); new QueryWrapper<JpStation>().eq("third_station_id", stationId).orderByDesc("create_time"));
String requstParam = JSON.toJSONString(requestInfo); List<GoodWeINverterDetailDto> inverterDetailDtoList = goodWeRequestUtil.getResPonseList(
List<GoodWeINverterDetailDto> inverterDetailDtoList = goodWeRequestUtil.getResPonse( GoodWeConstant.queryInventerUrl, GoodWeConstant.requestPost, requestInfo,
GoodWeConstant.queryInventerUrl, GoodWeConstant.requestPost, requstParam,
GoodWeConstant.resovleRule_data_list, GoodWeINverterDetailDto.class); GoodWeConstant.resovleRule_data_list, GoodWeINverterDetailDto.class);
inverterDetailDtoList.forEach(goodWeINverterDetailDto -> { inverterDetailDtoList.forEach(goodWeINverterDetailDto -> {
// System.out.println(goodWeINverterDetailDto.getIt_sn()); // System.out.println(goodWeINverterDetailDto.getIt_sn());
...@@ -480,6 +529,23 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe ...@@ -480,6 +529,23 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe
logger.info("-------固德威同步逆变器结束" + ts + "------- " + sdf.format(new Date())); logger.info("-------固德威同步逆变器结束" + ts + "------- " + sdf.format(new Date()));
} }
/**
* 删除多余的逆变器
* @param stationIds
*/
private void deleteGDWInverter(List<String> stationIds) {
QueryWrapper<JpInverter> wrapper = new QueryWrapper<JpInverter>().eq("third_code", PVProducerInfoEnum.GDW.getCode());
List<JpInverter> jpInverters = jpInverterMapper.selectList(wrapper);
if(CollectionUtil.isNotEmpty(jpInverters)){
for (JpInverter jpInverter : jpInverters) {
if(!stationIds.contains(jpInverter.getThirdStationId())){
//删除多余数据
jpInverterMapper.deleteById(jpInverter.getSequenceNbr());
}
}
}
}
@Override @Override
@Scheduled(cron = "${dataRequstScheduled.GoodWe}") @Scheduled(cron = "${dataRequstScheduled.GoodWe}")
@Async @Async
...@@ -847,9 +913,8 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe ...@@ -847,9 +913,8 @@ public class GoodWeDataAcquisitionServiceImpl implements GoodWeDataAcquisitionSe
requestInfo.put("endtime", today + " 23:59:59"); requestInfo.put("endtime", today + " 23:59:59");
requestInfo.put("stationid", stationid); requestInfo.put("stationid", stationid);
// requestInfo.put("status", 2); // requestInfo.put("status", 2);
String requstParam = JSON.toJSONString(requestInfo); List<GoodWeAlarmDto> alarmList = goodWeRequestUtil.getResPonseList(GoodWeConstant.alarmListUrl,
List<GoodWeAlarmDto> alarmList = goodWeRequestUtil.getResPonse(GoodWeConstant.alarmListUrl, GoodWeConstant.requestPost, requestInfo, GoodWeConstant.resovleRule_data_list, GoodWeAlarmDto.class);
GoodWeConstant.requestPost, requstParam, GoodWeConstant.resovleRule_data_list, GoodWeAlarmDto.class);
alarmList.forEach(goodWeAlarmDto -> { alarmList.forEach(goodWeAlarmDto -> {
if (!ObjectUtils.isEmpty(goodWeAlarmDto.getDevicesn())) { if (!ObjectUtils.isEmpty(goodWeAlarmDto.getDevicesn())) {
HYGFJPInverterWarn hygfjpInverterWarn = hygfjpInverterWarnMapper HYGFJPInverterWarn hygfjpInverterWarn = hygfjpInverterWarnMapper
......
...@@ -14,6 +14,8 @@ import java.util.stream.Stream; ...@@ -14,6 +14,8 @@ import java.util.stream.Stream;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import cn.hutool.core.collection.CollectionUtil;
import com.yeejoin.amos.api.householdapi.face.dto.GoodWeStationMonitorDto;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -118,18 +120,42 @@ public class SofarDataAcquisitionServiceImpl implements SofarDataAcquisitionServ ...@@ -118,18 +120,42 @@ public class SofarDataAcquisitionServiceImpl implements SofarDataAcquisitionServ
Map<String, Object> requestInfo = new HashMap<>(); Map<String, Object> requestInfo = new HashMap<>();
requestInfo.put("page", 1); requestInfo.put("page", 1);
requestInfo.put("size", 1000); requestInfo.put("size", 1000);
String param = JSON.toJSONString(requestInfo); List<SofarStationList> jsonObject = requestUtil.getResPonseList(SoFarConstant.stationListUrl,
List<SofarStationList> jsonObject = requestUtil.getResPonse(SoFarConstant.stationListUrl, SoFarConstant.requestPost, requestInfo, SoFarConstant.resovleRule_data, SofarStationList.class);
SoFarConstant.requestPost, param, SoFarConstant.resovleRule_data, SofarStationList.class);
// 新增td电站 // 新增td电站
for (SofarStationList sunlight : jsonObject) { for (SofarStationList sunlight : jsonObject) {
sunlight.setCreatedTime(System.currentTimeMillis()); sunlight.setCreatedTime(System.currentTimeMillis());
sofarStationListMapper.insert(sunlight); sofarStationListMapper.insert(sunlight);
} }
//删除多余的电站
deleteSHStation(jsonObject);
// mysql电站信息 // mysql电站信息
this.stationDetail(jsonObject); this.stationDetail(jsonObject);
} }
/**
* 删除多余的首航场站
* @param sofarStationLists
*/
private void deleteSHStation(List<SofarStationList> sofarStationLists) {
if(CollectionUtil.isNotEmpty(sofarStationLists)){
List<String> stationIds = new ArrayList<>();
for (SofarStationList sofarStationList : sofarStationLists) {
stationIds.add(sofarStationList.getId().toString());
}
QueryWrapper<JpStation> wrapper = new QueryWrapper<JpStation>().eq("third_code", PVProducerInfoEnum.SH.getCode());
List<JpStation> jpStations = jpStationMapper.selectList(wrapper);
if(CollectionUtil.isNotEmpty(jpStations)){
for (JpStation jpStation : jpStations) {
if(!stationIds.contains(jpStation.getThirdStationId())){
//删除多余数据
jpStationMapper.deleteById(jpStation.getSequenceNbr());
}
}
}
}
}
@Override @Override
public void stationDetail(List<SofarStationList> list) { public void stationDetail(List<SofarStationList> list) {
...@@ -1212,8 +1238,7 @@ public class SofarDataAcquisitionServiceImpl implements SofarDataAcquisitionServ ...@@ -1212,8 +1238,7 @@ public class SofarDataAcquisitionServiceImpl implements SofarDataAcquisitionServ
// if (jpStation.getThirdStationId().equals("517021808701218816")){ // if (jpStation.getThirdStationId().equals("517021808701218816")){
// System.out.println("6666666666666666666666666"); // System.out.println("6666666666666666666666666");
// } // }
String param = JSON.toJSONString(requestInfo); List<SofarWarm> jsonObject2 = requestUtil.getResPonseList(SoFarConstant.alert, SoFarConstant.requestPost, requestInfo,
List<SofarWarm> jsonObject2 = requestUtil.getResPonse(SoFarConstant.alert, SoFarConstant.requestPost, param,
SoFarConstant.stationAlertItems, SofarWarm.class); SoFarConstant.stationAlertItems, SofarWarm.class);
// if (jsonObject2 != null && jsonObject2.size() > 0) { // if (jsonObject2 != null && jsonObject2.size() > 0) {
// System.out.println("88888888888888888888888"); // System.out.println("88888888888888888888888");
......
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.DatePattern; import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
...@@ -113,8 +114,10 @@ public class SunlightServiceImpl implements SunlightService { ...@@ -113,8 +114,10 @@ public class SunlightServiceImpl implements SunlightService {
bodyparam.put("ps_type", "1,3,4,5,6,7,8"); bodyparam.put("ps_type", "1,3,4,5,6,7,8");
bodyparam.put("size", 3000); bodyparam.put("size", 3000);
bodyparam.put("curPage", 1); bodyparam.put("curPage", 1);
JSONObject data = SunlightUtil.getdata(SunlightUtil.getPowerStationList, bodyparam); JSONObject data = SunlightUtil.getDataList(SunlightUtil.getPowerStationList, bodyparam);
List<Sunlight> list = JSONArray.parseArray(JSON.toJSONString(data.get("pageList")), Sunlight.class); List<Sunlight> list = JSONArray.parseArray(JSON.toJSONString(data.get("pageList")), Sunlight.class);
//删除多余的场站
deleteYGStation(data);
this.stationDetail(data); this.stationDetail(data);
for (Sunlight sunlight : list) { for (Sunlight sunlight : list) {
...@@ -124,6 +127,31 @@ public class SunlightServiceImpl implements SunlightService { ...@@ -124,6 +127,31 @@ public class SunlightServiceImpl implements SunlightService {
logger.info("-------阳光同步电站/逆变器/采集器结束" + ts + "------- " + sdf.format(new Date())); logger.info("-------阳光同步电站/逆变器/采集器结束" + ts + "------- " + sdf.format(new Date()));
} }
/**
* 删除多余的阳光场站
* @param data
*/
private void deleteYGStation(JSONObject data) {
// 所有场站信息
List<SunlightDto> sunlightDtos = JSONArray.parseArray(JSON.toJSONString(data.get("pageList")), SunlightDto.class);
if(CollectionUtil.isNotEmpty(sunlightDtos)){
List<String> stationIds = new ArrayList<>();
for (SunlightDto sunlightDto : sunlightDtos) {
stationIds.add(sunlightDto.getPs_id().toString());
}
QueryWrapper<JpStation> wrapper = new QueryWrapper<JpStation>().eq("third_code", PVProducerInfoEnum.YG.getCode());
List<JpStation> jpStations = jpStationMapper.selectList(wrapper);
if(CollectionUtil.isNotEmpty(jpStations)){
for (JpStation jpStation : jpStations) {
if(!stationIds.contains(jpStation.getThirdStationId())){
//删除多余数据
jpStationMapper.deleteById(jpStation.getSequenceNbr());
}
}
}
}
}
// 电站数据如库,电站统计数据入库 // 电站数据如库,电站统计数据入库
public void stationDetail(JSONObject data) { public void stationDetail(JSONObject data) {
// 所有场站信息 // 所有场站信息
...@@ -271,7 +299,7 @@ public class SunlightServiceImpl implements SunlightService { ...@@ -271,7 +299,7 @@ public class SunlightServiceImpl implements SunlightService {
bodyparamjp11.put("size", 3000); bodyparamjp11.put("size", 3000);
bodyparamjp11.put("curPage", 1); bodyparamjp11.put("curPage", 1);
bodyparamjp11.put("device_type_list", lif11); bodyparamjp11.put("device_type_list", lif11);
JSONObject jsonObject1data11 = SunlightUtil.getdata(SunlightUtil.getDeviceList, bodyparamjp11); JSONObject jsonObject1data11 = SunlightUtil.getDataList(SunlightUtil.getDeviceList, bodyparamjp11);
List<Device> listdtx = JSONArray.parseArray(JSON.toJSONString(jsonObject1data11.get("pageList")), List<Device> listdtx = JSONArray.parseArray(JSON.toJSONString(jsonObject1data11.get("pageList")),
Device.class); Device.class);
// 获取电站下逆变器 // 获取电站下逆变器
...@@ -282,7 +310,7 @@ public class SunlightServiceImpl implements SunlightService { ...@@ -282,7 +310,7 @@ public class SunlightServiceImpl implements SunlightService {
bodyparamjp.put("size", 3000); bodyparamjp.put("size", 3000);
bodyparamjp.put("curPage", 1); bodyparamjp.put("curPage", 1);
bodyparamjp.put("device_type_list", lif); bodyparamjp.put("device_type_list", lif);
JSONObject jsonObject1data = SunlightUtil.getdata(SunlightUtil.getDeviceList, bodyparamjp); JSONObject jsonObject1data = SunlightUtil.getDataList(SunlightUtil.getDeviceList, bodyparamjp);
List<Device> listd = JSONArray.parseArray(JSON.toJSONString(jsonObject1data.get("pageList")), Device.class); List<Device> listd = JSONArray.parseArray(JSON.toJSONString(jsonObject1data.get("pageList")), Device.class);
// 获取电站,月发电量 // 获取电站,月发电量
...@@ -1000,7 +1028,7 @@ public class SunlightServiceImpl implements SunlightService { ...@@ -1000,7 +1028,7 @@ public class SunlightServiceImpl implements SunlightService {
Map<String, Object> bodyparamf = new HashMap<>(); Map<String, Object> bodyparamf = new HashMap<>();
bodyparamf.put("size", 1000); bodyparamf.put("size", 1000);
bodyparamf.put("curPage", 1); bodyparamf.put("curPage", 1);
JSONObject jsonObject = SunlightUtil.getdata(SunlightUtil.getFaultAlarmInfo, bodyparamf); JSONObject jsonObject = SunlightUtil.getDataList(SunlightUtil.getFaultAlarmInfo, bodyparamf);
List<SunlightWarm> listd = jsonObject.get("pageList") != null List<SunlightWarm> listd = jsonObject.get("pageList") != null
? JSONArray.parseArray(JSON.toJSONString(jsonObject.get("pageList")), SunlightWarm.class) ? JSONArray.parseArray(JSON.toJSONString(jsonObject.get("pageList")), SunlightWarm.class)
: null; : null;
......
...@@ -67,10 +67,7 @@ import java.text.SimpleDateFormat; ...@@ -67,10 +67,7 @@ import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -566,6 +563,10 @@ public class TanYinDataAcquisitionServiceImpl implements TanYinDataAcquisitionSe ...@@ -566,6 +563,10 @@ public class TanYinDataAcquisitionServiceImpl implements TanYinDataAcquisitionSe
for (TanYinInveterInfo tanYinInveterInfo : tanYinInveterInfos) { for (TanYinInveterInfo tanYinInveterInfo : tanYinInveterInfos) {
// region 逆变器信息 // region 逆变器信息
JSONObject tanYinInveterInfoResultJson = tanYinInveterInfoResultMap.getJSONObject(tanYinInveterInfo.getSn()); JSONObject tanYinInveterInfoResultJson = tanYinInveterInfoResultMap.getJSONObject(tanYinInveterInfo.getSn());
//处理空指针问题
if(Objects.isNull(tanYinInveterInfoResultJson)){
continue;
}
TanYinInveterInfo tanYinInveterInfoDTO = tanYinInveterInfoResultJson.toJavaObject(TanYinInveterInfo.class); TanYinInveterInfo tanYinInveterInfoDTO = tanYinInveterInfoResultJson.toJavaObject(TanYinInveterInfo.class);
tanYinInveterInfoDTO.setProjectNo(tanYinInveterInfo.getProjectNo()); tanYinInveterInfoDTO.setProjectNo(tanYinInveterInfo.getProjectNo());
tanYinInveterInfoDTO.setDeviceName(tanYinInveterInfo.getDeviceName()); tanYinInveterInfoDTO.setDeviceName(tanYinInveterInfo.getDeviceName());
......
package com.yeejoin.amos.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@Configuration
@EnableScheduling
public class SchedulerConfig {
@Bean
public ThreadPoolTaskScheduler taskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(10); // 设置线程池大小为10
scheduler.setThreadNamePrefix("my-scheduled-task-"); // 设置线程名称前缀
scheduler.initialize(); // 初始化线程池
return scheduler;
}
}
\ No newline at end of file
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