From 4f9901f28b7a312834ed37aad536db3e418bd6cc Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期三, 25 六月 2025 17:58:42 +0800
Subject: [PATCH] 光伏对接三方调整api
---
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TScreenContentServiceImpl.java | 12 ++++--
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/EnergyRefreshService.java | 2
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/KsolarUtils.java | 106 +++++++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 107 insertions(+), 13 deletions(-)
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TScreenContentServiceImpl.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TScreenContentServiceImpl.java
index caa54aa..7f7dcc9 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TScreenContentServiceImpl.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TScreenContentServiceImpl.java
@@ -133,13 +133,17 @@
List<LocalDate> dates = new ArrayList<>();
List<Double> values = new ArrayList<>();
LocalDate today = LocalDate.now();
+ ArrayList<Map<String, Object>> monthEnergy = KsolarUtils.getMonthEnergy(today.minusDays(7).toString().substring(0, 7), today.minusDays(1).toString().substring(0, 7));
// 生成每天数据
for (int i = 7; i >= 1; i--) {//升序
LocalDate day = today.minusDays(i);
- //统计
- dates.add(day);
- Double value = KsolarUtils.getTodayEnergy(day.toString()); // 100-250
- values.add(value);
+
+ Map<String, Object> stringObjectMap = monthEnergy.stream().filter(e -> e.get("time").toString().contains(day.toString())).findFirst().orElse(null);
+ if(stringObjectMap!=null){
+ values.add(Double.valueOf(stringObjectMap.get("value").toString()));
+ }else {
+ values.add(0.0);
+ }
}
vo.setDates(dates);
vo.setValues(values);
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/EnergyRefreshService.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/EnergyRefreshService.java
index 3ad10be..b5d03b8 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/EnergyRefreshService.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/EnergyRefreshService.java
@@ -48,7 +48,7 @@
private BigDecimal currentPhaseDischarge = BigDecimal.ZERO;
// 定时任务方法 - 能量刷新
- @Scheduled(cron = "0 * * * * ?") // 每分钟执行一次
+// @Scheduled(cron = "0 * * * * ?") // 每分钟执行一次
public synchronized void refreshValue() {
LocalTime now = LocalTime.now();
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/KsolarUtils.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/KsolarUtils.java
index 1efb97a..ab1137f 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/KsolarUtils.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/KsolarUtils.java
@@ -19,10 +19,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Random;
+import java.util.*;
/**
@@ -34,9 +31,17 @@
private static String token;
+ private static String accessToken;
+
private static List<String> stationIds= Arrays.asList("2025060710462417","2025060711331323","2025060715425437","2025060716010425");
+
+ /**
+ * 获取今日总发电量
+ * @param time
+ * @return
+ */
public static Double getTodayEnergy(String time) {
try {
HttpRequest get = HttpUtil.createGet("http://111.230.136.62:8092/station/list/earn");
@@ -60,7 +65,49 @@
return getTodayEnergy(time);
}
}
+ public static ArrayList<Map<String, Object>> getMonthEnergy(String time,String time1) {
+ ArrayList<Map<String, Object>> list = new ArrayList<>();
+ try {
+ HttpRequest get = HttpUtil.createGet("http://111.230.136.62:8092/protocol/user/statistic/elec/chart");
+ get.header("Authorization", "Bearer "+token);
+ get.form("stime", time);
+ get.form("attribId", "201");
+ HttpResponse execute = get.execute();
+ String body = execute.body();
+ if(body.contains("code")){
+ token = token();
+ return getMonthEnergy(time,time1);
+ }
+ JSONArray jsonArray = JSONArray.parseArray(body);
+ for (Object o1 : jsonArray) {
+ HashMap<String, Object> stringObjectHashMap = new HashMap<>();
+ JSONObject jsonObject = JSONObject.parseObject(o1.toString()) ;
+ stringObjectHashMap.put("time", jsonObject.getString("saveTime"));
+ stringObjectHashMap.put("value", jsonObject.getString("attribValue"));
+ list.add(stringObjectHashMap);
+ }
+ // 相同月份
+ if(!time.equals(time1)){
+ list.addAll(getMonthEnergy(time1,time1));
+ }
+ return list;
+ } catch (Exception e) {
+ e.printStackTrace();
+ token = token();
+ return getMonthEnergy(time,time1);
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ ArrayList<Map<String, Object>> monthEnergy = getMonthEnergy("2025-05", "2025-06");
+ System.out.println(monthEnergy);
+ }
+
+ /**
+ * 光伏累计
+ * @return
+ */
public static Double getAllEnergy(String time) {
try {
HttpRequest get = HttpUtil.createGet("http://111.230.136.62:8092/station/list/earn");
@@ -100,11 +147,13 @@
return divide;
}
+
+
private static Double getYearAllEnergy(String stationId) {
try {
HttpRequest get = HttpUtil.createGet("http://111.230.136.62:8092/protocol/station/statistic/elec/chart");
get.header("Authorization", "Bearer "+token);
- get.form("stationId", "2025060710462417");
+ get.form("stationId", stationId);
get.form("attribId", "202");
get.form("stime",LocalDate.now().getYear()+"" );
HttpResponse execute = get.execute();
@@ -118,7 +167,7 @@
} catch (Exception e) {
e.printStackTrace();
token = token();
- return getYearAllEnergy(LocalDate.now().getYear()+"");
+ return getYearAllEnergy(stationId);
}
}
@@ -138,9 +187,50 @@
return access_token;
}
- public static void main(String[] args) throws Exception {
- System.out.println(getYearAllEnergy("2025",""));
+
+ public static String getAccessToken(){
+ HttpRequest post = HttpRequest.post("https://www.zsdcloud.cn:8443/openApi/getAccessToken.action?accessId=87bde117-1f29-4371-8d4d-82324d17ddc3");
+ HttpResponse execute = post.execute();
+ String body = execute.body();
+ JSONObject jsonObject = JSONObject.parseObject(body);
+ return jsonObject.getString("result");
}
+ /**
+ * 消纳数据
+ * @return
+ */
+ public static String getElectricity(){
+ String value = "0";
+ HttpRequest post = HttpRequest.post("https://www.zsdcloud.cn:8443/openApi/equipment/select.action");
+ post.form("token", accessToken);
+ post.form("keyCode", "869916072003947");
+ post.form("version", "V2");
+ HttpResponse execute = post.execute();
+ String body = execute.body();
+ JSONObject jsonObject = JSONObject.parseObject(body);
+ String string = jsonObject.get("statusCode").toString();
+ if(!string.equals("200")){
+ accessToken = getAccessToken();
+ return getElectricity();
+
+ }
+ String string1 = jsonObject.getString("result");
+ JSONObject jsonObject1 = JSONObject.parseObject(string1);
+ String realInfo = jsonObject1.getString("realInfo");
+ JSONArray jsonArray = JSONArray.parseArray(realInfo);
+ for (Object o : jsonArray) {
+ JSONObject jsonObject2 = JSONObject.parseObject(o.toString());
+ if(jsonObject2.get("Name").toString().equals("累积日充电量")){
+ value= jsonObject2.get("Value").toString();
+ break;
+ }
+ }
+ return value;
+ }
+
+
+
+
}
\ No newline at end of file
--
Gitblit v1.7.1