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>