lxw
2023-12-08 b98ff4a43a253467592e2e1d963500173dfc0a97
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
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<Integer,Integer> countMap = new HashMap<>();
        countMap.put(0,0);
        countMap.put(1,0);
        countMap.put(2,0);
        countMap.put(3,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,levelMap.get(level).size());
        }
        return new Response().set(1,countMap);
    }
}