#
1
2 天以前 4e185f9a4d5ba2dffc922c2970badfe0a398e1c5
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
package com.vincent.rsf.openApi.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.CoercionAction;
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.openApi.config.PlatformProperties;
import com.vincent.rsf.openApi.entity.Loc;
import com.vincent.rsf.openApi.entity.constant.WmsConstant;
import com.vincent.rsf.openApi.entity.dto.CommonResponse;
import com.vincent.rsf.openApi.entity.params.WcsChangeLocParam;
import com.vincent.rsf.openApi.entity.params.WcsCreateInTaskParam;
import com.vincent.rsf.openApi.entity.params.WcsReassignLocParam;
import com.vincent.rsf.openApi.entity.params.WcsTaskReportParam;
import com.vincent.rsf.openApi.mapper.LocMapper;
import com.vincent.rsf.openApi.service.WmsWcsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
 
import java.util.Objects;
 
 
@Slf4j
@Service("wmsWcsService")
public class WmsWcsServiceImpl extends ServiceImpl<LocMapper, Loc> implements WmsWcsService {
 
    @Autowired
    private PlatformProperties.WmsApi wmsApi;
 
    @Autowired
    private RestTemplate restTemplate;
 
    /**
     * @author Munch D. Luffy
     * @date 2026/01/09
     * @description: 任务下发
     * @version 1.0
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R wcsCreateInTask(WcsCreateInTaskParam params)  {
        String createInTask =  wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.WCS_CREATE_IN_TASK;
        /**WMS基础配置链接*/
        log.info("入库任务申请,请求地址: {}, 请求参数: {}", createInTask , JSONObject.toJSONString(params));
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json");
        headers.add("api-version", "v2.0");
        HttpEntity httpEntity = new HttpEntity(params, headers);
        ResponseEntity<String> exchange = restTemplate.exchange(createInTask, HttpMethod.POST, httpEntity, String.class);
        log.info("WCS入库任务申请,响应结果: {}", exchange);
        if (Objects.isNull(exchange.getBody())) {
            return R.error().add("下发WMS返回参数为空!!!");
        } else {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.coercionConfigDefaults()
                    .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
            try {
                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
                if (result.getCode() == 200) {
                    return R.ok();
                } else {
                    return R.error(result.getMsg());
//                    throw new CoolException("任务执行状态上报失败!!");
                }
            } catch (JsonProcessingException e) {
//                throw new CoolException(e.getMessage());
            }
        }
        return R.error();
    }
 
    /**
     * @author Munch D. Luffy
     * @date 2026/01/09
     * @description: WCS任务上报通知
     * @version 1.0
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R wcsTaskReport(WcsTaskReportParam params)  {
        String createInTask =  wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.WCS_TASK_REPORT;
        /**WMS基础配置链接*/
        log.info("WCS任务上报通知,请求地址: {}, 请求参数: {}", createInTask , JSONObject.toJSONString(params));
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json");
        headers.add("api-version", "v2.0");
        HttpEntity httpEntity = new HttpEntity(params, headers);
        ResponseEntity<String> exchange = restTemplate.exchange(createInTask, HttpMethod.POST, httpEntity, String.class);
        log.info("WCS任务上报通知,响应结果: {}", exchange);
        if (Objects.isNull(exchange.getBody())) {
            return R.error().add("WCS任务上报通知告知wms返回参数为空!!!");
        } else {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.coercionConfigDefaults()
                    .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
            try {
                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
                if (result.getCode() == 200) {
                    return R.ok();
                } else {
                    return R.error(result.getMsg());
//                    throw new CoolException("任务执行状态上报失败!!");
                }
            } catch (JsonProcessingException e) {
//                throw new CoolException(e.getMessage());
            }
        }
        return R.error();
    }
 
    /**
     * @author Munch D. Luffy
     * @date 2026/01/09
     * @description: WCS申请任务重新分配入库
     * @version 1.0
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R wcsReassignLoc(WcsReassignLocParam params)  {
        String createInTask =  wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.WCS_REASSIGN_LOC;
        /**WMS基础配置链接*/
        log.info("WCS申请任务重新分配入库,请求地址: {}, 请求参数: {}", createInTask , JSONObject.toJSONString(params));
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json");
        headers.add("api-version", "v2.0");
        HttpEntity httpEntity = new HttpEntity(params, headers);
        ResponseEntity<String> exchange = restTemplate.exchange(createInTask, HttpMethod.POST, httpEntity, String.class);
        log.info("WCS申请任务重新分配入库,响应结果: {}", exchange);
        if (Objects.isNull(exchange.getBody())) {
            return R.error().add("WCS申请任务重新分配入库告知wms返回参数为空!!!");
        } else {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.coercionConfigDefaults()
                    .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
            try {
                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
                if (result.getCode() == 200) {
                    return R.ok();
                } else {
                    return R.error(result.getMsg());
//                    throw new CoolException("任务执行状态上报失败!!");
                }
            } catch (JsonProcessingException e) {
//                throw new CoolException(e.getMessage());
            }
        }
        return R.error();
    }
 
    /**
     * @author Munch D. Luffy
     * @date 2026/01/09
     * @description: WCS申请在库库位更换库位
     * @version 1.0
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R wcsChangeLoc(WcsChangeLocParam params)  {
        String createInTask =  wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.WCS_CHANGE_LOC;
        /**WMS基础配置链接*/
        log.info("WCS申请在库库位更换库位,请求地址: {}, 请求参数: {}", createInTask , JSONObject.toJSONString(params));
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json");
        headers.add("api-version", "v2.0");
        HttpEntity httpEntity = new HttpEntity(params, headers);
        ResponseEntity<String> exchange = restTemplate.exchange(createInTask, HttpMethod.POST, httpEntity, String.class);
        log.info("WCS申请在库库位更换库位,响应结果: {}", exchange);
        if (Objects.isNull(exchange.getBody())) {
            return R.error().add("WCS申请在库库位更换库位告知wms返回参数为空!!!");
        } else {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.coercionConfigDefaults()
                    .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
            try {
                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
                if (result.getCode() == 200) {
                    return R.ok();
                } else {
                    return R.error(result.getMsg());
//                    throw new CoolException("任务执行状态上报失败!!");
                }
            } catch (JsonProcessingException e) {
//                throw new CoolException(e.getMessage());
            }
        }
        return R.error();
    }
}