whyclxw
2025-05-29 3f2c786d82463b073eb8ba83553fdcc67131cb89
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
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.factory.BattCapFactory;
import com.whyc.mapper.BattInfMapper;
import com.whyc.mapper.BatttestdataInfMapper;
import com.whyc.pojo.db_batt_testdata.BatttestdataInf;
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.List;
 
@Service
public class BatttestdataInfService {
    @Autowired(required = false)
    private BatttestdataInfMapper mapper;
 
    @Autowired(required = false)
    private BattRtstateService rtstateService;
 
    @Autowired(required = false)
    private BattInfService battInfService;
 
 
    //获取最后一次测试数据并计算剩余容量
    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);
                tinf.setRestCap(restCap);
                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("data_available", 1);
        wrapper.eq("test_type", 3);
        wrapper.eq("test_starttype", 3);
        wrapper.last("limit 1");
        wrapper.last("  and test_timelong >= 7200 ORDER BY test_starttime DESC ");
        BatttestdataInf tinf = mapper.selectOne(wrapper);
        return tinf;
    }
}