yangys
2024-03-28 25475f31cd0d52ff328bbea9e80f15647dedd80b
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
package com.qianwen.smartman.modules.cps.service.impl;
 
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.google.common.collect.Sets;
import java.lang.invoke.SerializedLambda;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.compress.utils.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.qianwen.smartman.common.cache.RegionCache;
import com.qianwen.smartman.common.constant.CommonGroupConstant;
import com.qianwen.smartman.common.constant.ExcelConstant;
import com.qianwen.smartman.common.constant.ToolingConstant;
import com.qianwen.smartman.common.enums.CommonGroupTypeEnum;
import com.qianwen.smartman.common.utils.Lambda;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.smartman.common.utils.ValidatorUtils;
import com.qianwen.core.excel.util.ExcelUtil;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.mp.service.impl.BladeServiceImpl;
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.node.ForestNodeMerger;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.convert.ToolAppendixConvert;
import com.qianwen.smartman.modules.cps.convert.TrayConvert;
import com.qianwen.smartman.modules.cps.dto.TrayFaceDTO;
import com.qianwen.smartman.modules.cps.entity.CommonGroup;
import com.qianwen.smartman.modules.cps.entity.CommonGroupOfItem;
import com.qianwen.smartman.modules.cps.entity.ToolAppendix;
import com.qianwen.smartman.modules.cps.entity.Tray;
import com.qianwen.smartman.modules.cps.entity.TrayFixture;
import com.qianwen.smartman.modules.cps.entity.TrayStorage;
import com.qianwen.smartman.modules.cps.entity.TraySurface;
import com.qianwen.smartman.modules.cps.enums.CommonGroupEnum;
import com.qianwen.smartman.modules.cps.enums.TrayEnum;
import com.qianwen.smartman.modules.cps.excel.TrayImport;
import com.qianwen.smartman.modules.cps.mapper.TrayMapper;
import com.qianwen.smartman.modules.cps.service.ICommonGroupOfItemService;
import com.qianwen.smartman.modules.cps.service.ICommonGroupService;
import com.qianwen.smartman.modules.cps.service.IToolAppendixService;
import com.qianwen.smartman.modules.cps.service.ITrayFixtureService;
import com.qianwen.smartman.modules.cps.service.ITrayService;
import com.qianwen.smartman.modules.cps.service.ITrayStorageService;
import com.qianwen.smartman.modules.cps.service.ITraySurfaceService;
import com.qianwen.smartman.modules.cps.utils.ThrowFun;
import com.qianwen.smartman.modules.cps.vo.CommonGroupTypeVO;
import com.qianwen.smartman.modules.cps.vo.IdsVO;
import com.qianwen.smartman.modules.cps.vo.PageTrayVO;
import com.qianwen.smartman.modules.cps.vo.ToolAppendixVO;
import com.qianwen.smartman.modules.cps.vo.ToolingVO;
import com.qianwen.smartman.modules.cps.vo.TrayEasyVO;
import com.qianwen.smartman.modules.cps.vo.TraySaveVO;
import com.qianwen.smartman.modules.cps.vo.TrayTreeVO;
import com.qianwen.smartman.modules.cps.vo.TrayUpdateVO;
import com.qianwen.smartman.modules.cps.vo.TrayVO;
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
import com.qianwen.smartman.modules.system.service.ICodeGeneratorService;
import com.qianwen.smartman.modules.tpm.enums.MetaTypeEnum;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
 
@Service
public class TrayServiceImpl extends BladeServiceImpl<TrayMapper, Tray> implements ITrayService {
    private static final Logger log = LoggerFactory.getLogger(TrayServiceImpl.class);
    private final ITraySurfaceService surfaceService;
    private final ICommonGroupService commonGroupService;
    private final IToolAppendixService toolAppendixService;
    private final ITrayFixtureService fixtureService;
    private final ITrayStorageService storageService;
    private final ICommonGroupOfItemService commonGroupOfItemService;
    private final OssBuilder ossBuilder;
    private final ICodeGeneratorService codeGeneratorService;
 
    public TrayServiceImpl(final ITraySurfaceService surfaceService, final ICommonGroupService commonGroupService, final IToolAppendixService toolAppendixService, final ITrayFixtureService fixtureService, final ITrayStorageService storageService, final ICommonGroupOfItemService commonGroupOfItemService, final OssBuilder ossBuilder, final ICodeGeneratorService codeGeneratorService) {
        this.surfaceService = surfaceService;
        this.commonGroupService = commonGroupService;
        this.toolAppendixService = toolAppendixService;
        this.fixtureService = fixtureService;
        this.storageService = storageService;
        this.commonGroupOfItemService = commonGroupOfItemService;
        this.ossBuilder = ossBuilder;
        this.codeGeneratorService = codeGeneratorService;
    }
 
    @Override // org.springblade.modules.cps.service.ITrayService
    @Transactional(rollbackFor = {Exception.class})
    public TrayVO saveTray(TraySaveVO vo) {
        if (Func.isBlank(vo.getCode())) {
            String code = this.codeGeneratorService.getGeneratorCode(vo, MetaTypeEnum.TRAY.getCode());
            log.info("物料编码规则生成的code:{}", code + " ," + code.length());
            vo.setCode(code);
        }
        validCode(vo.getCode());
        Tray tray = TrayConvert.INSTANCE.convert(vo);
        save(tray);
        Long trayId = tray.getId();
        Long groupId = vo.getGroupId();
        CommonGroupOfItem item = CommonGroupOfItem.builder().groupId(groupId).itemId(trayId).groupType(CommonGroupTypeEnum.TRAY.getName()).groupCategory(CommonGroupConstant.DEFAULT_CATEGORY).build();
        this.commonGroupOfItemService.save(item);
        List<TrayFaceDTO> faceList = vo.getFaceList();
        if (Func.isNotEmpty(faceList)) {
            Set<String> codeSet = Sets.newHashSet();
            List<TraySurface> surfaces = faceList.stream().map(f -> {
                String faceCode = f.getFaceCode();
                String faceName = f.getFaceName();
                codeSet.add(faceCode);
                return new TraySurface().setName(faceName).setCode(faceCode).setProgramCode(f.getProgramCode()).setTrayId(trayId);
            }).collect(Collectors.toList());
            int size = faceList.size();
            if (codeSet.size() != size) {
                throw new ServiceException(MessageUtils.message("cps.tray.face.name.exist", new Object[0]));
            }
            this.surfaceService.saveBatch(surfaces);
        }
        return TrayConvert.INSTANCE.convert(tray).setFaceNumber(Integer.valueOf(Func.isEmpty(faceList) ? 0 : faceList.size()));
    }
 
    @Override // org.springblade.modules.cps.service.ITrayService
    public TrayVO getDetail(Long id) {
        Tray tray = (Tray) getById(id);
        CommonGroupOfItem item = (CommonGroupOfItem) this.commonGroupOfItemService.getOne(Wrappers.<CommonGroupOfItem>lambdaQuery().eq(CommonGroupOfItem::getItemId, id));
        Long groupId = item.getGroupId();
        CommonGroup group = (CommonGroup) this.commonGroupService.getById(groupId);
        long count = this.surfaceService.count(Lambda.eq((v0) -> {
            return v0.getTrayId();
        }, id));
        return TrayConvert.INSTANCE.convert(tray).setFaceNumber(Integer.valueOf(Math.toIntExact(count))).setGroupId(groupId).setGroupName(group.getName());
    }
 
    @Override // org.springblade.modules.cps.service.ITrayService
    public IPage<PageTrayVO> trayPage(Query query, String keyword, Long groupId) {
        if (ToolingConstant.TRAY_ROOT.equals(groupId)) {
            return this.baseMapper.trayPage(Condition.getPage(query), keyword, null);
        }
        return this.baseMapper.trayPage(Condition.getPage(query), keyword, groupId);
    }
 
    @Override // org.springblade.modules.cps.service.ITrayService
    @Transactional(rollbackFor = {Exception.class})
    public Boolean updateTray(TrayUpdateVO vo) {
        Tray tray = TrayConvert.INSTANCE.convert(vo);
        boolean update = updateById(tray);
        
        this.commonGroupOfItemService.update(Wrappers.<CommonGroupOfItem>lambdaUpdate()
                .set(CommonGroupOfItem::getGroupId, vo.getGroupId())
                .eq(CommonGroupOfItem::getItemId, vo.getId()));
        /*
        this.commonGroupOfItemService.update((Wrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set((v0) -> {
            return v0.getGroupId();
        }, vo.getGroupId())).eq((v0) -> {
            return v0.getItemId();
        }, vo.getId()));*/
        Integer availability = vo.getAvailability();
        boolean flag = Func.isNotEmpty(availability);
        if (flag) {
            this.baseMapper.updateFixTure(vo.getId(), availability);
        }
        return Boolean.valueOf(update);
    }
 
    @Override // org.springblade.modules.cps.service.ITrayService
    @Transactional(rollbackFor = {Exception.class})
    public Boolean removeTray(IdsVO vo) {
        List<Long> ids = Func.toLongList(vo.getIds());
        int count = removeFaceFixture(ids);
        ThrowFun.isTrue(count > 0).throwMessage(MessageUtils.message("cps.tray.face.banding.fixture", new Object[0]));
        long countTrayStorage = this.storageService.count(Wrappers.<TrayStorage>lambdaQuery().in(TrayStorage::getTrayId, ids));
        ThrowFun.isTrue(countTrayStorage > 0).throwMessage(MessageUtils.message("cps.tray.ware.station.fixture", new Object[0]));
        boolean remove = removeByIds(ids);
        boolean removeFace = this.surfaceService.remove(Wrappers.<TraySurface>lambdaQuery().in(TraySurface::getTrayId, ids));
        boolean removeFixture = this.fixtureService.remove(Wrappers.<TrayFixture>lambdaQuery().in(TrayFixture::getTrayId, ids));
        this.fixtureService.updateFixtureStatusByTray(ids);
        this.storageService.remove(Wrappers.<TrayStorage>lambdaQuery().in(TrayStorage::getTrayId, ids));
        return Boolean.valueOf(remove && removeFace && removeFixture);
    }
 
    @Override // org.springblade.modules.cps.service.ITrayService
    public List<ToolingVO> toolingTree(CommonGroupTypeVO vo) {
        switch (CommonGroupTypeEnum.of(vo.getGroupType())) {
            case TRAY:
                return groupTrayTree(vo);
            case FIXTURE:
                return groupFixtureTree(vo);
            default:
                return Lists.newArrayList();
        }
    }
 
    @Override // org.springblade.modules.cps.service.ITrayService
    @Transactional(rollbackFor = {Exception.class})
    public Boolean removeTree(Long id) {
        CommonGroup group = (CommonGroup) this.commonGroupService.getById(id);
        
        CommonGroup rootGroup = this.commonGroupService.getOne(Wrappers.<CommonGroup>lambdaQuery()
                .eq(CommonGroup::getGroupCategory, group.getGroupCategory())
                .eq(CommonGroup::getGroupType, group.getGroupType())
                .eq(CommonGroup::getName, CommonGroupConstant.DEFAULT_GROUP_NAME));
        
        List<CommonGroup> allSubGroup = this.commonGroupService.getAllSubGroup(Long.valueOf(Func.toLong(id)), group.getGroupType(), group.getGroupCategory());
        List<Long> groupId = allSubGroup.stream().map((v0) -> {
            return v0.getId();
        }).collect(Collectors.toList());
        
        boolean update = this.commonGroupOfItemService.update(Wrappers.<CommonGroupOfItem>lambdaUpdate()
                .set(CommonGroupOfItem::getGroupId, rootGroup.getId())
                .in(CommonGroupOfItem::getGroupId, groupId));
        
        /*
        boolean update = this.commonGroupOfItemService.update((Wrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set((v0) -> {
            return v0.getGroupId();
        }, rootGroup.getId())).in((v0) -> {
            return v0.getGroupId();
        }, groupId));*/
        boolean remove = this.commonGroupService.removeById(id);
        return Boolean.valueOf(update && remove);
    }
 
    @Override // org.springblade.modules.cps.service.ITrayService
    public List<TrayTreeVO> trayTree(CommonGroupTypeVO vo) {
        List<TrayTreeVO> trayTree = this.baseMapper.groupTray();
        return getTrayTree(trayTree, vo);
    }
 
    @Override // org.springblade.modules.cps.service.ITrayService
    public List<ToolAppendixVO> listToolAppendix(String id) {
        List<ToolAppendix> appendixList = this.toolAppendixService.list(Wrappers.<ToolAppendix>lambdaQuery()
                .eq(ToolAppendix::getParentId, id));
        /*
        List<ToolAppendix> appendixList = this.toolAppendixService.list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getParentId();
        }, id));*/
        return ToolAppendixConvert.INSTANCE.convert(appendixList);
    }
 
    @Override // org.springblade.modules.cps.service.ITrayService
    public List<TrayTreeVO> unUsedTrayTree(CommonGroupTypeVO vo) {
        List<TrayTreeVO> trayTree = this.baseMapper.unUsedGroupTray();
        return getUnUsedTray(trayTree);
    }
 
    @Override // org.springblade.modules.cps.service.ITrayService
    public List<TrayEasyVO> listTray() {
        List<Tray> list = list(Wrappers.<Tray>lambdaQuery()
                .orderByDesc(Arrays.asList(Tray::getCreateTime, Tray::getId) ));
        /*
        List<Tray> list = list((Wrapper) Wrappers.lambdaQuery().orderByDesc((v0) -> {
            return v0.getCreateTime();
        }, new SFunction[]{(v0) -> {
            return v0.getId();
        }}));*/
        return TrayConvert.INSTANCE.convertVO(list);
    }
 
    @Override // org.springblade.modules.cps.service.ITrayService
    @Transactional(rollbackFor = {Exception.class})
    public BladeFile importTray(MultipartFile file) {
        if (Objects.isNull(file)) {
            throw new ServiceException(MessageUtils.message("excel.import.file.is.null", new Object[0]));
        }
        List<TrayImport> trayData = ExcelUtil.read(file, 0, 2, TrayImport.class);
        if (Func.isEmpty(trayData)) {
            throw new ServiceException(MessageUtils.message("excel.import.data.can.not.be.null", new Object[0]));
        }
        if (trayData.size() > 200) {
            throw new ServiceException(MessageUtils.message("excel.import.size.failed", new Object[0]));
        }
        Set<String> trayCodeSet = list().stream().map((v0) -> {
            return v0.getCode();
        }).collect(Collectors.toSet());
        Map<String, List<TrayImport>> map = trayData.stream().filter(c -> {
            return Func.isNotEmpty(c.getTrayCode());
        }).collect(Collectors.groupingBy((v0) -> {
            return v0.getTrayCode();
        }));
        HashMap<String, Long> commonGroupNameMap = this.commonGroupService.getCommonGroupNameMap(CommonGroupTypeEnum.TRAY.getName(), CommonGroupConstant.DEFAULT_CATEGORY);
        checkTrayImport(trayData, commonGroupNameMap, map, trayCodeSet);
        List<TrayImport> fails = trayData.stream().filter(w -> {
            return StrUtil.isNotEmpty(w.getFailReason());
        }).collect(Collectors.toList());
        if (fails.size() > 0) {
            MultipartFile template = ExcelUtil.exportFillTemplateToMultipartFile(ExcelConstant.DIRECTORY + "trayImportErrorTemplate" + ExcelConstant.SUFFIX, MessageUtils.message("excel.import.failed.report.name", new Object[0]) + ExcelConstant.SUFFIX, "托盘信息表", trayData.stream().filter(x -> {
                return Func.isNotEmpty(x.getFailReason());
            }).collect(Collectors.toList()), (Object) null, (AbstractMergeStrategy) null);
            return this.ossBuilder.tempTemplate().putFile(template.getOriginalFilename(), template);
        }
        trayData.forEach(trayImport -> {
            if (trayImport.getTrayGroupName().equals(CommonGroupEnum.ALL.getCode())) {
                trayImport.setTrayGroupName(CommonGroupEnum.UNASSORTED.getCode());
            }
            if (trayCodeSet.contains(trayImport.getTrayCode())) {
                update(Wrappers.<Tray>update().lambda().eq(Tray::getCode, trayImport.getTrayCode()).set(Tray::getName, trayImport.getName()));
                /*
                update((Wrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().eq((v0) -> {
                    return v0.getCode();
                }, trayImport.getTrayCode())).set((v0) -> {
                    return v0.getName();
                }, trayImport.getName()));*/
                Tray tray = getOne(Wrappers.<Tray>query().lambda().eq(Tray::getCode, trayImport.getTrayCode()));
                this.commonGroupOfItemService.update(Wrappers.<CommonGroupOfItem>update().lambda()
                        .eq(CommonGroupOfItem::getItemId, tray.getId())
                        .set(CommonGroupOfItem::getGroupId, commonGroupNameMap.get(trayImport.getTrayGroupName())));
                /*
                this.commonGroupOfItemService.update((Wrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().eq((v0) -> {
                    return v0.getItemId();
                }, tray.getId())).set((v0) -> {
                    return v0.getGroupId();
                }, commonGroupNameMap.get(trayImport.getTrayGroupName())));
                */
                return;
            }
            TraySaveVO traySaveVO = new TraySaveVO();
            traySaveVO.setCode(trayImport.getTrayCode());
            traySaveVO.setName(Func.isEmpty(trayImport.getName()) ? trayImport.getTrayCode() : trayImport.getName());
            traySaveVO.setAvailability(TrayEnum.StatusEnum.ACTIVATING.getStatus());
            traySaveVO.setGroupId((Long) commonGroupNameMap.get(trayImport.getTrayGroupName()));
            traySaveVO.setFaceList(new ArrayList<>());
            saveTray(traySaveVO);
        });
        return null;
    }
 
    @Override // org.springblade.modules.cps.service.ITrayService
    public int removeFaceFixture(List<Long> ids) {
        return this.baseMapper.removeFaceFixture(ids);
    }
 
    private void checkTrayImport(List<TrayImport> trayData, Map<String, Long> commonGroupNameMap, Map<String, List<TrayImport>> map, Set<String> trayCodeSet) {
        for (TrayImport trayImport : trayData) {
            if (Func.isNotBlank(trayImport.getTrayGroupName()) && !commonGroupNameMap.containsKey(trayImport.getTrayGroupName())) {
                trayImport.setFailReason(MessageUtils.message("cps.tray.group.not.existing", new Object[0]));
            } else if (Func.isBlank(trayImport.getTrayGroupName())) {
                trayImport.setFailReason(MessageUtils.message("cps.tray.group.name.can.not.empty", new Object[0]));
            } else if (Func.isBlank(trayImport.getTrayCode())) {
                trayImport.setFailReason(MessageUtils.message("cps.tray.code.can.not.empty", new Object[0]));
            } else {
                if (Func.isNotBlank(trayImport.getTrayCode())) {
                    if (map.get(trayImport.getTrayCode()).size() > 1) {
                        trayImport.setFailReason(MessageUtils.message("cps.tray.code.existing", new Object[0]));
                    } else if (trayCodeSet.contains(trayImport.getTrayCode())) {
                        trayImport.setFailReason(MessageUtils.message("cps.tray.code.existing", new Object[0]));
                    }
                }
                if (ValidatorUtils.stringFilter(trayImport.getTrayCode())) {
                    trayImport.setFailReason(MessageUtils.message("cps.tray.code.exist.special.symbols.error", new Object[0]));
                } else if (Func.isNotEmpty(trayImport.getName()) && ValidatorUtils.stringFilter(trayImport.getName())) {
                    trayImport.setFailReason(MessageUtils.message("cps.tray.name.exist.special.symbols.error", new Object[0]));
                }
            }
        }
    }
 
    private List<TrayTreeVO> getUnUsedTray(List<TrayTreeVO> vo) {
        if (Func.isEmpty(vo)) {
            return Lists.newArrayList();
        }
        List<Long> groupIds = vo.stream().map((v0) -> {
            return v0.getParentId();
        }).collect(Collectors.toList());
        
        List<CommonGroup> commonGroups = this.commonGroupService.list(Wrappers.<CommonGroup>lambdaQuery().in(CommonGroup::getId, groupIds));
        /*
        List<CommonGroup> commonGroups = this.commonGroupService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getId();
        }, groupIds));
        */
        List<TrayTreeVO> groups = commonGroups.stream().map(this::convert).collect(Collectors.toList());
        vo.addAll(groups);
        return ForestNodeMerger.merge(vo);
    }
 
    private List<TrayTreeVO> getTrayTree(List<TrayTreeVO> vo, CommonGroupTypeVO groupTypeVO) {
        List<CommonGroup> commonGroups = this.commonGroupService.list(Wrappers.<CommonGroup>lambdaQuery()
                .eq(CommonGroup::getGroupType, groupTypeVO.getGroupType())
                .eq(CommonGroup::getGroupCategory, groupTypeVO.getGroupCategory()));
        /*
        List<CommonGroup> commonGroups = this.commonGroupService.list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getGroupType();
        }, groupTypeVO.getGroupType())).eq((v0) -> {
            return v0.getGroupCategory();
        }, groupTypeVO.getGroupCategory()));*/
        List<TrayTreeVO> groups = commonGroups.stream().map(this::convert).collect(Collectors.toList());
        vo.addAll(groups);
        return ForestNodeMerger.merge(vo);
    }
 
    private TrayTreeVO convert(CommonGroup group) {
        TrayTreeVO treeVO = new TrayTreeVO();
        treeVO.setId(group.getId());
        treeVO.setName(group.getName());
        treeVO.setCode(group.getCode());
        treeVO.setParentId(group.getParentId());
        treeVO.setIsGroup(Boolean.TRUE);
        return treeVO;
    }
 
    private List<ToolingVO> groupTrayTree(CommonGroupTypeVO vo) {
        List<ToolingVO> trayList = this.baseMapper.trayTree(vo);
        return ForestNodeMerger.merge(calculateToolingNum(trayList));
    }
 
    private List<ToolingVO> groupFixtureTree(CommonGroupTypeVO vo) {
        List<ToolingVO> trayList = this.baseMapper.fixtureTree(vo);
        return ForestNodeMerger.merge(calculateToolingNum(trayList));
    }
 
    private List<ToolingVO> calculateToolingNum(List<ToolingVO> vo) {
        List<ToolingVO> result = Lists.newArrayList();
        vo.forEach(v -> {
            int nums = vo.stream().filter(p -> {
                return p.getCode().indexOf(v.getCode()) == 0;
            }).mapToInt((v0) -> {
                return v0.getNumbers();
            }).sum();
            ToolingVO res = TrayConvert.INSTANCE.convert(v);
            res.setNumbers(Integer.valueOf(nums));
            result.add(res);
        });
        return result;
    }
 
    private void validCode(String code) {
        long count = count(Lambda.eq((v0) -> {
            return v0.getCode();
        }, code));
        ThrowFun.isTrue(count > 0).throwMessage(MessageUtils.message("cps.tray.code.exist", new Object[0]));
    }
}