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
package com.qianwen.smartman.modules.mdc.utils;
 
import com.google.common.collect.Lists;
import java.util.List;
import java.util.stream.Collectors;
import com.qianwen.smartman.common.cache.ParamCache;
import com.qianwen.core.tool.jackson.JsonUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.mdc.dto.OpenTypeDTO;
import com.qianwen.smartman.modules.mdc.entity.SuperAggregate;
import com.qianwen.smartman.modules.mdc.enums.OpenTypeEnums;
 
public class FilterOffUtils {
    /**
     * 过滤数据
     * @param <R>
     * @param data 聚合状态数据列表
     * @param openTypeEnums RUNNING/ALARM/OEE等
     * @return
     */
    public static <R extends SuperAggregate> List<R> filterOffDay(List<R> data, OpenTypeEnums openTypeEnums) {
        if (Func.isEmpty(data)) {
            return data;
        }
        //获取"分析设置"界面中的过滤配置,没有设置数据则返回false(不过滤)
        boolean filterType = whetherToFilter(OpenTypeEnums.PARAM_KEY_TYPE, openTypeEnums);//mdc_open_type,是否过滤掉休息时段(shiftTimeType=2)
        boolean filterShift = whetherToFilter(OpenTypeEnums.PARAM_KEY_SHIFT, openTypeEnums);//mdc_open_shift,是否过滤班制(shiftIndex>0的数据保留)
 
        if (!filterType && !filterShift) {
            return data;
        }
        return data.stream().filter(item -> {
            return (filterType && item.getShiftTimeType().equals(2)) ? false : true;//2:休息时间段,这里是去掉休息的状态数据
        }).filter(item2 -> {
            return !filterShift || item2.getShiftIndex().intValue() > 0;
        }).collect(Collectors.toList());
    }
 
    public static <R extends SuperAggregate> R filterOffDay(R data, OpenTypeEnums openTypeEnums) {
        if (filterOffDay(Lists.newArrayList(new SuperAggregate[]{data}), openTypeEnums).isEmpty()) {
            return null;
        }
        return data;
    }
 
    /**
     * 是否过滤数据(根据系统参数中的json数据,open==1就过滤)
     * @param typeEnums 过滤分类(班制/或类型) mdc_open_shift/mdc_open_type
     * @param enums 过滤的项目TIME_USED_ANALYSIS/ALARM_ANALYSIS ...
     * @return
     */
    public static boolean whetherToFilter(OpenTypeEnums typeEnums, OpenTypeEnums enums) {
        String value = ParamCache.getValue(typeEnums.getMsg());
        if (Func.isNull(value)) {
            return false;
        }
        List<OpenTypeDTO> dtos = JsonUtil.readList(value, OpenTypeDTO.class);
        if (Func.isEmpty(dtos)) {
            return false;
        }
        for (OpenTypeDTO dto : dtos) {
            if (dto.getType().equals(enums.name())) {
                return dto.getOpen().equals(1);
            }
        }
        return false;
    }
 
    public static boolean whetherToFilter(OpenTypeEnums enums) {
        return whetherToFilter(OpenTypeEnums.PARAM_KEY_TYPE, enums);
    }
}