yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package com.qianwen.smartman.modules.andon.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.qianwen.smartman.common.cache.cps.TimeSliceCache;
import com.qianwen.smartman.common.utils.LocalDateTimeUtils;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.tool.support.Kv;
import com.qianwen.core.tool.utils.DateUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.andon.dto.ShiftTimeDTO;
import com.qianwen.smartman.modules.andon.entity.AndonRecord;
import com.qianwen.smartman.modules.andon.enums.WorkType;
import com.qianwen.smartman.modules.andon.service.IAndonRecordService;
import com.qianwen.smartman.modules.andon.service.IAndonStatisticsService;
import com.qianwen.smartman.modules.andon.vo.AndonStatisticalCardVO;
import com.qianwen.smartman.modules.andon.vo.AndonStatisticsSearchVO;
import com.qianwen.smartman.modules.andon.vo.AndonTableStatisticalVO;
import com.qianwen.smartman.modules.andon.vo.CallTimeDateChartVO;
import com.qianwen.smartman.modules.andon.vo.CallTimeSearchVO;
import com.qianwen.smartman.modules.andon.vo.CallTimeShiftChartVO;
import com.qianwen.smartman.modules.andon.vo.CallTimeTableVO;
import com.qianwen.smartman.modules.andon.wrapper.StatisticsAndonWrapper;
import com.qianwen.smartman.modules.cps.entity.ShiftDetail;
import com.qianwen.smartman.modules.cps.entity.Workstation;
import com.qianwen.smartman.modules.cps.service.IWorkstationService;
import org.springframework.stereotype.Service;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/andon/service/impl/AndonStatisticsServiceImpl.class */
public class AndonStatisticsServiceImpl implements IAndonStatisticsService {
    private final IAndonRecordService recordService;
    private final IWorkstationService workstationService;
 
    public AndonStatisticsServiceImpl(final IAndonRecordService recordService, final IWorkstationService workstationService) {
        this.recordService = recordService;
        this.workstationService = workstationService;
    }
 
    @Override // org.springblade.modules.andon.service.IAndonStatisticsService
    public AndonStatisticalCardVO statisticalCard(AndonStatisticsSearchVO vo) {
        switch (WorkType.findByType(vo.getWorkType())) {
            case GROUP:
                return groupCard(vo);
            case WORKSTATION:
                return workstationCard(vo);
            default:
                return new AndonStatisticalCardVO();
        }
    }
 
    @Override // org.springblade.modules.andon.service.IAndonStatisticsService
    public IPage<AndonTableStatisticalVO> tableAndon(Query query, AndonStatisticsSearchVO vo) {
        switch (WorkType.findByType(vo.getWorkType())) {
            case GROUP:
                return groupTableAndon(query, vo);
            case WORKSTATION:
                return workstationTableAndon(query, vo);
            default:
                return new Page();
        }
    }
 
    @Override // org.springblade.modules.andon.service.IAndonStatisticsService
    public CallTimeShiftChartVO callTimeShiftChart(AndonStatisticsSearchVO vo) {
        switch (WorkType.findByType(vo.getWorkType())) {
            case GROUP:
                return groupCallTimeShiftChart(vo);
            case WORKSTATION:
                return workstationCallTimeShiftChart(vo);
            default:
                return new CallTimeShiftChartVO();
        }
    }
 
    @Override // org.springblade.modules.andon.service.IAndonStatisticsService
    public CallTimeDateChartVO callTimeDateChart(AndonStatisticsSearchVO vo) {
        switch (WorkType.findByType(vo.getWorkType())) {
            case GROUP:
                return groupCallTimeDateChart(vo);
            case WORKSTATION:
                return workstationCallTimeDateChart(vo);
            default:
                return new CallTimeDateChartVO();
        }
    }
 
    @Override // org.springblade.modules.andon.service.IAndonStatisticsService
    public IPage<CallTimeTableVO> callTimeTable(CallTimeSearchVO vo) {
        return null;
    }
 
    private CallTimeDateChartVO groupCallTimeDateChart(AndonStatisticsSearchVO vo) {
        List<Workstation> workstations = this.workstationService.listWorkStationByGroup(vo.getIds());
        if (Func.isEmpty(workstations)) {
            return new CallTimeDateChartVO();
        }
        List<Long> workstationIds = (List) workstations.stream().map((v0) -> {
            return v0.getId();
        }).collect(Collectors.toList());
        List<AndonRecord> records = this.recordService.queryCallTime(vo.getStartTime(), vo.getEndTime(), workstationIds);
        return StatisticsAndonWrapper.build().entity(records, vo);
    }
 
    private CallTimeDateChartVO workstationCallTimeDateChart(AndonStatisticsSearchVO vo) {
        return null;
    }
 
    private CallTimeShiftChartVO groupCallTimeShiftChart(AndonStatisticsSearchVO vo) {
        List<Workstation> workstations = this.workstationService.listWorkStationByGroup(vo.getIds());
        if (Func.isEmpty(workstations)) {
            return new CallTimeShiftChartVO();
        }
        return getCallTimeShiftChartVO(vo, workstations);
    }
 
    private CallTimeShiftChartVO getCallTimeShiftChartVO(AndonStatisticsSearchVO vo, List<Workstation> workstations) {
        Date startTime = vo.getStartTime();
        Date endTime = vo.getEndTime();
        List<LocalDate> dateList = LocalDateTimeUtils.getDateList(LocalDateTimeUtils.dateToLocalDate(startTime), LocalDateTimeUtils.dateToLocalDate(endTime));
        List<String> calendarCodes = (List) workstations.stream().map((v0) -> {
            return v0.getCalendarCode();
        }).filter((v0) -> {
            return Func.notNull(v0);
        }).collect(Collectors.toList());
        Map<String, Map<Integer, List<ShiftTimeDTO>>> timeMap = Kv.newMap();
        for (LocalDate date : dateList) {
            List<ShiftTimeDTO> timeDto = Lists.newArrayList();
            for (String code : calendarCodes) {
                List<ShiftDetail> detail = TimeSliceCache.getTimeShiftDetail(code, date);
                List<ShiftTimeDTO> collect = (List) detail.stream().map(dt -> {
                    LocalDateTime start = LocalDateTime.of(date, LocalTime.MIN).plus(dt.getShiftStartTime().intValue(), (TemporalUnit) ChronoUnit.MINUTES);
                    LocalDateTime end = LocalDateTime.of(date, LocalTime.MIN).plus(dt.getShiftEndTime().intValue(), (TemporalUnit) ChronoUnit.MINUTES);
                    return ShiftTimeDTO.builder().indexName(Func.isBlank(dt.getIndexName()) ? "班次" + dt.getShiftIndex() : dt.getIndexName()).shiftIndex(dt.getShiftIndex()).startTime(start).endTime(end).build();
                }).collect(Collectors.toList());
                timeDto.addAll(collect);
            }
            Map<Integer, List<ShiftTimeDTO>> collect2 = (Map) timeDto.stream().collect(Collectors.groupingBy((v0) -> {
                return v0.getShiftIndex();
            }));
            timeMap.put(DateUtil.formatDate(date), collect2);
        }
        List<Long> workstationIds = (List) workstations.stream().map((v0) -> {
            return v0.getId();
        }).collect(Collectors.toList());
        List<AndonRecord> records = this.recordService.queryCallTime(startTime, endTime, workstationIds);
        return StatisticsAndonWrapper.build().entity(timeMap, records, dateList);
    }
 
    private CallTimeShiftChartVO workstationCallTimeShiftChart(AndonStatisticsSearchVO vo) {
        List<Workstation> workstations = this.workstationService.listByIds(vo.getIds());
        if (Func.isEmpty(workstations)) {
            return new CallTimeShiftChartVO();
        }
        return getCallTimeShiftChartVO(vo, workstations);
    }
 
    private IPage<AndonTableStatisticalVO> groupTableAndon(Query query, AndonStatisticsSearchVO vo) {
        List<Long> ids = vo.getIds();
        if (Func.isEmpty(ids)) {
            return new Page();
        }
        List<Workstation> workstations = this.workstationService.listWorkStationByGroup(ids);
        if (Func.isEmpty(workstations)) {
            return new Page();
        }
        return getTableAndon(query, vo, workstations);
    }
 
    private IPage<AndonTableStatisticalVO> workstationTableAndon(Query query, AndonStatisticsSearchVO vo) {
        List<Long> ids = vo.getIds();
        if (Func.isEmpty(ids)) {
            return new Page();
        }
        List<Workstation> workstations = this.workstationService.listByIds(ids);
        if (Func.isEmpty(workstations)) {
            return new Page();
        }
        return getTableAndon(query, vo, workstations);
    }
 
    private IPage<AndonTableStatisticalVO> getTableAndon(Query query, AndonStatisticsSearchVO vo, List<Workstation> workstations) {
        return this.recordService.getTableAndon(query, vo.getStartTime(), vo.getEndTime(), (List) workstations.stream().map((v0) -> {
            return v0.getId();
        }).collect(Collectors.toList()));
    }
 
    private AndonStatisticalCardVO groupCard(AndonStatisticsSearchVO vo) {
        List<Long> ids = vo.getIds();
        if (Func.isEmpty(ids)) {
            return new AndonStatisticalCardVO();
        }
        List<Workstation> workstations = this.workstationService.listWorkStationByGroup(ids);
        if (Func.isEmpty(workstations)) {
            return new AndonStatisticalCardVO();
        }
        return getRecords(workstations, vo);
    }
 
    private AndonStatisticalCardVO workstationCard(AndonStatisticsSearchVO vo) {
        List<Long> ids = vo.getIds();
        if (Func.isEmpty(ids)) {
            return new AndonStatisticalCardVO();
        }
        List<Workstation> workstations = this.workstationService.listByIds(ids);
        if (Func.isEmpty(workstations)) {
            return new AndonStatisticalCardVO();
        }
        return getRecords(workstations, vo);
    }
 
    private AndonStatisticalCardVO getRecords(List<Workstation> workstations, AndonStatisticsSearchVO vo) {
        return this.recordService.queryCard((List) workstations.stream().map((v0) -> {
            return v0.getId();
        }).collect(Collectors.toList()), vo.getStartTime(), vo.getEndTime());
    }
}