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
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
package com.qianwen.smartman.modules.visual.service.impl;
 
import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import java.lang.invoke.SerializedLambda;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import com.qianwen.smartman.common.cache.cps.TimeSliceCache;
import com.qianwen.smartman.common.constant.DateConstant;
import com.qianwen.smartman.common.constant.VisualConstant;
import com.qianwen.smartman.common.utils.Lambda;
import com.qianwen.core.tool.utils.DateUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.dto.CalendarShiftTimeSlicesDTO;
import com.qianwen.smartman.modules.cps.entity.Workstation;
import com.qianwen.smartman.modules.cps.entity.WorkstationWcsUsage;
import com.qianwen.smartman.modules.cps.service.IWorkstationService;
import com.qianwen.smartman.modules.cps.service.IWorkstationWcsUsageService;
import com.qianwen.smartman.modules.mdc.entity.SuperAggregateOutput;
import com.qianwen.smartman.modules.mdc.enums.OpenTypeEnums;
import com.qianwen.smartman.modules.mdc.mapper.SuperAggregateOutputMapper;
import com.qianwen.smartman.modules.mdc.utils.FilterOffUtils;
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.tdengine.service.IWorkstationDynamicCollectService;
import com.qianwen.smartman.modules.visual.dto.DynamicCountDateAggregateDTO;
import com.qianwen.smartman.modules.visual.dto.VisualTimeDTO;
import com.qianwen.smartman.modules.visual.service.IVisualOutputService;
import com.qianwen.smartman.modules.visual.utils.VisualUtils;
import com.qianwen.smartman.modules.visual.vo.VisualSingleBaseVO;
import com.qianwen.smartman.modules.visual.vo.VisualUsagePolicyEnum;
import com.qianwen.smartman.modules.visual.vo.WorkstationCountVisualQueryVO;
import com.qianwen.smartman.modules.visual.vo.WorkstationShiftOutput;
import com.qianwen.smartman.modules.visual.wrapper.OutputWrapper;
import org.springframework.stereotype.Service;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/visual/service/impl/VisualOutputServiceImpl.class */
public class VisualOutputServiceImpl implements IVisualOutputService {
    private final SuperAggregateOutputMapper superAggregateOutputMapper;
    private final IWorkstationService workstationService;
    private final OutputWrapper outputWrapper;
    private final IWorkstationDynamicCollectService dynamicCollectService;
    private final IWorkstationWcsUsageService workstationWcsUsageService;
 
    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
        String implMethodName = lambda.getImplMethodName();
        boolean z = true;
        switch (implMethodName.hashCode()) {
            case 98245393:
                if (implMethodName.equals("getId")) {
                    z = true;
                    break;
                }
                break;
            case 764041336:
                if (implMethodName.equals("getUsageCode")) {
                    z = false;
                    break;
                }
                break;
        }
        switch (z) {
            case false:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/WorkstationWcsUsage") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getUsageCode();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getId();
                    };
                }
                break;
        }
        throw new IllegalArgumentException("Invalid lambda deserialization");
    }
 
    public VisualOutputServiceImpl(final SuperAggregateOutputMapper superAggregateOutputMapper, final IWorkstationService workstationService, final OutputWrapper outputWrapper, final IWorkstationDynamicCollectService dynamicCollectService, final IWorkstationWcsUsageService workstationWcsUsageService) {
        this.superAggregateOutputMapper = superAggregateOutputMapper;
        this.workstationService = workstationService;
        this.outputWrapper = outputWrapper;
        this.dynamicCollectService = dynamicCollectService;
        this.workstationWcsUsageService = workstationWcsUsageService;
    }
 
    @Override // org.springblade.modules.visual.service.IVisualOutputService
    public ChartSeriesDataVO getWorkstationHoursOutput(VisualSingleBaseVO visualBaseVO) {
        List<String> xList = new ArrayList<>();
        Long workstationId = visualBaseVO.getWorkStationId();
        String timeLevel = visualBaseVO.getTimeLevel();
        int level = Integer.parseInt(timeLevel);
        List<LocalDateTime> localDateTimes = getLocalDateTime(Integer.valueOf(level));
        for (LocalDateTime time : localDateTimes) {
            int dayOfMonth = time.getDayOfMonth();
            int hour = time.getHour();
            xList.add(dayOfMonth + "-" + hour);
        }
        VisualTimeDTO visualTimeDTO = VisualUtils.getTimeSectionByLevel(timeLevel);
        LocalDateTime startTime = visualTimeDTO.getStartTime();
        LocalDateTime endTime = visualTimeDTO.getEndTime();
        String name = ((Workstation) this.workstationService.getById(workstationId)).getName();
        List<SuperAggregateOutput> outputList = this.superAggregateOutputMapper.getOutputDataByWorkstationAndFactoryDate(workstationId, LocalDateTimeUtil.format(startTime, DateConstant.PATTERN_DATE_TIME), LocalDateTimeUtil.format(endTime, DateConstant.PATTERN_DATE_TIME));
        return this.outputWrapper.getWorkstationOutput(outputList, xList, name, 1);
    }
 
    @Override // org.springblade.modules.visual.service.IVisualOutputService
    public ChartSeriesDataVO getWorkstationDaysOutput(VisualSingleBaseVO visualBaseVO) {
        Long workstationId = visualBaseVO.getWorkStationId();
        String timeLevel = visualBaseVO.getTimeLevel();
        VisualTimeDTO timeSectionByLevel = VisualUtils.getTimeSectionDayByLevel(timeLevel);
        LocalDateTime startTime = timeSectionByLevel.getStartTime();
        LocalDateTime endTime = timeSectionByLevel.getEndTime();
        List<String> xList = getLocalDate(Integer.valueOf(timeLevel));
        String name = ((Workstation) this.workstationService.getById(workstationId)).getName();
        List<SuperAggregateOutput> outputList = this.superAggregateOutputMapper.getOutputDataByWorkstationAndFactoryDate(workstationId, LocalDateTimeUtil.format(startTime, DateConstant.PATTERN_DATE_TIME), LocalDateTimeUtil.format(endTime, DateConstant.PATTERN_DATE_TIME));
        return this.outputWrapper.getWorkstationOutput(outputList, xList, name, 2);
    }
 
    @Override // org.springblade.modules.visual.service.IVisualOutputService
    public ChartSeriesDataVO getShiftIndexOutput(WorkstationShiftOutput workstationShiftOutput) {
        WorkstationChartSeriesDataVO chartSeriesDataVO = new WorkstationChartSeriesDataVO();
        List<Workstation> xList = new ArrayList<>();
        List<Long> workStationIdList = workstationShiftOutput.getWorkStationIdList();
        ArrayList arrayList = new ArrayList();
        List<Workstation> list = this.workstationService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getId();
        }, workStationIdList));
        if (Func.isNotEmpty(list)) {
            ArrayList arrayList2 = new ArrayList();
            list.forEach(s -> {
                xList.add(s);
                String calendarCode = s.getCalendarCode();
                if (Func.isNotBlank(calendarCode)) {
                    CalendarShiftTimeSlicesDTO timeSliceShift = TimeSliceCache.getTimeSliceShift(calendarCode, DateUtil.now());
                    if (timeSliceShift != null) {
                        List<SuperAggregateOutput> superAggregateOutputList = this.superAggregateOutputMapper.getShiftOutput(Lists.newArrayList(new Long[]{s.getId()}), timeSliceShift.getShiftIndex(), Integer.valueOf(Func.toInt(timeSliceShift.getFactoryDate().replaceAll("-", ""))));
                        long sum = FilterOffUtils.filterOffDay(superAggregateOutputList, OpenTypeEnums.OUT_PUT).stream().mapToLong((v0) -> {
                            return v0.getOutput();
                        }).sum();
                        arrayList.add(Long.valueOf(sum));
                        return;
                    }
                    arrayList.add(0L);
                    return;
                }
                arrayList.add(0L);
            });
            SeriesItem seriesItem = new SeriesItem();
            seriesItem.setName(VisualConstant.SHIFT_OUTPUT);
            seriesItem.setData(arrayList);
            arrayList2.add(seriesItem);
            chartSeriesDataVO.generateCategories(xList, 3);
            chartSeriesDataVO.setSeries(arrayList2);
        }
        return chartSeriesDataVO;
    }
 
    private List<String> getLocalDate(Integer day) {
        List<String> list = Lists.newArrayList();
        LocalDate sevenDay = LocalDate.now();
        for (int i = day.intValue(); i >= 0; i--) {
            LocalDate localDate = sevenDay.minusDays(i);
            list.add(LocalDateTimeUtil.format(localDate, DateConstant.PATTERN_DATE));
        }
        return list;
    }
 
    private List<LocalDateTime> getLocalDateTime(Integer day) {
        List<LocalDateTime> list = Lists.newArrayList();
        LocalDateTime sevenDay = LocalDateTime.now();
        for (int i = day.intValue(); i >= 0; i--) {
            LocalDateTime localDateTime = sevenDay.minusHours(i);
            list.add(localDateTime);
        }
        return list;
    }
 
    @Override // org.springblade.modules.visual.service.IVisualOutputService
    public ChartSeriesDataVO getCountPulseOutput(final WorkstationCountVisualQueryVO visualQueryVO) {
        DynamicCountDateAggregateDTO visualCountDateAggregateDTO;
        WorkstationWcsUsage workstationWcsUsage = (WorkstationWcsUsage) this.workstationWcsUsageService.getOne(Lambda.eq((v0) -> {
            return v0.getUsageCode();
        }, visualQueryVO.getUsageCode()));
        if (workstationWcsUsage == null) {
            return null;
        }
        if (visualQueryVO.getPolicy().equals(VisualUsagePolicyEnum.SHIFT)) {
            visualCountDateAggregateDTO = this.dynamicCollectService.getShiftOutput(visualQueryVO.getWorkStationIdList(), workstationWcsUsage);
        } else {
            visualCountDateAggregateDTO = this.dynamicCollectService.getOutputDataByWorkstationAndFactoryDate(visualQueryVO.getWorkStationIdList(), visualQueryVO.getTimeLevel(), visualQueryVO.getPolicy(), workstationWcsUsage);
        }
        return visualQueryVO.getPolicy().wrapper(visualCountDateAggregateDTO);
    }
}