whyclxw
2024-01-17 71a7ca2daff23173fb6905ff562cf7a9830d5df0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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;
 
    @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);
    }
}