自动化立体仓库 - WMS系统
skyouc
2 天以前 88155592a3433104c12880fdd6d58cee0dedd3c7
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
package com.zy.api.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.api.controller.params.ReceviceTaskParams;
import com.zy.api.controller.params.WorkTaskParams;
import com.zy.api.service.WcsApiService;
import com.zy.asrs.entity.BasDevice;
import com.zy.asrs.entity.LocAroundBind;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.BasDeviceService;
import com.zy.asrs.service.LocAroundBindService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.WrkMastService;
import com.zy.common.constant.MesConstant;
import com.zy.common.utils.HttpHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
 
@Service
public class WcsApiServiceImpl implements WcsApiService {
 
    @Autowired
    private BasDeviceService basDeviceService;
    @Autowired
    private LocAroundBindService locAroundBindService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private WrkMastService wrkMastService;
 
    /**
     * 通知WCS锁定库位,及禁止当前库位的一切操作
     * @author Ryan
     * @date 2026/1/10 11:18
     * @param params
     * @return com.core.common.R
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R lockLocs(ReceviceTaskParams params) {
        BasDevice basDevice = basDeviceService.selectOne(new EntityWrapper<BasDevice>()
                .eq("status", 1)
                .eq("dev_no", params.getDeviceNo()));
        if (Objects.isNull(basDevice)) {
            throw new CoolException("机台信息不存在或已禁用!!");
        }
        List<LocAroundBind> binds = locAroundBindService.selectList(new EntityWrapper<LocAroundBind>().eq("dev_no", basDevice.getDevNo()));
        if (Objects.isNull(binds) || binds.isEmpty()) {
            throw new CoolException("机台未绑定工作站台!!");
        }
        Set<String> locs = binds.stream().map(LocAroundBind::getBLocNo).collect(Collectors.toSet());
 
        reportLockLocs(locs);
 
        return R.ok("上报成功!!");
    }
 
    /**
     * 余料回库 (搬运余料回库)
     * @author Ryan
     * @date 2026/1/10 13:19
     * @param params
     * @return com.core.common.R
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R backLocs(WorkTaskParams params) {
        if (Objects.isNull(params.getWrkCode())) {
            throw new CoolException("工作号不能为空!!");
        }
        String wrkCode = params.getWrkCode();
       if (wrkCode.contains("-1")) {
           throw new CoolException("配对任务编码错误,请检查后重新上传!!");
       }
 
        WrkMast mast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_code", params.getWrkCode()));
 
       if (Objects.isNull(mast)) {
           throw new CoolException("任务不存在!!");
       }
       if (!mast.getWrkSts().equals(103L)) {
           throw new CoolException("当前任务并非余料出库任务!!");
       }
        mast.setWrkSts(53L);
       if (!wrkMastService.updateById(mast)) {
           throw new CoolException("任务状态更新失败!!");
       }
 
       return R.ok("接收成功,执行回库中...");
    }
 
 
    /**
     * 上报锁定库位信息
     * @author Ryan
     * @date 2026/1/10 12:50
     * @param locs
     */
    @Transactional(rollbackFor = Exception.class)
    public void reportLockLocs(Set<String> locs) {
        String response;
        try {
          response =  new HttpHandler.Builder()
            .setUri(MesConstant.URL)
            .setPath(MesConstant.LOCK_LOCS_URL)
            .setJson(JSON.toJSONString(locs))
            .build()
            .doPost();
          R result = JSON.parseObject(response, R.class);
 
          if (result.get("code").equals("200")) {
                //TODO 上报是否成功
          }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
 
    }
}