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 getDevTinfByYearMonth(int userId) { Map map=new HashMap<>(); //本年 List listYear=mapper.getDevTinfByYear(userId); Map a200Map=new HashMap<>(); Map actmMap=new HashMap<>(); Map a200YearMap=new HashMap<>(); a200YearMap.put(2,0); a200YearMap.put(3,0); Map actmYearMap=new HashMap<>(); actmYearMap.put(2,0); actmYearMap.put(3,0); actmYearMap.put(4,0); //本年 Map> typeMapY = listYear.stream().collect(Collectors.groupingBy(BattLithiumTestDataInf::getDevType)); for (Integer type : typeMapY.keySet()) { List list=typeMapY.get(type); Map> 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 a200MonthMap=new HashMap<>(); a200MonthMap.put(2,0); a200MonthMap.put(3,0); Map actmMonthMap=new HashMap<>(); actmMonthMap.put(2,0); actmMonthMap.put(3,0); actmMonthMap.put(4,0); List listMonth=mapper.getDevTinfByMonth(userId); Map> typeMapM = listMonth.stream().collect(Collectors.groupingBy(BattLithiumTestDataInf::getDevType)); for (Integer type : typeMapM.keySet()) { List list=typeMapM.get(type); Map> 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 getDevTinfByWeek(int userId) { Map map=new HashMap<>(); Map a200dataMap=new HashMap<>(); Map actmdataMap=new HashMap<>(); Map a200weekDateMap=new HashMap<>(); a200weekDateMap.put(2,0); a200weekDateMap.put(3,0); Map 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 listW1=mapper.getDevTinfByWeek(userId,1); Map> typeMapW1 = listW1.stream().collect(Collectors.groupingBy(BattLithiumTestDataInf::getWeekDay)); for (String day : typeMapW1.keySet()) { List list1=typeMapW1.get(day); Map> testMapM1 = list1.stream().collect(Collectors.groupingBy(BattLithiumTestDataInf::getTestType)); //近一周a200 Map 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 listW2=mapper.getDevTinfByWeek(userId,2); Map> typeMapW2= listW2.stream().collect(Collectors.groupingBy(BattLithiumTestDataInf::getWeekDay)); for (String day : typeMapW2.keySet()) { List list2=typeMapW2.get(day); Map> testMapM2 = list2.stream().collect(Collectors.groupingBy(BattLithiumTestDataInf::getTestType)); //近一周actm Map 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 map=new HashMap<>(); //获取充放电数据 List listDis=mapper.getTinfById(3,devId); List listChr=mapper.getTinfById(2,devId); map.put("dis",listDis); map.put("chr",listChr); if(devId/100000000==2){ List listJun=mapper.getTinfById(4,devId); map.put("jun",listJun); } return new Response().setII(1,true,map,"获取设备的充放电记录"); } //获取设备某次记录详细的单体放电过程 public Response getTdataById(Integer devId, Integer testRecordCount) { List 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; } }