自动化立体仓库 - WMS系统
#
zjj
2025-04-14 bf9d0e6fe5c6c6c6a885007a0a7596f460a5e1f2
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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
package com.zy.common.service;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.Arith;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.Utils;
import com.zy.asrs.utils.VersionUtils;
import com.zy.common.model.LocTypeDto;
import com.zy.common.model.Shelves;
import com.zy.common.model.StartupDto;
import com.zy.common.properties.SlaveProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
/**
 * 货架核心功能
 * Created by vincent on 2020/6/11
 */
@Slf4j
@Service
public class CommonService {
 
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private WrkLastnoService wrkLastnoService;
    @Autowired
    private RowLastnoService rowLastnoService;
    @Autowired
    private BasCrnpService basCrnpService;
    @Autowired
    private StaDescService staDescService;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private SlaveProperties slaveProperties;
 
    /**
     * 生成工作号
     *
     * @param wrkMk
     * @return workNo(工作号)
     */
    public int getWorkNo(Integer wrkMk) {
        WrkLastno wrkLastno = wrkLastnoService.selectById(wrkMk);
        if (Cools.isEmpty(wrkLastno)) {
            throw new CoolException("数据异常,请联系管理员");
        }
 
        int workNo = wrkLastno.getWrkNo();
        int sNo = wrkLastno.getSNo();
        int eNo = wrkLastno.getENo();
        workNo = workNo >= eNo ? sNo : workNo + 1;
        while (true) {
            WrkMast wrkMast = wrkMastService.selectById(workNo);
            if (null != wrkMast) {
                workNo = workNo >= eNo ? sNo : workNo + 1;
            } else {
                break;
            }
        }
        // 修改序号记录
        if (workNo > 0) {
            wrkLastno.setWrkNo(workNo);
            wrkLastnoService.updateById(wrkLastno);
        }
        // 检验
        if (workNo == 0) {
            throw new CoolException("生成工作号失败,请联系管理员");
        } else {
            if (wrkMastService.selectById(workNo) != null) {
                throw new CoolException("生成工作号" + workNo + "在工作档中已存在");
            }
        }
        return workNo;
    }
 
    /**
     * 检索库位号
     *
     * @param whsType     类型 1:双深式货架
     * @param staDescId   路径工作类型
     * @param sourceStaNo 源站
     * @return locNo 检索到的库位号
     */
    @Transactional
    public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, String matnr, String batch, String grade, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
        // 目标库位
        LocMast locMast = null;
 
        // 靠近摆放规则 --- 空托
        locMast = getLocNoStep4(staDescId, locTypeDto, sourceStaNo);
        if (locMast != null) {
            //找到库位,返回dto
            return getLocNoStep6(staDescId, sourceStaNo, locMast);//返回dto
        }
 
        //库位规则
//        locMast = getLocNoStepRule(matnr, locTypeDto);
//        if (locMast != null) {
//            //找到库位,返回dto
//            return getLocNoStep6(staDescId, sourceStaNo, locMast);//返回dto
//        }
 
        // 靠近摆放规则 --- 相同订单号, 同天同规格物料
        locMast = getLocNoStep3(staDescId, matnr, batch, grade, locTypeDto, sourceStaNo);
        if (locMast != null) {
            //找到库位,返回dto
            return getLocNoStep6(staDescId, sourceStaNo, locMast);//返回dto
        }
 
        //搜索整个空库位组
        locMast = getLocNoStepSingle(locTypeDto, sourceStaNo);
        if (locMast != null) {
            //找到库位,返回dto
            return getLocNoStep6(staDescId, sourceStaNo, locMast);//返回dto
        }
 
        //找不到库位,抛出异常
        throw new CoolException("没有空库位");
 
    }
 
    @Transactional
    public StartupDto getLocNoRun(Integer whsType, Integer staDescId, Integer sourceStaNo, String matnr, String batch, String grade, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
        if (Cools.isEmpty(matnr)) {  //物料号
            matnr = "";
        }
        if (Cools.isEmpty(batch)) {  //箱号
            batch = "";
        }
        if (Cools.isEmpty(grade)) {  //备用
            grade = "";
        }
 
        // 初始化参数
        int crnNo = 0;      //堆垛机号
        int nearRow = 0;    //最浅库位排
        int curRow = 0;     //最深库位排
        int rowCount = 0;   //轮询轮次
        LocMast locMast = null;     // 目标库位
 
        StartupDto startupDto = new StartupDto();
        RowLastno rowLastno = rowLastnoService.selectById(whsType);
        int sRow = rowLastno.getsRow();
        int eRow = rowLastno.geteRow();
        int crnNumber = rowLastno.getCrnQty();
 
        if (Cools.isEmpty(rowLastno)) {
            throw new CoolException("数据异常,请联系管理员");
        }
        // ===============>>>> 开始执行
        curRow = rowLastno.getCurrentRow();
 
        if (!Cools.isEmpty(moveCrnNo) && moveCrnNo!=0){
            crnNumber = moveCrnNo;
            if (times==0){
                curRow = moveCrnNo*4-1;
            }else {
                curRow = moveCrnNo*4-2;
            }
        }
 
        //此程序用于优化堆垛机异常时的运行时间
        for (int i = times; i < crnNumber*2; i++) {
            int[] locNecessaryParameters = Utils.LocNecessaryParameters(whsType, curRow, crnNumber);
            log.info(Arrays.toString(locNecessaryParameters));
            curRow = locNecessaryParameters[1];
            crnNo = locNecessaryParameters[2];
            if (basCrnpService.checkSiteError(crnNo, true)) {
                rowCount =  locNecessaryParameters[0];
                nearRow = locNecessaryParameters[3];
                List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("row1", nearRow).eq("loc_sts", "O"));
                if (locMasts.size()<=10){
                    times++;
                    continue;
                }
                break;
            } else {
                times++;
            }
        }
        if (nearRow == 0) {
            throw new CoolException("无可用堆垛机");
        }
 
        boolean signRule1 = false;
        boolean signRule2 = false;
 
 
        // 靠近摆放规则 --- 同天同规格物料 //分离版
//        if (!Cools.isEmpty(matnr) &&  (staDescId == 1)){
//            signRule1 = true;
//        }
        // 靠近摆放规则 --- 同天同规格物料 //互通版
        if (!Cools.isEmpty(matnr) && staDescId == 1) {
            signRule2 = true;
        }
 
        if (!Cools.isEmpty(matnr) &&  (staDescId == 11 || staDescId == 111)) {
            signRule1 = true;
        }
 
        if (signRule1){
            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("row1", nearRow).eq("loc_sts", "O"));
            for (LocMast locMast1:locMasts){
                if (VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) {
                    continue;
                }
                String shallowLoc = Utils.getDeepLoc(slaveProperties,locMast1.getLocNo());
                LocMast locMast2 = locMastService.selectById(shallowLoc);
                if (!Cools.isEmpty(locMast2) && locMast2.getLocSts().equals("F")){
                    LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no", locMast2.getLocNo()));
                    if (!Cools.isEmpty(locDetl) && matnr.equals(locDetl.getMatnr())) {
                        locMast = locMast1;
                        break;
                    }
                }
            }
        }else if (signRule2){
            List<String> locNos = locDetlService.getSameDetlToday(matnr, sRow, eRow);
            for (String locNo : locNos) {
                if (Utils.isShallowLoc(slaveProperties, locNo)) {
                    continue;
                }
                String shallowLocNo = Utils.getShallowLoc(slaveProperties, locNo);
                // 检测目标库位是否为空库位
                LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) {
                    if (VersionUtils.locMoveCheckLocTypeComplete(shallowLoc, locTypeDto)) {
                        if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) {
                            locMast = shallowLoc;
                            crnNo = locMast.getCrnNo();
                            break;
                        }
                    }
                }
            }
        }
 
//        // 靠近摆放规则 --- 空托  //分离版
//        if (staDescId == 10) {
//            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("row1", nearRow).eq("loc_sts", "O"));
//            for (LocMast locMast1:locMasts){
//                if (VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) {
//                    continue;
//                }
//                String shallowLoc = Utils.getDeepLoc(slaveProperties,locMast1.getLocNo());
//                LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no",shallowLoc));
//                if (!Cools.isEmpty(locMast2) && locMast2.getLocSts().equals("D")){
//                    locMast = locMast1;
//                    break;
//                }
//            }
//        }
 
        // 靠近摆放规则 --- 空托 //互通版
        if (staDescId == 10) {
            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().in("crn_no",1,2).eq("loc_sts", "D").ge("row1", sRow).le("row1", eRow));
            if (locMasts.size() > 0) {
                for (LocMast loc : locMasts) {
                    if (Utils.isShallowLoc(slaveProperties, loc.getLocNo())) {
                        continue;
                    }
                    String shallowLocNo = Utils.getShallowLoc(slaveProperties, loc.getLocNo());
                    // 检测目标库位是否为空库位
                    LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                    if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) {
                        if (VersionUtils.locMoveCheckLocTypeComplete(shallowLoc, locTypeDto)) {
                            if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) {
                                locMast = shallowLoc;
                                crnNo = locMast.getCrnNo();
                                log.error("靠近摆放库位号");
                                break;
                            }
                        }
                    }
                }
            }
        }
 
        Wrapper<StaDesc> wrapper = null;
        StaDesc staDesc = null;
        BasDevp staNo = null;
 
        if (Utils.BooleanWhsTypeSta(whsType)) {
            // 获取目标站
            wrapper = new EntityWrapper<StaDesc>()
                    .eq("type_no", staDescId)
                    .eq("stn_no", sourceStaNo)
                    .eq("crn_no", crnNo);
            staDesc = staDescService.selectOne(wrapper);
            if (Cools.isEmpty(staDesc)) {
                log.error("type_no={},stn_no={},crn_no={}", staDescId, sourceStaNo, crnNo);
//                throw new CoolException("入库路径不存在");
                crnNo = 0;
                locMast = null;
            }else {
                staNo = basDevpService.selectById(staDesc.getCrnStn());
                if (!staNo.getAutoing().equals("Y")) {
//                throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用");
                    crnNo = 0;
                    locMast = null;
                }
                startupDto.setStaNo(staNo.getDevNo());
            }
        }
 
        // 更新库位排号
        if (Utils.BooleanWhsTypeSta(whsType) && Cools.isEmpty(locMast)) {
            rowLastno.setCurrentRow(curRow);
            rowLastnoService.updateById(rowLastno);
        }
 
        // 1.按规则查找库位
        if (Cools.isEmpty(locMast) && crnNo != 0) {
            List<LocMast> locMasts = null;
                locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
                        .eq("row1", nearRow)
                        .eq("loc_sts", "O")
                        .orderBy("lev1", true).orderBy("bay1", false));
 
 
            for (LocMast locMast1 : locMasts) {
                if (!VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) {
                    continue;
                }
                if (Utils.BooleanWhsTypeStaIoType(rowLastno)) {
                    String shallowLoc = Utils.getDeepLoc(slaveProperties, locMast1.getLocNo());
                    LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>()
                            .eq("loc_no", shallowLoc).eq("loc_sts", "O"));
                    if (!Cools.isEmpty(locMast2)) {
                        locMast = locMast2;
                        break;
                    }
                } else {
                    if (!Cools.isEmpty(locMast1)) {
                        locMast = locMast1;
                        break;
                    }
                }
            }
 
            if (Cools.isEmpty(locMast) && Utils.BooleanWhsTypeStaIoType(rowLastno)) {
                for (LocMast locMast1 : locMasts) {
                    if (!VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) {
                        continue;
                    }
                    if (Utils.BooleanWhsTypeStaIoType(rowLastno)) {
                        String shallowLoc = Utils.getDeepLoc(slaveProperties, locMast1.getLocNo());
                        LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>()
                                .eq("loc_no", shallowLoc).eq("loc_sts", "O"));
                        if (!Cools.isEmpty(locMast2)) {
                            locMast = locMast2;
                            break;
                        } else {
                            locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>()
                                    .eq("loc_no", shallowLoc).eq("loc_sts", "F"));
                            if (!Cools.isEmpty(locMast2)) {
                                locMast = locMast1;
                                break;
                            } else {
                                locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>()
                                        .eq("loc_no", shallowLoc).eq("loc_sts", "D"));
                                if (!Cools.isEmpty(locMast2)) {
                                    locMast = locMast1;
                                    break;
                                }
                            }
                        }
                    } else {
                        if (!Cools.isEmpty(locMast1)) {
                            locMast = locMast1;
                            break;
                        }
                    }
                }
            }
        }
        //查询当前库位类型空库位 小于5个则locmast = null
        List<LocMast> locTypeLocMasts = locMastService.selectList(new EntityWrapper<LocMast>()
                .eq("loc_sts", "O").eq("crn_no", crnNo).eq("loc_type1", locTypeDto.getLocType1())
        );
        if (null !=locTypeLocMasts && locTypeLocMasts.size()<=5){
            locMast = null;
        }
 
        if (!Cools.isEmpty(locMast) && !basCrnpService.checkSiteError(crnNo, true)) {
            locMast = null;
        }
 
        // 递归查询
        if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("O")) {
            // 当前巷道无空库位时,递归调整至下一巷道,检索全部巷道无果后,跳出递归
            if (times < rowCount*2) {
                times = times + 1;
                return getLocNoRun(1, staDescId, sourceStaNo, matnr, batch, grade,moveCrnNo, locTypeDto, times);
            }
//            // 2.库位当前所属尺寸无空库位时,调整尺寸参数,向上兼容检索库位
//            if (locTypeDto.getLocType1() < 2) {
//                int i = locTypeDto.getLocType1() + 1;
//                locTypeDto.setLocType1((short)i);
//                return getLocNo(1, staDescId, sourceStaNo, matnr,batch,grade, locTypeDto, 0);
//            }
            log.error("系统没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times);
            throw new CoolException("没有空库位");
        }
        String locNo = locMast.getLocNo();
 
        // 生成工作号
        int workNo = getWorkNo(0);
        // 返回dto
        startupDto.setWorkNo(workNo);
        startupDto.setCrnNo(crnNo);
        startupDto.setSourceStaNo(sourceStaNo);
        startupDto.setLocNo(locNo);
        return startupDto;
    }
 
    // 搜索单品(整个库位组)
    private LocMast getLocNoStepSingle(LocTypeDto locTypeDto, Integer sourceStaNo) {
        LocMast locMast = null;
 
        List<StaDesc> staDescs = staDescService.selectList(new EntityWrapper<StaDesc>().eq("type_no", 1).eq("stn_no", sourceStaNo));
        int num = 0;
        int crn_no = 1;
        for (StaDesc staDesc : staDescs) {
            List<LocMast> locMasts = locMastService.selectAreaEmpty(locTypeDto.getLocType1(), staDesc.getCrnNo());//搜索货物
            int temp = locMast == null ? 0 : locMasts.size();
            if (num <= temp) {
                num = temp;
                crn_no = staDesc.getCrnNo();
            }
        }
        //for (StaDesc staDesc : staDescs) {
        //单品
        List<LocMast> locMasts = locMastService.selectAreaEmpty(locTypeDto.getLocType1(), crn_no);//搜索货物
 
        for (LocMast mast : locMasts) {
            LocMast tmp = null;
            boolean groupLoc = Utils.isShallowLoc(slaveProperties, mast.getLocNo());
            if (groupLoc) {
                String shallowLoc = Utils.getDeepLoc(slaveProperties, mast.getLocNo());
                LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>()
                        .eq("loc_no", shallowLoc));
                if (!Cools.isEmpty(locMast2)) {
                    if (locMast2.getLocSts().equals("F") || locMast2.getLocSts().equals("D")) {
                        tmp = mast;
                        if (!Cools.isEmpty(mast)) {
                            if (mast.getLocSts().equals("O")) {
                                tmp = mast;
                            }
                        }
                    }
                    //预留空库位
                    if (tmp != null && locMastService.checkEmptyCount(mast, 10)) {
                        locMast = tmp;
                        return locMast;
                    }
                }
 
            } else {
                tmp = mast;
                //预留空库位
                if (tmp != null && locMastService.checkEmptyCount(mast, 10)) {
                    locMast = tmp;
                    return locMast;
                }
            }
 
 
            // }
        }
        return locMast;
    }
 
    // 靠近摆放规则 --- 相同订单号, 同天同规格物料
    private LocMast getLocNoStep3(Integer staDescId, String matnr, String batch, String grade, LocTypeDto
            locTypeDto, Integer sourceStaNo) {
        LocMast locMast = null;
        StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>().eq("type_no", 1).eq("stn_no", sourceStaNo));
        if (staDescId == 1) {
            //先判断工作档,查找主档IOType=1, wrkSts < 10的工作明细,料号相同的明细库位
            List<WrkMast> wrkMasts = wrkMastService.selectSameMatnrs(matnr, batch, grade);
            for (WrkMast wrkMast : wrkMasts) {
                LocMast locMast0 = locMastService.findNearloc(wrkMast.getLocNo());
                if (null != locMast0) {
                    if (!staDesc.getCrnNo().equals(locMast0.getCrnNo())) {
                        continue;
                    }
                    // 浅库位符合尺寸检测
                    if (VersionUtils.checkLocType(locMast0, locTypeDto)) {
                        locMast = locMast0;
                    }
                }
            }
            if (Cools.isEmpty(locMast)) {
                //再判断库存明细档,料号相同的明细库位
                List<String> locNos = locDetlService.getSameDetl(matnr, batch, grade);
                for (String locNo : locNos) {
                    LocMast locMast0 = locMastService.findNearloc(locNo);
                    if (null != locMast0) {
                        if (!staDesc.getCrnNo().equals(locMast0.getCrnNo())) {
                            continue;
                        }
                        // 浅库位符合尺寸检测
                        if (VersionUtils.checkLocType(locMast0, locTypeDto)) {
                            locMast = locMast0;
                            break;
                        }
                    }
                }
            }
        }
 
        return locMast;
    }
 
 
    //返回dto
    private StartupDto getLocNoStep6(Integer staDescId, Integer sourceStaNo, LocMast locMast) {
        StartupDto startupDto = new StartupDto();
        // 获取目标站
        Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
                .eq("type_no", staDescId)
                .eq("stn_no", sourceStaNo)
                .eq("crn_no", locMast.getCrnNo());
        StaDesc staDesc = staDescService.selectOne(wrapper);
        if (Cools.isEmpty(staDesc)) {
            log.error("入库路径不存在, staDescId={}, sourceStaNo={}", staDescId, sourceStaNo);
            throw new CoolException("入库路径不存在");
        }
 
        // 检测目标站
        BasDevp staNo = basDevpService.selectById(staDesc.getCrnStn());
        if (!staNo.getAutoing().equals("Y")) {
            throw new CoolException("目标站" + staDesc.getCrnStn() + "不可用");
        }
 
        // 生成工作号
        int workNo = getWorkNo(0);
        // 返回dto
        startupDto.setWorkNo(workNo);
        startupDto.setSourceStaNo(sourceStaNo);
        startupDto.setStaNo(staNo.getDevNo());
        startupDto.setLocNo(locMast.getLocNo());
        startupDto.setCrnNo(locMast.getCrnNo());
        return startupDto;
    }
 
    // 靠近摆放规则 --- 空托
    private LocMast getLocNoStep4(Integer staDescId, LocTypeDto locTypeDto, Integer sourceStaNo) {
        LocMast locMast = null;
        // 靠近摆放规则 --- 空托
        if (staDescId == 10) {
            // 获取目标站
            Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
                    .eq("type_no", staDescId)
                    .eq("stn_no", sourceStaNo);
            StaDesc staDesc = staDescService.selectOne(wrapper);
            if (staDesc == null) {
                throw new CoolException("入库路径不存在");
            }
 
            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
                    .eq("loc_sts", "O")
                    .eq("crn_no", staDesc.getCrnNo())
                    .eq("loc_type1", locTypeDto.getLocType1())
                    .orderBy("lev1,bay1,row1"));
            if (!locMasts.isEmpty()) {
                for (LocMast loc : locMasts) {
                    LocMast locMast0 = locMastService.findNearloc(loc.getLocNo());
                    // 浅库位符合尺寸检测
                    if (VersionUtils.checkLocType(locMast0, locTypeDto)) {
                        locMast = locMast0;
                        break;
                    }
                }
            }
 
            if (locMast == null) {
                throw new CoolException("缺少空库位");
            }
        }
        return locMast;
    }
 
 
    public static String zerofill(String msg, Integer count) {
        if (msg.length() == count) {
            return msg;
        } else if (msg.length() > count) {
            return msg.substring(0, 16);
        } else {
            StringBuilder msgBuilder = new StringBuilder(msg);
            for (int i = 0; i < count - msg.length(); ++i) {
                msgBuilder.insert(0, "0");
            }
            return msgBuilder.toString();
        }
    }
 
    /**
     * 根据入库站获取库位排号分配
     */
    private Integer getWhsType(Integer sourceStaNo, int times) {
        if (times >= 16) {
            return 4;
        }
        switch (sourceStaNo) {
            case 173:
            case 176:
            case 180:
            case 185:
                return 1;
            case 189:
            case 194:
            case 198:
            case 202:
                return 2;
            case 206:
//            case 211:
//            case 215:
//            case 219:
//            case 223:
            case 227:
                return 3;
            case 305:
            case 303:
            case 301:
                return 4;
            default:
                throw new CoolException("根据入库站获取库位排号分配失败,入库站:" + sourceStaNo);
        }
    }
 
}