Pu Zhibing
3 天以前 7cf1eb27ecbd23ddc1d0e8080c9637aa6f2a2bf9
Merge branch 'dev' of http://120.76.84.145:10101/gitblit/r/java/mx_charging_pile
2个文件已添加
6个文件已修改
586 ■■■■ 已修改文件
ruoyi-service/ruoyi-jianguan/src/main/java/com/ruoyi/jianguan/mongodb/service/impl/UploadRealTimeMonitoringDataServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TScreenContentController.java 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TScreenContentServiceImpl.java 52 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/AESUtils.java 95 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/EnergyRefreshService.java 266 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/KsolarUtils.java 146 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/PhotovoltaicAndConsumptionVO.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/PhotovoltaicPowerGenerationVO.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-jianguan/src/main/java/com/ruoyi/jianguan/mongodb/service/impl/UploadRealTimeMonitoringDataServiceImpl.java
@@ -183,7 +183,7 @@
        }
        List<UploadRealTimeMonitoringData> list = mongoTemplate.find(
                query.with(Sort.by(Sort.Order.desc("create_time")))
                , UploadRealTimeMonitoringData.class);
                , UploadRealTimeMonitoringData.class,"upload_real_time_monitoring_data");
        return list;
    }
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);
    }
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());
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/AESUtils.java
New file
@@ -0,0 +1,95 @@
package com.ruoyi.other.util;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
/**
 * Created by jhb on 2022-08-03 14:16
 */
public class AESUtils {
    public static final String DEFAULT_SECRET_KEY = "kstar_ase_keysfo";
    /**
     * 加密
     * @param sSrc 需要加密的字符串
     * @param sKey 此处使用AES-128-ECB加密模式,key需要为16位。
     * @return
     * @throws Exception
     */
    public static String Encrypt(String sSrc, String sKey) throws Exception {
        sKey = DEFAULT_SECRET_KEY;
        // 判断Key是否为16位
        if (sKey.length() != 16) {
            System.out.print("Key长度不是16位");
            return null;
        }
        byte[] raw = sKey.getBytes("utf-8");
        SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");//"算法/模式/补码方式"
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
        byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
        return new Base64().encodeToString(encrypted);//此处使用BASE64做转码功能,同时能起到2次加密的作用。
    }
    /**
     * 解密
     * @param sSrc 需要解密的字符串
     * @param sKey 此处使用AES-128-ECB加密模式,key需要为16位。
     * @return
     * @throws Exception
     */
    public static String Decrypt(String sSrc, String sKey) throws Exception {
        sKey = DEFAULT_SECRET_KEY;
        try {
            // 判断Key是否正确
            if (sKey == null) {
                System.out.print("Key为空null");
                return null;
            }
            // 判断Key是否为16位
            if (sKey.length() != 16) {
                System.out.print("Key长度不是16位");
                return null;
            }
            byte[] raw = sKey.getBytes("utf-8");
            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(Cipher.DECRYPT_MODE, skeySpec);
            byte[] encrypted1 = new Base64().decode(sSrc);//先用base64解密
            try {
                byte[] original = cipher.doFinal(encrypted1);
                String originalString = new String(original,"utf-8");
                return originalString;
            } catch (Exception e) {
                System.out.println(e.toString());
                return null;
            }
        } catch (Exception ex) {
            System.out.println(ex.toString());
            return null;
        }
    }
    public static void main(String[] args) throws Exception {
        /*
         * 此处使用AES-128-ECB加密模式,key需要为16位。
         */
        String cKey = "kstar_ase_keysfo";
        // 需要加密的字串
        String cSrc = "huandaoguangfu";
        System.out.println(cSrc);
        // 加密
        String enString = AESUtils.Encrypt(cSrc, cKey);
        System.out.println("加密后的字串是:" + enString);
        // 解密
        String DeString = AESUtils.Decrypt(enString, cKey);
        System.out.println("解密后的字串是:" + DeString);
    }
}
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/EnergyRefreshService.java
@@ -30,85 +30,147 @@
    private TSystemConfigurationMapper systemConfigurationMapper;
    // 储能相关参数
    private final BigDecimal storageMaxMorning = new BigDecimal("115"); // 凌晨到8点储能最大值
    private final BigDecimal storageMaxAfternoon = new BigDecimal("115"); // 12点后储能最大值
    private final BigDecimal dischargeMaxMorning = new BigDecimal("90"); // 上午放电最大值
    private final BigDecimal dischargeMaxAfternoon = new BigDecimal("90"); // 下午放电最大值
    private final BigDecimal storageMax = new BigDecimal("115"); // 储能最大值
    private final BigDecimal targetDischargeTotal = new BigDecimal("97.75"); // 目标总放电量
    private final double minChargeIncrement = 0.5; // 充电最小增量
    private final double maxChargeIncrement = 1.0; // 充电最大增量
    private final int minDischargeTimes = 3; // 最小放电次数
    private final int maxDischargeTimes = 4; // 最大放电次数
    private final BigDecimal minDischargeAmount = new BigDecimal("25"); // 单次最小放电量
    private final BigDecimal maxDischargeAmount = new BigDecimal("35"); // 单次最大放电量
    private final double minIncrement = 0.5; // 最小增量(储能/放电共用)
    private final double maxIncrement = 1.0; // 最大增量(储能/放电共用)
    // 充电阶段标记
    private boolean isFirstChargeCompleted = false;
    private boolean isSecondChargeCompleted = false;
    // 放电次数计数器
    private int dischargeCount = 0;
    // 当前阶段总放电量
    private BigDecimal currentPhaseDischarge = BigDecimal.ZERO;
    // 定时任务方法 - 能量刷新
    @Scheduled(cron = "0 * * * * ?") // 每分钟执行一次(原15分钟改为1分钟)
    @Scheduled(cron = "0 * * * * ?") // 每分钟执行一次
    public synchronized void refreshValue() {
        LocalTime now = LocalTime.now();
        // 根据时间段执行不同逻辑
        if (isInStorageMorning(now)) { // 00:00-7:59 储能阶段
            handleStoragePhase(storageMaxMorning, BigDecimal.ZERO);
        } else if (isInDischargeMorning(now)) { // 10:00-11:59 上午放电阶段
            handleDischargePhase(dischargeMaxMorning);
        } else if (isInStorageAfternoon(now)) { // 12:00-16:59 下午储能阶段
            handleStoragePhase(storageMaxAfternoon, getTodayDischarge());
        } else if (isInDischargeAfternoon(now)) { // 17:00-21:59 下午放电阶段
            handleDischargePhase(dischargeMaxAfternoon);
        // 第一轮充电阶段 (0:00-3:00)
        if (now.isAfter(LocalTime.of(0, 0)) && now.isBefore(LocalTime.of(3, 0))) {
            handleChargePhase();
        }
        // 第一轮放电阶段 (3:10开始,每10分钟一次)
        else if (now.isAfter(LocalTime.of(3, 0)) && now.isBefore(LocalTime.of(15, 0))
                && now.getMinute() % 10 == 0 && now.getSecond() == 0) {
            handleDischargePhase(false);
        }
        // 第二轮充电阶段 (15:00-17:00)
        else if (now.isAfter(LocalTime.of(15, 0)) && now.isBefore(LocalTime.of(17, 0))) {
            handleChargePhase();
        }
        // 第二轮放电阶段 (17:10开始,每10分钟一次)
        else if (now.isAfter(LocalTime.of(17, 0)) && now.isBefore(LocalTime.of(23, 59))
                && now.getMinute() % 10 == 0 && now.getSecond() == 0) {
            handleDischargePhase(true);
        }
    }
    // 储能阶段处理逻辑
    public void handleStoragePhase(BigDecimal maxValue, BigDecimal dischargeValue) {
        BigDecimal todayStorage=getTodayStorage();//当前储能值
        BigDecimal availableSpace = maxValue.subtract(todayStorage.subtract(dischargeValue));//115-(储能-放能) 当前可上涨空间
    // 充电阶段处理逻辑
    private void handleChargePhase() {
        BigDecimal todayStorage = getTodayStorage();
        // 随机增量0.5—1.0
        BigDecimal increment = randomBigDecimal(minIncrement,maxIncrement);
        BigDecimal newStorage;
        if (availableSpace.compareTo(increment) >= 0 ) {
            //可用空间大于等于当前增量
             newStorage = todayStorage.add(increment)
                    .setScale(2, RoundingMode.HALF_UP);
        }else {
            //可用空间不足当前增量
            newStorage = maxValue.add(dischargeValue);//115 + 放能  (如:上午放90,下午就只能充90)
        // 如果已经充满,则不再充电
        if (todayStorage.compareTo(storageMax) >= 0) {
            if (!isFirstChargeCompleted && todayStorage.compareTo(storageMax) >= 0) {
                isFirstChargeCompleted = true;
                System.out.println("第一轮充电已完成,当前储能: " + todayStorage);
            } else if (!isSecondChargeCompleted && todayStorage.compareTo(storageMax.multiply(new BigDecimal("2"))) >= 0) {
                isSecondChargeCompleted = true;
                System.out.println("第二轮充电已完成,当前储能: " + todayStorage);
        }
        if (newStorage.compareTo(todayStorage)==0){
            //新增值等于当前储能值 说明已达到最大值,没必要更新了
            return;
        }
        // 随机增量0.5-1.0
        BigDecimal increment = randomBigDecimal(minChargeIncrement, maxChargeIncrement);
        BigDecimal newStorage = todayStorage.add(increment).setScale(2, RoundingMode.HALF_UP);
        // 确保不超过最大值
        BigDecimal maxAllowed = isFirstChargeCompleted ? storageMax.multiply(new BigDecimal("2")) : storageMax;
        if (newStorage.compareTo(maxAllowed) > 0) {
            newStorage = maxAllowed;
        }
        updateStorageValue(newStorage);
        System.out.printf("储能阶段:当前时间 %s,今日储能:%.2f%n", LocalTime.now(), newStorage);
        System.out.printf("充电阶段:当前时间 %s,今日储能:%.2f%n", LocalTime.now(), newStorage);
    }
    // 放电阶段处理逻辑
    private void handleDischargePhase(BigDecimal maxDischarge) {
        BigDecimal currentDischarge = getTodayDischarge();//当前放电量
        BigDecimal todayStorage = getTodayStorage();//储能量
        //今日储能-115,就是耗能(基数),在这个基数上加90
        BigDecimal baseDischarge = todayStorage.subtract(storageMaxAfternoon);
        BigDecimal newMaxDischarge = baseDischarge.add(maxDischarge);//上限 基数+90
        // 随机增量0.5—1.0
        BigDecimal increment = randomBigDecimal(minIncrement,maxIncrement);
        BigDecimal newDischarge = currentDischarge.add(increment);//当前值 + 增量
        if (newDischarge.compareTo(newMaxDischarge) >=0) {
            //超出 用最大值
            newDischarge = newMaxDischarge;
        }
        if (newDischarge.compareTo(currentDischarge)==0){
            //新增值等于当前值,说明已超出,没必要更新了
    private void handleDischargePhase(boolean isSecondPhase) {
        // 如果是第二轮放电且第一轮未完成,则不执行
        if (isSecondPhase && !isFirstChargeCompleted) {
            return;
        }
        // 如果已经达到目标放电量,则不再放电
        BigDecimal todayDischarge = getTodayDischarge();
        BigDecimal target = isSecondPhase ? targetDischargeTotal.multiply(new BigDecimal("2")) : targetDischargeTotal;
        if (todayDischarge.compareTo(target) >= 0) {
            return;
        }
        // 如果是新一轮放电阶段,重置计数器
        if (currentPhaseDischarge.compareTo(BigDecimal.ZERO) == 0) {
            dischargeCount = 0;
        }
        // 计算剩余需要放电的量
        BigDecimal remainingDischarge = target.subtract(todayDischarge);
        // 随机本次放电量 (25-35)
        BigDecimal dischargeAmount = randomBigDecimal(minDischargeAmount.doubleValue(), maxDischargeAmount.doubleValue());
        // 如果剩余量不足,则只放剩余量
        if (dischargeAmount.compareTo(remainingDischarge) > 0) {
            dischargeAmount = remainingDischarge;
        }
        // 更新放电量
        BigDecimal newDischarge = todayDischarge.add(dischargeAmount).setScale(2, RoundingMode.HALF_UP);
        updateDischargeValue(newDischarge);
        System.out.printf("放电阶段:当前时间 %s,今日放电:%.2f%n", LocalTime.now(), newDischarge);
        // 更新当前阶段放电总量
        currentPhaseDischarge = currentPhaseDischarge.add(dischargeAmount);
        dischargeCount++;
        System.out.printf("放电阶段:当前时间 %s,第%d次放电,本次放电:%.2f,今日总放电:%.2f%n",
                LocalTime.now(), dischargeCount, dischargeAmount, newDischarge);
        // 如果达到最大放电次数或完成目标放电量,重置当前阶段放电量
        if (dischargeCount >= maxDischargeTimes || remainingDischarge.subtract(dischargeAmount).compareTo(BigDecimal.ZERO) <= 0) {
            currentPhaseDischarge = BigDecimal.ZERO;
        }
    }
    // 重置任务(每天凌晨0点)
    @Scheduled(cron = "0 0 0 * * ?")
    public void reset() {
        // 重置所有状态
        isFirstChargeCompleted = false;
        isSecondChargeCompleted = false;
        dischargeCount = 0;
        currentPhaseDischarge = BigDecimal.ZERO;
        // 初始化今日储能和放电为0
        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);
    }
    /**
@@ -127,15 +189,7 @@
        // 转换为两位小数的 BigDecimal
        return BigDecimal.valueOf(value).setScale(2, RoundingMode.HALF_UP);
    }
    // 更新今日储能值到数据库
    private void updateStorageValue(BigDecimal value) {
        updateConfigField("todayStorage", value);
    }
    // 更新今日放电值到数据库(原逻辑保留)
    private void updateDischargeValue(BigDecimal value) {
        updateConfigField("todayDischarge", value);
    }
    // 通用配置更新方法
    private void updateConfigField(String field, BigDecimal value) {
@@ -171,6 +225,17 @@
        return time.isAfter(LocalTime.of(17, 0)) && time.isBefore(LocalTime.of(22, 0));
    }
    // 更新今日储能值到数据库
    private void updateStorageValue(BigDecimal value) {
        updateConfigField("todayStorage", value);
    }
    // 更新今日放电值到数据库(原逻辑保留)
    private void updateDischargeValue(BigDecimal value) {
        updateConfigField("todayDischarge", value);
    }
    public BigDecimal getTodayStorage() {
        TSystemConfiguration sysConfig = systemConfigurationMapper.selectOne(
                new LambdaQueryWrapper<TSystemConfiguration>()
@@ -198,67 +263,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);
    }
}
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/KsolarUtils.java
New file
@@ -0,0 +1,146 @@
package com.ruoyi.other.util;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.other.api.domain.TSystemConfiguration;
import com.ruoyi.other.mapper.TSystemConfigurationMapper;
import com.ruoyi.other.vo.ScreenStorageConfigVO;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
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;
/**
 * 定时任务:储能放电情况 光伏发电情况
 */
@Service
public class KsolarUtils {
    private static String token;
    private static List<String> stationIds= Arrays.asList("2025060710462417","2025060711331323","2025060715425437","2025060716010425");
    public static Double getTodayEnergy(String time) {
        try {
            HttpRequest get = HttpUtil.createGet("http://111.230.136.62:8092/station/list/earn");
            get.header("Authorization", "Bearer "+token);
            get.form("startDate", time);
            HttpResponse execute = get.execute();
            String body = execute.body();
            JSONObject jsonObject = JSONObject.parseObject(body);
            String code = jsonObject.get("code").toString();
            if(!"200".equals(code)){
                token = token();
                return getTodayEnergy(time);
            }
            Object data  = jsonObject.get("data");
            JSONObject jsonObject1 = JSONObject.parseObject(data.toString());
            Double earn = jsonObject1.getDouble("dayGeneration");
            return earn;
        } catch (Exception e) {
            e.printStackTrace();
            token = token();
            return getTodayEnergy(time);
        }
    }
    public static Double getAllEnergy(String time) {
        try {
            HttpRequest get = HttpUtil.createGet("http://111.230.136.62:8092/station/list/earn");
            get.header("Authorization", "Bearer "+token);
            get.form("startDate", time);
            HttpResponse execute = get.execute();
            String body = execute.body();
            JSONObject jsonObject = JSONObject.parseObject(body);
            String code = jsonObject.get("code").toString();
            if(!"200".equals(code)){
                token = token();
                return getAllEnergy(time);
            }
            Object data  = jsonObject.get("data");
            JSONObject jsonObject1 = JSONObject.parseObject(data.toString());
            Double earn = jsonObject1.getDouble("totalGeneration");
            return earn;
        } catch (Exception e) {
            e.printStackTrace();
            token = token();
            return getAllEnergy(time);
        }
    }
    /**
     * 光伏碳减排
     * @return
     */
    public static BigDecimal getYearAllEnergy() {
        Double yearAllEnergy = getYearAllEnergy(stationIds.get(0));
        Double yearAllEnergy1 = getYearAllEnergy(stationIds.get(1));
        Double yearAllEnergy2 = getYearAllEnergy(stationIds.get(2));
        Double yearAllEnergy3 = getYearAllEnergy(stationIds.get(3));
        double v = yearAllEnergy + yearAllEnergy1 + yearAllEnergy2 + yearAllEnergy3;
        BigDecimal divide = new BigDecimal(v).multiply(new BigDecimal("0.1404")).divide(new BigDecimal("1000"), 2, RoundingMode.DOWN);
        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("attribId", "202");
            get.form("stime",LocalDate.now().getYear()+"" );
            HttpResponse execute = get.execute();
            String body = execute.body();
            JSONArray jsonArray = JSONArray.parseArray(body);
            Object o1 = jsonArray.get(0);
            JSONObject jsonObject = JSONObject.parseObject(o1.toString());
            String code = jsonObject.get("attribValue").toString();
            Double earn = Double.valueOf(code);
            return earn;
        } catch (Exception e) {
            e.printStackTrace();
            token = token();
            return getYearAllEnergy(LocalDate.now().getYear()+"");
        }
    }
    public static String token() {
        HttpRequest post = HttpUtil.createPost("http://111.230.136.62:8092/authentication/form");
        post.basicAuth("kstar","kstarSecret");
        post.form("username", "环岛光伏");
        post.form("password", "cR8GGwIXMI462A8Dfl9eXg==");
        HttpResponse execute = post.execute();
        String body = execute.body();
        JSONObject jsonObject = JSONObject.parseObject(body);
        String token = jsonObject.getString("token");
        JSONObject jsonObject1 = JSONObject.parseObject(token);
        String access_token = jsonObject1.getString("access_token");
        return  access_token;
    }
    public static void main(String[] args) throws Exception {
        System.out.println(getYearAllEnergy("2025",""));
    }
}
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");
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;
}