whyclxw
2025-06-04 834fd9864797c34489d5c3acfc7cc6bcb30ad31c
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.dto.Statistic.BattTinfStic;
import com.whyc.dto.Statistic.MonStic;
import com.whyc.dto.Statistic.StationStic;
import com.whyc.dto.Statistic.SticMonRes;
import com.whyc.factory.BattCapFactory;
import com.whyc.mapper.BattInfMapper;
import com.whyc.mapper.BatttestdataInfMapper;
import com.whyc.pojo.db_batt_testdata.BatttestdataId;
import com.whyc.pojo.db_batt_testdata.BatttestdataInf;
import com.whyc.pojo.db_param.AppParam;
import com.whyc.pojo.db_ram_db.BattRtdata;
import com.whyc.pojo.db_ram_db.BattRtstate;
import com.whyc.pojo.db_station.BattInf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class BatttestdataInfService {
    @Autowired(required = false)
    private BatttestdataInfMapper mapper;
 
    @Autowired(required = false)
    private BattRtstateService rtstateService;
 
    @Autowired(required = false)
    private BattRtdataService rtdataService;
 
    @Autowired(required = false)
    private BattInfService battInfService;
 
    @Autowired(required = false)
    private BatttestdataIdService battTestdataIdService;
 
    @Autowired(required = false)
    private AppParamService appParamService;
 
 
 
 
    //获取最后一次测试数据并计算剩余容量
    public Float getLastTestDataRestCap(Integer battgroupId) {
        //获取放电记录
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("battgroup_id",battgroupId);
        wrapper.orderByDesc("test_starttime");
        wrapper.last("limit 1");
        BatttestdataInf tinf=mapper.selectOne(wrapper);
        if(tinf!=null){
            int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
            Float restcap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Rest);
            return restcap;
        }else{
            return 0f;
        }
    }
    //蓄电池核容信息统计
    public Response getBattTinfStatistic(BattTinfStic stic) {
        PageHelper.startPage(stic.getPageNum(), stic.getPageSize());
        List<BatttestdataInf> list=mapper.getBattTinfStatistic(stic);
        if(list!=null&&list.size()>0){
            for (BatttestdataInf tinf:list) {
                //剩余容量和剩余时间计算
                int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
                Float restCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Rest);
                Float realCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
                tinf.setRestCap(restCap);
                tinf.setRealCap(realCap);
                tinf.setRestTime(0f);
                //获取电池组实时数据
                BattRtstate battRtstate=rtstateService.getBattRealInfo(tinf.getBattgroupId());
                //获取电池组信息
                BattInf binf=battInfService.getBinfByBattgroupId(tinf.getBattgroupId());
                //实时组端电流,剩余容量,标称容量
                if(battRtstate!=null){
                    Float restTime= BattCapFactory.getTheoryTime(battRtstate.getGroupCurr(), restCap, binf.getMoncapstd());
                    tinf.setRestTime(restTime);
                }
                //保留5位小数
                String precentCap = String.format("%.5f",(restCap/binf.getMoncapstd()*100));
                tinf.setPrecentCap(precentCap);
            }
        }
 
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list.size()>0,pageInfo,"蓄电池核容信息统计");
    }
    //获取上一次标准核容信息(标准核容的界定为单测核容时间达 2小时及以上的核容测试)
    public BatttestdataInf getLastStandardTestData(Integer battgroupId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("battgroup_id", battgroupId);
        wrapper.eq("test_type", 3);
        wrapper.eq("test_starttype", 3);
        wrapper.last("  and test_timelong >= 7200 ORDER BY test_starttime DESC ");
        wrapper.last("limit 1");
        BatttestdataInf tinf = mapper.selectOne(wrapper);
        return tinf;
    }
    /*单节数量统计
      1筛选满足条件的电池组,找最近一次标准核容放电记录的最后一笔数据
      2再按照公式计算单体实际容量,
      3然后找到判断优秀,劣化,损坏的参数,得到结果。
      4浮充电压图,需要显示单体+实时数据的单体电压,单体内阻
    */
    public Response getMonStatistic(MonStic stic) {
        Map<String,Object> map=new HashMap<>();
        List<SticMonRes> goodlist=new ArrayList();
        List<SticMonRes> badlist=new ArrayList();
        List<SticMonRes> damagelist=new ArrayList();
        map.put("goodlist",goodlist);
        map.put("badlist",badlist);
        map.put("damagelist",damagelist);
        map.put("goodlistNum",0);
        map.put("badlistNum",0);
        map.put("damagelistNum",0);
        //获取核容优劣,损坏参数
        List<AppParam> paramList=appParamService.getHrParam();
        Float badValue=0f;
        Float damageValue=0f;
        if(paramList!=null){
            for (AppParam param:paramList) {
                if(param.getParamNamePsx().equals("batt_mon_deteriorate_val")){
                    badValue=param.getParamValue();
                }
                if(param.getParamNamePsx().equals("batt_mon_damage_val")){
                    damageValue=param.getParamValue();
                }
 
            }
        }
        List<BattInf> binfList=battInfService.getMonStatistic(stic);
        Float realCap=0f;
        if(binfList==null){
           return new Response().set(1,false,"当前用户未管理满足条件的电池组");
        }
        for (BattInf binf:binfList) {
            BatttestdataInf tinf =getLastStandardTestData(binf.getBattgroupId());
            if(tinf==null){
                //将不满足条件的电池组的所有单体放入damage中
                setDamage(damagelist,binf);
                continue;
            }
            //找这次放电的最后一笔数据
            List<BatttestdataId> idDataList=battTestdataIdService.getLastDataByBattgroupId(tinf.getBattgroupId(),tinf.getTestRecordCount(),tinf.getRecordNum());
            if(idDataList==null||idDataList.size()==0){
                //将不满足条件的电池组的所有单体放入damage中
                setDamage(damagelist,binf);
                continue;
            }
            int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
            Float moncapStd=binf.getMoncapstd();
            for (BatttestdataId data:idDataList) {//求单体的 实际容量,最小值就是单体的单体电压
                realCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(),data.getMonVol() , tinf.getGroupVol(), BattCapFactory.CapType_Real);
                SticMonRes res=new SticMonRes();
                res.setBattgroupId(binf.getBattgroupId());
                res.setBattgroupName(binf.getBattgroupName());
                res.setMonNum(data.getMonNum());
                //获取单体的实时数据
                BattRtdata rtdata=rtdataService.getRtdataByNum(binf.getBattgroupId(),data.getMonNum());
                if(rtdata==null){
                    res.setMonVol(0f);
                    res.setMonRes(0f);
                }else{
                    res.setMonVol(rtdata.getMonVol());
                    res.setMonRes(rtdata.getMonRes());
                }
                if(realCap>=moncapStd*badValue){
                    goodlist.add(res);
                }
                if(realCap<=moncapStd*damageValue){
                    damagelist.add(res);
                }
                if((realCap>moncapStd*damageValue)&&(realCap<moncapStd*badValue)){
                    badlist.add(res);
                }
            }
        }
        map.put("goodlist",goodlist);
        map.put("badlist",badlist);
        map.put("damagelist",damagelist);
        map.put("goodlistNum",goodlist.size());
        map.put("badlistNum",badlist.size());
        map.put("damagelistNum",damagelist.size());
        return new Response().setII(1,true,map,"单节数量统计");
    }
    //将不满足条件的电池组的所有单体放入damage中
    private void setDamage(List damagelist, BattInf binf) {
        //获取电池组的实时数据
        List<BattRtdata> rtdataList=rtdataService.getRtdataRealInfo(binf.getBattgroupId());
        if(rtdataList==null||rtdataList.size()==0){
            for (int i=0;i<binf.getMoncount();i++){
                SticMonRes res=new SticMonRes();
                res.setBattgroupId(binf.getBattgroupId());
                res.setBattgroupName(binf.getBattgroupName());
                res.setMonNum(i+1);
                res.setMonVol(0f);
                res.setMonRes(0f);
                damagelist.add(res);
            }
        }else {
            for (BattRtdata rtdata:rtdataList) {
                SticMonRes res=new SticMonRes();
                res.setBattgroupId(binf.getBattgroupId());
                res.setBattgroupName(binf.getBattgroupName());
                res.setMonNum(rtdata.getMonNum());
                res.setMonVol(rtdata.getMonVol());
                res.setMonRes(rtdata.getMonRes());
                damagelist.add(res);
            }
        }
    }
}