| | |
| | | @Slf4j |
| | | @Service |
| | | public class TvRcsStationPollService { |
| | | private static final int MAX_LOG_LEN = 2000; |
| | | |
| | | @Resource |
| | | private RestTemplate restTemplate; |
| | |
| | | String stationId = pollProperties.getTaskNoStationId(); |
| | | if (StringUtils.hasText(pollProperties.getTaskNoPollUrl())) { |
| | | try { |
| | | String raw = restTemplate.getForObject(pollProperties.getTaskNoPollUrl(), String.class); |
| | | String raw = pollTaskNoRaw(); |
| | | String taskNo = applyTaskNoResponse(raw, stationId); |
| | | enrichSnapshotFromWms(stationId, taskNo); |
| | | } catch (RestClientException e) { |
| | |
| | | } |
| | | |
| | | 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(createStationBody(pollProperties.getErrorStationId())); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | HttpEntity<String> entity = new HttpEntity<>(objectMapper.writeValueAsString(body), headers); |
| | | HttpEntity<String> entity = new HttpEntity<>(reqBody, headers); |
| | | log.info("RCS站点轮询请求 POST /cv/station/getError url={} body={}", url, trimForLog(reqBody)); |
| | | ResponseEntity<String> resp = restTemplate.exchange( |
| | | pollProperties.getErrorPollUrl(), HttpMethod.POST, entity, String.class); |
| | | return resp.getBody(); |
| | | url, HttpMethod.POST, entity, String.class); |
| | | String respBody = resp.getBody(); |
| | | log.info("RCS站点轮询响应 POST /cv/station/getError body={}", trimForLog(respBody)); |
| | | return respBody; |
| | | } |
| | | return restTemplate.getForObject(pollProperties.getErrorPollUrl(), String.class); |
| | | log.info("RCS站点轮询请求 GET /cv/station/getError url={}", url); |
| | | String raw = restTemplate.getForObject(url, String.class); |
| | | log.info("RCS站点轮询响应 GET /cv/station/getError body={}", trimForLog(raw)); |
| | | 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 合并) */ |
| | |
| | | } |
| | | return arr; |
| | | } |
| | | |
| | | private static String trimForLog(String raw) { |
| | | if (raw == null) { |
| | | return "null"; |
| | | } |
| | | String text = raw.trim(); |
| | | if (text.length() <= MAX_LOG_LEN) { |
| | | return text; |
| | | } |
| | | return text.substring(0, MAX_LOG_LEN) + "...(truncated)"; |
| | | } |
| | | } |