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
204
205
package com.qianwen.smartman.modules.visual.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import java.lang.invoke.SerializedLambda;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.qianwen.smartman.common.cache.cps.TimeSliceCache;
import com.qianwen.smartman.common.cache.cps.WorkstationCache;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.smartman.common.constant.CommonGroupConstant;
import com.qianwen.smartman.common.constant.VisualConstant;
import com.qianwen.smartman.common.enums.CommonGroupTypeEnum;
import com.qianwen.core.tool.node.ForestNodeMerger;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.convert.CommonGroupConvert;
import com.qianwen.smartman.modules.cps.dto.CurrentShiftInfoDTO;
import com.qianwen.smartman.modules.cps.entity.CommonGroup;
import com.qianwen.smartman.modules.cps.entity.ShiftModel;
import com.qianwen.smartman.modules.cps.service.ICalendarService;
import com.qianwen.smartman.modules.cps.service.ICommonGroupService;
import com.qianwen.smartman.modules.cps.service.IShiftModelService;
import com.qianwen.smartman.modules.cps.vo.CommonGroupTypeVO;
import com.qianwen.smartman.modules.cps.vo.WorkstationInGroupVO;
import com.qianwen.smartman.modules.system.entity.Dict;
import com.qianwen.smartman.modules.system.service.IDictService;
import com.qianwen.smartman.modules.visual.service.IVisualDataSourceService;
import com.qianwen.smartman.modules.visual.vo.DropDownVO;
import com.qianwen.smartman.modules.visual.vo.WorkStationTreeVO;
import org.springframework.stereotype.Service;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/visual/service/impl/VisualDataSourceServiceImpl.class */
public class VisualDataSourceServiceImpl implements IVisualDataSourceService {
    private final ICommonGroupService commonGroupService;
    private final IDictService dictService;
    private final IShiftModelService shiftModelService;
    private final ICalendarService calendarService;
 
    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
        String implMethodName = lambda.getImplMethodName();
        boolean z = true;
        switch (implMethodName.hashCode()) {
            case -1492577373:
                if (implMethodName.equals("getGroupType")) {
                    z = false;
                    break;
                }
                break;
            case -1041904421:
                if (implMethodName.equals("getParentId")) {
                    z = true;
                    break;
                }
                break;
            case 985326823:
                if (implMethodName.equals("getGroupCategory")) {
                    z = true;
                    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/CommonGroup") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getGroupType();
                    };
                }
                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/modules/cps/entity/CommonGroup") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getGroupCategory();
                    };
                }
                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/modules/cps/entity/CommonGroup") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getParentId();
                    };
                }
                break;
        }
        throw new IllegalArgumentException("Invalid lambda deserialization");
    }
 
    public VisualDataSourceServiceImpl(final ICommonGroupService commonGroupService, final IDictService dictService, final IShiftModelService shiftModelService, final ICalendarService calendarService) {
        this.commonGroupService = commonGroupService;
        this.dictService = dictService;
        this.shiftModelService = shiftModelService;
        this.calendarService = calendarService;
    }
 
    @Override // org.springblade.modules.visual.service.IVisualDataSourceService
    public List<WorkStationTreeVO> workstationDataSource() {
        CommonGroupTypeVO commonGroupTypeVO = new CommonGroupTypeVO().setGroupCategory(CommonGroupConstant.DEFAULT_CATEGORY).setStatus(CommonConstant.ENABLE).setGroupType(CommonGroupTypeEnum.WORKSTATION.getName());
        List<WorkstationInGroupVO> list = this.commonGroupService.groupWorkstationList(commonGroupTypeVO);
        Stream<WorkstationInGroupVO> stream = hasChildGroup(list).stream();
        CommonGroupConvert commonGroupConvert = CommonGroupConvert.INSTANCE;
        commonGroupConvert.getClass();
        List<WorkStationTreeVO> vos = (List) stream.map(this::convertToChart).collect(Collectors.toList());
        return ForestNodeMerger.merge(vos);
    }
 
    @Override // org.springblade.modules.visual.service.IVisualDataSourceService
    public List<DropDownVO> timeLevelDataSource() {
        List<Dict> dictList = this.dictService.getList(VisualConstant.VISUAL_TIME_LEVEL);
        return (List) dictList.stream().map(dict -> {
            return DropDownVO.builder().id(dict.getDictKey()).name(dict.getDictValue()).build();
        }).collect(Collectors.toList());
    }
 
    /* JADX WARN: Multi-variable type inference failed */
    @Override // org.springblade.modules.visual.service.IVisualDataSourceService
    public List<DropDownVO> shiftSystem() {
        List<ShiftModel> list = this.shiftModelService.list();
        List<DropDownVO> dropDownVOList = new ArrayList<>();
        if (Func.isNotEmpty(list)) {
            dropDownVOList = (List) list.stream().map(shiftModel -> {
                return DropDownVO.builder().id(String.valueOf(shiftModel.getId())).name(shiftModel.getName()).build();
            }).collect(Collectors.toList());
        }
        return dropDownVOList;
    }
 
    @Override // org.springblade.modules.visual.service.IVisualDataSourceService
    public List<WorkStationTreeVO> shiftWorkStation(Long id) {
        List<WorkstationInGroupVO> collect = WorkstationCache.getShiftWorkStation(id);
        if (Func.isEmpty(collect)) {
            CommonGroupTypeVO commonGroupTypeVO = new CommonGroupTypeVO().setGroupCategory(CommonGroupConstant.DEFAULT_CATEGORY).setStatus(CommonConstant.ENABLE).setGroupType(CommonGroupTypeEnum.WORKSTATION.getName());
            List<WorkstationInGroupVO> commonList = this.commonGroupService.groupWorkstationList(commonGroupTypeVO);
            List<String> calendarCodeList = (List) commonList.stream().map((v0) -> {
                return v0.getCalendarCode();
            }).filter((v0) -> {
                return Func.isNotEmpty(v0);
            }).distinct().collect(Collectors.toList());
            Map<String, CurrentShiftInfoDTO> currentShiftInfo = TimeSliceCache.getCurrentShiftInfo(calendarCodeList);
            collect = (List) commonList.stream().filter(workstationInGroupVO -> {
                CurrentShiftInfoDTO currentShiftInfoDTO = (CurrentShiftInfoDTO) currentShiftInfo.get(workstationInGroupVO.getCalendarCode());
                Boolean flag = workstationInGroupVO.getIsGroup();
                if (Func.isNotEmpty(currentShiftInfoDTO)) {
                    Long modelId = this.calendarService.getShiftModelByFactoryDay(workstationInGroupVO.getCalendarCode(), currentShiftInfoDTO.getFactoryDay());
                    flag = Boolean.valueOf(id.equals(modelId));
                }
                return flag.booleanValue();
            }).collect(Collectors.toList());
            WorkstationCache.setShiftWorkStation(collect, id);
        }
        Stream<WorkstationInGroupVO> stream = hasChildGroup(collect).stream();
        CommonGroupConvert commonGroupConvert = CommonGroupConvert.INSTANCE;
        commonGroupConvert.getClass();
        List<WorkStationTreeVO> vos = (List) stream.map(this::convertToChart).collect(Collectors.toList());
        return ForestNodeMerger.merge(vos);
    }
 
    private List<WorkstationInGroupVO> hasChildGroup(List<WorkstationInGroupVO> list) {
        Set<Long> groupIds = (Set) list.stream().filter((v0) -> {
            return v0.getIsWorkstation();
        }).map((v0) -> {
            return v0.getParentId();
        }).filter((v0) -> {
            return Func.isNotEmpty(v0);
        }).collect(Collectors.toSet());
        CommonGroup root = findRoot();
        Set<Long> res = new HashSet<>(groupIds);
        res.add(root.getId());
        for (Long groupId : groupIds) {
            buildIds(res, list, groupId, root.getParentId());
        }
        if (res.size() == CommonGroupConstant.SIZE.intValue() && res.contains(root.getId())) {
            return Lists.newArrayList();
        }
        return (List) list.stream().filter(c -> {
            return res.contains(c.getId()) || c.getIsWorkstation().booleanValue();
        }).collect(Collectors.toList());
    }
 
    private void buildIds(Set<Long> ids, List<WorkstationInGroupVO> list, Long id, Long rootId) {
        for (WorkstationInGroupVO workstationInGroupVO : list) {
            if (workstationInGroupVO.getId().equals(id) && !workstationInGroupVO.getParentId().equals(rootId)) {
                ids.add(workstationInGroupVO.getParentId());
                buildIds(ids, list, workstationInGroupVO.getParentId(), rootId);
            }
        }
    }
 
    private CommonGroup findRoot() {
        return (CommonGroup) this.commonGroupService.getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getGroupCategory();
        }, CommonGroupConstant.DEFAULT_CATEGORY)).eq((v0) -> {
            return v0.getGroupType();
        }, CommonGroupTypeEnum.WORKSTATION.getName())).eq((v0) -> {
            return v0.getParentId();
        }, CommonGroupConstant.ROOT));
    }
}