后端(四面9分批次): 锁跳过留痕、状态词表收成单点、版本硬地板进 yml 并记账
- 14 处「拿不到锁就 continue」过去零日志,现统一带可聚合锚点并有留痕判据 (LockSkipWitnessTest 7 例 + LockSkipSilentExitGuardrailTest 4 例)。 - 任务状态词表:散落内联集合改由单一定义点判方向(TaskStatusVocabularyRatchetTest 7 例), CANCELED/CANCELLED 只做归一映射,没改库值也没改对外契约。 - 版本硬地板三键(min-supported / enforce / rejectUnreported)此前在任何 yml 里 0 处=出厂即惰性; 现在入册且 enforce=false 走记账模式(ClientVersionFloorConfigTest 9 例),真挡谁留给用户拍。 - 业务码→HTTP 状态只做映射单点 + 开关(默认关,开启前逐字节等价,BusinessErrorHttpStatusTest 8 例); 直接翻面会让三个前端把业务失败读成网络挂了。 - 验收:mvn -o test 这 5 个类 35 例 0 红(用 python subprocess 起 mvn——bash 里 cmd 包一层 开的是交互式 cmd,rc 是 cmd 的,会给出假的 rc=0)。
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package com.nanri.aiimage.common.api;
|
||||
|
||||
/**
|
||||
* 分页与列表条数默认值的<b>具名出处</b>(2026-10-09 评审「可读 5.0 / 交互 5.5」项 5:
|
||||
* {@code defaultValue} 里 15/20/50/1000 四种并存,31 处魔法数)。
|
||||
*
|
||||
* <p><b>这里没有"全局统一默认页容量"这一说,而且是故意的。</b>
|
||||
* 实测 49 处数字型 {@code defaultValue}(21 处页码 + 28 处条数)分属不同的真实用途:
|
||||
* 用户端列表、超管台、任务历史、扫描上限、导出取全量——把它们拍成一个值是<b>改行为</b>,
|
||||
* 不是清理。本类只做一件事:让每个数字有一个说明它<i>为什么是这个数</i>的名字,
|
||||
* 并让"同一个用途冒出第二个默认值"变成判据红({@code PageDefaultsLedgerTest})。
|
||||
*
|
||||
* <p>注解里的 {@code defaultValue} 必须是编译期字符串常量,所以常量声明成 {@link String};
|
||||
* 每个都配一个 {@code *_INT} 镜像,业务代码里要用数字时不必再 {@code Integer.parseInt}。
|
||||
*
|
||||
* <p>命名口径:{@code <用途>_PAGE_SIZE} 是"一页几条",{@code <用途>_LIMIT} 是"本次最多返回几条"
|
||||
* (不是分页,是扫描/返回截断)。两者不许混用——把 limit 当 pageSize 用会把上限调到用户可见的错位。
|
||||
*/
|
||||
public final class PageDefaults {
|
||||
|
||||
private PageDefaults() {
|
||||
}
|
||||
|
||||
// ---- 页码:21 处全是 1,这一族本来就是单一口径 ----
|
||||
|
||||
/** 起始页码。全树 21 处分页入口一致取 1(不是 0);改这个数等于把所有列表第一页翻空。 */
|
||||
public static final String FIRST_PAGE = "1";
|
||||
|
||||
/** {@link #FIRST_PAGE} 的数字镜像。 */
|
||||
public static final int FIRST_PAGE_INT = 1;
|
||||
|
||||
// ---- 每页条数:现存 4 个不同的真实默认 ----
|
||||
|
||||
/**
|
||||
* 用户端/超管列表页默认容量 = 15。现存 10 处(admin 用户、去重库、图片历史、
|
||||
* 无效 ASIN、ASIN 查询、店铺凭据、店铺管理、跳价 ASIN……)。
|
||||
*/
|
||||
public static final String USER_LIST_PAGE_SIZE = "15";
|
||||
|
||||
/** {@link #USER_LIST_PAGE_SIZE} 的数字镜像。 */
|
||||
public static final int USER_LIST_PAGE_SIZE_INT = 15;
|
||||
|
||||
/** 超管台列表默认容量 = 20。现存 6 处(设备日志、图视任务、通知×2、商品分类×2)。 */
|
||||
public static final String ADMIN_LIST_PAGE_SIZE = "20";
|
||||
|
||||
/** {@link #ADMIN_LIST_PAGE_SIZE} 的数字镜像。 */
|
||||
public static final int ADMIN_LIST_PAGE_SIZE_INT = 20;
|
||||
|
||||
/** 上架/采集类任务历史列表默认容量 = 50。现存 2 处 {@code page_size}(collect-data、publish)。 */
|
||||
public static final String TASK_LIST_PAGE_SIZE = "50";
|
||||
|
||||
/** {@link #TASK_LIST_PAGE_SIZE} 的数字镜像。 */
|
||||
public static final int TASK_LIST_PAGE_SIZE_INT = 50;
|
||||
|
||||
/**
|
||||
* 一次性取全量的"页容量"= 1000。<b>现存 2 处,都是用户端列表接口</b>:
|
||||
* {@code PriceTrackController}(价格追踪)与 {@code ShopMatchController}(店铺匹配)的
|
||||
* {@code page_size}。
|
||||
*
|
||||
* <p>这一条是评审点名的<b>疑似笔误</b>:用户端下拉的默认页容量给到 1000,表现更像"根本没分页"
|
||||
* 而不是"一页 1000 条"。单独一个常量、不复用 {@link #TASK_LIST_PAGE_SIZE},是为了让它
|
||||
* 在判据里数得出来(2 处);<b>本轮没有改它,也不自行改成 50</b>——改成多少、是不是保留
|
||||
* 客户端传参上限,需要产品/运维拍板。
|
||||
*/
|
||||
public static final String FULL_EXPORT_PAGE_SIZE = "1000";
|
||||
|
||||
/** {@link #FULL_EXPORT_PAGE_SIZE} 的数字镜像。 */
|
||||
public static final int FULL_EXPORT_PAGE_SIZE_INT = 1000;
|
||||
|
||||
// ---- 返回条数上限(不是分页)----
|
||||
|
||||
/** 单接口一次最多返回多少条 = 50。现存 4 处 {@code limit}(外观专利、采集数据、上架任务、相似 ASIN)。 */
|
||||
public static final String DEFAULT_RESULT_LIMIT = "50";
|
||||
|
||||
/** {@link #DEFAULT_RESULT_LIMIT} 的数字镜像。 */
|
||||
public static final int DEFAULT_RESULT_LIMIT_INT = 50;
|
||||
|
||||
/** 超管扫描类接口的单次上限 = 100。现存 3 处 {@code limit}(店铺数据采集列表、结果作业列表×2)。 */
|
||||
public static final String ADMIN_SCAN_LIMIT = "100";
|
||||
|
||||
/** {@link #ADMIN_SCAN_LIMIT} 的数字镜像。 */
|
||||
public static final int ADMIN_SCAN_LIMIT_INT = 100;
|
||||
}
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
package com.nanri.aiimage.common.exception;
|
||||
|
||||
import io.micrometer.core.instrument.Gauge;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 业务码 → 真 HTTP 状态码的<b>映射单点</b>(2026-10-09 评审「交互 5.5」项 4)。
|
||||
*
|
||||
* <p>现状实测:{@code GlobalExceptionHandler} 的 {@code BusinessException} 出口没有
|
||||
* {@code @ResponseStatus},于是 1,242 处业务失败全部以 <b>HTTP 200</b> 出。后果不是"不好看":
|
||||
* 业务失败在 HTTP 指标里彻底隐形(2026-09-18 那次滚动重启期间丢心跳就是这么被记成 200 的,
|
||||
* 见 {@code GlobalExceptionHandler} 里 503 那段注释),网关/监控/客户端拦截器都只能靠扒响应体猜。
|
||||
*
|
||||
* <p><b>但这一轮不翻面。</b>直接改状态码会让三个前端把"业务失败"当"网络挂了"处理——
|
||||
* 那是行为回归,不是修复。所以这里只做安全的一半:
|
||||
* <ol>
|
||||
* <li>映射表在这里,一处定完,判据钉死({@code BusinessErrorHttpStatusTest});</li>
|
||||
* <li>开关 {@code aiimage.api.business-error-http-status.enabled} <b>默认 false</b>;
|
||||
* 关闭时 {@link #render} 原样返回 {@code ApiResponse},序列化路径与今天逐字节一致;</li>
|
||||
* <li>"哪些 code 会变成非 200"是显式白名单:白名单外(含 {@code code == null})
|
||||
* <b>永远走 200</b>,所以翻开关不会把没预料到的码打成 4xx/5xx。</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p>开启动作要用户拍板:至少要先确认 {@code frontend-vue}、{@code admin-frontend-vue}
|
||||
* 与桌面端 {@code app_client} 三处拦截器都能吃非 200 + 同形响应体
|
||||
* (已实测 {@code admin-frontend-vue/src/api/envelope.ts} 对 401/403 同时读
|
||||
* {@code status}/{@code statusCode}/{@code code},这一族风险较低;其余两处本面无证据)。
|
||||
*
|
||||
* <p>白名单的取数口径来自实测码分布({@code src/main/java} 里 {@code BusinessException(code)} 的字面量统计):
|
||||
* 403×52、400×36、401×16、500×4、409×3、404×3、503×1,加 {@link BusinessCodes} 的 404xx/409xx 族、
|
||||
* {@code DeviceSessionPolicy.CODE_KICKED=4011}、{@code ClientVersionGuardFilter.CODE_TOO_OLD=4012}。
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class BusinessErrorHttpStatus {
|
||||
|
||||
/** 开关的配置键(写在 application.yml 里,默认 false)。 */
|
||||
public static final String ENABLED_KEY = "aiimage.api.business-error-http-status.enabled";
|
||||
|
||||
/** 记账指标:开关打开后每次真的把业务失败写成非 200 时 +1,按 code 打标签。 */
|
||||
public static final String METRIC = "aiimage.api.business.error.http_status";
|
||||
|
||||
/** 日志锚点:翻真之后现网靠这一条定位"哪个 code 在改状态码"。 */
|
||||
public static final String ANCHOR = "[business-http-status]";
|
||||
|
||||
/**
|
||||
* 映射白名单。业务码 → 真 HTTP 状态。<b>表外一律 200</b>(见 {@link #statusFor})。
|
||||
*
|
||||
* <p>3 位码是"码里已经写着 HTTP 语义"的那一族,照它的字面意思映射;
|
||||
* 4 位 401x 与 5 位 404xx/409xx 是项目自造的族,按 {@link BusinessCodes} 注释里的语义映射。
|
||||
*
|
||||
* <p>注意 {@link BusinessCodes#TASK_ALREADY_FINISHED}(40901) <b>不在表里</b>:
|
||||
* {@code GlobalExceptionHandler} 对它是幂等忽略、返回 {@code success=true},
|
||||
* 那是成功响应,不该被写成 409。
|
||||
*/
|
||||
private static final Map<Integer, HttpStatus> MAPPINGS = buildMappings();
|
||||
|
||||
private static Map<Integer, HttpStatus> buildMappings() {
|
||||
Map<Integer, HttpStatus> map = new LinkedHashMap<>();
|
||||
// —— 3 位族:码本身就是 HTTP 状态语义
|
||||
map.put(400, HttpStatus.BAD_REQUEST);
|
||||
map.put(401, HttpStatus.UNAUTHORIZED);
|
||||
map.put(403, HttpStatus.FORBIDDEN);
|
||||
map.put(404, HttpStatus.NOT_FOUND);
|
||||
map.put(409, HttpStatus.CONFLICT);
|
||||
map.put(422, HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
map.put(500, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
map.put(503, HttpStatus.SERVICE_UNAVAILABLE);
|
||||
// —— 4 位 401x 族:鉴权/凭据
|
||||
map.put(4011, HttpStatus.UNAUTHORIZED); // DeviceSessionPolicy.CODE_KICKED:被顶下线
|
||||
map.put(4012, HttpStatus.BAD_REQUEST); // ClientVersionGuardFilter.CODE_TOO_OLD:客户端版本过低
|
||||
// —— 5 位 404xx/409xx 族:BusinessCodes
|
||||
map.put(BusinessCodes.TASK_NOT_FOUND, HttpStatus.NOT_FOUND); // 40401
|
||||
map.put(BusinessCodes.TASK_BUSY, HttpStatus.CONFLICT); // 40902
|
||||
map.put(BusinessCodes.TASK_OWNER_FORWARD, HttpStatus.CONFLICT); // 40903
|
||||
return Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
/** 可为 null:没配 Micrometer 注册表时只留日志与映射判定。 */
|
||||
private static volatile MeterRegistry registry;
|
||||
private static final AtomicInteger RENDER_COUNT = new AtomicInteger();
|
||||
|
||||
@Value("${" + ENABLED_KEY + ":false}")
|
||||
private boolean enabled;
|
||||
|
||||
/** 关掉时静态侧也必须是 false——判据与生产共用同一个开关值,不许两套默认。 */
|
||||
private static volatile boolean enabledFlag;
|
||||
|
||||
public BusinessErrorHttpStatus() {
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public BusinessErrorHttpStatus(ObjectProvider<MeterRegistry> meterRegistryProvider,
|
||||
@Value("${" + ENABLED_KEY + ":false}") boolean enabled) {
|
||||
registry = meterRegistryProvider == null ? null : meterRegistryProvider.getIfAvailable();
|
||||
enabledFlag = enabled;
|
||||
log.info("{} 启动自检:{}={}({})映射白 {} 条,表外 code 恒走 200",
|
||||
ANCHOR, ENABLED_KEY, enabled,
|
||||
enabled ? "真改写 HTTP 状态" : "关闭:业务失败仍全部 HTTP 200,行为与改动前逐字节一致",
|
||||
MAPPINGS.size());
|
||||
if (enabled && registry != null) {
|
||||
Gauge.builder(METRIC + ".renders", RENDER_COUNT, AtomicInteger::get).register(registry);
|
||||
}
|
||||
}
|
||||
|
||||
/** 单测接线用:显式设置开关与注册表,不依赖容器。 */
|
||||
public static void bindForTests(boolean enabled, MeterRegistry meterRegistry) {
|
||||
enabledFlag = enabled;
|
||||
registry = meterRegistry;
|
||||
}
|
||||
|
||||
/** 当前是否启用了真状态码。 */
|
||||
public static boolean isEnabled() {
|
||||
return enabledFlag;
|
||||
}
|
||||
|
||||
/** 只改开关、不动映射(判据与回退用)。 */
|
||||
public void setEnabled(boolean value) {
|
||||
this.enabled = value;
|
||||
enabledFlag = value;
|
||||
}
|
||||
|
||||
public boolean isSwitchOn() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/** 映射表白名单的只读视图(判据③:"哪些 code 会被映射成非 200"就是这一份)。 */
|
||||
public static Map<Integer, HttpStatus> mappings() {
|
||||
return MAPPINGS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务码对应的 HTTP 状态。
|
||||
*
|
||||
* <p>三种落到 {@link HttpStatus#OK} 的情况,都是故意的:
|
||||
* {@code code == null}(历史上大量 {@code ApiResponse.fail(message)} 不带码)、
|
||||
* 表外码、成功响应。返回 OK 时 {@link #render} 不会构造 {@code ResponseEntity},
|
||||
* 也就是不会碰 HTTP 状态。
|
||||
*/
|
||||
public static HttpStatus statusFor(Integer code) {
|
||||
if (code == null) {
|
||||
return HttpStatus.OK;
|
||||
}
|
||||
return MAPPINGS.getOrDefault(code, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 出站点:开关关闭 → 原样返回 body(与改动前同一序列化成败路径);
|
||||
* 开关打开且 code 在白名单 → 包一层带状态码的 {@code ResponseEntity},响应体一个字节都不改。
|
||||
*/
|
||||
public static Object render(ApiResponse<?> body, Integer code) {
|
||||
if (!enabledFlag) {
|
||||
return body;
|
||||
}
|
||||
HttpStatus status = statusFor(code);
|
||||
if (status == HttpStatus.OK || body == null) {
|
||||
return body;
|
||||
}
|
||||
RENDER_COUNT.incrementAndGet();
|
||||
if (registry != null) {
|
||||
registry.counter(METRIC, "code", String.valueOf(code), "httpStatus",
|
||||
String.valueOf(status.value())).increment();
|
||||
}
|
||||
log.info("{} code={} -> HTTP {}(响应体不变,只改状态行)", ANCHOR, code, status.value());
|
||||
return ResponseEntity.status(status).body(body);
|
||||
}
|
||||
}
|
||||
+11
-6
@@ -78,8 +78,8 @@ public class GlobalExceptionHandler {
|
||||
}
|
||||
|
||||
@ExceptionHandler(BusinessException.class)
|
||||
public ApiResponse<Void> handleBusinessException(BusinessException ex, HttpServletRequest request,
|
||||
jakarta.servlet.http.HttpServletResponse response) {
|
||||
public Object handleBusinessException(BusinessException ex, HttpServletRequest request,
|
||||
jakarta.servlet.http.HttpServletResponse response) {
|
||||
// 停用/删除的成因走响应头而非新业务码:code 必须保持 401,改成新码会同时打断
|
||||
// 两面前端拦截器与桌面端 app_client/main.py 里按 'code': 401 识别鉴权失败的判定
|
||||
if (ex instanceof AccountDisabledException) {
|
||||
@@ -103,13 +103,18 @@ public class GlobalExceptionHandler {
|
||||
}
|
||||
if (Integer.valueOf(BusinessCodes.TASK_BUSY).equals(ex.getCode())) {
|
||||
// 锁竞争:必须如实返回失败 + 可重试码,否则 worker 会把「未落库」当成功而停止重试
|
||||
return ApiResponse.fail(BusinessCodes.TASK_BUSY,
|
||||
UserMessages.orFallback(ex.getMessage(), "这个任务正在处理中,请稍后重试"));
|
||||
return BusinessErrorHttpStatus.render(
|
||||
ApiResponse.fail(BusinessCodes.TASK_BUSY,
|
||||
UserMessages.orFallback(ex.getMessage(), "这个任务正在处理中,请稍后重试")),
|
||||
BusinessCodes.TASK_BUSY);
|
||||
}
|
||||
String userMessage = UserMessages.orFallback(ex.getMessage(), chineseFallbackFor(ex.getCode()));
|
||||
// 状态码出口只在 BusinessErrorHttpStatus 的开关为 true 时才改 HTTP 行;开关关时 render 原样
|
||||
// 返回同一个 ApiResponse 实例,序列化路径与 2026-10-09 之前逐字节一致(评审「交互 5.5」项 4,
|
||||
// 翻真的开启动作要用户拍:三个前端的拦截器先要能吃非 200 + 同形响应体)。
|
||||
return ex.getCode() == null
|
||||
? ApiResponse.fail(userMessage)
|
||||
: ApiResponse.fail(ex.getCode(), userMessage);
|
||||
? BusinessErrorHttpStatus.render(ApiResponse.fail(userMessage), null)
|
||||
: BusinessErrorHttpStatus.render(ApiResponse.fail(ex.getCode(), userMessage), ex.getCode());
|
||||
}
|
||||
|
||||
@ExceptionHandler(NoResourceFoundException.class)
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
package com.nanri.aiimage.common.task;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 任务状态词表的<b>唯一定义点</b>(2026-10-09 评审「流程 6.0」项 2:状态字面量集合散落 33 处/17 文件、没有单一状态机)。
|
||||
*
|
||||
* <p>先普查再说收口。2026-10-10 自己数出来的实际词表是 <b>4 套自有 + 1 套外部 + 若干模块内小状态机</b>,
|
||||
* 不是一个"全局状态机"能覆盖的东西,所以这里按<b>表</b>分组,每组各留自己的口径:
|
||||
* <ol>
|
||||
* <li>{@link FileTask}:{@code biz_file_task.status},大写。12 个客户端模块共用这一张表;</li>
|
||||
* <li>{@link BrandTask}:{@code brand_crawl_tasks.status},<b>小写</b>(该表历史写法就是小写);</li>
|
||||
* <li>{@link Job}:{@code task_file_job.status},结果作业自己的四态;</li>
|
||||
* <li>{@link LoopRun}:{@code price_track_loop_run.status},比上面三套多一个 {@code STOPPED};</li>
|
||||
* <li>外部词表(Coze 工作流 {@code execute_status} 等,见
|
||||
* {@code ImageVideoAsyncTaskService}):<b>不在这里定义</b>——那是别人家的返回值,
|
||||
* 收进来等于假装我们能改上游。</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p><b>三条不动的边界</b>(这是本类存在的约束,不是待办):
|
||||
* <ul>
|
||||
* <li>不改库里已存的值:{@code COMPLETED}、{@code CANCELED}、小写 {@code cancelled} 都还在库里躺着;</li>
|
||||
* <li>不改对外 API 的字符串契约:各模块接口原样回显 {@code FileTaskEntity#getStatus()},
|
||||
* 老行返回 {@code CANCELED} 就继续返回 {@code CANCELED};</li>
|
||||
* <li>不发明第三个词表:任务终态只有 {@code SUCCESS|COMPLETED|FAILED} 这一套口径,
|
||||
* 其中 {@code COMPLETED ≡ SUCCESS}(2026-10-04 状态三态收敛已定,见
|
||||
* {@code TaskCenterQueryMapper#SUCCESS_STATUSES_ORDERED}),别再往上添 {@code DONE}/{@code FINISHED}。</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>判据在 {@code TaskStatusVocabularyRatchetTest}:新增内联状态集合字面量、新增写死的状态常量声明、
|
||||
* 词表成员被改动都会红;现存例外按文件台账化。
|
||||
*/
|
||||
public final class TaskStatuses {
|
||||
|
||||
private TaskStatuses() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 词表 1:{@code biz_file_task.status}(大写)。12 个客户端模块的公共状态面。
|
||||
*
|
||||
* <p>{@code ERROR} 与 {@code COMPLETED} 是历史值:{@code COMPLETED} 并入"成功"口径展示,
|
||||
* {@code ERROR} 并入"失败"口径展示({@code TaskCenterQueryMapper} 的展开口径),
|
||||
* 两者都不能从读侧集合里删——删了老行就在任务中心里凭空消失。
|
||||
*/
|
||||
public static final class FileTask {
|
||||
public static final String PENDING = "PENDING";
|
||||
public static final String RUNNING = "RUNNING";
|
||||
public static final String SCHEDULED = "SCHEDULED";
|
||||
public static final String SUCCESS = "SUCCESS";
|
||||
/** {@code SUCCESS} 的历史拼写;展示上已并入成功,读侧必须继续认。 */
|
||||
public static final String COMPLETED = "COMPLETED";
|
||||
public static final String FAILED = "FAILED";
|
||||
/** 失败口径的历史第二拼写(并入"失败"筛选项)。 */
|
||||
public static final String ERROR = "ERROR";
|
||||
public static final String CANCELLED = "CANCELLED";
|
||||
/**
|
||||
* {@code CANCELLED} 的历史脏值拼写。<b>当前 Java 代码从不写它</b>
|
||||
* (实测:全树没有一处把 {@code CANCELED} 写进库),它只可能来自早期 jar/Python 侧留下的行,
|
||||
* 所以只在读侧接受集合里出现,并由 SQL 的 {@code CASE WHEN} 归一后对外输出。
|
||||
*/
|
||||
public static final String CANCELED = "CANCELED";
|
||||
|
||||
/** 在跑口径(任务中心「执行中」筛选项与"卡住"判定的同一集合)。 */
|
||||
public static final Set<String> ACTIVE = Set.of(PENDING, RUNNING, SCHEDULED);
|
||||
/** {@link #ACTIVE} 的固定顺序版:展开成 SQL {@code IN} 列表时文本要可断言。 */
|
||||
public static final List<String> ACTIVE_ORDERED = List.of(PENDING, RUNNING, SCHEDULED);
|
||||
|
||||
/** 终态集合(历史脏拼写 {@link #CANCELED} 也在内,少一个就有一行永远收不了尾)。 */
|
||||
public static final Set<String> TERMINAL = Set.of(SUCCESS, FAILED, CANCELLED, CANCELED);
|
||||
|
||||
/** 「跑完了」的可数口径(各模块历史页 success/failed 计数用;不含 {@code CANCELED},是原口径,别顺手加宽)。 */
|
||||
public static final List<String> FINISHED_ORDERED = List.of(SUCCESS, FAILED);
|
||||
|
||||
/** 前端「成功」筛选项的展开口径:{@code COMPLETED ≡ SUCCESS}。 */
|
||||
public static final List<String> SUCCESS_VIEW_ORDERED = List.of(SUCCESS, COMPLETED);
|
||||
|
||||
/** 前端「失败」筛选项的展开口径:{@code ERROR} 与取消都按「没成功」并入失败。 */
|
||||
public static final List<String> FAILED_VIEW_ORDERED = List.of(FAILED, ERROR, CANCELLED);
|
||||
|
||||
private FileTask() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 词表 2:{@code brand_crawl_tasks.status}(小写)。这张表从建表起状态就是小写,
|
||||
* 与 {@link FileTask} 不是一个字符集,混用会让 brand 任务在 UNION 口径里整批消失。
|
||||
*/
|
||||
public static final class BrandTask {
|
||||
public static final String PENDING = "pending";
|
||||
public static final String RUNNING = "running";
|
||||
public static final String SUCCESS = "success";
|
||||
public static final String FAILED = "failed";
|
||||
/** brand 侧唯一的取消拼写就是这个小写;{@code canceled} 全树没有第二处写点。 */
|
||||
public static final String CANCELLED = "cancelled";
|
||||
|
||||
public static final Set<String> ACTIVE = Set.of(PENDING, RUNNING);
|
||||
public static final List<String> ACTIVE_ORDERED = List.of(PENDING, RUNNING);
|
||||
public static final Set<String> TERMINAL = Set.of(SUCCESS, FAILED, CANCELLED);
|
||||
public static final List<String> TERMINAL_ORDERED = List.of(CANCELLED, FAILED, SUCCESS);
|
||||
|
||||
private BrandTask() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 词表 3:{@code task_file_job.status}——结果作业四态,比任务少一个取消态。 */
|
||||
public static final class Job {
|
||||
public static final String PENDING = "PENDING";
|
||||
public static final String RUNNING = "RUNNING";
|
||||
public static final String SUCCESS = "SUCCESS";
|
||||
public static final String FAILED = "FAILED";
|
||||
|
||||
/** 在跑口径(作业还在等结果)。 */
|
||||
public static final List<String> ACTIVE_ORDERED = List.of(PENDING, RUNNING);
|
||||
/** 可重跑口径:待办 + 失败但没打满重试次数。全树有 6 处,都是这一对。 */
|
||||
public static final List<String> RETRYABLE_ORDERED = List.of(PENDING, FAILED);
|
||||
|
||||
private Job() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 词表 4:{@code price_track_loop_run.status}——轮次运行态,比 {@link FileTask} 多一个 {@code STOPPED}。 */
|
||||
public static final class LoopRun {
|
||||
public static final String RUNNING = "RUNNING";
|
||||
public static final String SUCCESS = "SUCCESS";
|
||||
public static final String FAILED = "FAILED";
|
||||
public static final String STOPPED = "STOPPED";
|
||||
|
||||
/** 轮次终态(巡检按这一组判"这一轮不会再自己动了")。 */
|
||||
public static final Set<String> TERMINAL = Set.of(SUCCESS, FAILED, STOPPED);
|
||||
|
||||
private LoopRun() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消拼写的归一映射——<b>只用来判断,不用来改写值</b>:不改库、不改对外字符串。
|
||||
* 键是"读到的原始值",值是"归一后的规范拼写"。
|
||||
*
|
||||
* <p>为什么只做取消这一对:实测全树只有 {@code CANCELED}/{@code CANCELLED} 存在同义双拼,
|
||||
* 其余(SUCCESS/COMPLETED、ERROR/FAILED)是<b>并入展示口径</b>而不是拼写错误,
|
||||
* 混进同一张归一表会把"历史值"洗成"错别字",后面就没人敢信库值了。
|
||||
*/
|
||||
public static final Map<String, String> CANCEL_SPELLINGS = Map.of(
|
||||
"CANCELED", FileTask.CANCELLED,
|
||||
"CANCELLED", FileTask.CANCELLED,
|
||||
"canceled", BrandTask.CANCELLED,
|
||||
"cancelled", BrandTask.CANCELLED);
|
||||
|
||||
/** 是不是"取消"这一族(两种拼写、大小写都认);用于判定,不用于改写。 */
|
||||
public static boolean isCancelSpelling(String status) {
|
||||
return status != null && CANCEL_SPELLINGS.containsKey(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一到规范拼写:两种取消拼写各归各家(大写值归 {@code CANCELLED}、小写值归 {@code cancelled}),
|
||||
* <b>其它状态原样返回</b>。
|
||||
*
|
||||
* <p>刻意不做大小写统一:{@link FileTask} 是大写表、{@link BrandTask} 是小写表,
|
||||
* 一刀切 upper/lower 会 cross 到对方词表里去。
|
||||
*/
|
||||
public static String canonicalizeCancel(String status) {
|
||||
String mapped = status == null ? null : CANCEL_SPELLINGS.get(status);
|
||||
return mapped == null ? status : mapped;
|
||||
}
|
||||
|
||||
/**
|
||||
* 大写词表的全部<b>去重后</b>取值(判据用它核对"没有第五套")。
|
||||
*
|
||||
* <p>注意这里必须是去重集合:{@code Job.PENDING} 与 {@code FileTask.PENDING} 是同一个字符串,
|
||||
* 直接 {@code Set.of(全部常量)} 会在类初始化时抛 {@code duplicate element}——
|
||||
* 这条判据 2026-10-10 就是这么被抓红的,留着当例子。
|
||||
*/
|
||||
public static Set<String> allUppercaseStatuses() {
|
||||
return Set.copyOf(java.util.Arrays.asList(
|
||||
FileTask.PENDING, FileTask.RUNNING, FileTask.SCHEDULED, FileTask.SUCCESS,
|
||||
FileTask.COMPLETED, FileTask.FAILED, FileTask.ERROR, FileTask.CANCELLED,
|
||||
FileTask.CANCELED, LoopRun.STOPPED));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package com.nanri.aiimage.common.util;
|
||||
|
||||
import io.micrometer.core.instrument.Gauge;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* 分布式锁「没拿到就跳过」的可聚合出口(2026-10-09 评审「稳定 5.5」项)。
|
||||
*
|
||||
* <p>此前 {@code if (lockHandle == null) { continue; }} 在全树有 <b>27</b> 处(12 个文件),
|
||||
* 一处日志都不留。表现是:巡检任务每轮都跑、锁竞争越激烈被跳过的任务越多,而现网看不出任何痕迹
|
||||
* ——卡死任务没被收尾、结果作业没被续跑,日志里连一行都没有,只能靠人肉反推。跟
|
||||
* {@code TaskFileJobPublisher} 的 MQ 降级是同一个病:那条已经补了 {@code task.file.job.mq.degraded}
|
||||
* 计数出口,这批锁跳过出口是它的同类。
|
||||
*
|
||||
* <p>所以这里定的不是"把级别调大",而是<b>可聚合</b>:
|
||||
* <ul>
|
||||
* <li>锚点 {@value #ANCHOR}:一条 grep 得动的字面量,{@code point=}/{@code outcome=} 给聚合维度;</li>
|
||||
* <li>进程内台账 {@link #countOf}:按 point 累计,供判据与巡检直接读;</li>
|
||||
* <li>Micrometer 指标 {@value #METRIC}(可选,注册表缺席时只留日志与本地台账,判定一字不动,
|
||||
* 与 {@code TaskFileJobPublisher} 同一口径)。</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>{@code point} 是<b>稳定字面量</b>(形如 {@code brand:stale-running-scan}),不锚行号:
|
||||
* 方法搬家、加几行注释都不该让一条已经在响的告警变成孤儿。新增调用点请同步
|
||||
* {@code LockSkipWitnessTest} 里的点位台账。
|
||||
*
|
||||
* <p>静态 API 是有意的:这 12 个 Service 清一色 {@code @RequiredArgsConstructor},
|
||||
* 塞一个实例字段等于改 12 个构造器签名、打断几十支 {@code new XxxService(...)} 的既有判据。
|
||||
* 注册表由 Spring 在启动时绑一次({@link #LockSkipWitness});没起 Spring 的单测照样能调
|
||||
* {@link #record},台账与日志都不依赖容器。
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class LockSkipWitness {
|
||||
|
||||
/** 巡检/判据用的日志锚点。改这条字面量等于把现网告警规则删掉,动之前先对巡检。 */
|
||||
public static final String ANCHOR = "[lock-skip]";
|
||||
|
||||
/** 指标名:tag {@code point}/{@code outcome}/{@code moduleType}。 */
|
||||
public static final String METRIC = "aiimage.distributed.lock.skip";
|
||||
|
||||
/** outcome:循环里跳过这一项,后面还有别的(巡检批量扫描)。 */
|
||||
public static final String OUTCOME_SKIPPED = "skipped";
|
||||
|
||||
/** outcome:整次调用直接返回,本轮什么都没用做(含 try-with-resources 里锁没拿到)。 */
|
||||
public static final String OUTCOME_ABANDONED = "abandoned";
|
||||
|
||||
/** outcome:调用方没给结果类型——单独成桶,不折叠进上面两个真桶。 */
|
||||
public static final String OUTCOME_UNKNOWN = "unknown";
|
||||
|
||||
/** 台账键上限:point 是有限集合(调用点数),超上限后不再新增键,防无界增长。 */
|
||||
static final int LEDGER_KEYS_MAX = 256;
|
||||
|
||||
private static final ConcurrentMap<String, AtomicLong> LEDGER = new ConcurrentHashMap<>();
|
||||
private static final AtomicLong TOTAL = new AtomicLong();
|
||||
|
||||
/** 可为 null:没配 Micrometer 注册表时只留日志 + 本地台账。 */
|
||||
private static volatile MeterRegistry registry;
|
||||
|
||||
public LockSkipWitness() {
|
||||
}
|
||||
|
||||
/** 生产接线:注册表可选,缺席时不影响跳过语义与日志。 */
|
||||
@Autowired
|
||||
public LockSkipWitness(ObjectProvider<MeterRegistry> meterRegistryProvider) {
|
||||
bind(meterRegistryProvider == null ? null : meterRegistryProvider.getIfAvailable());
|
||||
}
|
||||
|
||||
/** 供 Spring 构造与单测显式接线;null 表示只用日志与本地台账。 */
|
||||
public static void bind(MeterRegistry meterRegistry) {
|
||||
registry = meterRegistry;
|
||||
if (meterRegistry != null) {
|
||||
// 计数器按 point 现建现取,注册一次总览 gauge,便于「一个 point 都没命中」也能看到 0。
|
||||
Gauge.builder(METRIC + ".total", TOTAL, AtomicLong::get).register(meterRegistry);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 记一次「没拿到锁所以跳过/放弃」。
|
||||
*
|
||||
* @param point 稳定点位字面量(不要用行号/方法名+行号拼)
|
||||
* @param outcome {@link #OUTCOME_SKIPPED} 或 {@link #OUTCOME_ABANDONED}
|
||||
* @param moduleType 业务模块类型,可为 null(归一为 unknown)
|
||||
* @param taskId 任务 id,可为 null
|
||||
*/
|
||||
public static void record(String point, String outcome, String moduleType, Long taskId) {
|
||||
String key = point == null || point.isBlank() ? "unpointed" : point.trim();
|
||||
// outcome 缺失归一到 unknown 而不是猜一个真桶:折叠进 skipped/abandoned 会让聚合面说谎。
|
||||
String normalizedOutcome = outcome == null || outcome.isBlank() ? OUTCOME_UNKNOWN : outcome.trim();
|
||||
String normalizedModule = moduleType == null || moduleType.isBlank() ? "unknown" : moduleType.trim();
|
||||
long count = ledgerOf(key).incrementAndGet();
|
||||
long total = TOTAL.incrementAndGet();
|
||||
MeterRegistry current = registry;
|
||||
if (current != null) {
|
||||
current.counter(METRIC,
|
||||
"point", key,
|
||||
"outcome", normalizedOutcome,
|
||||
"moduleType", normalizedModule)
|
||||
.increment();
|
||||
}
|
||||
log.warn("{} point={} outcome={} moduleType={} taskId={} skippedSoFar={} total={} —— "
|
||||
+ "未拿到分布式锁,本轮跳过(锁被其它实例持有或锁名不可用)",
|
||||
ANCHOR, key, normalizedOutcome, normalizedModule, taskId, count, total);
|
||||
}
|
||||
|
||||
/** 最省事的写法:跳过(skipped)结果 + 不带模块上下文。 */
|
||||
public static void recordSkip(String point, String moduleType, Long taskId) {
|
||||
record(point, OUTCOME_SKIPPED, moduleType, taskId);
|
||||
}
|
||||
|
||||
/** 最省事的写法:整次放弃(abandoned)结果 + 不带模块上下文。 */
|
||||
public static void recordAbandoned(String point, String moduleType, Long taskId) {
|
||||
record(point, OUTCOME_ABANDONED, moduleType, taskId);
|
||||
}
|
||||
|
||||
/** 定时任务级作业锁没抢到:整轮直接返回,没有模块/任务上下文。 */
|
||||
public static void skipped(String point) {
|
||||
record(point, OUTCOME_SKIPPED, null, null);
|
||||
}
|
||||
|
||||
/** 定时任务级作业锁没抢到且方法直接返回:本轮什么都没做。 */
|
||||
public static void abandoned(String point) {
|
||||
record(point, OUTCOME_ABANDONED, null, null);
|
||||
}
|
||||
|
||||
private static AtomicLong ledgerOf(String key) {
|
||||
AtomicLong existing = LEDGER.get(key);
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
if (LEDGER.size() >= LEDGER_KEYS_MAX) {
|
||||
// 超出上限:仍计入总量与日志,只是不再为未知点位开新键。
|
||||
return LEDGER.computeIfAbsent("overflow", k -> new AtomicLong());
|
||||
}
|
||||
return LEDGER.computeIfAbsent(key, k -> new AtomicLong());
|
||||
}
|
||||
|
||||
/** 某个点位累计跳过次数;没记过就是 0。 */
|
||||
public static long countOf(String point) {
|
||||
AtomicLong value = LEDGER.get(point);
|
||||
return value == null ? 0L : value.get();
|
||||
}
|
||||
|
||||
/** 全部点位的累计台账快照(不可变副本,按点位名排序)。 */
|
||||
public static Map<String, Long> snapshot() {
|
||||
Map<String, Long> out = new LinkedHashMap<>();
|
||||
LEDGER.entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.forEach(e -> out.put(e.getKey(), e.getValue().get()));
|
||||
return Collections.unmodifiableMap(out);
|
||||
}
|
||||
|
||||
/** 全部点位合计。 */
|
||||
public static long total() {
|
||||
return TOTAL.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试专用:清空台账,返回清理前的快照。
|
||||
*
|
||||
* <p>生产代码不要调——它会把巡检窗口里的计数抹平,看起来像"这段时间没人被锁挡"。
|
||||
* 之所以留着:判据要能钉住"走到这个分支留下了可查记录",而点位是全局静态计数,
|
||||
* 不清就测不出单次增量(用 delta 也能测,但 27 个点位共用一张表,清一次比 27 处读基线更好读)。
|
||||
*/
|
||||
public static Map<String, Long> resetLedgerForTests() {
|
||||
Map<String, Long> before = snapshot();
|
||||
LEDGER.clear();
|
||||
TOTAL.set(0L);
|
||||
return before;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import io.micrometer.core.instrument.Counter;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@@ -116,6 +117,33 @@ public class ClientVersionGuardFilter extends OncePerRequestFilter {
|
||||
return minSupportedVersion != null && !minSupportedVersion.trim().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动自述:把"地板到底在不在跑"打成一条看得见的日志。
|
||||
*
|
||||
* <p>此前这个类只有代码里的 {@code @Value} 默认值、任何 yml 里都没有这三键,于是"没配置"
|
||||
* 和"配置成惰性"都长得跟"这个功能不存在"一样——评审数出来就是"版本硬地板出厂即惰性"。
|
||||
* 三键现在写进 {@code application.yml} 了,这条自述补上另一半:万一被覆盖回空值
|
||||
* (或被紧急回退清空),启动日志里点名说清楚闸门没在跑,而不是安静地跳过每个请求。
|
||||
*/
|
||||
@PostConstruct
|
||||
void reportFloorState() {
|
||||
if (!isConfigured()) {
|
||||
log.warn("[版本地板] 启动自检:min-supported-version 未配置 ⇒ 闸门惰性,逐请求跳过,"
|
||||
+ "现网装机版本分布没有任何记账数据(enforce={} rejectUnreported={})",
|
||||
enforce, rejectUnreported);
|
||||
return;
|
||||
}
|
||||
if (parse(minSupportedVersion) == null) {
|
||||
log.warn("[版本地板] 启动自检:min-supported-version=\"{}\" 解析不出数字段 ⇒ 全部上报按 "
|
||||
+ "unparsable 记账、永不拒绝,请把配置改回点分数字版本", minSupportedVersion);
|
||||
return;
|
||||
}
|
||||
log.info("[版本地板] 启动自检:最低支持版本={} enforce={}({})rejectUnreported={}",
|
||||
minSupportedVersion.trim(), enforce,
|
||||
enforce ? "真拒绝:低于地板的装机会被挡在业务之前" : "记账模式:只计数与打日志,业务响应不变",
|
||||
rejectUnreported);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldNotFilter(HttpServletRequest request) {
|
||||
return !isConfigured() || !isClientFacing(request.getRequestURI());
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.admin.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.modules.admin.model.dto.AdminUserCreateRequest;
|
||||
import com.nanri.aiimage.modules.admin.model.dto.AdminUserUpdateRequest;
|
||||
import com.nanri.aiimage.modules.admin.model.vo.AdminUserListVo;
|
||||
@@ -33,8 +34,8 @@ public class AdminUserController {
|
||||
@GetMapping("/users")
|
||||
@Operation(summary = "分页查询用户列表")
|
||||
public ApiResponse<AdminUserListVo> listUsers(HttpServletRequest request,
|
||||
@RequestParam(required = false, defaultValue = "1") Integer page,
|
||||
@RequestParam(name = "page_size", required = false, defaultValue = "15") Integer pageSize,
|
||||
@RequestParam(required = false, defaultValue = PageDefaults.FIRST_PAGE) Integer page,
|
||||
@RequestParam(name = "page_size", required = false, defaultValue = PageDefaults.USER_LIST_PAGE_SIZE) Integer pageSize,
|
||||
@RequestParam(required = false) String username,
|
||||
@RequestParam(name = "search", required = false) String search,
|
||||
@RequestParam(name = "created_by_id", required = false) Long createdById,
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.appearancepatent.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.dto.AppearancePatentParseRequest;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.dto.AppearancePatentSubmitResultRequest;
|
||||
@@ -72,7 +73,7 @@ public class AppearancePatentController {
|
||||
@Parameter(description = "当前用户 ID,用于查询该用户自己的历史记录。", required = true, example = "1")
|
||||
@RequestParam("user_id") Long userId,
|
||||
@Parameter(description = "历史记录条数,默认 50,最大 100", example = "50")
|
||||
@RequestParam(value = "limit", required = false, defaultValue = "50") Integer limit,
|
||||
@RequestParam(value = "limit", required = false, defaultValue = PageDefaults.DEFAULT_RESULT_LIMIT) Integer limit,
|
||||
HttpServletRequest httpRequest) {
|
||||
userId = adminAuthSupport.resolveOwnershipUserId(httpRequest, userId);
|
||||
// 上限钳制(2026-09):文档写"最大 100"但此前无实际校验
|
||||
|
||||
+6
@@ -12,6 +12,7 @@ import com.nanri.aiimage.modules.appearancepatent.service.support.AppearancePate
|
||||
import com.nanri.aiimage.common.exception.TaskOwnerMismatchException;
|
||||
import com.nanri.aiimage.common.service.DistributedJobLockService;
|
||||
import com.nanri.aiimage.common.util.GroupResultPropagator;
|
||||
import com.nanri.aiimage.common.util.LockSkipWitness;
|
||||
import com.nanri.aiimage.common.util.FailedStatusRowFilter;
|
||||
import com.nanri.aiimage.common.util.StaleTaskDeathReason;
|
||||
import com.nanri.aiimage.config.AppearancePatentProperties;
|
||||
@@ -651,6 +652,7 @@ public class AppearancePatentTaskService {
|
||||
TaskDistributedLockService.LockHandle lockHandle = acquireTaskLock(task.getId(), 0L);
|
||||
if (lockHandle == null) {
|
||||
// 锁被 owner 实例/文件任务 worker 占用说明其仍活跃,静默跳过等下一轮
|
||||
LockSkipWitness.recordSkip("appearance-patent:running-stale-scan", MODULE_TYPE, task.getId());
|
||||
continue;
|
||||
}
|
||||
try (lockHandle) {
|
||||
@@ -666,6 +668,7 @@ public class AppearancePatentTaskService {
|
||||
}
|
||||
TaskDistributedLockService.LockHandle lockHandle = acquireTaskLock(taskId, 0L);
|
||||
if (lockHandle == null) {
|
||||
LockSkipWitness.recordAbandoned("appearance-patent:debug-finalize-stale", MODULE_TYPE, taskId);
|
||||
return;
|
||||
}
|
||||
try (lockHandle) {
|
||||
@@ -794,6 +797,8 @@ public class AppearancePatentTaskService {
|
||||
}
|
||||
TaskDistributedLockService.LockHandle neverReportedLock = acquireTaskLock(task.getId(), 0L);
|
||||
if (neverReportedLock == null) {
|
||||
LockSkipWitness.recordSkip("appearance-patent:never-reported-stale-scan",
|
||||
MODULE_TYPE, task.getId());
|
||||
continue;
|
||||
}
|
||||
try (neverReportedLock) {
|
||||
@@ -817,6 +822,7 @@ public class AppearancePatentTaskService {
|
||||
}
|
||||
TaskDistributedLockService.LockHandle lockHandle = acquireTaskLock(task.getId(), 0L);
|
||||
if (lockHandle == null) {
|
||||
LockSkipWitness.recordSkip("appearance-patent:no-result-shard-stale-scan", MODULE_TYPE, task.getId());
|
||||
continue;
|
||||
}
|
||||
try (lockHandle) {
|
||||
|
||||
+7
-3
@@ -19,9 +19,13 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class BrandTaskExpiredStopSpiImpl implements ExpiredAccountTaskStopSpi {
|
||||
|
||||
private static final String STATUS_PENDING = "pending";
|
||||
private static final String STATUS_RUNNING = "running";
|
||||
private static final String STATUS_CANCELLED = "cancelled";
|
||||
// 词表唯一出处:TaskStatuses.BrandTask(brand_crawl_tasks 状态是小写)。
|
||||
private static final String STATUS_PENDING =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.BrandTask.PENDING;
|
||||
private static final String STATUS_RUNNING =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.BrandTask.RUNNING;
|
||||
private static final String STATUS_CANCELLED =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.BrandTask.CANCELLED;
|
||||
|
||||
private final BrandCrawlTaskMapper brandCrawlTaskMapper;
|
||||
|
||||
|
||||
+15
-5
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.brand.service;
|
||||
|
||||
import com.nanri.aiimage.common.util.UserMessages;
|
||||
import com.nanri.aiimage.common.util.LockSkipWitness;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -101,11 +102,18 @@ public class BrandTaskService {
|
||||
return BLOCKED_SOURCE_HOSTS.contains(normalized) || normalized.endsWith(".localhost");
|
||||
}
|
||||
private static final long RESULT_SUBMIT_WAIT_MILLIS = 5 * 60 * 1000L;
|
||||
private static final String STATUS_PENDING = "pending";
|
||||
private static final String STATUS_RUNNING = "running";
|
||||
private static final String STATUS_SUCCESS = "success";
|
||||
private static final String STATUS_FAILED = "failed";
|
||||
private static final String STATUS_CANCELLED = "cancelled";
|
||||
// 状态词表唯一出处见 com.nanri.aiimage.common.task.TaskStatuses.BrandTask(brand_crawl_tasks 是小写表)。
|
||||
// 这里只留别名,不再抄字面量:这张表的值一旦和任务中心 UNION 的口径漂了,brand 任务会整批静默消失。
|
||||
private static final String STATUS_PENDING =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.BrandTask.PENDING;
|
||||
private static final String STATUS_RUNNING =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.BrandTask.RUNNING;
|
||||
private static final String STATUS_SUCCESS =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.BrandTask.SUCCESS;
|
||||
private static final String STATUS_FAILED =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.BrandTask.FAILED;
|
||||
private static final String STATUS_CANCELLED =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.BrandTask.CANCELLED;
|
||||
private static final String MODULE_TYPE = "BRAND";
|
||||
/** 结果文件并发上传数:OSS/MinIO 上传互不依赖,3 并发平衡收益与内存占用。 */
|
||||
private static final int RESULT_UPLOAD_CONCURRENCY = 3;
|
||||
@@ -1537,6 +1545,7 @@ public class BrandTaskService {
|
||||
for (BrandCrawlTaskEntity task : runningTasks) {
|
||||
TaskDistributedLockService.LockHandle taskLockHandle = acquireTaskLock(task.getId(), 0L);
|
||||
if (taskLockHandle == null) {
|
||||
LockSkipWitness.recordSkip("brand:stale-running-scan", MODULE_TYPE, task.getId());
|
||||
continue;
|
||||
}
|
||||
try (taskLockHandle) {
|
||||
@@ -1597,6 +1606,7 @@ public class BrandTaskService {
|
||||
for (BrandCrawlTaskEntity task : runningTasks) {
|
||||
TaskDistributedLockService.LockHandle taskLockHandle = acquireTaskLock(task.getId(), 0L);
|
||||
if (taskLockHandle == null) {
|
||||
LockSkipWitness.recordSkip("brand:long-running-scan", MODULE_TYPE, task.getId());
|
||||
continue;
|
||||
}
|
||||
try (taskLockHandle) {
|
||||
|
||||
+7
-3
@@ -18,9 +18,13 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class BrandTaskStaleRepairSpiImpl implements BrandTaskStaleRepairSpi {
|
||||
|
||||
private static final String STATUS_PENDING = "pending";
|
||||
private static final String STATUS_RUNNING = "running";
|
||||
private static final String STATUS_FAILED = "failed";
|
||||
// 词表唯一出处:TaskStatuses.BrandTask(brand_crawl_tasks 状态是小写)。
|
||||
private static final String STATUS_PENDING =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.BrandTask.PENDING;
|
||||
private static final String STATUS_RUNNING =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.BrandTask.RUNNING;
|
||||
private static final String STATUS_FAILED =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.BrandTask.FAILED;
|
||||
|
||||
private final BrandCrawlTaskMapper brandCrawlTaskMapper;
|
||||
|
||||
|
||||
+4
-3
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.collectdata.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.collectdata.model.dto.CollectDataCountryPreferenceSaveRequest;
|
||||
import com.nanri.aiimage.modules.collectdata.model.dto.CollectDataParseRequest;
|
||||
@@ -88,9 +89,9 @@ public class CollectDataController {
|
||||
@Parameter(description = "用户 ID,可选;传入时会校验任务归属")
|
||||
@RequestParam(value = "user_id", required = false) Long userId,
|
||||
@Parameter(description = "页码,从 1 开始", example = "1")
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
|
||||
@RequestParam(value = "page", required = false, defaultValue = PageDefaults.FIRST_PAGE) Integer page,
|
||||
@Parameter(description = "每页条数,默认 50,最大 200", example = "50")
|
||||
@RequestParam(value = "page_size", required = false, defaultValue = "50") Integer pageSize,
|
||||
@RequestParam(value = "page_size", required = false, defaultValue = PageDefaults.TASK_LIST_PAGE_SIZE) Integer pageSize,
|
||||
HttpServletRequest httpRequest) {
|
||||
userId = adminAuthSupport.resolveOwnershipUserId(httpRequest, userId);
|
||||
return ApiResponse.success(service.getItemsPage(taskId, userId, page, pageSize));
|
||||
@@ -121,7 +122,7 @@ public class CollectDataController {
|
||||
@Parameter(description = "当前用户 ID", required = true, example = "1")
|
||||
@RequestParam("user_id") Long userId,
|
||||
@Parameter(description = "返回数量上限,默认 50,最大 100", example = "50")
|
||||
@RequestParam(value = "limit", required = false, defaultValue = "50") Integer limit,
|
||||
@RequestParam(value = "limit", required = false, defaultValue = PageDefaults.DEFAULT_RESULT_LIMIT) Integer limit,
|
||||
HttpServletRequest httpRequest) {
|
||||
userId = adminAuthSupport.resolveOwnershipUserId(httpRequest, userId);
|
||||
return ApiResponse.success(service.history(userId, limit));
|
||||
|
||||
+3
@@ -12,6 +12,7 @@ import com.nanri.aiimage.common.exception.BusinessCodes;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.util.ExcelStreamReader;
|
||||
import com.nanri.aiimage.common.util.LockSkipWitness;
|
||||
import com.nanri.aiimage.modules.asincache.service.AsinResultCacheService;
|
||||
import com.nanri.aiimage.modules.collectdata.mapper.CollectDataCountryPrefMapper;
|
||||
import com.nanri.aiimage.modules.collectdata.mapper.CollectDataItemMapper;
|
||||
@@ -568,6 +569,7 @@ public class CollectDataService {
|
||||
try (TaskDistributedLockService.LockHandle lock =
|
||||
taskDistributedLockService.acquire(MODULE_TYPE, taskId, 0L)) {
|
||||
if (lock == null) {
|
||||
LockSkipWitness.recordAbandoned("collect-data:stale-finalize", MODULE_TYPE, taskId);
|
||||
return;
|
||||
}
|
||||
FileTaskEntity task = fileTaskMapper.selectById(taskId);
|
||||
@@ -674,6 +676,7 @@ public class CollectDataService {
|
||||
try (TaskDistributedLockService.LockHandle lock =
|
||||
taskDistributedLockService.acquire(MODULE_TYPE, taskId, 0L)) {
|
||||
if (lock == null) {
|
||||
LockSkipWitness.recordAbandoned("collect-data:no-upload-stale-finalize", MODULE_TYPE, taskId);
|
||||
return;
|
||||
}
|
||||
FileTaskEntity task = fileTaskMapper.selectById(taskId);
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.dedupe.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
@@ -78,8 +79,8 @@ public class DedupeTotalDataController {
|
||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", content = @Content(schema = @Schema(implementation = DedupeTotalDataPageVo.class)))
|
||||
})
|
||||
public ApiResponse<DedupeTotalDataPageVo> page(
|
||||
@Parameter(description = "页码") @RequestParam(name = "page", defaultValue = "1") Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(name = "page_size", defaultValue = "15") Long pageSize,
|
||||
@Parameter(description = "页码") @RequestParam(name = "page", defaultValue = PageDefaults.FIRST_PAGE) Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(name = "page_size", defaultValue = PageDefaults.USER_LIST_PAGE_SIZE) Long pageSize,
|
||||
@Parameter(description = "数据值模糊搜索关键字") @RequestParam(name = "keyword", required = false) String keyword,
|
||||
@Parameter(description = "用户名模糊搜索关键字") @RequestParam(name = "username", required = false) String username,
|
||||
@Parameter(description = "开始日期(包含)")
|
||||
|
||||
+5
@@ -3,6 +3,7 @@ package com.nanri.aiimage.modules.deletebrand.service;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.nanri.aiimage.common.service.DistributedJobLockService;
|
||||
import com.nanri.aiimage.common.util.LockSkipWitness;
|
||||
import com.nanri.aiimage.config.DeleteBrandProgressProperties;
|
||||
import com.nanri.aiimage.modules.appearancepatent.service.AppearancePatentTaskService;
|
||||
import com.nanri.aiimage.modules.brand.service.BrandTaskService;
|
||||
@@ -236,6 +237,8 @@ public class DeleteBrandStaleTaskService {
|
||||
|
||||
TaskDistributedLockService.LockHandle taskLockHandle = acquireTaskLock(MODULE_TYPE_DELETE_BRAND, task.getId());
|
||||
if (taskLockHandle == null) {
|
||||
LockSkipWitness.recordSkip("delete-brand:stale-heartbeat-scan",
|
||||
MODULE_TYPE_DELETE_BRAND, task.getId());
|
||||
continue;
|
||||
}
|
||||
boolean finalizeThrew;
|
||||
@@ -947,6 +950,8 @@ public class DeleteBrandStaleTaskService {
|
||||
for (FileTaskEntity task : runningTasks) {
|
||||
TaskDistributedLockService.LockHandle taskLockHandle = acquireTaskLock(MODULE_TYPE_DELETE_BRAND, task.getId());
|
||||
if (taskLockHandle == null) {
|
||||
LockSkipWitness.recordSkip("delete-brand:partial-result-scan",
|
||||
MODULE_TYPE_DELETE_BRAND, task.getId());
|
||||
continue;
|
||||
}
|
||||
try (taskLockHandle) {
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.devicelog.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
@@ -66,8 +67,8 @@ public class AdminDeviceLogController {
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
|
||||
@Parameter(description = "结束日期(含)") @RequestParam(required = false)
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
|
||||
@RequestParam(defaultValue = "1") Long page,
|
||||
@RequestParam(defaultValue = "20") Long pageSize,
|
||||
@RequestParam(defaultValue = PageDefaults.FIRST_PAGE) Long page,
|
||||
@RequestParam(defaultValue = PageDefaults.ADMIN_LIST_PAGE_SIZE) Long pageSize,
|
||||
@Parameter(description = "公司 ID(超管 tab;不传=不筛)")
|
||||
@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
AdminUserEntity operator = requireSuperAdmin(request);
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.imagehistory.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.service.DataReadScope;
|
||||
@@ -34,8 +35,8 @@ public class ImageHistoryController {
|
||||
@GetMapping("/history")
|
||||
@Operation(summary = "分页查询所有用户生成历史")
|
||||
public ApiResponse<ImageHistoryListVo> listHistory(HttpServletRequest request,
|
||||
@RequestParam(required = false, defaultValue = "1") Integer page,
|
||||
@RequestParam(name = "page_size", required = false, defaultValue = "15") Integer pageSize,
|
||||
@RequestParam(required = false, defaultValue = PageDefaults.FIRST_PAGE) Integer page,
|
||||
@RequestParam(name = "page_size", required = false, defaultValue = PageDefaults.USER_LIST_PAGE_SIZE) Integer pageSize,
|
||||
@RequestParam(name = "user_id", required = false) Long userId,
|
||||
@RequestParam(name = "time_start", required = false) String timeStart,
|
||||
@RequestParam(name = "time_end", required = false) String timeEnd,
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.imagevideo.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.service.DataReadScope;
|
||||
@@ -78,8 +79,8 @@ public class AdminImageVideoTaskController {
|
||||
@GetMapping
|
||||
@Operation(summary = "分页查询图生视频任务", description = "管理端按用户/任务状态/提交时间等条件分页查询近 3 天的工作流任务")
|
||||
public ApiResponse<Map<String, Object>> page(
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(name = "page_size", defaultValue = "20") Integer pageSize,
|
||||
@RequestParam(defaultValue = PageDefaults.FIRST_PAGE) Integer page,
|
||||
@RequestParam(name = "page_size", defaultValue = PageDefaults.ADMIN_LIST_PAGE_SIZE) Integer pageSize,
|
||||
@RequestParam(name = "user_id", required = false) Long userId,
|
||||
@RequestParam(required = false) String username,
|
||||
@RequestParam(required = false) String status,
|
||||
|
||||
+2
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nanri.aiimage.common.util.LockSkipWitness;
|
||||
import com.nanri.aiimage.config.ImageVideoProperties;
|
||||
import com.nanri.aiimage.common.service.DistributedJobLockService;
|
||||
import com.nanri.aiimage.modules.file.service.oss.OssStorageService;
|
||||
@@ -115,6 +116,7 @@ public class ImageVideoArchiveService {
|
||||
DistributedJobLockService.LockHandle jobLock = distributedJobLockService.tryLock(
|
||||
"image-video:retention-cleanup", java.time.Duration.ofMinutes(20));
|
||||
if (jobLock == null) {
|
||||
LockSkipWitness.abandoned("image-video:retention-cleanup");
|
||||
return;
|
||||
}
|
||||
try (jobLock) {
|
||||
|
||||
+5
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nanri.aiimage.common.util.LockSkipWitness;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.exception.TaskOwnerMismatchException;
|
||||
import com.nanri.aiimage.config.InstanceMetadata;
|
||||
@@ -141,6 +142,7 @@ public class ImageVideoAsyncTaskService {
|
||||
DistributedJobLockService.LockHandle jobLock =
|
||||
distributedJobLockService.tryLock("image-video:dispatch", java.time.Duration.ofSeconds(5));
|
||||
if (jobLock == null) {
|
||||
LockSkipWitness.abandoned("image-video:dispatch");
|
||||
return;
|
||||
}
|
||||
try (jobLock) {
|
||||
@@ -163,6 +165,7 @@ public class ImageVideoAsyncTaskService {
|
||||
DistributedJobLockService.LockHandle jobLock =
|
||||
distributedJobLockService.tryLock("image-video:poll", java.time.Duration.ofSeconds(30));
|
||||
if (jobLock == null) {
|
||||
LockSkipWitness.abandoned("image-video:poll");
|
||||
return;
|
||||
}
|
||||
try (jobLock) {
|
||||
@@ -208,6 +211,7 @@ public class ImageVideoAsyncTaskService {
|
||||
DistributedJobLockService.LockHandle jobLock =
|
||||
distributedJobLockService.tryLock("image-video:owner-takeover", java.time.Duration.ofSeconds(30));
|
||||
if (jobLock == null) {
|
||||
LockSkipWitness.abandoned("image-video:owner-takeover");
|
||||
return;
|
||||
}
|
||||
try (jobLock) {
|
||||
@@ -244,6 +248,7 @@ public class ImageVideoAsyncTaskService {
|
||||
DistributedJobLockService.LockHandle jobLock =
|
||||
distributedJobLockService.tryLock("image-video:failed-task-cleanup", java.time.Duration.ofSeconds(120));
|
||||
if (jobLock == null) {
|
||||
LockSkipWitness.abandoned("image-video:failed-task-cleanup");
|
||||
return;
|
||||
}
|
||||
try (jobLock) {
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.invalidasin.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
@@ -57,8 +58,8 @@ public class InvalidAsinDataController {
|
||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", content = @Content(schema = @Schema(implementation = InvalidAsinDataPageVo.class)))
|
||||
})
|
||||
public ApiResponse<InvalidAsinDataPageVo> page(
|
||||
@Parameter(description = "页码") @RequestParam(name = "page", defaultValue = "1") Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(name = "page_size", defaultValue = "15") Long pageSize,
|
||||
@Parameter(description = "页码") @RequestParam(name = "page", defaultValue = PageDefaults.FIRST_PAGE) Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(name = "page_size", defaultValue = PageDefaults.USER_LIST_PAGE_SIZE) Long pageSize,
|
||||
@Parameter(description = "模糊搜索关键字") @RequestParam(name = "keyword", required = false) String keyword,
|
||||
@Parameter(description = "ASIN 模糊搜索") @RequestParam(name = "data_value", required = false) String dataValue,
|
||||
@Parameter(description = "品牌模糊搜索") @RequestParam(name = "brand", required = false) String brand,
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.notification.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.notification.model.dto.NotificationPageQuery;
|
||||
import com.nanri.aiimage.modules.notification.model.vo.NotificationPageVo;
|
||||
@@ -49,8 +50,8 @@ public class AdminNotificationController {
|
||||
+ "startDate/endDate 为年月日闭区间。")
|
||||
public ApiResponse<NotificationPageVo> page(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "20") Long pageSize,
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = PageDefaults.FIRST_PAGE) Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = PageDefaults.ADMIN_LIST_PAGE_SIZE) Long pageSize,
|
||||
@Parameter(description = "只看未读") @RequestParam(required = false, defaultValue = "false") Boolean onlyUnread,
|
||||
@Parameter(description = "关键字(标题/内容)") @RequestParam(required = false) String keyword,
|
||||
@Parameter(description = "类型大类:system_error/task_error/config_error/system_notice")
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.notification.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.notification.model.dto.NotificationPageQuery;
|
||||
import com.nanri.aiimage.modules.notification.model.vo.NotificationPageVo;
|
||||
@@ -49,8 +50,8 @@ public class NotificationController {
|
||||
+ "startDate/endDate 为年月日闭区间。")
|
||||
public ApiResponse<NotificationPageVo> page(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "20") Long pageSize,
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = PageDefaults.FIRST_PAGE) Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = PageDefaults.ADMIN_LIST_PAGE_SIZE) Long pageSize,
|
||||
@Parameter(description = "只看未读") @RequestParam(required = false, defaultValue = "false") Boolean onlyUnread,
|
||||
@Parameter(description = "关键字(标题/内容)") @RequestParam(required = false) String keyword,
|
||||
@Parameter(description = "类型大类:system_error/task_error/config_error/system_notice")
|
||||
|
||||
+2
-1
@@ -105,7 +105,8 @@ public class PatrolDeleteTaskService {
|
||||
validateUserId(userId);
|
||||
ProductRiskDashboardVo vo = new ProductRiskDashboardVo();
|
||||
vo.setCandidateCount(patrolDeleteResolveService.countCandidates(userId));
|
||||
vo.setProcessedTaskCount(countTasks(userId, List.of("SUCCESS", "FAILED")));
|
||||
vo.setProcessedTaskCount(countTasks(userId,
|
||||
com.nanri.aiimage.common.task.TaskStatuses.FileTask.FINISHED_ORDERED));
|
||||
vo.setSuccessTaskCount(countTasks(userId, List.of("SUCCESS")));
|
||||
vo.setFailedTaskCount(countTasks(userId, List.of("FAILED")));
|
||||
return vo;
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.pricetrack.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.pricetrack.model.dto.PriceTrackCandidateAddRequest;
|
||||
import com.nanri.aiimage.modules.pricetrack.model.dto.PriceTrackCountryPreferenceSaveRequest;
|
||||
@@ -142,9 +143,9 @@ public class PriceTrackController {
|
||||
@Parameter(description = "任务编号", required = true, example = "200")
|
||||
@PathVariable Long taskId,
|
||||
@Parameter(description = "页码,从 1 开始", example = "1")
|
||||
@RequestParam(value = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(value = "page", defaultValue = PageDefaults.FIRST_PAGE) Integer page,
|
||||
@Parameter(description = "每页条数,默认 1000,最大 2000", example = "1000")
|
||||
@RequestParam(value = "page_size", defaultValue = "1000") Integer pageSize,
|
||||
@RequestParam(value = "page_size", defaultValue = PageDefaults.FULL_EXPORT_PAGE_SIZE) Integer pageSize,
|
||||
@Parameter(description = "店铺名称过滤条件,可重复传入,也可用英文逗号分隔;仅在任务关联店铺范围内生效", example = "测试店铺A")
|
||||
@RequestParam(value = "shop_name", required = false) List<String> shopNames,
|
||||
@Parameter(description = "国家代码过滤条件,可重复传入,也可用英文逗号分隔;仅在任务国家范围内生效", example = "DE")
|
||||
|
||||
+2
-1
@@ -65,7 +65,8 @@ public class PriceTrackLoopRunStaleService {
|
||||
private static final String STATUS_STOPPED = "STOPPED";
|
||||
|
||||
/** 子任务终态集合,与 PriceTrackLoopRunService.isChildTaskTerminal 口径一致。 */
|
||||
private static final Set<String> CHILD_TERMINAL_STATUSES = Set.of("SUCCESS", "FAILED", "STOPPED");
|
||||
private static final Set<String> CHILD_TERMINAL_STATUSES =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.LoopRun.TERMINAL;
|
||||
|
||||
/** 单轮最多扫描的轮次数,其余留给下一轮(每 2 分钟一次),避免一次扫太多拖慢巡检。 */
|
||||
static final int MAX_LOOP_RUNS_PER_SCAN = 200;
|
||||
|
||||
+2
-1
@@ -142,7 +142,8 @@ public class PriceTrackTaskService {
|
||||
Long processed = fileTaskMapper.selectCount(new LambdaQueryWrapper<FileTaskEntity>()
|
||||
.eq(FileTaskEntity::getModuleType, MODULE_TYPE)
|
||||
.eq(FileTaskEntity::getUserId, userId)
|
||||
.in(FileTaskEntity::getStatus, List.of("SUCCESS", "FAILED")));
|
||||
.in(FileTaskEntity::getStatus,
|
||||
com.nanri.aiimage.common.task.TaskStatuses.FileTask.FINISHED_ORDERED));
|
||||
Long success = fileTaskMapper.selectCount(new LambdaQueryWrapper<FileTaskEntity>()
|
||||
.eq(FileTaskEntity::getModuleType, MODULE_TYPE)
|
||||
.eq(FileTaskEntity::getUserId, userId)
|
||||
|
||||
+5
-4
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.productcategory.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.util.DownloadHeaderUtil;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
@@ -61,8 +62,8 @@ public class ProductCategoryController {
|
||||
public ApiResponse<ProductCategoryListVo> children(
|
||||
HttpServletRequest request,
|
||||
@RequestParam(value = "parent_id", required = false) Long parentId,
|
||||
@RequestParam(value = "page", defaultValue = "1") Long page,
|
||||
@RequestParam(value = "page_size", defaultValue = "20") Long pageSize) {
|
||||
@RequestParam(value = "page", defaultValue = PageDefaults.FIRST_PAGE) Long page,
|
||||
@RequestParam(value = "page_size", defaultValue = PageDefaults.ADMIN_LIST_PAGE_SIZE) Long pageSize) {
|
||||
requireOperator(request);
|
||||
return ApiResponse.success(productCategoryService.children(parentId, page, pageSize));
|
||||
}
|
||||
@@ -72,8 +73,8 @@ public class ProductCategoryController {
|
||||
public ApiResponse<ProductCategoryListVo> search(
|
||||
HttpServletRequest request,
|
||||
@RequestParam(value = "keyword", required = false) String keyword,
|
||||
@RequestParam(value = "page", defaultValue = "1") Long page,
|
||||
@RequestParam(value = "page_size", defaultValue = "20") Long pageSize) {
|
||||
@RequestParam(value = "page", defaultValue = PageDefaults.FIRST_PAGE) Long page,
|
||||
@RequestParam(value = "page_size", defaultValue = PageDefaults.ADMIN_LIST_PAGE_SIZE) Long pageSize) {
|
||||
requireOperator(request);
|
||||
return ApiResponse.success(productCategoryService.search(keyword, page, pageSize));
|
||||
}
|
||||
|
||||
+2
-1
@@ -128,7 +128,8 @@ public class ProductRiskTaskService {
|
||||
Long processed = fileTaskMapper.selectCount(new LambdaQueryWrapper<FileTaskEntity>()
|
||||
.eq(FileTaskEntity::getModuleType, MODULE_TYPE)
|
||||
.eq(FileTaskEntity::getUserId, userId)
|
||||
.in(FileTaskEntity::getStatus, List.of("SUCCESS", "FAILED")));
|
||||
.in(FileTaskEntity::getStatus,
|
||||
com.nanri.aiimage.common.task.TaskStatuses.FileTask.FINISHED_ORDERED));
|
||||
Long success = fileTaskMapper.selectCount(new LambdaQueryWrapper<FileTaskEntity>()
|
||||
.eq(FileTaskEntity::getModuleType, MODULE_TYPE)
|
||||
.eq(FileTaskEntity::getUserId, userId)
|
||||
|
||||
+4
-3
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.publish.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.publish.model.dto.PublishParseRequest;
|
||||
import com.nanri.aiimage.modules.publish.model.dto.PublishSubmitResultRequest;
|
||||
@@ -94,9 +95,9 @@ public class PublishController {
|
||||
@Parameter(description = "任务内文件 ID", required = true, example = "9101")
|
||||
@RequestParam("file_id") Long fileId,
|
||||
@Parameter(description = "页码,从 1 开始", example = "1")
|
||||
@RequestParam(value = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(value = "page", defaultValue = PageDefaults.FIRST_PAGE) Integer page,
|
||||
@Parameter(description = "每页条数,默认 50,最大 200", example = "50")
|
||||
@RequestParam(value = "page_size", defaultValue = "50") Integer pageSize,
|
||||
@RequestParam(value = "page_size", defaultValue = PageDefaults.TASK_LIST_PAGE_SIZE) Integer pageSize,
|
||||
HttpServletRequest httpRequest) {
|
||||
return ApiResponse.success(publishTaskService.getItemsPage(taskId,
|
||||
adminAuthSupport.resolveOwnershipUserId(httpRequest, userId), fileId, page, pageSize));
|
||||
@@ -164,7 +165,7 @@ public class PublishController {
|
||||
@Parameter(description = "当前登录用户 ID;服务端按会话身份校验,与登录账号不一致即拒绝", required = true, example = "1")
|
||||
@RequestParam("user_id") Long userId,
|
||||
@Parameter(description = "返回数量上限,默认 50,最大 100", example = "50")
|
||||
@RequestParam(value = "limit", defaultValue = "50") Integer limit,
|
||||
@RequestParam(value = "limit", defaultValue = PageDefaults.DEFAULT_RESULT_LIMIT) Integer limit,
|
||||
HttpServletRequest httpRequest) {
|
||||
// 上限钳制(2026-09):文档写"最多返回 100 条"但此前无实际校验
|
||||
int safeLimit = limit == null ? 100 : Math.min(Math.max(1, limit), 100);
|
||||
|
||||
+4
-1
@@ -12,6 +12,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.exception.TaskOwnerMismatchException;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.util.LockSkipWitness;
|
||||
import com.nanri.aiimage.config.InstanceMetadata;
|
||||
import com.nanri.aiimage.modules.file.service.LocalFileStorageService;
|
||||
import com.nanri.aiimage.modules.file.service.oss.OssStorageService;
|
||||
@@ -103,7 +104,7 @@ public class PublishTaskService {
|
||||
* PENDING/RUNNING 绝不在此列;PUBLISH 实际只会写 SUCCESS/FAILED,取消态是无害的超集。
|
||||
*/
|
||||
private static final Set<String> RETENTION_TERMINAL_STATUSES =
|
||||
Set.of(STATUS_SUCCESS, STATUS_FAILED, "CANCELLED", "CANCELED");
|
||||
com.nanri.aiimage.common.task.TaskStatuses.FileTask.TERMINAL;
|
||||
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
private final LocalFileStorageService localFileStorageService;
|
||||
@@ -520,6 +521,7 @@ public class PublishTaskService {
|
||||
try (TaskDistributedLockService.LockHandle lock =
|
||||
taskDistributedLockService.acquire(MODULE_TYPE, candidate.getId(), 0L)) {
|
||||
if (lock == null) {
|
||||
LockSkipWitness.recordSkip("publish:stale-heartbeat-scan", MODULE_TYPE, candidate.getId());
|
||||
continue;
|
||||
}
|
||||
transactionTemplate.executeWithoutResult(status -> failStaleTaskLocked(candidate.getId(), threshold));
|
||||
@@ -967,6 +969,7 @@ public class PublishTaskService {
|
||||
try (TaskDistributedLockService.LockHandle lock =
|
||||
taskDistributedLockService.acquire(MODULE_TYPE, candidate.getId(), 0L)) {
|
||||
if (lock == null) {
|
||||
LockSkipWitness.recordAbandoned("publish:no-upload-stale-finalize", MODULE_TYPE, candidate.getId());
|
||||
return;
|
||||
}
|
||||
transactionTemplate.executeWithoutResult(status -> failStaleTaskLockedInternal(
|
||||
|
||||
+2
-1
@@ -116,7 +116,8 @@ public class QueryAsinTaskService {
|
||||
validateUserId(userId);
|
||||
ProductRiskDashboardVo vo = new ProductRiskDashboardVo();
|
||||
vo.setCandidateCount(queryAsinResolveService.countCandidates(userId));
|
||||
vo.setProcessedTaskCount(countTasks(userId, List.of("SUCCESS", "FAILED")));
|
||||
vo.setProcessedTaskCount(countTasks(userId,
|
||||
com.nanri.aiimage.common.task.TaskStatuses.FileTask.FINISHED_ORDERED));
|
||||
vo.setSuccessTaskCount(countTasks(userId, List.of("SUCCESS")));
|
||||
vo.setFailedTaskCount(countTasks(userId, List.of("FAILED")));
|
||||
return vo;
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.shopdatacrawl.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskCandidateAddRequest;
|
||||
import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskCountryPreferenceSaveRequest;
|
||||
@@ -158,9 +159,9 @@ public class ShopDataCrawlTaskController {
|
||||
in = ParameterIn.QUERY, example = "1")
|
||||
@RequestParam("user_id") Long userId,
|
||||
@Parameter(name = "page", description = "页号,从 1 开始", in = ParameterIn.QUERY, example = "1")
|
||||
@RequestParam(value = "page", defaultValue = "1") int page,
|
||||
@RequestParam(value = "page", defaultValue = PageDefaults.FIRST_PAGE) int page,
|
||||
@Parameter(name = "limit", description = "每页条数,最大 100;默认 100 与旧版返回最近 100 条的行为一致", in = ParameterIn.QUERY, example = "20")
|
||||
@RequestParam(value = "limit", defaultValue = "100") int limit,
|
||||
@RequestParam(value = "limit", defaultValue = PageDefaults.ADMIN_SCAN_LIMIT) int limit,
|
||||
HttpServletRequest httpRequest) {
|
||||
userId = adminAuthSupport.resolveOwnershipUserId(httpRequest, userId);
|
||||
return ApiResponse.success(taskService.listHistory(userId, page, limit));
|
||||
|
||||
+2
-1
@@ -345,7 +345,8 @@ public class ShopDataCrawlTaskService {
|
||||
validateUserId(userId);
|
||||
ProductRiskDashboardVo vo = new ProductRiskDashboardVo();
|
||||
vo.setCandidateCount(shopDataCrawlResolveService.countCandidates(userId));
|
||||
vo.setProcessedTaskCount(countTasks(userId, List.of("SUCCESS", "FAILED")));
|
||||
vo.setProcessedTaskCount(countTasks(userId,
|
||||
com.nanri.aiimage.common.task.TaskStatuses.FileTask.FINISHED_ORDERED));
|
||||
vo.setSuccessTaskCount(countTasks(userId, List.of("SUCCESS")));
|
||||
vo.setFailedTaskCount(countTasks(userId, List.of("FAILED")));
|
||||
return vo;
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.shopkey.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.util.DownloadHeaderUtil;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
@@ -60,8 +61,8 @@ public class QueryAsinController {
|
||||
@Operation(summary = "分页查询 ASIN", description = "company_id 只收窄可见集、不放大,跨公司查看仅超管")
|
||||
public ApiResponse<QueryAsinPageVo> page(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "页码") @RequestParam(name = "page", defaultValue = "1") Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(name = "page_size", defaultValue = "15") Long pageSize,
|
||||
@Parameter(description = "页码") @RequestParam(name = "page", defaultValue = PageDefaults.FIRST_PAGE) Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(name = "page_size", defaultValue = PageDefaults.USER_LIST_PAGE_SIZE) Long pageSize,
|
||||
@Parameter(description = "分组ID") @RequestParam(name = "group_id", required = false) Long groupId,
|
||||
@Parameter(description = "店铺名") @RequestParam(name = "shop_name", required = false) String shopName,
|
||||
@Parameter(description = "商品 ASIN") @RequestParam(name = "asin", required = false) String asin,
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.shopkey.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.service.DataReadScope;
|
||||
@@ -58,8 +59,8 @@ public class ShopKeyController {
|
||||
})
|
||||
public ApiResponse<ShopKeyPageVo> page(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "15") Long pageSize,
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = PageDefaults.FIRST_PAGE) Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = PageDefaults.USER_LIST_PAGE_SIZE) Long pageSize,
|
||||
@Parameter(description = "按公司筛选(仅超管生效;非超管一律按会话公司裁剪)")
|
||||
@RequestParam(name = "company_id", required = false) Long companyId,
|
||||
@Parameter(description = "备注名 / 紫鸟账号 模糊词")
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.shopkey.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
@@ -79,8 +80,8 @@ public class ShopManageController {
|
||||
})
|
||||
public ApiResponse<ShopManagePageVo> page(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "15") Long pageSize,
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = PageDefaults.FIRST_PAGE) Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = PageDefaults.USER_LIST_PAGE_SIZE) Long pageSize,
|
||||
@Parameter(description = "分组 ID") @RequestParam(required = false) Long groupId,
|
||||
@Parameter(description = "店铺名称") @RequestParam(required = false) String shopName,
|
||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.shopkey.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.util.DownloadHeaderUtil;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
@@ -60,8 +61,8 @@ public class SkipPriceAsinController {
|
||||
@Operation(summary = "分页查询跳过跟价 ASIN", description = "支持按分组、店铺名、ASIN 和当前操作人可见范围筛选。")
|
||||
public ApiResponse<SkipPriceAsinPageVo> page(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "页码") @RequestParam(name = "page", defaultValue = "1") Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(name = "page_size", defaultValue = "15") Long pageSize,
|
||||
@Parameter(description = "页码") @RequestParam(name = "page", defaultValue = PageDefaults.FIRST_PAGE) Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(name = "page_size", defaultValue = PageDefaults.USER_LIST_PAGE_SIZE) Long pageSize,
|
||||
@Parameter(description = "分组 ID") @RequestParam(name = "group_id", required = false) Long groupId,
|
||||
@Parameter(description = "店铺名称") @RequestParam(name = "shop_name", required = false) String shopName,
|
||||
@Parameter(description = "商品 ASIN") @RequestParam(name = "asin", required = false) String asin,
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.shopmatch.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskCandidateAddRequest;
|
||||
import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskCountryPreferenceSaveRequest;
|
||||
@@ -186,9 +187,9 @@ public class ShopMatchController {
|
||||
public ApiResponse<ShopMatchSkipAsinPageVo> getTaskSkipAsinsPaginated(
|
||||
@Parameter(description = "任务编号", required = true, example = "200") @PathVariable Long taskId,
|
||||
@Parameter(description = "页码,从 1 开始", example = "1")
|
||||
@RequestParam(value = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(value = "page", defaultValue = PageDefaults.FIRST_PAGE) Integer page,
|
||||
@Parameter(description = "每页条数,默认 1000,最大 2000", example = "1000")
|
||||
@RequestParam(value = "page_size", defaultValue = "1000") Integer pageSize,
|
||||
@RequestParam(value = "page_size", defaultValue = PageDefaults.FULL_EXPORT_PAGE_SIZE) Integer pageSize,
|
||||
@Parameter(description = "店铺名称过滤条件,可重复传入,也可用英文逗号分隔", example = "测试店铺A")
|
||||
@RequestParam(value = "shop_name", required = false) List<String> shopNames,
|
||||
@Parameter(description = "国家代码过滤条件,可重复传入,也可用英文逗号分隔", example = "DE")
|
||||
|
||||
+2
-1
@@ -204,7 +204,8 @@ public class ShopMatchTaskService {
|
||||
Long processed = fileTaskMapper.selectCount(new LambdaQueryWrapper<FileTaskEntity>()
|
||||
.eq(FileTaskEntity::getModuleType, MODULE_TYPE)
|
||||
.eq(FileTaskEntity::getUserId, userId)
|
||||
.in(FileTaskEntity::getStatus, List.of("SUCCESS", "FAILED")));
|
||||
.in(FileTaskEntity::getStatus,
|
||||
com.nanri.aiimage.common.task.TaskStatuses.FileTask.FINISHED_ORDERED));
|
||||
Long success = fileTaskMapper.selectCount(new LambdaQueryWrapper<FileTaskEntity>()
|
||||
.eq(FileTaskEntity::getModuleType, MODULE_TYPE)
|
||||
.eq(FileTaskEntity::getUserId, userId)
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.similarasin.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.similarasin.model.dto.SimilarAsinFilterConditionAddRequest;
|
||||
import com.nanri.aiimage.modules.similarasin.model.dto.SimilarAsinParseRequest;
|
||||
@@ -129,7 +130,7 @@ public class SimilarAsinController {
|
||||
@Parameter(description = "当前用户 ID", required = true, example = "1")
|
||||
@RequestParam("user_id") Long userId,
|
||||
@Parameter(description = "历史记录条数,默认 50,最大 100", example = "50")
|
||||
@RequestParam(value = "limit", required = false, defaultValue = "50") Integer limit,
|
||||
@RequestParam(value = "limit", required = false, defaultValue = PageDefaults.DEFAULT_RESULT_LIMIT) Integer limit,
|
||||
HttpServletRequest httpRequest) {
|
||||
userId = adminAuthSupport.resolveOwnershipUserId(httpRequest, userId);
|
||||
return ApiResponse.success(service.history(userId, limit));
|
||||
|
||||
+6
@@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.exception.TaskOwnerMismatchException;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.util.LockSkipWitness;
|
||||
import com.nanri.aiimage.common.service.DistributedJobLockService;
|
||||
import com.nanri.aiimage.common.util.FailedStatusRowFilter;
|
||||
import com.nanri.aiimage.common.util.StaleTaskDeathReason;
|
||||
@@ -877,6 +878,7 @@ public class SimilarAsinTaskService implements SimilarAsinPipelineHost {
|
||||
TaskDistributedLockService.LockHandle taskLockHandle = ownershipSupport().acquireTaskLock(task.getId(), 0L);
|
||||
if (taskLockHandle == null) {
|
||||
// 锁被 owner 实例/文件任务 worker 占用说明其仍活跃,静默跳过等下一轮(2 分钟后再判)
|
||||
LockSkipWitness.recordSkip("similar-asin:heartbeat-stale-scan", MODULE_TYPE, task.getId());
|
||||
continue;
|
||||
}
|
||||
try (taskLockHandle) {
|
||||
@@ -892,6 +894,7 @@ public class SimilarAsinTaskService implements SimilarAsinPipelineHost {
|
||||
}
|
||||
TaskDistributedLockService.LockHandle taskLockHandle = ownershipSupport().acquireTaskLock(taskId, 0L);
|
||||
if (taskLockHandle == null) {
|
||||
LockSkipWitness.recordAbandoned("similar-asin:debug-finalize-stale", MODULE_TYPE, taskId);
|
||||
return;
|
||||
}
|
||||
try (taskLockHandle) {
|
||||
@@ -1023,6 +1026,7 @@ public class SimilarAsinTaskService implements SimilarAsinPipelineHost {
|
||||
TaskDistributedLockService.LockHandle neverReportedLock =
|
||||
ownershipSupport().acquireTaskLock(task.getId(), 0L);
|
||||
if (neverReportedLock == null) {
|
||||
LockSkipWitness.recordSkip("similar-asin:never-reported-stale-scan", MODULE_TYPE, task.getId());
|
||||
continue;
|
||||
}
|
||||
try (neverReportedLock) {
|
||||
@@ -1049,6 +1053,7 @@ public class SimilarAsinTaskService implements SimilarAsinPipelineHost {
|
||||
}
|
||||
TaskDistributedLockService.LockHandle taskLockHandle = ownershipSupport().acquireTaskLock(task.getId(), 0L);
|
||||
if (taskLockHandle == null) {
|
||||
LockSkipWitness.recordSkip("similar-asin:no-result-shard-stale-scan", MODULE_TYPE, task.getId());
|
||||
continue;
|
||||
}
|
||||
try (taskLockHandle) {
|
||||
@@ -1488,6 +1493,7 @@ public class SimilarAsinTaskService implements SimilarAsinPipelineHost {
|
||||
DistributedJobLockService.LockHandle lockHandle =
|
||||
distributedJobLockService.tryLock("similar-asin:llm-poll", Duration.ofMinutes(1));
|
||||
if (lockHandle == null) {
|
||||
LockSkipWitness.abandoned("similar-asin:llm-poll");
|
||||
return;
|
||||
}
|
||||
try (lockHandle) {
|
||||
|
||||
+5
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.similarasin.service.support;
|
||||
|
||||
import com.nanri.aiimage.common.util.UserMessages;
|
||||
import com.nanri.aiimage.common.util.LockSkipWitness;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import com.nanri.aiimage.modules.similarasin.model.dto.SimilarAsinParsedPayloadDto;
|
||||
import com.nanri.aiimage.modules.similarasin.model.dto.SimilarAsinResultGroupDto;
|
||||
@@ -984,6 +985,7 @@ public class SimilarAsinPipelineSupport {
|
||||
taskQueueExecutor.execute(() -> {
|
||||
TaskDistributedLockService.LockHandle taskLockHandle = ownershipSupport.acquireTaskLock(taskId, 0L);
|
||||
if (taskLockHandle == null) {
|
||||
LockSkipWitness.recordAbandoned("similar-asin:direct-llm-poll-fallback", MODULE_TYPE, taskId);
|
||||
return;
|
||||
}
|
||||
try (taskLockHandle) {
|
||||
@@ -1014,6 +1016,7 @@ public class SimilarAsinPipelineSupport {
|
||||
}
|
||||
TaskDistributedLockService.LockHandle taskLockHandle = ownershipSupport.acquireTaskLock(taskId, 0L);
|
||||
if (taskLockHandle == null) {
|
||||
LockSkipWitness.recordAbandoned("similar-asin:resubmit-pending-llm-states", MODULE_TYPE, taskId);
|
||||
return;
|
||||
}
|
||||
try (taskLockHandle) {
|
||||
@@ -1484,6 +1487,7 @@ public class SimilarAsinPipelineSupport {
|
||||
}
|
||||
TaskDistributedLockService.LockHandle lockHandle = ownershipSupport.acquireTaskLock(taskId, 0L);
|
||||
if (lockHandle == null) {
|
||||
LockSkipWitness.recordAbandoned("similar-asin:maybe-finalize-llm-job", MODULE_TYPE, taskId);
|
||||
return;
|
||||
}
|
||||
try (lockHandle) {
|
||||
@@ -1509,6 +1513,7 @@ public class SimilarAsinPipelineSupport {
|
||||
DistributedJobLockService.LockHandle lockHandle =
|
||||
distributedJobLockService.tryLock("similar-asin:llm-finalize:" + taskId, Duration.ofMinutes(5));
|
||||
if (lockHandle == null) {
|
||||
LockSkipWitness.recordAbandoned("similar-asin:llm-finalize-job-lock", MODULE_TYPE, taskId);
|
||||
return;
|
||||
}
|
||||
try (lockHandle) {
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.task.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskFileJobEntity;
|
||||
import com.nanri.aiimage.modules.task.service.TaskFileJobService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -30,7 +31,7 @@ public class TaskFileJobController {
|
||||
@RequestParam(value = "status", required = false) String status,
|
||||
@RequestParam(value = "module_type", required = false) String moduleType,
|
||||
@RequestParam(value = "task_id", required = false) Long taskId,
|
||||
@RequestParam(value = "limit", defaultValue = "100") int limit) {
|
||||
@RequestParam(value = "limit", defaultValue = PageDefaults.ADMIN_SCAN_LIMIT) int limit) {
|
||||
// 上限钳制(2026-09):该运维端点此前对 limit 无校验
|
||||
return ApiResponse.success(taskFileJobService.listJobs(status, moduleType, taskId,
|
||||
Math.min(Math.max(1, limit), 1000)));
|
||||
@@ -47,7 +48,7 @@ public class TaskFileJobController {
|
||||
@Operation(summary = "手动扫描并复位卡住的 RUNNING Job")
|
||||
public ApiResponse<Map<String, Object>> resetStuck(
|
||||
@RequestParam(value = "timeout_minutes", defaultValue = "30") int timeoutMinutes,
|
||||
@RequestParam(value = "limit", defaultValue = "100") int limit) {
|
||||
@RequestParam(value = "limit", defaultValue = PageDefaults.ADMIN_SCAN_LIMIT) int limit) {
|
||||
int reset = taskFileJobService.resetStuckRunningJobs(timeoutMinutes, limit);
|
||||
return ApiResponse.success(Map.of("reset", reset));
|
||||
}
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class CompletedTaskActiveJobInspector {
|
||||
|
||||
public ActiveJobReport inspectTerminalTasksWithActiveJobs(int limit) {
|
||||
List<FileTaskEntity> tasks = fileTaskMapper.selectList(new LambdaQueryWrapper<FileTaskEntity>()
|
||||
.in(FileTaskEntity::getStatus, List.of("SUCCESS", "FAILED"))
|
||||
.in(FileTaskEntity::getStatus, com.nanri.aiimage.common.task.TaskStatuses.FileTask.FINISHED_ORDERED)
|
||||
.orderByAsc(FileTaskEntity::getUpdatedAt)
|
||||
.last("limit " + Math.max(1, Math.min(limit, 500))));
|
||||
if (tasks == null || tasks.isEmpty()) {
|
||||
|
||||
+2
@@ -7,6 +7,7 @@ import com.nanri.aiimage.common.mapper.ShopManageGroupMapper;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.service.CompanyScopeSupport;
|
||||
import com.nanri.aiimage.common.service.DistributedJobLockService;
|
||||
import com.nanri.aiimage.common.util.LockSkipWitness;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileTaskMapper;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity;
|
||||
import com.nanri.aiimage.modules.task.spi.ExpiredAccountTaskStopSpi;
|
||||
@@ -62,6 +63,7 @@ public class ExpiredAccountTaskStopService {
|
||||
public void stopTasksOfExpiredAccounts() {
|
||||
var lock = distributedJobLockService.tryLock("expired-account-task-stop", Duration.ofSeconds(55));
|
||||
if (lock == null) {
|
||||
LockSkipWitness.abandoned("expired-account-task-stop");
|
||||
return;
|
||||
}
|
||||
try (lock) {
|
||||
|
||||
+2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.task.service;
|
||||
|
||||
import com.nanri.aiimage.common.service.DistributedJobLockService;
|
||||
import com.nanri.aiimage.common.util.LockSkipWitness;
|
||||
import com.nanri.aiimage.config.InspectionProperties;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
@@ -59,6 +60,7 @@ public class InspectionSqlReportTask {
|
||||
return;
|
||||
}
|
||||
if (distributedJobLockService == null) {
|
||||
LockSkipWitness.abandoned("inspection:sql-report-lock-service-missing");
|
||||
return;
|
||||
}
|
||||
DistributedJobLockService.LockHandle lockHandle =
|
||||
|
||||
+2
-1
@@ -40,7 +40,8 @@ import java.util.Set;
|
||||
@Service
|
||||
public class ModuleHistoryCleanupService {
|
||||
|
||||
private static final Set<String> TERMINAL_STATUSES = Set.of("SUCCESS", "FAILED", "CANCELLED", "CANCELED");
|
||||
private static final Set<String> TERMINAL_STATUSES =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.FileTask.TERMINAL;
|
||||
private static final Duration CLEANUP_LOCK_TTL = Duration.ofHours(2);
|
||||
private static final String COLLECT_DATA_MODULE_TYPE = "COLLECT_DATA";
|
||||
private static final int DEFAULT_BATCH_SIZE = 500;
|
||||
|
||||
+7
-7
@@ -152,7 +152,7 @@ public class TaskFileJobService {
|
||||
|
||||
public List<TaskFileJobEntity> listRunnableJobs(int limit) {
|
||||
return taskFileJobMapper.selectList(new LambdaQueryWrapper<TaskFileJobEntity>()
|
||||
.in(TaskFileJobEntity::getStatus, List.of("PENDING", "FAILED"))
|
||||
.in(TaskFileJobEntity::getStatus, com.nanri.aiimage.common.task.TaskStatuses.Job.RETRYABLE_ORDERED)
|
||||
.lt(TaskFileJobEntity::getRetryCount, MAX_RETRY_COUNT)
|
||||
.orderByAsc(TaskFileJobEntity::getUpdatedAt)
|
||||
.last("limit " + Math.max(1, Math.min(limit, 100))));
|
||||
@@ -178,7 +178,7 @@ public class TaskFileJobService {
|
||||
int safeLimit = Math.max(1, Math.min(limit, 100));
|
||||
|
||||
List<TaskFileJobEntity> ownerJobs = taskFileJobMapper.selectList(new LambdaQueryWrapper<TaskFileJobEntity>()
|
||||
.in(TaskFileJobEntity::getStatus, List.of("PENDING", "FAILED"))
|
||||
.in(TaskFileJobEntity::getStatus, com.nanri.aiimage.common.task.TaskStatuses.Job.RETRYABLE_ORDERED)
|
||||
.lt(TaskFileJobEntity::getRetryCount, MAX_RETRY_COUNT)
|
||||
.in(TaskFileJobEntity::getModuleType, List.of("APPEARANCE_PATENT", "SIMILAR_ASIN", "PUBLISH", "SHOP_DATA_CRAWL"))
|
||||
.eq(TaskFileJobEntity::getOwner, normalizedOwner)
|
||||
@@ -188,7 +188,7 @@ public class TaskFileJobService {
|
||||
List<TaskFileJobEntity> candidates = new ArrayList<>(ownerJobs);
|
||||
if (ownerJobs.size() < safeLimit) {
|
||||
LambdaQueryWrapper<TaskFileJobEntity> genericWrapper = new LambdaQueryWrapper<TaskFileJobEntity>()
|
||||
.in(TaskFileJobEntity::getStatus, List.of("PENDING", "FAILED"))
|
||||
.in(TaskFileJobEntity::getStatus, com.nanri.aiimage.common.task.TaskStatuses.Job.RETRYABLE_ORDERED)
|
||||
.lt(TaskFileJobEntity::getRetryCount, MAX_RETRY_COUNT)
|
||||
.and(wrapper -> wrapper
|
||||
.notIn(TaskFileJobEntity::getModuleType, List.of("APPEARANCE_PATENT", "SIMILAR_ASIN", "PUBLISH", "SHOP_DATA_CRAWL"))
|
||||
@@ -236,7 +236,7 @@ public class TaskFileJobService {
|
||||
int safeLimit = Math.max(1, Math.min(limit, 100));
|
||||
|
||||
List<TaskFileJobEntity> ownerJobs = taskFileJobMapper.selectList(new LambdaQueryWrapper<TaskFileJobEntity>()
|
||||
.in(TaskFileJobEntity::getStatus, List.of("PENDING", "FAILED"))
|
||||
.in(TaskFileJobEntity::getStatus, com.nanri.aiimage.common.task.TaskStatuses.Job.RETRYABLE_ORDERED)
|
||||
.lt(TaskFileJobEntity::getRetryCount, MAX_RETRY_COUNT)
|
||||
.in(TaskFileJobEntity::getModuleType, List.of("APPEARANCE_PATENT", "SIMILAR_ASIN", "PUBLISH", "SHOP_DATA_CRAWL"))
|
||||
.eq(TaskFileJobEntity::getOwner, normalizedOwner)
|
||||
@@ -248,7 +248,7 @@ public class TaskFileJobService {
|
||||
|
||||
List<TaskFileJobEntity> jobs = new ArrayList<>(ownerJobs);
|
||||
LambdaQueryWrapper<TaskFileJobEntity> genericWrapper = new LambdaQueryWrapper<TaskFileJobEntity>()
|
||||
.in(TaskFileJobEntity::getStatus, List.of("PENDING", "FAILED"))
|
||||
.in(TaskFileJobEntity::getStatus, com.nanri.aiimage.common.task.TaskStatuses.Job.RETRYABLE_ORDERED)
|
||||
.lt(TaskFileJobEntity::getRetryCount, MAX_RETRY_COUNT)
|
||||
.and(wrapper -> wrapper
|
||||
.notIn(TaskFileJobEntity::getModuleType, List.of("APPEARANCE_PATENT", "SIMILAR_ASIN", "PUBLISH", "SHOP_DATA_CRAWL"))
|
||||
@@ -521,7 +521,7 @@ public class TaskFileJobService {
|
||||
}
|
||||
return taskFileJobMapper.update(null, new LambdaUpdateWrapper<TaskFileJobEntity>()
|
||||
.eq(TaskFileJobEntity::getId, jobId)
|
||||
.in(TaskFileJobEntity::getStatus, List.of("PENDING", "FAILED"))
|
||||
.in(TaskFileJobEntity::getStatus, com.nanri.aiimage.common.task.TaskStatuses.Job.RETRYABLE_ORDERED)
|
||||
.and(wrapper -> wrapper.isNull(TaskFileJobEntity::getRetryCount)
|
||||
.or()
|
||||
.lt(TaskFileJobEntity::getRetryCount, MAX_RETRY_COUNT))
|
||||
@@ -831,7 +831,7 @@ public class TaskFileJobService {
|
||||
.eq(TaskFileJobEntity::getTaskId, taskId)
|
||||
.eq(TaskFileJobEntity::getModuleType, moduleType)
|
||||
.eq(TaskFileJobEntity::getJobType, JOB_TYPE_ASSEMBLE_RESULT)
|
||||
.in(TaskFileJobEntity::getStatus, List.of("PENDING", "RUNNING")));
|
||||
.in(TaskFileJobEntity::getStatus, com.nanri.aiimage.common.task.TaskStatuses.Job.ACTIVE_ORDERED));
|
||||
return count == null ? 0L : count;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -21,7 +21,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
@RequiredArgsConstructor
|
||||
public class TaskProgressSnapshotService {
|
||||
|
||||
private static final Set<String> TERMINAL_STATUSES = Set.of("SUCCESS", "FAILED", "CANCELLED", "CANCELED");
|
||||
private static final Set<String> TERMINAL_STATUSES =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.FileTask.TERMINAL;
|
||||
|
||||
private final TaskProgressSnapshotMapper taskProgressSnapshotMapper;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class TaskResultMissingInspector {
|
||||
|
||||
public MissingResultReport inspectTasksMissingResult(int limit) {
|
||||
List<FileTaskEntity> tasks = fileTaskMapper.selectList(new LambdaQueryWrapper<FileTaskEntity>()
|
||||
.in(FileTaskEntity::getStatus, List.of("SUCCESS", "FAILED"))
|
||||
.in(FileTaskEntity::getStatus, com.nanri.aiimage.common.task.TaskStatuses.FileTask.FINISHED_ORDERED)
|
||||
.orderByAsc(FileTaskEntity::getUpdatedAt)
|
||||
.last("limit " + Math.max(1, Math.min(limit, 500))));
|
||||
if (tasks == null || tasks.isEmpty()) {
|
||||
|
||||
+12
-10
@@ -39,17 +39,17 @@ public interface TaskCenterQueryMapper {
|
||||
+ "'SIMILAR_ASIN','COLLECT_DATA','SHOP_DATA_CRAWL'";
|
||||
|
||||
/**
|
||||
* 状态口径的单一来源。{@code @Select} 注解值必须是编译期常量,所以 SQL 里用下面
|
||||
* 的字符串字面量、Java 侧判卡住用这里的集合,两者由
|
||||
* {@code TaskCenterQueryMapperSqlTest.statusLiteralsStayInSyncWithSets} 守同步。
|
||||
* 状态口径的单一来源。{@code @Select} 注解值必须是编译期常量,所以 SQL 里的字符串字面量留在本接口,
|
||||
* Java 侧判卡住用的集合一律取自 {@link com.nanri.aiimage.common.task.TaskStatuses}(唯一词表),
|
||||
* 两边由 {@code TaskCenterQueryMapperSqlTest.statusLiteralsStayInSyncWithSets} 守同步。
|
||||
*/
|
||||
Set<String> ACTIVE_STATUS_SET = Set.of("PENDING", "RUNNING", "SCHEDULED");
|
||||
Set<String> ACTIVE_STATUS_SET = com.nanri.aiimage.common.task.TaskStatuses.FileTask.ACTIVE;
|
||||
|
||||
/**
|
||||
* {@link #ACTIVE_STATUS_SET} 的固定顺序版本:前端「在跑」筛选项就是这个集合的合并口径,
|
||||
* 展开成 IN 列表后 SQL 文本要可断言({@code Set} 的迭代顺序不保证,不能直接下 SQL)。
|
||||
*/
|
||||
List<String> ACTIVE_STATUSES_ORDERED = List.of("PENDING", "RUNNING", "SCHEDULED");
|
||||
List<String> ACTIVE_STATUSES_ORDERED = com.nanri.aiimage.common.task.TaskStatuses.FileTask.ACTIVE_ORDERED;
|
||||
|
||||
/** 状态筛选的合并哨兵值:它不是表里的状态,服务层负责展开成 {@link #ACTIVE_STATUSES_ORDERED}。 */
|
||||
String ACTIVE_STATUS_SENTINEL = "ACTIVE";
|
||||
@@ -58,19 +58,21 @@ public interface TaskCenterQueryMapper {
|
||||
* 前端「成功」筛选项的展开口径(2026-10-04 状态三态收敛:只留 执行中/成功/失败):
|
||||
* COMPLETED 是完成态的历史拼写,展示上已并入成功,筛选必须命中同样的行。
|
||||
*/
|
||||
List<String> SUCCESS_STATUSES_ORDERED = List.of("SUCCESS", "COMPLETED");
|
||||
List<String> SUCCESS_STATUSES_ORDERED =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.FileTask.SUCCESS_VIEW_ORDERED;
|
||||
|
||||
/** 前端「失败」筛选项的展开口径:ERROR 与取消/出错都按「没成功」并入失败(SQL 里 CANCELED 已归一为 CANCELLED)。 */
|
||||
List<String> FAILED_STATUSES_ORDERED = List.of("FAILED", "ERROR", "CANCELLED");
|
||||
List<String> FAILED_STATUSES_ORDERED =
|
||||
com.nanri.aiimage.common.task.TaskStatuses.FileTask.FAILED_VIEW_ORDERED;
|
||||
|
||||
/** biz_file_task 终态(CANCELLED 与历史脏值 CANCELED 并存)。 */
|
||||
Set<String> TERMINAL_STATUS_SET = Set.of("SUCCESS", "FAILED", "CANCELLED", "CANCELED");
|
||||
Set<String> TERMINAL_STATUS_SET = com.nanri.aiimage.common.task.TaskStatuses.FileTask.TERMINAL;
|
||||
|
||||
/** brand_crawl_tasks 进行中(该表状态小写)。 */
|
||||
Set<String> BRAND_ACTIVE_STATUS_SET = Set.of("pending", "running");
|
||||
Set<String> BRAND_ACTIVE_STATUS_SET = com.nanri.aiimage.common.task.TaskStatuses.BrandTask.ACTIVE;
|
||||
|
||||
/** brand_crawl_tasks 终态。 */
|
||||
Set<String> BRAND_TERMINAL_STATUS_SET = Set.of("success", "failed", "cancelled");
|
||||
Set<String> BRAND_TERMINAL_STATUS_SET = com.nanri.aiimage.common.task.TaskStatuses.BrandTask.TERMINAL;
|
||||
|
||||
/**
|
||||
* 逐行把「规范化后的店铺名」写进 {@code biz_file_result.source_filename} 的模块白名单
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.usersecret.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.config.UserSecretProperties;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.service.DataReadScope;
|
||||
@@ -55,8 +56,8 @@ public class AdminUserApiSecretController {
|
||||
@Parameter(description = "行级状态筛选:passed/failed/incomplete/error/unknown") @RequestParam(required = false) String checkStatus,
|
||||
@Parameter(description = "按数据权限分组筛选(仅超管生效)") @RequestParam(name = "group_id", required = false) Long groupId,
|
||||
@Parameter(description = "按公司筛选(仅超管生效;非超管一律按会话公司裁剪,越界公司为空页)") @RequestParam(name = "company_id", required = false) Long companyId,
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "15") Long pageSize) {
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = PageDefaults.FIRST_PAGE) Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = PageDefaults.USER_LIST_PAGE_SIZE) Long pageSize) {
|
||||
AdminUserEntity operator = adminAuthSupport.requireAdmin(request);
|
||||
AdminUserSecretQuery query = new AdminUserSecretQuery();
|
||||
query.setKeyword(keyword);
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.usersecret.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.service.DataReadScope;
|
||||
import com.nanri.aiimage.common.service.ReadScope;
|
||||
@@ -47,8 +48,8 @@ public class AdminUserSecretUsageController {
|
||||
@Parameter(description = "关键字:用户名") @RequestParam(required = false) String keyword,
|
||||
@Parameter(description = "按数据权限分组筛选(仅超管生效)") @RequestParam(name = "group_id", required = false) Long groupId,
|
||||
@Parameter(description = "按公司筛选(仅超管生效;非超管一律按会话公司裁剪,越界公司为空页)") @RequestParam(name = "company_id", required = false) Long companyId,
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "15") Long pageSize) {
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = PageDefaults.FIRST_PAGE) Long page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = PageDefaults.USER_LIST_PAGE_SIZE) Long pageSize) {
|
||||
AdminUserEntity operator = adminAuthSupport.requireAdmin(request);
|
||||
AdminUserSecretUsageQuery query = new AdminUserSecretUsageQuery();
|
||||
query.setStartDate(startDate);
|
||||
|
||||
+2
-1
@@ -91,7 +91,8 @@ public class WithdrawTaskService {
|
||||
validateUserId(userId);
|
||||
ProductRiskDashboardVo vo = new ProductRiskDashboardVo();
|
||||
vo.setCandidateCount(withdrawResolveService.countCandidates(userId));
|
||||
vo.setProcessedTaskCount(countTasks(userId, List.of("SUCCESS", "FAILED")));
|
||||
vo.setProcessedTaskCount(countTasks(userId,
|
||||
com.nanri.aiimage.common.task.TaskStatuses.FileTask.FINISHED_ORDERED));
|
||||
vo.setSuccessTaskCount(countTasks(userId, List.of("SUCCESS")));
|
||||
vo.setFailedTaskCount(countTasks(userId, List.of("FAILED")));
|
||||
return vo;
|
||||
|
||||
Reference in New Issue
Block a user