From 6aad35552e8b958ff8480a775343e6de1a66d23b Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期二, 24 六月 2025 21:02:37 +0800
Subject: [PATCH] 发电对接三方(待测试)

---
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TScreenContentServiceImpl.java |   52 ++++-------------
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/PhotovoltaicAndConsumptionVO.java        |    2 
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TScreenContentController.java    |   21 +------
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/PhotovoltaicPowerGenerationVO.java       |    2 
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/EnergyRefreshService.java              |   90 +++++++++++++++++------------
 5 files changed, 70 insertions(+), 97 deletions(-)

diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TScreenContentController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TScreenContentController.java
index 3e6d890..ba04879 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TScreenContentController.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TScreenContentController.java
@@ -15,6 +15,7 @@
 import com.ruoyi.other.service.TScreenContentService;
 import com.ruoyi.other.service.TSystemConfigurationService;
 import com.ruoyi.other.util.EnergyRefreshService;
+import com.ruoyi.other.util.KsolarUtils;
 import com.ruoyi.other.vo.*;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.BeanUtils;
@@ -63,25 +64,9 @@
     @GetMapping(value = "/photovoltaicAndConsumption")
     public AjaxResult<PhotovoltaicAndConsumptionVO> photovoltaicAndConsumption() {
         //需调用接口 获取光伏发电量
-        List<Integer> siteIds= Arrays.asList(25,26);
         PhotovoltaicAndConsumptionVO vo = new PhotovoltaicAndConsumptionVO();
-        List<TScreenContent> list = screenContentService.list(new LambdaQueryWrapper<TScreenContent>().in(TScreenContent::getSiteId, siteIds));
-        if(list==null|| list.isEmpty()){
-            return AjaxResult.success(vo);
-        }
-        vo.setGreenElectricityToday(list.get(0).getGreenElectricityToday());
-        list.remove(0);
-        list.forEach(x->{
-            vo.setGreenElectricityToday(vo.getGreenElectricityToday().add(x.getGreenElectricityToday()));
-        });
-
-        TSystemConfiguration sysConfig = systemConfigurationService.getOne(new LambdaQueryWrapper<TSystemConfiguration>()
-                .eq(TSystemConfiguration::getType,4));
-        BigDecimal refreshValueOne = new BigDecimal(sysConfig.getContent());
-        vo.setTodayGenerateElectricity(refreshValueOne);
-        vo.setGreenElectricityToday(refreshValueOne.multiply(new BigDecimal("0.94")).setScale(2, RoundingMode.HALF_UP));
-
-
+        vo.setTodayGenerateElectricity(new BigDecimal(KsolarUtils.getTodayEnergy(LocalDateTime.now().toString())));
+        vo.setGreenElectricityToday(vo.getTodayGenerateElectricity().multiply(new BigDecimal("0.94")).setScale(2, RoundingMode.HALF_UP));
         return AjaxResult.success(vo);
     }
 
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 1c016e9..caa54aa 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
@@ -15,6 +15,7 @@
 import com.ruoyi.other.mapper.TSystemConfigurationMapper;
 import com.ruoyi.other.service.TScreenContentService;
 import com.ruoyi.other.service.TSystemConfigurationService;
+import com.ruoyi.other.util.KsolarUtils;
 import com.ruoyi.other.vo.EmissionReductionVO;
 import com.ruoyi.other.vo.PhotovoltaicPowerGenerationVO;
 import com.ruoyi.other.vo.ScreenStorageConfigVO;
@@ -96,10 +97,19 @@
             systemConfigurationMapper.updateById(sysConfig);
             vo.setEnergyStorage(storageDisCharge.multiply(new BigDecimal("0.1404")).divide(new BigDecimal("1000"),2,RoundingMode.DOWN));
         }
+        //获取累计发电
+        vo.setPhotovoltaic(KsolarUtils.getYearAllEnergy());
+
 
         //总数:
         BigDecimal total = vo.getPhotovoltaic().add(vo.getEnergyStorage()).add(vo.getCharge());
         vo.setTotal(total);
+
+
+
+
+
+
         //计算比率
         vo.setPhotovoltaicRate(calculateRatio(vo.getPhotovoltaic(),vo.getTotal()).multiply(new BigDecimal("100")));
         vo.setEnergyStorageRate(calculateRatio(vo.getEnergyStorage(),vo.getTotal()).multiply(new BigDecimal("100")));
@@ -108,60 +118,27 @@
         return vo;
     }
 
-    public static void main(String[] args) {
-        BigDecimal divide = new BigDecimal("607").multiply(new BigDecimal("0.1404")).divide(new BigDecimal("1000"),2,RoundingMode.DOWN);
-        System.out.println(divide);
-    }
 
     //百分比计算
     public static BigDecimal calculateRatio(BigDecimal part, BigDecimal total) {
         if (total.compareTo(BigDecimal.ZERO) == 0) {
             throw new ArithmeticException("分母不能为零");
         }
-
         return part.divide(total, 4, RoundingMode.HALF_UP);
     }
 
     @Override
     public PhotovoltaicPowerGenerationVO photovoltaicPowerGeneration(List<Integer> siteIds) {
-        //需调用接口
-
-        //假数据
         PhotovoltaicPowerGenerationVO vo = new PhotovoltaicPowerGenerationVO();
         List<LocalDate> dates = new ArrayList<>();
-        List<Integer> values = new ArrayList<>();
+        List<Double> values = new ArrayList<>();
         LocalDate today = LocalDate.now();
         // 生成每天数据
         for (int i = 7; i >= 1; i--) {//升序
             LocalDate day = today.minusDays(i);
             //统计
             dates.add(day);
-            int value = new Random().nextInt(151) + 100; // 100-250
-
-            switch (i){
-                case 1:
-                    value = 1780; // 50-100
-                    break;
-                case 2:
-                    value = 1810; // 50-100
-                    break;
-                case 3:
-                    value = 1765; // 50-100
-                    break;
-                    case 4:
-                    value = 1793; // 50-100
-                    break;
-                    case 5:
-                    value = 1833; // 50-100
-                    break;
-                    case 6:
-                    value = 1815; // 50-100
-                    break;
-                    case 7:
-                    value =1794; // 50-100
-                    break;
-
-            }
+            Double value = KsolarUtils.getTodayEnergy(day.toString()); // 100-250
             values.add(value);
         }
         vo.setDates(dates);
@@ -206,13 +183,10 @@
         BigDecimal totalCharge = dailyRate.multiply(BigDecimal.valueOf(days));
         vo.setStorageCharge(totalCharge);
 
-        TSystemConfiguration sysConfig1 = systemConfigurationMapper.selectOne(new LambdaQueryWrapper<TSystemConfiguration>()
-                .eq(TSystemConfiguration::getType,5));
-        vo.setPhotovoltaic(new BigDecimal(sysConfig1.getContent()));
+        vo.setPhotovoltaic(new BigDecimal(KsolarUtils.getAllEnergy(LocalDate.now().toString())));
         vo.setGreenElectricity(vo.getPhotovoltaic().multiply(new BigDecimal("0.94")).setScale(2,  RoundingMode.HALF_UP));
 
         //获取储能放电量
-
         // 判断是否等于今天
         if (configVO.getLastUpdated().equals(today)) {
             vo.setStorageDisCharge(configVO.getStorageDisCharge());
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 9a9d17f..b462087 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
@@ -109,6 +109,15 @@
         updateStorageValue(BigDecimal.ZERO);
         updateDischargeValue(BigDecimal.ZERO);
         System.out.println("每日重置完成:今日储能和放电已清零");
+
+
+
+        TSystemConfiguration sysConfig = systemConfigurationMapper.selectOne(new LambdaQueryWrapper<TSystemConfiguration>()
+                .eq(TSystemConfiguration::getType,4));
+        sysConfig.setContent("0");
+        systemConfigurationMapper.updateById(sysConfig);
+
+
     }
 
     /**
@@ -198,67 +207,72 @@
 
 
 
-    public static BigDecimal refreshValueOne = new BigDecimal("0");
     /**
      *光伏发电和消纳
      */
-    @Scheduled(cron = "0 */1 * * * ?")  // 每分钟点执行
+//    @Scheduled(cron = "0 */1 * * * ?")  // 每分钟点执行
     public void refreshValueOne() {
         // 判断时间是否在6:00到8:59
         LocalTime now = LocalTime.now();
-        if (now.isAfter(LocalTime.of(6, 0)) && now.isBefore(LocalTime.of(8, 59))) {
-            refreshValueOne = refreshValueOne.add(new BigDecimal("0.5"));
-            List<TSystemConfiguration> sysConfigs = systemConfigurationMapper.selectList(new LambdaQueryWrapper<TSystemConfiguration>()
-                    .in(TSystemConfiguration::getType,4,5));
-            TSystemConfiguration sysConfig = sysConfigs.stream().filter(e -> e.getType() == 4).findFirst().orElse(null);
-            sysConfig.setContent(refreshValueOne.toString());
-            systemConfigurationMapper.updateById(sysConfig);
-
-
-            TSystemConfiguration sysConfig1 = sysConfigs.stream().filter(e -> e.getType() == 5).findFirst().orElse(null);
-            String string = new BigDecimal(sysConfig1.getContent()).add(new BigDecimal("0.5")).toString();
-            sysConfig1.setContent(string);
-            systemConfigurationMapper.updateById(sysConfig1);
-            // 在6:00到8:59之间,不执行
-            return;
-        }
+//        if (now.isAfter(LocalTime.of(6, 0)) && now.isBefore(LocalTime.of(8, 59))) {
+//            List<TSystemConfiguration> sysConfigs = systemConfigurationMapper.selectList(new LambdaQueryWrapper<TSystemConfiguration>()
+//                    .in(TSystemConfiguration::getType,4,5));
+//            TSystemConfiguration sysConfig = sysConfigs.stream().filter(e -> e.getType() == 4).findFirst().orElse(null);
+//
+//            sysConfig.setContent(new BigDecimal(sysConfig.getContent()).add(new BigDecimal("0.5")).toString());
+//            systemConfigurationMapper.updateById(sysConfig);
+//
+//
+//            TSystemConfiguration sysConfig1 = sysConfigs.stream().filter(e -> e.getType() == 5).findFirst().orElse(null);
+//            String string = new BigDecimal(sysConfig1.getContent()).add(new BigDecimal("0.5")).toString();
+//            sysConfig1.setContent(string);
+//            systemConfigurationMapper.updateById(sysConfig1);
+//            // 在6:00到8:59之间,不执行
+//            return;
+//        }
         // 9:00-16:59每分钟增加随机3 到 3.5
-        if (now.isAfter(LocalTime.of(9, 0)) && now.isBefore(LocalTime.of(16, 59))) {
-            refreshValueOne = refreshValueOne.add(new BigDecimal(3 + (3.5 - 3) * random.nextDouble())
-                    .setScale(2, RoundingMode.HALF_UP));
+        if (now.isAfter(LocalTime.of(6, 0)) && now.isBefore(LocalTime.of(12, 0))) {
             List<TSystemConfiguration> sysConfigs = systemConfigurationMapper.selectList(new LambdaQueryWrapper<TSystemConfiguration>()
                     .in(TSystemConfiguration::getType,4,5));
 
             TSystemConfiguration sysConfig = sysConfigs.stream().filter(e -> e.getType() == 4).findFirst().orElse(null);
-            sysConfig.setContent(refreshValueOne.toString());
+            sysConfig.setContent( new BigDecimal(sysConfig.getContent()).add(new BigDecimal(0.1 + (1 - 0.1) * random.nextDouble())
+                    .setScale(2, RoundingMode.HALF_UP)).toString());
             systemConfigurationMapper.updateById(sysConfig);
 
 
             TSystemConfiguration sysConfig1 = sysConfigs.stream().filter(e -> e.getType() == 5).findFirst().orElse(null);
-            String string = new BigDecimal(sysConfig1.getContent()).add(new BigDecimal(3 + (3.5 - 3) * random.nextDouble())).toString();
+            String string = new BigDecimal(sysConfig1.getContent()).add(new BigDecimal(0.1 + (1 - 0.1) * random.nextDouble())).toString();
             sysConfig1.setContent(string);
             systemConfigurationMapper.updateById(sysConfig1);
             return;
         }
+
         //17:00-18:59 每分钟增加0.5
-        if (now.isAfter(LocalTime.of(17, 0)) && now.isBefore(LocalTime.of(18, 59))) {
-            refreshValueOne = refreshValueOne.add(new BigDecimal("0.5"));
-            List<TSystemConfiguration> sysConfigs = systemConfigurationMapper.selectList(new LambdaQueryWrapper<TSystemConfiguration>()
-                    .in(TSystemConfiguration::getType,4,5));
-
-            TSystemConfiguration sysConfig = sysConfigs.stream().filter(e -> e.getType() == 4).findFirst().orElse(null);
-            sysConfig.setContent(refreshValueOne.toString());
-            systemConfigurationMapper.updateById(sysConfig);
-
-
-            TSystemConfiguration sysConfig1 = sysConfigs.stream().filter(e -> e.getType() == 5).findFirst().orElse(null);
-            String string = new BigDecimal(sysConfig1.getContent()).add(new BigDecimal("0.5")).toString();
-            sysConfig1.setContent(string);
-            systemConfigurationMapper.updateById(sysConfig1);
-        }
+//        if (now.isAfter(LocalTime.of(17, 0)) && now.isBefore(LocalTime.of(18, 59))) {
+//            List<TSystemConfiguration> sysConfigs = systemConfigurationMapper.selectList(new LambdaQueryWrapper<TSystemConfiguration>()
+//                    .in(TSystemConfiguration::getType,4,5));
+//
+//            TSystemConfiguration sysConfig = sysConfigs.stream().filter(e -> e.getType() == 4).findFirst().orElse(null);
+//
+//            sysConfig.setContent(new BigDecimal(sysConfig.getContent()).add(new BigDecimal("0.5")).toString());
+//            systemConfigurationMapper.updateById(sysConfig);
+//
+//
+//            TSystemConfiguration sysConfig1 = sysConfigs.stream().filter(e -> e.getType() == 5).findFirst().orElse(null);
+//            String string = new BigDecimal(sysConfig1.getContent()).add(new BigDecimal("0.5")).toString();
+//            sysConfig1.setContent(string);
+//            systemConfigurationMapper.updateById(sysConfig1);
+//        }
     }
 
 
+    public static void main(String[] args) {
+        Random random = new Random();
+        BigDecimal bigDecimal = new BigDecimal(0.1 + (1 - 0.1) * random.nextDouble());
+        System.out.println(bigDecimal);
+
+    }
 
 
 }
\ No newline at end of file
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/PhotovoltaicAndConsumptionVO.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/PhotovoltaicAndConsumptionVO.java
index dd9b28f..9ec03b0 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/PhotovoltaicAndConsumptionVO.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/PhotovoltaicAndConsumptionVO.java
@@ -14,7 +14,7 @@
     @ApiModelProperty("装机容量")
     private BigDecimal capacity = new BigDecimal("759.52");
     @ApiModelProperty("今日已发电")
-    private BigDecimal todayGenerateElectricity=new BigDecimal("71.29");
+    private BigDecimal todayGenerateElectricity=new BigDecimal("0");
 
     @ApiModelProperty("今日绿电消纳值")
     private BigDecimal greenElectricityToday=new BigDecimal("0.00");
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/PhotovoltaicPowerGenerationVO.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/PhotovoltaicPowerGenerationVO.java
index 578eac3..9fd06fa 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/PhotovoltaicPowerGenerationVO.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/PhotovoltaicPowerGenerationVO.java
@@ -11,5 +11,5 @@
     @ApiModelProperty("日期")
     private List<LocalDate> dates;
     @ApiModelProperty("数据")
-    private List<Integer> values;
+    private List<Double> values;
 }

--
Gitblit v1.7.1