fix(jd): 京东数据库摘除公司 tab(2026-11-16 用户定案「删除掉公司 tab 参考品牌数据库」=品牌库 2026-10-06 先例同形:摘的不只是 tab)——前端 admin_jd_database 退出 COMPANY_SCOPED_PAGES 注册表(定案注释+「公司维度不得回流」SHARED 清单钉住)+routes companyScoped:false+页面卸 companyTab watch 与两处 companyId 发送口(列表 params/类目下拉 fetchJdProductCategories 无参化,JdProductAssignPane 取数同形);后端读侧同窗摘:XML productConds 与 selectProductCategories 的公司维谓词删除(行 company_id 列保留=同步来源标记,JdSchemaContractTest 契约不动)、JdProductMapper.countProducts/selectProductPage 8 参、selectProductCategories() 无参、JdProductQueryService.page 10 参+Filter 去 companyId、AdminJdProductController.page 10 参数+categories(request) 去 superAdminScopedCompanyId 与 DataReadScope 注入、JdCollectController.categories() 调用方同步。判据:vue-tsc rc=0;node --test 9 文件 56/56(wiring SEND_POINTS 27→25、分组 21→19、watch 分母 12→11;menu-route 钉 companyScoped=false;jd-page 钉退出注册表);vitest mount 28/28(删「切公司 Tab 重取」用例,companyId 发送口全改 not.toHaveProperty);mvn -o test-compile rc=0;mvn -o test jd 模块全绿(AdminJdProductControllerTest 20/20:结构判据改「读侧零公司维度_公司tab口径整批摘除」反向钉 company_id/superAdminScopedCompanyId/DataReadScope 不得回潜,行为样本改 requireJdAccess 正门装 200 信封)

This commit is contained in:
2026-11-16 12:05:18 +08:00
parent 3bccc97698
commit 7b853a605e
16 changed files with 240 additions and 295 deletions
@@ -6,7 +6,6 @@ import com.nanri.aiimage.common.exception.BusinessException;
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
import com.nanri.aiimage.common.security.AdminAuthSupport;
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
import com.nanri.aiimage.common.service.DataReadScope;
import com.nanri.aiimage.modules.jd.model.dto.JdProductBatchAssignGroupRequest;
import com.nanri.aiimage.modules.jd.model.dto.JdProductBatchDeleteRequest;
import com.nanri.aiimage.modules.jd.model.dto.JdProductUpdateRequest;
@@ -60,13 +59,13 @@ import java.util.List;
* 非超管菜单权限(column_key/route_path 双匹配)。菜单行由 V196 只插 columns 不预授权
* ⇒ 默认仅 super_admin 可见可访问,其余角色由超管在权限页手工勾授后才放行。</p>
*
* <p><b>公司口径(2026-11-15 用户定案「京东数据库不区分公司、属于公共的」)</b>:行上的
* company_id 只剩「哪家公司客户端同步的」来源标记,不再构成可见性边界——读侧全公共;
* 唯一保留的公司维度是<b>站点超管</b>的公司 tab 筛选({@code superAdminScopedCompanyId}:
* 超管显式传 company_id 才收窄,非超管传什么都不收),也就是「管理员没有这个筛选、
* 超管可以筛选管理员」。详情与写侧(编辑/删除)没有公司维度:任何拿到本页菜单权限的
* 管理员对全部公共行可编辑可删除(同商品类目「谁都能改」的 2026-10-06 定案形状),
* 请求里的 company_id 传参已随公共化从写侧端点摘除。</p>
* <p><b>公司口径(2026-11-16 用户定案「删除掉公司 tab,参考品牌数据库」)</b>:读侧零公司
* 维度——company_id 请求参数与 {@code superAdminScopedCompanyId} 谓词已随公共化收尾整批
* 摘除(2026-11-15 定案「京东数据库不区分公司、属于公共的」的最后一截),行上的 company_id
* 只剩「哪家公司客户端同步的」来源标记,不构成可见性边界;每个拿到本页菜单权限的管理员
* (含站点超管)看到同一份全量公共库。详情与写侧(编辑/删除)同样没有公司维度:
* 对全部公共行可编辑可删除(同商品类目「谁都能改」的 2026-10-06 定案形状),写侧端点的
* company_id 传参已随 2026-11-15 公共化摘除。</p>
*
* <p>导出端点已随 2026-11-15 客户口径「导出也不用」整段下线(控制器/服务/mapper 参数一起删);
* {@code sale_status} 查询参数同窗撤掉(商品状态筛选框已从前端下线)。店铺筛选参数
@@ -77,7 +76,7 @@ import java.util.List;
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/api/admin/jd-products")
@Tag(name = "京东数据库", description = "后管京东店铺商品库:分页查询、详情、编辑与删除。数据全平台公共,仅超管可按公司(同步来源)筛选。")
@Tag(name = "京东数据库", description = "后管京东店铺商品库:分页查询、详情、编辑与删除。数据全平台公共,无公司维度。")
public class AdminJdProductController {
private static final String COLUMN_KEY = "admin_jd_database";
@@ -88,11 +87,10 @@ public class AdminJdProductController {
private final JdProductUpdateService jdProductUpdateService;
private final AdminAuthSupport adminAuthSupport;
private final PermissionMenuService permissionMenuService;
private final DataReadScope dataReadScope;
@GetMapping
@Operation(summary = "分页查询京东数据库商品", description = "公共库分页查询同步落表的京东商品;"
+ "company_id 只对站点超管生效(显式传才收窄=按同步来源公司筛),非超管传什么都不收(全量)。")
+ "全平台公共、无公司维度(2026-11-16 摘公司 tab:公司维参数与超管筛选谓词已整批摘除)。")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", content = @Content(schema = @Schema(implementation = JdProductPageVo.class)))
})
@@ -111,29 +109,19 @@ public class AdminJdProductController {
@RequestParam(name = "synced_from", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime syncedFrom,
@Parameter(description = "同步结束时间(包含,ISO datetime)")
@RequestParam(name = "synced_to", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime syncedTo,
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
HttpServletRequest request) {
RequestOperator operator = requireJdAccess(request);
AdminUserEntity user = operator.user();
// 公司维度只剩超管的公司 tab 筛选(superAdminScopedCompanyId):超管显式传才收窄,
// 非超管传什么都不收——公共库对每一家管理员都是同一份全量。
Long scopedCompanyId = dataReadScope.superAdminScopedCompanyId(user, companyId);
return ApiResponse.success(jdProductQueryService.page(page, pageSize, scopedCompanyId,
requireJdAccess(request);
return ApiResponse.success(jdProductQueryService.page(page, pageSize,
productCode, titleKeyword, category, groupId, ungrouped, grouped, syncedFrom, syncedTo));
}
@GetMapping("/categories")
@Operation(summary = "类目筛选下拉数据源", description = "已落库行 DISTINCT 的 category_path"
+ "(京麦末级类目名)+ 行数,按类目名排序;company_id 只对站点超管生效(显式传才收窄="
+ "选项集与超管当前公司 tab 的行集同源),非超管传什么都不收(全量)。")
public ApiResponse<List<JdProductCategoryVo>> categories(
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
HttpServletRequest request) {
RequestOperator operator = requireJdAccess(request);
AdminUserEntity user = operator.user();
// 类目下拉与列表同走超管筛选口径:选项集永远和当前请求能看到的行集同源。
Long scopedCompanyId = dataReadScope.superAdminScopedCompanyId(user, companyId);
return ApiResponse.success(jdProductQueryService.categories(scopedCompanyId));
+ "(京麦末级类目名)+ 行数,按类目名排序;全平台公共去重、无公司维度"
+ "(与用户端采集建单侧同一出口同一口径)。")
public ApiResponse<List<JdProductCategoryVo>> categories(HttpServletRequest request) {
requireJdAccess(request);
return ApiResponse.success(jdProductQueryService.categories());
}
@GetMapping("/{id}")
@@ -71,12 +71,12 @@ public class JdCollectController {
@GetMapping("/categories")
@Operation(summary = "采集类目下拉数据源", description = "建单页类目多选面板的选项集:公共库已落库行"
+ " DISTINCT 的 category_path(京麦末级类目名)+ 行数,按类目名排序。与后管京东数据库"
+ "同一条 SQL(JdProductQueryService.categories),公共库无公司维度——传 null 全量口径。"
+ "同一条 SQL(JdProductQueryService.categories),公共库无公司维度、全平台去重。"
+ "边界:从未采集过的店铺/新类目不在集内(先全店采一次即有),页面选项空态不阻塞建单。")
public ApiResponse<List<JdProductCategoryVo>> categories(HttpServletRequest httpRequest) {
// 登录用户即可读(公共库口径):解析不出会话身份就 401(fail-closed,与建单同口径)。
adminAuthSupport.requireOwnershipUserId(httpRequest, null);
return ApiResponse.success(jdProductQueryService.categories(null));
return ApiResponse.success(jdProductQueryService.categories());
}
@GetMapping("/groups")
@@ -42,14 +42,14 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
/**
* 后管只读页总数(Phase 5,v1.4):与 {@link #selectProductPage} 同一过滤面
* (公司/商品编码/标题关键词/类目/分组/未分类/已分类/同步起止,全部 SQL 侧下推,
* 铁律 20)。{@code companyId}/{@code groupId} 为空或 ≤0=不过滤该面;
* (商品编码/标题关键词/类目/分组/未分类/已分类/同步起止,全部 SQL 侧下推,
* 铁律 20)。公司维过滤已随 2026-11-16「删除掉公司 tab,参考品牌数据库」撤掉
* (数据全平台公共);{@code groupId} 为空或 ≤0=不过滤该面;
* {@code ungrouped=true}=只看未分类行(group_id IS NULL,店铺分类弹窗「未分类」范围);
* {@code grouped=true}=只看已分类行(group_id IS NOT NULL,页面筛选行「分类状态」档)。
* 店铺名过滤参数已随 2026-11-15 客户口径「店铺不需要」同窗撤掉(DB 列与详情/回传链不动)。
*/
long countProducts(@Param("companyId") Long companyId,
@Param("productCode") String productCode,
long countProducts(@Param("productCode") String productCode,
@Param("titleKeyword") String titleKeyword,
@Param("category") String category,
@Param("groupId") Long groupId,
@@ -90,8 +90,7 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
* <p>{@code offset}/{@code limit} 必须是服务侧钳制后的值——page 钳制防
* {@code (page-1)*page_size} 溢出(铁律 15),mapper 不做第二次换算,避免两处各算各的。</p>
*/
List<JdProductEntity> selectProductPage(@Param("companyId") Long companyId,
@Param("productCode") String productCode,
List<JdProductEntity> selectProductPage(@Param("productCode") String productCode,
@Param("titleKeyword") String titleKeyword,
@Param("category") String category,
@Param("groupId") Long groupId,
@@ -104,8 +103,8 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
/**
* 类目筛选下拉数据源(2026-11-15 用户口径「京麦的类目也要同步过来后台」):
* 本公司已落库行的 DISTINCT {@code category_path}(=京麦末级类目名)+ 行数。
* {@code companyId} 为空(超管不选公司)=跨公司全量去重。
* 已落库行的 DISTINCT {@code category_path}(=京麦末级类目名)+ 行数,全平台公共去重
* (2026-11-16 起与用户端采集建单侧同口径,无公司维过滤)。
*/
List<JdProductCategoryVo> selectProductCategories(@Param("companyId") Long companyId);
List<JdProductCategoryVo> selectProductCategories();
}
@@ -35,10 +35,10 @@ import java.util.Map;
* 先例:{@code page} 上限 {@link #MAX_PAGE}、{@code page_size} 上限 {@link #MAX_PAGE_SIZE},
* {@code page=Long.MAX_VALUE} 不会把乘积顶成负数生成 {@code LIMIT -N} 的 500 错。</p>
*
* <p><b>公司口径(2026-11-15 公共化)</b>:{@code scopedCompanyId} 由控制器经
* {@code DataReadScope#superAdminScopedCompanyId} 算好传入——只有站点超管显式传 company_id
* (公司 tab 筛选)才是正数,其余请求(含全部非超管)恒为 {@code null} = 全量;详情没有
* 公司维度,按 id 直取。</p>
* <p><b>公司口径(2026-11-16「删除掉公司 tab,参考品牌数据库」)</b>:读侧零公司维度——
* 公司 tab 与 {@code superAdminScopedCompanyId} 谓词已随公共化收尾整批摘除,每个管理员
* (含站点超管)看到同一份全量公共库;行上的 {@code company_id} 列仍是"哪家公司客户端
* 同步的"来源标记,随详情下发但不构成可见性边界。详情本就按 id 直取。</p>
*
* <p><b>详情 attr_json 解析(AC-7 未识别属性不丢弃)</b>:客户端实拍契约
* {@code {"tabs":[{"tab":"...","attrs":[{key,label,value}]}],"images":[...],"productCode":"..."}}——
@@ -75,12 +75,13 @@ public class JdProductQueryService {
/**
* 分页查询商品行({@code synced_at} 倒序)。
*
* <p>过滤面:公司(物化列 eq)、商品编码 contains、标题关键词 contains、
* 类目 eq、分组 eq、未分类(group_id IS NULL,店铺分类弹窗「未分类」范围)、
* <p>过滤面:商品编码 contains、标题关键词 contains、类目 eq、分组 eq、
* 未分类(group_id IS NULL,店铺分类弹窗「未分类」范围)、
* 已分类(group_id IS NOT NULL,页面筛选行「分类状态」档,2026-11-15 客户口径
* 「查询已分类的跟未分类,分类好的可以不显示」)、同步起止(datetime 闭区间)。</p>
* 「查询已分类的跟未分类,分类好的可以不显示」)、同步起止(datetime 闭区间)。
* 公司维过滤已随 2026-11-16 摘公司 tab 整批撤掉(全平台公共)。</p>
*/
public JdProductPageVo page(Long page, Long pageSize, Long scopedCompanyId,
public JdProductPageVo page(Long page, Long pageSize,
String productCode, String titleKeyword, String category, Long groupId, Boolean ungrouped,
Boolean grouped, LocalDateTime syncedFrom, LocalDateTime syncedTo) {
if (syncedFrom != null && syncedTo != null && syncedFrom.isAfter(syncedTo)) {
@@ -89,13 +90,13 @@ public class JdProductQueryService {
long safePage = page == null || page < 1 ? 1 : Math.min(page, MAX_PAGE);
long safeSize = pageSize == null ? PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT
: Math.min(Math.max(pageSize, 1), MAX_PAGE_SIZE);
Filter filter = filter(scopedCompanyId, productCode, titleKeyword, category,
Filter filter = filter(productCode, titleKeyword, category,
groupId, ungrouped, grouped, syncedFrom, syncedTo);
long total = jdProductMapper.countProducts(filter.companyId(), filter.productCode(),
long total = jdProductMapper.countProducts(filter.productCode(),
filter.titleKeyword(), filter.category(), filter.groupId(), filter.ungrouped(),
filter.grouped(), filter.syncedFrom(), filter.syncedTo());
List<JdProductEntity> rows = total <= 0 ? List.of()
: jdProductMapper.selectProductPage(filter.companyId(), filter.productCode(),
: jdProductMapper.selectProductPage(filter.productCode(),
filter.titleKeyword(), filter.category(), filter.groupId(), filter.ungrouped(),
filter.grouped(), filter.syncedFrom(), filter.syncedTo(),
(safePage - 1) * safeSize, (int) safeSize);
@@ -112,12 +113,11 @@ public class JdProductQueryService {
/**
* 类目筛选下拉数据源(2026-11-15 用户口径「京麦的类目也要同步过来后台」):
* 已落库行 distinct 的 {@code category_path}(=京麦末级类目名,契约 §2.3 E3)
* + 各自行数,按类目名排序。公司口径与分页同门(控制器经 {@code superAdminScopedCompanyId} 传入,
* {@code null} = 全量公共选项集)。
* + 各自行数,按类目名排序。全平台公共去重(2026-11-16 起与用户端采集建单侧
* 同一出口同一口径,无公司维过滤)。
*/
public List<JdProductCategoryVo> categories(Long scopedCompanyId) {
Long companyId = scopedCompanyId != null && scopedCompanyId > 0 ? scopedCompanyId : null;
return jdProductMapper.selectProductCategories(companyId);
public List<JdProductCategoryVo> categories() {
return jdProductMapper.selectProductCategories();
}
/**
@@ -173,23 +173,22 @@ public class JdProductQueryService {
// ---------------------------------------------------------------- 过滤面
/** 服务侧过滤面归一:companyId/groupId ≤0 按没选处理,文本 trim 后空串归 null。 */
private record Filter(Long companyId, String productCode, String titleKeyword,
/** 服务侧过滤面归一:groupId ≤0 按没选处理,文本 trim 后空串归 null(无公司维,2026-11-16 摘)。 */
private record Filter(String productCode, String titleKeyword,
String category, Long groupId, Boolean ungrouped, Boolean grouped,
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
}
private static Filter filter(Long scopedCompanyId, String productCode, String titleKeyword,
private static Filter filter(String productCode, String titleKeyword,
String category, Long groupId, Boolean ungrouped, Boolean grouped,
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
Long companyId = scopedCompanyId != null && scopedCompanyId > 0 ? scopedCompanyId : null;
Long safeGroupId = groupId != null && groupId > 0 ? groupId : null;
// 未分类与其它过滤面同口径:没显式要(true)=null=不进 IS NULL 分支。
Boolean safeUngrouped = Boolean.TRUE.equals(ungrouped) ? Boolean.TRUE : null;
// 已分类同口径:true=只看 group_id IS NOT NULL 的行;与未分类同选时 SQL 侧两谓词相与=空集
// (前端下拉是单选,正常到不了这个组合)。
Boolean safeGrouped = Boolean.TRUE.equals(grouped) ? Boolean.TRUE : null;
return new Filter(companyId, trimToNull(productCode), trimToNull(titleKeyword),
return new Filter(trimToNull(productCode), trimToNull(titleKeyword),
trimToNull(category), safeGroupId, safeUngrouped, safeGrouped, syncedFrom, syncedTo);
}
@@ -100,16 +100,16 @@
)
</select>
<!-- 后管只读页(Phase 5,v1.4)过滤面:公司(物化列 eq)、商品编码/标题关键词
(contains LIKE)、类目 eq、分组 eq、未分类(group_id IS NULL,店铺分类弹窗
「未分类」范围)、已分类(group_id IS NOT NULL,页面筛选行「分类状态」档,
2026-11-15 客户口径「查询已分类的跟未分类,分类好的可以不显示」)、
同步起止(datetime 闭区间)。
<!-- 后管只读页(Phase 5,v1.4)过滤面:商品编码/标题关键词(contains LIKE)、类目 eq、
分组 eq、未分类(group_id IS NULL,店铺分类弹窗「未分类」范围)、已分类
(group_id IS NOT NULL,页面筛选行「分类状态」档,2026-11-15 客户口径
「查询已分类的跟未分类,分类好的可以不显示」)、同步起止(datetime 闭区间)。
公司维过滤随 2026-11-16「删除掉公司 tab,参考品牌数据库」撤掉(数据全平台公共;
行 company_id 列仍是同步来源标记,不构成可见性边界)。
sale_status 筛选随 2026-11-15 客户口径撤掉;店铺名过滤同日客户口径「店铺不需要」
同窗撤掉(前端筛选框与列下线;DB 列本身与详情/回传链不动)。
全部走 #{} 占位符;offset/limit 必须是服务侧钳制后的值(铁律 15),mapper 不做第二次换算。 -->
<sql id="productConds">
<if test="companyId != null and companyId &gt; 0">AND p.company_id = #{companyId}</if>
<if test="productCode != null and productCode != ''">AND p.product_code LIKE CONCAT('%', #{productCode}, '%')</if>
<if test="titleKeyword != null and titleKeyword != ''">AND p.title LIKE CONCAT('%', #{titleKeyword}, '%')</if>
<if test="category != null and category != ''">AND p.category_path = #{category}</if>
@@ -142,14 +142,13 @@
LIMIT #{offset}, #{limit}
</select>
<!-- 类目筛选下拉数据源(2026-11-15 用户口径「京麦的类目也要同步过来后台」):本公司已落库行
的 DISTINCT category_path(=京麦末级类目名,契约 §2.3 E3)+ 行数。
空类目行不进下拉;companyId 为空(超管不选公司=全量)时跨公司去重。 -->
<!-- 类目筛选下拉数据源(2026-11-15 用户口径「京麦的类目也要同步过来后台」):已落库行
的 DISTINCT category_path(=京麦末级类目名,契约 §2.3 E3)+ 行数,全平台公共去重
(2026-11-16 起公司与后管两侧同口径,无公司维过滤)。空类目行不进下拉。 -->
<select id="selectProductCategories" resultType="com.nanri.aiimage.modules.jd.model.vo.JdProductCategoryVo">
SELECT p.category_path AS name, COUNT(*) AS productCount
FROM biz_jd_product p
WHERE p.category_path IS NOT NULL AND p.category_path != ''
<if test="companyId != null">AND p.company_id = #{companyId}</if>
GROUP BY p.category_path
ORDER BY p.category_path
</select>
@@ -5,7 +5,6 @@ import com.nanri.aiimage.common.api.PageDefaults;
import com.nanri.aiimage.common.exception.BusinessException;
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.jd.mapper.JdProductImageMapper;
import com.nanri.aiimage.modules.jd.mapper.JdProductMapper;
import com.nanri.aiimage.modules.jd.model.dto.JdProductBatchDeleteRequest;
@@ -48,16 +47,16 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
/**
* v1.4 Phase 5:后管「京东数据库」只读接口(列表/详情)与分组管理入口。
*
* <p>结构判据(照 {@code AdminAppearancePatentCleanItemsControllerTest} 双形态):
* 端点只读、鉴权 seam、公司口径(读侧只剩超管筛选 superAdminScopedCompanyId,公共库不走
* readCompanyIdOrOwn)、snake 参数带默认值、SQL 只落 XML;
* 行为样本:mock HttpServletRequest 把 company 参数交给 superAdminScopedCompanyId 并装进 200 信封、
* 端点只读、鉴权 seam、公司口径(2026-11-16 用户定案「删除掉公司 tab,参考品牌数据库」=
* 品牌库 2026-10-06 先例同形:company_id 请求参数与 superAdminScopedCompanyId 谓词整批摘除,
* 读侧零公司维度、反向钉住防回潜)、snake 参数带默认值、SQL 只落 XML;
* 行为样本:mock HttpServletRequest 走 requireJdAccess 鉴权正门并把结果装进 200 信封、
* 分页钳制 offset/limit(page=Long.MAX_VALUE 不得负,铁律 15)、详情 attr_json
* tabs→attrGroups 解析与非法形状兜底(AC-7)。
* 导出端点与 sale_status 筛选参数已随 2026-11-15 客户口径整段下线(反向钉住防回潜)。</p>
@@ -114,23 +113,30 @@ class AdminJdProductControllerTest {
}
@Test
void 公司口径只剩超管筛选_公共库不走readCompanyIdOrOwn() throws IOException {
void 读侧零公司维度_公司tab口径整批摘除() throws IOException {
String source = stripComments(Files.readString(CONTROLLER));
assertTrue(source.contains("DataReadScope"), "公司维度唯一出口是 DataReadScope");
assertTrue(source.contains("superAdminScopedCompanyId"),
"读侧(列表/类目)必须走 superAdminScopedCompanyId:只有站点超管显式传 company_id 才收窄"
+ "(公司 tab 筛选管理员),其余请求全量(2026-11-15 用户定案「京东数据库不区分公司、属于公共的」)");
// 2026-11-16 用户定案「删除掉公司 tab,参考品牌数据库」=品牌库 2026-10-06 先例同形:
// 摘的不只是 tab——company_id 参数与 superAdminScopedCompanyId 谓词一起撤,
// 数据全平台公共(行 company_id 列仍是同步来源标记,不构成可见性边界)。
assertFalse(source.contains("company_id"),
"company_id 请求参数必须已删除,不得回潜(2026-11-16 随公司 tab 整批摘除)");
assertFalse(source.contains("superAdminScopedCompanyId"),
"superAdminScopedCompanyId 谓词必须已删除:第五道门(超管显式收窄)对京东只读面不再生效");
assertFalse(source.contains("readCompanyIdOrOwn"),
"不得走 readCompanyIdOrOwn:它对非超管强制本公司,公共库对每一家管理员都是同一份全量");
"不得走 readCompanyIdOrOwn:全平台公共数据对每一家管理员都是同一份全量,无公司可见性边界");
assertFalse(source.contains("DataReadScope"),
"DataReadScope 不得再注入京东只读控制器(公司收口已随 2026-11-16 摘除)");
}
@Test
void 分页参数snake且带默认值() throws IOException {
String source = stripComments(Files.readString(CONTROLLER));
for (String param : List.of("page_size", "product_code", "title_keyword",
"group_id", "ungrouped", "grouped", "synced_from", "synced_to", "company_id")) {
"group_id", "ungrouped", "grouped", "synced_from", "synced_to")) {
assertTrue(source.contains(param), "查询参数必须 snake_case:" + param);
}
// company_id 参数已随 2026-11-16「删除掉公司 tab」整批摘除(读侧零公司维度支另有反向钉)。
assertFalse(source.contains("company_id"), "company_id 请求参数必须已删除,不得回潜");
// 商品状态筛选框已随 2026-11-15 客户口径从前端下线 ⇒ 服务端同名参数一起撤(反向钉住防回潜)。
assertFalse(source.contains("\"sale_status\""), "sale_status 筛选参数必须已删除,不得回潜");
// 店铺筛选同日客户口径「店铺不需要」下线 ⇒ shop_name 参数同窗撤(反向钉住防回潜)。
@@ -177,64 +183,58 @@ class AdminJdProductControllerTest {
// ===================== 行为样本 =====================
@Test
void 控制器把公司参数交给superAdminScopedCompanyId并把结果装进200信封() {
void 控制器列表走requireJdAccess正门并把查询结果装进200信封() {
JdProductQueryService queryService = mock(JdProductQueryService.class);
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
DataReadScope dataReadScope = mock(DataReadScope.class);
AdminJdProductController controller = new AdminJdProductController(
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class), authSupport,
permissionMenuService, dataReadScope);
permissionMenuService);
AdminUserEntity operator = new AdminUserEntity();
operator.setId(7L);
HttpServletRequest request = mock(HttpServletRequest.class);
when(authSupport.requireUser(request)).thenReturn(operator);
when(authSupport.currentRole(operator)).thenReturn("super_admin");
// 超管显式传 company_id=5 ⇒ 超管筛选把 5 交出来(不传时给 null=全量,同一行为样本家族)。
when(dataReadScope.superAdminScopedCompanyId(operator, 5L)).thenReturn(5L);
JdProductPageVo pageVo = new JdProductPageVo();
pageVo.setItems(List.of());
pageVo.setTotal(0L);
pageVo.setPage(1L);
pageVo.setPageSize((long) PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT);
when(queryService.page(1L, 20L, 5L, null, null, null, null, null, null, null, null)).thenReturn(pageVo);
when(queryService.page(1L, 20L, null, null, null, null, null, null, null, null)).thenReturn(pageVo);
// 2026-11-16 起请求面没有 company_id:任何授权身份看到的都是同一份全量。
ApiResponse<JdProductPageVo> response = controller.page(1L, 20L, null, null, null, null, null,
null, null, null, 5L, request);
null, null, null, request);
verify(dataReadScope).superAdminScopedCompanyId(operator, 5L);
verify(queryService).page(1L, 20L, 5L, null, null, null, null, null, null, null, null);
verify(queryService).page(1L, 20L, null, null, null, null, null, null, null, null);
assertEquals(Boolean.TRUE, response.isSuccess(), "拒绝走 403 业务码,放行必须是 success 信封(B80-03)");
assertEquals(pageVo, response.getData());
}
@Test
void 类目下拉端点走同一超管筛选口径并回选项集() {
void 类目下拉端点走同一鉴权正门并回全平台选项集() {
JdProductQueryService queryService = mock(JdProductQueryService.class);
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
DataReadScope dataReadScope = mock(DataReadScope.class);
AdminJdProductController controller = new AdminJdProductController(
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class), authSupport,
mock(PermissionMenuService.class), dataReadScope);
mock(PermissionMenuService.class));
AdminUserEntity operator = new AdminUserEntity();
operator.setId(7L);
HttpServletRequest request = mock(HttpServletRequest.class);
when(authSupport.requireUser(request)).thenReturn(operator);
when(authSupport.currentRole(operator)).thenReturn("super_admin");
when(dataReadScope.superAdminScopedCompanyId(operator, 5L)).thenReturn(5L);
JdProductCategoryVo row = new JdProductCategoryVo();
row.setName("艺考形体服");
row.setProductCount(85L);
when(queryService.categories(5L)).thenReturn(List.of(row));
when(queryService.categories()).thenReturn(List.of(row));
ApiResponse<List<JdProductCategoryVo>> response = controller.categories(5L, request);
ApiResponse<List<JdProductCategoryVo>> response = controller.categories(request);
verify(dataReadScope).superAdminScopedCompanyId(operator, 5L);
verify(queryService).categories(5L);
verify(queryService).categories();
assertEquals(Boolean.TRUE, response.isSuccess(), "类目下拉与列表同一鉴权正门(200 信封)");
assertEquals("艺考形体服", response.getData().get(0).getName(), "选项=已落库行的末级类目名");
assertEquals("艺考形体服", response.getData().get(0).getName(), "选项=已落库行的末级类目名(全平台去重)");
assertEquals(85L, response.getData().get(0).getProductCount());
}
@@ -242,10 +242,9 @@ class AdminJdProductControllerTest {
void 控制器详情走同一鉴权正门并回详情且不问公司() {
JdProductQueryService queryService = mock(JdProductQueryService.class);
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
DataReadScope dataReadScope = mock(DataReadScope.class);
AdminJdProductController controller = new AdminJdProductController(
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class), authSupport,
mock(PermissionMenuService.class), dataReadScope);
mock(PermissionMenuService.class));
AdminUserEntity operator = new AdminUserEntity();
operator.setId(7L);
@@ -258,8 +257,7 @@ class AdminJdProductControllerTest {
ApiResponse<JdProductDetailVo> response = controller.detail(11L, request);
// 公共库详情没有公司维度:DataReadScope 不参与(防有人把公司收口接回来)。
verifyNoInteractions(dataReadScope);
// 公共库详情没有公司维度(DataReadScope 反向钉在结构判据支,2026-11-16 已整批摘除)。
verify(queryService).detail(11L);
assertEquals(Boolean.TRUE, response.isSuccess());
assertEquals(detailVo, response.getData());
@@ -270,10 +268,9 @@ class AdminJdProductControllerTest {
JdProductQueryService queryService = mock(JdProductQueryService.class);
JdProductDeleteService deleteService = mock(JdProductDeleteService.class);
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
DataReadScope dataReadScope = mock(DataReadScope.class);
AdminJdProductController controller = new AdminJdProductController(
queryService, deleteService, mock(JdProductUpdateService.class), authSupport,
mock(PermissionMenuService.class), dataReadScope);
mock(PermissionMenuService.class));
AdminUserEntity operator = new AdminUserEntity();
operator.setId(7L);
@@ -288,8 +285,7 @@ class AdminJdProductControllerTest {
ApiResponse<JdProductDeleteVo> response = controller.delete(11L, request);
// 公共库写侧没有公司维度:不收 company_id、DataReadScope 不参与。
verifyNoInteractions(dataReadScope);
// 公共库写侧没有公司维度(结构判据支反向钉 company_id/DataReadScope 不得回流)。
verify(deleteService).delete(List.of(11L));
assertEquals(Boolean.TRUE, response.isSuccess());
assertEquals(9, response.getData().getObjectsDeleted());
@@ -300,10 +296,9 @@ class AdminJdProductControllerTest {
JdProductQueryService queryService = mock(JdProductQueryService.class);
JdProductDeleteService deleteService = mock(JdProductDeleteService.class);
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
DataReadScope dataReadScope = mock(DataReadScope.class);
AdminJdProductController controller = new AdminJdProductController(
queryService, deleteService, mock(JdProductUpdateService.class), authSupport,
mock(PermissionMenuService.class), dataReadScope);
mock(PermissionMenuService.class));
AdminUserEntity operator = new AdminUserEntity();
operator.setId(7L);
@@ -326,23 +321,23 @@ class AdminJdProductControllerTest {
JdProductQueryService service = new JdProductQueryService(mapper, mock(JdProductImageMapper.class),
mock(com.nanri.aiimage.modules.jd.mapper.JdProductSkuMapper.class),
mock(com.nanri.aiimage.modules.jd.mapper.JdProductGroupMapper.class));
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
// page=0 / size=null ⇒ 归一为第 1 页、默认 20 条;offset = 0。
service.page(0L, null, null, null, null, null, null, null, null, null, null);
service.page(0L, null, null, null, null, null, null, null, null, null);
ArgumentCaptor<Long> offset = ArgumentCaptor.forClass(Long.class);
ArgumentCaptor<Integer> limit = ArgumentCaptor.forClass(Integer.class);
verify(mapper).selectProductPage(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
isNull(), isNull(), isNull(), offset.capture(), limit.capture());
isNull(), isNull(), offset.capture(), limit.capture());
assertEquals(0L, offset.getValue());
assertEquals(PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT, limit.getValue());
// page=Long.MAX_VALUE / size=500 ⇒ 钳到 10_000 页、100 条;乘积 999_900 不得变负(铁律 15)。
service.page(Long.MAX_VALUE, 500L, null, null, null, null, null, null, null, null, null);
service.page(Long.MAX_VALUE, 500L, null, null, null, null, null, null, null, null);
ArgumentCaptor<Long> offsetMax = ArgumentCaptor.forClass(Long.class);
ArgumentCaptor<Integer> limitMax = ArgumentCaptor.forClass(Integer.class);
verify(mapper, times(2)).selectProductPage(any(), any(), any(), any(), any(), any(),
any(), any(), any(), offsetMax.capture(), limitMax.capture());
any(), any(), offsetMax.capture(), limitMax.capture());
assertEquals(999_900L, offsetMax.getValue(), "(page-1)*page_size 最大 999_900,钳制后不得溢出变负");
assertEquals(100, limitMax.getValue());
}
@@ -356,9 +351,9 @@ class AdminJdProductControllerTest {
LocalDateTime from = LocalDateTime.of(2026, 11, 14, 12, 0);
LocalDateTime to = LocalDateTime.of(2026, 11, 14, 8, 0);
BusinessException ex = assertThrows(BusinessException.class,
() -> service.page(1L, 20L, null, null, null, null, null, null, null, from, to));
() -> service.page(1L, 20L, null, null, null, null, null, null, from, to));
assertTrue(ex.getMessage().contains("开始时间不能晚于结束时间"), "倒挂时间按业务异常拒绝");
verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any());
verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any(), any(), any());
}
@Test
@@ -367,37 +362,37 @@ class AdminJdProductControllerTest {
JdProductQueryService service = new JdProductQueryService(mapper, mock(JdProductImageMapper.class),
mock(com.nanri.aiimage.modules.jd.mapper.JdProductSkuMapper.class),
mock(com.nanri.aiimage.modules.jd.mapper.JdProductGroupMapper.class));
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(0L);
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(0L);
// 超管显式传 5 ⇒ 按公司 5 筛(收窄);groupId ≤0 按没选分组处理;文本两侧空白剥掉。
// groupId ≤0 按没选分组处理;文本两侧空白剥掉。
// 类目(京麦末级类目名)走同一过滤面:传值原样直传、空白归 null。
service.page(1L, 20L, 5L, " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 0L, null, null, null, null);
verify(mapper).countProducts(eq(5L), eq("SKU-1"), eq("连衣裙"),
service.page(1L, 20L, " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 0L, null, null, null, null);
verify(mapper).countProducts(eq("SKU-1"), eq("连衣裙"),
eq("艺考形体服"), isNull(), isNull(), isNull(), isNull(), isNull());
// 全量(scopedCompanyId=null)⇒ companyId 不过滤。
service.page(1L, 20L, null, null, null, null, null, null, null, null, null);
// 全量口径(2026-11-16 起读侧无公司维)⇒ 过滤面全 null。
service.page(1L, 20L, null, null, null, null, null, null, null, null);
verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
isNull(), isNull(), isNull(), isNull());
isNull(), isNull(), isNull());
// 未分类范围(店铺分类弹窗「未分类」页签):ungrouped=true 原样下推到 SQL 侧。
service.page(1L, 20L, null, null, null, null, null, Boolean.TRUE, null, null, null);
verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
eq(Boolean.TRUE), isNull(), isNull(), isNull());
service.page(1L, 20L, null, null, null, null, Boolean.TRUE, null, null, null);
verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), eq(Boolean.TRUE),
isNull(), isNull(), isNull());
// ungrouped=false / 缺省按不过滤处理(Filter 归一成 null,不进 IS NULL 分支);
// 与②「全量」那发同形状,累计 2 次。
service.page(1L, 20L, null, null, null, null, null, Boolean.FALSE, null, null, null);
service.page(1L, 20L, null, null, null, null, Boolean.FALSE, null, null, null);
verify(mapper, times(2)).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
isNull(), isNull(), isNull(), isNull());
isNull(), isNull(), isNull());
// 已分类档(页面筛选行「分类状态」=已分类,2026-11-15 客户口径「分类好的可以不显示」反选):
// grouped=true 原样下推到 SQL 侧(group_id IS NOT NULL),ungrouped 不动。
service.page(1L, 20L, null, null, null, null, null, null, Boolean.TRUE, null, null);
service.page(1L, 20L, null, null, null, null, null, Boolean.TRUE, null, null);
verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
isNull(), eq(Boolean.TRUE), isNull(), isNull());
eq(Boolean.TRUE), isNull(), isNull());
// grouped=false / 缺省同口径归一成 null(不进 IS NOT NULL 分支);与②「全量」累计 3 次。
service.page(1L, 20L, null, null, null, null, null, null, Boolean.FALSE, null, null);
service.page(1L, 20L, null, null, null, null, null, Boolean.FALSE, null, null);
verify(mapper, times(3)).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
isNull(), isNull(), isNull(), isNull());
isNull(), isNull(), isNull());
}
@Test
@@ -405,10 +400,9 @@ class AdminJdProductControllerTest {
JdProductQueryService queryService = mock(JdProductQueryService.class);
JdProductUpdateService updateService = mock(JdProductUpdateService.class);
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
DataReadScope dataReadScope = mock(DataReadScope.class);
AdminJdProductController controller = new AdminJdProductController(
queryService, mock(JdProductDeleteService.class), updateService, authSupport,
mock(PermissionMenuService.class), dataReadScope);
mock(PermissionMenuService.class));
AdminUserEntity operator = new AdminUserEntity();
operator.setId(7L);
@@ -423,8 +417,7 @@ class AdminJdProductControllerTest {
body.setGroupId(3L);
ApiResponse<Integer> response = controller.batchAssignGroup(body, request);
// 公共库写侧没有公司维度:不收 company_id、DataReadScope 不参与。
verifyNoInteractions(dataReadScope);
// 公共库写侧没有公司维度(结构判据支反向钉 company_id/DataReadScope 不得回流)。
verify(updateService).assignGroup(List.of(11L, 12L), 3L);
assertEquals(Boolean.TRUE, response.isSuccess(), "放行必须是 success 信封(B80-03)");
assertEquals(2, response.getData(), "回执=实际更新的行数");
@@ -598,8 +591,8 @@ class AdminJdProductControllerTest {
grouped.setGroupId(3L);
JdProductEntity missing = productEntity(2L);
missing.setGroupId(99L);
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(2L);
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(), any(),
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(2L);
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(),
anyLong(), anyInt())).thenReturn(List.of(grouped, missing));
com.nanri.aiimage.modules.jd.model.entity.JdProductGroupEntity group =
new com.nanri.aiimage.modules.jd.model.entity.JdProductGroupEntity();
@@ -607,7 +600,7 @@ class AdminJdProductControllerTest {
group.setName("秋冬款");
when(groupMapper.selectBatchIds(any())).thenReturn(List.of(group));
JdProductPageVo vo = service.page(1L, 20L, 5L, null, null, null, null, null, null, null, null);
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, null, null);
assertEquals("秋冬款", vo.getItems().get(0).getGroupName(), "行集 group_id 一次取齐分组名(无逐行查询)");
assertNull(vo.getItems().get(1).getGroupName(), "分组已删=不猜名字(铁律 30),前端展示 -");