package com.whyc.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.BatttestdataIdMapper;
|
import com.whyc.mapper.BatttestdataInfMapper;
|
import com.whyc.pojo.db_batt_testdata.BatttestdataId;
|
import com.whyc.pojo.db_batt_testdata.BatttestdataInf;
|
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 BatttestdataInfService {
|
|
@Autowired(required = false)
|
private BatttestdataInfMapper mapper;
|
|
@Autowired(required = false)
|
private BatttestdataIdMapper dataMapper;
|
|
@Autowired(required = false)
|
private SubTablePageInfoService subService;
|
|
//充放电一体机测试统计
|
public Map<String, Object> getDevTinfByYearMonth(int userId) {
|
Map<String,Object> map=new HashMap<>();
|
//本年
|
List<BatttestdataInf> 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<BatttestdataInf>> typeMapY = listYear.stream().collect(Collectors.groupingBy(BatttestdataInf::getDevType));
|
|
for (Integer type : typeMapY.keySet()) {
|
List<BatttestdataInf> list=typeMapY.get(type);
|
Map<Integer, List<BatttestdataInf>> testMapY = list.stream().collect(Collectors.groupingBy(BatttestdataInf::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<BatttestdataInf> listMonth=mapper.getDevTinfByMonth(userId);
|
Map<Integer, List<BatttestdataInf>> typeMapM = listMonth.stream().collect(Collectors.groupingBy(BatttestdataInf::getDevType));
|
for (Integer type : typeMapM.keySet()) {
|
List<BatttestdataInf> list=typeMapM.get(type);
|
Map<Integer, List<BatttestdataInf>> testMapM = list.stream().collect(Collectors.groupingBy(BatttestdataInf::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<BatttestdataInf> listW1=mapper.getDevTinfByWeek(userId,1);
|
Map<String, List<BatttestdataInf>> typeMapW1 = listW1.stream().collect(Collectors.groupingBy(BatttestdataInf::getWeekDay));
|
for (String day : typeMapW1.keySet()) {
|
List<BatttestdataInf> list1=typeMapW1.get(day);
|
Map<Integer, List<BatttestdataInf>> testMapM1 = list1.stream().collect(Collectors.groupingBy(BatttestdataInf::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<BatttestdataInf> listW2=mapper.getDevTinfByWeek(userId,2);
|
Map<String, List<BatttestdataInf>> typeMapW2= listW2.stream().collect(Collectors.groupingBy(BatttestdataInf::getWeekDay));
|
for (String day : typeMapW2.keySet()) {
|
List<BatttestdataInf> list2=typeMapW2.get(day);
|
Map<Integer, List<BatttestdataInf>> testMapM2 = list2.stream().collect(Collectors.groupingBy(BatttestdataInf::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<BatttestdataInf> listDis=mapper.getTinfById(3,devId);
|
List<BatttestdataInf> listChr=mapper.getTinfById(2,devId);
|
map.put("dis",listDis);
|
map.put("chr",listChr);
|
if(devId/100000000==2){
|
List<BatttestdataInf> listJun=mapper.getTinfById(4,devId);
|
map.put("jun",listJun);
|
}
|
|
return new Response().setII(1,true,map,"获取设备的充放电记录");
|
}
|
//获取设备某次记录详细的单体放电过程
|
public Response getTdataById(Integer devId, Integer testRecordCount) {
|
List<BatttestdataId> list=subService.getTdataById(devId,testRecordCount);
|
|
return new Response().setII(1,list!=null,list,"获取设备某次记录详细的单体放电过程");
|
}
|
//获取放电inf
|
public BatttestdataInf getTinfExport(Integer devId, Integer testRecordCount) {
|
QueryWrapper wrapper=new QueryWrapper();
|
wrapper.eq("dev_id",devId);
|
wrapper.eq("test_record_count",testRecordCount);
|
wrapper.last("limit 1");
|
BatttestdataInf tinf=mapper.selectOne(wrapper);
|
return tinf;
|
}
|
}
|