package com.vincent.rsf.server.manager.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.vincent.rsf.server.manager.entity.CloudWmsNotifyLog; import com.vincent.rsf.server.manager.mapper.CloudWmsNotifyLogMapper; import com.vincent.rsf.server.manager.service.CloudWmsNotifyLogService; import com.vincent.rsf.server.system.constant.GlobalConfigCode; import com.vincent.rsf.server.system.entity.Config; import com.vincent.rsf.server.system.service.ConfigService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class CloudWmsNotifyLogServiceImpl extends ServiceImpl implements CloudWmsNotifyLogService { @Autowired private ConfigService configService; @Override public List listPending(int limit, int maxRetry) { Page page = new Page<>(1, Math.max(1, limit)); LambdaQueryWrapper wrapper = new LambdaQueryWrapper() .eq(CloudWmsNotifyLog::getNotifyStatus, getNotifyStatusPending()) .lt(CloudWmsNotifyLog::getRetryCount, maxRetry) .orderByAsc(CloudWmsNotifyLog::getId); return page(page, wrapper).getRecords(); } @Override public String getReportTypeInOutResult() { return getConfigString(GlobalConfigCode.CLOUD_WMS_REPORT_TYPE_IN_OUT_RESULT, CloudWmsNotifyLog.REPORT_TYPE_IN_OUT_RESULT); } @Override public String getReportTypeInventoryAdjust() { return getConfigString(GlobalConfigCode.CLOUD_WMS_REPORT_TYPE_INVENTORY_ADJUST, CloudWmsNotifyLog.REPORT_TYPE_INVENTORY_ADJUST); } @Override public int getNotifyStatusPending() { return getConfigInt(GlobalConfigCode.CLOUD_WMS_NOTIFY_STATUS_PENDING, CloudWmsNotifyLog.NOTIFY_STATUS_PENDING); } @Override public int getNotifyStatusSuccess() { return getConfigInt(GlobalConfigCode.CLOUD_WMS_NOTIFY_STATUS_SUCCESS, CloudWmsNotifyLog.NOTIFY_STATUS_SUCCESS); } @Override public int getNotifyStatusFail() { return getConfigInt(GlobalConfigCode.CLOUD_WMS_NOTIFY_STATUS_FAIL, CloudWmsNotifyLog.NOTIFY_STATUS_FAIL); } private String getConfigString(String flag, String defaultVal) { Config c = configService.getOne(new LambdaQueryWrapper().eq(Config::getFlag, flag).last("LIMIT 1")); if (c != null && c.getVal() != null && !c.getVal().isEmpty()) { return c.getVal().trim(); } return defaultVal; } private int getConfigInt(String flag, int defaultVal) { Integer v = getConfigInt(flag); return v != null ? v : defaultVal; } @Override 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.setMaxRetryCount(maxRetry); log.setRetryIntervalSeconds(interval); } /** 返回 null 表示未配置或解析失败 */ private Integer getConfigInt(String flag) { try { Config c = configService.getOne(new LambdaQueryWrapper().eq(Config::getFlag, flag).last("LIMIT 1")); if (c != null && c.getVal() != null && !c.getVal().isEmpty()) { return Integer.parseInt(c.getVal().trim()); } } catch (Exception ignored) { } return null; } }