自动化立体仓库 - WMS系统
zwl
2 天以前 909cc78ba290cefc3c4623eff234e85ca0140e6d
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
package com.zy.asrs.service.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.entity.param.MesToCombParam;
import com.zy.asrs.entity.param.OpenOrderPakoutPauseParam;
import com.zy.asrs.entity.param.OutTaskParam;
import com.zy.asrs.service.ExternalTaskFacadeService;
import com.zy.asrs.service.LocDetlService;
import com.zy.asrs.service.OpenService;
import com.zy.asrs.service.WaitPakinService;
import com.zy.asrs.service.WrkDetlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Objects;
 
/**
 * 对外任务门面。
 * 把 Controller 里的校验和放行逻辑沉到 service,便于 HTTP 和 MQTT 两条入口共用。
 */
@Service
public class ExternalTaskFacadeServiceImpl implements ExternalTaskFacadeService {
 
    @Autowired
    private OpenService openService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private WrkDetlService wrkDetlService;
    @Autowired
    private WaitPakinService waitPakinService;
 
    /**
     * 复用现有入库通知建档逻辑,并补充托盘重复校验。
     */
    @Override
    public R acceptInboundNotice(MesToCombParam param) {
        if (param == null) {
            return R.error("请求参数不能为空");
        }
        if (Cools.isEmpty(param.getPalletId())) {
            return R.error("palletId不能为空");
        }
        if (Cools.isEmpty(param.getBizNo())) {
            return R.error("bizNo不能为空");
        }
 
        int countLoc = locDetlService.selectCount(new EntityWrapper<com.zy.asrs.entity.LocDetl>().eq("zpallet", param.getPalletId()));
        int countWrk = wrkDetlService.selectCount(new EntityWrapper<com.zy.asrs.entity.WrkDetl>().eq("zpallet", param.getPalletId()));
        if (countLoc > 0 || countWrk > 0) {
            return R.error("托盘已在库存中/已开始入库");
        }
 
        if (waitPakinService.selectCount(new EntityWrapper<com.zy.asrs.entity.WaitPakin>()
                .eq("zpallet", param.getPalletId())
                .eq("io_status", "N")) > 0) {
            // 同托盘存在旧的待入库通知时,删除旧记录,保留最新一次预登记。
            waitPakinService.delete(new EntityWrapper<com.zy.asrs.entity.WaitPakin>().eq("zpallet", param.getPalletId()));
        }
 
        R result = openService.mesToComb(param);
        return result == null ? R.ok() : result;
    }
 
    /**
     * 复用现有出库建单逻辑;当 autoConfirm=true 时,继续调用原有确认接口自动放行。
     */
    @Override
    public R createOutboundTask(OutTaskParam param, boolean autoConfirm) {
        if (param == null) {
            return R.error("请求参数不能为空");
        }
        if (Cools.isEmpty(param.getOrderId())) {
            return R.error("出库单号不能为空");
        }
        if (Cools.isEmpty(param.getPalletId())) {
            return R.error("palletId不能为空");
        }
        if (Cools.isEmpty(param.getStationId())) {
            return R.error("stationId不能为空");
        }
        int countLoc = locDetlService.selectCount(new EntityWrapper<com.zy.asrs.entity.LocDetl>().eq("zpallet", param.getPalletId()));
        if (countLoc == 0) {
            return R.error("库存中不存在该托盘");
        }
 
        if (param.getSeq() == null) {
            param.setSeq(1);
        }
 
        R result = openService.outOrder(param, 1);
        if (!Objects.equals(result.get("code"), 200) || !autoConfirm) {
            return result;
        }
 
        // IoT pick 约定为“收到即执行”,因此这里直接复用原有确认放行接口。
        OpenOrderPakoutPauseParam executeParam = new OpenOrderPakoutPauseParam();
        executeParam.setOrderId(param.getOrderId());
        executeParam.setExecute(1);
        R confirmResult = openService.pakoutOrderPause(executeParam);
        if (result.get("wrkNo") != null) {
            confirmResult.add(Cools.add("wrkNo", result.get("wrkNo")));
        }
        return confirmResult;
    }
}