feat(公司tab): 接线 视频任务记录——company_id 走 DataReadScope,detail/zip 用同一把 ReadScope 门住
Task 8 的前半页(生成记录那半页 BLOCKED,见账本裁定)。 - controller 接住 requireAdminOrInternal 的返回值算范围,page 侧 readScope(operator, companyId) .userIdsOr(base):显式 user_id 与公司 tab 是交集,不是替换。 - mapper 的 userId 单值条件保留、并列 userIds IN <foreach>;null=不筛,空集在 service 首行早退, 绝不把 [] 交给 mapper(渲染成 IN () 是 500)。 - selectAdminZipRows 补 t.user_id:download-zip 的闸门要不越权就得先拿得到行主人。 - detail 的 404 文案拆开:404 只留给"真查不到行",越权是 403。zip 整单任一条越界 ⇒ 403, 不借 X-Archive-Error-Count 的"部分失败"语义盖越权。 - 前端 company_id 落在 builder 之后、发请求之前的唯一一处(normalizeHistoryParams 那类白名单 构造会把键静默丢掉);页面 watch(activeId) + 读 requestCompanyId。 验证(我自己复跑,不是转述):干净树定向 7/0(新 5 支 + G2 2 支)、全量前端 1726/1725/1 (G1 缺口清单 8 页→7 页,admin_image_video_tasks 已消失)、vue-tsc rc=0。
This commit is contained in:
@@ -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<ImageVideoRow[]>([])
|
||||
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()
|
||||
|
||||
@@ -12,10 +12,12 @@ export async function fetchImageVideoTasks(
|
||||
filter: ImageVideoFilter,
|
||||
page: number,
|
||||
pageSize: number,
|
||||
companyId?: number | null,
|
||||
): Promise<ImageVideoPageResult> {
|
||||
const { data } = await http.get<unknown>(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<unknown>(IMAGE_VIDEO_TASKS_ENDPOINT, { params: query })
|
||||
return parseImageVideoPage(data)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ export interface ImageVideoQuery {
|
||||
coze_execute_id?: string
|
||||
submitted_from?: string
|
||||
submitted_to?: string
|
||||
company_id?: number
|
||||
}
|
||||
|
||||
export function createImageVideoFilter(): ImageVideoFilter {
|
||||
|
||||
+24
-8
@@ -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<Long> base = userId != null && userId > 0 ? List.of(userId) : null;
|
||||
List<Long> 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<Map<String, Object>> 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<StreamingResponseBody> downloadZip(@RequestBody(required = false) Map<String, Object> body,
|
||||
HttpServletRequest request) {
|
||||
adminAuthSupport.requireAdminOrInternal(request);
|
||||
AdminUserEntity operator = adminAuthSupport.requireAdminOrInternal(request);
|
||||
List<VideoSelection> 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 的两个读出口(详情/打包下载)与列表同一把范围,判据都是行主人落不落得进同一批成员集。
|
||||
* <p>它们收不到 tab 的公司 id(tab 不是安全边界),所以 base 与 requestedCompanyId 都传 null:
|
||||
* 超管=不筛(返回 null),非超管/内部令牌=按会话裁剪到本公司成员。</p>
|
||||
*/
|
||||
private List<Long> 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);
|
||||
|
||||
+9
-1
@@ -35,6 +35,9 @@ public interface ImageVideoAdminTaskMapper {
|
||||
WHERE t.task_type = 'IMAGE_VIDEO_WORKFLOW'
|
||||
AND t.submitted_at >= DATE_SUB(NOW(), INTERVAL 3 DAY)
|
||||
<if test="userId != null"> AND t.user_id = #{userId}</if>
|
||||
<if test="userIds != null"> AND t.user_id IN
|
||||
<foreach collection="userIds" item="uid" open="(" separator="," close=")">#{uid}</foreach>
|
||||
</if>
|
||||
<if test="username != null and username != ''"> AND u.username LIKE CONCAT('%', #{username}, '%')</if>
|
||||
<if test="status != null and status != ''"> AND t.status = #{status}</if>
|
||||
<if test="executeId != null and executeId != ''"> AND t.coze_execute_id LIKE CONCAT('%', #{executeId}, '%')</if>
|
||||
@@ -46,6 +49,7 @@ public interface ImageVideoAdminTaskMapper {
|
||||
""")
|
||||
List<Map<String, Object>> selectAdminTaskPage(
|
||||
@Param("userId") Long userId,
|
||||
@Param("userIds") List<Long> 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)
|
||||
<if test="userId != null"> AND t.user_id = #{userId}</if>
|
||||
<if test="userIds != null"> AND t.user_id IN
|
||||
<foreach collection="userIds" item="uid" open="(" separator="," close=")">#{uid}</foreach>
|
||||
</if>
|
||||
<if test="username != null and username != ''"> AND u.username LIKE CONCAT('%', #{username}, '%')</if>
|
||||
<if test="status != null and status != ''"> AND t.status = #{status}</if>
|
||||
<if test="executeId != null and executeId != ''"> AND t.coze_execute_id LIKE CONCAT('%', #{executeId}, '%')</if>
|
||||
@@ -71,6 +78,7 @@ public interface ImageVideoAdminTaskMapper {
|
||||
""")
|
||||
Long countAdminTaskPage(
|
||||
@Param("userId") Long userId,
|
||||
@Param("userIds") List<Long> userIds,
|
||||
@Param("username") String username,
|
||||
@Param("status") String status,
|
||||
@Param("executeId") String executeId,
|
||||
@@ -79,7 +87,7 @@ public interface ImageVideoAdminTaskMapper {
|
||||
|
||||
@Select("""
|
||||
<script>
|
||||
SELECT t.id, t.video_urls_json, t.archived_videos_json
|
||||
SELECT t.id, t.user_id, t.video_urls_json, t.archived_videos_json
|
||||
FROM biz_image_video_async_task t
|
||||
WHERE t.task_type = 'IMAGE_VIDEO_WORKFLOW'
|
||||
AND t.submitted_at >= DATE_SUB(NOW(), INTERVAL 3 DAY)
|
||||
|
||||
+41
-6
@@ -70,15 +70,27 @@ public class ImageVideoAdminTaskService {
|
||||
|
||||
/**
|
||||
* 分页查询图生视频工作流任务,返回 {items, total, page, page_size}。
|
||||
*
|
||||
* <p>{@code userIds} 是 controller 经 {@code DataReadScope} 算好的公司成员集:
|
||||
* {@code null} = 不筛(超管没选公司,保持今天的行为),空集 = 这家公司没有成员账号。</p>
|
||||
*/
|
||||
public Map<String, Object> page(Long userId, String username, String status, String executeId,
|
||||
LocalDateTime submittedFrom, LocalDateTime submittedTo,
|
||||
int page, int pageSize) {
|
||||
int page, int pageSize, List<Long> userIds) {
|
||||
if (userIds != null && userIds.isEmpty()) {
|
||||
// 空集 = 这个公司今天没有任何成员账号 ⇒ 空页。绝不退化成"不筛"(那是越权)。
|
||||
Map<String, Object> empty = new LinkedHashMap<>();
|
||||
empty.put("items", List.of());
|
||||
empty.put("total", 0L);
|
||||
empty.put("page", (long) page);
|
||||
empty.put("page_size", (long) pageSize);
|
||||
return empty;
|
||||
}
|
||||
int offset = (page - 1) * pageSize;
|
||||
List<Map<String, Object>> rows = adminTaskMapper.selectAdminTaskPage(
|
||||
userId, username, status, executeId, submittedFrom, submittedTo, pageSize, offset);
|
||||
userId, userIds, username, status, executeId, submittedFrom, submittedTo, pageSize, offset);
|
||||
Long total = adminTaskMapper.countAdminTaskPage(
|
||||
userId, username, status, executeId, submittedFrom, submittedTo);
|
||||
userId, userIds, username, status, executeId, submittedFrom, submittedTo);
|
||||
List<Map<String, Object>> items = new ArrayList<>(rows.size());
|
||||
for (Map<String, Object> row : rows) {
|
||||
items.add(toListItem(row, false));
|
||||
@@ -93,19 +105,27 @@ public class ImageVideoAdminTaskService {
|
||||
|
||||
/**
|
||||
* 单任务详情(含 request/submit_response/result 原始 JSON,request 脱敏)。
|
||||
*
|
||||
* <p>闸门与列表同一把范围(spec §6.1「列表筛了、按 id 照读」= 越权):
|
||||
* {@code userIds} 非 null 而行主人不在里面 ⇒ 403;404 只留给真查不到行。</p>
|
||||
*/
|
||||
public Map<String, Object> detail(Long taskId) {
|
||||
public Map<String, Object> detail(Long taskId, List<Long> userIds) {
|
||||
Map<String, Object> row = adminTaskMapper.selectAdminTaskDetail(taskId);
|
||||
if (row == null) {
|
||||
throw new BusinessException(404, "视频任务不存在或无权访问");
|
||||
throw new BusinessException(404, "视频任务不存在");
|
||||
}
|
||||
assertRowInScope(row, userIds);
|
||||
return Map.of("item", toListItem(row, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量打包下载选中的视频。逐文件远程拉取写入 zip,部分失败时记录错误清单文件。
|
||||
*
|
||||
* <p>范围闸门在打包之前:一次请求里任一条越界就整单 403,绝不并进
|
||||
* {@code X-Archive-Error-Count} 的"部分失败"语义(那是给拉不到文件用的,
|
||||
* 拿它掩盖越权等于把越权报成网络问题)。</p>
|
||||
*/
|
||||
public ZipBundle buildZip(List<VideoSelection> selections) {
|
||||
public ZipBundle buildZip(List<VideoSelection> selections, List<Long> userIds) {
|
||||
List<Long> taskIds = selections.stream()
|
||||
.map(VideoSelection::taskId)
|
||||
.distinct()
|
||||
@@ -113,6 +133,7 @@ public class ImageVideoAdminTaskService {
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, Map<String, Object>> tasks = new HashMap<>();
|
||||
for (Map<String, Object> row : adminTaskMapper.selectAdminZipRows(taskIds)) {
|
||||
assertRowInScope(row, userIds);
|
||||
if (row.get("id") instanceof Number id) {
|
||||
tasks.put(id.longValue(), row);
|
||||
}
|
||||
@@ -187,6 +208,20 @@ public class ImageVideoAdminTaskService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 行主人落不落得进列表那条同样的成员集:{@code userIds == null} 才是"这一页不筛",
|
||||
* 空集与非 null 集合都按"落不进就 403"处理(读不出主人同样算越界,不放行)。
|
||||
*/
|
||||
private void assertRowInScope(Map<String, Object> row, List<Long> userIds) {
|
||||
if (userIds == null) {
|
||||
return;
|
||||
}
|
||||
Object ownerId = row.get("user_id");
|
||||
if (!(ownerId instanceof Number owner) || !userIds.contains(owner.longValue())) {
|
||||
throw new BusinessException(403, "该任务不属于当前公司");
|
||||
}
|
||||
}
|
||||
|
||||
private HttpURLConnection openRemoteConnection(String url) throws IOException {
|
||||
HttpURLConnection connection = (HttpURLConnection) URI.create(url).toURL().openConnection();
|
||||
connection.setConnectTimeout(HTTP_CONNECT_TIMEOUT_MILLIS);
|
||||
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
package com.nanri.aiimage.modules.imagevideo.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.modules.imagevideo.mapper.ImageVideoAdminTaskMapper;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* 公司 tab 的成员集合怎么进这条查询(Task 8)。
|
||||
*
|
||||
* <p>范围本身在 controller 里由 {@code DataReadScope} 算,service 只收算好的
|
||||
* {@code List<Long> userIds}:null = 不筛(超管没选公司,今天的行为),
|
||||
* 空集 = 这家公司今天没有成员账号(必须空页,绝不许退化成不筛)。</p>
|
||||
*/
|
||||
class ImageVideoAdminTaskServiceTest {
|
||||
|
||||
private final ImageVideoAdminTaskMapper mapper = mock(ImageVideoAdminTaskMapper.class);
|
||||
private final ImageVideoAdminTaskService service =
|
||||
new ImageVideoAdminTaskService(mapper, new ObjectMapper());
|
||||
|
||||
@Test
|
||||
@DisplayName("超管选了公司:userId 的单值过滤之外必须多出成员集合")
|
||||
@SuppressWarnings("unchecked")
|
||||
void companyMembersGoToBothPageAndCountQueries() {
|
||||
when(mapper.selectAdminTaskPage(any(), any(), any(), any(), any(), any(), any(), anyInt(), anyInt()))
|
||||
.thenReturn(List.of());
|
||||
when(mapper.countAdminTaskPage(any(), any(), any(), any(), any(), any(), any())).thenReturn(0L);
|
||||
|
||||
service.page(null, null, null, null, null, null, 1, 20, List.of(11L, 12L));
|
||||
|
||||
// 关键:行集与总数必须拿到同一个范围。只换 page 不换 count ⇒ "总数对不上但没人报错"。
|
||||
ArgumentCaptor<List<Long>> rowsCap = ArgumentCaptor.forClass((Class) List.class);
|
||||
ArgumentCaptor<List<Long>> cntCap = ArgumentCaptor.forClass((Class) List.class);
|
||||
verify(mapper).selectAdminTaskPage(any(), rowsCap.capture(), any(), any(), any(), any(), any(),
|
||||
anyInt(), anyInt());
|
||||
verify(mapper).countAdminTaskPage(any(), cntCap.capture(), any(), any(), any(), any(), any());
|
||||
assertThat(rowsCap.getValue()).containsExactlyInAnyOrder(11L, 12L);
|
||||
assertThat(cntCap.getValue()).containsExactlyInAnyOrder(11L, 12L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("不筛时传 null,不是空集——空集在 mapper 那里会渲染出 IN () 语法错")
|
||||
void unfilteredPassesNullNotEmptyList() {
|
||||
when(mapper.selectAdminTaskPage(any(), any(), any(), any(), any(), any(), any(), anyInt(), anyInt()))
|
||||
.thenReturn(List.of());
|
||||
|
||||
service.page(null, null, null, null, null, null, 1, 20, null);
|
||||
|
||||
verify(mapper).selectAdminTaskPage(any(), isNull(), any(), any(), any(), any(), any(),
|
||||
anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("成员集为空=空页,两支 mapper 一支都不许碰(退化成不筛就是越权)")
|
||||
void emptyMemberSetShortCircuitsWithoutTouchingMapper() {
|
||||
Map<String, Object> result = service.page(null, null, null, null, null, null, 3, 20, List.of());
|
||||
|
||||
assertThat(result)
|
||||
.containsEntry("items", List.of())
|
||||
.containsEntry("total", 0L)
|
||||
.containsEntry("page", 3L)
|
||||
.containsEntry("page_size", 20L);
|
||||
verify(mapper, never()).selectAdminTaskPage(any(), any(), any(), any(), any(), any(), any(),
|
||||
anyInt(), anyInt());
|
||||
verify(mapper, never()).countAdminTaskPage(any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("detail:行主人不在成员集里=403,真查不到行才是 404;不筛(null)时照旧放行")
|
||||
void detailGatesRowOwnerAndKeepsNotFoundForMissingRow() {
|
||||
when(mapper.selectAdminTaskDetail(7L)).thenReturn(videoRow(7L, 99L));
|
||||
when(mapper.selectAdminTaskDetail(8L)).thenReturn(null);
|
||||
|
||||
assertThatThrownBy(() -> service.detail(7L, List.of(11L, 12L)))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessage("该任务不属于当前公司")
|
||||
.extracting(e -> ((BusinessException) e).getCode())
|
||||
.isEqualTo(403);
|
||||
assertThatThrownBy(() -> service.detail(8L, List.of(11L)))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessage("视频任务不存在")
|
||||
.extracting(e -> ((BusinessException) e).getCode())
|
||||
.isEqualTo(404);
|
||||
|
||||
// 主人落在成员集里 ⇒ 读得到;集合为 null(超管没选公司)⇒ 同一条行也读得到。
|
||||
assertThat(service.detail(7L, List.of(99L)).get("item")).isNotNull();
|
||||
assertThat(service.detail(7L, null).get("item")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("download-zip:任一行越界整单 403,不许塞进 X-Archive-Error-Count 的部分失败")
|
||||
void zipRejectsWholeRequestWhenAnyRowIsOutOfScope() throws Exception {
|
||||
when(mapper.selectAdminZipRows(List.of(7L, 8L)))
|
||||
.thenReturn(List.of(videoRow(7L, 11L), videoRow(8L, 99L)));
|
||||
List<ImageVideoAdminTaskService.VideoSelection> selections =
|
||||
List.of(new ImageVideoAdminTaskService.VideoSelection(7L, 0),
|
||||
new ImageVideoAdminTaskService.VideoSelection(8L, 0));
|
||||
|
||||
assertThatThrownBy(() -> service.buildZip(selections, List.of(11L, 12L)))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessage("该任务不属于当前公司")
|
||||
.extracting(e -> ((BusinessException) e).getCode())
|
||||
.isEqualTo(403);
|
||||
|
||||
// 在范围内的行照旧走"打包"语义(这里没有可下载的视频 ⇒ 记一条错误,不是 403)。
|
||||
ImageVideoAdminTaskService.ZipBundle bundle =
|
||||
service.buildZip(List.of(new ImageVideoAdminTaskService.VideoSelection(7L, 0)), List.of(11L));
|
||||
java.nio.file.Files.deleteIfExists(bundle.file());
|
||||
assertThat(bundle.fileCount()).isZero();
|
||||
assertThat(bundle.errorCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
/** 一条最小可用的任务行:user_id 是闸门唯一的判据,video_urls_json 留空好让 zip 不碰网络。 */
|
||||
private Map<String, Object> videoRow(long taskId, Long ownerId) {
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("id", taskId);
|
||||
row.put("user_id", ownerId);
|
||||
row.put("video_urls_json", "[]");
|
||||
return row;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user