package com.ruoyi.other.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.domain.R; import com.ruoyi.order.api.feignClient.ChargingOrderClient; import com.ruoyi.other.api.domain.TScreenContent; import com.ruoyi.other.mapper.TScreenContentMapper; import com.ruoyi.other.service.TScreenContentService; import com.ruoyi.other.util.KsolarUtils; import com.ruoyi.other.vo.EmissionReductionVO; import com.ruoyi.other.vo.PhotovoltaicPowerGenerationVO; import com.ruoyi.other.vo.ScreenTopVO; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDate; import java.util.*; /** *

* 服务实现类 *

* * @author huliguo * @since 2025/5/23 */ @Service public class TScreenContentServiceImpl extends ServiceImpl implements TScreenContentService { @Resource private ChargingOrderClient chargingOrderClient; @Override public EmissionReductionVO emissionReduction(List siteIds) { ScreenTopVO top = top(Arrays.asList(25, 26)); //需调用接口 计算光伏减排 EmissionReductionVO vo = new EmissionReductionVO(); //获取总电量 计算累计充电二氧化碳减排量 BigDecimal charge = top.getCarCharge(); BigDecimal multiplier = new BigDecimal("1.564"); //计算累计充电二氧化碳减排量 if (charge.compareTo(BigDecimal.ZERO) != 0) { // 定义乘数和除数 // 0.1404 // 计算:charge × 0.1404 ÷ 1000 charge = charge .multiply(multiplier) // 乘以 0.1404 .divide(new BigDecimal("10000"), 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 siteIds) { PhotovoltaicPowerGenerationVO vo = new PhotovoltaicPowerGenerationVO(); List dates = new ArrayList<>(); List values = new ArrayList<>(); LocalDate today = LocalDate.now(); ArrayList> 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); Map 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); return vo; } @Override public ScreenTopVO top(List siteIds) { ScreenTopVO vo = new ScreenTopVO(); BigDecimal charge = new BigDecimal("0.00"); BigDecimal carCharge = new BigDecimal("0.00"); BigDecimal greenElectricity = new BigDecimal("0.00"); if (siteIds != null && !siteIds.isEmpty()) { //获取充电量 R r = chargingOrderClient.getSumDegreeBySiteIds(Arrays.asList(25, 26)); if (r.getCode() == 200) { charge = r.getData(); } //汽车放电量 carCharge = this.baseMapper.getCarDisCharge(siteIds); //累计绿电消纳电量 greenElectricity = this.baseMapper.getGreenElectricity(siteIds); } vo.setCarCharge(charge); vo.setCarDisCharge(carCharge); vo.setGreenElectricity(greenElectricity); //计算储能充电量 String electricity = KsolarUtils.getElectricity(); vo.setStorageCharge(new BigDecimal(electricity.split("_")[0])); 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 getCarportData() { HashMap carportData = this.baseMapper.getCarportData(); int count = Integer.valueOf(carportData.get("parkingPlace").toString()) - Integer.valueOf(carportData.get("remainPlace").toString()); carportData.put("useCarport", count); return carportData; } }