自动化立体仓库 - WMS系统
skyouc
2 天以前 61eb8dfa4ff44b539d9dd03205705270ba6e1fa7
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
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, "lock");
 
        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.getTaskNo())) {
            throw new CoolException("工作号不能为空!!");
        }
        String wrkCode = params.getTaskNo();
       if (wrkCode.contains("-1")) {
           throw new CoolException("配对任务编码错误,请检查后重新上传!!");
       }
 
        WrkMast mast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_code", params.getTaskNo()));
 
       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("接收成功,执行回库中...");
    }
 
    /**
     * 下发任务至WCS
     * @author Ryan
     * @date 2026/1/10 13:58
     * @param params
     * @return com.core.common.R
     */
    @Override
    public R pubWrkToWcs(WorkTaskParams params) {
        if (Objects.isNull(params.getTaskNo())) {
            return R.error("任务号不能为空!!");
        }
        if (Objects.isNull(params.getBarcode())) {
            return R.error("托盘码不能为空!!");
        }
        if (Objects.isNull(params.getLocNo())) {
            return R.error("目标库位不能为空!!");
        }
        String url = MesConstant.PUB_TASK_IN;
        if (Objects.isNull(params.getType()) && params.getType().equals("out")) {
            url = MesConstant.PUB_TASK_OUT;
        }
        String response;
        try {
            response =  new HttpHandler.Builder()
                    .setUri(MesConstant.URL)
                    .setPath(url)
                    .setJson(JSON.toJSONString(params))
                    .build()
                    .doPost();
            R result = JSON.parseObject(response, R.class);
 
            if (result.get("code").equals("200")) {
                //TODO 上报是否成功
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return null;
    }
 
 
    /**
     * 上报锁定/释放库位信息
     * @author Ryan
     * @date 2026/1/10 12:50
     * @param locs
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void reportLockLocs(Set<String> locs, String type) {
        String url = MesConstant.LOCK_LOCS_URL;
        if (!Objects.isNull(type)) {
            if (type.equals("release")) {
                url = MesConstant.RELEASE_LOCS_URL;
            }
        }
        String response;
        try {
          response =  new HttpHandler.Builder()
            .setUri(MesConstant.URL)
            .setPath(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);
        }
 
    }
}