whycxzp
2025-05-28 5826c5028d061efb0c2c8c7eeaf31a9bca535d7a
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whyc.dto.Response;
import com.whyc.mapper.BattLithiumTestDataMapper;
import com.whyc.mapper.BattLithiumTestDataInfMapper;
import com.whyc.pojo.db_lithium_testdata.BattLithiumTestData;
import com.whyc.pojo.db_lithium_testdata.BattLithiumTestDataInf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
@Service
public class BattLithiumTestDataInfService {
 
    @Autowired(required = false)
    private BattLithiumTestDataInfMapper mapper;
 
    @Autowired(required = false)
    private BattLithiumTestDataMapper dataMapper;
 
    @Autowired(required = false)
    private SubTablePageInfoService subService;
 
    //充放电一体机测试统计
    public Map<String, Object> getDevTinfByYearMonth(int userId) {
        Map<String,Object> map=new HashMap<>();
        //本年
        List<BattLithiumTestDataInf> listYear=mapper.getDevTinfByYear(userId);
 
        Map<String,Object> a200Map=new HashMap<>();
        Map<String,Object> actmMap=new HashMap<>();
 
        Map<Integer,Integer> a200YearMap=new HashMap<>();
        a200YearMap.put(2,0);
        a200YearMap.put(3,0);
        Map<Integer,Integer> actmYearMap=new HashMap<>();
        actmYearMap.put(2,0);
        actmYearMap.put(3,0);
        actmYearMap.put(4,0);
        //本年
        Map<Integer, List<BattLithiumTestDataInf>> typeMapY = listYear.stream().collect(Collectors.groupingBy(BattLithiumTestDataInf::getDevType));
 
        for (Integer type : typeMapY.keySet()) {
            List<BattLithiumTestDataInf> list=typeMapY.get(type);
            Map<Integer, List<BattLithiumTestDataInf>> testMapY = list.stream().collect(Collectors.groupingBy(BattLithiumTestDataInf::getTestType));
            for (Integer test : testMapY.keySet()) {
                if(type==1){
                    a200YearMap.put(test, testMapY.get(test).size());
                }
                if(type==2){
                    actmYearMap.put(test, testMapY.get(test).size());
                }
 
            }
        }
        a200Map.put("a200YearMap",a200YearMap);
        actmMap.put("actmYearMap",actmYearMap);
 
        //本月
        Map<Integer,Integer> a200MonthMap=new HashMap<>();
        a200MonthMap.put(2,0);
        a200MonthMap.put(3,0);
        Map<Integer,Integer> actmMonthMap=new HashMap<>();
        actmMonthMap.put(2,0);
        actmMonthMap.put(3,0);
        actmMonthMap.put(4,0);
        List<BattLithiumTestDataInf> listMonth=mapper.getDevTinfByMonth(userId);
        Map<Integer, List<BattLithiumTestDataInf>> typeMapM = listMonth.stream().collect(Collectors.groupingBy(BattLithiumTestDataInf::getDevType));
        for (Integer type : typeMapM.keySet()) {
            List<BattLithiumTestDataInf> list=typeMapM.get(type);
            Map<Integer, List<BattLithiumTestDataInf>> testMapM = list.stream().collect(Collectors.groupingBy(BattLithiumTestDataInf::getTestType));
            for (Integer test : testMapM.keySet()) {
                if(type==1){
                    a200MonthMap.put(test, testMapM.get(test).size());
                }
                if(type==2){
                    actmMonthMap.put(test, testMapM.get(test).size());
                }
 
            }
        }
        a200Map.put("a200MonthMap",a200MonthMap);
        actmMap.put("actmMonthMap",actmMonthMap);
 
        map.put("a200Map",a200Map);
        map.put("actmMap",actmMap);
        return map;
    }
    //近一周电池测试趋势统计(从当前时间开始)
    public Map<String, Object> getDevTinfByWeek(int userId) {
        Map<String,Object> map=new HashMap<>();
 
        Map<String,Object> a200dataMap=new HashMap<>();
        Map<String,Object> actmdataMap=new HashMap<>();
 
        Map<Integer,Integer> a200weekDateMap=new HashMap<>();
        a200weekDateMap.put(2,0);
        a200weekDateMap.put(3,0);
 
        Map<Integer,Integer> actmweekDataMap=new HashMap<>();
        actmweekDataMap.put(2,0);
        actmweekDataMap.put(3,0);
        actmweekDataMap.put(4,0);
 
        // 当前日期
        LocalDate today = LocalDate.now();
        for(int i=0;i<7;i++){
            LocalDate resultDate = today.minusDays(i);
            a200dataMap.put(resultDate.toString(),a200weekDateMap);
            actmdataMap.put(resultDate.toString(),actmweekDataMap);
        }
 
        List<BattLithiumTestDataInf> listW1=mapper.getDevTinfByWeek(userId,1);
        Map<String, List<BattLithiumTestDataInf>> typeMapW1 = listW1.stream().collect(Collectors.groupingBy(BattLithiumTestDataInf::getWeekDay));
        for (String day : typeMapW1.keySet()) {
            List<BattLithiumTestDataInf> list1=typeMapW1.get(day);
            Map<Integer, List<BattLithiumTestDataInf>> testMapM1 = list1.stream().collect(Collectors.groupingBy(BattLithiumTestDataInf::getTestType));
            //近一周a200
            Map<Integer,Integer> a200weekMap=new HashMap<>();
            a200weekMap.put(2,0);
            a200weekMap.put(3,0);
            for (Integer test : testMapM1.keySet()) {
                a200weekMap.put(test, testMapM1.get(test).size());
            }
            a200dataMap.put(day,a200weekMap);
        }
 
        List<BattLithiumTestDataInf> listW2=mapper.getDevTinfByWeek(userId,2);
        Map<String, List<BattLithiumTestDataInf>> typeMapW2= listW2.stream().collect(Collectors.groupingBy(BattLithiumTestDataInf::getWeekDay));
        for (String day : typeMapW2.keySet()) {
            List<BattLithiumTestDataInf> list2=typeMapW2.get(day);
            Map<Integer, List<BattLithiumTestDataInf>> testMapM2 = list2.stream().collect(Collectors.groupingBy(BattLithiumTestDataInf::getTestType));
            //近一周actm
            Map<Integer,Integer> actmweekMap=new HashMap<>();
            actmweekMap.put(2,0);
            actmweekMap.put(3,0);
            actmweekMap.put(4,0);
            for (Integer test : testMapM2.keySet()) {
                actmweekMap.put(test, testMapM2.get(test).size());
            }
            actmdataMap.put(day,actmweekMap);
        }
        map.put("a200",a200dataMap);
        map.put("actm",actmdataMap);
        return map;
    }
   //获取设备的充放电记录
    public Response getTinfById(Integer devId) {
        Map<String,Object> map=new HashMap<>();
        //获取充放电数据
        List<BattLithiumTestDataInf> listDis=mapper.getTinfById(3,devId);
        List<BattLithiumTestDataInf> listChr=mapper.getTinfById(2,devId);
        map.put("dis",listDis);
        map.put("chr",listChr);
        if(devId/100000000==2){
            List<BattLithiumTestDataInf> listJun=mapper.getTinfById(4,devId);
            map.put("jun",listJun);
        }
 
        return new Response().setII(1,true,map,"获取设备的充放电记录");
    }
    //获取设备某次记录详细的单体放电过程
    public Response getTdataById(Integer devId, Integer testRecordCount) {
        List<BattLithiumTestData> list=subService.getTdataByIdWithListA200(devId,testRecordCount);
 
        return new Response().setII(1,list!=null,list,null);
    }
    //获取放电inf
    public BattLithiumTestDataInf getTinfExport(Integer devId, Integer testRecordCount) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("dev_id",devId);
        wrapper.eq("test_record_count",testRecordCount);
        wrapper.last("limit 1");
        BattLithiumTestDataInf tinf=mapper.selectOne(wrapper);
        return  tinf;
    }
}