package com.whyc.service;
|
|
import com.github.pagehelper.PageInfo;
|
import com.whyc.dto.BreakAlarmDto;
|
import com.whyc.dto.DevAlarmHisDto;
|
import com.whyc.dto.Response;
|
import com.whyc.factory.ThreadPoolExecutorFactory;
|
import com.whyc.pojo.db_ckpwrdev_alarm.CKPowerDevAlarmHistory;
|
import com.whyc.pojo.db_ckpwrdev_break_alarm.CKPowerDevBreakAlarmHistory;
|
import com.whyc.util.SubTablePageInfoUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.text.ParseException;
|
import java.util.*;
|
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class CKPowerDevBreakAlarmHistoryService {
|
@Autowired
|
private SubTablePageInfoUtils subTablePageInfoUtils;
|
|
@Autowired
|
private SubTablePageInfoService subTablePageInfoService;
|
|
|
|
public Response getPage(BreakAlarmDto alarmDto) throws ParseException {
|
Integer pageNum = alarmDto.getPageNum();
|
Integer pageSize = alarmDto.getPageSize();
|
Date almStartTime = alarmDto.getAlmStarttime();
|
Date almEndTime = alarmDto.getAlmStarttime1();
|
PageInfo<Object> pageInfo = subTablePageInfoUtils.getPageInfo(pageNum, pageSize, almStartTime, almEndTime,
|
"db_ckpwrdev_break_alarm", "tb_ckpowerdev_break_alarm_history", alarmDto);
|
return new Response<>().setII(1, pageInfo, null, "返回结果");
|
}
|
//历史头部统计
|
public Response getCountByLevel() throws InterruptedException {
|
Map<String,Integer> countMap = new HashMap<>();
|
countMap.put("0",0);
|
countMap.put("1",0);
|
countMap.put("2",0);
|
countMap.put("3",0);
|
List<CKPowerDevBreakAlarmHistory> allList=new ArrayList<>();
|
//查询所有的历史时间表
|
List<String> tableYearListInDB=subTablePageInfoService.getBreakAlmHisList();
|
//多线程读取
|
ThreadPoolExecutor pool = ThreadPoolExecutorFactory.getPoolExecutor();
|
CountDownLatch latch = new CountDownLatch(tableYearListInDB.size());
|
for (String tableYear : tableYearListInDB) {
|
pool.execute(()-> {
|
List<CKPowerDevBreakAlarmHistory> hisList = subTablePageInfoService.selectBreakLevelCountList(tableYear);
|
allList.addAll(hisList);
|
latch.countDown();
|
});
|
}
|
latch.await();
|
countMap.put("0",allList.size());
|
Map<Integer, List<CKPowerDevBreakAlarmHistory>> levelMap = allList.stream().collect(Collectors.groupingBy(CKPowerDevBreakAlarmHistory::getAlmLevel));
|
Set<Integer> levelKeyMap = levelMap.keySet();
|
for (Integer level : levelKeyMap) {
|
countMap.put(level.toString(),levelMap.get(level).size());
|
}
|
return new Response().set(1,countMap);
|
}
|
}
|