diff --git a/sql/optional/mall/mall.sql b/sql/optional/mall/mall.sql index ae5770a21..486b6f2fc 100644 --- a/sql/optional/mall/mall.sql +++ b/sql/optional/mall/mall.sql @@ -39,7 +39,7 @@ CREATE TABLE `market_activity` ( `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '促销活动'; +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '促销活动'; -- ---------------------------- -- Records of market_activity @@ -66,7 +66,7 @@ CREATE TABLE `market_banner` ( `sort` tinyint NULL DEFAULT NULL COMMENT '排序', `memo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '描述', PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'Banner管理'; +) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'Banner管理'; -- ---------------------------- -- Records of market_banner diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java index af97bb9c3..801e2dd51 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java @@ -19,6 +19,8 @@ public interface ErrorCodeConstants { // ========== 商品品牌相关编号 1008002000 ========== ErrorCode BRAND_NOT_EXISTS = new ErrorCode(1008002000, "品牌不存在"); + ErrorCode BRAND_DISABLED = new ErrorCode(1008002001, "品牌不存在"); + ErrorCode BRAND_NAME_EXISTS = new ErrorCode(1008002002, "品牌名称已存在"); // ========== 商品规格名称 1008003000 ========== ErrorCode PROPERTY_NOT_EXISTS = new ErrorCode(1008003000, "规格名称不存在"); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java index 0558d9866..2227afeaf 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java @@ -33,7 +33,7 @@ public class ProductBrandController { @ApiOperation("创建品牌") @PreAuthorize("@ss.hasPermission('product:brand:create')") public CommonResult createBrand(@Valid @RequestBody ProductBrandCreateReqVO createReqVO) { - return success(brandService.createProductBrand(createReqVO)); + return success(brandService.createBrand(createReqVO)); } @PutMapping("/update") @@ -73,7 +73,7 @@ public class ProductBrandController { @GetMapping("/list") @ApiOperation("获得品牌列表") @PreAuthorize("@ss.hasPermission('product:brand:query')") - public CommonResult> getProductCategoryList(@Valid ProductBrandListReqVO listVO) { + public CommonResult> getBrandList(@Valid ProductBrandListReqVO listVO) { List list = brandService.getBrandList(listVO); list.sort(Comparator.comparing(ProductBrandDO::getSort)); return success(ProductBrandConvert.INSTANCE.convertList(list)); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandBaseVO.java index 3ad5d45ee..fa5ecd2d1 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandBaseVO.java @@ -20,7 +20,8 @@ public class ProductBrandBaseVO { @NotNull(message = "品牌图片不能为空") private String picUrl; - @ApiModelProperty(value = "品牌排序", example = "1") + @ApiModelProperty(value = "品牌排序", required = true, example = "1") + @NotNull(message = "品牌排序不能为空") private Integer sort; @ApiModelProperty(value = "品牌描述", example = "描述") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandPageReqVO.java index 8dae40244..3b3d829de 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandPageReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandPageReqVO.java @@ -21,7 +21,7 @@ public class ProductBrandPageReqVO extends PageParam { @ApiModelProperty(value = "品牌名称", example = "芋道") private String name; - @ApiModelProperty(value = "状态", example = "0") + @ApiModelProperty(value = "状态", example = "0", notes = "参考 CommonStatusEnum 枚举") private Integer status; @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/ProductCategoryController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/ProductCategoryController.java index 2a93a5a26..4144e6a57 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/ProductCategoryController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/ProductCategoryController.java @@ -34,14 +34,14 @@ public class ProductCategoryController { @PostMapping("/create") @ApiOperation("创建商品分类") @PreAuthorize("@ss.hasPermission('product:category:create')") - public CommonResult createProductCategory(@Valid @RequestBody ProductCategoryCreateReqVO createReqVO) { + public CommonResult createCategory(@Valid @RequestBody ProductCategoryCreateReqVO createReqVO) { return success(categoryService.createCategory(createReqVO)); } @PutMapping("/update") @ApiOperation("更新商品分类") @PreAuthorize("@ss.hasPermission('product:category:update')") - public CommonResult updateProductCategory(@Valid @RequestBody ProductCategoryUpdateReqVO updateReqVO) { + public CommonResult updateCategory(@Valid @RequestBody ProductCategoryUpdateReqVO updateReqVO) { categoryService.updateCategory(updateReqVO); return success(true); } @@ -50,7 +50,7 @@ public class ProductCategoryController { @ApiOperation("删除商品分类") @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('product:category:delete')") - public CommonResult deleteProductCategory(@RequestParam("id") Long id) { + public CommonResult deleteCategory(@RequestParam("id") Long id) { categoryService.deleteCategory(id); return success(true); } @@ -59,7 +59,7 @@ public class ProductCategoryController { @ApiOperation("获得商品分类") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('product:category:query')") - public CommonResult getProductCategory(@RequestParam("id") Long id) { + public CommonResult getCategory(@RequestParam("id") Long id) { ProductCategoryDO category = categoryService.getCategory(id); return success(ProductCategoryConvert.INSTANCE.convert(category)); } @@ -67,7 +67,7 @@ public class ProductCategoryController { @GetMapping("/list") @ApiOperation("获得商品分类列表") @PreAuthorize("@ss.hasPermission('product:category:query')") - public CommonResult> getProductCategoryList(@Valid ProductCategoryListReqVO treeListReqVO) { + public CommonResult> getCategoryList(@Valid ProductCategoryListReqVO treeListReqVO) { List list = categoryService.getEnableCategoryList(treeListReqVO); list.sort(Comparator.comparing(ProductCategoryDO::getSort)); return success(ProductCategoryConvert.INSTANCE.convertList(list)); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java index 55e4e6927..a62df7dc8 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java @@ -27,4 +27,8 @@ public interface ProductBrandMapper extends BaseMapperX { .likeIfPresent(ProductBrandDO::getName, reqVO.getName())); } + default ProductBrandDO selectByName(String name) { + return selectOne(ProductBrandDO::getName, name); + } + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java index 54d4df601..a90ec8a87 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java @@ -21,7 +21,7 @@ public interface ProductBrandService { * @param createReqVO 创建信息 * @return 编号 */ - Long createProductBrand(@Valid ProductBrandCreateReqVO createReqVO); + Long createBrand(@Valid ProductBrandCreateReqVO createReqVO); /** * 更新品牌 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java index 28a02da38..c7a3e5198 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.product.service.brand; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandListReqVO; @@ -8,6 +9,7 @@ import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpd import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert; import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; import cn.iocoder.yudao.module.product.dal.mysql.brand.ProductBrandMapper; +import com.google.common.annotations.VisibleForTesting; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -16,7 +18,7 @@ import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.BRAND_NOT_EXISTS; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; /** * 品牌 Service 实现类 @@ -31,7 +33,10 @@ public class ProductBrandServiceImpl implements ProductBrandService { private ProductBrandMapper brandMapper; @Override - public Long createProductBrand(ProductBrandCreateReqVO createReqVO) { + public Long createBrand(ProductBrandCreateReqVO createReqVO) { + // 校验 + validateBrandNameUnique(null, createReqVO.getName()); + // 插入 ProductBrandDO brand = ProductBrandConvert.INSTANCE.convert(createReqVO); brandMapper.insert(brand); @@ -43,6 +48,7 @@ public class ProductBrandServiceImpl implements ProductBrandService { public void updateBrand(ProductBrandUpdateReqVO updateReqVO) { // 校验存在 validateBrandExists(updateReqVO.getId()); + validateBrandNameUnique(updateReqVO.getId(), updateReqVO.getName()); // 更新 ProductBrandDO updateObj = ProductBrandConvert.INSTANCE.convert(updateReqVO); brandMapper.updateById(updateObj); @@ -51,7 +57,7 @@ public class ProductBrandServiceImpl implements ProductBrandService { @Override public void deleteBrand(Long id) { // 校验存在 - this.validateBrandExists(id); + validateBrandExists(id); // 删除 brandMapper.deleteById(id); } @@ -62,6 +68,21 @@ public class ProductBrandServiceImpl implements ProductBrandService { } } + @VisibleForTesting + public void validateBrandNameUnique(Long id, String name) { + ProductBrandDO brand = brandMapper.selectByName(name); + if (brand == null) { + return; + } + // 如果 id 为空,说明不用比较是否为相同 id 的字典类型 + if (id == null) { + throw exception(BRAND_NAME_EXISTS); + } + if (!brand.getId().equals(id)) { + throw exception(BRAND_NAME_EXISTS); + } + } + @Override public ProductBrandDO getBrand(Long id) { return brandMapper.selectById(id); @@ -79,9 +100,13 @@ public class ProductBrandServiceImpl implements ProductBrandService { @Override public void validateProductBrand(Long id) { - if(getBrand(id) == null){ + ProductBrandDO brand = brandMapper.selectById(id); + if (brand == null) { throw exception(BRAND_NOT_EXISTS); } + if (brand.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) { + throw exception(BRAND_DISABLED); + } } @Override diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java index b4664fd4d..ebfe599d6 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java @@ -63,7 +63,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { if (productCategoryMapper.selectCountByParentId(id) > 0) { throw exception(CATEGORY_EXISTS_CHILDREN); } - + // TODO 芋艿 补充只有不存在商品才可以删除 // 删除 productCategoryMapper.deleteById(id); } @@ -94,8 +94,8 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { @Override public void validateCategoryLevel(Long id) { Integer level = getProductCategoryLevel(id, 1); - if(level < 3){ - throw exception(CATEGORY_LEVEL_ERROR); + if (level < 3){ + throw exception(CATEGORY_LEVEL_ERROR); } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImplTest.java index 179778d0b..93817d44c 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImplTest.java +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImplTest.java @@ -43,7 +43,7 @@ public class ProductBrandServiceImplTest extends BaseDbUnitTest { ProductBrandCreateReqVO reqVO = randomPojo(ProductBrandCreateReqVO.class); // 调用 - Long brandId = brandService.createProductBrand(reqVO); + Long brandId = brandService.createBrand(reqVO); // 断言 assertNotNull(brandId); // 校验记录的属性是否正确 diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index fb31aa345..c26354ead 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -45,7 +45,7 @@ spring: datasource: master: name: ruoyi-vue-pro - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 + url: jdbc:mysql://139.9.196.247:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例 # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 @@ -56,7 +56,7 @@ spring: # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W slave: # 模拟从库,可根据自己需要修改 name: ruoyi-vue-pro - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 + url: jdbc:mysql://139.9.196.247:3306/${spring.datasource.dynamic.datasource.slave.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例 # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 @@ -68,10 +68,10 @@ spring: # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 redis: - host: 127.0.0.1 # 地址 + host: 139.9.196.247 # 地址 port: 6379 # 端口 database: 0 # 数据库索引 -# password: 123456 # 密码,建议生产环境开启 + password: 123456 # 密码,建议生产环境开启 jasypt: encryptor: diff --git a/yudao-ui-admin/src/views/mall/product/category/index.vue b/yudao-ui-admin/src/views/mall/product/category/index.vue index fccadb81c..24ae64319 100644 --- a/yudao-ui-admin/src/views/mall/product/category/index.vue +++ b/yudao-ui-admin/src/views/mall/product/category/index.vue @@ -61,10 +61,8 @@ - +