whyclxw
5 天以前 8c635598000e40edfb3edf5934124ad48d60f62d
src/main/java/com/whyc/service/BattRealdataIdService.java
@@ -9,6 +9,11 @@
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;
@@ -40,6 +45,13 @@
    @Autowired
    private BattInfService binfService;
    @Autowired(required = false)
    private BattRtstateService rtstateService;
    @Autowired
    private PowerheartParamService heartService;
    //获取电池组最近一季度的单体数据
@@ -162,14 +174,22 @@
        }
        return new Response().setII(1,map.size()>0,map,"获取电池组最近一季度的温度数据");
    }
    //系统概览获取半小时核容设备信息
    public Response getHalfHourBattDevData(Integer battgroupId,Integer granularity) {
    //系统概览获取前N笔核容设备信息
    public Response getBattDevData100(Integer powerId,Integer battgroupId) {
        String dateTime = ActionUtil.sdfwithOutday.format(new Date());
        String tableName ="db_data_history.tb_batt_realdata_"+battgroupId+"_"+dateTime;
        //获取前笔数*时间间隔
        PowerheartParam heartParam=heartService.getHeartParamByPowerId(powerId);
        Integer interverCount=100*10;//默认值
        Integer granularity=10;//默认值
        if(heartParam!=null){
            interverCount=heartParam.getAcinInterverCfg()*heartParam.getAcinCountCfg();
            granularity=heartParam.getAcinInterverCfg();
        }
        //获取前半个小时数据
        LocalDateTime now = LocalDateTime.now();
        // 计算半小时前的时间点
        LocalDateTime halfHourAgo = now.minusMinutes(30);
        LocalDateTime halfHourAgo = now.minusMinutes(interverCount);
        // 格式化输出
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String halfHourAgoTime=halfHourAgo.format(formatter);
@@ -182,6 +202,16 @@
    }
    //历史实时数据
    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();
@@ -216,37 +246,6 @@
        }
        latch.await(10, TimeUnit.MINUTES);
        List dataListSorted = dataList.stream().sorted(Comparator.comparing(RealDateDTO::getRecordTime)).collect(Collectors.toList());
        return new Response().set(1, dataListSorted);
    }
    //电池告警点击具体告警信息查看从告警开始时间到现在的历史实时数据
    public Response getBattHisRealInAlm(Integer battgroupId, String startTime, Integer almId) throws ParseException, InterruptedException {
        List<RealDateDTO> dataList = new LinkedList<>();
        List<List<Date>> monthTimeList = DateUtil.getMonthTime(ThreadLocalUtil.parse(startTime,1),new Date());
        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);
                realdata.setTableName(table);//表名时间格式部分
                //判断表是否存在
                int tableNum = subTablePageInfoService.judgeTable_realdata(table);
                List<RealDateDTO> list = new ArrayList();
                if (tableNum > 0) {
                    list = subTablePageInfoService.getBattHisRealInAlm(realdata);
                }
                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().set(1, dataListSorted);
        return new Response().setIII(1, dataListSorted!=null,dataListSorted,map,"历史实时查询");
    }
}