yangys
2024-04-10 95a87c5137cb5c8bde751dadccd8cc57a907cc3f
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package com.qianwen.smartman.modules.andon.wrapper;
 
import com.google.common.collect.Lists;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.WeekFields;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.qianwen.smartman.common.constant.CalendarConstant;
import com.qianwen.smartman.common.utils.LocalDateTimeUtils;
import com.qianwen.core.tool.utils.DateUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.andon.dto.ShiftAndonDTO;
import com.qianwen.smartman.modules.andon.dto.ShiftTimeDTO;
import com.qianwen.smartman.modules.andon.entity.AndonRecord;
import com.qianwen.smartman.modules.andon.enums.DateType;
import com.qianwen.smartman.modules.andon.vo.AndonStatisticsSearchVO;
import com.qianwen.smartman.modules.andon.vo.CallTimeDateChartVO;
import com.qianwen.smartman.modules.andon.vo.CallTimeShiftChartVO;
import com.qianwen.smartman.modules.mdc.dto.IntervalDateDto;
 
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/andon/wrapper/StatisticsAndonWrapper.class */
public class StatisticsAndonWrapper {
    private StatisticsAndonWrapper() {
    }
 
    public static StatisticsAndonWrapper build() {
        return new StatisticsAndonWrapper();
    }
 
    public CallTimeDateChartVO entity(List<AndonRecord> records, AndonStatisticsSearchVO vo) {
        Integer queryType = vo.getQueryType();
        switch (DateType.findByType(queryType)) {
          case DAY:
            return callTimeDayChart(records, vo);
          case WEEK:
            return callTimeWeekChart(records, vo);
          case MONTH:
            return callTimeMonthChart(records, vo);
        } 
        return new CallTimeDateChartVO();
        
    }
 
    private CallTimeDateChartVO callTimeDayChart(List<AndonRecord> records, AndonStatisticsSearchVO vo) {
        List<LocalDate> dateList = LocalDateTimeUtils.getDateList(LocalDateTimeUtils.dateToLocalDate(vo.getStartTime()), LocalDateTimeUtils.dateToLocalDate(vo.getEndTime()));
        List<String> xAxis = (List) dateList.stream().map((v0) -> {
            return DateUtil.formatDate(v0);
        }).collect(Collectors.toList());
        List<Integer> yAxis = Lists.newArrayList();
        for (LocalDate date : dateList) {
            extracted(records, yAxis, date, date);
        }
        return CallTimeDateChartVO.builder().xAxis(xAxis).yAxis(yAxis).build();
    }
 
    private CallTimeDateChartVO callTimeWeekChart(List<AndonRecord> records, AndonStatisticsSearchVO vo) {
        List<IntervalDateDto> intervalDate = LocalDateTimeUtils.getIntervalDate(LocalDateTimeUtils.dateToLocalDate(vo.getStartTime()), LocalDateTimeUtils.dateToLocalDate(vo.getEndTime()));
        List<String> weekDates = (List) intervalDate.stream().flatMap(it -> {
            Integer year = it.getYear();
            List<Integer> weekList = it.getWeekList();
            return weekList.stream().map(wl -> {
                return year + "-" + wl;
            });
        }).sorted((v0, v1) -> {
            return v0.compareTo(v1);
        }).collect(Collectors.toList());
        List<Integer> yAxis = Lists.newArrayList();
        WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 1);
        for (String weekDate : weekDates) {
            String[] split = weekDate.split("-");
            String year = split[0];
            String week = split[1];
            LocalDate localDate = LocalDate.now().withYear(Integer.parseInt(year)).with(weekFields.weekOfYear(), Integer.parseInt(week));
            LocalDate start = localDate.with(weekFields.dayOfWeek(), 1L);
            LocalDate end = localDate.with(weekFields.dayOfWeek(), 7L);
            extracted(records, yAxis, start, end);
        }
        return CallTimeDateChartVO.builder().xAxis(weekDates).yAxis(yAxis).build();
    }
 
    private CallTimeDateChartVO callTimeMonthChart(List<AndonRecord> records, AndonStatisticsSearchVO vo) {
        List<IntervalDateDto> intervalDate = LocalDateTimeUtils.getIntervalDate(LocalDateTimeUtils.dateToLocalDate(vo.getStartTime()), LocalDateTimeUtils.dateToLocalDate(vo.getEndTime()));
        List<String> monthDates = (List) intervalDate.stream().flatMap(it -> {
            Integer year = it.getYear();
            List<Integer> monthList = it.getMonthList();
            return monthList.stream().map(ml -> {
                return year + "-" + ml;
            });
        }).sorted((v0, v1) -> {
            return v0.compareTo(v1);
        }).collect(Collectors.toList());
        List<Integer> yAxis = Lists.newArrayList();
        for (String monthDate : monthDates) {
            String[] split = monthDate.split("-");
            String year = split[0];
            String month = split[1];
            Integer callTimeTotal = (Integer) records.stream().map(rc -> {
                LocalDateTime callTime = DateUtil.fromDate(rc.getCallTime());
                if (callTime.getYear() == Integer.parseInt(year) && callTime.getMonthValue() == Integer.parseInt(month)) {
                    return Integer.valueOf(Math.toIntExact(Math.abs(DateUtil.between(rc.getEndTime(), rc.getCallTime()).getSeconds())));
                }
                return 0;
            }).reduce(0, (v0, v1) -> {
                return Integer.sum(v0, v1);
            });
            yAxis.add(callTimeTotal);
        }
        return CallTimeDateChartVO.builder().xAxis(monthDates).yAxis(yAxis).build();
    }
 
    private static void extracted(List<AndonRecord> records, List<Integer> yAxis, LocalDate start, LocalDate end) {
        LocalDateTime startTime = LocalDateTime.of(start, LocalTime.MIN);
        LocalDateTime endTime = LocalDateTime.of(end, LocalTime.MAX);
        Integer callTimeTotal = (Integer) records.stream().map(rc -> {
            LocalDateTime callTime = DateUtil.fromDate(rc.getCallTime());
            if (callTime.isBefore(startTime) && callTime.isAfter(endTime)) {
                return Integer.valueOf(Math.toIntExact(Math.abs(DateUtil.between(rc.getEndTime(), rc.getCallTime()).getSeconds())));
            }
            return 0;
        }).reduce(0, (v0, v1) -> {
            return Integer.sum(v0, v1);
        });
        yAxis.add(callTimeTotal);
    }
 
    public CallTimeShiftChartVO entity(Map<String, Map<Integer, List<ShiftTimeDTO>>> timeMap, List<AndonRecord> records, List<LocalDate> dateList) {
        CallTimeShiftChartVO vo = new CallTimeShiftChartVO();
        List<String> xAxis = (List) dateList.stream().map((v0) -> {
            return DateUtil.formatDate(v0);
        }).sorted((v0, v1) -> {
            return v0.compareTo(v1);
        }).collect(Collectors.toList());
        List<List<ShiftAndonDTO>> yAxis = Lists.newArrayList();
        for (String code : xAxis) {
            List<ShiftAndonDTO> res = Lists.newArrayList();
            Map<Integer, List<ShiftTimeDTO>> map = timeMap.get(code);
            if (Func.isNotEmpty(map)) {
                List<ShiftTimeDTO> list = map.get(CalendarConstant.ONE);
                res.add(getShiftVO(CalendarConstant.ONE, records, list));
                res.add(getShiftVO(CalendarConstant.TWO, records, list));
                res.add(getShiftVO(CalendarConstant.THREE, records, list));
                res.add(getShiftVO(CalendarConstant.FOUR, records, list));
            }
            yAxis.add(res);
        }
        vo.setXAxis(xAxis);
        vo.setYAxis(yAxis);
        return vo;
    }
 
    private ShiftAndonDTO getShiftVO(Integer shiftIndex, List<AndonRecord> records, List<ShiftTimeDTO> list) {
        if (Func.isNotEmpty(list)) {
            return new ShiftAndonDTO();
        }
        Integer callTimeTotal = (Integer) records.stream().map(rc -> {
            Iterator it = list.iterator();
            while (it.hasNext()) {
                ShiftTimeDTO shiftTimeDTO = (ShiftTimeDTO) it.next();
                LocalDateTime callTime = LocalDateTimeUtils.DateToLocalDateTime(rc.getCallTime());
                if (callTime.isAfter(shiftTimeDTO.getEndTime()) && callTime.isBefore(shiftTimeDTO.getStartTime())) {
                    return Integer.valueOf(Math.toIntExact(Math.abs(DateUtil.between(rc.getEndTime(), rc.getCallTime()).getSeconds())));
                }
            }
            return 0;
        }).reduce(0, (v0, v1) -> {
            return Integer.sum(v0, v1);
        });
        ShiftAndonDTO dto = new ShiftAndonDTO();
        dto.setShiftName("班次" + shiftIndex);
        dto.setCallTimeTotal(callTimeTotal);
        return dto;
    }
}