feat(jd): 店铺分类弹窗新建收成+图标/排序输入下线;京东数据库下线店铺筛选与列(后端 shop_name 参数同窗撤)

This commit is contained in:
2026-11-15 23:58:52 +08:00
parent 6818f9777b
commit 4506253989
12 changed files with 135 additions and 131 deletions
@@ -67,8 +67,9 @@ import java.util.List;
* 请求里的 company_id 传参已随公共化从写侧端点摘除。</p>
*
* <p>导出端点已随 2026-11-15 客户口径「导出也不用」整段下线(控制器/服务/mapper 参数一起删);
* {@code sale_status} 查询参数同窗撤掉(商品状态筛选框已从前端下线)。DB 列
* {@code biz_jd_product.sale_status} 与详情/回传链不动。</p>
* {@code sale_status} 查询参数同窗撤掉(商品状态筛选框已从前端下线)。店铺筛选参数
* {@code shop_name} 同日客户口径「店铺不需要」同窗撤掉(前端筛选框与列下线;DB 列
* {@code biz_jd_product.shop_name} 与详情/回传链不动)。</p>
*/
@RestController
@RequiredArgsConstructor
@@ -96,7 +97,6 @@ public class AdminJdProductController {
public ApiResponse<JdProductPageVo> page(
@Parameter(description = "页码") @RequestParam(name = "page", defaultValue = PageDefaults.FIRST_PAGE) Long page,
@Parameter(description = "每页数量") @RequestParam(name = "page_size", defaultValue = PageDefaults.JD_PRODUCTS_PAGE_SIZE) Long pageSize,
@Parameter(description = "店铺名(包含匹配)") @RequestParam(name = "shop_name", required = false) String shopName,
@Parameter(description = "商品编码(包含匹配)") @RequestParam(name = "product_code", required = false) String productCode,
@Parameter(description = "标题关键词(包含匹配)") @RequestParam(name = "title_keyword", required = false) String titleKeyword,
@Parameter(description = "类目(京麦末级类目名,eq)") @RequestParam(name = "category", required = false) String category,
@@ -116,7 +116,7 @@ public class AdminJdProductController {
// 公司维度只剩超管的公司 tab 筛选(superAdminScopedCompanyId):超管显式传才收窄,
// 非超管传什么都不收——公共库对每一家管理员都是同一份全量。
Long scopedCompanyId = dataReadScope.superAdminScopedCompanyId(user, companyId);
return ApiResponse.success(jdProductQueryService.page(page, pageSize, scopedCompanyId, shopName,
return ApiResponse.success(jdProductQueryService.page(page, pageSize, scopedCompanyId,
productCode, titleKeyword, category, groupId, ungrouped, grouped, syncedFrom, syncedTo));
}
@@ -42,13 +42,13 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
/**
* 后管只读页总数(Phase 5,v1.4):与 {@link #selectProductPage} 同一过滤面
* (公司/店铺名/商品编码/标题关键词/类目/分组/未分类/已分类/同步起止,全部 SQL 侧下推,
* (公司/商品编码/标题关键词/类目/分组/未分类/已分类/同步起止,全部 SQL 侧下推,
* 铁律 20)。{@code companyId}/{@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("shopName") String shopName,
@Param("productCode") String productCode,
@Param("titleKeyword") String titleKeyword,
@Param("category") String category,
@@ -91,7 +91,6 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
* {@code (page-1)*page_size} 溢出(铁律 15),mapper 不做第二次换算,避免两处各算各的。</p>
*/
List<JdProductEntity> selectProductPage(@Param("companyId") Long companyId,
@Param("shopName") String shopName,
@Param("productCode") String productCode,
@Param("titleKeyword") String titleKeyword,
@Param("category") String category,
@@ -47,7 +47,8 @@ import java.util.Map;
* 主表高频列直接从 entity 映射,不走 JSON。</p>
*
* <p>导出(byte[] xlsx)已随 2026-11-15 客户口径「导出也不用」整段下线,控制器端点同窗删;
* {@code sale_status} 过滤参数同窗撤掉(前端筛选框下线),DB 列与详情/回传链不动。</p>
* {@code sale_status} 过滤参数同窗撤掉(前端筛选框下线);店铺筛选参数同日客户口径
* 「店铺不需要」同窗撤掉(DB 列与详情/回传链不动)。</p>
*/
@Slf4j
@Service
@@ -74,12 +75,12 @@ public class JdProductQueryService {
/**
* 分页查询商品行({@code synced_at} 倒序)。
*
* <p>过滤面:公司(物化列 eq)、店铺名 contains、商品编码 contains、标题关键词 contains、
* <p>过滤面:公司(物化列 eq)、商品编码 contains、标题关键词 contains、
* 类目 eq、分组 eq、未分类(group_id IS NULL,店铺分类弹窗「未分类」范围)、
* 已分类(group_id IS NOT NULL,页面筛选行「分类状态」档,2026-11-15 客户口径
* 「查询已分类的跟未分类,分类好的可以不显示」)、同步起止(datetime 闭区间)。</p>
*/
public JdProductPageVo page(Long page, Long pageSize, Long scopedCompanyId, String shopName,
public JdProductPageVo page(Long page, Long pageSize, Long scopedCompanyId,
String productCode, String titleKeyword, String category, Long groupId, Boolean ungrouped,
Boolean grouped, LocalDateTime syncedFrom, LocalDateTime syncedTo) {
if (syncedFrom != null && syncedTo != null && syncedFrom.isAfter(syncedTo)) {
@@ -88,13 +89,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, shopName, productCode, titleKeyword, category,
Filter filter = filter(scopedCompanyId, productCode, titleKeyword, category,
groupId, ungrouped, grouped, syncedFrom, syncedTo);
long total = jdProductMapper.countProducts(filter.companyId(), filter.shopName(), filter.productCode(),
long total = jdProductMapper.countProducts(filter.companyId(), 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.shopName(), filter.productCode(),
: jdProductMapper.selectProductPage(filter.companyId(), filter.productCode(),
filter.titleKeyword(), filter.category(), filter.groupId(), filter.ungrouped(),
filter.grouped(), filter.syncedFrom(), filter.syncedTo(),
(safePage - 1) * safeSize, (int) safeSize);
@@ -173,12 +174,12 @@ public class JdProductQueryService {
// ---------------------------------------------------------------- 过滤面
/** 服务侧过滤面归一:companyId/groupId ≤0 按没选处理,文本 trim 后空串归 null。 */
private record Filter(Long companyId, String shopName, String productCode, String titleKeyword,
private record Filter(Long companyId, String productCode, String titleKeyword,
String category, Long groupId, Boolean ungrouped, Boolean grouped,
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
}
private static Filter filter(Long scopedCompanyId, String shopName, String productCode, String titleKeyword,
private static Filter filter(Long scopedCompanyId, String productCode, String titleKeyword,
String category, Long groupId, Boolean ungrouped, Boolean grouped,
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
Long companyId = scopedCompanyId != null && scopedCompanyId > 0 ? scopedCompanyId : null;
@@ -188,7 +189,7 @@ public class JdProductQueryService {
// 已分类同口径:true=只看 group_id IS NOT NULL 的行;与未分类同选时 SQL 侧两谓词相与=空集
// (前端下拉是单选,正常到不了这个组合)。
Boolean safeGrouped = Boolean.TRUE.equals(grouped) ? Boolean.TRUE : null;
return new Filter(companyId, trimToNull(shopName), trimToNull(productCode), trimToNull(titleKeyword),
return new Filter(companyId, trimToNull(productCode), trimToNull(titleKeyword),
trimToNull(category), safeGroupId, safeUngrouped, safeGrouped, syncedFrom, syncedTo);
}
@@ -100,16 +100,16 @@
)
</select>
<!-- 后管只读页(Phase 5,v1.4)过滤面:公司(物化列 eq)、店铺名/商品编码/标题关键词
<!-- 后管只读页(Phase 5,v1.4)过滤面:公司(物化列 eq)、商品编码/标题关键词
(contains LIKE)、类目 eq、分组 eq、未分类(group_id IS NULL,店铺分类弹窗
「未分类」范围)、已分类(group_id IS NOT NULL,页面筛选行「分类状态」档,
2026-11-15 客户口径「查询已分类的跟未分类,分类好的可以不显示」)、
同步起止(datetime 闭区间)。
sale_status 筛选随 2026-11-15 客户口径撤掉(前端筛选框下线;列本身与详情/回传链不动)。
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="shopName != null and shopName != ''">AND p.shop_name LIKE CONCAT('%', #{shopName}, '%')</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>
@@ -127,12 +127,14 @@ class AdminJdProductControllerTest {
@Test
void 分页参数snake且带默认值() throws IOException {
String source = stripComments(Files.readString(CONTROLLER));
for (String param : List.of("page_size", "shop_name", "product_code", "title_keyword",
for (String param : List.of("page_size", "product_code", "title_keyword",
"group_id", "ungrouped", "grouped", "synced_from", "synced_to", "company_id")) {
assertTrue(source.contains(param), "查询参数必须 snake_case:" + param);
}
// 商品状态筛选框已随 2026-11-15 客户口径从前端下线 ⇒ 服务端同名参数一起撤(反向钉住防回潜)。
assertFalse(source.contains("\"sale_status\""), "sale_status 筛选参数必须已删除,不得回潜");
// 店铺筛选同日客户口径「店铺不需要」下线 ⇒ shop_name 参数同窗撤(反向钉住防回潜)。
assertFalse(source.contains("shop_name"), "shop_name 筛选参数必须已删除,不得回潜(店铺列/详情仍保留)");
assertTrue(source.contains("PageDefaults"), "page/page_size 默认值必须取 PageDefaults"
+ "(page_size 默认 20=PageDefaults.JD_PRODUCTS_PAGE_SIZE);"
+ "page 钳制防 (page-1)*page_size 溢出的行为样本见查询服务钳制支(铁律 15)");
@@ -196,13 +198,13 @@ class AdminJdProductControllerTest {
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, null)).thenReturn(pageVo);
when(queryService.page(1L, 20L, 5L, null, null, null, null, null, null, null, null)).thenReturn(pageVo);
ApiResponse<JdProductPageVo> response = controller.page(1L, 20L, null, null, null, null, null,
null, null, null, null, 5L, request);
null, null, null, 5L, request);
verify(dataReadScope).superAdminScopedCompanyId(operator, 5L);
verify(queryService).page(1L, 20L, 5L, null, null, null, null, null, null, null, null, null);
verify(queryService).page(1L, 20L, 5L, null, null, null, null, null, null, null, null);
assertEquals(Boolean.TRUE, response.isSuccess(), "拒绝走 403 业务码,放行必须是 success 信封(B80-03)");
assertEquals(pageVo, response.getData());
}
@@ -324,23 +326,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(), any())).thenReturn(1L);
when(mapper.countProducts(any(), 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, null);
service.page(0L, null, 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(), isNull(), offset.capture(), limit.capture());
isNull(), 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, null);
service.page(Long.MAX_VALUE, 500L, null, 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(), any(), offsetMax.capture(), limitMax.capture());
any(), any(), any(), offsetMax.capture(), limitMax.capture());
assertEquals(999_900L, offsetMax.getValue(), "(page-1)*page_size 最大 999_900,钳制后不得溢出变负");
assertEquals(100, limitMax.getValue());
}
@@ -354,9 +356,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, null, from, to));
() -> service.page(1L, 20L, null, 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(), any());
verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any());
}
@Test
@@ -365,37 +367,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(), any())).thenReturn(0L);
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(0L);
// 超管显式传 5 ⇒ 按公司 5 筛(收窄);groupId ≤0 按没选分组处理;文本两侧空白剥掉。
// 类目(京麦末级类目名)走同一过滤面:传值原样直传、空白归 null。
service.page(1L, 20L, 5L, " 店铺甲 ", " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 0L, null, null, null, null);
verify(mapper).countProducts(eq(5L), eq("店铺甲"), eq("SKU-1"), eq("连衣裙"),
service.page(1L, 20L, 5L, " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 0L, null, null, null, null);
verify(mapper).countProducts(eq(5L), 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, null);
service.page(1L, 20L, null, null, null, null, null, null, null, null, null);
verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
isNull(), isNull(), isNull(), isNull(), isNull());
isNull(), isNull(), isNull(), isNull());
// 未分类范围(店铺分类弹窗「未分类」页签):ungrouped=true 原样下推到 SQL 侧。
service.page(1L, 20L, null, null, null, null, null, null, Boolean.TRUE, null, null, null);
service.page(1L, 20L, null, null, null, null, null, Boolean.TRUE, null, null, null);
verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
isNull(), eq(Boolean.TRUE), 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, null, Boolean.FALSE, null, null, null);
service.page(1L, 20L, null, 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(), isNull(), isNull());
// 已分类档(页面筛选行「分类状态」=已分类,2026-11-15 客户口径「分类好的可以不显示」反选):
// grouped=true 原样下推到 SQL 侧(group_id IS NOT NULL),ungrouped 不动。
service.page(1L, 20L, null, null, null, null, null, null, null, Boolean.TRUE, null, null);
service.page(1L, 20L, null, null, null, null, null, null, Boolean.TRUE, null, null);
verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
isNull(), isNull(), eq(Boolean.TRUE), isNull(), isNull());
isNull(), eq(Boolean.TRUE), isNull(), isNull());
// grouped=false / 缺省同口径归一成 null(不进 IS NOT NULL 分支);与②「全量」累计 3 次。
service.page(1L, 20L, null, null, null, null, null, null, null, Boolean.FALSE, null, null);
service.page(1L, 20L, null, 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(), isNull(), isNull());
}
@Test
@@ -596,8 +598,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(), any())).thenReturn(2L);
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(),
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(),
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();
@@ -605,7 +607,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, null);
JdProductPageVo vo = service.page(1L, 20L, 5L, null, null, null, null, null, null, null, null);
assertEquals("秋冬款", vo.getItems().get(0).getGroupName(), "行集 group_id 一次取齐分组名(无逐行查询)");
assertNull(vo.getItems().get(1).getGroupName(), "分组已删=不猜名字(铁律 30),前端展示 -");