yangys
2024-04-02 b773661de485d9748386bfdd15a7ac7cd399be36
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
package com.qianwen.smartman.modules.visual.service.impl;
 
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 org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.qianwen.core.tool.node.ForestNodeMerger;
import com.qianwen.core.tool.utils.Func;
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.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;
 
@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;
 
 
    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);
        
        List<WorkStationTreeVO> vos = hasChildGroup(list).stream().map(CommonGroupConvert.INSTANCE::convertToChart).collect(Collectors.toList());
        /*
        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 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.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 =  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 = 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);
        }
        
        List<WorkStationTreeVO> vos = hasChildGroup(collect).stream().map(CommonGroupConvert.INSTANCE::convertToChart).collect(Collectors.toList());
        /*
        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 = 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.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 this.commonGroupService.getOne(Wrappers.<CommonGroup>lambdaQuery()
                .eq(CommonGroup::getGroupCategory, CommonGroupConstant.DEFAULT_CATEGORY)
                .eq(CommonGroup::getGroupType, CommonGroupTypeEnum.WORKSTATION.getName())
                .eq(CommonGroup::getParentId, CommonGroupConstant.ROOT));
        /*
        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));*/
    }
}