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) {
//需调用接口 计算光伏减排
EmissionReductionVO vo = new EmissionReductionVO();
//获取总电量 计算累计充电二氧化碳减排量(与大屏累计充电量同口径: 已结束+已支付订单)
BigDecimal charge = BigDecimal.ZERO;
R r = chargingOrderClient.getLargeScreenTotalCapacity(siteIds);
if (r.getCode() == 200 && r.getData() != null) {
charge = r.getData();
}
BigDecimal multiplier = new BigDecimal("0.1564");
//计算累计充电二氧化碳减排量
if (charge.compareTo(BigDecimal.ZERO) != 0) {
// 计算:charge × 0.1564 ÷ 1000
charge = charge
.multiply(multiplier) // 乘以 0.1564
.divide(new BigDecimal("1000"), 2, RoundingMode.HALF_DOWN); // 除以 1000,保留2位小数,四舍五入
}
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) {
return BigDecimal.ZERO;
}
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