自动化立体仓库 - WMS系统
skyouc
2 天以前 01a74bb0c1835cb56c410a62bef1e66f605f7103
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
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.service.WcsApiService;
import com.zy.asrs.entity.BasDevice;
import com.zy.asrs.entity.LocAroundBind;
import com.zy.asrs.service.BasDeviceService;
import com.zy.asrs.service.LocAroundBindService;
import com.zy.asrs.service.LocMastService;
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;
 
    /**
     * 通知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:11
     * @param params
     * @return com.core.common.R
     */
    @Override
    public R backLocs(ReceviceTaskParams params) {
        return null;
    }
 
    /**
     * 上报锁定库位信息
     * @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);
        }
 
    }
}