zhangc
2025-03-15 a402a173ebbaa5851f2b76be9f6102c054a2832b
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
package com.zy.asrs.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.core.common.Cools;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.entity.TaskWrkReport;
import com.zy.asrs.entity.wms.StorageEscalationParam;
import com.zy.asrs.entity.wms.WmsResult;
import com.zy.asrs.service.*;
import com.zy.common.service.CommonService;
import com.zy.common.utils.HttpHandler;
import com.zy.common.utils.Synchro;
import com.zy.core.properties.SlaveProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import java.io.IOException;
import java.util.Date;
 
@Service
public class ToWmsServiceImpl implements ToWmsService {
 
 
    @Autowired
    private TaskWrkService taskWrkService;
    @Autowired
    private SlaveProperties slaveProperties;
    @Autowired
    private TaskWrkReportService taskWrkReportService;
    @Autowired
    private StaDescService staDescService;
    @Autowired
    private CommonService commonService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private BasDevpService basDevpService;
 
 
    @Autowired
    private ApiLogService apiLogService;
 
 
    @Value("${wms.url}")
    private String wmsUrl;
    /**
     * 申请入库
     */
    @Value("${wms.inboundTaskApplyPath}")
    private String inboundTaskApplyPath;
    /**
     * 任务开始时,WCS回调WMS
     */
    @Value("${wms.taskExecCallback}")
    private String taskExecCallback;
    /**
     * 任务完成结束时,WCS回调WMS
     */
    @Value("${wms.taskStatusFeedbackPath}")
    private String taskStatusFeedbackPath;
 
    @Value("${wms.code}")
    private String code;
 
    @Value("${wms.successCode}")
    private String successCode;
 
    @Value("${wms.msg}")
    private String msg;
 
    @Value("${wms.data}")
    private String data;
 
    @Override
    public void addReportLog(TaskWrk taskWrk) {
        TaskWrkReport taskWrkReport = new TaskWrkReport();
        Synchro.Copy(taskWrk, taskWrkReport);
        taskWrkReport.setCreateTime(new Date());
        taskWrkReportService.insert(taskWrkReport);
    }
 
    @Override
    public WmsResult getLocNoFromWms(StorageEscalationParam wmsParam) {
        String response = "";
        Boolean success = false;
        try {
            response = new HttpHandler.Builder()
                    .setUri(wmsUrl)
                    .setPath(inboundTaskApplyPath)
                    .setJson(JSON.toJSONString(wmsParam))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            if (!Cools.isEmpty(response) && !Cools.isEmpty(jsonObject.get(code)) && jsonObject.get(code).equals(successCode)) {
                WmsResult result = JSON.parseObject(jsonObject.get(data).toString(), WmsResult.class);
                return result;
            }
        } catch (IOException e) {
 
        } finally {
            addApiLog("入库任务请求获取库位", wmsUrl + inboundTaskApplyPath, JSON.toJSONString(wmsParam), response, success);
        }
        return null;
    }
 
 
    private void addApiLog(String nameSpace, String url, String param, String response, Boolean success) {
        apiLogService.save(nameSpace, url, null, "127.0.0.1", param, response, success);
    }
}