From 49f98d682437c5d91fa07a72bdc3cb45c0600f82 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期四, 19 六月 2025 09:57:19 +0800
Subject: [PATCH] Merge branch 'dev' of http://120.76.84.145:10101/gitblit/r/java/mx_charging_pile

---
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TScreenContentServiceImpl.java |  255 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 255 insertions(+), 0 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
new file mode 100644
index 0000000..1c016e9
--- /dev/null
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TScreenContentServiceImpl.java
@@ -0,0 +1,255 @@
+package com.ruoyi.other.service.impl;
+
+import com.alibaba.fastjson2.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.web.domain.BasePojo;
+import com.ruoyi.order.api.feignClient.ChargingOrderClient;
+import com.ruoyi.order.api.model.TChargingOrder;
+import com.ruoyi.other.api.domain.TScreenContent;
+import com.ruoyi.other.api.domain.TSystemConfiguration;
+import com.ruoyi.other.mapper.TScreenContentMapper;
+import com.ruoyi.other.mapper.TSystemConfigurationMapper;
+import com.ruoyi.other.service.TScreenContentService;
+import com.ruoyi.other.service.TSystemConfigurationService;
+import com.ruoyi.other.vo.EmissionReductionVO;
+import com.ruoyi.other.vo.PhotovoltaicPowerGenerationVO;
+import com.ruoyi.other.vo.ScreenStorageConfigVO;
+import com.ruoyi.other.vo.ScreenTopVO;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import javax.json.Json;
+import javax.json.JsonObject;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.temporal.ChronoUnit;
+import java.util.*;
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author huliguo
+ * @since 2025/5/23
+ */
+@Service
+public class TScreenContentServiceImpl extends ServiceImpl<TScreenContentMapper, TScreenContent> implements TScreenContentService {
+
+    @Resource
+    private ChargingOrderClient chargingOrderClient;
+    @Resource
+    private TSystemConfigurationMapper systemConfigurationMapper;
+
+    @Override
+    public EmissionReductionVO emissionReduction(List<Integer> siteIds) {
+        ScreenTopVO top = top(Arrays.asList(25, 26));
+        //需调用接口 计算光伏减排
+        EmissionReductionVO vo = new EmissionReductionVO();
+        //获取总电量 计算累计充电二氧化碳减排量
+        BigDecimal charge=top.getCarCharge();
+        //计算累计充电二氧化碳减排量
+        if (charge.compareTo(BigDecimal.ZERO) != 0) {
+            // 定义乘数和除数
+            BigDecimal multiplier = new BigDecimal("0.1404"); // 0.1404
+            BigDecimal divisor = new BigDecimal("1000");    // 1000
+            // 计算:charge × 0.1404 ÷ 1000
+            charge = charge
+                    .multiply(multiplier)      // 乘以 0.1404
+                    .divide(new BigDecimal("1000"),2, RoundingMode.HALF_DOWN); // 除以 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().multiply(new BigDecimal("0.1404")).divide(new BigDecimal("1000"),2,RoundingMode.DOWN));
+        }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.multiply(new BigDecimal("0.1404")).divide(new BigDecimal("1000"),2,RoundingMode.DOWN));
+        }
+
+        //总数:
+        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 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<>();
+        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;
+
+            }
+            values.add(value);
+        }
+        vo.setDates(dates);
+        vo.setValues(values);
+        return vo;
+    }
+
+    @Override
+    public ScreenTopVO top(List<Integer> 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<BigDecimal> 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);
+
+        //获取系统建设日期和累计储能放电量
+        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;//包括今天
+
+        BigDecimal dailyRate = new BigDecimal("100");
+        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.setGreenElectricity(vo.getPhotovoltaic().multiply(new BigDecimal("0.94")).setScale(2,  RoundingMode.HALF_UP));
+
+        //获取储能放电量
+
+        // 判断是否等于今天
+        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);
+
+
+         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