whyclxw
2025-05-29 6c13a67934178804ba4845ed821a07145e679a0e
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
package com.whyc.service;
 
import com.whyc.dto.Real.CompareDto;
import com.whyc.dto.Real.QuarterDto;
import com.whyc.dto.Response;
import com.whyc.mapper.CommonMapper;
import com.whyc.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
 
@Service
public class BattRealdataIdService {
    @Autowired
    private SubTablePageInfoService subTablePageInfoService;
    @Resource
    private CommonMapper commonMapper;
 
    //获取电池组最近一季度的单体数据
    public Response getBattQuarter(Integer battgroupId) {
        HashMap<String,Object> map = new HashMap<>();
        Float maxVol=0f;
        Float minVol=0f;
        Float avgVol=0f;
        int num=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_batt_realdata_"+battgroupId+"_"+date;
            String existTableName = commonMapper.existTable("db_data_history", "tb_batt_realdata_"+battgroupId+"_"+date);
            if(existTableName == null){
                continue;
            }
            //判断表是否存在
            List<QuarterDto> datalist=subTablePageInfoService.getBattRealHis(tableName,"mon_vol");
            map.put(date,datalist);
            //获取表中最大,最小,平均数据值
            CompareDto compareData=subTablePageInfoService.getBattCompareHis(tableName,"mon_vol");
            if(num==0){
                maxVol=compareData.getMaxValue();
                minVol=compareData.getMinValue();
            }
            if (compareData.getMaxValue() >= maxVol) {
                maxVol =compareData.getMaxValue();
            }
            if (compareData.getMinValue() <= minVol) {
                minVol = compareData.getMinValue();
            }
            avgVol += compareData.getAvgValue();
            map.put("maxVol",maxVol);
            map.put("minVol",minVol);
            map.put("avgVol",avgVol/datelist.size());
            num++;
        }
        return new Response().setII(1,map.size()>0,map,"获取电池组最近一季度的数据");
    }
}