whyclxw
2 天以前 f998f917f90d86499bf8a24c8912e270655e4d43
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whyc.dto.Real.QuarterDto;
import com.whyc.dto.Response;
import com.whyc.dto.Statistic.ComPareChangeCurve;
import com.whyc.dto.Statistic.ComPareChart;
import com.whyc.mapper.BattresdataInfMapper;
import com.whyc.mapper.CommonMapper;
import com.whyc.pojo.db_batt_testdata.BattresdataId;
import com.whyc.pojo.db_batt_testdata.BattresdataInf;
import com.whyc.pojo.db_station.BattInf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.*;
 
@Service
public class BattresdataInfService {
    @Autowired(required = false)
    private BattresdataInfMapper mapper;
 
    @Autowired(required = false)
    private SubTablePageInfoService  subTablePageInfoService;
 
    @Resource
    private CommonMapper commonMapper;
 
    //上一次内阻测试数据
    public BattresdataInf getLastTestData(Integer battgroupId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("battgroup_id", battgroupId);
        wrapper.last(" limit 1");
        wrapper.last(" ORDER BY test_starttime DESC ");
        BattresdataInf rinf = mapper.selectOne(wrapper);
        return rinf;
    }
    //获取内阻初始数据(第一次内阻测试的第一笔数据)
    public List<QuarterDto> getFirstResData(Integer battgroupId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("battgroup_id", battgroupId);
        wrapper.last(" limit 1");
        wrapper.last(" ORDER BY test_record_count asc ");
        BattresdataInf rinf = mapper.selectOne(wrapper);
        if(rinf!=null){
            String existTableName = commonMapper.existTable("db_batt_testdata", "tb_battresdata_"+battgroupId);
            if(existTableName != null){
                List<QuarterDto> list=subTablePageInfoService.getBattResInfData(battgroupId,rinf.getTestRecordCount());
                return list;
            }
        }
        return null;
    }
 
    //蓄电池对比分析右侧最高单体内阻数据(最新一次内阻测试)
    public ComPareChart getMaxResData(BattInf binf) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("battgroup_id", binf.getBattgroupId());
        wrapper.last(" limit 1");
        wrapper.last(" ORDER BY test_starttime desc ");
        BattresdataInf rinf = mapper.selectOne(wrapper);
        ComPareChart chart=new ComPareChart();
        chart.setBattgroupName(binf.getBattgroupName());
        chart.setBattgroupId(binf.getBattgroupId());
        chart.setValue(0f);
        chart.setMonNum(1);
        if(rinf!=null){
            String existTableName = commonMapper.existTable("db_batt_testdata", "tb_battresdata_"+binf.getBattgroupId());
            if(existTableName != null){
                //取内阻测试的最大内阻和单体编号
                List<QuarterDto> list=subTablePageInfoService.getMaxResInInfData(binf.getBattgroupId(),rinf.getTestRecordCount());
                if(list!=null&&list.size()>0){
                    Map<String, Object> map =list.stream()
                            .max(Comparator.comparing(QuarterDto::getNumValue))
                            .map(dto -> {
                                Map<String, Object> result = new HashMap<>();
                                result.put("maxNumValue", dto.getNumValue());
                                result.put("monNum", dto.getMonNum());
                                return result;
                            })
                            .orElse(Collections.emptyMap());
                    chart.setBattgroupId(binf.getBattgroupId());
                    chart.setBattgroupName(binf.getBattgroupName());
                    chart.setValue(Float.parseFloat(map.get("maxNumValue").toString()));
                    chart.setMonNum(Integer.parseInt(map.get("monNum").toString()));
                }
            }
        }
        return chart;
    }
    //点击右侧折线图画出电池组单体的所有内阻测试单体内阻变化图(1.2.15/16/17)
    public Response getMonResChangeByBattgroupId(Integer battgroupId, Integer monNum) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("battgroup_id", battgroupId);
        wrapper.last(" ORDER BY test_starttime asc ");
        List<BattresdataInf> list = mapper.selectList(wrapper);
        List<ComPareChangeCurve> curvelist=new ArrayList<>();
        for (BattresdataInf rinf:list) {
            String existTableName = commonMapper.existTable("db_batt_testdata", "tb_battresdata_"+battgroupId);
            if(existTableName != null){
                //取内阻测试指定单体的单体电压
                ComPareChangeCurve curve=subTablePageInfoService.getMonResChangeByBattgroupId(battgroupId,rinf.getTestRecordCount(),monNum);
                if(curve!=null){
                    curvelist.add(curve);
                }
            }
        }
        return new Response().setII(1,list.size()>0,curvelist,"点击右侧折线图画出电池组单体的所有内阻测试单体内阻变化图(1.2.15/16/17)");
    }
}