寄点电站数据接入

This commit is contained in:
2026-02-26 09:07:01 +08:00
parent a967f5aa44
commit 36bc9ef2f1
5 changed files with 557 additions and 1 deletions

View File

@ -0,0 +1,177 @@
package com.ho.business.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.ho.business.vo.req.StationReqVO;
import com.ho.common.tools.constant.CommonConstant;
import com.ho.common.tools.service.RedisService;
import com.ho.common.tools.util.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* 西安寄点能源股份有限公司
* 西安寄点能源 API 接口 服务
*
* @author kerwin
*/
@Service
@Slf4j
public class ShipEnergyService {
/**
* token 缓存 key
*/
private static final String SHIP_ENERGY_TOKEN_KEY = "ShipEnergyToken";
/**
* 获取token 参数 platform
*/
private static final String PLATFORM = "f9599b6c79a5efbfc6ddce5fed1bbed5";
/**
* 获取token 参数 platformsecret
*/
private static final String PLATFORM_SECRET = "2928b16f9cb8e85199a4caa6ba3b6620";
/**
* 寄点能源- 获取token Url
*/
private static final String TOKEN_URL = "https://www.emind2000.cloud/rest-api/gettoken";
/**
* 寄点能源- 获取项目列表 Url
*/
private static final String STATION_URL = "https://www.emind2000.cloud/rest-api/getStations";
/**
* 寄点能源- 主监控汇总 Url
*/
private static final String MAIN_URL = "https://www.emind2000.cloud/rest-api/getMainTotal";
@Autowired
private RedisService redisService;
@Autowired
private StationService stationService;
/**
* 寄点能源 - 获取token
* @return token
*/
public String getToken(){
String token = null;
if(redisService.hasKey(SHIP_ENERGY_TOKEN_KEY)){
token = (String)redisService.get(SHIP_ENERGY_TOKEN_KEY);
}
Map<String, String> params = Maps.newHashMap();
params.put("platform",PLATFORM);
params.put("platformsecret",PLATFORM_SECRET);
try {
String json = HttpUtils.getWithForm(TOKEN_URL,params);
JSONObject jsonObject = JSONObject.parseObject(json);
Integer code = jsonObject.getInteger("code");
if(CommonConstant.HttpCode.SUCCESS_CODE.equals(code)){
JSONObject data = jsonObject.getJSONObject("data");
token = data.getString("access_token");
//redis 缓存
redisService.set(SHIP_ENERGY_TOKEN_KEY,token,10, TimeUnit.HOURS);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return token;
}
/**
* 寄点能源 - 获取 项目列表
* @return 项目列表 json 字符串
*/
public String getStations(){
String Authorization = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjo5Nzg2LCJ1c2VyX2tleSI6Ijk3ODY6N2RkNjU0MTgtNDg5ZS00MzgzLWI1ZmYtMTU2MmI5ZTY0NDFkIiwidXNlcm5hbWUiOiJ6emt5YXBpIn0.fQLMlOHaEjmfHeyEu5EcxZmQ8UjRBOUoteNV-tJ2ttAwyJmQidOk7xqL25K_wRIC-OQKt0vFVOpTzMFdH71uhw";
Map<String, String> headers = new HashMap<>();
headers.put("Authorization",Authorization);
try {
String json = HttpUtils.getWithHeaders(STATION_URL,null,headers);
JSONObject jsonObject = JSONObject.parseObject(json);
Integer code = jsonObject.getInteger("code");
if(CommonConstant.HttpCode.SUCCESS_CODE.equals(code)){
JSONObject data = jsonObject.getJSONObject("data");
return data.getString("rows");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
/**
*
* 寄点能源 - 获取 主监控汇总信息
* @param stationId 电站id
* @return 返回对应电站汇总信息
*/
public String getMainTotal(String stationId){
String Authorization = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjo5Nzg2LCJ1c2VyX2tleSI6Ijk3ODY6MmE5YjUzODUtNjNiNC00OWRiLWFjODEtNzhmNWRmNjE0ZDgyIiwidXNlcm5hbWUiOiJ6emt5YXBpIn0.WMi4PgYQByeYXBfOGVM0mc4P5GcyAcGRkDo8F7TK8fXIkj9QZ9D34WmugiVX3GxRGODFs3u1ujH7qJyuQAM99w";
Map<String, String> headers = new HashMap<>();
headers.put("Authorization",Authorization);
Map<String, String> params = new HashMap<>();
params.put("stationId",stationId);
try {
String json = HttpUtils.getWithHeaders(MAIN_URL,params,headers);
JSONObject jsonObject = JSONObject.parseObject(json);
Integer code = jsonObject.getInteger("code");
if(CommonConstant.HttpCode.SUCCESS_CODE.equals(code)){
return jsonObject.getString("data");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
/*****************************************业务处理******************************************************/
/**
* 寄点能源 - 电站信息融合储能平台处理
*/
public void addShipEnergyStation(){
String stationJson = getStations();
JSONArray jsonStation = JSON.parseArray(stationJson);
jsonStation.forEach(i->{
JSONObject jsonObj = (JSONObject) i;
Integer stationId = jsonObj.getInteger("stationId");
String name = jsonObj.getString("name");
String address = jsonObj.getString("address");
String province = jsonObj.getString("province");
String city = jsonObj.getString("city");
BigDecimal longitude = jsonObj.getBigDecimal("longitude");
BigDecimal latitude = jsonObj.getBigDecimal("latitude");
BigDecimal maxPower = jsonObj.getBigDecimal("maxPower");
BigDecimal capacity = jsonObj.getBigDecimal("capacity");
Date commossioningTime = jsonObj.getDate("commossioningTime");
StationReqVO vo = new StationReqVO();
vo.setId(stationId+10000);
vo.setName(name);
vo.setAddress(address);
vo.setLongitude(longitude);
vo.setLatitude(latitude);
vo.setCapacity(capacity);
vo.setRatePower(maxPower);
vo.setGridTime(commossioningTime);
vo.setGroupId(155);
vo.setDeptId(155);
stationService.insertStation(vo);
});
}
}