fuliqi
2024-10-15 c4d949d801ef6261741567ddbd7594631503ef82
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
package com.ycl.calculate;
 
 
import com.ycl.platform.domain.result.BaseResult;
import com.ycl.platform.domain.vo.TMonitorVO;
import com.ycl.platform.mapper.TMonitorMapper;
import constant.ApiConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
 
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
 
/**
 * 抽出各区域统计数量方法
 */
@Component
@Slf4j
public abstract class IndexCalculationServe<T extends BaseResult, S> extends IndexCalculationUtils {
    @Autowired
    private TMonitorMapper monitorMapper;
 
    //抽象方法,由子类编写具体逻辑算法
    protected abstract void updateAreaStats(Map<String, S> areaStatsMap, String key, T result);
 
    protected Map<String, S> getAreaStatsMap(List<T> list, Boolean needDept) {
        if (CollectionUtils.isEmpty(list)) {
            log.info("数据为空");
            return null;
        }
        //返回以国标码为key的设备map
        Map<String, TMonitorVO> monitorMap = monitorMapper.selectListByIds(list.stream().map(BaseResult::getNo).collect(Collectors.toList()))
                .stream().collect(Collectors.toMap(TMonitorVO::getSerialNumber, Function.identity()));
        Map<String, S> areaStatsMap = new HashMap<>();
 
        for (T result : list) {
            //获取设备所属部门
            TMonitorVO monitor = monitorMap.get(result.getNo());
            if (monitor == null) continue;
            String deptId = monitor.getDeptId().toString();
            updateAreaStats(areaStatsMap, deptId, result);
 
            // 处理省厅考核数据
            if (result.getProvinceTag() != null && result.getProvinceTag()) {
                String provinceKey = ApiConstants.Province + deptId;
                updateAreaStats(areaStatsMap, provinceKey, result);
            }
            // 处理公安部考核数据(公安部数据只有视频才有,所以这里定义了needDept来决定是否需要处理部级数据)
            if (needDept) {
                if (result.getDeptTag() != null && result.getDeptTag()) {
                    String deptKey = ApiConstants.Dept + deptId;
                    updateAreaStats(areaStatsMap, deptKey, result);
                }
            }
        }
        return areaStatsMap;
    }
}