product:优化商品分类的代码

This commit is contained in:
YunaiV
2022-12-14 20:32:44 +08:00
parent 5474ae876d
commit 2f9eef589b
8 changed files with 95 additions and 40 deletions

View File

@@ -103,6 +103,25 @@ public class ProductCategoryServiceImplTest extends BaseDbUnitTest {
assertServiceException(() -> productCategoryService.deleteCategory(id), CATEGORY_NOT_EXISTS);
}
@Test
public void testGetCategoryLevel() {
// mock 数据
ProductCategoryDO category1 = randomPojo(ProductCategoryDO.class,
o -> o.setParentId(ProductCategoryDO.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);
}
@Test
public void testGetCategoryList() {
// mock 数据

View File

@@ -187,9 +187,9 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest {
});
Mockito.when(productSkuService.getSkusBySpuId(createReqVO.getId())).thenReturn(productSkuDOS);
Mockito.when(productPropertyValueService.getPropertyValueListByPropertyId(new ArrayList<>(collect.keySet()))).thenReturn(productPropertyValueRespVO);
Mockito.when(productPropertyService.getPropertyVOList(new ArrayList<>(collect.keySet()))).thenReturn(productPropertyRespVOS);
// Mockito.when(productPropertyValueService.getPropertyValueListByPropertyId(new ArrayList<>(collect.keySet()))).thenReturn(productPropertyValueRespVO);
// Mockito.when(productPropertyService.getPropertyVOList(new ArrayList<>(collect.keySet()))).thenReturn(productPropertyRespVOS);
//
// 调用
ProductSpuDetailRespVO spuDetail = productSpuService.getSpuDetail(createReqVO.getId());

View File

@@ -52,3 +52,19 @@ CREATE TABLE IF NOT EXISTS `product_spu` (
`deleted` bit(1) NOT NULL DEFAULT 0 COMMENT '是否删除',
PRIMARY KEY (`id`)
) COMMENT '商品spu';
CREATE TABLE IF NOT EXISTS `product_category` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '分类编号',
`parent_id` bigint DEFAULT NULL COMMENT '父分类编号',
`name` varchar(128) NOT NULL COMMENT '分类名称',
`description` varchar(128) NOT NULL COMMENT '分类描述',
`pic_url` varchar DEFAULT NULL COMMENT '分类图片',
`sort` int NOT NULL DEFAULT '0' COMMENT '排序字段',
`status` bit(1) DEFAULT NULL COMMENT '状态',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`creator` varchar DEFAULT NULL COMMENT '创建人',
`updater` varchar DEFAULT NULL COMMENT '更新人',
`deleted` bit(1) NOT NULL DEFAULT 0 COMMENT '是否删除',
PRIMARY KEY (`id`)
) COMMENT '商品分类';