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
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
package com.qianwen.smartman.modules.cps.service.impl;
 
import cn.hutool.core.lang.Snowflake;
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.lang.invoke.SerializedLambda;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.MessageUtils;
import com.qianwen.smartman.common.websocket.entity.FmsArea;
import com.qianwen.core.excel.util.ExcelUtil;
import com.qianwen.core.mp.service.impl.BladeServiceImpl;
import com.qianwen.core.oss.model.BladeFile;
import com.qianwen.core.secure.utils.AuthUtil;
import com.qianwen.core.tool.support.Kv;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.convert.TrayStorageConvert;
import com.qianwen.smartman.modules.cps.dto.RemoveIdsDTO;
import com.qianwen.smartman.modules.cps.entity.CommonGroupOfItem;
import com.qianwen.smartman.modules.cps.entity.Tray;
import com.qianwen.smartman.modules.cps.entity.TrayStorage;
import com.qianwen.smartman.modules.cps.entity.WarehouseArea;
import com.qianwen.smartman.modules.cps.entity.WarehouseStation;
import com.qianwen.smartman.modules.cps.excel.TrayStorageImport;
import com.qianwen.smartman.modules.cps.mapper.TrayStorageMapper;
import com.qianwen.smartman.modules.cps.service.ICommonGroupOfItemService;
import com.qianwen.smartman.modules.cps.service.ITrayService;
import com.qianwen.smartman.modules.cps.service.ITrayStorageService;
import com.qianwen.smartman.modules.cps.service.IWarehouseAreaService;
import com.qianwen.smartman.modules.cps.service.IWarehouseStationService;
import com.qianwen.smartman.modules.cps.utils.StringUtils;
import com.qianwen.smartman.modules.cps.utils.ThrowFun;
import com.qianwen.smartman.modules.cps.vo.TrayFixRemoveVO;
import com.qianwen.smartman.modules.cps.vo.TrayStorageAddVO;
import com.qianwen.smartman.modules.cps.vo.TrayStorageVO;
import com.qianwen.smartman.modules.cps.vo.WareTrayStorageVO;
import com.qianwen.smartman.modules.cps.vo.WarehouseAreaStationVO;
import com.qianwen.smartman.modules.fms.entity.FmsRealTimeTray;
import com.qianwen.smartman.modules.fms.enums.PositionTypeEnum;
import com.qianwen.smartman.modules.fms.service.IFmsRealTimeTrayService;
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/cps/service/impl/TrayStorageServiceImpl.class */
public class TrayStorageServiceImpl extends BladeServiceImpl<TrayStorageMapper, TrayStorage> implements ITrayStorageService {
    private static final Logger log = LoggerFactory.getLogger(TrayStorageServiceImpl.class);
    @Autowired
    @Lazy
    private ITrayService trayService;
    @Autowired
    @Lazy
    private IWarehouseAreaService warehouseAreaService;
    @Autowired
    @Lazy
    private IWarehouseStationService warehouseStationService;
    @Autowired
    private OssBuilder ossBuilder;
    @Autowired
    private IFmsRealTimeTrayService fmsRealTimeTrayService;
    @Autowired
    private ICommonGroupOfItemService itemService;
 
    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
        String implMethodName = lambda.getImplMethodName();
        boolean z = true;
        switch (implMethodName.hashCode()) {
            case -927447111:
                if (implMethodName.equals("getTrayCode")) {
                    z = false;
                    break;
                }
                break;
            case -75622813:
                if (implMethodName.equals("getCode")) {
                    z = true;
                    break;
                }
                break;
            case 98245393:
                if (implMethodName.equals("getId")) {
                    z = true;
                    break;
                }
                break;
            case 1929248666:
                if (implMethodName.equals("getWarehouseCode")) {
                    z = true;
                    break;
                }
                break;
            case 1956157548:
                if (implMethodName.equals("getInUse")) {
                    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/fms/entity/FmsRealTimeTray") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getTrayCode();
                    };
                }
                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/Tray") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getInUse();
                    };
                }
                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/Tray") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getInUse();
                    };
                }
                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/WarehouseStation") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getWarehouseCode();
                    };
                }
                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();
                    };
                }
                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;
            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/WarehouseArea") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getCode();
                    };
                }
                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/Tray") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getCode();
                    };
                }
                break;
        }
        throw new IllegalArgumentException("Invalid lambda deserialization");
    }
 
    @Override // org.springblade.modules.cps.service.ITrayStorageService
    public List<WareTrayStorageVO> listTray(Long id) {
        return this.baseMapper.listTray(id);
    }
 
    @Override // org.springblade.modules.cps.service.ITrayStorageService
    @Transactional(rollbackFor = {Exception.class})
    public List<TrayStorageVO> addTrayStorage(TrayStorageAddVO vo) {
        List<Long> trayIds = vo.getTrayIds();
        Long warehouseStationId = vo.getWarehouseStationId();
        List<TrayStorage> storages = (List) trayIds.stream().map(c -> {
            return new TrayStorage().setTrayId(c).setWarehouseStationId(warehouseStationId);
        }).collect(Collectors.toList());
        saveBatch(storages);
        this.trayService.update((Wrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set((v0) -> {
            return v0.getInUse();
        }, ToolingConstant.TOOLING_IN_USE)).in((v0) -> {
            return v0.getId();
        }, trayIds));
        saveFmsRealTimeTray(storages);
        return TrayStorageConvert.INSTANCE.convert(storages);
    }
 
    private void saveFmsRealTimeTray(List<TrayStorage> trayStorages) {
        List<FmsRealTimeTray> fmsRealTimeTrays = Lists.newArrayList();
        Set<Long> trayIds = Sets.newHashSet();
        Set<Long> warehouseStationIds = Sets.newHashSet();
        trayStorages.forEach(trayStorage -> {
            trayIds.add(trayStorage.getTrayId());
            warehouseStationIds.add(trayStorage.getWarehouseStationId());
        });
        Map<Long, String> trayMap = (Map) this.trayService.listByIds(trayIds).stream().collect(Collectors.toMap((v0) -> {
            return v0.getId();
        }, (v0) -> {
            return v0.getCode();
        }));
        Map<Long, String> warehouseStationMap = (Map) this.warehouseStationService.getWarehouseStationList(warehouseStationIds).stream().collect(Collectors.toMap((v0) -> {
            return v0.getId();
        }, (v0) -> {
            return v0.getWarehouseAreaCode();
        }));
        trayStorages.forEach(trayStorage2 -> {
            FmsRealTimeTray fmsRealTimeTray = new FmsRealTimeTray().setTrayCode((String) trayMap.get(trayStorage2.getTrayId())).setCurrentPosition((String) warehouseStationMap.get(trayStorage2.getWarehouseStationId())).setCurrentType(PositionTypeEnum.LOCATION.getType());
            fmsRealTimeTrays.add(fmsRealTimeTray);
        });
        this.fmsRealTimeTrayService.saveBatch(fmsRealTimeTrays);
    }
 
    @Override // org.springblade.modules.cps.service.ITrayStorageService
    @Transactional(rollbackFor = {Exception.class})
    public Boolean removeBind(TrayFixRemoveVO vo) {
        List<RemoveIdsDTO> ids = vo.getIds();
        if (Func.isEmpty(ids)) {
            return false;
        }
        List<Long> idList = Lists.newArrayList();
        List<Long> trayIds = Lists.newArrayList();
        ids.forEach(s -> {
            idList.add(s.getId());
            trayIds.add(s.getOthersId());
        });
        int count = this.trayService.removeFaceFixture(trayIds);
        ThrowFun.isTrue(count > 0).throwMessage(MessageUtils.message("cps.tray.face.banding.fixture", new Object[0]));
        boolean remove = removeByIds(idList);
        boolean update = this.trayService.update((Wrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set((v0) -> {
            return v0.getInUse();
        }, ToolingConstant.TOOLING_NOT_USE)).in((v0) -> {
            return v0.getId();
        }, trayIds));
        Boolean fmsRealTimeTrayFlag = removeFmsRealTimeTray(trayIds);
        return Boolean.valueOf(remove && update && fmsRealTimeTrayFlag.booleanValue());
    }
 
    private Boolean removeFmsRealTimeTray(List<Long> trayIds) {
        List<Tray> trays = this.trayService.listByIds(trayIds);
        List<String> trayCodes = (List) trays.stream().map((v0) -> {
            return v0.getCode();
        }).collect(Collectors.toList());
        return Boolean.valueOf(this.fmsRealTimeTrayService.remove((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getTrayCode();
        }, trayCodes)));
    }
 
    @Override // org.springblade.modules.cps.service.ITrayStorageService
    public List<WarehouseAreaStationVO> areaStationTree() {
        return this.warehouseAreaService.areaStationTree();
    }
 
    @Override // org.springblade.modules.cps.service.ITrayStorageService
    public List<FmsArea> fmsAreaStationTree() {
        return this.warehouseAreaService.fmsAreaStationTree();
    }
 
    @Override // org.springblade.modules.cps.service.ITrayStorageService
    @Transactional(rollbackFor = {Exception.class})
    public BladeFile importTrayStorage(MultipartFile file) {
        List<TrayStorageImport> rawData = ExcelUtil.read(file, 0, 2, TrayStorageImport.class);
        ThrowFun.isTrue(Func.isEmpty(rawData)).throwMessage(MessageUtils.message("excel.import.data.can.not.be.null", new Object[0]));
        ThrowFun.isTrue(rawData.size() > 200).throwMessage(MessageUtils.message("excel.import.size.failed", new Object[0]));
        Map<String, WarehouseArea> areaMap = Kv.newMap();
        List<WarehouseArea> needSaveArea = Lists.newArrayList();
        Map<String, WarehouseStation> warehouseStationMap = Kv.newMap();
        List<WarehouseStation> needSaveStation = Lists.newArrayList();
        Map<String, Tray> trayMap = Kv.newMap();
        List<Tray> needSaveTray = Lists.newArrayList();
        getTrayStorage(rawData, areaMap, warehouseStationMap, trayMap);
        List<TrayStorageImport> failExcel = Lists.newArrayList();
        for (TrayStorageImport data : rawData) {
            boolean validImport = validImport(data, failExcel, areaMap, needSaveArea, warehouseStationMap, needSaveStation, trayMap, needSaveTray);
            if (validImport) {
                break;
            }
        }
        if (Func.isNotEmpty(failExcel)) {
            return exportFailFile(failExcel);
        }
        Map<String, WarehouseArea> needSaveAreaMap = (Map) needSaveArea.stream().collect(Collectors.toMap((v0) -> {
            return v0.getCode();
        }, Function.identity(), v1, v2 -> {
            return v1;
        }));
        Map<String, WarehouseStation> needSaveStationMap = (Map) needSaveStation.stream().collect(Collectors.toMap((v0) -> {
            return v0.getWarehouseCode();
        }, Function.identity(), v12, v22 -> {
            return v12;
        }));
        if (Func.isNotEmpty(needSaveArea)) {
            this.warehouseAreaService.saveBatch(needSaveAreaMap.values());
            areaMap.putAll(needSaveAreaMap);
        }
        if (Func.isNotEmpty(needSaveStation)) {
            this.warehouseStationService.saveBatch(needSaveStationMap.values());
            warehouseStationMap.putAll(needSaveStationMap);
        }
        if (Func.isNotEmpty(needSaveTray)) {
            this.trayService.saveBatch(needSaveTray);
            List<CommonGroupOfItem> items = (List) needSaveTray.stream().map(tray -> {
                return CommonGroupOfItem.builder().groupId(105L).itemId(tray.getId()).groupType(CommonGroupTypeEnum.TRAY.getName()).groupCategory(CommonGroupConstant.DEFAULT_CATEGORY).build();
            }).collect(Collectors.toList());
            this.itemService.saveBatch(items);
            trayMap.putAll((Map) needSaveTray.stream().collect(Collectors.toMap((v0) -> {
                return v0.getCode();
            }, v -> {
                return v;
            })));
        }
        saveTrayStorage(rawData, warehouseStationMap, trayMap);
        return null;
    }
 
    private void saveTrayStorage(List<TrayStorageImport> rawData, Map<String, WarehouseStation> warehouseStationMap, Map<String, Tray> trayMap) {
        List<TrayStorage> trayStorageList = Lists.newArrayList();
        List<Tray> trays = Lists.newArrayList();
        rawData.forEach(data -> {
            WarehouseStation warehouseStation = (WarehouseStation) warehouseStationMap.get(data.getLocationCode());
            Tray tray = (Tray) trayMap.get(data.getTrayCode());
            tray.setInUse(ToolingConstant.TOOLING_IN_USE);
            trays.add(tray);
            TrayStorage trayStorage = new TrayStorage().setTrayId(tray.getId()).setWarehouseStationId(warehouseStation.getId());
            trayStorageList.add(trayStorage);
        });
        List<TrayStorage> trayStorages = list();
        Map<String, TrayStorage> trayFixtureMap = (Map) trayStorages.stream().collect(Collectors.toMap(k -> {
            return StringUtils.getKey(k.getTrayId(), k.getWarehouseStationId());
        }, v -> {
            return v;
        }));
        List<TrayStorage> collect = (List) trayStorageList.stream().distinct().filter(c -> {
            return !trayFixtureMap.containsKey(StringUtils.getKey(c.getTrayId(), c.getWarehouseStationId()));
        }).collect(Collectors.toList());
        if (Func.isNotEmpty(collect)) {
            saveBatch(collect);
            saveFmsRealTimeTray(collect);
        }
        if (Func.isNotEmpty(trays)) {
            this.trayService.updateBatchById(trays);
        }
    }
 
    private BladeFile exportFailFile(List<TrayStorageImport> failExcel) {
        MultipartFile multipartFile = ExcelUtil.exportFillTemplateToMultipartFile(ExcelConstant.DIRECTORY + "trayStorageFailTemplate" + ExcelConstant.SUFFIX, MessageUtils.message("excel.import.failed.report.name", new Object[0]) + ExcelConstant.SUFFIX, ExcelConstant.SHEET, failExcel, (Object) null, (AbstractMergeStrategy) null);
        return this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
    }
 
    public boolean validImport(TrayStorageImport data, List<TrayStorageImport> failExcel, Map<String, WarehouseArea> areaMap, List<WarehouseArea> needSaveArea, Map<String, WarehouseStation> stationMap, List<WarehouseStation> needSaveStation, Map<String, Tray> trayMap, List<Tray> needSaveTray) {
        Snowflake snowflake = new Snowflake(new Random().nextInt(4) + 1, new Random().nextInt(4) + 1, true);
        String areaCode = data.getAreaCode();
        if (Func.isBlank(areaCode)) {
            data.setFailReason(MessageUtils.message("excel.export.area.code.not.null", new Object[0]));
            failExcel.add(data);
            return true;
        }
        String areaName = data.getAreaName();
        if (Func.isBlank(areaName)) {
            data.setFailReason(MessageUtils.message("excel.export.area.name.not.null", new Object[0]));
            failExcel.add(data);
            return true;
        }
        WarehouseArea area = areaMap.get(areaCode);
        if (Func.isNull(area)) {
            WarehouseArea houseArea = new WarehouseArea().setTenantId(AuthUtil.getTenantId()).setCode(areaCode).setName(areaName).setParentId(1L);
            houseArea.setId(Long.valueOf(snowflake.nextId()));
            needSaveArea.add(houseArea);
            int size = 0;
            for (WarehouseArea warehouseArea : needSaveArea) {
                String code = warehouseArea.getCode();
                String name = warehouseArea.getName();
                if (code.equals(areaCode) && !name.equals(areaName)) {
                    size++;
                }
            }
            if (size > 0) {
                data.setFailReason(MessageUtils.message("excel.export.file.area.code.name.system.exists", new Object[0]));
                failExcel.add(data);
                return true;
            }
            area = houseArea;
        } else if (!areaName.equals(area.getName())) {
            data.setFailReason(MessageUtils.message("excel.export.area.code.name.system.exists", new Object[0]));
            failExcel.add(data);
            return true;
        }
        String locationCode = data.getLocationCode();
        if (Func.isBlank(locationCode)) {
            data.setFailReason(MessageUtils.message("excel.export.station.code.not.be.null", new Object[0]));
            failExcel.add(data);
            return true;
        }
        String locationName = data.getLocationName();
        if (Func.isBlank(locationName)) {
            data.setFailReason(MessageUtils.message("excel.export.station.name.not.be.null", new Object[0]));
            failExcel.add(data);
            return true;
        }
        WarehouseStation station = stationMap.get(locationCode);
        if (Func.isNull(station)) {
            WarehouseStation houseStation = new WarehouseStation().setTenantId(AuthUtil.getTenantId()).setAreaId(area.getId()).setWarehouseAreaName(areaName).setWarehouseAreaCode(areaCode).setWarehouseName(locationName).setWarehouseCode(locationCode);
            houseStation.setId(Long.valueOf(snowflake.nextId()));
            needSaveStation.add(houseStation);
            int size2 = 0;
            for (WarehouseStation warehouseStation : needSaveStation) {
                String code2 = warehouseStation.getWarehouseCode();
                String name2 = warehouseStation.getWarehouseName();
                if (code2.equals(locationCode) && !name2.equals(locationName)) {
                    size2++;
                }
            }
            if (size2 > 0) {
                data.setFailReason(MessageUtils.message("excel.export.file.station.code.name.system.exists", new Object[0]));
                failExcel.add(data);
                return true;
            }
        } else if (!locationName.equals(station.getWarehouseName())) {
            data.setFailReason(MessageUtils.message("excel.export.station.system.exists", new Object[0]));
            failExcel.add(data);
            return true;
        }
        String trayCode = data.getTrayCode();
        if (Func.isBlank(trayCode)) {
            data.setFailReason(MessageUtils.message("excel.export.tray.code.not.be.null", new Object[0]));
            failExcel.add(data);
            return true;
        }
        Tray tray = trayMap.get(trayCode);
        if (Func.isEmpty(tray)) {
            String trayName = data.getTrayName();
            Tray newTray = new Tray().setCode(trayCode).setName(Func.isBlank(trayName) ? trayCode : trayName).setTrayStatus(1).setInUse(0).setAvailability(1);
            needSaveTray.add(newTray);
            int size3 = 0;
            for (Tray trays : needSaveTray) {
                String code3 = trays.getCode();
                if (code3.equals(trayCode)) {
                    size3++;
                }
            }
            if (size3 > 1) {
                data.setFailReason(MessageUtils.message("excel.export.file.tray.code.name.system.exists", new Object[0]));
                failExcel.add(data);
                return true;
            }
            return false;
        } else if (Func.isNotBlank(data.getTrayName()) && !tray.getName().equals(data.getTrayName())) {
            data.setFailReason(MessageUtils.message("excel.export.tray.code.system.exists", new Object[0]));
            failExcel.add(data);
            return true;
        } else if (ToolingConstant.TOOLING_IN_USE.equals(tray.getInUse())) {
            data.setFailReason(MessageUtils.message("excel.export.tray.in.use", new Object[0]));
            failExcel.add(data);
            return true;
        } else {
            return false;
        }
    }
 
    private void getTrayStorage(List<TrayStorageImport> rawData, Map<String, WarehouseArea> areaMap, Map<String, WarehouseStation> warehouseStationMap, Map<String, Tray> trayMap) {
        Wrapper lambdaQuery = Wrappers.lambdaQuery();
        Wrapper lambdaQuery2 = Wrappers.lambdaQuery();
        Wrapper lambdaQuery3 = Wrappers.lambdaQuery();
        boolean flag1 = false;
        boolean flag2 = false;
        boolean flag3 = false;
        for (TrayStorageImport data : rawData) {
            if (requiredArea(data)) {
                if (flag1) {
                    lambdaQuery.or();
                }
                flag1 = true;
                lambdaQuery.eq((v0) -> {
                    return v0.getCode();
                }, data.getAreaCode());
            }
            if (requiredLocation(data)) {
                if (flag2) {
                    lambdaQuery2.or();
                }
                flag2 = true;
                lambdaQuery2.eq((v0) -> {
                    return v0.getWarehouseCode();
                }, data.getLocationCode());
            }
            if (requiredTray(data)) {
                if (flag3) {
                    lambdaQuery3.or();
                }
                flag3 = true;
                lambdaQuery3.eq((v0) -> {
                    return v0.getCode();
                }, data.getTrayCode());
            }
        }
        String sqlSegment1 = lambdaQuery.getSqlSegment();
        if (Func.isNotEmpty(sqlSegment1)) {
            List<WarehouseArea> areaList = this.warehouseAreaService.list(lambdaQuery);
            if (Func.isNotEmpty(areaList)) {
                Map<String, WarehouseArea> map = (Map) areaList.stream().collect(Collectors.toMap((v0) -> {
                    return v0.getCode();
                }, v -> {
                    return v;
                }));
                areaMap.putAll(map);
            }
        }
        String sqlSegment2 = lambdaQuery2.getSqlSegment();
        if (Func.isNotEmpty(sqlSegment2)) {
            List<WarehouseStation> warehouseStations = this.warehouseStationService.list(lambdaQuery2);
            if (Func.isNotEmpty(warehouseStations)) {
                Map<String, WarehouseStation> map1 = (Map) warehouseStations.stream().collect(Collectors.toMap((v0) -> {
                    return v0.getWarehouseCode();
                }, v2 -> {
                    return v2;
                }));
                warehouseStationMap.putAll(map1);
            }
        }
        String sqlSegment3 = lambdaQuery3.getSqlSegment();
        if (Func.isNotEmpty(sqlSegment3)) {
            List<Tray> trays = this.trayService.list(lambdaQuery3);
            if (Func.isNotEmpty(trays)) {
                Map<String, Tray> map2 = (Map) trays.stream().collect(Collectors.toMap((v0) -> {
                    return v0.getCode();
                }, v3 -> {
                    return v3;
                }));
                trayMap.putAll(map2);
            }
        }
    }
 
    private boolean requiredArea(TrayStorageImport data) {
        return Func.isNotBlank(data.getAreaCode()) && Func.isNotBlank(data.getAreaName());
    }
 
    private boolean requiredLocation(TrayStorageImport data) {
        return Func.isNotBlank(data.getLocationCode()) && Func.isNotBlank(data.getLocationName());
    }
 
    private boolean requiredTray(TrayStorageImport data) {
        return Func.isNotBlank(data.getTrayCode());
    }
}