Commit d2ac09c1 authored by caotao's avatar caotao

户用光伏数据采集优化

parent 50ad4dfa
......@@ -3,37 +3,54 @@ package com.yeejoin.amos.api.householdapi.Utils;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.api.householdapi.face.model.HouseholdPvProducerInfoDto;
import com.yeejoin.amos.api.householdapi.face.orm.entity.HouseholdPvProducerInfo;
import com.yeejoin.amos.api.householdapi.face.service.impl.HouseholdPvProducerInfoServiceImpl;
import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
@Component
public class HouseholdPvUtils {
private static HouseholdPvProducerInfoServiceImpl householdPvProducerInfoServiceImpl;
public static HashMap<String, String> getHeaderByProducerCode(PVProducerInfoEnum producerInfoEnum) {
HashMap<String, String> hashMap = new HashMap<>();
if (PVProducerInfoEnum.GDW.equals(producerInfoEnum)) {
public HouseholdPvUtils(HouseholdPvProducerInfoServiceImpl householdPvProducerInfoServiceImpl) {
this.householdPvProducerInfoServiceImpl = householdPvProducerInfoServiceImpl;
}
public static HashMap<String, Object> getHeaderByProducerCode(String code) {
HashMap<String, Object> hashMap = new HashMap<>();
HashMap<String, String> hashMaphead = new HashMap<>();
HouseholdPvProducerInfo householdPvProducerInfo = householdPvProducerInfoServiceImpl.queryForHouseholdPvProducerInfoByCode(code);
String url = householdPvProducerInfo.getProdcerUrl() + householdPvProducerInfo.getTokenUrl();
hashMap.put("apiurl", householdPvProducerInfo.getProdcerUrl());
if (PVProducerInfoEnum.GDW.getCode().equals(code)) {
HashMap<String, String> map = new HashMap<>();
map.put("account", "18679135705");
map.put("account", householdPvProducerInfo.getProdcerAccount());
map.put("pwd", "Ljf5705@sems");
String body = JSON.toJSONString(map);
String response = HttpUtil.createPost("http://openapi.sems.com.cn/api/OpenApi/GetToken").body(body).execute().body();
String response = HttpUtil.createPost(url).body(body).execute().body();
JSONObject jsonObject = JSON.parseObject(response);
if (jsonObject.get("data") != null) {
JSONObject jsonObject1 = (JSONObject) jsonObject.get("data");
hashMap.put("token", (String) jsonObject1.get("token"));
hashMaphead.put("token", (String) jsonObject1.get("token"));
hashMap.put("header", hashMaphead);
}
} else if (PVProducerInfoEnum.SH.equals(producerInfoEnum)) {
} else if (PVProducerInfoEnum.SH.getCode().equals(code)) {
HashMap<String, Object> map = new HashMap<>();
map.put("accountName","18120415291");
map.put("appId",447430219192733696l);
map.put("appSecret","5881ee8c062817016a2b34425c45937d");
map.put("corporationId","447430928264990720");
map.put("accountType",2);
map.put("accountName", householdPvProducerInfo.getProdcerAccount());
map.put("appId", householdPvProducerInfo.getProdcerAppid());
map.put("appSecret", householdPvProducerInfo.getProdcerAppsecret());
map.put("corporationId", householdPvProducerInfo.getCorporationId());
map.put("accountType", 2);
String body = JSON.toJSONString(map);
String response = HttpUtil.createPost("https://openapi.sofarsolarmonitor.com/account/auth/createToken").body(body).execute().body();
String response = HttpUtil.createPost(url).body(body).execute().body();
JSONObject jsonObject = JSON.parseObject(response);
hashMap.put("Authorization", (String) jsonObject.get("data"));
hashMaphead.put("Authorization", (String) jsonObject.get("data"));
hashMap.put("header",hashMaphead);
}
return hashMap;
}
......
package com.yeejoin.amos.api.householdapi.controller;
import cn.hutool.http.HttpUtil;
import com.yeejoin.amos.api.householdapi.Utils.HouseholdPvUtils;
import com.yeejoin.amos.api.householdapi.face.model.HouseholdPvApiDto;
import com.yeejoin.amos.api.householdapi.face.model.HouseholdPvProducerInfoDto;
import com.yeejoin.amos.api.householdapi.face.service.impl.HouseholdPvApiServiceImpl;
import com.yeejoin.amos.api.householdapi.face.service.impl.HouseholdPvProducerInfoServiceImpl;
import com.yeejoin.amos.openapi.enums.PVProducerInfoEnum;
import fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.hutool.http.HttpUtil;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.io.IOException;
import java.util.HashMap;
......@@ -27,45 +29,28 @@ import java.util.Map;
* @date 2023-06-07
*/
@RestController
@Api(tags = "户用光伏三方厂商示例")
@RequestMapping(value = "/household-pv-api-test")
public class HouseholdPvApiTestController {
@Autowired
private HouseholdPvApiServiceImpl householdPvApiServiceImpl;
@Autowired
private HouseholdPvProducerInfoServiceImpl householdPvProducerInfoServiceImpl;
@Api(tags = "测试")
@RequestMapping(value = "/household-pv-api-test1")
public class HouseholdTestController {
@Autowired
private HouseholdPvApiServiceImpl householdPvApiServiceImpl;
@Autowired
private HouseholdPvProducerInfoServiceImpl householdPvProducerInfoServiceImpl;
/**
* 新增户用光伏-厂商API haders
*
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@PostMapping(value = "/gdwdemo")
@ApiOperation(httpMethod = "get", value = "固德威示例", notes = "固德威示例")
public String save() throws IOException {
Map<String,String> stringObjectHashMap =HouseholdPvUtils.getHeaderByProducerCode(PVProducerInfoEnum.GDW);
Map<String,Object> body = new HashMap<>();
body.put("page_index",1);
body.put("page_size",20);
String stringbody = JSON.toJSONString(body);
String respone=HttpUtil.createPost("http://openapi.sems.com.cn/api/OpenApi/GetUserPowerStation").
headerMap(stringObjectHashMap,true).
body(stringbody).execute().body();
return respone;
}
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
@PostMapping(value = "/shdemo")
@ApiOperation(httpMethod = "get", value = "首航示例", notes = "首航示例")
public String save2( ) throws IOException {
Map<String,String> stringObjectHashMap =HouseholdPvUtils.getHeaderByProducerCode(PVProducerInfoEnum.SH);
Map<String,Object> body = new HashMap<>();
body.put("page",1);
body.put("size",10);
String stringbody = JSON.toJSONString(body);
String respone=HttpUtil.createPost("https://openapi.sofarsolarmonitor.com/station/v1.0/list").
headerMap(stringObjectHashMap,true).
body(stringbody).execute().body();
public String save(Long seq) throws IOException {
HouseholdPvApiDto householdPvApiDto = householdPvApiServiceImpl.queryBySeq(seq);
HashMap<String,Object> producerInfo = HouseholdPvUtils.getHeaderByProducerCode(householdPvApiDto.getProducerId());
HashMap<String,String> headMap = (HashMap<String, String>) producerInfo.get("header");
String respone = HttpUtil.createPost(producerInfo.get("apiurl")+householdPvApiDto.getApiUrl()).headerMap(headMap,true).
body(householdPvApiDto.getParamInfo()).execute().body();
return respone;
}
}
......@@ -76,4 +76,10 @@ public class HouseholdPvProducerInfo extends BaseEntity {
*/
@TableField("code")
private String code;
/**
* token_url
*/
@TableField("token_url")
private String tokenUrl;
}
package com.yeejoin.amos.api.householdapi.face.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.api.householdapi.face.model.HouseholdPvProducerInfoDto;
import com.yeejoin.amos.api.householdapi.face.orm.dao.HouseholdPvProducerInfoMapper;
import com.yeejoin.amos.api.householdapi.face.orm.entity.HouseholdPvProducerInfo;
......@@ -8,6 +10,7 @@ import com.yeejoin.amos.api.householdapi.face.service.IHouseholdPvProducerInfoSe
import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
/**
......@@ -21,14 +24,20 @@ public class HouseholdPvProducerInfoServiceImpl extends BaseService<HouseholdPvP
/**
* 分页查询
*/
public Page<HouseholdPvProducerInfoDto> queryForHouseholdPvProducerInfoPage(Page<HouseholdPvProducerInfoDto> page) {
public Page<HouseholdPvProducerInfoDto> queryForHouseholdPvProducerInfoPage(Page<HouseholdPvProducerInfoDto> page) {
return this.queryForPage(page, null, false);
}
/**
* 列表查询 示例
*/
public List<HouseholdPvProducerInfoDto> queryForHouseholdPvProducerInfoList() {
return this.queryForList("" , false);
public List<HouseholdPvProducerInfoDto> queryForHouseholdPvProducerInfoList() {
return this.queryForList("", false);
}
public HouseholdPvProducerInfo queryForHouseholdPvProducerInfoByCode(String code) {
return this.baseMapper.selectOne(new QueryWrapper<HouseholdPvProducerInfo>().eq("code", code));
}
}
\ 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