| | |
| | | package com.whyc.service; |
| | | |
| | | import com.whyc.dto.BatteryInfo; |
| | | import com.whyc.dto.DataAnalysisFloatDTO; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.BatteryDataMapper; |
| | | import com.whyc.mapper.BatteryResDataMapper; |
| | | import com.whyc.mapper.BatteryTestDataMapper; |
| | | import com.whyc.constant.AlarmConstant; |
| | | import com.whyc.dto.*; |
| | | import com.whyc.mapper.*; |
| | | import com.whyc.pojo.BatteryEndurance; |
| | | import com.whyc.pojo.BatteryRTState; |
| | | import com.whyc.pojo.Tables; |
| | | import com.whyc.util.BattCapFactory; |
| | | import com.whyc.util.MathUtil; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.text.DecimalFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class BatteryDataService { |
| | |
| | | @Resource |
| | | private BatteryTestDataMapper testDataMapper; |
| | | |
| | | @Resource |
| | | private AnalysisMonFieldMapper monFieldMapper; |
| | | |
| | | @Resource |
| | | private DBMapper dbMapper; |
| | | |
| | | public Response getEndurance(Integer userId) { |
| | | List<BatteryEndurance> enduranceList = mapper.endurance(userId); |
| | | List<Integer> times = Arrays.asList(1, 2, 3); |
| | | List<Integer> times = Arrays.asList(1, 2, 3,5,8); |
| | | Map resultMap = enduranceAnalysis(enduranceList,times); |
| | | return new Response<Map>().set(1,resultMap); |
| | | } |
| | | |
| | | /**按时间阶段统计续航*/ |
| | | private static Map enduranceAnalysis(List<BatteryEndurance> enduranceList, List<Integer> times) { |
| | | Map<String,Integer> map = new HashMap<>(); |
| | | Map<String,Integer> map = new LinkedHashMap<>(); |
| | | |
| | | //初始化续航分类 |
| | | for (int i = 0; i < times.size(); i++) { |
| | | if(i ==0 ){ |
| | | map.put("续航"+times.get(0)+"小时内",0); |
| | | } |
| | | else if(i == times.size()-1){ |
| | | map.put("续航"+times.get(i-1)+"小时到"+times.get(i)+"小时",0); |
| | | map.put("续航"+times.get(times.size()-1)+"小时以上",0); |
| | | }else { |
| | | map.put("续航" + times.get(i-1) + "小时到" + times.get(i) + "小时", 0); |
| | | } |
| | | } |
| | | |
| | | for (int i = 0; i < enduranceList.size(); i++) { |
| | | //每一个具体的续航进行分组 |
| | | if(enduranceList.get(i).getEnduranceActualTime()<times.get(0)){ |
| | | if(enduranceList.get(i).getEnduranceActualTime()<times.get(0)*60){ |
| | | map.put("续航"+times.get(0)+"小时内",Optional.ofNullable(map.get("续航"+times.get(0)+"小时内")).orElse(0)+1); |
| | | } |
| | | else if(enduranceList.get(i).getEnduranceActualTime()>times.get(times.size()-1)){ |
| | | else if(enduranceList.get(i).getEnduranceActualTime()>times.get(times.size()-1)*60){ |
| | | map.put("续航"+times.get(times.size()-1)+"小时以上",Optional.ofNullable(map.get("续航"+times.get(times.size()-1)+"小时以上")).orElse(0)+1); |
| | | }else { |
| | | for (int j = 0; j < times.size(); j++) { |
| | | if (enduranceList.get(i).getEnduranceActualTime() <= times.get(j)) { |
| | | if (enduranceList.get(i).getEnduranceActualTime() <= times.get(j)*60) { |
| | | map.put("续航" + times.get(j - 1) + "小时到" + times.get(j) + "小时", Optional.ofNullable(map.get("续航" + times.get(j - 1) + "小时到" + times.get(j) + "小时")).orElse(0) + 1); |
| | | break; |
| | | } |
| | |
| | | return maps; |
| | | } |
| | | |
| | | /** |
| | | * 落后单体统计,统计各种类型所占比例: |
| | | * 容量告警:单体容量告警 |
| | | * 容量更换:单体容量更换 |
| | | * 总电池单体-上面两种:单体容量健康 |
| | | */ |
| | | public Response getMonCapStatus(Integer userId) { |
| | | //初始化 单体容量健康 单体容量告警 单体容量更换 和 map |
| | | Map<String,Integer> monCapMap = new HashMap(); |
| | | Integer monCapGood = 0; |
| | | Integer monCapAlarm = 0; |
| | | Integer monCapChange = 0; |
| | | |
| | | //查询用户管理的总单体数 |
| | | Integer totalMonNum = mapper.getTotalMonNum(userId); |
| | | //查询用户管理的落后单体数 |
| | | List<BadBattMonDTO> list = mapper.getBadMonOfCapAlarm(userId); |
| | | |
| | | if(!list.isEmpty()) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | //容量告警 |
| | | if (list.get(i).getNote() == AlarmConstant.Alarm_CapAlarm) { |
| | | monCapAlarm = list.get(i).getNum(); |
| | | } |
| | | //容量更换 |
| | | else { |
| | | monCapChange = list.get(i).getNum(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | monCapGood = totalMonNum - monCapAlarm -monCapChange ; |
| | | monCapMap.put("单体容量健康",monCapGood); |
| | | monCapMap.put("单体容量告警",monCapAlarm); |
| | | monCapMap.put("单体容量更换",monCapChange); |
| | | return new Response().set(1,monCapMap); |
| | | } |
| | | |
| | | /**单体信息统计*/ |
| | | public List<AnalysisMonFieldDTO> monFieldStatistics(String filedName, String fieldName2) { |
| | | //查询所有的电池组 |
| | | List<Tables> tables = dbMapper.getTableNames("db_batt_testdata", "tb_batttestdata\\_[1-9]+"); |
| | | List<String> tableNames = new LinkedList<>(); |
| | | tables.forEach(tableName -> { |
| | | tableNames.add(tableName.getTableName()); |
| | | }); |
| | | //查询每个电池组的单体字段数据 |
| | | List<AnalysisMonFieldDTO> list = testDataMapper.getStatisticsByTableNames(tableNames,filedName,fieldName2); |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /**单体内阻统计*/ |
| | | public List<AnalysisMonFieldDTO> monResStatistics() { |
| | | //查询所有的电池组 |
| | | List<Tables> tables = dbMapper.getTableNames("db_batt_testdata", "tb_battresdata\\_[1-9]+"); |
| | | List<String> tableNames = new LinkedList<>(); |
| | | tables.forEach(tableName -> { |
| | | tableNames.add(tableName.getTableName()); |
| | | }); |
| | | //查询每个电池组的单体字段数据 |
| | | List<AnalysisMonFieldDTO> list = resMapper.getResStatisticsByTableNames(tableNames); |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /**单体容量统计*/ |
| | | public List<AnalysisMonFieldDTO> monCapStatistics() { |
| | | List<AnalysisMonFieldDTO> analysisMonFieldList = new LinkedList<>(); |
| | | //查询所有的stop表 |
| | | List<Tables> tables = dbMapper.getTableNames("db_batt_testdata","tb_batttestdatastop*"); |
| | | List<String> groupIds = new LinkedList<>(); |
| | | tables.forEach(tableName -> { |
| | | groupIds.add(tableName.getTableName().split("_")[2]); |
| | | }); |
| | | //查询每个电池组的单体字段数据,同时要查询出来标准字段,以此来计算每个单体的容量 |
| | | List<AnalysisMonCapDTO> analysisMonCapDTOs = testDataMapper.getCapStatisticsByGroupIds(groupIds); |
| | | Map<Integer, List<AnalysisMonCapDTO>> analysisCapMap = analysisMonCapDTOs.stream().collect(Collectors.groupingBy(AnalysisMonCapDTO::getBattGroupId)); |
| | | //遍历每个电池组,获取统计数据 |
| | | for(Map.Entry<Integer,List<AnalysisMonCapDTO>> entry : analysisCapMap.entrySet()){ |
| | | AnalysisMonFieldDTO analysisMonField = new AnalysisMonFieldDTO(); |
| | | double minCap = 0d; |
| | | double maxCap = 0d; |
| | | double avgCap = 0d; |
| | | double realCap = 0d; |
| | | double capSum = 0d; |
| | | int size =0; |
| | | |
| | | Integer battGroupId = entry.getKey(); |
| | | List<AnalysisMonCapDTO> capDTOList = entry.getValue(); |
| | | //执行容量统计 |
| | | for (AnalysisMonCapDTO monCapDTO : capDTOList){ |
| | | //if(monCapDTO.getMonVol()>monCapDTO.getMonVolStd()*0.9f){ |
| | | int hourRate=BattCapFactory.GetHourRate(monCapDTO.getMonCapStd(),monCapDTO.getTestCurr()); |
| | | realCap = BattCapFactory.GetMonomerCap(monCapDTO.getMonCapStd(),hourRate,monCapDTO.getTestCap(),monCapDTO.getMaxMonVol(), |
| | | monCapDTO.getMonVol(),monCapDTO.getMonVolStd(),BattCapFactory.CapType_Real); |
| | | /*}else{ |
| | | //查询电池测试表中对应的测试批次的单体剩余容量 |
| | | realCap = Math.abs(testDataMapper.getRestCapByCondition(monCapDTO)); |
| | | }*/ |
| | | if(realCap<minCap){ |
| | | minCap = realCap; |
| | | } |
| | | if(realCap>maxCap){ |
| | | maxCap=realCap; |
| | | } |
| | | capSum+=realCap; |
| | | size++; |
| | | } |
| | | |
| | | avgCap = capSum/size; |
| | | |
| | | analysisMonField.setBattGroupId(battGroupId); |
| | | analysisMonField.setBattGroupName(capDTOList.get(0).getBattGroupName()); |
| | | analysisMonField.setStationName(capDTOList.get(0).getStationName()); |
| | | analysisMonField.setMinMonCap(minCap); |
| | | analysisMonField.setMaxMonCap(maxCap); |
| | | analysisMonField.setAvgMonCap(avgCap); |
| | | //将统计数据放到数组中 |
| | | analysisMonFieldList.add(analysisMonField); |
| | | } |
| | | |
| | | return analysisMonFieldList; |
| | | } |
| | | |
| | | public Response getMonVol(Integer userId) { |
| | | HashMap<String, Object> resMap = new HashMap<>(); |
| | | List<BatteryInfo> batteryInfos = testDataMapper.getStationAndBatteryGroupIds(userId); |
| | | /*List<BatteryInfo> batteryInfos = testDataMapper.getStationAndBatteryGroupIds(userId); |
| | | for (BatteryInfo temp:batteryInfos) { |
| | | //根据BattGroupIds查询到对应的数值 |
| | | String[] batteryGroupIds = temp.getBatteryGroupIds().split(","); |
| | |
| | | } |
| | | DataAnalysisFloatDTO dataStatistics = testDataMapper.getStatisticsByBattGroupIds(ids,"mon_vol"); |
| | | resMap.put(temp.getStationName(),dataStatistics); |
| | | } |
| | | return new Response<>().set(1,resMap); |
| | | }*/ |
| | | |
| | | //查询单体电压数据 |
| | | List<AnalysisMonFieldDTO> monFields = monFieldMapper.getMonField("tb_mon_vol",userId); |
| | | |
| | | return new Response<>().set(1,monFields); |
| | | } |
| | | |
| | | public Response getMonTemp(Integer userId) { |
| | | HashMap<String, Object> resMap = new HashMap<>(); |
| | | List<BatteryInfo> batteryInfos = testDataMapper.getStationAndBatteryGroupIds(userId); |
| | | /*List<BatteryInfo> batteryInfos = testDataMapper.getStationAndBatteryGroupIds(userId); |
| | | for (BatteryInfo temp:batteryInfos) { |
| | | //根据BattGroupIds查询到对应的数值 |
| | | String[] batteryGroupIds = temp.getBatteryGroupIds().split(","); |
| | |
| | | } |
| | | DataAnalysisFloatDTO dataStatistics = testDataMapper.getStatisticsByBattGroupIds(ids,"mon_tmp"); |
| | | resMap.put(temp.getStationName(),dataStatistics); |
| | | } |
| | | return new Response<>().set(1,resMap); |
| | | }*/ |
| | | |
| | | //查询单体温度数据 |
| | | List<AnalysisMonFieldDTO> monFields = monFieldMapper.getMonField("tb_mon_tmp",userId); |
| | | |
| | | |
| | | return new Response<>().set(1,monFields); |
| | | } |
| | | |
| | | public Response getMonRes(Integer userId) { |
| | | HashMap<String, Object> resMap = new HashMap<>(); |
| | | List<BatteryInfo> batteryInfos = resMapper.getResStationAndBatteryGroupIds(userId); |
| | | /*List<BatteryInfo> batteryInfos = resMapper.getResStationAndBatteryGroupIds(userId); |
| | | for (BatteryInfo temp:batteryInfos) { |
| | | //根据BattGroupIds查询到对应的数值 |
| | | String[] batteryGroupIds = temp.getBatteryGroupIds().split(","); |
| | |
| | | } |
| | | DataAnalysisFloatDTO dataStatistics = resMapper.getResStatisticsByBattGroupIds(ids); |
| | | resMap.put(temp.getStationName(),dataStatistics); |
| | | } |
| | | return new Response<>().set(1,resMap); |
| | | }*/ |
| | | |
| | | //查询单体内阻数据 |
| | | List<AnalysisMonFieldDTO> monFields = monFieldMapper.getMonField("tb_mon_res",userId); |
| | | |
| | | return new Response<>().set(1,monFields); |
| | | } |
| | | |
| | | public Response getMonCap(Integer userId) { |
| | | HashMap<String, Object> resMap = new HashMap<>(); |
| | | /*HashMap<String, Object> resMap = new HashMap<>(); |
| | | List<BatteryInfo> batteryInfos = testDataMapper.getStationAndBatteryGroupIds(userId); |
| | | for (BatteryInfo temp:batteryInfos) { |
| | | String[] batteryGroupIds = temp.getBatteryGroupIds().split(","); |
| | |
| | | |
| | | List<Double> minMonCapList =new LinkedList<>(); |
| | | List<Double> maxMonCapList =new LinkedList<>(); |
| | | List<Double> avgMonCapList =new LinkedList<>(); |
| | | |
| | | for(BatteryInfo monData:batteryStatisticList){ |
| | | //求每个单体容量的最值 |
| | | //获取最小单体实际容量 |
| | | for (int i = 0; i < batteryStdList.size(); i++) { |
| | | if(batteryStdList.get(i).getBatteryGroupId()==monData.getBatteryGroupId()){ |
| | | if(batteryStdList.get(i).getBatteryGroupId().intValue()==monData.getBatteryGroupId()){ |
| | | |
| | | int hourRateMin = BattCapFactory.GetHourRate(batteryStdList.get(i).getMonCapStd(), monData.getMinTestCurr()); |
| | | double monRealCapMin = BattCapFactory.GetMonomerCap(batteryStdList.get(i).getMonCapStd(), hourRateMin, monData.getMinTestCap(), monData.getMaxMonVol(), monData.getMinMonVol(), batteryStdList.get(i).getMonVolStd(), BattCapFactory.CapType_Real); |
| | |
| | | avgMonCap=Double.parseDouble(decimalFormat.format(avgMonCap)); |
| | | |
| | | //单体容量 |
| | | /*minCapList.add(minMonCap); |
| | | maxCapList.add(maxMonCap); |
| | | averageCapList.add(avgMonCap);*/ |
| | | minMonCapList.add(minMonCap); |
| | | maxMonCapList.add(maxMonCap); |
| | | avgMonCapList.add(avgMonCap); |
| | | |
| | | List<List> capList = new LinkedList<>(); |
| | | capList.add(minMonCapList); |
| | | capList.add(maxMonCapList); |
| | | capList.add(avgMonCapList); |
| | | |
| | | resMap.put(temp.getStationName(),null); |
| | | } |
| | | return new Response<>().set(1,resMap); |
| | | resMap.put(temp.getStationName(),capList); |
| | | }*/ |
| | | //return new Response<>().set(1,resMap); |
| | | |
| | | //查询单体电压数据 |
| | | List<AnalysisMonFieldDTO> monFields = monFieldMapper.getMonField("tb_mon_cap",userId); |
| | | |
| | | return new Response<>().set(1,monFields); |
| | | |
| | | } |
| | | |
| | |
| | | Map map = enduranceAnalysis(batteryEnduranceList, timeList); |
| | | |
| | | } |
| | | |
| | | } |