From 98ca807d4b9ad660f5cb813c19504b9a5ba7d7bb Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 12 Dec 2022 22:25:31 +0800 Subject: [PATCH] =?UTF-8?q?product=EF=BC=9A=E4=BC=98=E5=8C=96=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=B1=9E=E6=80=A7=E9=A1=B9=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/enums/ErrorCodeConstants.java | 1 + .../property/ProductPropertyController.java | 28 ++++++-- .../ProductPropertyAndValueRespVO.java | 20 ++++-- .../vo/property/ProductPropertyBaseVO.java | 5 -- .../vo/property/ProductPropertyListReqVO.java | 3 - .../vo/value/ProductPropertyValueBaseVO.java | 4 -- .../property/ProductPropertyConvert.java | 16 ++++- .../property/ProductPropertyDO.java | 9 --- .../property/ProductPropertyValueDO.java | 7 -- .../mysql/property/ProductPropertyMapper.java | 9 ++- .../property/ProductPropertyValueMapper.java | 14 ++-- .../property/ProductPropertyService.java | 22 +----- .../property/ProductPropertyServiceImpl.java | 71 +++++++------------ .../property/ProductPropertyValueService.java | 31 +++++++- .../ProductPropertyValueServiceImpl.java | 20 +++++- .../service/sku/ProductSkuServiceImpl.java | 4 +- .../service/spu/ProductSpuServiceImpl.java | 4 +- .../src/api/mall/product/property.js | 2 +- .../src/views/mall/product/property/index.vue | 32 --------- 19 files changed, 150 insertions(+), 152 deletions(-) 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 fc13ac760..ba3798318 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 @@ -25,6 +25,7 @@ public interface ErrorCodeConstants { // ========== 商品属性项 1008003000 ========== ErrorCode PROPERTY_NOT_EXISTS = new ErrorCode(1008003000, "属性项不存在"); ErrorCode PROPERTY_EXISTS = new ErrorCode(1008003001, "属性项的名称已存在"); + ErrorCode PROPERTY_DELETE_FAIL_VALUE_EXISTS = new ErrorCode(1008003002, "属性项下存在属性值,无法删除"); // ========== 商品属性值 1008004000 ========== ErrorCode PROPERTY_VALUE_NOT_EXISTS = new ErrorCode(1008004000, "属性值不存在"); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java index f06761ce8..5efecd0c7 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java @@ -1,9 +1,14 @@ package cn.iocoder.yudao.module.product.controller.admin.property; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.*; +import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert; +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; import cn.iocoder.yudao.module.product.service.property.ProductPropertyService; +import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -13,10 +18,11 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; - +import java.util.Collections; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @Api(tags = "管理后台 - 商品属性项") @RestController @@ -26,6 +32,8 @@ public class ProductPropertyController { @Resource private ProductPropertyService productPropertyService; + @Resource + private ProductPropertyValueService productPropertyValueService; @PostMapping("/create") @ApiOperation("创建属性项") @@ -56,28 +64,36 @@ public class ProductPropertyController { @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('product:property:query')") public CommonResult getProperty(@RequestParam("id") Long id) { - return success(productPropertyService.getProperty(id)); + return success(ProductPropertyConvert.INSTANCE.convert(productPropertyService.getProperty(id))); } @GetMapping("/list") @ApiOperation("获得属性项列表") @PreAuthorize("@ss.hasPermission('product:property:query')") public CommonResult> getPropertyList(@Valid ProductPropertyListReqVO listReqVO) { - return success(productPropertyService.getPropertyVOList(listReqVO)); + return success(ProductPropertyConvert.INSTANCE.convertList(productPropertyService.getPropertyList(listReqVO))); } @GetMapping("/page") @ApiOperation("获得属性项分页") @PreAuthorize("@ss.hasPermission('product:property:query')") public CommonResult> getPropertyPage(@Valid ProductPropertyPageReqVO pageVO) { - return success(productPropertyService.getPropertyPage(pageVO)); + return success(ProductPropertyConvert.INSTANCE.convertPage(productPropertyService.getPropertyPage(pageVO))); } - @GetMapping("/listAndValue") + @GetMapping("/get-value-list") @ApiOperation("获得属性项列表") @PreAuthorize("@ss.hasPermission('product:property:query')") public CommonResult> getPropertyAndValueList(@Valid ProductPropertyListReqVO listReqVO) { - return success(productPropertyService.getPropertyAndValueList(listReqVO)); + // 查询属性项 + List keys = productPropertyService.getPropertyList(listReqVO); + if (CollUtil.isEmpty(keys)) { + return success(Collections.emptyList()); + } + // 查询属性值 + List values = productPropertyValueService.getPropertyValueListByPropertyId( + convertSet(keys, ProductPropertyDO::getId)); + return success(ProductPropertyConvert.INSTANCE.convertList(keys, values)); } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyAndValueRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyAndValueRespVO.java index 03d82fd3c..e9abab56b 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyAndValueRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyAndValueRespVO.java @@ -1,13 +1,11 @@ package cn.iocoder.yudao.module.product.controller.admin.property.vo.property; -import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -import java.time.LocalDateTime; import java.util.List; @ApiModel("管理后台 - 商品属性项 + 属性值 Response VO") @@ -19,12 +17,24 @@ public class ProductPropertyAndValueRespVO extends ProductPropertyBaseVO { @ApiModelProperty(value = "属性项的编号", required = true, example = "1024") private Long id; - @ApiModelProperty(value = "创建时间", required = true) - private LocalDateTime createTime; + @ApiModelProperty(value = "属性项的名称", required = true, example = "颜色") + private String name; /** * 属性值的集合 */ - private List values; + private List values; + + @ApiModel("管理后台 - 属性值的简单 Response VO") + @Data + public static class Value { + + @ApiModelProperty(value = "属性值的编号", required = true, example = "2048") + private Long id; + + @ApiModelProperty(value = "属性值的名称", required = true, example = "红色") + private String name; + + } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyBaseVO.java index bfedb42dc..fb089dce1 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyBaseVO.java @@ -4,7 +4,6 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; /** * 商品属性项 Base VO,提供给添加、修改、详细的子 VO 使用 @@ -20,8 +19,4 @@ public class ProductPropertyBaseVO { @ApiModelProperty(value = "备注", example = "颜色") private String remark; - @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举") - @NotNull(message = "状态不能为空") - private Integer status; - } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyListReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyListReqVO.java index e70f2c399..1233480d1 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyListReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyListReqVO.java @@ -13,7 +13,4 @@ public class ProductPropertyListReqVO { @ApiModelProperty(value = "名称", example = "颜色") private String name; - @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举") - private Integer status; - } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/value/ProductPropertyValueBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/value/ProductPropertyValueBaseVO.java index 0c077665d..76b2f1a8b 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/value/ProductPropertyValueBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/value/ProductPropertyValueBaseVO.java @@ -21,10 +21,6 @@ public class ProductPropertyValueBaseVO { @NotEmpty(message = "名称名字不能为空") private String name; - @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举") - @NotNull(message = "状态不能为空") - private Integer status; - @ApiModelProperty(value = "备注", example = "颜色") private String remark; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyConvert.java index 3e5a71117..211bcc293 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyConvert.java @@ -1,15 +1,18 @@ package cn.iocoder.yudao.module.product.convert.property; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyAndValueRespVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyRespVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyUpdateReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; import java.util.List; +import java.util.Map; /** * 属性项 Convert @@ -25,12 +28,21 @@ public interface ProductPropertyConvert { ProductPropertyDO convert(ProductPropertyUpdateReqVO bean); - ProductPropertyAndValueRespVO convert(ProductPropertyRespVO bean); - ProductPropertyRespVO convert(ProductPropertyDO bean); List convertList(List list); PageResult convertPage(PageResult page); + default List convertList(List keys, List values) { + Map> valueMap = CollectionUtils.convertMultiMap(values, ProductPropertyValueDO::getPropertyId); + return CollectionUtils.convertList(keys, key -> { + ProductPropertyAndValueRespVO respVO = convert02(key); + respVO.setValues(convertList02(valueMap.get(key.getId()))); + return respVO; + }); + } + ProductPropertyAndValueRespVO convert02(ProductPropertyDO bean); + List convertList02(List list); + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyDO.java index 973730b67..2976674c1 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyDO.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.product.dal.dataobject.property; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; @@ -31,17 +30,9 @@ public class ProductPropertyDO extends BaseDO { * 名称 */ private String name; - /** - * 状态 - * - * 枚举 {@link CommonStatusEnum} - */ - private Integer status; /** * 备注 */ private String remark; - // TODO 芋艿:rule;规格属性 (发布商品时,和 SKU 关联);规格参数(搜索商品时,与 Category 关联搜索) - } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyValueDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyValueDO.java index 6a964c76a..d73fe06b2 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyValueDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyValueDO.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.product.dal.dataobject.property; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; @@ -38,12 +37,6 @@ public class ProductPropertyValueDO extends BaseDO { * 名称 */ private String name; - /** - * 状态 - * - * 枚举 {@link CommonStatusEnum} - */ - private Integer status; /** * 备注 * diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyMapper.java index 0639ff884..195b50d13 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyMapper.java @@ -3,17 +3,19 @@ package cn.iocoder.yudao.module.product.dal.mysql.property; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyListReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyPageReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + @Mapper public interface ProductPropertyMapper extends BaseMapperX { default PageResult selectPage(ProductPropertyPageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() .likeIfPresent(ProductPropertyDO::getName, reqVO.getName()) - .eqIfPresent(ProductPropertyDO::getStatus, reqVO.getStatus()) .betweenIfPresent(ProductPropertyDO::getCreateTime, reqVO.getCreateTime()) .orderByDesc(ProductPropertyDO::getId)); } @@ -23,4 +25,9 @@ public interface ProductPropertyMapper extends BaseMapperX { .eqIfPresent(ProductPropertyDO::getName, name)); } + default List selectList(ProductPropertyListReqVO listReqVO) { + return selectList(new LambdaQueryWrapperX() + .eqIfPresent(ProductPropertyDO::getName, listReqVO.getName())); + } + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyValueMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyValueMapper.java index 70565a7d0..402df51e7 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyValueMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyValueMapper.java @@ -7,12 +7,13 @@ import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.Produc import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; import org.apache.ibatis.annotations.Mapper; +import java.util.Collection; import java.util.List; @Mapper public interface ProductPropertyValueMapper extends BaseMapperX { - default List selectListByPropertyId(List propertyIds) { + default List selectListByPropertyId(Collection propertyIds) { return selectList(new LambdaQueryWrapperX() .inIfPresent(ProductPropertyValueDO::getPropertyId, propertyIds)); } @@ -23,17 +24,20 @@ public interface ProductPropertyValueMapper extends BaseMapperX().eq(ProductPropertyValueDO::getPropertyId, propertyId) - .eq(ProductPropertyValueDO::getDeleted, false)); + default void deleteByPropertyId(Long propertyId) { + delete(new LambdaQueryWrapperX() + .eq(ProductPropertyValueDO::getPropertyId, propertyId)); } default PageResult selectPage(ProductPropertyValuePageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() .eqIfPresent(ProductPropertyValueDO::getPropertyId, reqVO.getPropertyId()) .likeIfPresent(ProductPropertyValueDO::getName, reqVO.getName()) - .eqIfPresent(ProductPropertyValueDO::getStatus, reqVO.getStatus()) .orderByDesc(ProductPropertyValueDO::getId)); } + default Integer selectCountByPropertyId(Long propertyId) { + return selectCount(ProductPropertyValueDO::getPropertyId, propertyId).intValue(); + } + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyService.java index 3fb78ef4c..855d2f0f6 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyService.java @@ -42,7 +42,7 @@ public interface ProductPropertyService { * @param listReqVO 集合查询 * @return 属性项集合 */ - List getPropertyVOList(ProductPropertyListReqVO listReqVO); + List getPropertyList(ProductPropertyListReqVO listReqVO); /** * 获取属性名称分页 @@ -50,7 +50,7 @@ public interface ProductPropertyService { * @param pageReqVO 分页条件 * @return 属性项分页 */ - PageResult getPropertyPage(ProductPropertyPageReqVO pageReqVO); + PageResult getPropertyPage(ProductPropertyPageReqVO pageReqVO); /** * 获得指定编号的属性项 @@ -58,7 +58,7 @@ public interface ProductPropertyService { * @param id 编号 * @return 属性项 */ - ProductPropertyRespVO getProperty(Long id); + ProductPropertyDO getProperty(Long id); /** * 根据属性项的编号的集合,获得对应的属性项数组 @@ -68,20 +68,4 @@ public interface ProductPropertyService { */ List getPropertyList(Collection ids); - /** - * 根据属性项的编号的集合,获得对应的属性项数组 - * - * @param ids 属性项的编号的集合 - * @return 属性项数组 - */ - List getPropertyVOList(Collection ids); - - /** - * 获得属性项 + 值的列表 - * - * @param listReqVO 列表查询 - * @return 属性项 + 值的列表 - */ - List getPropertyAndValueList(ProductPropertyListReqVO listReqVO); - } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java index 573cefebe..ba0704c72 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java @@ -1,15 +1,15 @@ package cn.iocoder.yudao.module.product.service.property; +import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.*; +import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyCreateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyListReqVO; +import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyPageReqVO; +import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyUpdateReqVO; import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert; -import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert; import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; -import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyMapper; -import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyValueMapper; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -17,11 +17,9 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.Collection; import java.util.List; -import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_EXISTS; -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_NOT_EXISTS; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; /** * 商品属性项 Service 实现类 @@ -36,15 +34,17 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { private ProductPropertyMapper productPropertyMapper; @Resource - private ProductPropertyValueMapper productPropertyValueMapper; + @Lazy // 延迟加载,解决循环依赖问题 + private ProductPropertyValueService productPropertyValueService; @Override @Transactional(rollbackFor = Exception.class) public Long createProperty(ProductPropertyCreateReqVO createReqVO) { - // 校验存在 + // 校验名字重复 if (productPropertyMapper.selectByName(createReqVO.getName()) != null) { throw exception(PROPERTY_EXISTS); } + // 插入 ProductPropertyDO property = ProductPropertyConvert.INSTANCE.convert(createReqVO); productPropertyMapper.insert(property); @@ -55,12 +55,14 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { @Override @Transactional(rollbackFor = Exception.class) public void updateProperty(ProductPropertyUpdateReqVO updateReqVO) { - // 校验存在 validatePropertyExists(updateReqVO.getId()); + // 校验名字重复 ProductPropertyDO productPropertyDO = productPropertyMapper.selectByName(updateReqVO.getName()); - if (productPropertyDO != null && !productPropertyDO.getId().equals(updateReqVO.getId())) { + if (productPropertyDO != null && + ObjUtil.notEqual(productPropertyDO.getId(), updateReqVO.getId())) { throw exception(PROPERTY_EXISTS); } + // 更新 ProductPropertyDO updateObj = ProductPropertyConvert.INSTANCE.convert(updateReqVO); productPropertyMapper.updateById(updateObj); @@ -70,10 +72,15 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { public void deleteProperty(Long id) { // 校验存在 validatePropertyExists(id); + // 校验其下是否有规格值 + if (productPropertyValueService.getPropertyValueCountByPropertyId(id) > 0) { + throw exception(PROPERTY_DELETE_FAIL_VALUE_EXISTS); + } + // 删除 productPropertyMapper.deleteById(id); // 同步删除属性值 - productPropertyValueMapper.deletePropertyValueByPropertyId(id); + productPropertyValueService.deletePropertyValueByPropertyId(id); } private void validatePropertyExists(Long id) { @@ -83,22 +90,18 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { } @Override - public List getPropertyVOList(ProductPropertyListReqVO listReqVO) { - return ProductPropertyConvert.INSTANCE.convertList(productPropertyMapper.selectList(new LambdaQueryWrapperX() - .likeIfPresent(ProductPropertyDO::getName, listReqVO.getName()) - .eqIfPresent(ProductPropertyDO::getStatus, listReqVO.getStatus()))); + public List getPropertyList(ProductPropertyListReqVO listReqVO) { + return productPropertyMapper.selectList(listReqVO); } @Override - public PageResult getPropertyPage(ProductPropertyPageReqVO pageReqVO) { - PageResult pageResult = productPropertyMapper.selectPage(pageReqVO); - return ProductPropertyConvert.INSTANCE.convertPage(pageResult); + public PageResult getPropertyPage(ProductPropertyPageReqVO pageReqVO) { + return productPropertyMapper.selectPage(pageReqVO); } @Override - public ProductPropertyRespVO getProperty(Long id) { - ProductPropertyDO property = productPropertyMapper.selectById(id); - return ProductPropertyConvert.INSTANCE.convert(property); + public ProductPropertyDO getProperty(Long id) { + return productPropertyMapper.selectById(id); } @Override @@ -106,24 +109,4 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { return productPropertyMapper.selectBatchIds(ids); } - // TODO @芋艿:丢到 Controller - @Override - public List getPropertyVOList(Collection ids) { - return ProductPropertyConvert.INSTANCE.convertList(productPropertyMapper.selectBatchIds(ids)); - } - - // TODO @芋艿:丢到 Controller - @Override - public List getPropertyAndValueList(ProductPropertyListReqVO listReqVO) { - List propertyList = getPropertyVOList(listReqVO); - - // 查询属性值 - List valueDOList = productPropertyValueMapper.selectListByPropertyId(CollectionUtils.convertList(propertyList, ProductPropertyRespVO::getId)); - Map> valueDOMap = CollectionUtils.convertMultiMap(valueDOList, ProductPropertyValueDO::getPropertyId); - return CollectionUtils.convertList(propertyList, m -> { - ProductPropertyAndValueRespVO productPropertyAndValueRespVO = ProductPropertyConvert.INSTANCE.convert(m); - productPropertyAndValueRespVO.setValues(ProductPropertyValueConvert.INSTANCE.convertList(valueDOMap.get(m.getId()))); - return productPropertyAndValueRespVO; - }); - } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueService.java index d5816537f..8cf4cce2a 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueService.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.Produc import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO; +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO; import java.util.Collection; @@ -47,6 +48,14 @@ public interface ProductPropertyValueService { */ ProductPropertyValueRespVO getPropertyValue(Long id); + /** + * 根据属性项编号数组,获得属性值列表 + * + * @param propertyIds 属性项目编号数组 + * @return 属性值列表 + */ + List getPropertyValueListByPropertyId(Collection propertyIds); + /** * 根据编号数组,获得属性值列表 * @@ -56,12 +65,20 @@ public interface ProductPropertyValueService { List getPropertyValueDetailList(Collection ids); /** - * 获得属性值 + * 根据属性项编号,获得属性值数组 * - * @param id 编号 + * @param propertyIds 属性项编号数组 * @return 属性值 */ - List getPropertyValueListByPropertyId(List id); + List getPropertyValueListByPropertyId(List propertyIds); + + /** + * 根据属性项编号,活的属性值数量 + * + * @param propertyId 属性项编号数 + * @return 属性值数量 + */ + Integer getPropertyValueCountByPropertyId(Long propertyId); /** * 获取属性值的分页 @@ -70,4 +87,12 @@ public interface ProductPropertyValueService { * @return 属性值的分页 */ PageResult getPropertyValueListPage(ProductPropertyValuePageReqVO pageReqVO); + + /** + * 删除指定属性项编号下的属性值们 + * + * @param propertyId 属性项的编号 + */ + void deletePropertyValueByPropertyId(Long propertyId); + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java index 309cc3e31..8671a40e9 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java @@ -73,6 +73,11 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ return ProductPropertyValueConvert.INSTANCE.convert(productPropertyValueDO); } + @Override + public List getPropertyValueListByPropertyId(Collection propertyIds) { + return productPropertyValueMapper.selectListByPropertyId(propertyIds); + } + @Override public List getPropertyValueDetailList(Collection ids) { // 获得属性值列表 @@ -91,12 +96,23 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ } @Override - public List getPropertyValueListByPropertyId(List id) { - return ProductPropertyValueConvert.INSTANCE.convertList(productPropertyValueMapper.selectList("property_id", id)); + public List getPropertyValueListByPropertyId(List propertyIds) { + return ProductPropertyValueConvert.INSTANCE.convertList(productPropertyValueMapper.selectList("property_id", propertyIds)); + } + + @Override + public Integer getPropertyValueCountByPropertyId(Long propertyId) { + return productPropertyValueMapper.selectCountByPropertyId(propertyId); } @Override public PageResult getPropertyValueListPage(ProductPropertyValuePageReqVO pageReqVO) { return ProductPropertyValueConvert.INSTANCE.convertPage(productPropertyValueMapper.selectPage(pageReqVO)); } + + @Override + public void deletePropertyValueByPropertyId(Long propertyId) { + productPropertyValueMapper.deleteByPropertyId(propertyId); + } + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java index 093f5daea..4f3d2ebed 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java @@ -3,11 +3,11 @@ package cn.iocoder.yudao.module.product.service.sku; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; -import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyRespVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.mysql.sku.ProductSkuMapper; import cn.iocoder.yudao.module.product.enums.ErrorCodeConstants; @@ -89,7 +89,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { .flatMap(p -> p.getProperties().stream()) // 遍历多个 Property 属性 .map(ProductSkuBaseVO.Property::getPropertyId) // 将每个 Property 转换成对应的 propertyId,最后形成集合 .collect(Collectors.toSet()); - List propertyList = productPropertyService.getPropertyVOList(propertyIds); + List propertyList = productPropertyService.getPropertyList(propertyIds); if (propertyList.size() != propertyIds.size()) { throw exception(PROPERTY_NOT_EXISTS); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java index 9dda8da50..01c69ec49 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java @@ -5,7 +5,6 @@ import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyViewRespVO; -import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyRespVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; @@ -15,6 +14,7 @@ import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO; import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; @@ -142,7 +142,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { Map> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId)); List propertyValueList = productPropertyValueService.getPropertyValueListByPropertyId(new ArrayList<>(propertyMaps.keySet())); - List propertyList = productPropertyService.getPropertyVOList(new ArrayList<>(propertyMaps.keySet())); + List propertyList = productPropertyService.getPropertyList(propertyMaps.keySet()); // 装载组装过后的属性 List productPropertyViews = new ArrayList<>(); propertyList.forEach(p -> { diff --git a/yudao-ui-admin/src/api/mall/product/property.js b/yudao-ui-admin/src/api/mall/product/property.js index f668454a0..f8ec1c63a 100644 --- a/yudao-ui-admin/src/api/mall/product/property.js +++ b/yudao-ui-admin/src/api/mall/product/property.js @@ -57,7 +57,7 @@ export function getPropertyList(query) { // 获得属性项列表 export function getPropertyListAndValue(query) { return request({ - url: '/product/property/listAndValue', + url: '/product/property/get-value-list', method: 'get', params: query }) diff --git a/yudao-ui-admin/src/views/mall/product/property/index.vue b/yudao-ui-admin/src/views/mall/product/property/index.vue index 301106d4e..b3b8d4566 100644 --- a/yudao-ui-admin/src/views/mall/product/property/index.vue +++ b/yudao-ui-admin/src/views/mall/product/property/index.vue @@ -41,11 +41,6 @@ - - -