PC
2024-03-31 608f20e0d5d8f95d9bbb917e95e2913682deb77d
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
package com.qianwen.smartman.modules.mdc.service.impl;
 
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.qianwen.core.excel.util.ExcelUtil;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.oss.model.BladeFile;
import com.qianwen.core.tool.utils.CollectionUtil;
import com.qianwen.core.tool.utils.DateUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.common.constant.DateConstant;
import com.qianwen.smartman.common.constant.ExcelConstant;
import com.qianwen.smartman.common.utils.LocalDateTimeUtils;
import com.qianwen.smartman.common.utils.LocalDateUtil;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.smartman.modules.cps.dto.ShiftInfoDTO;
import com.qianwen.smartman.modules.cps.mapper.WorkstationMapper;
import com.qianwen.smartman.modules.cps.service.IShiftDetailService;
import com.qianwen.smartman.modules.cps.vo.WorkstationVO;
import com.qianwen.smartman.modules.mdc.convert.AlarmConvert;
import com.qianwen.smartman.modules.mdc.entity.SuperAggregate;
import com.qianwen.smartman.modules.mdc.entity.SuperAlarm;
import com.qianwen.smartman.modules.mdc.enums.OpenTypeEnums;
import com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum;
import com.qianwen.smartman.modules.mdc.excel.AlarmDataSheetExcel;
import com.qianwen.smartman.modules.mdc.excel.AlarmDataSheetExcelForOther;
import com.qianwen.smartman.modules.mdc.mapper.SuperAlarmMapper;
import com.qianwen.smartman.modules.mdc.service.IAlarmService;
import com.qianwen.smartman.modules.mdc.utils.FilterOffUtils;
import com.qianwen.smartman.modules.mdc.vo.AlarmDataSheetShiftVO;
import com.qianwen.smartman.modules.mdc.vo.AlarmDataSheetVO;
import com.qianwen.smartman.modules.mdc.vo.AlarmShiftSearchExcelVO;
import com.qianwen.smartman.modules.mdc.vo.AlarmShiftSearchVO;
import com.qianwen.smartman.modules.mdc.vo.AlarmSummaryGraphShiftVO;
import com.qianwen.smartman.modules.mdc.vo.AlarmSummaryGraphVO;
import com.qianwen.smartman.modules.mdc.vo.SplitFilterListVO;
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
 
import cn.hutool.core.util.StrUtil;
 
@Service
public class AlarmServiceImpl implements IAlarmService {
    private static final Logger log = LoggerFactory.getLogger(AlarmServiceImpl.class);
    private final SuperAlarmMapper alarmMapper;
    private final OssBuilder ossBuilder;
    private final IShiftDetailService shiftDetailService;
    private final WorkstationMapper workstationMapper;
    public final Integer LENGTH_1 = 1;
 
    public AlarmServiceImpl(final SuperAlarmMapper alarmMapper, final OssBuilder ossBuilder, final IShiftDetailService shiftDetailService, final WorkstationMapper workstationMapper) {
        this.alarmMapper = alarmMapper;
        this.ossBuilder = ossBuilder;
        this.shiftDetailService = shiftDetailService;
        this.workstationMapper = workstationMapper;
    }
 
    @Override // org.springblade.modules.mdc.service.IAlarmService
    public IPage<AlarmDataSheetVO> pageAlarm(Query query, AlarmShiftSearchVO vo) {
        if (Func.isNull(vo.getWorkstationId())) {
            return new Page<>();
        }
        LocalDate queryTime = vo.getQueryTime();
        List<SuperAlarm> list = this.alarmMapper.selectListAlarm(vo, DateUtil.format(queryTime, "yyyyMMdd"));
        Map<String, List<SuperAlarm>> map = FilterOffUtils.filterOffDay(list, OpenTypeEnums.ALARM_ANALYSIS).stream().collect(Collectors.groupingBy(c -> {
            return c.getCode() + c.getMessage();
        }));
        Integer size = query.getSize();
        Integer current = query.getCurrent();
        Page<AlarmDataSheetVO> page = new Page<>(current.intValue(), size.intValue(), map.size());
        if (map.size() == 0) {
            return page;
        }
        List<SuperAlarm> alarms = this.alarmMapper.selectListAlarm(vo, DateUtil.format(queryTime, "yyyyMMdd"));
        List<AlarmDataSheetVO> res = AlarmConvert.INSTANCE.convert(FilterOffUtils.filterOffDay(alarms, OpenTypeEnums.ALARM_ANALYSIS));
        List<AlarmDataSheetVO> alarmDataSheetVOS = new ArrayList<>();
        Map<String, List<AlarmDataSheetVO>> resMap = res.stream().collect(Collectors.groupingBy(c2 -> {
            return c2.getAlarmCode() + c2.getAlarmMsg();
        }));
        resMap.values().forEach(alarmDataSheetVOList -> {
            ((AlarmDataSheetVO) alarmDataSheetVOList.get(0)).setCount(Integer.valueOf(alarmDataSheetVOList.size()));
            alarmDataSheetVOS.add(alarmDataSheetVOList.get(0));
        });
        if (query.getSize().intValue() == -1) {
            page.setRecords(alarmDataSheetVOS);
        } else if (alarmDataSheetVOS.size() < ((query.getCurrent().intValue() - 1) * query.getSize().intValue()) + query.getSize().intValue()) {
            page.setRecords(alarmDataSheetVOS.subList((query.getCurrent().intValue() - 1) * query.getSize().intValue(), alarmDataSheetVOS.size()));
        } else {
            page.setRecords(alarmDataSheetVOS.subList((query.getCurrent().intValue() - 1) * query.getSize().intValue(), ((query.getCurrent().intValue() - 1) * query.getSize().intValue()) + query.getSize().intValue()));
        }
        return page;
    }
 
    @Override // org.springblade.modules.mdc.service.IAlarmService
    public BladeFile exportAlarm(AlarmShiftSearchExcelVO vo) {
        BladeFile bladeFile;
        
        List<SuperAlarm> superAlarms = this.alarmMapper.selectListAlarmByShift(LocalDateTimeUtils.formatTimeLocalDate(vo.getStartTime(), "yyyyMMdd"), LocalDateTimeUtils.formatTimeLocalDate(vo.getEndTime(), "yyyyMMdd"), vo.getWorkstationId());
        superAlarms = FilterOffUtils.filterOffDay(superAlarms, OpenTypeEnums.ALARM_ANALYSIS);
        superAlarms.sort(Comparator.comparing(SuperAggregate::getFactoryDate));
        Collections.reverse(superAlarms);
        //superAlarms = superAlarms.stream().collect(Collectors.toList());
        /*
        List<SuperAlarm> superAlarms = FilterOffUtils.filterOffDay(this.alarmMapper.selectListAlarmByShift(LocalDateTimeUtils.formatTimeLocalDate(vo.getStartTime(), "yyyyMMdd"), LocalDateTimeUtils.formatTimeLocalDate(vo.getEndTime(), "yyyyMMdd"), vo.getWorkstationId()), OpenTypeEnums.ALARM_ANALYSIS).stream().sorted(Comparator.comparing((v0) -> {
            return v0.getFactoryDate();
        }).reversed()).collect(Collectors.toList());*/
        WorkstationVO workstationVO = (WorkstationVO) this.workstationMapper.queryWorkstationAndGroup(Condition.getPage(new Query().setSize(-1)), Lists.newArrayList(new Long[]{vo.getWorkstationId()})).getRecords().get(0);
        if (vo.getEnums().equals(StatisticalMethodEnum.SHIFT)) {
            List<SuperAlarm> superAlarms2 = superAlarms.stream().filter(s -> {
                return s.getShiftIndex().intValue() > 0;
            }).collect(Collectors.toList());
            List<ShiftInfoDTO> shiftInfoDtoList = this.shiftDetailService.getShiftInfoDtoList(Lists.newArrayList(new Long[]{vo.getWorkstationId()}), vo.getStartTime(), vo.getEndTime());
            bladeFile = exportShift(superAlarms2, workstationVO, shiftInfoDtoList);
        } else {
            bladeFile = export(superAlarms, workstationVO, vo.getEnums());
        }
        return bladeFile;
    }
 
    private BladeFile exportShift(List<SuperAlarm> superAlarms, WorkstationVO workstationVO, List<ShiftInfoDTO> shiftInfoDtoList) {
        Map<String, List<SuperAlarm>> mapGroupByShift = superAlarms.stream().collect(Collectors.groupingBy(s -> {
            return s.getFactoryDate() + "-" + s.getShiftIndex();
        }));
        List<AlarmDataSheetExcel> alarmDataSheetExcelList = new ArrayList<>();
        String shift = MessageUtils.message("mdc.excel.alarm.shift", new Object[0]);
        Map<String, String> shiftIndexToName = shiftInfoDtoList.stream().collect(Collectors.toMap(s2 -> {
            return s2.getDate().replace("-", "") + "-" + s2.getShiftIndex();
        }, (v0) -> {
            return v0.getIndexName();
        }));
        Map<String, List<SuperAlarm>> result = new LinkedHashMap<>();
        mapGroupByShift.entrySet().stream().sorted(Map.Entry.comparingByKey(Comparator.reverseOrder())).forEachOrdered(x -> {
            List<SuperAlarm> list = result.put(x.getKey(), x.getValue());
        });
        result.forEach((k, v) -> {
            Map<String, List<SuperAlarm>> mapGroupByAlarmCodeAndMessage = v.stream().collect(Collectors.groupingBy(s3 -> {
                return s3.getCode() + "-" + s3.getMessage();
            }));
            mapGroupByAlarmCodeAndMessage.forEach((key, value) -> {
                String alarmMessage;
                AlarmDataSheetExcel alarmDataSheetExcel = new AlarmDataSheetExcel();
                String[] split = k.split("-");
                alarmDataSheetExcel.setDate(LocalDateTimeUtils.formatTimeLocalDate(LocalDate.parse(split[0], DateTimeFormatter.ofPattern("yyyyMMdd")), DateConstant.PATTERN_DATE));
                String indexName = (String) shiftIndexToName.get(k);
                alarmDataSheetExcel.setShift(Func.isNotEmpty(indexName) ? indexName : StrUtil.format("{}{}", new Object[]{shift, split[1]}));
                alarmDataSheetExcel.setWorkstationCode(workstationVO.getCode());
                alarmDataSheetExcel.setWorkstationName(workstationVO.getName());
                alarmDataSheetExcel.setWorkstationGroup(workstationVO.getGroupName());
                String[] splitByMessage = key.split("-");
                String alarmCode = splitByMessage[0];
                if (splitByMessage.length > this.LENGTH_1.intValue()) {
                    alarmMessage = splitByMessage[1];
                } else {
                    alarmMessage = "";
                }
                alarmDataSheetExcel.setAlarmCode(alarmCode);
                alarmDataSheetExcel.setAlarmMsg(alarmMessage);
                alarmDataSheetExcel.setCount(String.valueOf(value.size()));
                alarmDataSheetExcelList.add(alarmDataSheetExcel);
            });
        });
        String fileName = String.format("%s-%s.xlsx", ExcelConstant.ALARM, DateUtil.time());
        MultipartFile multipartFile = ExcelUtil.exportToMultipartFile(fileName, ExcelConstant.ALARM, alarmDataSheetExcelList, AlarmDataSheetExcel.class);
        return this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
    }
 
    private BladeFile export(List<SuperAlarm> superAlarms, WorkstationVO workstationVO, StatisticalMethodEnum statisticalMethodEnum) {
        Map<String, List<SuperAlarm>> map;
        String the = MessageUtils.message("mdc.efficiency.analysis.the", new Object[0]);
        String week = MessageUtils.message("mdc.efficiency.analysis.week", new Object[0]);
        if (statisticalMethodEnum.equals(StatisticalMethodEnum.DAY)) {
            map = superAlarms.stream().collect(Collectors.groupingBy(s -> {
                return String.valueOf(s.getFactoryDate());
            }));
        } else if (statisticalMethodEnum.equals(StatisticalMethodEnum.WEEK)) {
            map = superAlarms.stream().collect(Collectors.groupingBy(s2 -> {
                return s2.getFactoryYear() + "-" + s2.getFactoryWeek();
            }));
        } else {
            map = superAlarms.stream().collect(Collectors.groupingBy(s3 -> {
                return s3.getFactoryYear() + "-" + s3.getFactoryMonth();
            }));
        }
        List<AlarmDataSheetExcelForOther> alarmDataSheetExcelForOtherList = new ArrayList<>();
        Map<String, List<SuperAlarm>> result = new LinkedHashMap<>();
        map.entrySet().stream().sorted(Map.Entry.comparingByKey(Comparator.reverseOrder())).forEachOrdered(x -> {
            List list = (List) result.put(x.getKey(), x.getValue());
        });
        result.forEach((k, v) -> {
            Map<String, List<SuperAlarm>> mapGroupByAlarmCodeAndMessage = v.stream().collect(Collectors.groupingBy(s4 -> {
                return s4.getCode() + "-" + s4.getMessage();
            }));
            mapGroupByAlarmCodeAndMessage.forEach((key, value) -> {
                String alarmMessage;
                String[] split = k.split("-");
                AlarmDataSheetExcelForOther alarmDataSheetExcelForOther = new AlarmDataSheetExcelForOther();
                if (statisticalMethodEnum.equals(StatisticalMethodEnum.DAY)) {
                    alarmDataSheetExcelForOther.setDate(LocalDateTimeUtils.formatTimeLocalDate(LocalDate.parse(k, DateTimeFormatter.ofPattern("yyyyMMdd")), DateConstant.PATTERN_DATE));
                } else if (statisticalMethodEnum.equals(StatisticalMethodEnum.WEEK)) {
                    alarmDataSheetExcelForOther.setDate(StrUtil.format("{}-{}", new Object[]{split[0], StrUtil.format("{}{}{}", new Object[]{the, split[1], week})}));
                } else {
                    alarmDataSheetExcelForOther.setDate(StrUtil.format("{}-{}", new Object[]{split[0], split[1]}));
                }
                alarmDataSheetExcelForOther.setWorkstationCode(workstationVO.getCode());
                alarmDataSheetExcelForOther.setWorkstationName(workstationVO.getName());
                alarmDataSheetExcelForOther.setWorkstationGroup(workstationVO.getGroupName());
                String[] splitByMessage = key.split("-");
                String alarmCode = splitByMessage[0];
                if (splitByMessage.length > this.LENGTH_1.intValue()) {
                    alarmMessage = splitByMessage[1];
                } else {
                    alarmMessage = "";
                }
                alarmDataSheetExcelForOther.setAlarmCode(alarmCode);
                alarmDataSheetExcelForOther.setAlarmMsg(alarmMessage);
                alarmDataSheetExcelForOther.setCount(String.valueOf(value.size()));
                alarmDataSheetExcelForOtherList.add(alarmDataSheetExcelForOther);
            });
        });
        String fileName = String.format("%s-%s.xlsx", ExcelConstant.ALARM, DateUtil.time());
        MultipartFile multipartFile = ExcelUtil.exportToMultipartFile(fileName, ExcelConstant.ALARM, alarmDataSheetExcelForOtherList, AlarmDataSheetExcelForOther.class);
        return this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
    }
 
    @Override // org.springblade.modules.mdc.service.IAlarmService
    public AlarmSummaryGraphVO summaryGraph(AlarmShiftSearchVO vo) {
        if (Func.isNull(vo.getWorkstationId())) {
            return new AlarmSummaryGraphVO();
        }
        List<SuperAlarm> alarms = this.alarmMapper.queryAlarm(null, vo, DateUtil.format(vo.getQueryTime(), "yyyyMMdd"));
        Map<String, Integer> map = FilterOffUtils.filterOffDay(alarms, OpenTypeEnums.ALARM_ANALYSIS).stream().collect(Collectors.groupingBy((v0) -> {
            return v0.getCode();
        }, Collectors.reducing(0, e -> {
            return 1;
        }, (v0, v1) -> {
            return Integer.sum(v0, v1);
        })));
        return AlarmSummaryGraphVO.builder().res(map).build();
    }
 
    @Override // org.springblade.modules.mdc.service.IAlarmService
    public List<AlarmDataSheetShiftVO> listShiftAlarm(AlarmShiftSearchVO vo) {
        String shift = MessageUtils.message("mdc.excel.alarm.shift", new Object[0]);
        List<ShiftInfoDTO> shiftInfoDtoList = this.shiftDetailService.getShiftInfoDtoList(Lists.newArrayList(new Long[]{vo.getWorkstationId()}), vo.getQueryTime(), vo.getQueryTime());
        if (Func.isEmpty(shiftInfoDtoList)) {
            return new ArrayList();
        }
        return shiftInfoDtoList.stream().map(shiftInfoDTO -> {
            AlarmDataSheetShiftVO alarmDataSheetShiftVO = new AlarmDataSheetShiftVO();
            vo.setShiftIndex(shiftInfoDTO.getShiftIndex());
            Query query = new Query();
            query.setSize(-1);
            query.setCurrent(1);
            List<AlarmDataSheetVO> alarmDataSheetVOList = pageAlarm(query, vo).getRecords();
            alarmDataSheetShiftVO.setShiftIndex(shiftInfoDTO.getShiftIndex());
            alarmDataSheetShiftVO.setShiftName(Func.isNotEmpty(shiftInfoDTO.getIndexName()) ? shiftInfoDTO.getIndexName() : StrUtil.format("{}{}", new Object[]{shift, shiftInfoDTO.getShiftIndex()}));
            alarmDataSheetShiftVO.setAlarmDataSheetVOList(alarmDataSheetVOList);
            return alarmDataSheetShiftVO;
        }).collect(Collectors.toList());
    }
 
    @Override // org.springblade.modules.mdc.service.IAlarmService
    public List<AlarmSummaryGraphShiftVO> summaryShiftGraph(AlarmShiftSearchVO vo) {
        String shift = MessageUtils.message("mdc.excel.alarm.shift", new Object[0]);
        List<ShiftInfoDTO> shiftInfoDtoList = this.shiftDetailService.getShiftInfoDtoList(Lists.newArrayList(new Long[]{vo.getWorkstationId()}), vo.getQueryTime(), vo.getQueryTime());
        if (Func.isEmpty(shiftInfoDtoList)) {
            return new ArrayList<>();
        }
        return shiftInfoDtoList.stream().map(shiftInfoDTO -> {
            AlarmSummaryGraphShiftVO alarmSummaryGraphShiftVO = new AlarmSummaryGraphShiftVO();
            alarmSummaryGraphShiftVO.setShiftIndex(shiftInfoDTO.getShiftIndex());
            alarmSummaryGraphShiftVO.setShiftIndexName(Func.isNotEmpty(shiftInfoDTO.getIndexName()) ? shiftInfoDTO.getIndexName() : StrUtil.format("{}{}", new Object[]{shift, shiftInfoDTO.getShiftIndex()}));
            vo.setShiftIndex(shiftInfoDTO.getShiftIndex());
            AlarmSummaryGraphVO alarmSummaryGraphVO = summaryGraph(vo);
            alarmSummaryGraphShiftVO.setRes(alarmSummaryGraphVO.getRes());
            return alarmSummaryGraphShiftVO;
        }).collect(Collectors.toList());
    }
 
    private List<AlarmDataSheetExcelForOther> getDayData(AlarmShiftSearchExcelVO vo, WorkstationVO workstationVO) {
        List<SuperAlarm> list = this.alarmMapper.selectAllAlarm(vo, DateUtil.format(vo.getStartTime(), "yyyyMMdd"), DateUtil.format(vo.getEndTime(), "yyyyMMdd"), null, null);
        List<SuperAlarm> tempList = new ArrayList<>();
        Set<String> set = new HashSet<>();
        list.forEach(i -> {
            if (!set.contains(i.getCode() + i.getMessage() + i.getFactoryDate())) {
                tempList.add(i);
                set.add(i.getCode() + i.getMessage() + i.getFactoryDate());
            }
        });
        Map<String, List<SuperAlarm>> countMap = tempList.stream().collect(Collectors.groupingBy(c -> {
            return c.getFactoryDate() + c.getCode();
        }));
        List<AlarmDataSheetExcelForOther> result = new ArrayList<>();
        for (Map.Entry<String, List<SuperAlarm>> entry : countMap.entrySet()) {
            if (CollectionUtil.isNotEmpty(entry.getValue())) {
                AlarmDataSheetExcelForOther alarmDataSheetExcelForOther = new AlarmDataSheetExcelForOther();
                LocalDate localDate = LocalDateUtil.stringToLocalDate(String.valueOf(entry.getValue().get(0).getFactoryDate()), "yyyyMMdd");
                alarmDataSheetExcelForOther.setDate(localDate.format(DateTimeFormatter.ofPattern(DateConstant.PATTERN_DATE)));
                alarmDataSheetExcelForOther.setWorkstationGroup(workstationVO.getGroupName());
                alarmDataSheetExcelForOther.setWorkstationCode(workstationVO.getCode());
                alarmDataSheetExcelForOther.setWorkstationName(workstationVO.getName());
                alarmDataSheetExcelForOther.setAlarmCode(entry.getValue().get(0).getCode());
                alarmDataSheetExcelForOther.setAlarmMsg(entry.getValue().get(0).getMessage());
                alarmDataSheetExcelForOther.setCount(String.valueOf(entry.getValue().size()));
                result.add(alarmDataSheetExcelForOther);
            }
        }
        return result;
    }
 
    /* JADX WARN: Multi-variable type inference failed */
    private List<AlarmDataSheetExcelForOther> getMonthOrWeekDate(Map<Integer, List<Integer>> map, AlarmShiftSearchExcelVO vo, WorkstationVO workstationVO) {
        List<SuperAlarm> list = new ArrayList<>();
        for (Map.Entry<Integer, List<Integer>> entry : map.entrySet()) {
            list.addAll(this.alarmMapper.selectAllAlarm(vo, null, null, entry.getKey(), entry.getValue()));
        }
        List<SuperAlarm> tempList = new ArrayList<>();
        Set<String> set = new HashSet<>();
        list.forEach(i -> {
            if (!set.contains(i.getCode() + i.getMessage() + i.getFactoryDate())) {
                tempList.add(i);
                set.add(i.getCode() + i.getMessage() + i.getFactoryDate());
            }
        });
        Map<String, List<SuperAlarm>> countMap = new HashMap<>();
        if (StatisticalMethodEnum.WEEK.equals(vo.getEnums())) {
            countMap = tempList.stream().collect(Collectors.groupingBy(c -> {
                return c.getFactoryYear() + "" + c.getFactoryWeek() + c.getCode();
            }));
        }
        if (StatisticalMethodEnum.MONTH.equals(vo.getEnums())) {
            countMap = tempList.stream().collect(Collectors.groupingBy(c2 -> {
                return c2.getFactoryYear() + "" + c2.getFactoryMonth() + c2.getCode();
            }));
        }
        List<AlarmDataSheetExcelForOther> result = new ArrayList<>();
        for (Map.Entry<String, List<SuperAlarm>> entry2 : countMap.entrySet()) {
            if (CollectionUtil.isNotEmpty(entry2.getValue())) {
                AlarmDataSheetExcelForOther alarmDataSheetExcelForOther = new AlarmDataSheetExcelForOther();
                if (StatisticalMethodEnum.WEEK.equals(vo.getEnums())) {
                    alarmDataSheetExcelForOther.setDate(StrUtil.format("{}-第{}周", new Object[]{entry2.getValue().get(0).getFactoryYear(), entry2.getValue().get(0).getFactoryWeek()}));
                }
                if (StatisticalMethodEnum.MONTH.equals(vo.getEnums())) {
                    alarmDataSheetExcelForOther.setDate(StrUtil.format("{}-{}", new Object[]{entry2.getValue().get(0).getFactoryYear(), entry2.getValue().get(0).getFactoryMonth()}));
                }
                alarmDataSheetExcelForOther.setWorkstationGroup(workstationVO.getGroupName());
                alarmDataSheetExcelForOther.setWorkstationCode(workstationVO.getCode());
                alarmDataSheetExcelForOther.setWorkstationName(workstationVO.getName());
                alarmDataSheetExcelForOther.setAlarmCode(entry2.getValue().get(0).getCode());
                alarmDataSheetExcelForOther.setAlarmMsg(entry2.getValue().get(0).getMessage());
                alarmDataSheetExcelForOther.setCount(String.valueOf(entry2.getValue().size()));
                result.add(alarmDataSheetExcelForOther);
            }
        }
        return result;
    }
 
    Map<Integer, List<Integer>> organizeQuery(SplitFilterListVO splitFilterListVO, AlarmShiftSearchExcelVO vo) {
        Map<Integer, List<Integer>> map = new HashMap<>();
        splitFilterListVO.getItems().forEach(i -> {
            if (map.containsKey(i.getYear())) {
                if (StatisticalMethodEnum.WEEK.equals(vo.getEnums())) {
                    List<Integer> week =  map.get(i.getYear());
                    week.add(i.getWeek());
                    map.put(i.getYear(), week);
                }
                if (StatisticalMethodEnum.MONTH.equals(vo.getEnums())) {
                    List<Integer> month =  map.get(i.getYear());
                    month.add(i.getMonth());
                    map.put(i.getYear(), month);
                    return;
                }
                return;
            }
            if (StatisticalMethodEnum.WEEK.equals(vo.getEnums())) {
                List<Integer> arrayList = new ArrayList<>();
                arrayList.add(i.getWeek());
                map.put(i.getYear(), arrayList);
            }
            if (StatisticalMethodEnum.MONTH.equals(vo.getEnums())) {
                List<Integer> arrayList2 = new ArrayList<>();
                arrayList2.add(i.getMonth());
                map.put(i.getYear(), arrayList2);
            }
        });
        return map;
    }
}