feat(jd): 京麦授权类目树按店铺存(客户端上报+后管并集读取)
后管「京东数据库 › 商品目录」的树原是 2026-11-16 从花屿巷旗舰店抓包硬编码的快照, 换店(家居日用数据库店)打开就是整棵服饰内衣/母婴/运动户外、节点全 0,264 件收纳品 全落「树外兜底」。授权类目树是按店铺的资产,改由客户端采集窗口顺手收、服务端按店铺存。 - V215__jd_shop_category_tree.sql:biz_jd_shop_category_tree(shop_id × node_id 唯一, 存平台公共类目名,不含业务数据 ⇒ 不做公司维隔离) - POST /api/jd-shop-category-tree:整店快照替换(先删后插,500 行一批);缺店铺 ID/ 空树/超 5000 节点一律拒且不碰库(空树拒=不静默清空已有快照) - GET /api/jd-shop-category-tree:已上报店铺并集森林(node_id 全局同一套 ⇒ 合并去重; 父缺失提升为根;末级 children 置 null)+店铺清单(节点数、最新采集时间) - 鉴权 requireUserOrInternal:后管走 JWT、采集器走 X-Internal-Token(与分片回传同形) 判据 JdShopCategoryTreeServiceTest 13 支(扁平化层级/父/同级序、空名节点丢自身保子级、 四条拒绝分支不碰库、先删后插与满批切分、并集去重/父缺失提根/末级 null、店铺清单口径); SqlLayeringConventionTest.XML_STATEMENT_TOTAL 154→156(delete+insert 两条写语句,无 select)。
This commit is contained in:
+68
@@ -0,0 +1,68 @@
|
||||
package com.nanri.aiimage.modules.jd.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.jd.model.dto.JdShopCategoryTreeReportRequest;
|
||||
import com.nanri.aiimage.modules.jd.model.vo.JdShopCategoryTreeVo;
|
||||
import com.nanri.aiimage.modules.jd.service.JdShopCategoryTreeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 京麦授权类目树(2026-11-23):客户端上报 + 后管读取。
|
||||
*
|
||||
* <p>两个入口:</p>
|
||||
* <ul>
|
||||
* <li>{@code POST /api/jd-shop-category-tree}:本机采集器在采集窗口顺手收到
|
||||
* {@code getVenderLicenseCategory} 后整棵上报(带 {@code X-Internal-Token},
|
||||
* 与分片回传同形);整店替换、幂等,采不到不报(后台回落内置快照)。</li>
|
||||
* <li>{@code GET /api/jd-shop-category-tree}:后管「京东数据库」左栏取已上报店铺的并集森林;
|
||||
* 节点计数徽标仍由 {@code /api/jd-products/categories} 提供(那一侧按公司隔离)。</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>鉴权:{@code requireUserOrInternal}——后管走登录 JWT,采集器走可信内部 token,
|
||||
* 两者任一通过;都不通过按 401。</p>
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@RequestMapping("/api/jd-shop-category-tree")
|
||||
@Tag(name = "京麦授权类目树", description = "按店铺存授权类目树:客户端采集时上报,后管按并集渲染商品目录树。")
|
||||
public class JdShopCategoryTreeController {
|
||||
|
||||
private final JdShopCategoryTreeService treeService;
|
||||
private final AdminAuthSupport adminAuthSupport;
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "上报店铺授权类目树(采集器调用)",
|
||||
description = "整店快照替换:先删该店旧行再批量插入。缺店铺 ID、空树、超上限一律拒,"
|
||||
+ "不覆盖已有快照(否则后台树会凭空消失)。")
|
||||
public ApiResponse<Map<String, Object>> report(
|
||||
@RequestBody JdShopCategoryTreeReportRequest body,
|
||||
HttpServletRequest request) {
|
||||
adminAuthSupport.requireUserOrInternal(request);
|
||||
int nodes = treeService.report(body);
|
||||
return ApiResponse.success(Map.of("nodes", nodes));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@Operation(summary = "读取授权类目树(后管商品目录左栏)",
|
||||
description = "已上报店铺并集后的森林(平台类目 id 合并去重)+ 覆盖店铺清单;"
|
||||
+ "shops 为空表示还没有任何店铺上报过,页面回落到内置快照。")
|
||||
public ApiResponse<JdShopCategoryTreeVo> tree(
|
||||
@Parameter(hidden = true) HttpServletRequest request) {
|
||||
adminAuthSupport.requireUserOrInternal(request);
|
||||
return ApiResponse.success(treeService.tree());
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.nanri.aiimage.modules.jd.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.jd.model.entity.JdShopCategoryTreeEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 京麦授权类目树(biz_jd_shop_category_tree,V215,2026-11-23)数据访问口。
|
||||
*
|
||||
* <p>读侧(后管渲染)与单表 CRUD 走 BaseMapper + wrapper;写侧只有两条自定义 SQL
|
||||
* 落 {@code mapper/jd/JdShopCategoryTreeMapper.xml}(铁律 1):整店删除 + 批量插入,
|
||||
* 由 service 在同一事务里包成「整店快照替换」。</p>
|
||||
*/
|
||||
@Mapper
|
||||
public interface JdShopCategoryTreeMapper extends BaseMapper<JdShopCategoryTreeEntity> {
|
||||
|
||||
/** 删掉该店铺的全部历史节点(整店替换的第一步;空集合不进来,调用方先校验 shopId)。 */
|
||||
int deleteByShopId(@Param("shopId") String shopId);
|
||||
|
||||
/**
|
||||
* 批量插入该店铺本次快照的全部节点。调用方保证 rows 非空、同 shopId、
|
||||
* 且已删过旧行(唯一键 uk_jd_shop_cat_node 撞键即报错,不静默跳过——那说明
|
||||
* 上报体里自带了重复 node_id,属于脏数据要显形)。
|
||||
*/
|
||||
int insertBatch(@Param("rows") List<JdShopCategoryTreeEntity> rows);
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.nanri.aiimage.modules.jd.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 授权类目树节点(上报请求的递归形状,字段名与 admin 前端 {@code JD_CATEGORY_TREE} 同形)。
|
||||
*
|
||||
* <p>{@code value}=京麦平台类目 id(字符串);过滤只用 {@code name} 等值,
|
||||
* {@code value} 仅用于父子挂接与合并去重。</p>
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "授权类目树节点")
|
||||
public class JdShopCategoryNodeDto {
|
||||
|
||||
@Schema(description = "类目名(京麦 label)")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "平台类目 id(京麦 value)")
|
||||
private String value;
|
||||
|
||||
@Schema(description = "子级;缺省或空=末级")
|
||||
private List<JdShopCategoryNodeDto> children;
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.nanri.aiimage.modules.jd.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端上报「京麦授权类目树」的请求体({@code POST /api/jd-shop-category-tree},2026-11-23)。
|
||||
*
|
||||
* <p>树形状与京麦 {@code getVenderLicenseCategory} 响应同形({@code data[]} 的
|
||||
* {@code label/value/children}),客户端只做字段名归一(label→name),不重排、不裁剪。
|
||||
* 一次上报=该店铺的**整棵**快照(服务端整店替换,不做增量合并)。</p>
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "京麦授权类目树上报(整店快照)")
|
||||
public class JdShopCategoryTreeReportRequest {
|
||||
|
||||
@Schema(description = "京麦 venderId(店铺 ID);取不到时上报会被拒(树无法归属到店铺)")
|
||||
private String shopId;
|
||||
|
||||
@Schema(description = "店铺展示名(仅供排查)")
|
||||
private String shopName;
|
||||
|
||||
@Schema(description = "授权类目树(一级节点列表,逐级 children)")
|
||||
private List<JdShopCategoryNodeDto> tree;
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.nanri.aiimage.modules.jd.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 京麦授权类目树节点({@code biz_jd_shop_category_tree},V215,2026-11-23)。
|
||||
*
|
||||
* <p>一行=「店铺 × 平台类目节点」,唯一键 {@code uk_jd_shop_cat_node(shop_id, node_id)}。
|
||||
* 授权类目树是**按店铺**的资产(每家店授权的类目子集不同),原实现是 admin 前端硬编码的
|
||||
* 一家店快照,换店就整树零命中、商品全落「树外兜底」。改由客户端采集窗口顺手收
|
||||
* {@code getVenderLicenseCategory} 上报,后台按已上报店铺并集渲染。</p>
|
||||
*
|
||||
* <p>只存平台公共类目名,不含商品/公司业务数据 ⇒ 不做公司维隔离;计数徽标仍由
|
||||
* {@code biz_jd_product} 的按公司查询提供(两步各管各的口径)。</p>
|
||||
*/
|
||||
@Data
|
||||
@TableName("biz_jd_shop_category_tree")
|
||||
public class JdShopCategoryTreeEntity {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
/** 京麦 venderId(店铺 ID,字符串数字)。 */
|
||||
private String shopId;
|
||||
/** 上报时的店铺展示名(仅供排查,不参与业务判定)。 */
|
||||
private String shopName;
|
||||
/** 平台类目 id(京麦授权树 value)。 */
|
||||
private String nodeId;
|
||||
/** 父类目 id;null=一级节点。 */
|
||||
private String parentNodeId;
|
||||
/** 类目名(末级名=biz_jd_product.category_path 的词表)。 */
|
||||
private String nodeName;
|
||||
/** 层级(1 起)。 */
|
||||
private Integer nodeLevel;
|
||||
/** 同级原序(京麦面板顺序)。 */
|
||||
private Integer sortOrder;
|
||||
/** 本次整店快照的采集时间。 */
|
||||
private LocalDateTime capturedAt;
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.nanri.aiimage.modules.jd.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 授权类目树节点(读取回执的递归形状,与 admin 前端 {@code JD_CATEGORY_TREE} 逐字同形,
|
||||
* 页面可直接替换静态常量:过滤按 {@code name} 等值,{@code value} 只作父子挂接与去重)。
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "授权类目树节点(读取)")
|
||||
public class JdShopCategoryNodeVo {
|
||||
|
||||
@Schema(description = "类目名")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "平台类目 id")
|
||||
private String value;
|
||||
|
||||
@Schema(description = "子级;空=末级")
|
||||
private List<JdShopCategoryNodeVo> children;
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.nanri.aiimage.modules.jd.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 授权类目树读取回执({@code GET /api/jd-shop-category-tree},后管「京东数据库」左栏用)。
|
||||
*
|
||||
* <p>{@code nodes}=已上报店铺并集后的森林(平台类目 id 全局同一套 ⇒ 按 node_id 合并去重,
|
||||
* 同店重复上报不会长出重复分支);{@code shops}=覆盖情况,页面用它判「有没有服务端树」
|
||||
* 来决定是渲染真树还是回落到内置快照。</p>
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "授权类目树(已上报店铺并集)")
|
||||
public class JdShopCategoryTreeVo {
|
||||
|
||||
@Schema(description = "类目树森林(一级节点列表)")
|
||||
private List<JdShopCategoryNodeVo> nodes;
|
||||
|
||||
@Schema(description = "已上报的店铺清单")
|
||||
private List<Shop> shops;
|
||||
|
||||
@Data
|
||||
@Schema(description = "已上报店铺")
|
||||
public static class Shop {
|
||||
@Schema(description = "京麦 venderId")
|
||||
private String shopId;
|
||||
@Schema(description = "店铺展示名")
|
||||
private String shopName;
|
||||
@Schema(description = "该店快照采集时间")
|
||||
private String capturedAt;
|
||||
@Schema(description = "该店节点数")
|
||||
private Integer nodeCount;
|
||||
}
|
||||
}
|
||||
+225
@@ -0,0 +1,225 @@
|
||||
package com.nanri.aiimage.modules.jd.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.modules.jd.mapper.JdShopCategoryTreeMapper;
|
||||
import com.nanri.aiimage.modules.jd.model.dto.JdShopCategoryNodeDto;
|
||||
import com.nanri.aiimage.modules.jd.model.dto.JdShopCategoryTreeReportRequest;
|
||||
import com.nanri.aiimage.modules.jd.model.entity.JdShopCategoryTreeEntity;
|
||||
import com.nanri.aiimage.modules.jd.model.vo.JdShopCategoryNodeVo;
|
||||
import com.nanri.aiimage.modules.jd.model.vo.JdShopCategoryTreeVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 京麦授权类目树:客户端上报(整店快照替换)+后管读取(已上报店铺并集森林)。
|
||||
*
|
||||
* <p>为什么按店铺存(2026-11-23):授权类目树是**每家店**的资产——原实现把 2026-11-16
|
||||
* 从花屿巷旗舰店抓的一份快照硬编码进 admin 前端,换一家店(家居日用店)打开就是整棵
|
||||
* 服饰内衣/母婴/运动户外树、节点全 0,本店商品(收纳盒/脏衣篓)全落「树外兜底」,
|
||||
* 界面看着像「这家店卖女装」。现在改由客户端采集窗口顺手收 {@code getVenderLicenseCategory}
|
||||
* 上报,后台按并集渲染;没有上报记录的店仍由页面回落到内置快照(显示层另有「本店无匹配」
|
||||
* 消歧档兜住)。</p>
|
||||
*
|
||||
* <p>合并口径:京麦平台类目 {@code node_id} 全局同一套(每家店只是授权子集不同)⇒
|
||||
* 并集按 {@code node_id} 去重,同店重复上报、多店同名跨支(如「唐装」两个 id)都如实保留,
|
||||
* 不按名字合并(名字等值过滤在前端,两处同名行本来就会一起命中,B112-05 口径)。</p>
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class JdShopCategoryTreeService {
|
||||
|
||||
/** 单店节点数上限:京麦现状 250 个末级 / 约 500 个节点;给 10 倍余量,超了按脏数据拒。 */
|
||||
static final int MAX_NODES = 5000;
|
||||
/** 树深上限(页面面板最深 4 级;给 8 级防脏数据递归炸栈)。 */
|
||||
static final int MAX_DEPTH = 8;
|
||||
/** 名称/ID 长度上限(与 DDL 对齐)。 */
|
||||
static final int MAX_TEXT = 128;
|
||||
/** 批量插入每批行数(避开单条 SQL 参数上限)。 */
|
||||
static final int INSERT_BATCH = 500;
|
||||
|
||||
private static final DateTimeFormatter TS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
private final JdShopCategoryTreeMapper mapper;
|
||||
|
||||
/**
|
||||
* 上报该店铺的整棵授权类目树:事务内先删该店旧行、再批量插入本次快照。
|
||||
*
|
||||
* <p>幂等语义=「最后一次上报说了算」:京麦改树后客户端再采一次即覆盖。
|
||||
* 空树/缺店铺 ID 一律拒(不写库、不静默清空已有快照——那会让后台树凭空消失)。</p>
|
||||
*
|
||||
* @return 本次落库的节点数
|
||||
*/
|
||||
@Transactional
|
||||
public int report(JdShopCategoryTreeReportRequest request) {
|
||||
String shopId = trimToNull(request == null ? null : request.getShopId());
|
||||
if (shopId == null) {
|
||||
throw new BusinessException("缺少店铺 ID,授权类目树无法归属到店铺");
|
||||
}
|
||||
if (shopId.length() > 64) {
|
||||
throw new BusinessException("店铺 ID 超长,拒绝落库");
|
||||
}
|
||||
String shopName = clip(trimToNull(request.getShopName()), MAX_TEXT);
|
||||
LocalDateTime capturedAt = LocalDateTime.now();
|
||||
List<JdShopCategoryTreeEntity> rows = new ArrayList<>();
|
||||
flatten(request.getTree(), null, 1, rows, shopId, shopName, capturedAt);
|
||||
if (rows.isEmpty()) {
|
||||
throw new BusinessException("授权类目树为空,未落库(不覆盖已有快照)");
|
||||
}
|
||||
if (rows.size() > MAX_NODES) {
|
||||
throw new BusinessException("授权类目树节点数 " + rows.size() + " 超出上限 " + MAX_NODES
|
||||
+ ",按脏数据拒绝");
|
||||
}
|
||||
mapper.deleteByShopId(shopId);
|
||||
for (int from = 0; from < rows.size(); from += INSERT_BATCH) {
|
||||
mapper.insertBatch(rows.subList(from, Math.min(from + INSERT_BATCH, rows.size())));
|
||||
}
|
||||
log.info("[jd-shop-category-tree] 上报落库 shopId={} shopName={} nodes={}",
|
||||
shopId, shopName, rows.size());
|
||||
return rows.size();
|
||||
}
|
||||
|
||||
/** 整棵树的扁平化(DFS 前序,同级 index 即 sort_order)。字段脏值就地归一,不抛异常。 */
|
||||
private void flatten(List<JdShopCategoryNodeDto> nodes, String parentNodeId, int level,
|
||||
List<JdShopCategoryTreeEntity> out, String shopId, String shopName,
|
||||
LocalDateTime capturedAt) {
|
||||
if (nodes == null || nodes.isEmpty() || level > MAX_DEPTH) {
|
||||
return;
|
||||
}
|
||||
int order = 0;
|
||||
for (JdShopCategoryNodeDto node : nodes) {
|
||||
if (node == null) {
|
||||
continue;
|
||||
}
|
||||
String name = trimToNull(node.getName());
|
||||
String nodeId = trimToNull(node.getValue());
|
||||
if (name == null || nodeId == null) {
|
||||
// 缺名字或缺 id 的节点自身不落库,但子级仍递归(挂到上一层,不丢整支)。
|
||||
flatten(node.getChildren(), parentNodeId, level + 1, out, shopId, shopName, capturedAt);
|
||||
continue;
|
||||
}
|
||||
JdShopCategoryTreeEntity row = new JdShopCategoryTreeEntity();
|
||||
row.setShopId(shopId);
|
||||
row.setShopName(shopName);
|
||||
row.setNodeId(clip(nodeId, 64));
|
||||
row.setParentNodeId(parentNodeId);
|
||||
row.setNodeName(clip(name, MAX_TEXT));
|
||||
row.setNodeLevel(level);
|
||||
row.setSortOrder(order++);
|
||||
row.setCapturedAt(capturedAt);
|
||||
out.add(row);
|
||||
flatten(node.getChildren(), row.getNodeId(), level + 1, out, shopId, shopName, capturedAt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后管渲染用:已上报店铺并集后的类目森林。
|
||||
*
|
||||
* <p>排序:层级 → 同级原序 → 主键(多店合并后同层顺序稳定,不随库内主键抖动)。
|
||||
* 父节点缺失(另一家店只授权了子树片段)的节点提升为根——否则整支会从树上消失,
|
||||
* 与「树上对不上的进树外兜底」是两条不同语义,不能混。</p>
|
||||
*/
|
||||
public JdShopCategoryTreeVo tree() {
|
||||
List<JdShopCategoryTreeEntity> rows = mapper.selectList(
|
||||
new LambdaQueryWrapper<JdShopCategoryTreeEntity>()
|
||||
.orderByAsc(JdShopCategoryTreeEntity::getNodeLevel)
|
||||
.orderByAsc(JdShopCategoryTreeEntity::getSortOrder)
|
||||
.orderByAsc(JdShopCategoryTreeEntity::getId));
|
||||
Map<String, JdShopCategoryNodeVo> byId = new LinkedHashMap<>();
|
||||
Map<String, JdShopCategoryTreeEntity> captured = new LinkedHashMap<>();
|
||||
for (JdShopCategoryTreeEntity row : rows) {
|
||||
if (row.getNodeId() == null || row.getNodeName() == null) {
|
||||
continue;
|
||||
}
|
||||
if (!byId.containsKey(row.getNodeId())) {
|
||||
JdShopCategoryNodeVo node = new JdShopCategoryNodeVo();
|
||||
node.setName(row.getNodeName());
|
||||
node.setValue(row.getNodeId());
|
||||
node.setChildren(new ArrayList<>());
|
||||
byId.put(row.getNodeId(), node);
|
||||
}
|
||||
captured.putIfAbsent(row.getNodeId(), row);
|
||||
}
|
||||
List<JdShopCategoryNodeVo> roots = new ArrayList<>();
|
||||
for (Map.Entry<String, JdShopCategoryNodeVo> entry : byId.entrySet()) {
|
||||
JdShopCategoryTreeEntity row = captured.get(entry.getKey());
|
||||
String parentId = row == null ? null : row.getParentNodeId();
|
||||
JdShopCategoryNodeVo parent = parentId == null ? null : byId.get(parentId);
|
||||
if (parent == null) {
|
||||
roots.add(entry.getValue());
|
||||
} else {
|
||||
parent.getChildren().add(entry.getValue());
|
||||
}
|
||||
}
|
||||
// 末级节点的 children 置空(前端 leaf 判定=children 缺省/空,统一成 null 更省报文)。
|
||||
for (JdShopCategoryNodeVo node : byId.values()) {
|
||||
if (node.getChildren() != null && node.getChildren().isEmpty()) {
|
||||
node.setChildren(null);
|
||||
}
|
||||
}
|
||||
JdShopCategoryTreeVo vo = new JdShopCategoryTreeVo();
|
||||
vo.setNodes(roots);
|
||||
vo.setShops(shops(rows));
|
||||
return vo;
|
||||
}
|
||||
|
||||
/** 已上报店铺清单(页面判「有没有服务端树」;同店多批次只取最新一次采集时间)。 */
|
||||
private List<JdShopCategoryTreeVo.Shop> shops(List<JdShopCategoryTreeEntity> rows) {
|
||||
Map<String, JdShopCategoryTreeVo.Shop> shops = new LinkedHashMap<>();
|
||||
Map<String, LocalDateTime> latest = new LinkedHashMap<>();
|
||||
for (JdShopCategoryTreeEntity row : rows) {
|
||||
if (row.getShopId() == null) {
|
||||
continue;
|
||||
}
|
||||
JdShopCategoryTreeVo.Shop shop = shops.get(row.getShopId());
|
||||
if (shop == null) {
|
||||
shop = new JdShopCategoryTreeVo.Shop();
|
||||
shop.setShopId(row.getShopId());
|
||||
shop.setNodeCount(0);
|
||||
shops.put(row.getShopId(), shop);
|
||||
}
|
||||
shop.setNodeCount(shop.getNodeCount() + 1);
|
||||
if (trimToNull(row.getShopName()) != null) {
|
||||
shop.setShopName(row.getShopName());
|
||||
}
|
||||
LocalDateTime at = row.getCapturedAt();
|
||||
if (at != null && (latest.get(row.getShopId()) == null || at.isAfter(latest.get(row.getShopId())))) {
|
||||
latest.put(row.getShopId(), at);
|
||||
}
|
||||
}
|
||||
List<JdShopCategoryTreeVo.Shop> out = new ArrayList<>();
|
||||
for (Map.Entry<String, JdShopCategoryTreeVo.Shop> entry : shops.entrySet()) {
|
||||
LocalDateTime at = latest.get(entry.getKey());
|
||||
if (at != null) {
|
||||
entry.getValue().setCapturedAt(TS.format(at));
|
||||
}
|
||||
out.add(entry.getValue());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static String trimToNull(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
String trimmed = value.trim();
|
||||
return trimmed.isEmpty() ? null : trimmed;
|
||||
}
|
||||
|
||||
private static String clip(String value, int max) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return value.length() <= max ? value : value.substring(0, max);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
-- 京麦授权类目树(按店铺)——客户端采集时上报,后管「京东数据库 › 商品目录」按它渲染。
|
||||
--
|
||||
-- 背景(2026-11-23):后管原来把 2026-11-16 从**一家店铺**(花屿巷旗舰店)抓的
|
||||
-- getVenderLicenseCategory 快照硬编码在 admin 前端(jd-category-tree.ts),换一家店
|
||||
-- (家居日用店)打开就是整棵服饰内衣/母婴/运动户外树、节点全 0,本店商品全落「树外兜底」。
|
||||
-- 授权类目树是按店铺的资产 ⇒ 改由客户端在采集窗口顺手收一次、上报落本表,
|
||||
-- 后台按已上报店铺并集渲染(平台类目 node_id 全局同一套,合并去重安全)。
|
||||
--
|
||||
-- 口径:
|
||||
-- * 一行=一个类目节点;uk(shop_id, node_id) 保证同店同节点只有一行,上报走整店替换;
|
||||
-- * node_id = 京麦授权接口的 value(平台类目 id,字符串);parent_node_id 为空=一级;
|
||||
-- * 本表只存平台公共类目名,不含任何商品/公司业务数据,故不做公司维隔离
|
||||
-- (计数徽标另由 biz_jd_product 的按公司查询提供)。
|
||||
CREATE TABLE IF NOT EXISTS `biz_jd_shop_category_tree` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`shop_id` VARCHAR(64) NOT NULL COMMENT '京麦 venderId(店铺 ID)',
|
||||
`shop_name` VARCHAR(128) DEFAULT NULL COMMENT '上报时的店铺展示名(仅供排查)',
|
||||
`node_id` VARCHAR(64) NOT NULL COMMENT '平台类目 id(京麦授权树 value)',
|
||||
`parent_node_id` VARCHAR(64) DEFAULT NULL COMMENT '父类目 id;NULL=一级',
|
||||
`node_name` VARCHAR(128) NOT NULL COMMENT '类目名(末级名即 biz_jd_product.category_path 的词表)',
|
||||
`node_level` TINYINT NOT NULL DEFAULT 1 COMMENT '层级(1 起)',
|
||||
`sort_order` INT NOT NULL DEFAULT 0 COMMENT '同级原序(京麦面板顺序)',
|
||||
`captured_at` DATETIME NOT NULL COMMENT '本次整店快照的采集时间',
|
||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '落库时间',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_jd_shop_cat_node` (`shop_id`, `node_id`),
|
||||
KEY `idx_jd_shop_cat_shop` (`shop_id`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT = '京麦授权类目树(按店铺,客户端上报)';
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nanri.aiimage.modules.jd.mapper.JdShopCategoryTreeMapper">
|
||||
<!-- 京麦授权类目树(V215,2026-11-23):SQL 全部落 XML(铁律 1)。
|
||||
写侧=整店快照替换:先 deleteByShopId 再 insertBatch(同一事务,service 里包)。
|
||||
读侧(后管渲染并集森林)走 BaseMapper + wrapper,无 XML。 -->
|
||||
<delete id="deleteByShopId">
|
||||
DELETE FROM biz_jd_shop_category_tree WHERE shop_id = #{shopId}
|
||||
</delete>
|
||||
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO biz_jd_shop_category_tree
|
||||
(shop_id, shop_name, node_id, parent_node_id, node_name, node_level, sort_order, captured_at)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.shopId}, #{row.shopName}, #{row.nodeId}, #{row.parentNodeId},
|
||||
#{row.nodeName}, #{row.nodeLevel}, #{row.sortOrder}, #{row.capturedAt})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -146,7 +146,10 @@ class SqlLayeringConventionTest {
|
||||
// mapper/company/CompanyMapper.xml(898e8a5e 走了注解通道,本测试当窗抓到),SQL 文本
|
||||
// 未改写;逐条登记进 MigratedSqlEquivalenceTest.NOT_MIGRATED(同文件 XML_SELECT_TOTAL
|
||||
// 同轮 107 → 109)。
|
||||
private static final int XML_STATEMENT_TOTAL = 154;
|
||||
// 154 → 156:2026-11-23 京麦授权类目树(V215)新落 mapper/jd/JdShopCategoryTreeMapper.xml
|
||||
// 2 条写语句——deleteByShopId(整店快照替换第一步,1 delete)+ insertBatch(500 行一批,
|
||||
// 1 insert);全部新写非迁移语句,该文件 XML_SELECT_TOTAL 不动(无 select)。
|
||||
private static final int XML_STATEMENT_TOTAL = 156;
|
||||
|
||||
/**
|
||||
* wrapper 里夹带函数级 SQL 的现状("这不是简单单表"的证据),文件名 → 条数:
|
||||
|
||||
+312
@@ -0,0 +1,312 @@
|
||||
package com.nanri.aiimage.modules.jd.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.modules.jd.mapper.JdShopCategoryTreeMapper;
|
||||
import com.nanri.aiimage.modules.jd.model.dto.JdShopCategoryNodeDto;
|
||||
import com.nanri.aiimage.modules.jd.model.dto.JdShopCategoryTreeReportRequest;
|
||||
import com.nanri.aiimage.modules.jd.model.entity.JdShopCategoryTreeEntity;
|
||||
import com.nanri.aiimage.modules.jd.model.vo.JdShopCategoryNodeVo;
|
||||
import com.nanri.aiimage.modules.jd.model.vo.JdShopCategoryTreeVo;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 京麦授权类目树(V215,2026-11-23):按店铺整店快照替换 + 后管并集森林。
|
||||
*
|
||||
* <p>判据:flatten 的层级/父 id/同级原序;缺名字或缺 id 的节点自身不落库但子级上提
|
||||
* (挂到上一层父,不丢整支);缺店铺 ID、空树、超 5000 节点一律拒且**不碰库**
|
||||
* (空树拒=不静默清空已有快照);先删后插的顺序与 500 行分批;读侧按 node_id 合并
|
||||
* (平台类目 id 全局同一套,多店并集去重)+父缺失提升为根+末级 children 置 null;
|
||||
* 店铺清单累加节点数并取最新采集时间。</p>
|
||||
*/
|
||||
class JdShopCategoryTreeServiceTest {
|
||||
|
||||
private final JdShopCategoryTreeMapper mapper = mock(JdShopCategoryTreeMapper.class);
|
||||
private final JdShopCategoryTreeService service = new JdShopCategoryTreeService(mapper);
|
||||
|
||||
@BeforeAll
|
||||
static void initTableInfo() {
|
||||
// 读侧 wrapper 用 lambda 列引用,裸单测 JVM 里不初始化就解析不了(同 JdGroupShopServiceTest)。
|
||||
MapperBuilderAssistant assistant = new MapperBuilderAssistant(new MybatisConfiguration(), "");
|
||||
TableInfoHelper.initTableInfo(assistant, JdShopCategoryTreeEntity.class);
|
||||
}
|
||||
|
||||
// ===================== 上报:扁平化 =====================
|
||||
|
||||
@Test
|
||||
void report_扁平化保留层级父子与同级顺序() {
|
||||
JdShopCategoryTreeReportRequest request = request("228346061", "家居日用数据库店",
|
||||
node("服饰内衣", "1315",
|
||||
node("女装", "1343", node("连衣裙", "9719")),
|
||||
node("男装", "1344")),
|
||||
node("运动户外", "1318"));
|
||||
|
||||
int nodes = service.report(request);
|
||||
|
||||
assertEquals(5, nodes);
|
||||
List<JdShopCategoryTreeEntity> rows = captureInserted(1).get(0);
|
||||
assertEquals(List.of("1315", "1343", "9719", "1344", "1318"),
|
||||
rows.stream().map(JdShopCategoryTreeEntity::getNodeId).collect(Collectors.toList()),
|
||||
"DFS 前序落库(同级 order 即 sort_order)");
|
||||
JdShopCategoryTreeEntity root = rows.get(0);
|
||||
assertEquals(1, root.getNodeLevel());
|
||||
assertNull(root.getParentNodeId(), "一级节点 parent 为空");
|
||||
assertEquals(0, root.getSortOrder());
|
||||
assertEquals("228346061", root.getShopId());
|
||||
assertEquals("家居日用数据库店", root.getShopName());
|
||||
assertEquals(2, rows.get(1).getNodeLevel());
|
||||
assertEquals("1315", rows.get(1).getParentNodeId());
|
||||
assertEquals(3, rows.get(2).getNodeLevel());
|
||||
assertEquals("1343", rows.get(2).getParentNodeId());
|
||||
assertEquals(1, rows.get(3).getSortOrder(), "女装已占 order 0,男装是 1");
|
||||
assertEquals(1, rows.get(4).getSortOrder(), "运动户外在根层也是第 2 个");
|
||||
assertNotNull(rows.get(0).getCapturedAt(), "整店快照共用一个采集时间");
|
||||
assertEquals(rows.get(0).getCapturedAt(), rows.get(4).getCapturedAt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void report_缺名字或id的节点自身不落库但子级上提() {
|
||||
JdShopCategoryTreeReportRequest request = request("228346061", "家居日用数据库店",
|
||||
node("服饰内衣", "1315",
|
||||
node(null, "9999", node("保留", "1343")),
|
||||
node("无id", null, node("也保留", "1344"))));
|
||||
|
||||
service.report(request);
|
||||
|
||||
List<JdShopCategoryTreeEntity> rows = captureInserted(1).get(0);
|
||||
assertEquals(List.of("1315", "1343", "1344"),
|
||||
rows.stream().map(JdShopCategoryTreeEntity::getNodeId).collect(Collectors.toList()),
|
||||
"缺名字/缺 id 的父节点吃掉自身,但子级上提(不丢整支)");
|
||||
assertEquals("1315", rows.get(1).getParentNodeId(), "上提后挂到最近的有效父(按 node_id 建父子)");
|
||||
assertEquals(3, rows.get(1).getNodeLevel(),
|
||||
"层级按实际深度保留:跳过的空名节点占了一级,子级不重算成 2(读侧排序仍先父后子)");
|
||||
assertEquals("1315", rows.get(2).getParentNodeId());
|
||||
assertEquals(3, rows.get(2).getNodeLevel(), "层级按实际深度保留(不是提一级重算)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void report_字段超长截断而不是拒整棵树() {
|
||||
String longName = "类".repeat(JdShopCategoryTreeService.MAX_TEXT + 10);
|
||||
service.report(request("228346061", longName, node(longName, "1315")));
|
||||
|
||||
JdShopCategoryTreeEntity row = captureInserted(1).get(0).get(0);
|
||||
assertEquals(JdShopCategoryTreeService.MAX_TEXT, row.getNodeName().length());
|
||||
assertEquals(JdShopCategoryTreeService.MAX_TEXT, row.getShopName().length(),
|
||||
"店铺名与节点名同口径截断(展示字段,不值得拒整棵树)");
|
||||
}
|
||||
|
||||
// ===================== 上报:拒绝分支 =====================
|
||||
|
||||
@Test
|
||||
void report_缺店铺ID拒绝且不碰库() {
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.report(request(" ", "某店", node("服饰内衣", "1315"))));
|
||||
assertTrue(error.getMessage().contains("店铺 ID"));
|
||||
verifyNoInteractions(mapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void report_店铺ID超长拒绝() {
|
||||
assertThrows(BusinessException.class,
|
||||
() -> service.report(request("1".repeat(65), "某店", node("服饰内衣", "1315"))));
|
||||
verifyNoInteractions(mapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void report_空树拒绝且不覆盖已有快照() {
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.report(request("228346061", "家居日用数据库店")));
|
||||
assertTrue(error.getMessage().contains("为空"));
|
||||
verify(mapper, never()).deleteByShopId(anyString());
|
||||
verify(mapper, never()).insertBatch(anyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void report_全是脏节点等同空树拒绝() {
|
||||
assertThrows(BusinessException.class, () -> service.report(
|
||||
request("228346061", "家居日用数据库店", node("", "1315"), node("有名字", ""))));
|
||||
verifyNoInteractions(mapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void report_超节点上限拒绝() {
|
||||
List<JdShopCategoryNodeDto> many = new ArrayList<>();
|
||||
for (int index = 0; index <= JdShopCategoryTreeService.MAX_NODES; index++) {
|
||||
many.add(node("类目" + index, String.valueOf(index)));
|
||||
}
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.report(request("228346061", "家居日用数据库店",
|
||||
many.toArray(new JdShopCategoryNodeDto[0]))));
|
||||
assertTrue(error.getMessage().contains("超出上限"));
|
||||
verify(mapper, never()).deleteByShopId(anyString());
|
||||
}
|
||||
|
||||
// ===================== 上报:先删后插 / 分批 =====================
|
||||
|
||||
@Test
|
||||
void report_先删后插且满批切分() {
|
||||
int total = JdShopCategoryTreeService.INSERT_BATCH * 2 + 200;
|
||||
List<JdShopCategoryNodeDto> many = new ArrayList<>();
|
||||
for (int index = 0; index < total; index++) {
|
||||
many.add(node("类目" + index, String.valueOf(index)));
|
||||
}
|
||||
|
||||
int nodes = service.report(request("228346061", "家居日用数据库店",
|
||||
many.toArray(new JdShopCategoryNodeDto[0])));
|
||||
|
||||
assertEquals(total, nodes);
|
||||
InOrder order = inOrder(mapper);
|
||||
order.verify(mapper).deleteByShopId("228346061");
|
||||
order.verify(mapper, times(3)).insertBatch(anyList());
|
||||
List<Integer> sizes = captureInserted(3).stream().map(List::size).collect(Collectors.toList());
|
||||
assertEquals(List.of(JdShopCategoryTreeService.INSERT_BATCH,
|
||||
JdShopCategoryTreeService.INSERT_BATCH, 200), sizes,
|
||||
"旧行全删后按 500 行一批插入,末批是余数");
|
||||
order.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
// ===================== 读取:并集森林 =====================
|
||||
|
||||
@Test
|
||||
void tree_按nodeId合并多店并集且父缺失提升为根() {
|
||||
when(mapper.selectList(any())).thenReturn(List.of(
|
||||
row(1L, "shopA", "甲店", "1315", null, "服饰内衣", 1, 0),
|
||||
row(2L, "shopA", "甲店", "1343", "1315", "女装", 2, 0),
|
||||
row(3L, "shopB", "乙店", "1315", null, "服饰内衣", 1, 0),
|
||||
row(4L, "shopB", "乙店", "34094", "1318", "舞蹈体操鞋服/装备", 2, 0)));
|
||||
|
||||
JdShopCategoryTreeVo vo = service.tree();
|
||||
|
||||
assertEquals(2, vo.getNodes().size(), "1315 两店同 id 合并成一支;34094 的父 1318 未授权 ⇒ 提为根");
|
||||
JdShopCategoryNodeVo apparel = vo.getNodes().get(0);
|
||||
assertEquals("1315", apparel.getValue());
|
||||
assertEquals("服饰内衣", apparel.getName());
|
||||
assertEquals(1, apparel.getChildren().size(), "同 id 不因多店上报长出重复子支");
|
||||
JdShopCategoryNodeVo women = apparel.getChildren().get(0);
|
||||
assertEquals("1343", women.getValue());
|
||||
assertNull(women.getChildren(), "末级 children 统一置 null(省报文,前端 leaf 判定同口径)");
|
||||
assertEquals("34094", vo.getNodes().get(1).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tree_脏行缺id或缺名跳过但店铺清单如实累计() {
|
||||
when(mapper.selectList(any())).thenReturn(List.of(
|
||||
row(1L, "shopA", "甲店", "1315", null, "服饰内衣", 1, 0),
|
||||
row(2L, "shopA", "甲店", null, null, "缺id", 1, 1),
|
||||
row(3L, "shopA", "甲店", "9999", null, null, 1, 2)));
|
||||
|
||||
JdShopCategoryTreeVo vo = service.tree();
|
||||
|
||||
assertEquals(1, vo.getNodes().size());
|
||||
assertEquals(1, vo.getShops().size());
|
||||
assertEquals(3, vo.getShops().get(0).getNodeCount(), "清单是覆盖情况,按行如实累计");
|
||||
}
|
||||
|
||||
@Test
|
||||
void tree_店铺清单取最新采集时间() {
|
||||
LocalDateTime early = LocalDateTime.of(2026, 11, 20, 9, 0);
|
||||
LocalDateTime late = LocalDateTime.of(2026, 11, 23, 18, 30);
|
||||
when(mapper.selectList(any())).thenReturn(List.of(
|
||||
row(1L, "shopA", "甲店", "1315", null, "服饰内衣", 1, 0, early),
|
||||
row(2L, "shopA", "甲店", "1343", "1315", "女装", 2, 0, late),
|
||||
row(3L, "shopB", "乙店", "1318", null, "运动户外", 1, 0, early)));
|
||||
|
||||
List<JdShopCategoryTreeVo.Shop> shops = service.tree().getShops();
|
||||
|
||||
assertEquals(2, shops.size());
|
||||
assertEquals("shopA", shops.get(0).getShopId());
|
||||
assertEquals("甲店", shops.get(0).getShopName());
|
||||
assertEquals(2, shops.get(0).getNodeCount());
|
||||
assertEquals("2026-11-23 18:30:00", shops.get(0).getCapturedAt(),
|
||||
"同店多行取最新一次采集时间");
|
||||
assertEquals("2026-11-20 09:00:00", shops.get(1).getCapturedAt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tree_空表返回空森林与空店铺清单() {
|
||||
when(mapper.selectList(any())).thenReturn(List.of());
|
||||
|
||||
JdShopCategoryTreeVo vo = service.tree();
|
||||
|
||||
assertEquals(List.of(), vo.getNodes());
|
||||
assertEquals(List.of(), vo.getShops(), "shops 为空=还没有店上报过,页面回落内置快照");
|
||||
}
|
||||
|
||||
// ===================== 夹具 =====================
|
||||
|
||||
private static JdShopCategoryTreeReportRequest request(String shopId, String shopName,
|
||||
JdShopCategoryNodeDto... tree) {
|
||||
JdShopCategoryTreeReportRequest request = new JdShopCategoryTreeReportRequest();
|
||||
request.setShopId(shopId);
|
||||
request.setShopName(shopName);
|
||||
request.setTree(tree.length == 0 ? List.of() : List.of(tree));
|
||||
return request;
|
||||
}
|
||||
|
||||
private static JdShopCategoryNodeDto node(String name, String value,
|
||||
JdShopCategoryNodeDto... children) {
|
||||
JdShopCategoryNodeDto node = new JdShopCategoryNodeDto();
|
||||
node.setName(name);
|
||||
node.setValue(value);
|
||||
node.setChildren(children.length == 0 ? null : List.of(children));
|
||||
return node;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private List<List<JdShopCategoryTreeEntity>> captureInserted(int batches) {
|
||||
ArgumentCaptor<List<JdShopCategoryTreeEntity>> captor =
|
||||
ArgumentCaptor.forClass((Class) List.class);
|
||||
verify(mapper, times(batches)).insertBatch(captor.capture());
|
||||
return captor.getAllValues();
|
||||
}
|
||||
|
||||
private static JdShopCategoryTreeEntity row(Long id, String shopId, String shopName,
|
||||
String nodeId, String parentNodeId,
|
||||
String nodeName, int level, int order) {
|
||||
return row(id, shopId, shopName, nodeId, parentNodeId, nodeName, level, order,
|
||||
LocalDateTime.of(2026, 11, 23, 12, 0));
|
||||
}
|
||||
|
||||
private static JdShopCategoryTreeEntity row(Long id, String shopId, String shopName,
|
||||
String nodeId, String parentNodeId,
|
||||
String nodeName, int level, int order,
|
||||
LocalDateTime capturedAt) {
|
||||
JdShopCategoryTreeEntity row = new JdShopCategoryTreeEntity();
|
||||
row.setId(id);
|
||||
row.setShopId(shopId);
|
||||
row.setShopName(shopName);
|
||||
row.setNodeId(nodeId);
|
||||
row.setParentNodeId(parentNodeId);
|
||||
row.setNodeName(nodeName);
|
||||
row.setNodeLevel(level);
|
||||
row.setSortOrder(order);
|
||||
row.setCapturedAt(capturedAt);
|
||||
return row;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user