| | |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Collection; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | |
| | | String stationId = pollProperties.getTaskNoStationId(); |
| | | if (StringUtils.hasText(pollProperties.getTaskNoPollUrl())) { |
| | | try { |
| | | String url = pollProperties.getTaskNoPollUrl(); |
| | | log.info("RCS站点轮询请求 GET /cv/station/getTaskNo url={}", url); |
| | | String raw = restTemplate.getForObject(url, String.class); |
| | | log.info("RCS站点轮询响应 GET /cv/station/getTaskNo body={}", trimForLog(raw)); |
| | | String raw = pollTaskNoRaw(); |
| | | String taskNo = applyTaskNoResponse(raw, stationId); |
| | | enrichSnapshotFromWms(stationId, taskNo); |
| | | } catch (RestClientException e) { |
| | |
| | | try { |
| | | Map<String, Object> res = wmsServerFeignClient.openAsrsQueryTask(req); |
| | | if (res == null) { |
| | | wcsStationStatusService.upsertFromRcsPoll(stationId, taskNo, null); |
| | | // wcsStationStatusService.upsertFromRcsPoll(stationId, taskNo, null); |
| | | wcsStationStatusService.clearStationSnapshot(stationId); |
| | | return; |
| | | } |
| | | Object codeObj = res.get("code"); |
| | | int code = parseCode(codeObj); |
| | | if (code != 200) { |
| | | log.debug("WMS queryTask 非成功 code={} msg={}", code, res.get("msg")); |
| | | wcsStationStatusService.upsertFromRcsPoll(stationId, taskNo, null); |
| | | // wcsStationStatusService.upsertFromRcsPoll(stationId, taskNo, null); |
| | | wcsStationStatusService.clearStationSnapshot(stationId); |
| | | return; |
| | | } |
| | | Object data = res.get("data"); |
| | | @SuppressWarnings("unchecked") |
| | | Map<String, Object> dataMap = data instanceof Map ? (Map<String, Object>) data : null; |
| | | if (dataMap == null || !hasWrkDetls(dataMap)) { |
| | | // queryTask 空数据时清空站点缓存,避免电视机显示历史物料 |
| | | wcsStationStatusService.clearStationSnapshot(stationId); |
| | | return; |
| | | } |
| | | wcsStationStatusService.upsertFromRcsPoll(stationId, taskNo, dataMap); |
| | | } catch (Exception e) { |
| | | log.warn("WMS queryTask 调用失败: {}", e.getMessage()); |
| | | wcsStationStatusService.upsertFromRcsPoll(stationId, taskNo, null); |
| | | // wcsStationStatusService.upsertFromRcsPoll(stationId, taskNo, null); |
| | | wcsStationStatusService.clearStationSnapshot(stationId); |
| | | } |
| | | } |
| | | |
| | | private static boolean hasWrkDetls(Map<String, Object> dataMap) { |
| | | if (dataMap == null) { |
| | | return false; |
| | | } |
| | | Object wrkDetls = dataMap.get("wrkDetls"); |
| | | if (wrkDetls == null) { |
| | | return false; |
| | | } |
| | | if (wrkDetls instanceof Collection) { |
| | | return !((Collection<?>) wrkDetls).isEmpty(); |
| | | } |
| | | if (wrkDetls.getClass().isArray()) { |
| | | return java.lang.reflect.Array.getLength(wrkDetls) > 0; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private static int parseCode(Object codeObj) { |
| | |
| | | private String pollErrorRaw() throws Exception { |
| | | String url = pollProperties.getErrorPollUrl(); |
| | | if (pollProperties.isErrorPollUsePost()) { |
| | | ObjectNode body = objectMapper.createObjectNode(); |
| | | body.put("staNo", pollProperties.getErrorStationId()); |
| | | String reqBody = objectMapper.writeValueAsString(body); |
| | | String reqBody = objectMapper.writeValueAsString(createStationBody(pollProperties.getErrorStationId())); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | HttpEntity<String> entity = new HttpEntity<>(reqBody, headers); |
| | |
| | | return raw; |
| | | } |
| | | |
| | | private String pollTaskNoRaw() throws Exception { |
| | | String url = pollProperties.getTaskNoPollUrl(); |
| | | if (pollProperties.isTaskNoPollUsePost()) { |
| | | String reqBody = objectMapper.writeValueAsString(createStationBody(pollProperties.getTaskNoStationId())); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | HttpEntity<String> entity = new HttpEntity<>(reqBody, headers); |
| | | // log.info("RCS站点轮询请求 GET /cv/station/getTaskNo url={}", url); |
| | | log.info("RCS站点轮询请求 POST /cv/station/getTaskNo url={} body={}", url, trimForLog(reqBody)); |
| | | ResponseEntity<String> resp = restTemplate.exchange( |
| | | url, HttpMethod.POST, entity, String.class); |
| | | String respBody = resp.getBody(); |
| | | // log.info("RCS站点轮询响应 GET /cv/station/getTaskNo body={}", trimForLog(raw)); |
| | | log.info("RCS站点轮询响应 POST /cv/station/getTaskNo body={}", trimForLog(respBody)); |
| | | return respBody; |
| | | } |
| | | log.info("RCS站点轮询请求 GET /cv/station/getTaskNo url={}", url); |
| | | String raw = restTemplate.getForObject(url, String.class); |
| | | log.info("RCS站点轮询响应 GET /cv/station/getTaskNo body={}", trimForLog(raw)); |
| | | return raw; |
| | | } |
| | | |
| | | private ObjectNode createStationBody(String stationId) { |
| | | ObjectNode body = objectMapper.createObjectNode(); |
| | | if (StringUtils.hasText(stationId)) { |
| | | body.put("stationId", stationId); |
| | | body.put("staNo", stationId); |
| | | } |
| | | return body; |
| | | } |
| | | |
| | | /** 写入 tvRcs 任务号 Hash;返回解析出的 taskNo(用于 WMS 合并) */ |
| | | private String applyTaskNoResponse(String raw, String staNo) { |
| | | if (!StringUtils.hasText(staNo)) { |