| | |
| | | |
| | | @Scheduled(cron = "0/30 * * * * ?") |
| | | public void syncCloudWmsNotify() { |
| | | List<CloudWmsNotifyLog> pending = cloudWmsNotifyLogService.listPending(BATCH_LIMIT, 999); |
| | | // List<CloudWmsNotifyLog> pending = cloudWmsNotifyLogService.listPending(BATCH_LIMIT, 999); |
| | | List<CloudWmsNotifyLog> pending = cloudWmsNotifyLogService.listPending(BATCH_LIMIT, -1); |
| | | if (pending.isEmpty()) { |
| | | return; |
| | | } |
| | |
| | | Integer maxRetry = logRecord.getMaxRetryCount(); |
| | | Integer intervalSeconds = logRecord.getRetryIntervalSeconds(); |
| | | if (maxRetry == null || intervalSeconds == null || intervalSeconds <= 0) { |
| | | log.warn("云仓上报待办跳过:重试参数缺失,id={},bizRef={},maxRetry={},intervalSeconds={}", |
| | | logRecord.getId(), logRecord.getBizRef(), maxRetry, intervalSeconds); |
| | | continue; |
| | | } |
| | | if (logRecord.getRetryCount() != null && logRecord.getRetryCount() >= maxRetry) { |
| | | // if (logRecord.getRetryCount() != null && logRecord.getRetryCount() >= maxRetry) { |
| | | if (!isInfiniteRetry(maxRetry) |
| | | && logRecord.getRetryCount() != null |
| | | && logRecord.getRetryCount() >= maxRetry) { |
| | | log.info("云仓上报待办跳过:重试次数已达上限,id={},bizRef={},retryCount={},maxRetry={}", |
| | | logRecord.getId(), logRecord.getBizRef(), logRecord.getRetryCount(), maxRetry); |
| | | continue; |
| | | } |
| | | if (logRecord.getLastNotifyTime() != null) { |
| | | long elapsed = (nowMs - logRecord.getLastNotifyTime().getTime()) / 1000; |
| | | if (elapsed < intervalSeconds) { |
| | | log.info("云仓上报待办跳过:未到重试间隔,id={},bizRef={},elapsed={}s,interval={}s", |
| | | logRecord.getId(), logRecord.getBizRef(), elapsed, intervalSeconds); |
| | | continue; |
| | | } |
| | | } |
| | |
| | | Date now = new Date(); |
| | | int nextRetry = (logRecord.getRetryCount() == null ? 0 : logRecord.getRetryCount()) + 1; |
| | | int effectiveMaxRetry = logRecord.getMaxRetryCount(); |
| | | log.info("云仓上报开始,id={},bizRef={},reportType={},attempt={},requestBody={}", |
| | | logRecord.getId(), logRecord.getBizRef(), reportType, nextRetry, requestBody); |
| | | |
| | | try { |
| | | if (cloudWmsNotifyLogService.getReportTypeInOutResult().equals(reportType)) { |
| | |
| | | responseJson = String.valueOf(res); |
| | | } |
| | | Object codeObj = res != null ? res.get("code") : null; |
| | | boolean success = Integer.valueOf(200).equals(codeObj); |
| | | int status = success ? cloudWmsNotifyLogService.getNotifyStatusSuccess() : cloudWmsNotifyLogService.getNotifyStatusPending(); |
| | | if (!success && nextRetry >= effectiveMaxRetry) { |
| | | status = cloudWmsNotifyLogService.getNotifyStatusFail(); |
| | | } |
| | | Object statusObj = res != null ? res.get("status") : null; |
| | | boolean success = Integer.valueOf(200).equals(codeObj) || Integer.valueOf(200).equals(statusObj); |
| | | int status = success ? cloudWmsNotifyLogService.getNotifyStatusSuccess() : cloudWmsNotifyLogService.getNotifyStatusFail(); |
| | | logRecord.setLastRequestBody(requestBody); |
| | | logRecord.setLastResponseBody(responseJson); |
| | | logRecord.setLastNotifyTime(now); |
| | |
| | | logRecord.setNotifyStatus(status); |
| | | logRecord.setUpdateTime(now); |
| | | cloudWmsNotifyLogService.updateById(logRecord); |
| | | log.info("云仓上报结束,id={},bizRef={},attempt={},notifyStatus={},responseBody={}", |
| | | logRecord.getId(), logRecord.getBizRef(), nextRetry, status, responseJson); |
| | | } |
| | | |
| | | private void setFailResult(CloudWmsNotifyLog logRecord, String requestBody, String errorMsg, int nextRetry, Date now, int effectiveMaxRetry) { |
| | |
| | | logRecord.setLastResponseBody(errorMsg); |
| | | logRecord.setLastNotifyTime(now); |
| | | logRecord.setRetryCount(nextRetry); |
| | | logRecord.setNotifyStatus(nextRetry >= effectiveMaxRetry ? cloudWmsNotifyLogService.getNotifyStatusFail() : cloudWmsNotifyLogService.getNotifyStatusPending()); |
| | | // logRecord.setNotifyStatus(nextRetry >= effectiveMaxRetry ? cloudWmsNotifyLogService.getNotifyStatusFail() : cloudWmsNotifyLogService.getNotifyStatusPending()); |
| | | int status = !isInfiniteRetry(effectiveMaxRetry) && nextRetry >= effectiveMaxRetry |
| | | ? cloudWmsNotifyLogService.getNotifyStatusFail() |
| | | : cloudWmsNotifyLogService.getNotifyStatusPending(); |
| | | logRecord.setNotifyStatus(status); |
| | | logRecord.setUpdateTime(now); |
| | | cloudWmsNotifyLogService.updateById(logRecord); |
| | | log.warn("云仓上报失败,id={},bizRef={},attempt={},notifyStatus={},error={}", |
| | | logRecord.getId(), logRecord.getBizRef(), nextRetry, logRecord.getNotifyStatus(), errorMsg); |
| | | } |
| | | |
| | | /** maxRetry = -1 表示无限重发 */ |
| | | private boolean isInfiniteRetry(Integer maxRetry) { |
| | | return maxRetry != null && maxRetry == -1; |
| | | } |
| | | } |