| | |
| | | package com.whyc.service; |
| | | |
| | | import ch.qos.logback.core.joran.action.ActionUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.DevAlarmHisDto; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.factory.ThreadPoolExecutorFactory; |
| | | import com.whyc.pojo.db_ckpwrdev_alarm.CKPowerDevAlarm; |
| | | import com.whyc.pojo.db_ckpwrdev_alarm.CKPowerDevAlarmHistory; |
| | | import com.whyc.util.DateUtil; |
| | | import com.whyc.util.SubTablePageInfoUtils; |
| | | import com.whyc.util.UserUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | 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 CKPowerDevAlarmHistoryService { |
| | | @Autowired |
| | | private SubTablePageInfoUtils subTablePageInfoUtils; |
| | | |
| | | public Response getPage(CKPowerDevAlarm alarm) { |
| | | return null; |
| | | @Autowired |
| | | private SubTablePageInfoService subTablePageInfoService; |
| | | |
| | | public Response getPage(DevAlarmHisDto 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_alarm", "tb_ckpowerdev_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); |
| | | countMap.put("ac",0); |
| | | countMap.put("dc",0); |
| | | countMap.put("gc",0); |
| | | List<CKPowerDevAlarmHistory> allList=new ArrayList<>(); |
| | | //查询所有的历史时间表 |
| | | List<String> tableYearListInDB=subTablePageInfoService.getDevAlmHisList(); |
| | | //多线程读取 |
| | | ThreadPoolExecutor pool = ThreadPoolExecutorFactory.getPoolExecutor(); |
| | | CountDownLatch latch = new CountDownLatch(tableYearListInDB.size()); |
| | | for (String tableYear : tableYearListInDB) { |
| | | pool.execute(()-> { |
| | | List<CKPowerDevAlarmHistory> hisList = subTablePageInfoService.selectLevelCountList(tableYear); |
| | | allList.addAll(hisList); |
| | | latch.countDown(); |
| | | }); |
| | | } |
| | | latch.await(); |
| | | countMap.put("0",allList.size()); |
| | | Map<Integer, List<CKPowerDevAlarmHistory>> levelMap = allList.stream().collect(Collectors.groupingBy(CKPowerDevAlarmHistory::getAlmLevel)); |
| | | Set<Integer> levelKeyMap = levelMap.keySet(); |
| | | for (Integer level : levelKeyMap) { |
| | | countMap.put(level.toString(),levelMap.get(level).size()); |
| | | } |
| | | Map<Integer, List<CKPowerDevAlarmHistory>> typeMap = allList.stream().collect(Collectors.groupingBy(CKPowerDevAlarmHistory::getDevType)); |
| | | Set<Integer> typeKeyMap = typeMap.keySet(); |
| | | for (Integer type : typeKeyMap) { |
| | | if(type==1){ |
| | | countMap.put("ac",levelMap.get(type).size()); |
| | | } |
| | | if(type==2){ |
| | | countMap.put("dc",levelMap.get(type).size()); |
| | | } |
| | | if(type==3){ |
| | | countMap.put("gc",levelMap.get(type).size()); |
| | | } |
| | | |
| | | } |
| | | return new Response().set(1,countMap); |
| | | } |
| | | } |