| | |
| | | package com.whyc.service; |
| | | |
| | | import com.whyc.dto.Real.CompareDto; |
| | | import com.whyc.dto.Real.QuarterDto; |
| | | import com.whyc.dto.Real.*; |
| | | import com.whyc.dto.RealDataStatic.ResRealDataAc; |
| | | import com.whyc.dto.RealDataStatic.ResRealDataMon; |
| | | import com.whyc.dto.RealDataStatic.SticRealDataAc; |
| | | import com.whyc.dto.RealDataStatic.SticRealDataBatt; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.factory.ThreadPoolExecutorFactory; |
| | | import com.whyc.mapper.CommonMapper; |
| | | |
| | | import com.whyc.pojo.db_data_history.BattRealdataId; |
| | | import com.whyc.pojo.db_param.AlmAnalysisParam; |
| | | import com.whyc.pojo.db_param.AppParam; |
| | | import com.whyc.pojo.db_param.PowerheartParam; |
| | | import com.whyc.pojo.db_ram_db.BattRtstate; |
| | | import com.whyc.pojo.db_station.BattInf; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.DateUtil; |
| | | import com.whyc.util.ThreadLocalUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.text.ParseException; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.concurrent.CountDownLatch; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static java.lang.Thread.sleep; |
| | | |
| | | @Service |
| | | public class BattRealdataIdService { |
| | |
| | | @Resource |
| | | private CommonMapper commonMapper; |
| | | |
| | | @Autowired |
| | | private BattresdataInfService resInfService; |
| | | |
| | | @Autowired |
| | | private BattInfService binfService; |
| | | |
| | | @Autowired(required = false) |
| | | private BattRtstateService rtstateService; |
| | | |
| | | @Autowired |
| | | private PowerheartParamService heartService; |
| | | |
| | | |
| | | |
| | | //获取电池组最近一季度的单体数据 |
| | | public Response getBattQuarter(Integer battgroupId) { |
| | | public Response getBattQuarterVol(Integer battgroupId) { |
| | | HashMap<String,Object> map = new HashMap<>(); |
| | | Float maxVol=0f; |
| | | Float minVol=0f; |
| | | Float avgVol=0f; |
| | | Float maxData=0f; |
| | | Float minData=0f; |
| | | Float avgData=0f; |
| | | int num=0; |
| | | List<String> datelist = ActionUtil.getLastQuarterYearMonths(); |
| | | for (int i=0;i<datelist.size();i++) { |
| | |
| | | //获取表中最大,最小,平均数据值 |
| | | CompareDto compareData=subTablePageInfoService.getBattCompareHis(tableName,"mon_vol"); |
| | | if(num==0){ |
| | | maxVol=compareData.getMaxData(); |
| | | minVol=compareData.getMinData(); |
| | | maxData=compareData.getMaxData(); |
| | | minData=compareData.getMinData(); |
| | | } |
| | | if (compareData.getMaxData() >= maxVol) { |
| | | maxVol =compareData.getMaxData(); |
| | | if (compareData.getMaxData() >= maxData) { |
| | | maxData =compareData.getMaxData(); |
| | | } |
| | | if (compareData.getMinData() <= minVol) { |
| | | minVol = compareData.getMinData(); |
| | | if (compareData.getMinData() <= minData) { |
| | | minData= compareData.getMinData(); |
| | | } |
| | | avgVol += compareData.getAvgData(); |
| | | map.put("maxVol",maxVol); |
| | | map.put("minVol",minVol); |
| | | map.put("avgVol",avgVol/datelist.size()); |
| | | avgData+= compareData.getAvgData(); |
| | | map.put("maxData",maxData); |
| | | map.put("minData",minData); |
| | | map.put("avgData",avgData/datelist.size()); |
| | | num++; |
| | | } |
| | | return new Response().setII(1,map.size()>0,map,"获取电池组最近一季度的数据"); |
| | | return new Response().setII(1,map.size()>0,map,"获取电池组最近一季度的电压数据"); |
| | | } |
| | | //获取电池组最近一季度的内阻数据 |
| | | public Response getBattQuarterRes(Integer battgroupId) { |
| | | HashMap<String,Object> map = new HashMap<>(); |
| | | Float maxData=0f; |
| | | Float minData=0f; |
| | | Float avgData=0f; |
| | | int num=0; |
| | | List<String> datelist = ActionUtil.getLastQuarterYearMonths(); |
| | | //获取内阻初始数据(第一次内阻测试的第一笔数据) |
| | | List<QuarterDto> list=resInfService.getFirstResData(battgroupId); |
| | | if(list==null){//当初始值为0时使用标称内阻 |
| | | list=binfService.getBinfResStd(battgroupId); |
| | | } |
| | | map.put("startRes",list); |
| | | for (int i=0;i<datelist.size();i++) { |
| | | String date=datelist.get(i); |
| | | String tableName ="db_data_history.tb_batt_realdata_"+battgroupId+"_"+date; |
| | | String existTableName = commonMapper.existTable("db_data_history", "tb_batt_realdata_"+battgroupId+"_"+date); |
| | | if(existTableName == null){ |
| | | continue; |
| | | } |
| | | //判断表是否存在 |
| | | List<QuarterDto> datalist=subTablePageInfoService.getBattRealHis(tableName,"mon_res"); |
| | | map.put(date,datalist); |
| | | //获取表中最大,最小,平均数据值 |
| | | CompareDto compareData=subTablePageInfoService.getBattCompareHis(tableName,"mon_res"); |
| | | if(num==0){ |
| | | maxData=compareData.getMaxData(); |
| | | minData=compareData.getMinData(); |
| | | } |
| | | if (compareData.getMaxData() >= maxData) { |
| | | maxData =compareData.getMaxData(); |
| | | } |
| | | if (compareData.getMinData() <= minData) { |
| | | minData= compareData.getMinData(); |
| | | } |
| | | avgData+= compareData.getAvgData(); |
| | | map.put("maxData",maxData); |
| | | map.put("minData",minData); |
| | | map.put("avgData",avgData/datelist.size()); |
| | | num++; |
| | | } |
| | | return new Response().setII(1,map.size()>0,map,"获取电池组最近一季度的内阻数据"); |
| | | } |
| | | //获取电池组最近一季度的温度数据 |
| | | public Response getBattQuarterTmp(Integer battgroupId) { |
| | | HashMap<String,Object> map = new HashMap<>(); |
| | | Float maxData=0f; |
| | | Float minData=0f; |
| | | Float avgData=0f; |
| | | int num=0; |
| | | List<String> datelist = ActionUtil.getLastQuarterYearMonths(); |
| | | for (int i=0;i<datelist.size();i++) { |
| | | String date=datelist.get(i); |
| | | String tableName ="db_data_history.tb_batt_realdata_"+battgroupId+"_"+date; |
| | | String existTableName = commonMapper.existTable("db_data_history", "tb_batt_realdata_"+battgroupId+"_"+date); |
| | | //判断表是否存在 |
| | | if(existTableName == null){ |
| | | continue; |
| | | } |
| | | List<QuarterDto> datalist=subTablePageInfoService.getBattRealHis(tableName,"mon_tmp"); |
| | | map.put(date,datalist); |
| | | //获取表中最大,最小,平均数据值 |
| | | CompareDto compareData=subTablePageInfoService.getBattCompareHis(tableName,"mon_tmp"); |
| | | if(num==0){ |
| | | maxData=compareData.getMaxData(); |
| | | minData=compareData.getMinData(); |
| | | } |
| | | if (compareData.getMaxData() >= maxData) { |
| | | maxData =compareData.getMaxData(); |
| | | } |
| | | if (compareData.getMinData() <= minData) { |
| | | minData= compareData.getMinData(); |
| | | } |
| | | avgData+= compareData.getAvgData(); |
| | | map.put("maxData",maxData); |
| | | map.put("minData",minData); |
| | | map.put("avgData",avgData/datelist.size()); |
| | | num++; |
| | | } |
| | | return new Response().setII(1,map.size()>0,map,"获取电池组最近一季度的温度数据"); |
| | | } |
| | | //系统概览获取前N笔核容设备信息 |
| | | public Response getBattDevData100(Integer powerId,Integer battgroupId) throws ParseException, InterruptedException { |
| | | //获取前笔数*时间间隔 |
| | | PowerheartParam heartParam=heartService.getHeartParamByPowerId(powerId); |
| | | Integer interverCount=100*10;//默认值 |
| | | Integer granularity=5;//默认值 |
| | | if(heartParam!=null){ |
| | | interverCount=heartParam.getHrInterverCfg()*heartParam.getHrCountCfg(); |
| | | granularity=heartParam.getHrInterverCfg(); |
| | | } |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | String dateTime = now.format(formatter); |
| | | Date endTime=ActionUtil.sdf.parse(dateTime); |
| | | // 计算笔数*时间间隔的时间点 |
| | | LocalDateTime halfHourAgo = now.minusMinutes(interverCount); |
| | | // 格式化输出 |
| | | String halfHourAgoTime=halfHourAgo.format(formatter); |
| | | Date startTime=ActionUtil.sdf.parse(halfHourAgoTime); |
| | | List<List<Date>> monthTimeList = DateUtil.getMonthTime(startTime,endTime); |
| | | List<RealDateDTO> dataList = new LinkedList<>(); |
| | | ThreadPoolExecutor pool = ThreadPoolExecutorFactory.getPoolExecutor(); |
| | | CountDownLatch latch = new CountDownLatch(monthTimeList.size()); |
| | | for (int i = 0; i < monthTimeList.size(); i++) { |
| | | int finalI = i; |
| | | Integer finalGranularity = granularity; |
| | | pool.execute(() -> { |
| | | int finalII = finalI; |
| | | Date recordDatetime=monthTimeList.get(finalII).get(0); |
| | | Date recordDatetime1=monthTimeList.get(finalII).get(1); |
| | | String table = battgroupId + "_" + ThreadLocalUtil.format(recordDatetime,2); |
| | | String tableName="db_data_history.tb_batt_realdata_"+table; |
| | | //判断表是否存在 |
| | | int tableNum = subTablePageInfoService.judgeTable_realdata(table); |
| | | List<RealDateDTO> list = new ArrayList(); |
| | | if (tableNum > 0) { |
| | | //获取指定时间段内最大最小recordNum确保数据的完整 |
| | | List recordNums= subTablePageInfoService.getBattMaxAndMinRecordNum(tableName,recordDatetime,recordDatetime1); |
| | | Integer maxRecordNum= 0; |
| | | Integer minRecordNum= 0; |
| | | if(recordNums.size()>0){ |
| | | maxRecordNum=(Integer)recordNums.get(0); |
| | | minRecordNum=(Integer)recordNums.get(1); |
| | | } |
| | | list = subTablePageInfoService.getBattDevData100(tableName, finalGranularity,recordDatetime,recordDatetime1,maxRecordNum,minRecordNum); |
| | | } |
| | | dataList.addAll(list); |
| | | latch.countDown(); |
| | | }); |
| | | sleep(200); |
| | | } |
| | | latch.await(10, TimeUnit.MINUTES); |
| | | List dataListSorted = dataList.stream().sorted(Comparator.comparing(RealDateDTO::getRecordTime)).collect(Collectors.toList()); |
| | | return new Response().setII(1,dataList.size()>0,dataListSorted,"获取半小时内核容设备信息"); |
| | | } |
| | | //历史实时数据 |
| | | public Response getBattRealDataHis(Integer battgroupId, Integer granularity,String startTime,String endTime) throws ParseException, InterruptedException { |
| | | Map<String,Object> map=new HashMap<>(); |
| | | //实时获取电池组信息 |
| | | BattRtstate battRtstate = rtstateService.getBattRealInfo(battgroupId); |
| | | //获取电池组信息 |
| | | BattInf binf = binfService.getBinfByBattgroupId(battgroupId); |
| | | map.put("标称容量",binf.getMoncapstd()); |
| | | map.put("蓄电池数量",binf.getMoncount()); |
| | | map.put("标称电压",binf.getMonvolstd()); |
| | | map.put("浮充电压",battRtstate.getGroupVol()); |
| | | |
| | | List<RealDateDTO> dataList = new LinkedList<>(); |
| | | List<List<Date>> monthTimeList = DateUtil.getMonthTime(ThreadLocalUtil.parse(startTime,1), ThreadLocalUtil.parse(endTime,1)); |
| | | ThreadPoolExecutor pool = ThreadPoolExecutorFactory.getPoolExecutor(); |
| | | CountDownLatch latch = new CountDownLatch(monthTimeList.size()); |
| | | for (int i = 0; i < monthTimeList.size(); i++) { |
| | | int finalI = i; |
| | | pool.execute(() -> { |
| | | int finalII = finalI; |
| | | BattRealdataId realdata = new BattRealdataId(); |
| | | realdata.setRecordTime(monthTimeList.get(finalII).get(0)); |
| | | realdata.setRecordTime1(monthTimeList.get(finalII).get(1)); |
| | | String table = battgroupId + "_" + ThreadLocalUtil.format(realdata.getRecordTime(),2); |
| | | String tableName="db_data_history.tb_batt_realdata_"+table; |
| | | realdata.setTableName(table);//表名时间格式部分 |
| | | //判断表是否存在 |
| | | int tableNum = subTablePageInfoService.judgeTable_realdata(table); |
| | | List<RealDateDTO> list = new ArrayList(); |
| | | if (tableNum > 0) { |
| | | //获取指定时间段内最大最小recordNum确保数据的完整 |
| | | List recordNums= subTablePageInfoService.getBattMaxAndMinRecordNum(tableName,realdata.getRecordTime(),realdata.getRecordTime1()); |
| | | Integer maxRecordNum= 0; |
| | | Integer minRecordNum= 0; |
| | | if(recordNums.size()>0){ |
| | | maxRecordNum=(Integer)recordNums.get(0); |
| | | minRecordNum=(Integer)recordNums.get(1); |
| | | } |
| | | list = subTablePageInfoService.getBattRealDataHis(realdata,granularity,maxRecordNum,minRecordNum); |
| | | } |
| | | dataList.addAll(list); |
| | | latch.countDown(); |
| | | }); |
| | | sleep(200); |
| | | } |
| | | latch.await(10, TimeUnit.MINUTES); |
| | | List dataListSorted = dataList.stream().sorted(Comparator.comparing(RealDateDTO::getRecordTime)).collect(Collectors.toList()); |
| | | return new Response().setIII(1, dataListSorted!=null,dataListSorted,map,"历史实时查询"); |
| | | } |
| | | //实时数据统计曲线--核容设备 |
| | | public Response getSticRealHrData(SticRealDataAc stic) throws ParseException, InterruptedException { |
| | | Integer granularity=5;//默认值 |
| | | Map<String,Date> startAndEndTime=DateUtil.getStartAndEndTime(stic.getSticTime()); |
| | | //获取两个时间分割多少张表 |
| | | List<List<Date>> monthTimeList = DateUtil.getMonthTime(startAndEndTime.get("startTime"),startAndEndTime.get("endTime")); |
| | | List<ResRealDataAc> dataList = new LinkedList<>(); |
| | | Map<String, Map<String,List<String>>> allTimeMap=new HashMap<>(); |
| | | ThreadPoolExecutor pool = ThreadPoolExecutorFactory.getPoolExecutor(); |
| | | CountDownLatch latch = new CountDownLatch(monthTimeList.size()); |
| | | for (int i = 0; i < monthTimeList.size(); i++) { |
| | | int finalI = i; |
| | | Integer finalGranularity = granularity; |
| | | Map<String,List<String>> propertyInfo=stic.getPropertyInfo(); |
| | | pool.execute(() -> { |
| | | int finalII = finalI; |
| | | Date recordDatetime=monthTimeList.get(finalII).get(0); |
| | | Date recordDatetime1=monthTimeList.get(finalII).get(1); |
| | | String timeTable=ThreadLocalUtil.format(recordDatetime,2); |
| | | String table = stic.getBattgroupId() + "_" + timeTable; |
| | | String tableName="db_data_history.tb_batt_realdata_"+table; |
| | | //判断表是否存在 |
| | | int tableNum = subTablePageInfoService.judgeTable_realdata(table); |
| | | List<ResRealDataAc> list = new ArrayList(); |
| | | Map<String,List<String>> timeMap=new HashMap<>(); |
| | | if (tableNum > 0) { |
| | | //获取指定时间段内最大最小recordNum确保数据的完整 |
| | | List recordNums= subTablePageInfoService.getBattMaxAndMinRecordNum(tableName,recordDatetime,recordDatetime1); |
| | | Integer maxRecordNum= 0; |
| | | Integer minRecordNum= 0; |
| | | if(recordNums.size()>0){ |
| | | maxRecordNum=(Integer)recordNums.get(0); |
| | | minRecordNum=(Integer)recordNums.get(1); |
| | | } |
| | | list = subTablePageInfoService.getSticRealHrData(tableName, finalGranularity,recordDatetime,recordDatetime1,maxRecordNum,minRecordNum,propertyInfo); |
| | | //所有属性的异动点 |
| | | List<Integer> allChangeNums=new ArrayList<>(); |
| | | //获取指定时间取出每个参数的异动次数和异动的recordNum |
| | | for (Map.Entry<String, List<String>> entry : propertyInfo.entrySet()) { |
| | | String param = entry.getKey(); |
| | | List<String> valueList = entry.getValue(); |
| | | for (String value : valueList) { |
| | | float upperLimit=550; |
| | | float lowerLimit=50; |
| | | //查询电源字段的异动 |
| | | List changes= subTablePageInfoService.getBattChangesRecordNum(tableName,recordDatetime,recordDatetime1,value,upperLimit,lowerLimit); |
| | | List<Integer> numList= (List<Integer>) changes.get(0);//record_num的集合 |
| | | List<String> timeList= (List<String>) changes.get(1);//record_datetime的集合 |
| | | if(numList!=null&&numList.size()>0){ |
| | | allChangeNums.addAll(numList); |
| | | } |
| | | //存放每个参数的异动时间点 |
| | | timeMap.put(value,timeList); |
| | | } |
| | | } |
| | | //只有存在异动点采取查询异动数据 |
| | | if(allChangeNums.size()>0){ |
| | | //查询大类参数下所有异动recordNum的记录之和 |
| | | List<ResRealDataAc> paramList=subTablePageInfoService.getBattPropertyChangesByRecordNum(tableName,recordDatetime,recordDatetime1,allChangeNums,propertyInfo); |
| | | list.addAll(paramList); |
| | | } |
| | | } |
| | | allTimeMap.put(timeTable,timeMap); |
| | | dataList.addAll(list); |
| | | latch.countDown(); |
| | | }); |
| | | sleep(200); |
| | | } |
| | | latch.await(10, TimeUnit.MINUTES); |
| | | List<ResRealDataAc> uniqueList = dataList.stream() |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | List dataListSorted = uniqueList.stream().sorted(Comparator.comparing(ResRealDataAc::getRecordNum)).collect(Collectors.toList()); |
| | | //所有异动点合并去重 |
| | | Map<String, List<String>> mergedMap =ActionUtil.getMergeMap(allTimeMap); |
| | | return new Response().setIII(1,dataList.size()>0,dataListSorted,mergedMap,"实时数据统计曲线--核容设备"); |
| | | } |
| | | //蓄电池组 |
| | | public Response getSticRealMonData(SticRealDataBatt stic) throws ParseException, InterruptedException { |
| | | Integer granularity=2;//默认值 |
| | | Map<String,Date> startAndEndTime=DateUtil.getStartAndEndTime(stic.getSticTime()); |
| | | //获取两个时间分割多少张表 |
| | | List<List<Date>> monthTimeList = DateUtil.getMonthTime(startAndEndTime.get("startTime"),startAndEndTime.get("endTime")); |
| | | List<ResRealDataMon> dataList = new LinkedList<>(); |
| | | Map<String, Map<String,List<String>>> allTimeMap=new HashMap<>(); |
| | | ThreadPoolExecutor pool = ThreadPoolExecutorFactory.getPoolExecutor(); |
| | | CountDownLatch latch = new CountDownLatch(monthTimeList.size()); |
| | | for (int i = 0; i < monthTimeList.size(); i++) { |
| | | int finalI = i; |
| | | Integer finalGranularity = granularity; |
| | | List<String> propertyList=stic.getPropertyList(); |
| | | pool.execute(() -> { |
| | | int finalII = finalI; |
| | | Date recordDatetime=monthTimeList.get(finalII).get(0); |
| | | Date recordDatetime1=monthTimeList.get(finalII).get(1); |
| | | String timeTable=ThreadLocalUtil.format(recordDatetime,2); |
| | | String table = stic.getBattgroupId() + "_" + timeTable; |
| | | String tableName="db_data_history.tb_batt_realdata_"+table; |
| | | //判断表是否存在 |
| | | int tableNum = subTablePageInfoService.judgeTable_realdata(table); |
| | | List<ResRealDataMon> list = new ArrayList(); |
| | | Map<String,List<String>> timeMap=new HashMap<>(); |
| | | if (tableNum > 0) { |
| | | //获取指定时间段内最大最小recordNum确保数据的完整 |
| | | List recordNums= subTablePageInfoService.getBattMaxAndMinRecordNum(tableName,recordDatetime,recordDatetime1); |
| | | Integer maxRecordNum= 0; |
| | | Integer minRecordNum= 0; |
| | | if(recordNums.size()>0){ |
| | | maxRecordNum=(Integer)recordNums.get(0); |
| | | minRecordNum=(Integer)recordNums.get(1); |
| | | } |
| | | list = subTablePageInfoService.getSticRealMonData(tableName, finalGranularity,recordDatetime,recordDatetime1,maxRecordNum,minRecordNum); |
| | | //所有属性的异动点 |
| | | List<Integer> allChangeNums=new ArrayList<>(); |
| | | if(propertyList!=null){ |
| | | for (String value:propertyList) { |
| | | //获取指定时间取出每个参数的异动次数和异动的recordNum |
| | | float upperLimit=3.5f; |
| | | float lowerLimit=2.0f; |
| | | //查询电源字段的异动 |
| | | List changes= subTablePageInfoService.getBattChangesRecordNum(tableName,recordDatetime,recordDatetime1,value,upperLimit,lowerLimit); |
| | | List<Integer> numList= (List<Integer>) changes.get(0);//record_num的集合 |
| | | if(numList!=null&&numList.size()>0){ |
| | | allChangeNums.addAll(numList); |
| | | } |
| | | List<String> timeList= (List<String>) changes.get(1);//record_datetime的集合 |
| | | //存放每个参数的异动时间点 |
| | | timeMap.put(value,timeList); |
| | | } |
| | | } |
| | | //只有存在异动点采取查询异动数据 |
| | | if(allChangeNums.size()>0){ |
| | | //查询大类参数下所有异动recordNum的记录之和 |
| | | List<ResRealDataMon> paramList=subTablePageInfoService.getMonPropertyChangesByRecordNum(tableName,recordDatetime,recordDatetime1,allChangeNums); |
| | | list.addAll(paramList); |
| | | } |
| | | } |
| | | allTimeMap.put(timeTable,timeMap); |
| | | dataList.addAll(list); |
| | | latch.countDown(); |
| | | }); |
| | | sleep(200); |
| | | } |
| | | latch.await(10, TimeUnit.MINUTES); |
| | | List<ResRealDataMon> uniqueList = dataList.stream() |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | List dataListSorted = uniqueList.stream().sorted(Comparator.comparing(ResRealDataMon::getRecordNum)).collect(Collectors.toList()); |
| | | //所有异动点合并去重 |
| | | Map<String, List<String>> mergedMap =ActionUtil.getMergeMap(allTimeMap); |
| | | return new Response().setIII(1,dataList.size()>0,dataListSorted,mergedMap,"实时数据统计曲线--蓄电池组"); |
| | | } |
| | | } |