diff --git a/admin-frontend-vue/src/pages/tasks/ImageVideoTasksPage.vue b/admin-frontend-vue/src/pages/tasks/ImageVideoTasksPage.vue index 490d507ef..56ab5b46a 100644 --- a/admin-frontend-vue/src/pages/tasks/ImageVideoTasksPage.vue +++ b/admin-frontend-vue/src/pages/tasks/ImageVideoTasksPage.vue @@ -2,7 +2,7 @@ import { formatDateTime } from '@/utils/datetime' /** 视频任务记录页 · 像素复刻旧版 admin.html panel-image-video-tasks(自绘:form-box 筛选[用户名/提交起止+查询/重置] + panel-box toolbar[全选/批量下载/权限配置/汇总] + 任务卡片网格 + 旧式分页)。 * script 逻辑沿用现有 Vue 实现(批量打包/明细抽屉/权限授权)。 */ -import { computed, onMounted, reactive, ref } from 'vue' +import { computed, onMounted, reactive, ref, watch } from 'vue' import { ElMessage } from 'element-plus' import { requestVideoZipDownload, fetchImageVideoTasks, fetchImageVideoTaskDetail } from './image-video-api.ts' import { fetchImageVideoPermissionUsers, saveImageVideoPermissions } from './image-video-api.ts' @@ -18,9 +18,11 @@ import { import { grantedUserIds, type TaskPermissionItem } from './task-permission.ts' import { imageVideoDownloadFilename, videoKeysOf } from './image-video-view.ts' import { useAdminSessionStore } from '@/stores/admin-session' +import { useCompanyTabStore } from '@/stores/company-tab' import OldPagination from '@/components/OldPagination.vue' const session = useAdminSessionStore() +const companyTab = useCompanyTabStore() const loading = ref(false) const tasks = ref([]) const totalTasks = ref(0) @@ -114,7 +116,7 @@ function toFilter(): ImageVideoFilter { async function load() { loading.value = true try { - const result = await fetchImageVideoTasks(toFilter(), page.value, pageSize.value) + const result = await fetchImageVideoTasks(toFilter(), page.value, pageSize.value, companyTab.requestCompanyId) tasks.value = result.items totalTasks.value = result.total page.value = result.page @@ -125,6 +127,9 @@ async function load() { } } +// 切公司 = 重新取数。不重取的页 = tab 在那页上是假的(G1 的 pageFiles 断言盯着这条)。 +watch(() => companyTab.activeId, () => void load()) + function apply() { page.value = 1 void load() diff --git a/admin-frontend-vue/src/pages/tasks/image-video-api.ts b/admin-frontend-vue/src/pages/tasks/image-video-api.ts index 3914fdc7c..86f25cd05 100644 --- a/admin-frontend-vue/src/pages/tasks/image-video-api.ts +++ b/admin-frontend-vue/src/pages/tasks/image-video-api.ts @@ -12,10 +12,12 @@ export async function fetchImageVideoTasks( filter: ImageVideoFilter, page: number, pageSize: number, + companyId?: number | null, ): Promise { - const { data } = await http.get(IMAGE_VIDEO_TASKS_ENDPOINT, { - params: toImageVideoQuery(filter, page, pageSize), - }) + // 公司 tab 的值由页面传进来,落在 builder 之后(filter 里塞不进:toImageVideoQuery 是白名单构造)。 + const query = toImageVideoQuery(filter, page, pageSize) + if (companyId != null) query.company_id = companyId + const { data } = await http.get(IMAGE_VIDEO_TASKS_ENDPOINT, { params: query }) return parseImageVideoPage(data) } diff --git a/admin-frontend-vue/src/pages/tasks/image-video-filter.ts b/admin-frontend-vue/src/pages/tasks/image-video-filter.ts index 57fd551e9..2d068381d 100644 --- a/admin-frontend-vue/src/pages/tasks/image-video-filter.ts +++ b/admin-frontend-vue/src/pages/tasks/image-video-filter.ts @@ -27,6 +27,7 @@ export interface ImageVideoQuery { coze_execute_id?: string submitted_from?: string submitted_to?: string + company_id?: number } export function createImageVideoFilter(): ImageVideoFilter { diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/imagevideo/controller/AdminImageVideoTaskController.java b/backend-java/src/main/java/com/nanri/aiimage/modules/imagevideo/controller/AdminImageVideoTaskController.java index 30f603309..1b41dc64b 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/imagevideo/controller/AdminImageVideoTaskController.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/imagevideo/controller/AdminImageVideoTaskController.java @@ -2,6 +2,8 @@ package com.nanri.aiimage.modules.imagevideo.controller; import com.nanri.aiimage.common.api.ApiResponse; import com.nanri.aiimage.common.exception.BusinessException; +import com.nanri.aiimage.common.model.entity.AdminUserEntity; +import com.nanri.aiimage.common.service.DataReadScope; import com.nanri.aiimage.common.util.DownloadHeaderUtil; import com.nanri.aiimage.common.security.AdminAuthSupport; import com.nanri.aiimage.modules.imagevideo.service.ImageVideoAdminTaskService; @@ -63,6 +65,7 @@ public class AdminImageVideoTaskController { private final ImageVideoAdminTaskService adminTaskService; private final AdminAuthSupport adminAuthSupport; + private final DataReadScope dataReadScope; @GetMapping @Operation(summary = "分页查询图生视频任务", description = "管理端按用户/任务状态/提交时间等条件分页查询近 3 天的工作流任务") @@ -75,8 +78,12 @@ public class AdminImageVideoTaskController { @RequestParam(name = "coze_execute_id", required = false) String executeId, @RequestParam(name = "submitted_from", required = false) String submittedFrom, @RequestParam(name = "submitted_to", required = false) String submittedTo, + @RequestParam(name = "company_id", required = false) Long companyId, HttpServletRequest request) { - adminAuthSupport.requireAdminOrInternal(request); + AdminUserEntity operator = adminAuthSupport.requireAdminOrInternal(request); + // 既有语义保留:显式传 user_id 时按那一个人筛;公司 tab 叠在它上面(交集)。 + List base = userId != null && userId > 0 ? List.of(userId) : null; + List scoped = dataReadScope.readScope(operator, companyId).userIdsOr(base); int safePage = Math.max(1, page == null ? 1 : page); int safePageSize = Math.min(100, Math.max(10, pageSize == null ? 20 : pageSize)); String cleanUsername = username == null ? null : username.trim(); @@ -84,26 +91,26 @@ public class AdminImageVideoTaskController { String cleanExecuteId = executeId == null ? null : executeId.trim(); LocalDateTime from = parseAdminDatetimeParam("submitted_from", submittedFrom); LocalDateTime to = parseAdminDatetimeParam("submitted_to", submittedTo); - log.info("[image-video] 管理端查询图生视频任务 page={} pageSize={} userId={} username={} status={}", - safePage, safePageSize, userId, cleanUsername, cleanStatus); + log.info("[image-video] 管理端查询图生视频任务 page={} pageSize={} userId={} username={} status={} " + + "companyId={}", safePage, safePageSize, userId, cleanUsername, cleanStatus, companyId); return ApiResponse.success(adminTaskService.page(userId, cleanUsername, cleanStatus, - cleanExecuteId, from, to, safePage, safePageSize)); + cleanExecuteId, from, to, safePage, safePageSize, scoped)); } @GetMapping("/{taskId}") @Operation(summary = "查询图生视频任务详情", description = "返回单个任务详情(含脱敏后的请求参数与结果 JSON)") public ApiResponse> detail(@PathVariable Long taskId, HttpServletRequest request) { - adminAuthSupport.requireAdminOrInternal(request); - return ApiResponse.success(adminTaskService.detail(taskId)); + AdminUserEntity operator = adminAuthSupport.requireAdminOrInternal(request); + return ApiResponse.success(adminTaskService.detail(taskId, scopeOf(operator))); } @PostMapping("/download-zip") @Operation(summary = "批量打包下载视频", description = "按任务+视频下标批量打包 zip;部分失败通过响应头 X-Archive-Error-Count 提示") public ResponseEntity downloadZip(@RequestBody(required = false) Map body, HttpServletRequest request) { - adminAuthSupport.requireAdminOrInternal(request); + AdminUserEntity operator = adminAuthSupport.requireAdminOrInternal(request); List selections = parseSelections(body); - ZipBundle bundle = adminTaskService.buildZip(selections); + ZipBundle bundle = adminTaskService.buildZip(selections, scopeOf(operator)); String filename = "video-tasks-" + LocalDateTime.now().format(ZIP_FILENAME_FORMATTER) + ".zip"; StreamingResponseBody stream = outputStream -> writeZipFile(bundle.file(), outputStream); return ResponseEntity.ok() @@ -114,6 +121,15 @@ public class AdminImageVideoTaskController { .body(stream); } + /** + * 按 id 的两个读出口(详情/打包下载)与列表同一把范围,判据都是行主人落不落得进同一批成员集。 + *

它们收不到 tab 的公司 id(tab 不是安全边界),所以 base 与 requestedCompanyId 都传 null: + * 超管=不筛(返回 null),非超管/内部令牌=按会话裁剪到本公司成员。

+ */ + private List scopeOf(AdminUserEntity operator) { + return dataReadScope.readScope(operator, null).userIdsOr(null); + } + private void writeZipFile(Path file, OutputStream output) throws IOException { try (InputStream input = Files.newInputStream(file)) { input.transferTo(output); diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/imagevideo/mapper/ImageVideoAdminTaskMapper.java b/backend-java/src/main/java/com/nanri/aiimage/modules/imagevideo/mapper/ImageVideoAdminTaskMapper.java index 5802b5e4a..dfed47217 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/imagevideo/mapper/ImageVideoAdminTaskMapper.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/imagevideo/mapper/ImageVideoAdminTaskMapper.java @@ -35,6 +35,9 @@ public interface ImageVideoAdminTaskMapper { WHERE t.task_type = 'IMAGE_VIDEO_WORKFLOW' AND t.submitted_at >= DATE_SUB(NOW(), INTERVAL 3 DAY) AND t.user_id = #{userId} + AND t.user_id IN + #{uid} + AND u.username LIKE CONCAT('%', #{username}, '%') AND t.status = #{status} AND t.coze_execute_id LIKE CONCAT('%', #{executeId}, '%') @@ -46,6 +49,7 @@ public interface ImageVideoAdminTaskMapper { """) List> selectAdminTaskPage( @Param("userId") Long userId, + @Param("userIds") List userIds, @Param("username") String username, @Param("status") String status, @Param("executeId") String executeId, @@ -62,6 +66,9 @@ public interface ImageVideoAdminTaskMapper { WHERE t.task_type = 'IMAGE_VIDEO_WORKFLOW' AND t.submitted_at >= DATE_SUB(NOW(), INTERVAL 3 DAY) AND t.user_id = #{userId} + AND t.user_id IN + #{uid} + AND u.username LIKE CONCAT('%', #{username}, '%') AND t.status = #{status} AND t.coze_execute_id LIKE CONCAT('%', #{executeId}, '%') @@ -71,6 +78,7 @@ public interface ImageVideoAdminTaskMapper { """) Long countAdminTaskPage( @Param("userId") Long userId, + @Param("userIds") List userIds, @Param("username") String username, @Param("status") String status, @Param("executeId") String executeId, @@ -79,7 +87,7 @@ public interface ImageVideoAdminTaskMapper { @Select("""