feat(公司tab): 任务看板五个端点按公司筛(一处 resolve 收窄,detail 靠 scope.visible 同宽)
This commit is contained in:
+75
-12
@@ -3,6 +3,7 @@ package com.nanri.aiimage.modules.taskcenter.controller;
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.service.DataReadScope;
|
||||
import com.nanri.aiimage.modules.permission.service.PermissionMenuService;
|
||||
import com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterTaskQuery;
|
||||
import com.nanri.aiimage.modules.taskcenter.model.vo.TaskCenterOverviewVo;
|
||||
@@ -13,6 +14,7 @@ import com.nanri.aiimage.modules.taskcenter.service.TaskCenterQueryService;
|
||||
import com.nanri.aiimage.modules.taskcenter.service.TaskCenterScopeService;
|
||||
import com.nanri.aiimage.modules.taskcenter.service.TaskCenterVariantService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -29,6 +31,13 @@ import java.util.List;
|
||||
*
|
||||
* <p>仅超管默认可见;管理员需超管在「用户管理 → 菜单权限」授权 {@code admin_task_center}
|
||||
* 后才能访问。数据范围 = 本人 + 本组用户 + 自己管理的成员(超管不裁剪)。</p>
|
||||
*
|
||||
* <p>公司 tab(spec §4):五个端点各收一个可选 {@code company_id},都在 handler 体内过唯一出口
|
||||
* {@link DataReadScope#readScope} 算成员集,再交给 {@code TaskCenterScopeService.resolve} 与既有口径
|
||||
* 求交——一处收窄,五个出口天然同宽(详情走 {@code scope.visible()},用的就是同一条集合)。
|
||||
* 那一行之所以在五个 handler 里各写一遍而不是抽进私有方法:护栏
|
||||
* {@code CompanyIdParamGoesThroughReadScopeTest} 的断言 A/C/D 认的就是「handler 体内」出现过出口、
|
||||
* 结果被接住当实参传出去、且 {@code company_id} 那个值真进了出口实参列表,抽走即三只都红。</p>
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -42,20 +51,35 @@ public class AdminTaskCenterController {
|
||||
private final TaskCenterScopeService scopeService;
|
||||
private final TaskCenterQueryService queryService;
|
||||
private final TaskCenterVariantService variantService;
|
||||
private final DataReadScope dataReadScope;
|
||||
|
||||
@GetMapping("/overview")
|
||||
@Operation(summary = "汇总卡", description = "总店铺/在跑店铺数、进行中任务数、今日完成任务数、"
|
||||
+ "疑似卡住数(进行中且 >10 分钟无上报)。")
|
||||
public ApiResponse<TaskCenterOverviewVo> overview(HttpServletRequest request) {
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(request);
|
||||
public ApiResponse<TaskCenterOverviewVo> overview(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "公司 ID(超管 tab;不传=不筛)")
|
||||
@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
AdminUserEntity operator = authorizedOperator(request);
|
||||
boolean superAdmin = isSuper(operator);
|
||||
Long operatorId = operator.getId();
|
||||
List<Long> companyUserIds = superAdmin ? dataReadScope.readScope(operator, companyId).userIdsOr(null) : null;
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(operatorId, companyUserIds);
|
||||
return ApiResponse.success(queryService.overview(scope));
|
||||
}
|
||||
|
||||
@GetMapping("/shop-options")
|
||||
@Operation(summary = "店铺筛选候选",
|
||||
description = "店铺库(biz_shop_manage)在可见范围内的店铺名,供筛选下拉精确匹配;只出店铺名。")
|
||||
public ApiResponse<List<String>> shopOptions(HttpServletRequest request) {
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(request);
|
||||
public ApiResponse<List<String>> shopOptions(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "公司 ID(超管 tab;不传=不筛)")
|
||||
@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
AdminUserEntity operator = authorizedOperator(request);
|
||||
boolean superAdmin = isSuper(operator);
|
||||
Long operatorId = operator.getId();
|
||||
List<Long> companyUserIds = superAdmin ? dataReadScope.readScope(operator, companyId).userIdsOr(null) : null;
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(operatorId, companyUserIds);
|
||||
return ApiResponse.success(queryService.shopOptions(scope));
|
||||
}
|
||||
|
||||
@@ -64,8 +88,16 @@ public class AdminTaskCenterController {
|
||||
description = "biz_file_task(12 个客户端模块)∪ brand_crawl_tasks 按创建时间倒序;"
|
||||
+ "店铺按规范化名精确匹配(来源=上架结果文件 + 逐店落行的结果文件名);"
|
||||
+ "进行中且 >10 分钟无上报标记 stuck。")
|
||||
public ApiResponse<TaskCenterTaskPageVo> tasks(HttpServletRequest request, TaskCenterTaskQuery query) {
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(request);
|
||||
public ApiResponse<TaskCenterTaskPageVo> tasks(
|
||||
HttpServletRequest request,
|
||||
TaskCenterTaskQuery query,
|
||||
@Parameter(description = "公司 ID(超管 tab;不传=不筛)")
|
||||
@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
AdminUserEntity operator = authorizedOperator(request);
|
||||
boolean superAdmin = isSuper(operator);
|
||||
Long operatorId = operator.getId();
|
||||
List<Long> companyUserIds = superAdmin ? dataReadScope.readScope(operator, companyId).userIdsOr(null) : null;
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(operatorId, companyUserIds);
|
||||
return ApiResponse.success(queryService.tasks(scope, query));
|
||||
}
|
||||
|
||||
@@ -74,8 +106,14 @@ public class AdminTaskCenterController {
|
||||
description = "参数 taskNo(品牌任务为 brand-<id>):基础信息 + 进度快照 + 分组明细 + 错误信息;"
|
||||
+ "任务不存在或不在可见范围时 data 为空。")
|
||||
public ApiResponse<TaskCenterTaskDetailVo> taskDetail(HttpServletRequest request,
|
||||
@RequestParam String taskNo) {
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(request);
|
||||
@RequestParam String taskNo,
|
||||
@Parameter(description = "公司 ID(超管 tab;不传=不筛)")
|
||||
@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
AdminUserEntity operator = authorizedOperator(request);
|
||||
boolean superAdmin = isSuper(operator);
|
||||
Long operatorId = operator.getId();
|
||||
List<Long> companyUserIds = superAdmin ? dataReadScope.readScope(operator, companyId).userIdsOr(null) : null;
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(operatorId, companyUserIds);
|
||||
TaskCenterTaskDetailVo detail = queryService.detail(scope, taskNo);
|
||||
if (detail == null) {
|
||||
return ApiResponse.success("任务不存在或无权查看", null);
|
||||
@@ -92,14 +130,39 @@ public class AdminTaskCenterController {
|
||||
@RequestParam(required = false) Integer status,
|
||||
@RequestParam(required = false) String taskType,
|
||||
@RequestParam(required = false) Integer page,
|
||||
@RequestParam(required = false) Integer pageSize) {
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(request);
|
||||
@RequestParam(required = false) Integer pageSize,
|
||||
@Parameter(description = "公司 ID(超管 tab;不传=不筛)")
|
||||
@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
AdminUserEntity operator = authorizedOperator(request);
|
||||
boolean superAdmin = isSuper(operator);
|
||||
Long operatorId = operator.getId();
|
||||
List<Long> companyUserIds = superAdmin ? dataReadScope.readScope(operator, companyId).userIdsOr(null) : null;
|
||||
TaskCenterScopeService.ScopeContext scope = resolveScope(operatorId, companyUserIds);
|
||||
return ApiResponse.success(variantService.variantTasks(scope, status, taskType, page, pageSize));
|
||||
}
|
||||
|
||||
private TaskCenterScopeService.ScopeContext resolveScope(HttpServletRequest request) {
|
||||
/** 会话闸门(登录态 + 菜单权限),五个端点同一把;service 只认算好的 operatorId。 */
|
||||
private AdminUserEntity authorizedOperator(HttpServletRequest request) {
|
||||
AdminUserEntity operator = adminAuthSupport.requireAdminOrInternal(request);
|
||||
permissionMenuService.requireClientTaskCenterAccess(operator);
|
||||
return scopeService.resolve(operator.getId());
|
||||
return operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否站点超管——用的是 {@code AdminAuthSupport.currentRole}(与 {@code DataReadScope} 内部同一把尺子,
|
||||
* 含「role 为空 + isAdmin=1 + createdById 为空」的历史超管推断),不是这里新造的判定。
|
||||
* 只有超管才按公司 tab 收窄:非超管的可见集里含「靠分组可见」的行,给它叠成员集会把那批行
|
||||
* 从每一个 tab 里静默删掉;它的公司维度本来就由会话独家决定(spec §4)。
|
||||
*/
|
||||
private boolean isSuper(AdminUserEntity operator) {
|
||||
return "super_admin".equals(adminAuthSupport.currentRole(operator));
|
||||
}
|
||||
|
||||
/**
|
||||
* 五个端点共用的收窄出口:{@code companyUserIds} 必须是 handler 体内 {@code readScope} 算出来的那个值
|
||||
* ({@code null} = 不收窄),不许在这一层重新取公司值——那样护栏 A/C/D 看见的就不是这条链了。
|
||||
*/
|
||||
private TaskCenterScopeService.ScopeContext resolveScope(Long operatorId, List<Long> companyUserIds) {
|
||||
return scopeService.resolve(operatorId, companyUserIds);
|
||||
}
|
||||
}
|
||||
|
||||
+35
@@ -17,6 +17,9 @@ import java.util.Set;
|
||||
* 客户端任务管理的数据范围:超管看全部,管理员看「本人 + 本组用户 + 自己管理的成员」。
|
||||
* 口径与 {@code DedupeTotalDataService.resolveAccessScope} 一致——范围按任务发起账号
|
||||
* (biz_file_task.user_id)判定,不按设备归属,设备跨组使用也不会串组。
|
||||
*
|
||||
* <p>公司 tab(spec §4)叠在这条既有口径之上:{@link #resolve(Long, List)} 只与上面的集合求交,
|
||||
* 超管选了公司才有收窄,非超管的范围仍由会话独家决定。</p>
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -27,6 +30,38 @@ public class TaskCenterScopeService {
|
||||
private final CompanyScopeSupport companyScopeSupport;
|
||||
|
||||
public ScopeContext resolve(Long operatorId) {
|
||||
return resolve(operatorId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 公司 tab 的收窄点:在 {@link #resolveBase(Long)} 的既有可见集上**只叠一层交集**,一律不放大
|
||||
* (spec §4)。客户端任务管理的五个端点共用这一处,所以「列表筛了但按 id 能读」在这一页不存在
|
||||
* ——详情走 {@code scope.visible(userId)},与列表同一条集合。
|
||||
*
|
||||
* <p>{@code companyUserIds} 由 controller 过唯一出口 {@code DataReadScope.readScope} 算好
|
||||
* (本 service 手上只有 operatorId,没有操作者实体之外的会话信息,交不出这个集合)。
|
||||
* <b>{@code null} 与空集不是一回事</b>:{@code null} = 不收窄(非超管、或超管没选公司),
|
||||
* 逐字退回今天的行为;空集 = 选了公司但这家一个账号都没有,必须收窄成恒不命中
|
||||
* ({@link ScopeContext#sqlUserIds()} 的 {@code [-1]} 兜底)。这里要是把空集也当「没选」放过,
|
||||
* 症状是「切到空公司 tab 反而看见全量」——越权,且不报错。</p>
|
||||
*
|
||||
* @param companyUserIds 公司成员账号集;{@code null} 表示不按公司收窄
|
||||
*/
|
||||
public ScopeContext resolve(Long operatorId, List<Long> companyUserIds) {
|
||||
ScopeContext base = resolveBase(operatorId);
|
||||
if (companyUserIds == null) {
|
||||
return base;
|
||||
}
|
||||
LinkedHashSet<Long> visible = new LinkedHashSet<>();
|
||||
addAll(visible, companyUserIds);
|
||||
if (!base.allUsers()) {
|
||||
visible.retainAll(base.visibleUserIds());
|
||||
}
|
||||
return new ScopeContext(false, Set.copyOf(visible));
|
||||
}
|
||||
|
||||
/** 今天的三条腿,逐字保留(超管直通 / 公司超管按会话 / 管理员按分组),不动口径、不换 mapper 方法。 */
|
||||
private ScopeContext resolveBase(Long operatorId) {
|
||||
AdminUserEntity operator = requireOperator(operatorId);
|
||||
if (isSuperAdmin(operator)) {
|
||||
return new ScopeContext(true, Set.of());
|
||||
|
||||
Reference in New Issue
Block a user