ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -4097,7 +4097,8 @@ LocalDateTime endDate = today.minusDays(1).atTime(LocalTime.MAX); // 查询数据库 List<OrderCountByDate> orderCounts = this.baseMapper.countOrdersByDate(startDate, endDate, gunIds);*/ // 转换结果 List<LocalDate> dates = new ArrayList<>(); List<Integer> counts = new ArrayList<>(); LocalDate today = LocalDate.now(); @@ -4113,7 +4114,7 @@ .eq(TChargingOrder::getDelFlag,0)//未删除 .in(TChargingOrder::getStatus,Arrays.asList(3,5))//充电中、已结束 .in(TChargingOrder::getChargingGunId,gunIds)//符合条件的充电枪 站点 超充快充 .between(BasePojo::getCreateTime,startOfDay,endOfDay));//每天 .between(TChargingOrder::getCreateTime,startOfDay,endOfDay));//每天 } dates.add(day); counts.add(count.intValue()); @@ -4122,7 +4123,6 @@ vo.setCounts(counts); return R.ok(vo); } @Override public BigDecimal getSumDegreeBySiteIds(List<Integer> siteIds) { ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TScreenContentController.java
@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.Arrays; import java.util.List; /** @@ -54,8 +55,18 @@ @GetMapping(value = "/photovoltaicAndConsumption") public AjaxResult<PhotovoltaicAndConsumptionVO> photovoltaicAndConsumption() { //需调用接口 获取光伏发电量 return AjaxResult.success(new PhotovoltaicAndConsumptionVO()); 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())); }); return AjaxResult.success(vo); } ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TScreenContentServiceImpl.java
@@ -56,7 +56,7 @@ public EmissionReductionVO emissionReduction(List<Integer> siteIds) { //需调用接口 计算光伏减排 EmissionReductionVO vo = new EmissionReductionVO(); //获取总电量 计算电量 //获取总电量 计算累计充电二氧化碳减排量 BigDecimal charge=new BigDecimal("0.00"); if (siteIds!=null && !siteIds.isEmpty()){ R<BigDecimal> r = chargingOrderClient.getSumDegreeBySiteIds(siteIds); @@ -64,7 +64,7 @@ charge=r.getData(); } } //计算电量占比率 //计算累计充电二氧化碳减排量 if (charge.compareTo(BigDecimal.ZERO) != 0) { // 定义乘数和除数 BigDecimal multiplier = new BigDecimal("0.1404"); // 0.1404 @@ -75,7 +75,54 @@ .divide(divisor, 2, RoundingMode.HALF_UP); // 除以 1000,保留6位小数,四舍五入 } vo.setCharge(charge); //获取累计储能放电量 TSystemConfiguration sysConfig = systemConfigurationMapper.selectOne(new LambdaQueryWrapper<TSystemConfiguration>() .eq(TSystemConfiguration::getType,3)); //解析 ScreenStorageConfigVO configVO = JSON.parseObject(sysConfig.getContent(), ScreenStorageConfigVO.class); LocalDate today = LocalDate.now(); // 判断是否等于今天 if (configVO.getLastUpdated().equals(today)) { vo.setEnergyStorage(configVO.getStorageDisCharge()); }else { //判断离今天还有几天 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.setEnergyStorage(storageDisCharge); } //总数: BigDecimal total = vo.getPhotovoltaic().add(vo.getEnergyStorage()).add(vo.getCharge()); vo.setTotal(total); //计算比率 vo.setPhotovoltaicRate(calculateRatio(vo.getPhotovoltaic(),vo.getTotal())); vo.setEnergyStorageRate(calculateRatio(vo.getEnergyStorage(),vo.getTotal())); vo.setChargeRate(calculateRatio(vo.getCharge(),vo.getTotal())); return vo; } //百分比计算 public static BigDecimal calculateRatio(BigDecimal part, BigDecimal total) { if (total.compareTo(BigDecimal.ZERO) == 0) { throw new ArithmeticException("分母不能为零"); } return part.divide(total, 2, RoundingMode.HALF_UP); } @Override @@ -134,8 +181,7 @@ int days = (int) ChronoUnit.DAYS.between(systemCreateTime, today) +1;//包括今天 BigDecimal dailyRate = new BigDecimal("100"); BigDecimal totalCharge = dailyRate.multiply(BigDecimal.valueOf(days)) .divide(BigDecimal.valueOf(10000), 2, RoundingMode.HALF_UP); BigDecimal totalCharge = dailyRate.multiply(BigDecimal.valueOf(days)); vo.setStorageCharge(totalCharge); //获取储能放电量 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/EmissionReductionVO.java
@@ -10,18 +10,18 @@ @ApiModelProperty("累计光伏发电二氧化碳减排量(吨)") private BigDecimal photovoltaic = new BigDecimal("63.00"); @ApiModelProperty("累计光伏发电二氧化碳减排量(占比率)") private BigDecimal photovoltaicRate = new BigDecimal("48.8"); private BigDecimal photovoltaicRate ; @ApiModelProperty("累计储能二氧化碳减排量(吨)") private BigDecimal energyStorage = new BigDecimal("20.00"); private BigDecimal energyStorage ; @ApiModelProperty("累计储能二氧化碳减排量(占比率)") private BigDecimal energyStorageRate = new BigDecimal("48.8"); private BigDecimal energyStorageRate ; @ApiModelProperty("累计充电二氧化碳减排量(吨)") private BigDecimal charge; @ApiModelProperty("累计充电二氧化碳减排量(占比率)") private BigDecimal chargeRate = new BigDecimal("4.8"); private BigDecimal chargeRate ; @ApiModelProperty("总计二氧化碳减排量(吨)") private BigDecimal total = new BigDecimal("48000"); private BigDecimal total ; } ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/vo/PhotovoltaicAndConsumptionVO.java
@@ -1,5 +1,6 @@ package com.ruoyi.other.vo; import com.baomidou.mybatisplus.annotation.TableField; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -15,4 +16,7 @@ @ApiModelProperty("今日已发电") private BigDecimal todayGenerateElectricity=new BigDecimal("71.29"); @ApiModelProperty("今日绿电消纳值") private BigDecimal greenElectricityToday=new BigDecimal("0.00"); }