@Override
    public Integer getCategoryLevel(Long id) {
        if (Objects.equals(id, PARENT_ID_NULL)) {
            return 0;
        }
        int level = 1;
        // for 的原因，是因为避免脏数据，导致可能的死循环。一般不会超过 100 层哈
        for (int i = 0; i < Byte.MAX_VALUE; i++) {
            // 如果没有父节点，break 结束
            ProductCategoryDO category = productCategoryMapper.selectById(id);
            if (category == null
                    || Objects.equals(category.getParentId(), PARENT_ID_NULL)) {
                break;
            }
            // 继续递归父节点
            level++;
            id = category.getParentId();
        }
        return level;
    }
@Test
    public void testGetCategoryLevel() {
        // mock 数据
        ProductCategoryDO category1 = randomPojo(ProductCategoryDO.class,
                o -> o.setParentId(PARENT_ID_NULL));
        productCategoryMapper.insert(category1);
        ProductCategoryDO category2 = randomPojo(ProductCategoryDO.class,
                o -> o.setParentId(category1.getId()));
        productCategoryMapper.insert(category2);
        ProductCategoryDO category3 = randomPojo(ProductCategoryDO.class,
                o -> o.setParentId(category2.getId()));
        productCategoryMapper.insert(category3);

        // 调用，并断言
        assertEquals(productCategoryService.getCategoryLevel(category1.getId()), 1);
        assertEquals(productCategoryService.getCategoryLevel(category2.getId()), 2);
        assertEquals(productCategoryService.getCategoryLevel(category3.getId()), 3);
    }