自动化立体仓库 - WCS系统
#
hmpc
2025-03-02 9e086905993eab6b45fb95a3faba14402404bd94
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
package com.zy.asrs.controller;
 
import com.alibaba.fastjson.JSON;
import com.core.annotations.AppAuth;
import com.core.common.*;
import com.core.exception.CoolException;
import com.zy.asrs.entity.param.WcsTaskDistributionParam;
import com.zy.asrs.service.OpenService;
import com.zy.common.web.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
 
/**
 * Created by vincent on 2024/10/16
 */
@Slf4j
@RestController
@RequestMapping("open/rcs")
public class  OpenController extends BaseController {
 
    private static final boolean auth = true;
    public static final ArrayList<String> APP_KEY_LIST = new ArrayList<String>() {{
        add("ea1f0459efc02a79f046f982767939ae");
    }};
 
    @Autowired
    private OpenService openService;
 
    /**
     * 添加出库单
     */
    @PostMapping("/task/cs/down/default/v1")
    @AppAuth(memo = "WCS任务下发")
    public synchronized R wcsTaskDistribution(@RequestHeader(required = false) String appkey,
                                            @RequestBody WcsTaskDistributionParam param,
                                            HttpServletRequest request) {
        auth(appkey, param, request);
        if (Cools.isEmpty(param)) {
            return R.parse(BaseRes.PARAM);
        }
        if (Cools.isEmpty(param.getTaskNo())) {
            return R.error("工作号[taskNo]不能为空");
        }
        if (Cools.isEmpty(param.getStartSta()) || param.getStartSta$()==0) {
            return R.error("起点[startSta]不能为空");
        }
        if (Cools.isEmpty(param.getEndSta())  || param.getEndSta$()==0) {
            return R.error("终点[endSta]不能为空");
        }
//        openService.wcsTaskDistribution(param);
 
        return openService.wcsTaskDistribution(param);
    }
 
    /**
     * 添加出库单
     */
    @PostMapping("/task/cs/down/default/v2")
    @AppAuth(memo = "WCS任务下发")
    public synchronized R wcsTaskDistribution2(@RequestHeader(required = false) String appkey,
                                              @RequestBody List<WcsTaskDistributionParam> param1,
                                              HttpServletRequest request) {
        auth(appkey, param1, request);
        for (WcsTaskDistributionParam param:param1){
            if (Cools.isEmpty(param)) {
                return R.parse(BaseRes.PARAM);
            }
            if (Cools.isEmpty(param.getTaskNo())) {
                return R.error("工作号[taskNo]不能为空");
            }
            if (Cools.isEmpty(param.getStartSta()) || param.getStartSta$()==0) {
                return R.error("起点[startSta]不能为空");
            }
            if (Cools.isEmpty(param.getEndSta())  || param.getEndSta$()==0) {
                return R.error("终点[endSta]不能为空");
            }
//        openService.wcsTaskDistribution(param);
 
             openService.wcsTaskDistribution(param);
        }
        return R.ok();
    }
 
    /**
     * 数据同步
     */
    @PostMapping("/status/cs/default/v1")
    @AppAuth(memo = "WCS数据同步")
    public synchronized R wcsTaskStatus(@RequestHeader(required = false) String appkey,
                                              @RequestBody Long timestamp,
                                              HttpServletRequest request) {
        auth(appkey, timestamp, request);
        if (Cools.isEmpty(timestamp)) {
            return R.parse(BaseRes.PARAM);
        }
 
        return openService.wcsTaskStatus(timestamp);
    }
 
 
    private void auth(String appkey, Object obj, HttpServletRequest request) {
//        log.info("{}接口被访问;appkey:{};请求数据:{}", "open/sensorType/list/auth/v1", appkey, JSON.toJSONString(obj));
        request.setAttribute("cache", obj);
        if (!auth) {
            return;
        }
        if (Cools.isEmpty(appkey)) {
            throw new CoolException("认证失败,请确认appkey无误!");
        }
        if (!APP_KEY_LIST.contains(appkey)) {
            throw new CoolException("认证失败,请确认appkey无误!");
        }
    }
 
}