whycxzp
2025-06-12 a0a525d59f1cb3167a54af9309c8dab162e89005
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.whyc.service;
 
import com.whyc.dto.Real.CompareDto;
import com.whyc.dto.Real.PwrHisRealAcInDto;
import com.whyc.dto.Real.PwrHisRealDcoutInDto;
import com.whyc.dto.Real.QuarterDto;
import com.whyc.dto.Response;
import com.whyc.dto.Statistic.QuarterPwr7Res;
import com.whyc.mapper.CommonMapper;
import com.whyc.pojo.db_data_history.BattRealdataId;
import com.whyc.pojo.db_data_history.PwrdevHistorydataId;
import com.whyc.pojo.db_station.PowerInf;
import com.whyc.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class PwrdevHistorydataIdService {
    @Autowired
    private SubTablePageInfoService subTablePageInfoService;
    @Resource
    private CommonMapper commonMapper;
 
    @Autowired
    private PowerInfService  powerInfService;
 
    //系统概览获取半小时交流输入统计
    public Response getHalfHourPwrHisAcinData(Integer powerId,Integer granularity) {
        String dateTime = ActionUtil.sdfwithOutday.format(new Date());
        //获取前半个小时数据
        LocalDateTime now = LocalDateTime.now();
        // 计算半小时前的时间点
        LocalDateTime halfHourAgo = now.minusMinutes(30);
        // 格式化输出
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String halfHourAgoTime=halfHourAgo.format(formatter);
        String tableName ="db_data_history.tb_pwrdev_historydata_"+powerId+"_"+dateTime;
        String existTableName = commonMapper.existTable("db_data_history", "tb_pwrdev_historydata_"+powerId+"_"+dateTime);
        if(existTableName == null){
            return new Response().set(1,false,"当前电池组不存在前面小时数据");
        }
        List<PwrHisRealAcInDto> datalist=subTablePageInfoService.getHalfHourPwrHisAcinData(tableName,granularity,halfHourAgoTime);
        return new Response().setII(1,datalist.size()>0,datalist,"获取半小时内交流输入统计");
 
    }
    //系统概览获取半小时直流输出统计
    public Response getHalfHourPwrHisDcoutData(Integer powerId,Integer granularity) {
        String dateTime = ActionUtil.sdfwithOutday.format(new Date());
        //获取前半个小时数据
        LocalDateTime now = LocalDateTime.now();
        // 计算半小时前的时间点
        LocalDateTime halfHourAgo = now.minusMinutes(30);
        // 格式化输出
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String halfHourAgoTime=halfHourAgo.format(formatter);
 
        String tableName ="db_data_history.tb_pwrdev_historydata_"+powerId+"_"+dateTime;
        String existTableName = commonMapper.existTable("db_data_history", "tb_pwrdev_historydata_"+powerId+"_"+dateTime);
        if(existTableName == null){
            return new Response().set(1,false,"当前电源不存在前面小时数据");
        }
        List<PwrHisRealDcoutInDto> datalist=subTablePageInfoService.getHalfHourPwrHisDcoutData(tableName,granularity,halfHourAgoTime);
        Long modelCfg=0l;
        PowerInf pinf=powerInfService.getPowerInfById(powerId);
        if(pinf!=null){
            modelCfg=pinf.getModelCfg();
        }
        return new Response().setIII(1,datalist.size()>0,datalist,modelCfg,"获取半小时内直流输出统计");
    }
    //1.2.7优良电源统计上一季度的电源某一属性和参数阈值超过的次数
    public Map<String,Integer> getPwrQuarter7(Integer powerId, Map<String,Float> paramValue) {
        Map<String,Integer> map=new HashMap<>();
        map.put("acin1Vola",0);
        map.put("acoutVola",0);
        map.put("dcoutVol",0);
        map.put("dcoutCurr",0);
        List<String> datelist = ActionUtil.getLastQuarterYearMonths();
        for (int i=0;i<datelist.size();i++) {
            String date=datelist.get(i);
            String tableName ="db_data_history.tb_pwrdev_historydata_"+powerId+"_"+date;
            String existTableName = commonMapper.existTable("db_data_history", "tb_pwrdev_historydata_"+powerId+"_"+date);
            //判断表是否存在
            if(existTableName == null){
                continue;
            }
            List<QuarterPwr7Res> datalist=subTablePageInfoService.getPwrQuarter7(tableName);
            // 遍历 dataList 并比较属性值
            for (QuarterPwr7Res data : datalist) {
                if (data.getAcin1Vola() > paramValue.get("acin1Vola")) {
                    map.put("acin1Vola", map.get("acin1Vola") + 1);
                }
                if (data.getAcoutVola() > paramValue.get("acoutVola")) {
                    map.put("acoutVola", map.get("acoutVola") + 1);
                }
                if (data.getDcoutVol() > paramValue.get("dcoutVol")) {
                    map.put("dcoutVol", map.get("dcoutVol") + 1);
                }
                if (data.getDcoutCurr() > paramValue.get("dcoutCurr")) {
                    map.put("dcoutCurr", map.get("dcoutCurr") + 1);
                }
            }
        }
        return map;
    }
}