自动化立体仓库 - WMS系统
#
LSH
2023-12-28 9d8c158d4d3739ae5f8f1cb24b66232362cd44aa
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
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.Mat;
import com.zy.asrs.entity.param.*;
import com.zy.asrs.entity.result.StockVo;
import com.zy.asrs.service.MatService;
import com.zy.asrs.service.OpenService;
import com.zy.common.model.DetlDto;
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.*;
 
/**
 * Created by vincent on 2022/4/8
 */
@Slf4j
@RestController
@RequestMapping("open/asrs")
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;
    @Autowired
    private MatService matService;
 
    @PostMapping("/order/matSync/default/v1")
    @AppAuth(memo = "商品信息同步接口")
    public synchronized R syncMatInfo(@RequestHeader(required = false) String appkey,
                                      @RequestBody(required = false) MatSyncParam param,
                                      HttpServletRequest request){
        auth(appkey, param, request);
        if (Cools.isEmpty(param)) {
            return R.parse(BaseRes.PARAM);
        }
        openService.syncMat(param);
        return R.ok();
    }
 
    /**
     * 添加入库单
     */
    @PostMapping("/order/pakin/default/v1")
    @AppAuth(memo = "添加订单入库")
    public synchronized R pakinOrderCreate(@RequestHeader(required = false) String appkey,
                                           @RequestBody OpenOrderPakinJDParam param1,
                                           HttpServletRequest request) {
        auth(appkey, param1, request);
        if (Cools.isEmpty(param1)) {
            return R.parse(BaseRes.PARAM);
        }
        if (Cools.isEmpty(param1.getOrderNo())) {
            return R.error("单据编号[orderNo]不能为空");
        }
        if (Cools.isEmpty(param1.getId())) {
            return R.error("单据唯一值[id]不能为空");
        }
        if (Cools.isEmpty(param1.getFormId())) {
            return R.error("单据类型[orderType]不能为空");
        }
        if (Cools.isEmpty(param1.getMatList())) {
            return R.error("单据明细[orderDetails]不能为空");
        }
 
 
        List<Map<String, Object>> result = new ArrayList<>();
 
        for (OpenOrderPakinJDParam.DetlDto2 detlDto2:param1.getMatList()){
            Mat mat = matService.selectByMatnr(detlDto2.getMatnr());
            if (Cools.isEmpty(mat)){
                Map<String, Object> map = new HashMap<>();
                map.put("matnr", detlDto2.getMatnr());
                map.put("maktx", detlDto2.getMaktx());
//                map.put("owner", detlDto2.getOwner());
//                map.put("batch", detlDto2.getBatch());
                result.add(map);
            }
        }
        if (!Cools.isEmpty(result) && result.size()!=0){
            return R.error("请先下发以下商品信息:").add(result);
        }
 
 
        OpenOrderPakinParam param = new OpenOrderPakinParam(param1);
        openService.pakinOrderCreate(param);
        return R.ok();
    }
 
    /**
     * 添加入库单
     */
    @PostMapping("/order/pakmove/default/v1")
    @AppAuth(memo = "添加调拨单")
    public synchronized R pakmoveOrderCreate(@RequestHeader(required = false) String appkey,
                                           @RequestBody OpenOrderPakinJDParam param1,
                                           HttpServletRequest request) {
        auth(appkey, param1, request);
        if (Cools.isEmpty(param1)) {
            return R.parse(BaseRes.PARAM);
        }
        if (Cools.isEmpty(param1.getOrderNo())) {
            return R.error("单据编号[orderNo]不能为空");
        }
        if (Cools.isEmpty(param1.getId())) {
            return R.error("单据唯一值[id]不能为空");
        }
//        if (Cools.isEmpty(param1.getFormId())) {
//            return R.error("单据类型[orderType]不能为空");
//        }
        if (Cools.isEmpty(param1.getMatList())) {
            return R.error("单据明细[orderDetails]不能为空");
        }
 
 
        List<Map<String, Object>> result = new ArrayList<>();
 
        for (OpenOrderPakinJDParam.DetlDto2 detlDto2:param1.getMatList()){
            Mat mat = matService.selectByMatnr(detlDto2.getMatnr());
            if (Cools.isEmpty(mat)){
                Map<String, Object> map = new HashMap<>();
                map.put("matnr", detlDto2.getMatnr());
                map.put("maktx", detlDto2.getMaktx());
//                map.put("owner", detlDto2.getOwner());
//                map.put("batch", detlDto2.getBatch());
                result.add(map);
            }
        }
        if (!Cools.isEmpty(result) && result.size()!=0){
            return R.error("请先下发以下商品信息:").add(result);
        }
 
 
        OpenOrderPakinParam param = new OpenOrderPakinParam(param1);
        openService.pakinOrderCreate(param);
        return R.ok();
    }
 
    /*
     * 速腾数字孪生调用接口
     * */
    @PostMapping("/digital/twin/inventory/quantity")
    public synchronized R inventoryQuantity(@RequestHeader(required = false) String appkey,
                                            HttpServletRequest request) {
        auth(appkey, null, request);
        return R.ok(openService.inventoryQuantity());
    }
    /*
     * 速腾数字孪生调用接口
     * */
    @PostMapping("/digital/ownerAll/number/quantity")
    public synchronized R ownerAllNumber(@RequestHeader(required = false) String appkey,
                                         HttpServletRequest request) {
        auth(appkey, null, request);
        return openService.ownerAllNumber();
    }
 
 
    /**
     * 添加出库单
     */
    @PostMapping("/order/pakout/default/v1")
    @AppAuth(memo = "添加订单出库")
    public synchronized R pakoutOrderCreate(@RequestHeader(required = false) String appkey,
                                            @RequestBody OpenOrderPakinJDParam param1,
                                            HttpServletRequest request) {
        auth(appkey, param1, request);
        if (Cools.isEmpty(param1)) {
            return R.parse(BaseRes.PARAM);
        }
        if (Cools.isEmpty(param1.getOrderNo())) {
            return R.error("单据编号[orderNo]不能为空");
        }
        if (Cools.isEmpty(param1.getId())) {
            return R.error("单据唯一值[id]不能为空");
        }
        if (Cools.isEmpty(param1.getFormId())) {
            return R.error("单据类型[FormId]不能为空");
        }
        if (Cools.isEmpty(param1.getCreateDate())) {
            return R.error("单据明细[orderDetails]不能为空");
        }
 
        List<Map<String, Object>> result = new ArrayList<>();
 
        for (OpenOrderPakinJDParam.DetlDto2 detlDto2:param1.getMatList()){
            Mat mat = matService.selectByMatnr(detlDto2.getMatnr());
            if (Cools.isEmpty(mat)){
                Map<String, Object> map = new HashMap<>();
                map.put("matnr", detlDto2.getMatnr());
                map.put("maktx", detlDto2.getMaktx());
//                map.put("owner", detlDto2.getOwner());
//                map.put("batch", detlDto2.getBatch());
                result.add(map);
            }
        }
        if (!Cools.isEmpty(result) && result.size()!=0){
            return R.error("请先下发以下商品信息:").add(result);
        }
        OpenOrderPakoutParam param = new OpenOrderPakoutParam(param1);
 
        openService.pakoutOrderCreate(param);
        return R.ok();
    }
 
 
 
    /**
     * 库存统计
     */
    @RequestMapping("/stock/default/v1")
    public R queryStock(@RequestHeader(required = false) String appkey,
                        @RequestBody StockVo stockVo,
                        HttpServletRequest request) {
        auth(appkey, stockVo, request);
        return R.ok().add(openService.queryStock(stockVo));
    }
 
    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无误!");
        }
    }
 
    /*******************************************************    数字孪生    *******************************************************/
 
    @PostMapping("/wrkdetl")
    public R getInOutDetl(){
        return openService.getInOutDetl();
    }
 
    public static void main(String[] args) {
        // 1
        System.out.println("======================================");
        OpenOrderPakinParam param = new OpenOrderPakinParam();
        param.setOrderNo(String.valueOf(new SnowflakeIdWorker().nextId()));
        param.setOrderType("打包上线单");
        param.setOrderTime(DateUtils.convert(new Date()));
        List<DetlDto> orderDetails = new ArrayList<>();
        param.setOrderDetails(orderDetails);
        for (int i = 0; i < 3; i++) {
            DetlDto detlDto = new DetlDto();
            switch (i) {
                case 0:
                    detlDto.setMatnr("MDH020030530");
                    detlDto.setBatch("500");
                    detlDto.setAnfme(18.0);
                    break;
                case 1:
                    detlDto.setMatnr("MDH020016416");
                    detlDto.setBatch("500");
                    detlDto.setAnfme(32.0);
                    break;
                case 2:
                    detlDto.setMatnr("LSH90152025");
                    detlDto.setAnfme(50.0);
                    break;
                default:
                    break;
            }
            orderDetails.add(detlDto);
        }
        System.out.println(JSON.toJSONString(param));
        // 2
        System.out.println("======================================");
        OpenOrderCompleteParam param1 = new OpenOrderCompleteParam();
        param1.setOrderNo("963001846497017856");
        System.out.println(JSON.toJSONString(param1));
    }
 
}