| | |
| | | |
| | | @Override |
| | | public List<CloudWmsNotifyLog> listPending(int limit, int maxRetry) { |
| | | Page<CloudWmsNotifyLog> page = new Page<>(1, Math.max(1, limit)); |
| | | // .lt(CloudWmsNotifyLog::getRetryCount, maxRetry) |
| | | LambdaQueryWrapper<CloudWmsNotifyLog> wrapper = new LambdaQueryWrapper<CloudWmsNotifyLog>() |
| | | .eq(CloudWmsNotifyLog::getNotifyStatus, getNotifyStatusPending()) |
| | | // 仅查询数据库配置状态:待通知 + 失败(可重试) |
| | | .in(CloudWmsNotifyLog::getNotifyStatus, getNotifyStatusPending(), getNotifyStatusFail()) |
| | | // 仅查询可重试数据:无限重试、未配置上限、或未达到上限 |
| | | .apply("(max_retry_count IS NULL OR max_retry_count = -1 OR retry_count < max_retry_count)") |
| | | // 仅查询已到重试时间的数据,避免前 50 条未到间隔导致后续记录长期饥饿 |
| | | .apply("(last_notify_time IS NULL OR retry_interval_seconds IS NULL OR retry_interval_seconds <= 0 OR TIMESTAMPDIFF(SECOND, last_notify_time, NOW()) >= retry_interval_seconds)") |
| | | .orderByAsc(CloudWmsNotifyLog::getLastNotifyTime) |
| | | .orderByAsc(CloudWmsNotifyLog::getId); |
| | | if (maxRetry >= 0) { |
| | | wrapper.lt(CloudWmsNotifyLog::getRetryCount, maxRetry); |
| | | } |
| | | if (limit < 0) { |
| | | return list(wrapper); |
| | | } |
| | | Page<CloudWmsNotifyLog> page = new Page<>(1, Math.max(1, limit)); |
| | | return page(page, wrapper).getRecords(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | private String getConfigString(String flag, String defaultVal) { |
| | | Config c = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, flag).last("LIMIT 1")); |
| | | Config c = configService.getOne(new LambdaQueryWrapper<Config>() |
| | | .eq(Config::getFlag, flag) |
| | | .orderByDesc(Config::getId) |
| | | .last("LIMIT 1")); |
| | | if (c != null && c.getVal() != null && !c.getVal().isEmpty()) { |
| | | return c.getVal().trim(); |
| | | } |
| | |
| | | public void fillFromConfig(CloudWmsNotifyLog log) { |
| | | Integer maxRetry = getConfigInt(GlobalConfigCode.CLOUD_WMS_NOTIFY_MAX_RETRY); |
| | | Integer interval = getConfigInt(GlobalConfigCode.CLOUD_WMS_NOTIFY_RETRY_INTERVAL_SECONDS); |
| | | log.setNotifyStatus(getNotifyStatusPending()); |
| | | log.setMaxRetryCount(maxRetry); |
| | | log.setRetryIntervalSeconds(interval); |
| | | } |
| | |
| | | /** 返回 null 表示未配置或解析失败 */ |
| | | private Integer getConfigInt(String flag) { |
| | | try { |
| | | Config c = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, flag).last("LIMIT 1")); |
| | | Config c = configService.getOne(new LambdaQueryWrapper<Config>() |
| | | .eq(Config::getFlag, flag) |
| | | .orderByDesc(Config::getId) |
| | | .last("LIMIT 1")); |
| | | if (c != null && c.getVal() != null && !c.getVal().isEmpty()) { |
| | | return Integer.parseInt(c.getVal().trim()); |
| | | } |