| | |
| | | */ |
| | | @Override |
| | | public CommonResponse reportTask(TaskReportParams params) { |
| | | log.info("RCS回调,请求参数: {}", JSONObject.toJSONString(params)); |
| | | log.info("任务执行通知上报,请求参数: {}", JSONObject.toJSONString(params)); |
| | | |
| | | // 参数校验 |
| | | if (Objects.isNull(params)) { |
| | |
| | | |
| | | // 将任务上报回调转发到WMS系统 |
| | | String callUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.callBack; |
| | | log.info("RCS回调,请求地址: {}, 转换后参数: {}", callUrl, exMsgParams.toJSONString()); |
| | | log.info("任务执行通知上报,请求地址: {}, 转换后参数: {}", callUrl, exMsgParams.toJSONString()); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add("Content-Type", "application/json"); |
| | | headers.add("api-version", "v2.0"); |
| | | HttpEntity httpEntity = new HttpEntity(exMsgParams, headers); |
| | | ResponseEntity<String> exchange = restTemplate.exchange(callUrl, HttpMethod.POST, httpEntity, String.class); |
| | | log.info("RCS回调,响应结果: {}", exchange); |
| | | log.info("任务执行通知上报,响应结果: {}", exchange); |
| | | |
| | | if (Objects.isNull(exchange.getBody())) { |
| | | // 如果回调失败,返回成功响应(避免RCS重复回调) |
| | | CommonResponse response = new CommonResponse(); |
| | | response.setCode(200); |
| | | response.setMsg("接收成功"); |
| | | log.warn("RCS回调失败,但返回成功响应,任务编号:{},批次:{}", params.getTaskNo(), params.getBatchNo()); |
| | | log.warn("任务执行通知上报回调失败,但返回成功响应,任务编号:{},批次:{}", params.getTaskNo(), params.getBatchNo()); |
| | | return response; |
| | | } else { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | |
| | | try { |
| | | CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class); |
| | | if (result.getCode() == 200) { |
| | | log.info("RCS回调上报成功,任务编号:{},批次:{}", params.getTaskNo(), params.getBatchNo()); |
| | | log.info("任务执行通知上报成功,任务编号:{},批次:{}", params.getTaskNo(), params.getBatchNo()); |
| | | return result; |
| | | } else { |
| | | log.warn("RCS回调上报回调返回非200状态,任务编号:{},批次:{},响应:{}", params.getTaskNo(), params.getBatchNo(), exchange.getBody()); |
| | | log.warn("任务执行通知上报回调返回非200状态,任务编号:{},批次:{},响应:{}", params.getTaskNo(), params.getBatchNo(), exchange.getBody()); |
| | | return result; |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | log.error("RCS回调上报回调响应解析失败,任务编号:{},批次:{},错误:{}", params.getTaskNo(), params.getBatchNo(), e.getMessage()); |
| | | log.error("任务执行通知上报回调响应解析失败,任务编号:{},批次:{},错误:{}", params.getTaskNo(), params.getBatchNo(), e.getMessage()); |
| | | // 解析失败时返回成功响应,避免RCS重复回调 |
| | | CommonResponse response = new CommonResponse(); |
| | | response.setCode(200); |