task-116: 后台管理新增/导入表单弹窗化 + 分组管理独立菜单与UI优化 + 轻量进度端点
- 后台管理页(admin)所有面板的新增/导入表单改为弹窗操作,原有字段 ID 全部保留、提交逻辑不变;导入删除入口不再触发二次确认拦截 - 分组管理升级为独立菜单(V102 + schema initializer),移除 5 个面板内的管理分组按钮;分组列表改为蓝白主题、增加权限分组横幅 - Python 侧 group-manage 权限守卫(_ensure_backend_menu_access 补充 group-manage) - 引入 V101(biz_task_file_job 复合索引)+ 新增 TaskProgressLight/TaskFileJob 轻量端点与进度聚合作 - 前端 progress-light / page-separated-loads / dispatch-guard 共享模块及单元测试
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
package com.nanri.aiimage.modules.task.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 共享轻量进度查询请求(各模块 progress/light 端点共用)。
|
||||
* 最多处理 200 个任务 ID,超长部分截断丢弃(轮询端点保持响应快)。
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "任务轻量进度查询请求")
|
||||
public class TaskProgressLightRequest {
|
||||
@NotNull
|
||||
@Schema(description = "需要查询进度的任务 ID 列表。前端只传正在轮询的活跃任务;后端批量查询,最多 200 个。",
|
||||
example = "[3938,3939]", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private List<Long> taskIds = new ArrayList<>();
|
||||
@Schema(description = "当前用户 ID(可省略;传入时仅返回该用户的任务,owner-scoped 模块使用)。", example = "1")
|
||||
private Long userId;
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.nanri.aiimage.modules.task.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 共享轻量进度批量响应:items 按请求顺序返回,查不到的任务进 missingTaskIds。
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "任务轻量进度批量响应")
|
||||
public class TaskProgressLightBatchVo {
|
||||
@Schema(description = "按请求顺序返回的轻量进度项。")
|
||||
private List<TaskProgressLightVo> items = new ArrayList<>();
|
||||
@Schema(description = "查询不到的任务 ID 列表。")
|
||||
private List<Long> missingTaskIds = new ArrayList<>();
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.nanri.aiimage.modules.task.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 共享轻量进度项(11 模块 progress/light 轮询专用)。
|
||||
* 白名单键与 similarasin 的 SimilarAsinTaskLightVo 保持一致:
|
||||
* taskId/status/statusCode?/fileStatus?/fileError?/fileReady?/updatedAt。
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "任务轻量进度项(前端轮询专用,不含明细/result 内容)")
|
||||
public class TaskProgressLightVo {
|
||||
@Schema(description = "任务 ID。", example = "3938")
|
||||
private Long taskId;
|
||||
@Schema(description = "任务状态:PENDING=已解析待推送,RUNNING=执行中,SUCCESS=成功,FAILED=失败。", example = "RUNNING")
|
||||
private String status;
|
||||
@Schema(description = "业务状态码(预留字段,当前恒为 null)。", example = "null")
|
||||
private String statusCode;
|
||||
@Schema(description = "结果文件组装 Job 状态:SUCCESS/RUNNING/FAILED;无 Job 时为空。", example = "SUCCESS")
|
||||
private String fileStatus;
|
||||
@Schema(description = "文件组装失败时的错误信息;无错误时为空。", example = "组装失败: 文件写入超时")
|
||||
private String fileError;
|
||||
@Schema(description = "结果文件是否已就绪。", example = "true")
|
||||
private Boolean fileReady;
|
||||
@Schema(description = "最后更新时间,ISO 本地时间字符串。", example = "2026-04-26T10:05:00")
|
||||
private String updatedAt;
|
||||
}
|
||||
+22
@@ -531,6 +531,28 @@ public class TaskFileJobService {
|
||||
return jobMap;
|
||||
}
|
||||
|
||||
/** 按任务 ID 集合一次 IN 查询 ASSEMBLE_RESULT Job,返回 taskId→Job 的 Map(轻量进度接口用)。 */
|
||||
public Map<Long, TaskFileJobEntity> findAssembleJobsByTaskIds(String moduleType, List<Long> taskIds) {
|
||||
List<Long> normalizedIds = taskIds == null ? List.of() : taskIds.stream()
|
||||
.filter(id -> id != null && id > 0)
|
||||
.distinct()
|
||||
.toList();
|
||||
if (normalizedIds.isEmpty() || moduleType == null || moduleType.isBlank()) {
|
||||
return Map.of();
|
||||
}
|
||||
List<TaskFileJobEntity> jobs = taskFileJobMapper.selectList(new LambdaQueryWrapper<TaskFileJobEntity>()
|
||||
.eq(TaskFileJobEntity::getModuleType, moduleType)
|
||||
.eq(TaskFileJobEntity::getJobType, JOB_TYPE_ASSEMBLE_RESULT)
|
||||
.in(TaskFileJobEntity::getTaskId, normalizedIds));
|
||||
Map<Long, TaskFileJobEntity> jobMap = new LinkedHashMap<>();
|
||||
for (TaskFileJobEntity job : jobs) {
|
||||
if (job != null && job.getTaskId() != null) {
|
||||
jobMap.putIfAbsent(job.getTaskId(), job);
|
||||
}
|
||||
}
|
||||
return jobMap;
|
||||
}
|
||||
|
||||
public long countUnfinishedAssembleJobs(Long taskId, String moduleType) {
|
||||
if (taskId == null || taskId <= 0 || moduleType == null || moduleType.isBlank()) {
|
||||
return 0L;
|
||||
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package com.nanri.aiimage.modules.task.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileTaskMapper;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskFileJobEntity;
|
||||
import com.nanri.aiimage.modules.task.model.vo.TaskProgressLightBatchVo;
|
||||
import com.nanri.aiimage.modules.task.model.vo.TaskProgressLightVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 共享轻量进度装配器:11 模块 progress/light 统一实现。
|
||||
* 语义与 similarasin 的 progressLight 一致——只查任务行 + 一次 ASSEMBLE Job IN 批量查询;
|
||||
* 空/重复/非正数过滤;超过 MAX_TASK_IDS 截断丢弃;缺失任务进 missingTaskIds;
|
||||
* fileStatus/fileError/fileReady 由 Job 推导;状态值语义与各模块 progress/batch 一致。
|
||||
* userId 非空时按用户过滤(publish 等 owner-scoped 模块使用)。
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class TaskProgressLightAssembler {
|
||||
|
||||
public static final int MAX_TASK_IDS = 200;
|
||||
|
||||
private final FileTaskMapper fileTaskMapper;
|
||||
private final TaskFileJobService taskFileJobService;
|
||||
|
||||
public TaskProgressLightBatchVo assemble(String moduleType, Long userId, List<Long> taskIds) {
|
||||
TaskProgressLightBatchVo vo = new TaskProgressLightBatchVo();
|
||||
List<Long> normalizedIds = taskIds == null ? List.of() : taskIds.stream()
|
||||
.filter(id -> id != null && id > 0)
|
||||
.distinct()
|
||||
.limit(MAX_TASK_IDS)
|
||||
.toList();
|
||||
if (normalizedIds.isEmpty()) {
|
||||
return vo;
|
||||
}
|
||||
LambdaQueryWrapper<FileTaskEntity> query = new LambdaQueryWrapper<FileTaskEntity>()
|
||||
.select(FileTaskEntity::getId,
|
||||
FileTaskEntity::getStatus,
|
||||
FileTaskEntity::getUpdatedAt)
|
||||
.in(FileTaskEntity::getId, normalizedIds);
|
||||
if (userId != null) {
|
||||
query.eq(FileTaskEntity::getUserId, userId);
|
||||
}
|
||||
Map<Long, FileTaskEntity> taskMap = new LinkedHashMap<>();
|
||||
for (FileTaskEntity task : fileTaskMapper.selectList(query)) {
|
||||
if (task != null && moduleType.equals(task.getModuleType())) {
|
||||
taskMap.put(task.getId(), task);
|
||||
}
|
||||
}
|
||||
Map<Long, TaskFileJobEntity> jobMap = taskFileJobService.findAssembleJobsByTaskIds(moduleType, new ArrayList<>(taskMap.keySet()));
|
||||
for (Long taskId : normalizedIds) {
|
||||
FileTaskEntity task = taskMap.get(taskId);
|
||||
if (task == null) {
|
||||
vo.getMissingTaskIds().add(taskId);
|
||||
continue;
|
||||
}
|
||||
TaskFileJobEntity job = jobMap.get(taskId);
|
||||
TaskProgressLightVo item = new TaskProgressLightVo();
|
||||
item.setTaskId(task.getId());
|
||||
item.setStatus(task.getStatus());
|
||||
item.setFileReady(job != null && job.getResultFileUrl() != null && !job.getResultFileUrl().isBlank());
|
||||
item.setFileStatus(job == null ? null : job.getStatus());
|
||||
item.setFileError(job == null ? null : job.getErrorMessage());
|
||||
item.setUpdatedAt(task.getUpdatedAt() == null ? null : task.getUpdatedAt().toString());
|
||||
vo.getItems().add(item);
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user