yangys
2024-03-27 e48aa2ac8dea1be5db11c63edf0b912c4ad5ce65
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package com.qianwen.smartman.modules.visual.wrapper;
 
import cn.hutool.core.collection.ListUtil;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.qianwen.smartman.common.constant.DateConstant;
import com.qianwen.smartman.common.constant.VisualConstant;
import com.qianwen.core.tool.utils.DateUtil;
import com.qianwen.smartman.modules.cps.entity.Workstation;
import com.qianwen.smartman.modules.mdc.entity.SuperAggregateOutput;
import com.qianwen.smartman.modules.system.entity.SeriesItem;
import com.qianwen.smartman.modules.system.vo.ChartSeriesDataVO;
import com.qianwen.smartman.modules.system.vo.WorkstationChartSeriesDataVO;
import com.qianwen.smartman.modules.visual.dto.DynamicCountDateAggregateDTO;
 
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/visual/wrapper/VisualCountPulseWrapper.class */
public class VisualCountPulseWrapper {
    static final /* synthetic */ boolean $assertionsDisabled;
 
    static {
        $assertionsDisabled = !VisualCountPulseWrapper.class.desiredAssertionStatus();
    }
 
    public static ChartSeriesDataVO<Long> visualCountDataByHour(DynamicCountDateAggregateDTO countAggregateDataDTO) {
        return visualCountDataByCondition(countAggregateDataDTO, ChronoUnit.HOURS, date -> {
            return date.getDayOfMonth() + "-" + date.getHour();
        });
    }
 
    public static ChartSeriesDataVO<Long> visualCountDataByDay(DynamicCountDateAggregateDTO countAggregateDataDTO) {
        return visualCountDataByCondition(countAggregateDataDTO, ChronoUnit.DAYS, date -> {
            return DateUtil.format(date, DateConstant.PATTERN_DATE);
        });
    }
 
    public static ChartSeriesDataVO<Long> visualCountDataByShift(DynamicCountDateAggregateDTO countAggregateDataDTO) {
        Map<Long, Long> aggregateData = (Map) countAggregateDataDTO.getList().stream().collect(Collectors.groupingBy((v0) -> {
            return v0.getWorkstationId();
        }, Collectors.summingLong((v0) -> {
            return v0.getOutput();
        })));
        WorkstationChartSeriesDataVO<Long> chartSeriesDataVO = new WorkstationChartSeriesDataVO<>();
        List<Long> data = (List) countAggregateDataDTO.getWorkstationList().stream().map(workstation -> {
            return (Long) aggregateData.getOrDefault(workstation.getId(), 0L);
        }).collect(Collectors.toList());
        SeriesItem<Long> item = new SeriesItem<>(VisualConstant.SHIFT_OUTPUT, data);
        chartSeriesDataVO.generateCategories(countAggregateDataDTO.getWorkstationList(), 3);
        chartSeriesDataVO.setSeries(ListUtil.toList(new SeriesItem[]{item}));
        return chartSeriesDataVO;
    }
 
    private static ChartSeriesDataVO<Long> visualCountDataByCondition(DynamicCountDateAggregateDTO countAggregateDataDTO, ChronoUnit chronoUnit, Function<LocalDateTime, String> categoriesFormat) {
        UnaryOperator<LocalDateTime> unaryOperator;
        if ($assertionsDisabled || countAggregateDataDTO.getStartTime() != null) {
            if ($assertionsDisabled || countAggregateDataDTO.getEndTime() != null) {
                List<Workstation> workstationList = countAggregateDataDTO.getWorkstationList();
                Map<Long, String> categoriesSuffix = (Map) workstationList.stream().collect(Collectors.toMap((v0) -> {
                    return v0.getId();
                }, (v0) -> {
                    return v0.getName();
                }));
                List<SuperAggregateOutput> list = countAggregateDataDTO.getList();
                LocalDateTime startTime = countAggregateDataDTO.getStartTime();
                LocalDateTime endTime = countAggregateDataDTO.getEndTime();
                long between = chronoUnit.between(startTime, endTime);
                if (chronoUnit.equals(ChronoUnit.HOURS)) {
                    unaryOperator = date -> {
                        return date.plusHours(1L);
                    };
                } else {
                    unaryOperator = chronoUnit.equals(ChronoUnit.DAYS) ? date2 -> {
                        return date2.plusDays(1L);
                    } : null;
                }
                UnaryOperator<LocalDateTime> operator = unaryOperator;
                if ($assertionsDisabled || operator != null) {
                    List<String> categories = (List) Stream.iterate(startTime, operator).limit(between + 1).map(categoriesFormat).collect(Collectors.toList());
                    ChartSeriesDataVO<Long> chartSeriesDataVO = new ChartSeriesDataVO<>();
                    Map<Long, SeriesItem<Long>> seriesMap = new HashMap<>();
                    ((Map) list.stream().collect(Collectors.groupingBy((v0) -> {
                        return v0.getWorkstationId();
                    }))).forEach(id, aggregateOutputs -> {
                        Map<String, Long> collectMap = (Map) aggregateOutputs.stream().collect(Collectors.groupingBy(aggregate -> {
                            return (String) categoriesFormat.apply(aggregate.getTs().toLocalDateTime());
                        }, Collectors.summingLong((v0) -> {
                            return v0.getOutput();
                        })));
                        seriesMap.put(id, new SeriesItem((String) categoriesSuffix.get(id), (List) categories.stream().map(it -> {
                            return (Long) collectMap.getOrDefault(it, 0L);
                        }).collect(Collectors.toList())));
                    });
                    chartSeriesDataVO.setCategories(categories);
                    chartSeriesDataVO.setSeries((List) countAggregateDataDTO.getWorkstationList().stream().map(item -> {
                        return (SeriesItem) seriesMap.get(item.getId());
                    }).filter((v0) -> {
                        return Objects.nonNull(v0);
                    }).collect(Collectors.toList()));
                    return chartSeriesDataVO;
                }
                throw new AssertionError();
            }
            throw new AssertionError();
        }
        throw new AssertionError();
    }
}