feat(jd): 整合自定义分类并保护商品数据
This commit is contained in:
+10
-6
@@ -71,6 +71,11 @@ import java.util.List;
|
||||
* {@code sale_status} 查询参数同窗撤掉(商品状态筛选框已从前端下线)。店铺筛选参数
|
||||
* {@code shop_name} 同日客户口径「店铺不需要」同窗撤掉(前端筛选框与列下线;DB 列
|
||||
* {@code biz_jd_product.shop_name} 与详情/回传链不动)。</p>
|
||||
*
|
||||
* <p><b>分类并入类目(2026-11-16 用户口径「分类不要了,全部整合到类目里」)</b>:
|
||||
* 分页查询的 {@code ungrouped}/{@code grouped}(分类状态档)整批撤掉;独立「分类」筛选框
|
||||
* 前端下线,{@code group_id} 保留、改由类目面板「自定义分类」选中驱动(存量分组数据由
|
||||
* V201 清空,分组表保留作自定义分类存储)。</p>
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -100,19 +105,18 @@ public class AdminJdProductController {
|
||||
@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,
|
||||
@Parameter(description = "分组 id") @RequestParam(name = "group_id", required = false) Long groupId,
|
||||
@Parameter(description = "只看未分类(group_id IS NULL,店铺分类弹窗「未分类」范围)")
|
||||
@RequestParam(name = "ungrouped", required = false) Boolean ungrouped,
|
||||
@Parameter(description = "只看已分类(group_id IS NOT NULL,页面筛选行「分类状态」档)")
|
||||
@RequestParam(name = "grouped", required = false) Boolean grouped,
|
||||
@Parameter(description = "自定义分类 id(类目面板「自定义分类」选中驱动)") @RequestParam(name = "group_id", required = false) Long groupId,
|
||||
@Parameter(description = "同步开始时间(包含,ISO datetime)")
|
||||
@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,
|
||||
HttpServletRequest request) {
|
||||
requireJdAccess(request);
|
||||
if (request.getParameter("grouped") != null || request.getParameter("ungrouped") != null) {
|
||||
throw new BusinessException("页面版本已更新,请刷新页面后重新查询");
|
||||
}
|
||||
return ApiResponse.success(jdProductQueryService.page(page, pageSize,
|
||||
productCode, titleKeyword, category, groupId, ungrouped, grouped, syncedFrom, syncedTo));
|
||||
productCode, titleKeyword, category, groupId, syncedFrom, syncedTo));
|
||||
}
|
||||
|
||||
@GetMapping("/categories")
|
||||
|
||||
@@ -42,19 +42,18 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
|
||||
|
||||
/**
|
||||
* 后管只读页总数(Phase 5,v1.4):与 {@link #selectProductPage} 同一过滤面
|
||||
* (商品编码/标题关键词/类目/分组/未分类/已分类/同步起止,全部 SQL 侧下推,
|
||||
* 铁律 20)。公司维过滤已随 2026-11-16「删除掉公司 tab,参考品牌数据库」撤掉
|
||||
* (商品编码/标题关键词/类目/自定义分类/同步起止,全部 SQL 侧下推,铁律 20)。
|
||||
* 公司维过滤已随 2026-11-16「删除掉公司 tab,参考品牌数据库」撤掉
|
||||
* (数据全平台公共);{@code groupId} 为空或 ≤0=不过滤该面;
|
||||
* {@code ungrouped=true}=只看未分类行(group_id IS NULL,店铺分类弹窗「未分类」范围);
|
||||
* {@code grouped=true}=只看已分类行(group_id IS NOT NULL,页面筛选行「分类状态」档)。
|
||||
* {@code ungrouped}/{@code grouped} 两档(未分类/已分类)已随同日口径
|
||||
* 「分类不要了,全部整合到类目里」撤掉(独立「分类」筛选框前端下线,
|
||||
* {@code groupId} 改由类目面板「自定义分类」选中驱动)。
|
||||
* 店铺名过滤参数已随 2026-11-15 客户口径「店铺不需要」同窗撤掉(DB 列与详情/回传链不动)。
|
||||
*/
|
||||
long countProducts(@Param("productCode") String productCode,
|
||||
@Param("titleKeyword") String titleKeyword,
|
||||
@Param("category") String category,
|
||||
@Param("groupId") Long groupId,
|
||||
@Param("ungrouped") Boolean ungrouped,
|
||||
@Param("grouped") Boolean grouped,
|
||||
@Param("syncedFrom") LocalDateTime syncedFrom,
|
||||
@Param("syncedTo") LocalDateTime syncedTo);
|
||||
|
||||
@@ -94,8 +93,6 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
|
||||
@Param("titleKeyword") String titleKeyword,
|
||||
@Param("category") String category,
|
||||
@Param("groupId") Long groupId,
|
||||
@Param("ungrouped") Boolean ungrouped,
|
||||
@Param("grouped") Boolean grouped,
|
||||
@Param("syncedFrom") LocalDateTime syncedFrom,
|
||||
@Param("syncedTo") LocalDateTime syncedTo,
|
||||
@Param("offset") long offset,
|
||||
|
||||
+14
-19
@@ -75,15 +75,15 @@ public class JdProductQueryService {
|
||||
/**
|
||||
* 分页查询商品行({@code synced_at} 倒序)。
|
||||
*
|
||||
* <p>过滤面:商品编码 contains、标题关键词 contains、类目 eq、分组 eq、
|
||||
* 未分类(group_id IS NULL,店铺分类弹窗「未分类」范围)、
|
||||
* 已分类(group_id IS NOT NULL,页面筛选行「分类状态」档,2026-11-15 客户口径
|
||||
* 「查询已分类的跟未分类,分类好的可以不显示」)、同步起止(datetime 闭区间)。
|
||||
* <p>过滤面:商品编码 contains、标题关键词 contains、类目 eq、分组 eq(2026-11-16 起
|
||||
* 由类目面板「自定义分类」选中驱动)、同步起止(datetime 闭区间)。
|
||||
* 未分类/已分类两档(ungrouped/grouped)与独立「分类」筛选框随同日口径
|
||||
* 「分类不要了,全部整合到类目里」整批撤掉。
|
||||
* 公司维过滤已随 2026-11-16 摘公司 tab 整批撤掉(全平台公共)。</p>
|
||||
*/
|
||||
public JdProductPageVo page(Long page, Long pageSize,
|
||||
String productCode, String titleKeyword, String category, Long groupId, Boolean ungrouped,
|
||||
Boolean grouped, LocalDateTime syncedFrom, LocalDateTime syncedTo) {
|
||||
String productCode, String titleKeyword, String category, Long groupId,
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
|
||||
if (syncedFrom != null && syncedTo != null && syncedFrom.isAfter(syncedTo)) {
|
||||
throw new BusinessException("开始时间不能晚于结束时间");
|
||||
}
|
||||
@@ -91,14 +91,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, ungrouped, grouped, syncedFrom, syncedTo);
|
||||
groupId, syncedFrom, syncedTo);
|
||||
long total = jdProductMapper.countProducts(filter.productCode(),
|
||||
filter.titleKeyword(), filter.category(), filter.groupId(), filter.ungrouped(),
|
||||
filter.grouped(), filter.syncedFrom(), filter.syncedTo());
|
||||
filter.titleKeyword(), filter.category(), filter.groupId(),
|
||||
filter.syncedFrom(), filter.syncedTo());
|
||||
List<JdProductEntity> rows = total <= 0 ? List.of()
|
||||
: jdProductMapper.selectProductPage(filter.productCode(),
|
||||
filter.titleKeyword(), filter.category(), filter.groupId(), filter.ungrouped(),
|
||||
filter.grouped(), filter.syncedFrom(), filter.syncedTo(),
|
||||
filter.titleKeyword(), filter.category(), filter.groupId(),
|
||||
filter.syncedFrom(), filter.syncedTo(),
|
||||
(safePage - 1) * safeSize, (int) safeSize);
|
||||
List<JdProductListItemVo> items = rows.stream().map(this::toListItem).toList();
|
||||
fillGroupNames(items);
|
||||
@@ -175,21 +175,16 @@ public class JdProductQueryService {
|
||||
|
||||
/** 服务侧过滤面归一:groupId ≤0 按没选处理,文本 trim 后空串归 null(无公司维,2026-11-16 摘)。 */
|
||||
private record Filter(String productCode, String titleKeyword,
|
||||
String category, Long groupId, Boolean ungrouped, Boolean grouped,
|
||||
String category, Long groupId,
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
|
||||
}
|
||||
|
||||
private static Filter filter(String productCode, String titleKeyword,
|
||||
String category, Long groupId, Boolean ungrouped, Boolean grouped,
|
||||
String category, Long groupId,
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
|
||||
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(trimToNull(productCode), trimToNull(titleKeyword),
|
||||
trimToNull(category), safeGroupId, safeUngrouped, safeGrouped, syncedFrom, syncedTo);
|
||||
trimToNull(category), safeGroupId, syncedFrom, syncedTo);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 列表/详情搬运
|
||||
|
||||
+5
-39
@@ -44,11 +44,8 @@ import java.util.Set;
|
||||
* statObject 对撞落 {@code biz_jd_product_image},唯一出口
|
||||
* {@link JdProductImageIngestService#registerTaskImages})→
|
||||
* scope 台账合并写(断点游标 + 批次号 + 累计行数)→
|
||||
* {@code isEnd=true} 时任务落 SUCCESS 并执行<b>覆盖清理</b>:同一店铺里本次没采到、
|
||||
* 所属任务已不在在飞的旧行整行删掉(用户拍板 2026-11-15:重爬同一店铺直接覆盖旧数据)。
|
||||
* 清理只在收尾时做且本次 {@code itemsReceived=0} 不清(B94-01 教训:载荷读不准的空回传
|
||||
* 不得抹掉存量),在飞任务(PENDING/RUNNING)的行不动,删除本体走
|
||||
* {@link JdProductRowDeleteService#deleteRows}(SKU/图片行级联)。</p>
|
||||
* {@code isEnd=true} 时任务落 SUCCESS;由于现有回传不能证明分页完整,暂不执行覆盖清理,
|
||||
* 保留历史商品并记录警告。
|
||||
*
|
||||
* <p>回传 payload 键集契约({@code JdIngestPayloadContractTest} 绊线钉住):顶层
|
||||
* {@code batchId / cursor / items / isEnd}(+ {@code error} 失败上报),行内
|
||||
@@ -168,7 +165,9 @@ public class JdResultIngestService {
|
||||
int itemsReceived = mergeScopeState(scope, request, request.getItems() == null ? 0 : request.getItems().size());
|
||||
if (Boolean.TRUE.equals(request.getIsEnd())) {
|
||||
finalizeSuccess(task, itemsReceived);
|
||||
purgeSupersededRows(task, companyId, itemsReceived);
|
||||
// 客户端缺少可验证的完整分页回执,不能据此删除未回传的旧商品。
|
||||
log.warn("[{}] 缺少全店分页完整性证明,跳过覆盖清理 taskId={} itemsReceived={}",
|
||||
LOG_TAG, task.getId(), itemsReceived);
|
||||
}
|
||||
JdIngestChunkVo vo = new JdIngestChunkVo();
|
||||
vo.setAccept(true);
|
||||
@@ -235,39 +234,6 @@ public class JdResultIngestService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 覆盖清理(用户拍板 2026-11-15:重爬同一店铺直接覆盖旧数据,采集完成时清)。
|
||||
*
|
||||
* <p>只清「本次没采到」的旧行:同公司、同店铺(shop_id 取本任务落过的行)、
|
||||
* task_id 不是本任务、且所属任务已不在在飞的行(在飞任务如 PENDING/RUNNING 的行不动,
|
||||
* 同店铺并发两单时先收尾的单不得抹掉仍在跑的单的行,后收尾的单会在自己的收尾时清)。
|
||||
* 删除本体走 {@link JdProductRowDeleteService#deleteRows}(SKU/图片行级联,同一事务)。</p>
|
||||
*
|
||||
* <p>两条护栏:① 本次 {@code itemsReceived=0} 不清(B94-01 教训——载荷读不准的空回传
|
||||
* 一旦清库=存量整库抹掉);② 清理失败不推翻采集结果(新数据已完整落库且任务已落
|
||||
* SUCCESS),但必须留痕不静默:error 日志+scope 台账记 lastError。</p>
|
||||
*/
|
||||
private void purgeSupersededRows(FileTaskEntity task, Long companyId, int itemsReceived) {
|
||||
if (itemsReceived <= 0) {
|
||||
log.warn("[{}] 收尾回传 0 行,跳过覆盖清理(B94-01:不清旧) taskId={}", LOG_TAG, task.getId());
|
||||
return;
|
||||
}
|
||||
try {
|
||||
List<Long> staleIds = jdProductMapper.selectSupersededProductIds(companyId, task.getId());
|
||||
if (staleIds.isEmpty()) {
|
||||
log.info("[{}] 覆盖清理无候选行(本次已覆盖全部旧行) taskId={}", LOG_TAG, task.getId());
|
||||
return;
|
||||
}
|
||||
int deleted = jdProductRowDeleteService.deleteRows(staleIds);
|
||||
log.info("[{}] 覆盖清理完成:本次没采到的旧行已删 taskId={} candidates={} deleted={}",
|
||||
LOG_TAG, task.getId(), staleIds.size(), deleted);
|
||||
} catch (Exception ex) {
|
||||
log.error("[{}] 覆盖清理失败(本次采集数据已完整落库,仅旧数据未清,可重爬一次补清) taskId={}",
|
||||
LOG_TAG, task.getId(), ex);
|
||||
recordLastError(task.getId(), "覆盖清理失败(本次采集数据已完整落库,仅旧数据未清,可重爬一次补清)");
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- V199 保护闸:人工编辑锁与删除忽略 ----------
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user