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
@@ -0,0 +1,185 @@
package com.nanri.aiimage.common.util;
import com.alibaba.excel.EasyExcel;
import com.nanri.aiimage.common.exception.BusinessException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* ExcelStreamReader 的异常出口契约(现网缺陷:带单元格图片的 xlsx 解析失败时
* POI 的 ExcelAnalysisException 原样冒到 GlobalExceptionHandler,用户拿到 HTTP 500 且看不到真因)。
*/
class ExcelStreamReaderParseFailureTest {
@TempDir
Path tempDir;
/** 生产现场形状:xlsx 包里有一个未声明 content type 的 media 部件。 */
@Test
void parseFailureOnMalformedPackageSurfacesAsIoExceptionWithReason() throws Exception {
Path bad = tempDir.resolve("cellimage-no-content-type.xlsx");
Files.write(bad, packageWithUndeclaredMediaPart());
IOException thrown = assertThrows(IOException.class,
() -> ExcelStreamReader.readFirstSheet(bad.toFile(), noopHandler()));
String reason = rawParseFailureMessageOf(bad);
assertTrue(thrown.getMessage().contains(reason),
"消息里要能看到底层真因 [" + reason + "],实际=" + thrown.getMessage());
}
/** 反向钉:读全部 sheet 的入口同样收口(另有 6 个调用点走这条)。 */
@Test
void parseFailureOnReadAllSheetsAlsoSurfacesAsIoException() throws Exception {
Path bad = tempDir.resolve("cellimage-no-content-type-all.xlsx");
Files.write(bad, packageWithUndeclaredMediaPart());
assertThrows(IOException.class, () -> ExcelStreamReader.readAllSheets(bad.toFile(), noopHandler()));
}
/** 反向钉:调用方在 onRow 里抛的业务异常不能被改写成 IOException,否则 400 语义会塌成"文件坏了"。 */
@Test
void handlerBusinessExceptionIsNotRewrittenIntoIoException() throws Exception {
Path good = writeWorkbook();
BusinessException thrown = assertThrows(BusinessException.class, () -> ExcelStreamReader
.readFirstSheet(good.toFile(), rowHandlerThatThrows(
new BusinessException("品牌列缺失,请检查表头"))));
assertEquals("品牌列缺失,请检查表头", thrown.getMessage());
}
/** 调用方抛的运行时异常原样透传,不借"解析失败"这条路被包成 IOException。 */
@Test
void handlerRuntimeExceptionPropagatesUnchanged() throws Exception {
Path good = writeWorkbook();
IllegalStateException failure = new IllegalStateException("行处理失败");
IllegalStateException thrown = assertThrows(IllegalStateException.class,
() -> ExcelStreamReader.readFirstSheet(good.toFile(), rowHandlerThatThrows(failure)));
assertSame(failure, thrown);
}
/** 调用方抛的受检异常走 IOException 契约,且不把内部包装类漏给调用方。 */
@Test
void handlerCheckedExceptionSurfacesAsIoExceptionWithReason() throws Exception {
Path good = writeWorkbook();
IOException thrown = assertThrows(IOException.class, () -> ExcelStreamReader.readFirstSheet(
good.toFile(), rowHandlerThatThrows(new Exception("行数据超出上限 5000"))));
assertTrue(thrown.getMessage().contains("行数据超出上限 5000"),
"消息里要能看到调用方抛出的真因,实际=" + thrown.getMessage());
}
/** 好文件照旧能读完(保证收口没有把正常路径一起改掉)。 */
@Test
void validWorkbookStillReadsRows() throws Exception {
Path good = writeWorkbook();
StringBuilder seen = new StringBuilder();
assertDoesNotThrow(() -> ExcelStreamReader.readFirstSheet(
good.toFile(), (sheetName, sheetNo, rowIndex, headerMap, rowMap) ->
seen.append(rowMap.get(0))));
assertEquals("Nike", seen.toString());
}
private Path writeWorkbook() {
Path file = tempDir.resolve("ok.xlsx");
List<List<String>> head = List.of(List.of("品牌"), List.of("ASIN"));
List<List<String>> data = List.of(List.of("Nike", "B01ABC"));
EasyExcel.write(file.toFile()).head(head).sheet("Sheet1").doWrite(data);
return file;
}
private ExcelStreamReader.SheetRowHandler noopHandler() {
return new ExcelStreamReader.SheetRowHandler() {
@Override
public void onRow(String sheetName, Integer sheetNo, int rowIndex,
Map<Integer, String> headerMap, Map<Integer, String> rowMap) {
}
};
}
private ExcelStreamReader.SheetRowHandler rowHandlerThatThrows(Exception failure) {
return new ExcelStreamReader.SheetRowHandler() {
@Override
public void onRow(String sheetName, Integer sheetNo, int rowIndex,
Map<Integer, String> headerMap, Map<Integer, String> rowMap) throws Exception {
throw failure;
}
};
}
/** 直接喂同一个坏包,取 POI 自己报出来的真因文本,用来断言它没被收口吞掉。 */
private String rawParseFailureMessageOf(Path badFile) throws IOException {
String message = null;
try (var input = Files.newInputStream(badFile)) {
EasyExcel.read(input).sheet(0).headRowNumber(1).doRead();
throw new AssertionError("构造的坏包必须让 EasyExcel 抛异常,否则这条用例证明不了收口");
} catch (RuntimeException ex) {
Throwable deepest = ex;
while (deepest.getCause() != null) {
deepest = deepest.getCause();
}
message = deepest.getMessage();
}
assertTrue(message != null && message.length() > 20,
"底层真因文本应当有信息量,实际=" + message);
return message;
}
private byte[] packageWithUndeclaredMediaPart() throws IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try (ZipOutputStream zip = new ZipOutputStream(bytes, StandardCharsets.UTF_8)) {
put(zip, "[Content_Types].xml", """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Default Extension="xml" ContentType="application/xml"/>
<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>
</Types>""");
put(zip, "_rels/.rels", """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
</Relationships>""");
put(zip, "xl/workbook.xml", """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<sheets><sheet name="Sheet1" sheetId="1" r:id="rId1"/></sheets>
</workbook>""");
put(zip, "xl/_rels/workbook.xml.rels", """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/cellImages" Target="cellimages.xml"/>
</Relationships>""");
put(zip, "xl/cellimages.xml", """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cellImages xmlns="http://www.wps.cn/officeDocument/2020/cellImage"/>""");
zip.putNextEntry(new ZipEntry("xl/media/cellimage1.jpeg"));
zip.write(new byte[]{(byte) 0xFF, (byte) 0xD8, (byte) 0xFF, (byte) 0xD9});
zip.closeEntry();
}
return bytes.toByteArray();
}
private void put(ZipOutputStream zip, String name, String content) throws IOException {
zip.putNextEntry(new ZipEntry(name));
zip.write(content.getBytes(StandardCharsets.UTF_8));
zip.closeEntry();
}
}