From 988bbb6fe92380ba992a146ed94df2d8973a4edb Mon Sep 17 00:00:00 2001 From: liujie <1793218484@qq.com> Date: 星期四, 10 七月 2025 16:48:47 +0800 Subject: [PATCH] 储能对接 --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TScreenContentServiceImpl.java | 126 ++++++++++++++++++++++-------------------- 1 files changed, 66 insertions(+), 60 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 52dc72a..bee6136 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; @@ -30,10 +31,7 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.time.temporal.ChronoUnit; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Random; +import java.util.*; import java.util.concurrent.ThreadLocalRandom; /** @@ -54,46 +52,72 @@ @Override public EmissionReductionVO emissionReduction(List<Integer> siteIds) { + ScreenTopVO top = top(Arrays.asList(25, 26)); //需调用接口 计算光伏减排 EmissionReductionVO vo = new EmissionReductionVO(); - //获取总电量 计算电量 - BigDecimal charge=new BigDecimal("0.00"); - if (siteIds!=null && !siteIds.isEmpty()){ - R<BigDecimal> r = chargingOrderClient.getSumDegreeBySiteIds(siteIds); - if (r.getCode()==200){ - charge=r.getData(); - } - } - //计算电量占比率 + //获取总电量 计算累计充电二氧化碳减排量 + BigDecimal charge=top.getCarCharge(); + BigDecimal multiplier = new BigDecimal("0.1404"); + //计算累计充电二氧化碳减排量 if (charge.compareTo(BigDecimal.ZERO) != 0) { // 定义乘数和除数 - BigDecimal multiplier = new BigDecimal("0.1404"); // 0.1404 - BigDecimal divisor = new BigDecimal("1000"); // 1000 + // 0.1404 // 计算:charge × 0.1404 ÷ 1000 charge = charge .multiply(multiplier) // 乘以 0.1404 - .divide(divisor, 2, RoundingMode.HALF_UP); // 除以 1000,保留6位小数,四舍五入 + .divide(new BigDecimal("1000"),2, RoundingMode.HALF_DOWN); // 除以 1000,保留6位小数,四舍五入 } vo.setCharge(charge); + + //获取累计储能放电量 + String s = KsolarUtils.getElectricity().split("_")[0]; + vo.setEnergyStorage(new BigDecimal(s).multiply(multiplier) // 乘以 0.1404 + .divide(new BigDecimal("1000"),2, RoundingMode.HALF_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"))); + vo.setChargeRate(calculateRatio(vo.getCharge(),vo.getTotal()).multiply(new BigDecimal("100"))); + return vo; + } + + + //百分比计算 + 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(); + 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); - int value = new Random().nextInt(151) + 100; // 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); @@ -109,7 +133,7 @@ BigDecimal greenElectricity=new BigDecimal("0.00"); if (siteIds!=null && !siteIds.isEmpty()){ //获取充电量 - R<BigDecimal> r = chargingOrderClient.getSumDegreeBySiteIds(siteIds); + R<BigDecimal> r = chargingOrderClient.getSumDegreeBySiteIds(Arrays.asList(25,26)); if (r.getCode()==200){ charge=r.getData(); } @@ -123,44 +147,26 @@ vo.setCarDisCharge(carCharge); vo.setGreenElectricity(greenElectricity); - //获取系统建设日期和累计储能放电量 - TSystemConfiguration sysConfig = systemConfigurationMapper.selectOne(new LambdaQueryWrapper<TSystemConfiguration>() - .eq(TSystemConfiguration::getType,3)); - //解析 - ScreenStorageConfigVO configVO = JSON.parseObject(sysConfig.getContent(), ScreenStorageConfigVO.class); //计算储能充电量 - LocalDate systemCreateTime = configVO.getSystemCreateTime(); - LocalDate today = LocalDate.now(); - int days = (int) ChronoUnit.DAYS.between(systemCreateTime, today) +1;//包括今天 + String electricity = KsolarUtils.getElectricity(); + vo.setStorageCharge(new BigDecimal( electricity.split("_")[0])); - BigDecimal dailyRate = new BigDecimal("100"); - BigDecimal totalCharge = dailyRate.multiply(BigDecimal.valueOf(days)) - .divide(BigDecimal.valueOf(10000), 2, RoundingMode.HALF_UP); - vo.setStorageCharge(totalCharge); - //获取储能放电量 - - // 判断是否等于今天 - if (configVO.getLastUpdated().equals(today)) { - vo.setStorageDisCharge(configVO.getStorageDisCharge()); - return vo; - } - //判断离今天还有几天 - int count = (int) ChronoUnit.DAYS.between(configVO.getLastUpdated(), today) +1;//包括今天 - BigDecimal storageDisCharge = configVO.getStorageDisCharge(); - // 每天生成一个随机值(不超过100)并累加 - for (int i = 0; i < count; i++) { - int dailyCharge = ThreadLocalRandom.current().nextInt(0, 101); // 0-100的随机数 - storageDisCharge = storageDisCharge.add(new BigDecimal(dailyCharge)); - } - - // 更新回对象 - configVO.setStorageDisCharge(storageDisCharge); - configVO.setLastUpdated(today); - String json = JSON.toJSONString(configVO); - sysConfig.setContent(json); - - systemConfigurationMapper.updateById(sysConfig); - vo.setStorageDisCharge(storageDisCharge); + vo.setPhotovoltaic(new BigDecimal(KsolarUtils.getAllEnergy(LocalDate.now().toString()))); + vo.setGreenElectricity(vo.getPhotovoltaic().multiply(new BigDecimal("0.94")).setScale(2, RoundingMode.HALF_UP)); + vo.setStorageDisCharge(new BigDecimal(electricity.split("_")[1])); return vo; } + + @Override + public void carportData(Integer parkingPlace, Integer remainPlace) { + this.baseMapper.carportData(parkingPlace,remainPlace); + } + + @Override + public HashMap<String, Object> getCarportData() { + HashMap<String, Object> carportData = this.baseMapper.getCarportData(); + int count = Integer.valueOf(carportData.get("parkingPlace").toString()) - Integer.valueOf(carportData.get("remainPlace").toString()); + carportData.put("useCarport",count); + return carportData; + } } -- Gitblit v1.7.1