package com.whyc.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.whyc.dto.Real.QuarterDto;
|
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;
|
}
|
}
|