| | |
| | | import com.vincent.rsf.openApi.entity.dto.CommonResponse; |
| | | import com.vincent.rsf.openApi.entity.constant.RcsConstant; |
| | | import com.vincent.rsf.openApi.entity.dto.SyncLocsDto; |
| | | import com.vincent.rsf.openApi.entity.dto.LocationAllocateResponse; |
| | | import com.vincent.rsf.openApi.entity.params.ExMsgCallbackParams; |
| | | import com.vincent.rsf.openApi.entity.params.LocSiteParams; |
| | | import com.vincent.rsf.openApi.entity.params.LocationAllocateParams; |
| | | import com.vincent.rsf.openApi.entity.params.RcsPubTaskParams; |
| | | import com.vincent.rsf.openApi.entity.params.SyncRcsLocsParam; |
| | | import com.vincent.rsf.openApi.entity.params.TaskReportParams; |
| | |
| | | */ |
| | | @Override |
| | | public CommonResponse reportTask(TaskReportParams params) { |
| | | log.info("任务执行通知上报,请求参数: {}", JSONObject.toJSONString(params)); |
| | | log.info("RCS回调,请求参数: {}", JSONObject.toJSONString(params)); |
| | | |
| | | // 参数校验 |
| | | if (Objects.isNull(params)) { |
| | |
| | | |
| | | // 将任务上报回调转发到WMS系统 |
| | | String callUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.callBack; |
| | | log.info("任务执行通知上报,请求地址: {}, 转换后参数: {}", callUrl, exMsgParams.toJSONString()); |
| | | log.info("RCS回调-WMS-SERVER任务上报-,请求地址: {}, 转换后参数: {}", 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("任务执行通知上报,响应结果: {}", exchange); |
| | | log.info("RCS回调-WMS-SERVER任务上报-,响应结果: {}", exchange); |
| | | |
| | | if (Objects.isNull(exchange.getBody())) { |
| | | // 如果回调失败,返回成功响应(避免RCS重复回调) |
| | | CommonResponse response = new CommonResponse(); |
| | | response.setCode(200); |
| | | response.setMsg("接收成功"); |
| | | log.warn("任务执行通知上报回调失败,但返回成功响应,任务编号:{},批次:{}", params.getTaskNo(), params.getBatchNo()); |
| | | return response; |
| | | // 回调失败,抛出异常 |
| | | log.error("========== RCS回调-WMS-SERVER任务上报-失败 =========="); |
| | | log.error("RCS回调-WMS-SERVER任务上报-响应体为空,无法解析响应结果"); |
| | | log.error("RCS回调-WMS-SERVER任务上报-请求地址:{}", callUrl); |
| | | log.error("RCS回调-WMS-SERVER任务上报-请求参数:{}", exMsgParams.toJSONString()); |
| | | log.error("RCS回调-WMS-SERVER任务上报-失败的任务编号:{},批次:{}", params.getTaskNo(), params.getBatchNo()); |
| | | throw new CoolException("RCS回调-WMS-SERVER任务上报-失败,WMS响应体为空!任务编号:" + params.getTaskNo() + ",批次:" + params.getBatchNo()); |
| | | } else { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | objectMapper.coercionConfigDefaults() |
| | |
| | | try { |
| | | CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class); |
| | | if (result.getCode() == 200) { |
| | | log.info("任务执行通知上报成功,任务编号:{},批次:{}", params.getTaskNo(), params.getBatchNo()); |
| | | log.info("RCS回调-WMS-SERVER任务上报-成功,任务编号:{},批次:{}", params.getTaskNo(), params.getBatchNo()); |
| | | return result; |
| | | } else { |
| | | log.warn("任务执行通知上报回调返回非200状态,任务编号:{},批次:{},响应:{}", params.getTaskNo(), params.getBatchNo(), exchange.getBody()); |
| | | log.warn("RCS回调-WMS-SERVER任务上报-返回非200状态,任务编号:{},批次:{},响应:{}", params.getTaskNo(), params.getBatchNo(), exchange.getBody()); |
| | | return result; |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | log.error("任务执行通知上报回调响应解析失败,任务编号:{},批次:{},错误:{}", params.getTaskNo(), params.getBatchNo(), e.getMessage()); |
| | | log.error("RCS回调-WMS-SERVER任务上报-响应解析失败,任务编号:{},批次:{},错误:{}", params.getTaskNo(), params.getBatchNo(), e.getMessage()); |
| | | // 解析失败时返回成功响应,避免RCS重复回调 |
| | | CommonResponse response = new CommonResponse(); |
| | | response.setCode(200); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2026/2/6 |
| | | * @description: 申请入库任务,分配库位 |
| | | * @version 1.0 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R allocateLocation(LocationAllocateParams params) { |
| | | log.info("========== 开始申请入库任务,分配库位 =========="); |
| | | log.info("料箱码:{},入库站点:{},入库类型:{}", params.getBarcode(), params.getStaNo(), params.getType()); |
| | | |
| | | // 调用WMS server内部接口进行库位分配 |
| | | String wmsUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + "/rsf-server/wcs/allocate/location"; |
| | | log.info("WMS请求地址:{}", wmsUrl); |
| | | |
| | | // 构建请求参数 |
| | | JSONObject requestParams = new JSONObject(); |
| | | requestParams.put("barcode", params.getBarcode()); |
| | | requestParams.put("staNo", params.getStaNo()); |
| | | requestParams.put("type", params.getType()); |
| | | log.info("请求参数:{}", requestParams.toJSONString()); |
| | | |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add("Content-Type", "application/json"); |
| | | HttpEntity httpEntity = new HttpEntity(requestParams, headers); |
| | | |
| | | long startTime = System.currentTimeMillis(); |
| | | ResponseEntity<String> exchange = restTemplate.exchange(wmsUrl, HttpMethod.POST, httpEntity, String.class); |
| | | long endTime = System.currentTimeMillis(); |
| | | log.info("WMS响应耗时:{}ms", (endTime - startTime)); |
| | | log.info("WMS响应状态码:{}", exchange.getStatusCode()); |
| | | log.info("WMS响应体:{}", exchange.getBody()); |
| | | |
| | | if (Objects.isNull(exchange.getBody())) { |
| | | log.error("========== 申请入库任务失败 =========="); |
| | | log.error("WMS响应体为空,无法解析响应结果"); |
| | | return R.error("申请入库任务失败,WMS响应体为空!!"); |
| | | } else { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | objectMapper.coercionConfigDefaults() |
| | | .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty); |
| | | try { |
| | | JSONObject responseJson = JSONObject.parseObject(exchange.getBody()); |
| | | Integer code = responseJson.getInteger("code"); |
| | | String msg = responseJson.getString("msg"); |
| | | |
| | | if (code != null && code == 200) { |
| | | JSONObject data = responseJson.getJSONObject("data"); |
| | | if (data != null) { |
| | | String locNo = data.getString("locNo"); |
| | | log.info("========== 申请入库任务成功 =========="); |
| | | log.info("分配库位号:{}", locNo); |
| | | |
| | | LocationAllocateResponse response = new LocationAllocateResponse(); |
| | | response.setLocNo(locNo); |
| | | return R.ok(response); |
| | | } else { |
| | | log.error("========== 申请入库任务失败 =========="); |
| | | log.error("响应数据为空"); |
| | | return R.error("申请入库任务失败,响应数据为空!!"); |
| | | } |
| | | } else { |
| | | log.error("========== 申请入库任务失败 =========="); |
| | | log.error("WMS返回错误 - code:{},msg:{}", code, msg); |
| | | return R.error(msg != null ? msg : "申请入库任务失败!!"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("========== 申请入库任务异常 =========="); |
| | | log.error("解析WMS响应失败,响应体:{}", exchange.getBody(), e); |
| | | return R.error("解析WMS响应失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | } |