whycxzp
2025-04-14 8e85ad8e022d2885c410d0654bce08e2a392b08f
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.BattCapFactory;
import com.whyc.dto.ReportBattDTO;
import com.whyc.dto.Response;
import com.whyc.mapper.AlarmParamMapper;
import com.whyc.mapper.BattAlarmMapper;
import com.whyc.mapper.BattInfMapper;
import com.whyc.mapper.BattTestInfMapper;
import com.whyc.pojo.*;
import com.whyc.pojo.db_batt.BattInf;
import com.whyc.pojo.db_dis_batt.BattTestInf;
import com.whyc.util.ActionUtil;
import com.whyc.util.PageInfoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
 
import java.util.*;
 
@Service
public class BattTestInfService {
    @Autowired(required = false)
    private BattTestInfMapper mapper;
 
    @Autowired(required = false)
    private BattInfMapper binfMapper;
 
    @Autowired(required = false)
    private AlarmParamMapper alarmParamMapper;
 
    @Autowired(required = false)
    private BattAlarmMapper alarmMapper;
 
    @Autowired(required = false)
    private SubTableService subTableService;
 
 
    //查询充放电记录
    public Response getPageByBattGroupId(int battGroupId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        QueryWrapper wrapper = Wrappers.query();
        wrapper.eq("binf_id", battGroupId);
        List<BattTestInf> list = mapper.selectList(wrapper);
        PageInfo pageInfo = new PageInfo(list);
        return new Response().set(1, pageInfo);
    }
 
    public Response getDischargePage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<BattTestInf> list =mapper.getDischargeList();
        PageInfo pageInfo = new PageInfo(list);
        return new Response().set(1, pageInfo);
    }
 
    /*
    //1.4电池性能评估
    public Response searchGroupAssess(int pageNum, int pageSize, ReportBattDTO tinf, int userId){
        //List<BattInf> battinfList = binfMapper.searchGroupAssess(tinf, userId);
        List<BattInf> battinfList = binfMapper.searchGroupAssess();
        List<Map> result = new ArrayList<>();
        Integer assess = tinf.getAssess();//性能筛选
        Integer wj = tinf.getWj();//往年还是本年
        Integer statictype= tinf.getStatictype();//统计方式
        if (assess == null) {
            assess = -1;
        }
        if (wj == null) {
            wj = -1;
        }
        if (battinfList != null && battinfList.size() > 0) {
            for (BattInf binf : battinfList) {
                Integer battGroupId = binf.getBinfId();
                Map<String, Object> map=new HashMap<>();
                Map<String, Object> batttestdataInfList = searchDischargeTest(battGroupId, binf.getMonCap(), binf.getMonVol(), tinf.getRecordStartTime(), tinf.getRecordEndTime(),wj);
                if(statictype==0){
                    //对每个电池组状态进行判断(容量+内阻)
                    map = getAssess2(binf, batttestdataInfList,assess);
                }else{
                    //对每个电池组状态进行判断(容量)
                    map = getAssess3(binf, batttestdataInfList,assess);
                }
                if (assess == -1) {
                    result.add(map);
                } else {
                    if (map.get("flag") == assess) {
                        result.add(map);
                    }
                }
            }
        }
        PageInfo pageInfo = PageInfoUtils.list2PageInfo(result, pageNum, pageSize);
        return new Response().set(1, pageInfo, "查询成功");
    }
 
    //1.4电池组性能评估(根据电池组id查询所有的放电记录求出放电总次数,最高历史容量,最低历史容量,平均容量,最新测试容量)
    public Map<String, Object> searchDischargeTest(Integer battGroupId, float monCapStd, float monVolStd, Date recordStartTime, Date recordEndTime, int wj) {
        List<BattTestInf> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        if(wj==0){//本年
            list=mapper.searchDischargeTest(battGroupId, recordStartTime, recordEndTime);
            if( list.size()==0){
                map.put("wj", "N");
            }else{
                map.put("wj", "J");
            }
        }else if(wj==1){//往年
            list = mapper.searchDischargeTest_WJ(battGroupId, recordStartTime);
            if( list.size()==0){
                map.put("wj", "N");
            }else{
                map.put("wj", "W");
            }
        }else if(wj==-1){//全部
            list=mapper.searchDischargeTest(battGroupId, recordStartTime, recordEndTime);
            if( list.size()==0){
                list = mapper.searchDischargeTest_WJ(battGroupId, recordStartTime);
                if( list.size()==0){
                    map.put("wj", "N");
                }else{
                    map.put("wj", "W");
                }
            }else{
                map.put("wj", "J");
            }
        }
        List<BattTestInf> testList = new LinkedList<>();
        int sum = 0;//总测试次数
        float cap = 0f;//实际容量
        float allCap = 0f;//总容量
        float maxCap = 0f;//最高容量
        float minCap = 10000f;//最低容量
        float avgCap = 0f;//平均容量
        float lastCap = 0f;//最近测试容量
        for (int i = 0; i < list.size(); i++) {
            BattTestInf binf = list.get(i);
            int hourRate = BattCapFactory.GetHourRate(monCapStd, binf.getTestCurr());
            cap = (float) BattCapFactory.GetMonomerCap(monCapStd, hourRate, binf.getTestCap(), binf.getMaxMonvol(), binf.getMinMonvol(), monVolStd, BattCapFactory.CapType_Real);
            binf.setRealCap(cap);
            testList.add(binf);
            if (sum == 0) {
                lastCap = cap;
            }
            if (maxCap <= cap) {
                maxCap = cap;//最大
            }
            if (minCap >= cap) {
                minCap = cap;//最小
            }
            allCap += cap;
            sum++;
        }
        if (sum != 0) {
            avgCap = allCap / sum;//平均容量
        } else {
            avgCap = 0;
            minCap = 0;
        }
        map.put("battGroupid", battGroupId);
        map.put("sum", sum);
        map.put("maxCap", maxCap);
        map.put("avgCap", avgCap);
        map.put("minCap", minCap);
        map.put("lastCap", lastCap);
        map.put("testList", testList);
        return map;
    }
 
    //筛选蓄电池组后评性能(2024。4.15修改)
    public Map<String, Object> getAssess2(BattInf binf, Map<String, Object> mapList,int assess) {
        Map<String, Object> map = new HashMap();
        map.put("battinf", binf);
        map.put("battTestDataInf", mapList);
        map.put("wj",mapList.get("wj"));
        //直接去集合第2个数(放电次数),第6个数(实际预估容量:最近一次核容的实际容量)
        int battGroupId = (int) mapList.get("battGroupid");
        int disNum = (int) mapList.get("sum");
        float realCap = (Float) mapList.get("lastCap");
        float monCapStd = binf.getMonCap();
        //0.查询劣化(告警)和损坏(更换)的阈值
        QueryWrapper<AlarmParam> alarmWrapper = new QueryWrapper();
        alarmWrapper.and(wrapper -> {
            return wrapper.eq("alm_name", "Batt_Alarm_Type_CapAlarm").or().eq("alm_name", "Batt_Alarm_Type_CapChange");
        });
        alarmWrapper.orderByAsc("alm_id");
        List<AlarmParam> paramList = alarmParamMapper.selectList(alarmWrapper);
        float capAlarm = 0f;
        float capChange = 0f;
        if (paramList != null && paramList.size() > 0) {
            capAlarm = paramList.get(0).getAlmLowCoe();//劣化参数0.8
            capChange = paramList.get(1).getAlmLowCoe();//损坏参数0.6
        } else {
            capAlarm = 0.8f;
            capChange = 0.6f;
        }
        //查询电池告警(内阻告警)
        List listALmRes = getAlm2(battGroupId);
        map.put("noDisAlmSH",listALmRes);
        //未放电:本年度未放电
        if( (disNum==0) ){
            map.put("flag",0);
        }
        //优秀:本年度已放电,且容量健康,无内阻告警(预告警(重要),告警(紧急))
        if( (disNum>0)&&(realCap > capAlarm * monCapStd)&&(listALmRes.size()<=0)){
            map.put("flag",1);
        }
 
        */
    /*劣化:本年度未放电,内阻告警(预告警(重要),告警(紧急))
     *容量小于劣化阈值,大于损坏阈值,内阻告警(预告警,告警)
     *     容量小于劣化阈值,内阻正常
     *     容量正常,内阻告警(预告警,告警)
     *//*
 
        if (((disNum==0)&&(listALmRes.size()>0))
                ||((disNum>0)&&(realCap <= capAlarm * monCapStd && realCap >= capChange * monCapStd)&&(listALmRes.size()>0))
                ||((disNum>0)&&(realCap <= capAlarm * monCapStd)&&(listALmRes.size()<=0))
                ||(disNum>0)&&(realCap > capAlarm * monCapStd)&&(listALmRes.size()>0)){
            if((assess==0)&&(disNum==0)){
                map.put("flag",0);
            }else{
                map.put("flag",2);
            }
        }
        //损坏:容量低,内阻告警
        if((disNum!=0)&&(realCap< capChange * monCapStd)&&(listALmRes.size()>0)){
            map.put("flag",3);
        }
        return map;
    }
    //查询电池告警(2024。4.15修改)
    */
    /*未放电:本年度未放电
     *优秀:本年度已放电,且容量健康,无内阻告警(预告警(重要),告警(紧急))
     *劣化:本年度未放电,内阻告警(预告警(重要),告警(紧急))
     *     容量小于劣化阈值,大于损坏阈值,内阻告警(预告警,告警)
     *     容量小于劣化阈值,内阻正常
     *     容量正常,内阻告警(预告警,告警)
     * 损坏:容量低,内阻告警
     * *//*
 
    private List getAlm2(Integer battGroupId) {
        List list = alarmMapper.getAlm2(battGroupId);
        return list;
    }
    //筛选蓄电池组后评性能(2024。4.15修改)
    public Map<String, Object> getAssess3(BattInf binf, Map<String, Object> mapList,int assess) {
        Map<String, Object> map = new HashMap();
        map.put("battinf", binf);
        map.put("battTestDataInf", mapList);
        map.put("wj", mapList.get("wj"));
        //直接去集合第2个数(放电次数),第6个数(实际预估容量:最近一次核容的实际容量)
        int battGroupId = (int) mapList.get("battGroupid");
        int disNum = (int) mapList.get("sum");
        float realCap = (Float) mapList.get("lastCap");
        float monCapStd = binf.getMonCap();
        //0.查询劣化(告警)和损坏(更换)的阈值
        QueryWrapper<AlarmParam> alarmWrapper = new QueryWrapper();
        alarmWrapper.and(wrapper -> {
            return wrapper.eq("alm_name", "Batt_Alarm_Type_CapAlarm").or().eq("alm_name", "Batt_Alarm_Type_CapChange");
        });
        alarmWrapper.orderByAsc("alm_id");
        List<AlarmParam> paramList = alarmParamMapper.selectList(alarmWrapper);
        float capAlarm = 0f;
        float capChange = 0f;
        if (paramList != null && paramList.size() > 0) {
            capAlarm = paramList.get(0).getAlmLowCoe();//劣化参数0.8
            capChange = paramList.get(1).getAlmLowCoe();//损坏参数0.6
        } else {
            capAlarm = 0.8f;
            capChange = 0.6f;
        }
        //未放电:本年度未放电
        if ((disNum == 0)) {
            map.put("flag", 0);
        }
        //优秀:本年度已放电,且容量健康)
        if ((disNum > 0) && (realCap > capAlarm * monCapStd)) {
            map.put("flag", 1);
        }
        */
    /*劣化:
     *容量小于劣化阈值,大于损坏阈值
     *//*
 
        if (((disNum > 0) && (realCap <= capAlarm * monCapStd && realCap >= capChange * monCapStd))) {
            map.put("flag", 2);
        }
        //损坏:容量低
        if ((disNum > 0) && (realCap < capChange * monCapStd)) {
            map.put("flag", 3);
        }
        return map;
    }
 
    //电池单体性能评估
    public Response searchMonNumAssess( int binfId,  int monNum) {
        //获取指定电池组信息
        QueryWrapper wrapper=Wrappers.query();
        wrapper.eq("binf_id",binfId);
        wrapper.last("limit 1");
        BattInf binf=binfMapper.selectOne(wrapper);
        Map<String, Object> map = new HashMap<>();
        //获取有效的放电记录
        List<BattTestInf> list=mapper.searchDischarge(binfId);
        float cap = 0f;//实际容量
        //取最近一笔数据
        BattTestInf  tinf=list.stream().findFirst().orElse((BattTestInf) ActionUtil.objeNull);
        if(tinf!=null){
            int hourRate = BattCapFactory.GetHourRate(binf.getMonCap(), tinf.getTestCurr());
            //取该单体最后一笔放电记录
            BattTestInfData tData=subTableService.getMonNumData(binfId,tinf.getTestRecordCount(),tinf.getRecordNum(),monNum);
            if(tData!=null){
                cap = (float) BattCapFactory.GetMonomerCap(binf.getMonCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tData.getMonVol(), binf.getMonVol(), BattCapFactory.CapType_Real);
 
            }
           }
        map.put("cap",cap);
        //评估单体
        return new Response().set(1, map, "查询成功");
    }
 
    }*/
}