自动化立体仓库 - WMS系统
pang.jiabao
7 天以前 71fd2c86e0206f614c068be05f67356deaca9b09
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
package com.zy.asrs.task;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.exception.CoolException;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.WrkMastService;
import com.zy.common.model.enums.WorkNoType;
import com.zy.common.service.CommonService;
import com.zy.system.timer.LoadingConfigTimer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.Date;
 
@Slf4j
@Component
public class AutoLocMoveScheduler {
 
 
    @Autowired
    private WrkMastService wrkMastService;
    
    @Resource
    private CommonService commonService;
 
    @Resource
    private LocMastService locMastService;
 
    @Resource
    private LoadingConfigTimer loadingConfigTimer;
 
    // 立体库跑库程序,生产勿用 ,一个巷道放一个托盘
    @Scheduled(cron = "0/5 * * * * ? ")
    public synchronized void autoMoveLoc() {
        if(!loadingConfigTimer.getAutoMoveLocTest().equals("Y") ){
            return;
        }
        for(int i = 1; i <= 2; i++ ){
            // 源库位
            LocMast sourceLocMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_sts", "D").eq("crn_no", i));
            if(sourceLocMast != null) {
                // 获取一个移动的目标库位
                LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("crn_no", i).isNull("loc_type3")
                        .eq("loc_sts","O").orderBy("lev1").orderBy("bay1").orderBy("row1"));
 
                if (locMast != null) {
                    if (!locMast.getLocSts().equals("O") || (!sourceLocMast.getLocSts().equals("F") && !sourceLocMast.getLocSts().equals("D"))){
                        log.error("{}库位状态已改变",sourceLocMast.getLocNo());
                        continue;
                    }
                    String sourceLoc = sourceLocMast.getLocNo(); // 源库位
                    String locNo = locMast.getLocNo(); // 目标库位
 
                    // 创建移库任务
                    Date now = new Date();
                    // 获取工作号
                    int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
                    // 保存工作档
                    WrkMast wrkMast = new WrkMast();
                    wrkMast.setWrkNo(workNo);
                    wrkMast.setIoTime(now);
                    wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID
                    wrkMast.setIoType(11); // 入出库状态: 11.库格移载
                    wrkMast.setIoPri(10D);
                    wrkMast.setCrnNo(locMast.getCrnNo());
                    wrkMast.setSourceLocNo(sourceLoc); // 源库位
                    wrkMast.setLocNo(locNo); // 目标库位
                    wrkMast.setFullPlt("N"); // 满板:Y
                    wrkMast.setPicking("N"); // 拣料
                    wrkMast.setExitMk("N"); // 退出
                    wrkMast.setEmptyMk("Y"); // 空板
                    wrkMast.setBarcode(locMast.getBarcode()); // 托盘码
                    wrkMast.setLinkMis("N");
                    wrkMast.setAppeTime(now);
                    wrkMast.setModiTime(now);
                    wrkMastService.insert(wrkMast);
 
                    // 修改源库位状态
                    if (sourceLocMast.getLocSts().equals("D") || sourceLocMast.getLocSts().equals("F")) {
                        sourceLocMast.setLocSts("R"); // R.出库预约
                        sourceLocMast.setModiTime(now);
                        sourceLocMast.setLocType3((short)1);
                        if (!locMastService.updateById(sourceLocMast)){
                            throw new CoolException("更新源库位状态失败");
                        }
                    } else {
                        throw new CoolException("源库位出库失败,状态:"+sourceLocMast.getLocSts$());
                    }
                    // 修改目标库位状态
                    if (locMast.getLocSts().equals("O")) {
                        locMast.setLocSts("S"); // S.入库预约
                        locMast.setModiTime(now);
                        if (!locMastService.updateById(locMast)) {
                            throw new CoolException("更新目标库位状态失败");
                        }
                    } else {
                        throw new CoolException("移转失败,目标库位状态:"+locMast.getLocSts$());
                    }
                    log.info("移库任务下发成功,源库位:{},目标库位:{}",sourceLoc,locNo);
                }
            }
        }
    }
 
}