feat(jd): 京东数据库页分类状态快筛(已分类/未分类)——classified 参数按当前分组在 SQL 侧 EXISTS/NOT EXISTS 下推(铁律20同形,判据与读侧填分类列同形);后管工具栏「全部分类」旁三档下拉选中即查;与 11-16 撤掉的旧 grouped/ungrouped 无关(那两档读已停用列,控制器仍拒收)。判据:XML 两分支谓词/成对直传/classified 参数在册绊线+纯测试三档+挂载 2 例

This commit is contained in:
2026-11-17 16:58:28 +08:00
parent 20ee73349e
commit d25c91f6da
10 changed files with 220 additions and 43 deletions
@@ -120,6 +120,9 @@ 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 = "分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」):"
+ "true=当前分组下有分类,false=未分类,缺省=全部;按 V203 归属表 SQL 侧下推")
@RequestParam(name = "classified", required = false) Boolean classified,
HttpServletRequest request) {
RequestOperator operator = requireJdAccess(request);
if (request.getParameter("grouped") != null || request.getParameter("ungrouped") != null) {
@@ -131,7 +134,8 @@ public class AdminJdProductController {
requireVisibleCategory(scope, groupId);
}
return ApiResponse.success(jdProductQueryService.page(page, pageSize,
productCode, titleKeyword, category, groupId, syncedFrom, syncedTo, scopedOwnerGroupId));
productCode, titleKeyword, category, groupId, syncedFrom, syncedTo, classified,
scopedOwnerGroupId));
}
@GetMapping("/categories")
@@ -49,13 +49,18 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
* 「分类不要了,全部整合到类目里」撤掉(独立「分类」筛选框前端下线,
* {@code groupId} 改由类目面板「自定义分类」选中驱动)。
* 店铺名过滤参数已随 2026-11-15 客户口径「店铺不需要」同窗撤掉(DB 列与详情/回传链不动)。
* {@code classified}+{@code ownerGroupId}(2026-11-17 用户口径「加个已分类和未分类的筛选」):
* 按 V203 归属表 EXISTS/NOT EXISTS 快筛分类状态,NULL=不过滤;与 11-16 撤掉的旧
* grouped/ungrouped(读已停用的 biz_jd_product.group_id 列)不是一回事。
*/
long countProducts(@Param("productCode") String productCode,
@Param("titleKeyword") String titleKeyword,
@Param("category") String category,
@Param("groupId") Long groupId,
@Param("syncedFrom") LocalDateTime syncedFrom,
@Param("syncedTo") LocalDateTime syncedTo);
@Param("syncedTo") LocalDateTime syncedTo,
@Param("classified") Boolean classified,
@Param("ownerGroupId") Long ownerGroupId);
/**
* 商品上架配额计数({@code JdPublishQuotaService}):按 owner uid 集(管理员本人+
@@ -95,6 +100,8 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
@Param("groupId") Long groupId,
@Param("syncedFrom") LocalDateTime syncedFrom,
@Param("syncedTo") LocalDateTime syncedTo,
@Param("classified") Boolean classified,
@Param("ownerGroupId") Long ownerGroupId,
@Param("offset") long offset,
@Param("limit") int limit);
@@ -79,14 +79,18 @@ public class JdProductQueryService {
* 分页查询商品行({@code synced_at} 倒序)。
*
* <p>过滤面:商品编码 contains、标题关键词 contains、类目 eq、分组 eq(2026-11-16 起
* 由类目面板「自定义分类」选中驱动)、同步起止(datetime 闭区间)。
* 未分类/已分类两档(ungrouped/grouped)与独立「分类」筛选框随同日口径
* 「分类不要了,全部整合到类目里」整批撤掉。
* 由类目面板「自定义分类」选中驱动)、同步起止(datetime 闭区间)、分类状态档
* {@code classified}(2026-11-17 用户口径「加个已分类和未分类的筛选」:true=当前分组下
* 有分类、false=没有、null=全部;按 V203 归属表 EXISTS/NOT EXISTS 在 SQL 侧下推,
* 判据与 {@link #fillGroupNames} 填分类列的条件同形——「筛选说未分类的行,列表分类列
* 也必须是未分类」)。
* 2026-11-16 撤掉的旧 ungrouped/grouped 两档读的是已停用的 biz_jd_product.group_id 列,
* 与本档不是一回事;独立「分类」筛选框的撤掉口径不变。
* 公司维过滤已随 2026-11-16 摘公司 tab 整批撤掉(全平台公共)。</p>
*/
public JdProductPageVo page(Long page, Long pageSize,
String productCode, String titleKeyword, String category, Long groupId,
LocalDateTime syncedFrom, LocalDateTime syncedTo, Long ownerGroupId) {
LocalDateTime syncedFrom, LocalDateTime syncedTo, Boolean classified, Long ownerGroupId) {
if (syncedFrom != null && syncedTo != null && syncedFrom.isAfter(syncedTo)) {
throw new BusinessException("开始时间不能晚于结束时间");
}
@@ -94,14 +98,14 @@ public class JdProductQueryService {
long safeSize = pageSize == null ? PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT
: Math.min(Math.max(pageSize, 1), MAX_PAGE_SIZE);
Filter filter = filter(productCode, titleKeyword, category,
groupId, syncedFrom, syncedTo);
groupId, syncedFrom, syncedTo, classified);
long total = jdProductMapper.countProducts(filter.productCode(),
filter.titleKeyword(), filter.category(), filter.groupId(),
filter.syncedFrom(), filter.syncedTo());
filter.syncedFrom(), filter.syncedTo(), filter.classified(), ownerGroupId);
List<JdProductEntity> rows = total <= 0 ? List.of()
: jdProductMapper.selectProductPage(filter.productCode(),
filter.titleKeyword(), filter.category(), filter.groupId(),
filter.syncedFrom(), filter.syncedTo(),
filter.syncedFrom(), filter.syncedTo(), filter.classified(), ownerGroupId,
(safePage - 1) * safeSize, (int) safeSize);
List<JdProductListItemVo> items = rows.stream().map(this::toListItem).toList();
fillGroupNames(items, ownerGroupId);
@@ -176,18 +180,19 @@ public class JdProductQueryService {
// ---------------------------------------------------------------- 过滤面
/** 服务侧过滤面归一:groupId ≤0 按没选处理,文本 trim 后空串归 null(无公司维,2026-11-16 摘)。 */
/** 服务侧过滤面归一:groupId ≤0 按没选处理,文本 trim 后空串归 null(无公司维,2026-11-16 摘);
* classified 原样直传(null=不过滤该面,2026-11-17 分类状态快筛)。 */
private record Filter(String productCode, String titleKeyword,
String category, Long groupId,
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
LocalDateTime syncedFrom, LocalDateTime syncedTo, Boolean classified) {
}
private static Filter filter(String productCode, String titleKeyword,
String category, Long groupId,
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
LocalDateTime syncedFrom, LocalDateTime syncedTo, Boolean classified) {
Long safeGroupId = groupId != null && groupId > 0 ? groupId : null;
return new Filter(trimToNull(productCode), trimToNull(titleKeyword),
trimToNull(category), safeGroupId, syncedFrom, syncedTo);
trimToNull(category), safeGroupId, syncedFrom, syncedTo, classified);
}
// ---------------------------------------------------------------- 列表/详情搬运
@@ -122,6 +122,29 @@
WHERE a.product_id = p.id AND a.category_id = #{groupId}
)
</if>
<!-- 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」):已分类=在
「当前数据权限分组」(owner_group_id)下有 category_id 非空的归属行——与读侧
fillGroupNames 把分类列填出来的条件同形;未分类=NOT EXISTS。谓词 SQL 侧下推
(铁律 20 同形,不得 Java 侧对已取页 filter)。owner_group_id 为 NULL(作用域
无可分组)时 EXISTS 恒假、NOT EXISTS 恒真——与列表「分类列全空」口径天然一致,
不需要服务侧特判。与 2026-11-16 撤掉的旧 grouped/ungrouped 不是一回事:那两档
读的是已停用的 biz_jd_product.group_id 列,本档读 V203 归属表。 -->
<if test="classified != null">
<choose>
<when test="classified == true">
AND EXISTS (
SELECT 1 FROM biz_jd_product_group_assign cs
WHERE cs.product_id = p.id AND cs.owner_group_id = #{ownerGroupId} AND cs.category_id IS NOT NULL
)
</when>
<otherwise>
AND NOT EXISTS (
SELECT 1 FROM biz_jd_product_group_assign cs
WHERE cs.product_id = p.id AND cs.owner_group_id = #{ownerGroupId} AND cs.category_id IS NOT NULL
)
</otherwise>
</choose>
</if>
<if test="syncedFrom != null">AND p.synced_at &gt;= #{syncedFrom}</if>
<if test="syncedTo != null">AND p.synced_at &lt;= #{syncedTo}</if>
</sql>