yangys
2024-03-30 871c0fce344b24c8046ec01173eca79b9e60c1d7
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
package com.qianwen.smartman.modules.mdc.service.impl;
 
import cn.hutool.core.util.StrUtil;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.qianwen.smartman.common.constant.DateConstant;
import com.qianwen.smartman.common.utils.LocalDateTimeUtils;
import com.qianwen.smartman.common.utils.LocalDateUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.mdc.dto.IntervalDateDto;
import com.qianwen.smartman.modules.mdc.enums.StatisticalMethodEnum;
import com.qianwen.smartman.modules.mdc.service.IStatisticsService;
import com.qianwen.smartman.modules.mdc.utils.MdcConvertUtil;
import com.qianwen.smartman.modules.mdc.vo.AnalysisFilterVO;
import com.qianwen.smartman.modules.mdc.vo.DateInfo;
import com.qianwen.smartman.modules.mdc.vo.SplitFilterListVO;
import com.qianwen.smartman.modules.mdc.vo.SplitFilterVO;
import org.springframework.stereotype.Service;
 
@Service
public class StatisticsServiceImpl implements IStatisticsService {
    @Override // org.springblade.modules.mdc.service.IStatisticsService
    public SplitFilterListVO organizeQueryConditions(AnalysisFilterVO input) {
        List<IntervalDateDto> intervalDateDtoList;
        Map<String, String> shiftKeyNameMap = MdcConvertUtil.keyNameToMap(input.getShiftList());
        List<DateInfo> result = new ArrayList<>();
        if (Func.isNotEmpty(input.getIsReverse()) && input.getIsReverse().booleanValue()) {
            intervalDateDtoList = LocalDateTimeUtils.getIntervalDateReverse(input.getStartDate(), input.getEndDate());
        } else {
            intervalDateDtoList = LocalDateTimeUtils.getIntervalDate(input.getStartDate(), input.getEndDate());
        }
        if (StatisticalMethodEnum.SHIFT.equals(input.getStatisticalMethod())) {
            buildShiftData(intervalDateDtoList, shiftKeyNameMap, result);
        } else if (StatisticalMethodEnum.DAY.equals(input.getStatisticalMethod())) {
            buildDayData(intervalDateDtoList, result);
        } else if (StatisticalMethodEnum.WEEK.equals(input.getStatisticalMethod())) {
            buildWeekData(intervalDateDtoList, result);
        } else {
            buildMonthData(intervalDateDtoList, result);
        }
        SplitFilterListVO vo = new SplitFilterListVO();
        vo.setItems( result.stream().map(c -> {
            SplitFilterVO voItem = new SplitFilterVO();
            voItem.setTitle(c.getTitle());
            voItem.setDate(c.getDate());
            voItem.setMonth(c.getMonth());
            voItem.setYear(c.getYear());
            voItem.setShiftIndex(c.getShiftIndex());
            voItem.setStatisticalMethod(input.getStatisticalMethod());
            voItem.setWeek(c.getWeek());
            voItem.setWorkStationList(input.getWorkStationList());
            return voItem;
        }).collect(Collectors.toList()));
        return vo;
    }
 
    private void buildMonthData(List<IntervalDateDto> intervalDateDtoList, List<DateInfo> result) {
        intervalDateDtoList.forEach(intervalDateDto -> {
            intervalDateDto.getMonthList().forEach(month -> {
                Integer year = intervalDateDto.getYear();
                String code = StrUtil.format("{}_{}", new Object[]{year, month});
                String title = StrUtil.format("{}-{}", new Object[]{year, month});
                result.add(new DateInfo(code, title, null, null, month, year));
            });
        });
    }
 
    private void buildWeekData(List<IntervalDateDto> intervalDateDtoList, List<DateInfo> result) {
        intervalDateDtoList.forEach(intervalDateDto -> {
            intervalDateDto.getWeekList().forEach(week -> {
                Integer year = intervalDateDto.getYear();
                String code = StrUtil.format("{}_{}", new Object[]{year, week});
                String title = StrUtil.format("{}-{}", new Object[]{year, week});
                result.add(new DateInfo(code, title, null, week, null, year));
            });
        });
    }
 
    private void buildDayData(List<IntervalDateDto> intervalDateDtoList, List<DateInfo> result) {
        IntervalDateDto intervalDateDto = intervalDateDtoList.get(0);
        List<String> dayList = intervalDateDto.getDayList();
        dayList.forEach(day -> {
            LocalDate localDate = LocalDateUtil.stringToLocalDate(day, DateConstant.PATTERN_DATE);
            Integer week = LocalDateTimeUtils.getWeek(localDate);
            Integer month = LocalDateTimeUtils.getMonth(localDate);
            Integer year = LocalDateTimeUtils.getYear(localDate);
            result.add(new DateInfo(day, day, day, week, month, year));
        });
    }
 
    public void buildShiftData(List<IntervalDateDto> intervalDateDtoList, Map<String, String> shiftKeyNameMap, List<DateInfo> result) {
        IntervalDateDto intervalDateDto = intervalDateDtoList.get(0);
        List<String> dayList = intervalDateDto.getDayList();
        dayList.forEach(day -> {
            shiftKeyNameMap.forEach((shiftIndex, shiftName) -> {
                String code = StrUtil.format("{}_{}", new Object[]{day, shiftIndex});
                String title = StrUtil.format("{}-{}", new Object[]{day, shiftKeyNameMap.get(String.valueOf(shiftIndex))});
                LocalDate localDate = LocalDateUtil.stringToLocalDate(day, DateConstant.PATTERN_DATE);
                Integer week = LocalDateTimeUtils.getWeek(localDate);
                Integer month = LocalDateTimeUtils.getMonth(localDate);
                Integer year = LocalDateTimeUtils.getYear(localDate);
                result.add(new DateInfo(code, title, day, week, month, year, Integer.valueOf(shiftIndex)));
            });
        });
    }
}