fix: 全维度审查修复(安全/正确性/性能/稳定性/客户端/前端)
安全 - /api/ziniao/** 五个匿名接口加管理员鉴权(此前可匿名换取任意员工店铺登录令牌) - 删除 Flask 遗留后门:默认密码建超管 + 每次启动写生产 users 表(服务端与客户端各一份) - 进度/详情接口归属过滤:新增 TaskProgressOwnershipSupport,11 模块 progress/light 与 /tasks/batch 接入,DTO 补 userId,前端 13 个查询封装补传(未传时后端不过滤,兼容旧端) - 代理提取链接(含账密)不再明文入日志(新增 common/util/SecretMasking) - 全局异常兜底不再回传原始异常信息;内部令牌比较改常量时间 - 登录加失败计数与锁定(10 次锁 15 分钟);品牌源文件下载加 SSRF 防护 - AdminApiGuardFilter 覆盖前缀从 2 扩到 15(开关默认 false,行为不变,为收紧做准备) - 生产关闭 springdoc/knife4j(/doc.html 匿名可读全部接口定义) 正确性 - 40901/40902 拆分:锁竞争不再被伪装成 success=true(此前客户端停止重试、分片静默丢失) - 假成功收敛:集采明细批量写失败改为抛出、去重 worker 异常标失败、4 个 worker 改判 success 字段、publish 空 ASIN 行参与批次 flush、巡店删除全失败带 error 上报 - 客户端心跳 discard 移入 finally(7 模块,失败路径不再留僵尸 RUNNING 任务) - 状态机条件更新:跟价停止循环、集采 activate/fail、imagevideo 归档回填、店铺匹配提交 性能 - 前端入口包 JS 1.05MB→204KB、CSS 355KB→10.7KB(Element Plus 改按需 + el-config-provider) - 载荷引用计数按指针里的 taskId 收敛(原 JSON 列 IN 全表扫且逐行调用) - 店铺明细多值批量 INSERT;快照 upsert 预载缓存;结果文件列改单条 UPDATE - 新增迁移 V120(补 3 个缺失索引)/V121(删 4 个被覆盖的冗余索引)/V122(URL 前缀索引) 稳定性 - 新增 common/util/ThreadPools 有界线程池替换 5 处无界队列(防堆积 OOM) - Redis 锁释放改 Lua 原子校验(原裸 delete 会误删他人已过期的锁) - imagevideo 加死节点接管;锁续期失败重试;调度池 4→16;openStream 全部加超时 - 事务内远程对象删除移到提交后;启动恢复锁按实例命名 客户端 - 不再 taskkill /f /im chrome.exe(改为按调试端口精准回收,不杀用户自己的浏览器) - 密码检测不再无条件杀紫鸟进程;品牌检测加全局互斥(代理池不再互相覆盖) - base_dir 统一到 exe 目录(原被 os.getcwd() 覆盖,日志/缓存会分裂两个目录) - 缓存加定时清理;图片下载加超时;mkstemp 句柄托管 测试 - 同步更新受影响的契约测试(构造器签名/条件更新/方法改名/新增接口方法等) - 修复 FaultInjectionTest 等 3 处 mock 未 stub 流式 read 导致的读循环 OOM - mvn test 2795 个测试全绿
This commit is contained in:
+10
-3
@@ -52,6 +52,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import com.nanri.aiimage.modules.task.model.dto.TaskProgressLightRequest;
|
||||
import com.nanri.aiimage.modules.task.model.vo.TaskProgressLightBatchVo;
|
||||
import com.nanri.aiimage.modules.task.service.TaskProgressOwnershipSupport;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -65,6 +66,7 @@ public class PriceTrackController {
|
||||
|
||||
private final PriceTrackService priceTrackService;
|
||||
private final PriceTrackTaskService priceTrackTaskService;
|
||||
private final TaskProgressOwnershipSupport progressOwnershipSupport;
|
||||
private final PriceTrackLoopRunService priceTrackLoopRunService;
|
||||
private final SkipPriceAsinService skipPriceAsinService;
|
||||
|
||||
@@ -259,13 +261,17 @@ public class PriceTrackController {
|
||||
@PostMapping("/tasks/batch")
|
||||
@Operation(summary = "批量查询任务详情", description = "按 taskIds 返回任务概要和各店铺结果,供前端查询使用。")
|
||||
public ApiResponse<PriceTrackTaskBatchVo> tasksBatch(@Valid @RequestBody PriceTrackTaskBatchRequest request) {
|
||||
return ApiResponse.success(priceTrackTaskService.getTaskDetailsBatch(request.getTaskIds()));
|
||||
// 归属过滤:/tasks/batch 同样按 userId 过滤(此前无校验,遍历 taskId 即可读他人任务详情)
|
||||
return ApiResponse.success(priceTrackTaskService.getTaskDetailsBatch(progressOwnershipSupport
|
||||
.filterOwnedTaskIds(request.getTaskIds(), request.getUserId())));
|
||||
}
|
||||
|
||||
@PostMapping("/tasks/progress/batch")
|
||||
@Operation(summary = "批量查询任务进度摘要", description = "仅返回任务状态、时间和错误等轻量信息,供前端轮询降载。")
|
||||
public ApiResponse<PriceTrackTaskBatchVo> taskProgressBatch(@Valid @RequestBody PriceTrackTaskBatchRequest request) {
|
||||
return ApiResponse.success(priceTrackTaskService.getTaskProgressBatch(request.getTaskIds()));
|
||||
// 归属过滤:只查询属于该用户的任务(userId 未传时保持原行为,兼容未升级调用方)
|
||||
return ApiResponse.success(priceTrackTaskService.getTaskProgressBatch(progressOwnershipSupport
|
||||
.filterOwnedTaskIds(request.getTaskIds(), request.getUserId())));
|
||||
}
|
||||
|
||||
@PostMapping("/tasks/progress/light")
|
||||
@@ -273,7 +279,8 @@ public class PriceTrackController {
|
||||
description = "与 progress/batch 同输入,只返回轻量字段(taskId/status/statusCode/fileStatus/fileError/fileReady/updatedAt),"
|
||||
+ "不查明细/result 行,响应体更小;旧 progress/batch 端点保留不动。")
|
||||
public ApiResponse<TaskProgressLightBatchVo> progressLight(@Valid @RequestBody TaskProgressLightRequest request) {
|
||||
return ApiResponse.success(priceTrackTaskService.progressLight(request.getTaskIds()));
|
||||
// 透传 userId:此前传 null = 不过滤归属,匿名遍历 taskId 即可读他人任务状态(2026-09 审查)
|
||||
return ApiResponse.success(priceTrackTaskService.progressLight(request.getTaskIds(), request.getUserId()));
|
||||
}
|
||||
|
||||
@PostMapping("/tasks/{taskId}/result")
|
||||
|
||||
+4
@@ -13,4 +13,8 @@ public class PriceTrackTaskBatchRequest {
|
||||
@NotEmpty(message = "taskIds不能为空")
|
||||
@Schema(description = "待查询的任务主键列表,无效或非本模块 taskId 会出现在 missingTaskIds", requiredMode = Schema.RequiredMode.REQUIRED, example = "[200,201]")
|
||||
private List<Long> taskIds = new ArrayList<>();
|
||||
|
||||
/** 当前用户 ID(可省略;传入时仅返回该用户的任务,用于进度接口归属过滤)。 */
|
||||
@Schema(description = "当前用户 ID(可省略;传入时仅返回该用户的任务)", example = "1")
|
||||
private Long userId;
|
||||
}
|
||||
|
||||
+15
-2
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.pricetrack.service;
|
||||
|
||||
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.exception.BusinessException;
|
||||
@@ -149,7 +150,13 @@ public class PriceTrackLoopRunService {
|
||||
if (entity.getActiveTaskId() == null || isChildTaskTerminal(entity.getActiveTaskId())) {
|
||||
markStopped(entity, null);
|
||||
} else {
|
||||
loopRunMapper.updateById(entity);
|
||||
// 只更新 stop_requested 字段:整行 updateById 会用读取快照覆盖并发写入的字段——
|
||||
// 用户点「停止循环」的瞬间子任务刚好完成时,handleChildFinished 写入的状态
|
||||
// 会被这里的旧快照覆盖回去,INFINITE 循环继续跑并继续产生真实任务
|
||||
loopRunMapper.update(null, new LambdaUpdateWrapper<PriceTrackLoopRunEntity>()
|
||||
.eq(PriceTrackLoopRunEntity::getId, entity.getId())
|
||||
.set(PriceTrackLoopRunEntity::getStopRequested, true)
|
||||
.set(PriceTrackLoopRunEntity::getUpdatedAt, LocalDateTime.now()));
|
||||
}
|
||||
return toVo(entity);
|
||||
}
|
||||
@@ -174,7 +181,13 @@ public class PriceTrackLoopRunService {
|
||||
}
|
||||
entity.setActiveTaskId(childTaskId);
|
||||
entity.setUpdatedAt(LocalDateTime.now());
|
||||
loopRunMapper.updateById(entity);
|
||||
// 字段级更新 + status CAS:整行 updateById 会覆盖并发写入的 stop_requested,
|
||||
// 导致「停止循环」请求被静默丢弃
|
||||
loopRunMapper.update(null, new LambdaUpdateWrapper<PriceTrackLoopRunEntity>()
|
||||
.eq(PriceTrackLoopRunEntity::getId, entity.getId())
|
||||
.eq(PriceTrackLoopRunEntity::getStatus, entity.getStatus())
|
||||
.set(PriceTrackLoopRunEntity::getActiveTaskId, childTaskId)
|
||||
.set(PriceTrackLoopRunEntity::getUpdatedAt, LocalDateTime.now()));
|
||||
log.info("[price-track-loop] child bound loopRunId={} childTaskId={} roundIndex={} shopIndex={}",
|
||||
loopRunId, childTaskId, roundIndex, shopIndex);
|
||||
}
|
||||
|
||||
+17
-3
@@ -3,6 +3,7 @@ package com.nanri.aiimage.modules.pricetrack.service;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nanri.aiimage.common.exception.BusinessCodes;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.util.ExcelStreamReader;
|
||||
import com.nanri.aiimage.config.TaskPressureProperties;
|
||||
@@ -64,9 +65,11 @@ import com.nanri.aiimage.modules.task.service.TaskProgressLightAssembler;
|
||||
public class PriceTrackTaskService {
|
||||
|
||||
private static final String MODULE_TYPE = "PRICE_TRACK";
|
||||
/** 批量进度查询的任务 id 上限(轮询端点防滥用,与 patroldelete/deletebrand 保持一致)。 */
|
||||
private static final int MAX_PROGRESS_TASK_IDS = 50;
|
||||
|
||||
public TaskProgressLightBatchVo progressLight(List<Long> taskIds) {
|
||||
return taskProgressLightAssembler.assemble(MODULE_TYPE, null, taskIds);
|
||||
public TaskProgressLightBatchVo progressLight(List<Long> taskIds, Long userId) {
|
||||
return taskProgressLightAssembler.assemble(MODULE_TYPE, userId, taskIds);
|
||||
}
|
||||
private static final String CONTENT_TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||
private static final String ASIN_ROWS_PAYLOAD_SCOPE = "price-track-asin-rows";
|
||||
@@ -386,6 +389,16 @@ public class PriceTrackTaskService {
|
||||
if (taskIds == null || taskIds.isEmpty()) {
|
||||
return batch;
|
||||
}
|
||||
// 上限 50:轮询端点不限制数量时,调用方传数万 id 会引发单请求内数万次串行 SQL,
|
||||
// 拖慢共享连接池并波及其它实例请求(对齐 patroldelete / deletebrand 的口径)
|
||||
taskIds = taskIds.stream()
|
||||
.filter(taskId -> taskId != null && taskId > 0)
|
||||
.distinct()
|
||||
.limit(MAX_PROGRESS_TASK_IDS)
|
||||
.toList();
|
||||
if (taskIds.isEmpty()) {
|
||||
return batch;
|
||||
}
|
||||
Map<Long, FileTaskEntity> taskMap = loadTaskProgressMapByIds(taskIds);
|
||||
for (Long taskId : taskIds) {
|
||||
if (taskId == null || taskId <= 0) {
|
||||
@@ -2167,7 +2180,8 @@ public class PriceTrackTaskService {
|
||||
private TaskDistributedLockService.LockHandle acquireTaskLockOrThrow(Long taskId) {
|
||||
TaskDistributedLockService.LockHandle lockHandle = acquireTaskLock(taskId);
|
||||
if (lockHandle == null) {
|
||||
throw new BusinessException(40901, "任务正在处理中,请稍后再试");
|
||||
log.warn("[price-track] 任务锁竞争,拒绝本次提交 taskId={}", taskId);
|
||||
throw new BusinessException(BusinessCodes.TASK_BUSY, "任务正在处理中,请稍后再试");
|
||||
}
|
||||
return lockHandle;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user