feat(公司tab): 批次 2/3/4 再接 8 页,注册表收到 16 页——用户页回流 company_id 按新边界改写反向钉

「切 tab 数据还一样」的根因一直是分母小于现实:批次 1 只登记 8 页,本轮按控制方
三次点名扩到 16 页(company-scope.ts 是唯一清单,routes.ts 的 companyScoped 逐页对平)。

批次 2(五页 ASIN 中心):去重总数据 / 不符合ASIN / 查询ASIN / 最低价ASIN / 商品类目。
批次 3(两页店铺中心):撞款监控、店铺数据记录。这两页没有归属列可筛,归属口径是
「本公司账号名下的店铺」——后端由 DataReadScope 推公司 → 成员账号 → biz_shop_manage.
created_by_id,前端只把 activeId 当 company_id 送下去。空成员集必须交空集合,绝不能
退化成 null(null 在这里=全量,那样第二家会看到全部数据)。
批次 4(用户管理):后端早就认 company_id(只对站点超管生效,公司超管恒锁本公司),
断的是前端——UserListQuery 里连这个字段都没有,三家 tab 看的是同一份全量列表。

三处口径改动,逐条说明:
1)company-user-list.test.ts 的反向钉被改写。2026-10-04 定案把公司维度从用户页整体摘掉,
   那条钉的原文是「列表查询/筛选/行渲染不允许出现公司维度」。控制方 2026-10-05 明确要
   用户管理区分公司 tab,所以钉的边界收窄成两半:渲染层(行级公司列、「所属公司」标签、
   筛选状态、顶栏公司名)仍不得回流;请求层的 company_id 是这次加回来的,尺子换成
   「取值口唯一」——页面每处 companyId 都必须等于 companyTab.requestCompanyId,且
   normalizeUserPageParams/toUserListQuery 两只白名单构造器体内不许出现公司值。
   新增一支行为钉:往归一化里传 companyId 必须被丢掉,这是 users.ts 读原始入参的全部理由
   (写成 normalized.companyId 时 TS 照样绿、运行时恒 undefined)。
2)align-dup-console 那条 watch 看守的 token 扩到含 reload。变异自证里「删掉 void
   loadConsole()」当场全绿:体里的清筛选项守住了,重新取数那半没人守。批次 3/4 三对
   token 一起写到 reload 为止(批次 1/2 的老条目不动)。
3)公司管理页补正/反向两把尺子:company-config-entry-super-only 新增「吃公司 tab 的页面
   集合恰好等于 COMPANY_SCOPED_PAGES 的 pageFiles」——按代码真值比,不按清单比,所以
   清单不改一字而往 CompaniesPage.vue 里塞 store 也会红。谓词带括号,否则 import 行也算消费者。

菜单权限(admin_columns)本轮不动:MenusPage 只消费 /api/admin/permission-menus 这一份全局
菜单字典,切 tab 一样是数据本身全局,不是筛选坏了。真问题在写侧——PermissionMenuService
create/update/delete 只有 ensureAdminOperatorIfPresent(isAdmin 即放行),公司管理员改的是
全平台的菜单行。收窄为仅站点超管 vs 给 permission_menu 加归属列,两种改法代价差一个量级,
留给控制方定档。

护栏:G1 发送口 22 个 / 页面分组 17、watch 体看守 10 对、operation-guide 的 tab 文案 15 页
(撞款监控是显式豁免,另有一条自检盯「豁免落空」)。
变异自证 12/12 全杀(前端 10 + 公司管理反向钉 2),分母钉死在 27 例。
门禁:后端全量 3823 例 / 0 失败 / 0 错误 / 7 skipped,BUILD SUCCESS;admin-frontend-vue
1741 例 / 0 红;vue-tsc rc=0。首轮后端 4 红是另一路 task_partial 改动与本轮编译抢跑,
单跑 13 例已绿,本笔不含他们的任何文件。

未上线:jar 与 admin-vue 都没出包,V147 未在生产执行。
This commit is contained in:
2026-10-06 02:32:59 +08:00
parent e5e36aa713
commit 16583f578d
87 changed files with 3519 additions and 459 deletions
@@ -3,6 +3,7 @@ package com.nanri.aiimage.modules.dedupe.controller;
import com.nanri.aiimage.common.api.ApiResponse;
import com.nanri.aiimage.common.exception.BusinessException;
import com.nanri.aiimage.common.security.AdminAuthSupport;
import com.nanri.aiimage.common.service.DataReadScope;
import com.nanri.aiimage.common.util.DownloadHeaderUtil;
import com.nanri.aiimage.modules.dedupe.model.dto.DedupeTotalDataCreateRequest;
import com.nanri.aiimage.modules.dedupe.model.dto.DedupeTotalDataUpdateRequest;
@@ -48,6 +49,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.MessageDigest;
import java.util.List;
@RestController
@RequiredArgsConstructor
@@ -65,6 +67,7 @@ public class DedupeTotalDataController {
private final DedupeTotalDataService dedupeTotalDataService;
private final AdminAuthSupport adminAuthSupport;
private final PermissionMenuService permissionMenuService;
private final DataReadScope dataReadScope;
@@ -86,10 +89,16 @@ public class DedupeTotalDataController {
@Parameter(description = "国家代码(如 DE、UK)") @RequestParam(name = "country", required = false) String country,
@Parameter(description = "顺序翻页游标(上一页返回的 nextLastId;传了就忽略 page 偏移)")
@RequestParam(name = "last_id", required = false) Long lastId,
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
HttpServletRequest request) {
RequestOperator operator = requireDedupeTotalDataAccess(request);
AdminUserEntity user = operator.user();
List<Long> memberIds = operator.superAdmin()
? dataReadScope.readScope(user, companyId).userIdsOr(null)
: null;
return ApiResponse.success(dedupeTotalDataService.page(
page, pageSize, keyword, username, startDate, endDate, groupId, country, lastId, operator.id()));
page, pageSize, keyword, username, startDate, endDate, groupId, country, lastId,
operator.id(), memberIds));
}
@GetMapping("/export")
@@ -102,19 +111,27 @@ public class DedupeTotalDataController {
@RequestParam(name = "end_date", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
@Parameter(description = "分组 ID") @RequestParam(name = "group_id", required = false) Long groupId,
@Parameter(description = "国家代码(如 DE、UK)") @RequestParam(name = "country", required = false) String country,
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
HttpServletRequest request) {
if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
throw new BusinessException(400, "invalid export date range");
}
RequestOperator operator = requireDedupeTotalDataAccess(request);
AdminUserEntity user = operator.user();
Long operatorId = operator.id();
List<Long> memberIds = operator.superAdmin()
? dataReadScope.readScope(user, companyId).userIdsOr(null)
: null;
boolean monthlyZip = isCrossMonthRange(startDate, endDate);
String filename = "dedupe-total-data-" + LocalDateTime.now().format(EXPORT_FILENAME_FORMATTER)
+ (monthlyZip ? ".zip" : ".xlsx");
// 两个分支的实参表都不许出现嵌套括号(operator.id() 那种写法护栏 G2 的单层括号判据看不穿,
// 会把它当成"范围没交给任何调用"而假红),所以 operatorId 先在局部变量里落好。
StreamingResponseBody body = monthlyZip
? outputStream -> dedupeTotalDataService.writeMonthlyZipExport(
outputStream, username, startDate, endDate, groupId, country, operator.id())
outputStream, username, startDate, endDate, groupId, country, operatorId, memberIds)
: outputStream -> dedupeTotalDataService.writeExport(
outputStream, username, startDate, endDate, groupId, country, operator.id());
outputStream, username, startDate, endDate, groupId, country, operatorId, memberIds);
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, DownloadHeaderUtil.contentDisposition(filename))
.contentType(MediaType.parseMediaType(monthlyZip ? ZIP_CONTENT_TYPE : XLSX_CONTENT_TYPE))
@@ -224,7 +241,7 @@ public class DedupeTotalDataController {
if (!superAdmin && !hasDedupeTotalDataPermission(operator)) {
throw new BusinessException(403, "无权访问数据去重总数据");
}
return new RequestOperator(operator.getId(), superAdmin);
return new RequestOperator(operator.getId(), superAdmin, operator);
}
private AdminUserEntity resolveOperator(HttpServletRequest request) {
@@ -267,7 +284,13 @@ public class DedupeTotalDataController {
private record RequestOperator(Long id, boolean superAdmin) {
// 公司 tab 的读范围就地算在 handler 里,不留私有收口方法:G2 的断言 A 只在这支 handler 的
// 块内找 readScope(,私有方法在它自己的闭括号处收口、不算在内(CompanyIdParamGoesThroughReadScopeTest
// 类注释第 5、7 条),挪进去 = 这一页的 tab 没人看守。收窄只给超管:非超管已由 resolveAccessScope
// 按会话裁剪,且他的可见集里含「靠分组可见」的行,叠一层账号 IN 会把那批行静默删掉
// (同 ShopManageController 的口径)。
private record RequestOperator(Long id, boolean superAdmin, AdminUserEntity user) {
}
private boolean isTrustedInternalRequest(String suppliedToken) {
return adminAuthSupport.isTrustedSuppliedToken(suppliedToken);
@@ -160,16 +160,18 @@ public class DedupeTotalDataService {
public DedupeTotalDataPageVo page(long page, long pageSize, String keyword, String username,
LocalDate startDate, LocalDate endDate, Long groupId, String country, Long operatorId) {
return page(page, pageSize, keyword, username, startDate, endDate, groupId, country, null, operatorId);
return page(page, pageSize, keyword, username, startDate, endDate, groupId, country, null, operatorId, null);
}
/**
* @param lastId keyset 游标(上一页返回的 nextLastId);非空时忽略 page 偏移,
* 直接按 id 倒序取"比它小"的一页,避免深分页 offset 扫索引的代价
* @param companyMemberIds 公司 tab 收窄后的成员账号集({@code DataReadScope} 给出);
* null = 不筛(超管没选公司 / 非超管走会话范围)
*/
public DedupeTotalDataPageVo page(long page, long pageSize, String keyword, String username,
LocalDate startDate, LocalDate endDate, Long groupId, String country,
Long lastId, Long operatorId) {
Long lastId, Long operatorId, List<Long> companyMemberIds) {
if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
throw new BusinessException("开始日期不能晚于结束日期");
}
@@ -194,6 +196,7 @@ public class DedupeTotalDataService {
endDate == null ? null : endDate.plusDays(1).atStartOfDay())
.orderByDesc(DedupeTotalDataEntity::getId);
applyGroupScope(query, scope, groupId);
applyCompanyScope(query, companyMemberIds);
Long total = dedupeTotalDataMapper.selectCount(query);
boolean keyset = lastId != null && lastId > 0;
if (keyset) {
@@ -256,6 +259,17 @@ public class DedupeTotalDataService {
Long groupId,
String country,
Long operatorId) {
writeExport(outputStream, username, startDate, endDate, groupId, country, operatorId, null);
}
public void writeExport(OutputStream outputStream,
String username,
LocalDate startDate,
LocalDate endDate,
Long groupId,
String country,
Long operatorId,
List<Long> companyMemberIds) {
if (outputStream == null) {
throw new BusinessException("导出输出流不能为空");
}
@@ -264,7 +278,8 @@ public class DedupeTotalDataService {
}
String safeUsername = username == null ? "" : username.trim();
AccessScope scope = resolveAccessScope(operatorId);
buildExportWorkbook(outputStream, safeUsername, startDate, endDate, groupId, country, scope);
buildExportWorkbook(outputStream, safeUsername, startDate, endDate, groupId, country, scope, false,
companyMemberIds);
}
public void writeMonthlyZipExport(OutputStream outputStream,
@@ -283,11 +298,22 @@ public class DedupeTotalDataService {
Long groupId,
String country,
Long operatorId) {
writeMonthlyZipExport(outputStream, username, startDate, endDate, groupId, country, operatorId, null);
}
public void writeMonthlyZipExport(OutputStream outputStream,
String username,
LocalDate startDate,
LocalDate endDate,
Long groupId,
String country,
Long operatorId,
List<Long> companyMemberIds) {
if (outputStream == null) {
throw new BusinessException("export output stream cannot be null");
}
if (startDate == null || endDate == null || YearMonth.from(startDate).equals(YearMonth.from(endDate))) {
writeExport(outputStream, username, startDate, endDate, groupId, country, operatorId);
writeExport(outputStream, username, startDate, endDate, groupId, country, operatorId, companyMemberIds);
return;
}
if (startDate.isAfter(endDate)) {
@@ -311,7 +337,7 @@ public class DedupeTotalDataService {
LocalDate entryEndDate = endDate.isBefore(monthEnd) ? endDate : monthEnd;
zipOutputStream.putNextEntry(new ZipEntry(monthlyExportEntryName(currentMonth)));
buildExportWorkbook(zipOutputStream, safeUsername, entryStartDate, entryEndDate,
groupId, safeCountry, scope, groupPrevalidated);
groupId, safeCountry, scope, groupPrevalidated, companyMemberIds);
zipOutputStream.closeEntry();
currentMonth = currentMonth.plusMonths(1);
}
@@ -330,7 +356,7 @@ public class DedupeTotalDataService {
Long groupId,
String country,
AccessScope scope) {
buildExportWorkbook(outputStream, username, startDate, endDate, groupId, country, scope, false);
buildExportWorkbook(outputStream, username, startDate, endDate, groupId, country, scope, false, null);
}
private void buildExportWorkbook(OutputStream outputStream,
@@ -340,7 +366,8 @@ public class DedupeTotalDataService {
Long groupId,
String country,
AccessScope scope,
boolean groupPrevalidated) {
boolean groupPrevalidated,
List<Long> companyMemberIds) {
try (SXSSFWorkbook workbook = new SXSSFWorkbook(100)) {
Sheet sheet = workbook.createSheet("DedupeTotalData");
Row header = sheet.createRow(0);
@@ -354,7 +381,7 @@ public class DedupeTotalDataService {
int rowIndex = 1;
while (true) {
LambdaQueryWrapper<DedupeTotalDataEntity> pageQuery = buildExportQuery(
username, startDate, endDate, groupId, country, scope, groupPrevalidated);
username, startDate, endDate, groupId, country, scope, groupPrevalidated, companyMemberIds);
if (lastId != null) {
pageQuery.lt(DedupeTotalDataEntity::getId, lastId);
}
@@ -402,7 +429,7 @@ public class DedupeTotalDataService {
LocalDate endDate,
Long groupId,
AccessScope scope) {
return buildExportQuery(username, startDate, endDate, groupId, null, scope, false);
return buildExportQuery(username, startDate, endDate, groupId, null, scope, false, null);
}
private LambdaQueryWrapper<DedupeTotalDataEntity> buildExportQuery(String username,
@@ -411,7 +438,8 @@ public class DedupeTotalDataService {
Long groupId,
String country,
AccessScope scope,
boolean groupPrevalidated) {
boolean groupPrevalidated,
List<Long> companyMemberIds) {
String safeUsername = username == null ? "" : username.trim();
String safeCountry = country == null ? "" : country.trim();
LambdaQueryWrapper<DedupeTotalDataEntity> query = new LambdaQueryWrapper<DedupeTotalDataEntity>()
@@ -425,6 +453,7 @@ public class DedupeTotalDataService {
endDate == null ? null : endDate.plusDays(1).atStartOfDay())
.orderByDesc(DedupeTotalDataEntity::getId);
applyGroupScope(query, scope, groupId, groupPrevalidated);
applyCompanyScope(query, companyMemberIds);
return query;
}
@@ -1252,6 +1281,26 @@ public class DedupeTotalDataService {
});
}
/**
* 公司 tab 收窄:本表按「上传账号」认公司——{@code uploader_user_id} 是 NOT NULL(V75 先回灌再收紧),
* 且有 idx_uploader_user_id_id 可走点查。
*
* <p>不读 V145 新加的 company_id:写入侧实体没有该字段、{@code insertBatchIgnore} 的列清单也不带,
* 全靠 MySQL 的 DEFAULT 1 兜底,所以第 2 家账号新导入的行今天仍会被盖成公司 1。那一列不能当读侧依据。</p>
*
* <p>空集给一条不可能命中的条件而不是"不筛":tab 选了这家公司却看得到全平台,比看不到更坏。</p>
*/
private void applyCompanyScope(LambdaQueryWrapper<DedupeTotalDataEntity> query, List<Long> companyMemberIds) {
if (companyMemberIds == null) {
return;
}
if (companyMemberIds.isEmpty()) {
query.eq(DedupeTotalDataEntity::getId, -1L);
return;
}
query.in(DedupeTotalDataEntity::getUploaderUserId, companyMemberIds);
}
private ShopManageGroupEntity resolveWritableGroup(Long groupId, AdminUserEntity operator) {
if (groupId == null || groupId <= 0) {
throw new BusinessException("请选择分组");