From 63dd545c506a4d52f01e016b09370678b8eac7c2 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Wed, 6 Mar 2019 21:39:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE=E5=AD=97?= =?UTF-8?q?=E5=85=B8=20tree=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admins/AdminController.java | 2 +- .../controller/admins/DataDictController.java | 24 ++++++ .../application/convert/DataDictConvert.java | 4 + .../admin/application/vo/DataDictEnumVO.java | 34 +++++++++ .../admin/application/vo/DataDictValueVO.java | 32 ++++++++ .../admins/AdminsProductAttrController.java | 74 ++++++++++++++++++ .../convert/ProductAttrConvert.java | 25 +++++++ .../AdminsProductAttrAndValuePairVO.java | 54 +++++++++++++ .../vo/admins/AdminsProductAttrDetailVO.java | 60 +++++++++------ .../vo/admins/AdminsProductAttrPageVO.java | 34 +++++++++ .../vo/admins/AdminsProductAttrSimpleVO.java | 45 +++++++++++ .../vo/admins/AdminsProductAttrVO.java | 20 +++++ .../AdminsProductAttrValueDetailVO.java | 56 ++++++++++++++ .../AdminsProductAttrValueSimpleVO.java | 32 ++++++++ .../vo/admins/AdminsProductSkuDetailVO.java | 6 +- .../vo/admins/AdminsProductSpuPageVO.java | 9 +-- .../mall/product/api/ProductAttrService.java | 23 ++++++ .../api/bo/ProductAttrAndValuePairBO.java | 61 +++++++++++++++ .../product/api/bo/ProductAttrDetailBO.java | 61 +++++++++------ .../product/api/bo/ProductAttrPageBO.java | 37 +++++++++ .../product/api/bo/ProductAttrSimpleBO.java | 50 +++++++++++++ .../api/bo/ProductAttrValueDetailBO.java | 62 +++++++++++++++ .../api/bo/ProductAttrValueSimpleBO.java | 35 +++++++++ .../product/api/bo/ProductSkuDetailBO.java | 6 +- .../product/api/dto/ProductAttrPageDTO.java | 44 +++++++++++ .../product/api/dto/ProductSpuPageDTO.java | 3 + .../product/convert/ProductAttrConvert.java | 38 ++++++++++ .../product/convert/ProductSpuConvert.java | 10 +-- .../mall/product/dao/ProductAttrMapper.java | 8 ++ .../product/dao/ProductAttrValueMapper.java | 4 + .../service/ProductAttrServiceImpl.java | 75 ++++++++++++++++--- .../service/ProductSpuServiceImpl.java | 17 +++-- .../resources/mapper/ProductAttrMapper.xml | 37 +++++++++ .../mapper/ProductAttrValueMapper.xml | 23 ++++++ 34 files changed, 1023 insertions(+), 82 deletions(-) create mode 100644 admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictEnumVO.java create mode 100644 admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictValueVO.java create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductAttrController.java create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/convert/ProductAttrConvert.java create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrAndValuePairVO.java create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrPageVO.java create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrSimpleVO.java create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrVO.java create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrValueDetailVO.java create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrValueSimpleVO.java create mode 100644 product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductAttrService.java create mode 100644 product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrAndValuePairBO.java create mode 100644 product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrPageBO.java create mode 100644 product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrSimpleBO.java create mode 100644 product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrValueDetailBO.java create mode 100644 product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrValueSimpleBO.java create mode 100644 product/product-service-api/src/main/java/cn/iocoder/mall/product/api/dto/ProductAttrPageDTO.java create mode 100644 product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductAttrConvert.java diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java index a14c331d2..4f5a4744b 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java @@ -113,7 +113,7 @@ public class AdminController { @ApiImplicitParam(name = "id", value = "管理员编号", required = true, example = "1"), @ApiImplicitParam(name = "username", value = "账号", required = true, example = "15601691300"), @ApiImplicitParam(name = "nickname", value = "昵称", required = true, example = "小王"), - @ApiImplicitParam(name = "password", value = "密码", required = true, example = "buzhidao"), + @ApiImplicitParam(name = "password", value = "密码", example = "buzhidao"), }) public CommonResult update(@RequestParam("id") Integer id, @RequestParam("username") String username, diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java index 90903c4f9..8e283a710 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DataDictController.java @@ -6,15 +6,19 @@ import cn.iocoder.mall.admin.api.bo.DataDictBO; import cn.iocoder.mall.admin.api.dto.DataDictAddDTO; import cn.iocoder.mall.admin.api.dto.DataDictUpdateDTO; import cn.iocoder.mall.admin.application.convert.DataDictConvert; +import cn.iocoder.mall.admin.application.vo.DataDictEnumVO; import cn.iocoder.mall.admin.application.vo.DataDictVO; import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; import com.alibaba.dubbo.config.annotation.Reference; +import com.google.common.collect.ImmutableListMultimap; +import com.google.common.collect.Multimaps; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; +import java.util.ArrayList; import java.util.List; @RestController @@ -32,6 +36,26 @@ public class DataDictController { return DataDictConvert.INSTANCE.convert(result); } + @GetMapping("/tree") + @ApiOperation(value = "数据字典树结构", notes = "该接口返回的信息更为精简。一般用于前端缓存数据字典到本地。") + public CommonResult> tree() { + // 查询数据字典全列表 + CommonResult> result = dataDictService.selectDataDictList(); + if (result.isError()) { + return CommonResult.error(result); + } + // 构建基于 enumValue 聚合的 Multimap + ImmutableListMultimap dataDictMap = Multimaps.index(result.getData(), DataDictBO::getEnumValue); // KEY 是 enumValue ,VALUE 是 DataDictBO 数组 + // 构建返回结果 + List dataDictEnumVOs = new ArrayList<>(dataDictMap.size()); + dataDictMap.keys().forEach(enumValue -> { + DataDictEnumVO dataDictEnumVO = new DataDictEnumVO().setEnumValue(enumValue) + .setValues(DataDictConvert.INSTANCE.convert2(dataDictMap.get(enumValue))); + dataDictEnumVOs.add(dataDictEnumVO); + }); + return CommonResult.success(dataDictEnumVOs); + } + @PostMapping("/add") @ApiOperation(value = "创建数据字典") @ApiImplicitParams({ diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java index a7dc3c7fd..1b18244e6 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/DataDictConvert.java @@ -3,6 +3,7 @@ package cn.iocoder.mall.admin.application.convert; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.admin.api.bo.DataDictBO; import cn.iocoder.mall.admin.application.vo.DataDictVO; +import cn.iocoder.mall.admin.application.vo.DataDictValueVO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -26,4 +27,7 @@ public interface DataDictConvert { @Mappings({}) CommonResult convert2(CommonResult result); + @Mappings({}) + List convert2(List dataDictBOs); + } \ No newline at end of file diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictEnumVO.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictEnumVO.java new file mode 100644 index 000000000..8075d4770 --- /dev/null +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictEnumVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.admin.application.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +@ApiModel("数据字典枚举 VO") +public class DataDictEnumVO { + + @ApiModelProperty(value = "大类枚举值", required = true, example = "gender") + private String enumValue; + @ApiModelProperty(value = "小类数值数组", required = true) + private List values; + + public String getEnumValue() { + return enumValue; + } + + public DataDictEnumVO setEnumValue(String enumValue) { + this.enumValue = enumValue; + return this; + } + + public List getValues() { + return values; + } + + public DataDictEnumVO setValues(List values) { + this.values = values; + return this; + } + +} \ No newline at end of file diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictValueVO.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictValueVO.java new file mode 100644 index 000000000..2602d3359 --- /dev/null +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/DataDictValueVO.java @@ -0,0 +1,32 @@ +package cn.iocoder.mall.admin.application.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel("数据字典枚举值 VO") +public class DataDictValueVO { + + @ApiModelProperty(value = "小类数值", required = true, example = "1") + private String value; + @ApiModelProperty(value = "展示名", required = true, example = "男") + private String displayName; + + public String getValue() { + return value; + } + + public DataDictValueVO setValue(String value) { + this.value = value; + return this; + } + + public String getDisplayName() { + return displayName; + } + + public DataDictValueVO setDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + +} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductAttrController.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductAttrController.java new file mode 100644 index 000000000..aab184f00 --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductAttrController.java @@ -0,0 +1,74 @@ +package cn.iocoder.mall.product.application.controller.admins; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.product.api.ProductAttrService; +import cn.iocoder.mall.product.api.bo.ProductAttrPageBO; +import cn.iocoder.mall.product.api.bo.ProductAttrSimpleBO; +import cn.iocoder.mall.product.api.dto.ProductAttrPageDTO; +import cn.iocoder.mall.product.application.convert.ProductAttrConvert; +import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrPageVO; +import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrSimpleVO; +import com.alibaba.dubbo.config.annotation.Reference; +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("admins") +@Api("商品规格") +public class AdminsProductAttrController { + + @Reference(validation = "true") + private ProductAttrService productAttrService; + + @GetMapping("/attr/page") + public CommonResult attrPage(@RequestParam(value = "name", required = false) String name, + @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { + // 创建 ProductAttrPageDTO 对象 + ProductAttrPageDTO productAttrPageDTO = new ProductAttrPageDTO().setName(name).setPageNo(pageNo).setPageSize(pageSize); + // 查询分页 + CommonResult result = productAttrService.getProductAttrPage(productAttrPageDTO); + // 返回结果 + return ProductAttrConvert.INSTANCE.convert2(result); + } + + @GetMapping("/attr/tree") + public CommonResult> tree() { + // 查询全列表 + CommonResult> result = productAttrService.getProductAttrList(); + // 返回结果 + return ProductAttrConvert.INSTANCE.convert(result); + } + + @PostMapping("/attr/add") + public CommonResult addAttr() { + return null; + } + + public CommonResult updateAttr() { + return null; + } + + public CommonResult updateAttrStatus() { + return null; + } + + // TODO 芋艿 暂时不考虑 delete Attr 。因为关联逻辑比较多 + + public CommonResult addAttrValue() { + return null; + } + + public CommonResult updateAttrValue() { + return null; + } + + public CommonResult updateAttrValueStr() { + return null; + } + + // TODO 芋艿 暂时不考虑 delete Attr Value 。因为关联逻辑比较多 + +} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/convert/ProductAttrConvert.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/convert/ProductAttrConvert.java new file mode 100644 index 000000000..026caa4d4 --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/convert/ProductAttrConvert.java @@ -0,0 +1,25 @@ +package cn.iocoder.mall.product.application.convert; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.product.api.bo.ProductAttrPageBO; +import cn.iocoder.mall.product.api.bo.ProductAttrSimpleBO; +import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrPageVO; +import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrSimpleVO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface ProductAttrConvert { + + ProductAttrConvert INSTANCE = Mappers.getMapper(ProductAttrConvert.class); + + @Mappings({}) + CommonResult convert2(CommonResult result); + + @Mappings({}) + CommonResult> convert(CommonResult> result); + +} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrAndValuePairVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrAndValuePairVO.java new file mode 100644 index 000000000..7d6aeb2f7 --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrAndValuePairVO.java @@ -0,0 +1,54 @@ +package cn.iocoder.mall.product.application.vo.admins; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "商品规格属性和值对 VO") +public class AdminsProductAttrAndValuePairVO { + + @ApiModelProperty(value = "规格编号", required = true, example = "1") + private Integer attrId; + @ApiModelProperty(value = "规格名", required = true, example = "颜色") + private String attrName; + @ApiModelProperty(value = "规格值", required = true, example = "10") + private Integer attrValueId; + @ApiModelProperty(value = "规格值名", required = true, example = "红色") + private String attrValueName; + + public Integer getAttrId() { + return attrId; + } + + public AdminsProductAttrAndValuePairVO setAttrId(Integer attrId) { + this.attrId = attrId; + return this; + } + + public String getAttrName() { + return attrName; + } + + public AdminsProductAttrAndValuePairVO setAttrName(String attrName) { + this.attrName = attrName; + return this; + } + + public Integer getAttrValueId() { + return attrValueId; + } + + public AdminsProductAttrAndValuePairVO setAttrValueId(Integer attrValueId) { + this.attrValueId = attrValueId; + return this; + } + + public String getAttrValueName() { + return attrValueName; + } + + public AdminsProductAttrAndValuePairVO setAttrValueName(String attrValueName) { + this.attrValueName = attrValueName; + return this; + } + +} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrDetailVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrDetailVO.java index 5d4a0b9be..8b5660062 100644 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrDetailVO.java +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrDetailVO.java @@ -3,51 +3,65 @@ package cn.iocoder.mall.product.application.vo.admins; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -@ApiModel(value = "商品规格 VO") +import java.util.Date; +import java.util.List; + +@ApiModel(value = "商品规格明细 VO", description = "带有规格值数组") public class AdminsProductAttrDetailVO { @ApiModelProperty(value = "规格编号", required = true, example = "1") - private Integer attrId; + private Integer id; @ApiModelProperty(value = "规格名", required = true, example = "颜色") - private String attrName; - @ApiModelProperty(value = "规格值", required = true, example = "10") - private Integer attrValueId; - @ApiModelProperty(value = "规格值名", required = true, example = "红色") - private String attrValueName; + private String name; + @ApiModelProperty(value = "状态", required = true, example = "1") + private Integer status; + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳") + private Date createTime; + @ApiModelProperty(value = "规格值数组", required = true) + private List values; - public Integer getAttrId() { - return attrId; + public Integer getId() { + return id; } - public AdminsProductAttrDetailVO setAttrId(Integer attrId) { - this.attrId = attrId; + public AdminsProductAttrDetailVO setId(Integer id) { + this.id = id; return this; } - public String getAttrName() { - return attrName; + public String getName() { + return name; } - public AdminsProductAttrDetailVO setAttrName(String attrName) { - this.attrName = attrName; + public AdminsProductAttrDetailVO setName(String name) { + this.name = name; return this; } - public Integer getAttrValueId() { - return attrValueId; + public Integer getStatus() { + return status; } - public AdminsProductAttrDetailVO setAttrValueId(Integer attrValueId) { - this.attrValueId = attrValueId; + public AdminsProductAttrDetailVO setStatus(Integer status) { + this.status = status; return this; } - public String getAttrValueName() { - return attrValueName; + public Date getCreateTime() { + return createTime; } - public AdminsProductAttrDetailVO setAttrValueName(String attrValueName) { - this.attrValueName = attrValueName; + public AdminsProductAttrDetailVO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } + + public List getValues() { + return values; + } + + public AdminsProductAttrDetailVO setValues(List values) { + this.values = values; return this; } diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrPageVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrPageVO.java new file mode 100644 index 000000000..44a5c67e8 --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrPageVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.product.application.vo.admins; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +@ApiModel(value = "商品规格明细分页 VO") +public class AdminsProductAttrPageVO { + + @ApiModelProperty(value = "规格数组", required = true) + private List attrs; + @ApiModelProperty(value = "总数", required = true) + private Integer count; + + public List getAttrs() { + return attrs; + } + + public AdminsProductAttrPageVO setAttrs(List attrs) { + this.attrs = attrs; + return this; + } + + public Integer getCount() { + return count; + } + + public AdminsProductAttrPageVO setCount(Integer count) { + this.count = count; + return this; + } + +} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrSimpleVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrSimpleVO.java new file mode 100644 index 000000000..c446654a5 --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrSimpleVO.java @@ -0,0 +1,45 @@ +package cn.iocoder.mall.product.application.vo.admins; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +@ApiModel(value = "商品规格精简 VO", description = "带有规格值数组") +public class AdminsProductAttrSimpleVO { + + @ApiModelProperty(value = "规格编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "规格名", required = true, example = "颜色") + private String name; + @ApiModelProperty(value = "规格值数组", required = true) + private List values; + + public Integer getId() { + return id; + } + + public AdminsProductAttrSimpleVO setId(Integer id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public AdminsProductAttrSimpleVO setName(String name) { + this.name = name; + return this; + } + + public List getValues() { + return values; + } + + public AdminsProductAttrSimpleVO setValues(List values) { + this.values = values; + return this; + } + +} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrVO.java new file mode 100644 index 000000000..5cbedeb18 --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.mall.product.application.vo.admins; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.Date; + +@ApiModel(value = "商品规格 VO", description = "不带有规格值数组") +public class AdminsProductAttrVO { + + @ApiModelProperty(value = "规格编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "规格名", required = true, example = "颜色") + private String name; + @ApiModelProperty(value = "状态", required = true, example = "1") + private Integer status; + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳") + private Date createTime; + +} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrValueDetailVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrValueDetailVO.java new file mode 100644 index 000000000..3276afe4a --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrValueDetailVO.java @@ -0,0 +1,56 @@ +package cn.iocoder.mall.product.application.vo.admins; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.Date; + +@ApiModel(value = "商品规格值 VO") +public class AdminsProductAttrValueDetailVO { + + @ApiModelProperty(value = "规格值编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "规格值名", required = true, example = "颜色") + private String name; + @ApiModelProperty(value = "状态", required = true, example = "1") + private Integer status; + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳") + private Date createTime; + + public Integer getId() { + return id; + } + + public AdminsProductAttrValueDetailVO setId(Integer id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public AdminsProductAttrValueDetailVO setName(String name) { + this.name = name; + return this; + } + + public Integer getStatus() { + return status; + } + + public AdminsProductAttrValueDetailVO setStatus(Integer status) { + this.status = status; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public AdminsProductAttrValueDetailVO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } + +} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrValueSimpleVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrValueSimpleVO.java new file mode 100644 index 000000000..c814343c8 --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrValueSimpleVO.java @@ -0,0 +1,32 @@ +package cn.iocoder.mall.product.application.vo.admins; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "商品规格值精简 VO") +public class AdminsProductAttrValueSimpleVO { + + @ApiModelProperty(value = "规格值编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "规格值名", required = true, example = "颜色") + private String name; + + public Integer getId() { + return id; + } + + public AdminsProductAttrValueSimpleVO setId(Integer id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public AdminsProductAttrValueSimpleVO setName(String name) { + this.name = name; + return this; + } + +} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductSkuDetailVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductSkuDetailVO.java index 46348fecb..1c0b270e7 100644 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductSkuDetailVO.java +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductSkuDetailVO.java @@ -16,7 +16,7 @@ public class AdminsProductSkuDetailVO { @ApiModelProperty(value = "图片地址", required = true, example = "http://www.iocoder.cn") private String picURL; @ApiModelProperty(value = "规格值数组", required = true) - private List attrs; + private List attrs; @ApiModelProperty(value = "价格,单位:分", required = true, example = "100") private Integer price; @ApiModelProperty(value = "库存数量", required = true, example = "100") @@ -68,11 +68,11 @@ public class AdminsProductSkuDetailVO { return this; } - public List getAttrs() { + public List getAttrs() { return attrs; } - public AdminsProductSkuDetailVO setAttrs(List attrs) { + public AdminsProductSkuDetailVO setAttrs(List attrs) { this.attrs = attrs; return this; } diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductSpuPageVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductSpuPageVO.java index 0f9569375..4e381cb77 100644 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductSpuPageVO.java +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductSpuPageVO.java @@ -1,19 +1,16 @@ package cn.iocoder.mall.product.application.vo.admins; import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import java.util.List; @ApiModel("商品 SPU 分页 VO") public class AdminsProductSpuPageVO { - /** - * spu 数组 - */ + @ApiModelProperty(value = "spu 数组", required = true) private List spus; - /** - * 总数 - */ + @ApiModelProperty(value = "总数", required = true) private Integer count; public List getSpus() { diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductAttrService.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductAttrService.java new file mode 100644 index 000000000..07d69d49c --- /dev/null +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductAttrService.java @@ -0,0 +1,23 @@ +package cn.iocoder.mall.product.api; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.product.api.bo.ProductAttrPageBO; +import cn.iocoder.mall.product.api.bo.ProductAttrSimpleBO; +import cn.iocoder.mall.product.api.dto.ProductAttrPageDTO; + +import java.util.List; + +public interface ProductAttrService { + + CommonResult getProductAttrPage(ProductAttrPageDTO productAttrPageDTO); + + /** + * 获得规格属性数组 + * + * 注意,该方法过滤了禁用的规格 + * + * @return 规格属性数组 + */ + CommonResult> getProductAttrList(); + +} \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrAndValuePairBO.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrAndValuePairBO.java new file mode 100644 index 000000000..527d3865f --- /dev/null +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrAndValuePairBO.java @@ -0,0 +1,61 @@ +package cn.iocoder.mall.product.api.bo; + +/** + * 商品规格明细 BO + */ +public class ProductAttrAndValuePairBO { + + /** + * 规格编号 + */ + private Integer attrId; + /** + * 规格名 + */ + private String attrName; + /** + * 规格值 + */ + private Integer attrValueId; + /** + * 规格值名 + */ + private String attrValueName; + + public Integer getAttrId() { + return attrId; + } + + public ProductAttrAndValuePairBO setAttrId(Integer attrId) { + this.attrId = attrId; + return this; + } + + public String getAttrName() { + return attrName; + } + + public ProductAttrAndValuePairBO setAttrName(String attrName) { + this.attrName = attrName; + return this; + } + + public Integer getAttrValueId() { + return attrValueId; + } + + public ProductAttrAndValuePairBO setAttrValueId(Integer attrValueId) { + this.attrValueId = attrValueId; + return this; + } + + public String getAttrValueName() { + return attrValueName; + } + + public ProductAttrAndValuePairBO setAttrValueName(String attrValueName) { + this.attrValueName = attrValueName; + return this; + } + +} \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrDetailBO.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrDetailBO.java index 0ba4506de..dcb6c78df 100644 --- a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrDetailBO.java +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrDetailBO.java @@ -1,61 +1,76 @@ package cn.iocoder.mall.product.api.bo; +import java.util.Date; +import java.util.List; + /** - * 商品规格明细 BO + * 商品规格明细 VO */ public class ProductAttrDetailBO { /** * 规格编号 */ - private Integer attrId; + private Integer id; /** * 规格名 */ - private String attrName; + private String name; /** - * 规格值 + * 状态 */ - private Integer attrValueId; + private Integer status; /** - * 规格值名 + * 创建时间 */ - private String attrValueName; + private Date createTime; + /** + * 规格值数组 + */ + private List values; - public Integer getAttrId() { - return attrId; + public Integer getId() { + return id; } - public ProductAttrDetailBO setAttrId(Integer attrId) { - this.attrId = attrId; + public ProductAttrDetailBO setId(Integer id) { + this.id = id; return this; } - public String getAttrName() { - return attrName; + public String getName() { + return name; } - public ProductAttrDetailBO setAttrName(String attrName) { - this.attrName = attrName; + public ProductAttrDetailBO setName(String name) { + this.name = name; return this; } - public Integer getAttrValueId() { - return attrValueId; + public Integer getStatus() { + return status; } - public ProductAttrDetailBO setAttrValueId(Integer attrValueId) { - this.attrValueId = attrValueId; + public ProductAttrDetailBO setStatus(Integer status) { + this.status = status; return this; } - public String getAttrValueName() { - return attrValueName; + public Date getCreateTime() { + return createTime; } - public ProductAttrDetailBO setAttrValueName(String attrValueName) { - this.attrValueName = attrValueName; + public ProductAttrDetailBO setCreateTime(Date createTime) { + this.createTime = createTime; return this; } + public List getValues() { + return values; + } + + public ProductAttrDetailBO setValues(List values) { + this.values = values; + return this; + } } \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrPageBO.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrPageBO.java new file mode 100644 index 000000000..14923f57f --- /dev/null +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrPageBO.java @@ -0,0 +1,37 @@ +package cn.iocoder.mall.product.api.bo; + +import java.util.List; + +/** + * 商品规格明细分页 BO + */ +public class ProductAttrPageBO { + + /** + * 规格数组 + */ + private List attrs; + /** + * 总数 + */ + private Integer count; + + public List getAttrs() { + return attrs; + } + + public ProductAttrPageBO setAttrs(List attrs) { + this.attrs = attrs; + return this; + } + + public Integer getCount() { + return count; + } + + public ProductAttrPageBO setCount(Integer count) { + this.count = count; + return this; + } + +} \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrSimpleBO.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrSimpleBO.java new file mode 100644 index 000000000..1a0ecb399 --- /dev/null +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrSimpleBO.java @@ -0,0 +1,50 @@ +package cn.iocoder.mall.product.api.bo; + +import java.util.List; + +/** + * 商品规格精简 VO + */ +public class ProductAttrSimpleBO { + + /** + * 规格编号 + */ + private Integer id; + /** + * 规格名 + */ + private String name; + /** + * 规格值数组 + */ + private List values; + + public Integer getId() { + return id; + } + + public ProductAttrSimpleBO setId(Integer id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public ProductAttrSimpleBO setName(String name) { + this.name = name; + return this; + } + + public List getValues() { + return values; + } + + public ProductAttrSimpleBO setValues(List values) { + this.values = values; + return this; + } + +} \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrValueDetailBO.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrValueDetailBO.java new file mode 100644 index 000000000..5e3954fed --- /dev/null +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrValueDetailBO.java @@ -0,0 +1,62 @@ +package cn.iocoder.mall.product.api.bo; + +import java.util.Date; + +/** + * 商品规格值 VO + */ +public class ProductAttrValueDetailBO { + + /** + * 规格值编号 + */ + private Integer id; + /** + * 规格值名 + */ + private String name; + /** + * 状态 + */ + private Integer status; + /** + * 创建时间 + */ + private Date createTime; + + public Integer getId() { + return id; + } + + public ProductAttrValueDetailBO setId(Integer id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public ProductAttrValueDetailBO setName(String name) { + this.name = name; + return this; + } + + public Integer getStatus() { + return status; + } + + public ProductAttrValueDetailBO setStatus(Integer status) { + this.status = status; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public ProductAttrValueDetailBO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } +} \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrValueSimpleBO.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrValueSimpleBO.java new file mode 100644 index 000000000..ea23bc301 --- /dev/null +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrValueSimpleBO.java @@ -0,0 +1,35 @@ +package cn.iocoder.mall.product.api.bo; + +/** + * 商品规格值 VO + */ +public class ProductAttrValueSimpleBO { + + /** + * 规格值编号 + */ + private Integer id; + /** + * 规格值名 + */ + private String name; + + public Integer getId() { + return id; + } + + public ProductAttrValueSimpleBO setId(Integer id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public ProductAttrValueSimpleBO setName(String name) { + this.name = name; + return this; + } + +} \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductSkuDetailBO.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductSkuDetailBO.java index 67fe8eaa0..6435cc69c 100644 --- a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductSkuDetailBO.java +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductSkuDetailBO.java @@ -22,7 +22,7 @@ public class ProductSkuDetailBO { /** * 规格值数组 */ - private List attrs; + private List attrs; /** * 价格,单位:分 */ @@ -60,11 +60,11 @@ public class ProductSkuDetailBO { return this; } - public List getAttrs() { + public List getAttrs() { return attrs; } - public ProductSkuDetailBO setAttrs(List attrs) { + public ProductSkuDetailBO setAttrs(List attrs) { this.attrs = attrs; return this; } diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/dto/ProductAttrPageDTO.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/dto/ProductAttrPageDTO.java new file mode 100644 index 000000000..20319219d --- /dev/null +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/dto/ProductAttrPageDTO.java @@ -0,0 +1,44 @@ +package cn.iocoder.mall.product.api.dto; + +import javax.validation.constraints.NotNull; + +/** + * 商品规格分页 DTO + */ +public class ProductAttrPageDTO { + + private String name; + + @NotNull(message = "页码不能为空") + private Integer pageNo; + @NotNull(message = "每页条数不能为空") + private Integer pageSize; + + public String getName() { + return name; + } + + public ProductAttrPageDTO setName(String name) { + this.name = name; + return this; + } + + public Integer getPageNo() { + return pageNo; + } + + public ProductAttrPageDTO setPageNo(Integer pageNo) { + this.pageNo = pageNo; + return this; + } + + public Integer getPageSize() { + return pageSize; + } + + public ProductAttrPageDTO setPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + +} \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/dto/ProductSpuPageDTO.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/dto/ProductSpuPageDTO.java index b325904ee..51f4127f9 100644 --- a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/dto/ProductSpuPageDTO.java +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/dto/ProductSpuPageDTO.java @@ -2,6 +2,9 @@ package cn.iocoder.mall.product.api.dto; import javax.validation.constraints.NotNull; +/** + * 商品 Spu 分页 DTO + */ public class ProductSpuPageDTO { private String name; diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductAttrConvert.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductAttrConvert.java new file mode 100644 index 000000000..717f398e7 --- /dev/null +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductAttrConvert.java @@ -0,0 +1,38 @@ +package cn.iocoder.mall.product.convert; + +import cn.iocoder.mall.product.api.bo.ProductAttrDetailBO; +import cn.iocoder.mall.product.api.bo.ProductAttrSimpleBO; +import cn.iocoder.mall.product.api.bo.ProductAttrValueDetailBO; +import cn.iocoder.mall.product.api.bo.ProductAttrValueSimpleBO; +import cn.iocoder.mall.product.dataobject.ProductAttrDO; +import cn.iocoder.mall.product.dataobject.ProductAttrValueDO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface ProductAttrConvert { + + ProductAttrConvert INSTANCE = Mappers.getMapper(ProductAttrConvert.class); + + @Mappings({}) + List convert(List attrs); + + @Mappings({}) + ProductAttrValueDetailBO convert(ProductAttrValueDO value); + + @Mappings({}) + List convert2(List values); + + @Mappings({}) + List convert3(List attrs); + +// @Mappings({}) +// ProductAttrValueSimpleBO convert3(ProductAttrValueDO value); +// + @Mappings({}) + List convert4(List values); + +} \ No newline at end of file diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductSpuConvert.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductSpuConvert.java index 4935dafe4..5421dd036 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductSpuConvert.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductSpuConvert.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.product.convert; import cn.iocoder.common.framework.util.StringUtil; -import cn.iocoder.mall.product.api.bo.ProductAttrDetailBO; +import cn.iocoder.mall.product.api.bo.ProductAttrAndValuePairBO; import cn.iocoder.mall.product.api.bo.ProductSkuDetailBO; import cn.iocoder.mall.product.api.bo.ProductSpuBO; import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO; @@ -63,13 +63,13 @@ public interface ProductSpuConvert { }) ProductSkuDetailBO convert2(ProductSkuDO sku); - @Mappings({}) - default ProductSpuDetailBO convert2(ProductSpuDO spu, List skus, List productAttrDetailBOs) { + @Mappings({}) // TODO 芋艿,后续细看下 mapstruct 的 API ,优化这块 + default ProductSpuDetailBO convert2(ProductSpuDO spu, List skus, List productAttrDetailBOs) { // 创建并转换 ProductSpuDetailBO 对象 ProductSpuDetailBO spuDetail = this.convert2(spu).setPicUrls(StringUtil.split(spu.getPicUrls(), ",")); // 创建 ProductAttrDetailBO 的映射。其中,KEY 为 ProductAttrDetailBO.attrValueId ,即规格值的编号 - Map productAttrDetailBOMap = productAttrDetailBOs.stream().collect( - Collectors.toMap(ProductAttrDetailBO::getAttrValueId, productAttrDetailBO -> productAttrDetailBO)); + Map productAttrDetailBOMap = productAttrDetailBOs.stream().collect( + Collectors.toMap(ProductAttrAndValuePairBO::getAttrValueId, productAttrDetailBO -> productAttrDetailBO)); // 创建并转换 ProductSpuDetailBO 数组 spuDetail.setSkus(new ArrayList<>()); skus.forEach(sku -> { diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductAttrMapper.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductAttrMapper.java index a89830fca..376d74af7 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductAttrMapper.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductAttrMapper.java @@ -14,4 +14,12 @@ public interface ProductAttrMapper { List selectListByIds(@Param("ids") Collection ids); + List selectListByStatus(@Param("status") Integer status); + + List selectListByNameLike(@Param("name") String name, + @Param("offset") Integer offset, + @Param("limit") Integer limit); + + Integer selectCountByNameLike(@Param("name") String name); + } \ No newline at end of file diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductAttrValueMapper.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductAttrValueMapper.java index f73a37fa3..dbeafcae9 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductAttrValueMapper.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductAttrValueMapper.java @@ -14,4 +14,8 @@ public interface ProductAttrValueMapper { List selectListByIds(@Param("ids") Collection ids); + List selectListByStatus(@Param("status") Integer status); + + List selectListByAttrIds(@Param("attrIds") Collection attrIds); + } \ No newline at end of file diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductAttrServiceImpl.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductAttrServiceImpl.java index b823845b8..c478c93d2 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductAttrServiceImpl.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductAttrServiceImpl.java @@ -2,16 +2,25 @@ package cn.iocoder.mall.product.service; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.product.api.ProductAttrService; +import cn.iocoder.mall.product.api.bo.ProductAttrAndValuePairBO; import cn.iocoder.mall.product.api.bo.ProductAttrDetailBO; +import cn.iocoder.mall.product.api.bo.ProductAttrPageBO; +import cn.iocoder.mall.product.api.bo.ProductAttrSimpleBO; import cn.iocoder.mall.product.api.constant.ProductAttrConstants; import cn.iocoder.mall.product.api.constant.ProductErrorCodeEnum; +import cn.iocoder.mall.product.api.dto.ProductAttrPageDTO; +import cn.iocoder.mall.product.convert.ProductAttrConvert; import cn.iocoder.mall.product.dao.ProductAttrMapper; import cn.iocoder.mall.product.dao.ProductAttrValueMapper; import cn.iocoder.mall.product.dataobject.ProductAttrDO; import cn.iocoder.mall.product.dataobject.ProductAttrValueDO; +import com.google.common.collect.ImmutableListMultimap; +import com.google.common.collect.Multimaps; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; @@ -24,22 +33,25 @@ import java.util.stream.Collectors; * @see cn.iocoder.mall.product.dataobject.ProductAttrValueDO */ @Service -public class ProductAttrServiceImpl { +@com.alibaba.dubbo.config.annotation.Service(validation = "true") +public class ProductAttrServiceImpl implements ProductAttrService { @Autowired private ProductAttrMapper productAttrMapper; @Autowired - private ProductAttrValueMapper productValueMapper; + private ProductAttrValueMapper productAttrValueMapper; - public CommonResult> validProductAttrAndValue(Set productAttrValueIds) { + public CommonResult> validProductAttrAndValue(Set productAttrValueIds, boolean validStatus) { // 首先,校验规格值 - List attrValues = productValueMapper.selectListByIds(productAttrValueIds); + List attrValues = productAttrValueMapper.selectListByIds(productAttrValueIds); if (attrValues.size() != productAttrValueIds.size()) { return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_NOT_EXIST.getCode()); } - for (ProductAttrValueDO attrValue : attrValues) { // 同时,校验下状态 - if (ProductAttrConstants.ATTR_STATUS_DISABLE.equals(attrValue.getStatus())) { - return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_NOT_EXIST.getCode()); + if (validStatus) { + for (ProductAttrValueDO attrValue : attrValues) { // 同时,校验下状态 + if (ProductAttrConstants.ATTR_STATUS_DISABLE.equals(attrValue.getStatus())) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_NOT_EXIST.getCode()); + } } } // 然后,校验规格 @@ -48,17 +60,58 @@ public class ProductAttrServiceImpl { if (attrs.size() != attrIds.size()) { return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_ATTR_NOT_EXIST.getCode()); } - for (ProductAttrDO attr : attrs) { // 同时,校验下状态 - if (ProductAttrConstants.ATTR_VALUE_STATUS_DISABLE.equals(attr.getStatus())) { - return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_ATTR_NOT_EXIST.getCode()); + if (validStatus) { + for (ProductAttrDO attr : attrs) { // 同时,校验下状态 + if (ProductAttrConstants.ATTR_VALUE_STATUS_DISABLE.equals(attr.getStatus())) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_ATTR_NOT_EXIST.getCode()); + } } } // 返回成功 Map attrMap = attrs.stream().collect(Collectors.toMap(ProductAttrDO::getId, productAttrDO -> productAttrDO)); // ProductAttrDO 的映射,方便查找。 - List result = attrValues.stream().map(productAttrValueDO -> new ProductAttrDetailBO() + List result = attrValues.stream().map(productAttrValueDO -> new ProductAttrAndValuePairBO() .setAttrId(productAttrValueDO.getAttrId()).setAttrName(attrMap.get(productAttrValueDO.getAttrId()).getName()) .setAttrValueId(productAttrValueDO.getId()).setAttrValueName(productAttrValueDO.getName())).collect(Collectors.toList()); return CommonResult.success(result); } + @Override + public CommonResult getProductAttrPage(ProductAttrPageDTO productAttrPageDTO) { + ProductAttrPageBO productAttrPageBO = new ProductAttrPageBO(); + // 查询分页数据 + int offset = productAttrPageDTO.getPageNo() * productAttrPageDTO.getPageSize(); + productAttrPageBO.setAttrs(ProductAttrConvert.INSTANCE.convert(productAttrMapper.selectListByNameLike(productAttrPageDTO.getName(), + offset, productAttrPageDTO.getPageSize()))); + // 查询分页总数 + productAttrPageBO.setCount(productAttrMapper.selectCountByNameLike(productAttrPageDTO.getName())); + // 将规格值拼接上去 + if (!productAttrPageBO.getAttrs().isEmpty()) { + Set attrIds = productAttrPageBO.getAttrs().stream().map(ProductAttrDetailBO::getId).collect(Collectors.toSet()); + List attrValues = productAttrValueMapper.selectListByAttrIds(attrIds); + ImmutableListMultimap attrValueMap = Multimaps.index(attrValues, ProductAttrValueDO::getAttrId); // KEY 是 attrId ,VALUE 是 ProductAttrValueDO 数组 + for (ProductAttrDetailBO productAttrDetailBO : productAttrPageBO.getAttrs()) { + productAttrDetailBO.setValues(ProductAttrConvert.INSTANCE.convert2(((attrValueMap).get(productAttrDetailBO.getId())))); + } + } + // 返回结果 + return CommonResult.success(productAttrPageBO); + } + + @Override + public CommonResult> getProductAttrList() { + // 查询所有开启的规格数组 + List attrs = ProductAttrConvert.INSTANCE.convert3(productAttrMapper.selectListByStatus(ProductAttrConstants.ATTR_STATUS_ENABLE)); + // 如果为空,则返回空 + if (attrs.isEmpty()) { + return CommonResult.success(Collections.emptyList()); + } + // 将规格值拼接上去 + List attrValues = productAttrValueMapper.selectListByStatus(ProductAttrConstants.ATTR_VALUE_STATUS_ENABLE); + ImmutableListMultimap attrValueMap = Multimaps.index(attrValues, ProductAttrValueDO::getAttrId); // KEY 是 attrId ,VALUE 是 ProductAttrValueDO 数组 + for (ProductAttrSimpleBO productAttrSimpleBO : attrs) { + productAttrSimpleBO.setValues(ProductAttrConvert.INSTANCE.convert4(((attrValueMap).get(productAttrSimpleBO.getId())))); + } + return CommonResult.success(attrs); + } + } \ No newline at end of file diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductSpuServiceImpl.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductSpuServiceImpl.java index 145d32041..ae3d7daba 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductSpuServiceImpl.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductSpuServiceImpl.java @@ -6,7 +6,7 @@ import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.util.StringUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.product.api.ProductSpuService; -import cn.iocoder.mall.product.api.bo.ProductAttrDetailBO; +import cn.iocoder.mall.product.api.bo.ProductAttrAndValuePairBO; import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO; import cn.iocoder.mall.product.api.bo.ProductSpuPageBO; import cn.iocoder.mall.product.api.constant.ProductErrorCodeEnum; @@ -61,7 +61,8 @@ public class ProductSpuServiceImpl implements ProductSpuService { // 获得规格 Set productAttrValueIds = new HashSet<>(); skus.forEach(sku -> productAttrValueIds.addAll(StringUtil.splitToInt(sku.getAttrs(), ","))); - CommonResult> validAttrResult = productAttrService.validProductAttrAndValue(productAttrValueIds); + CommonResult> validAttrResult = productAttrService.validProductAttrAndValue(productAttrValueIds, + false); // 读取规格时,不考虑规格是否被禁用 if (validAttrResult.isError()) { return CommonResult.error(validAttrResult); } @@ -81,7 +82,8 @@ public class ProductSpuServiceImpl implements ProductSpuService { // 校验规格是否存在 Set productAttrValueIds = new HashSet<>(); productSpuAddDTO.getSkus().forEach(productSkuAddDTO -> productAttrValueIds.addAll(productSkuAddDTO.getAttrs())); - CommonResult> validAttrResult = productAttrService.validProductAttrAndValue(productAttrValueIds); + CommonResult> validAttrResult = productAttrService.validProductAttrAndValue(productAttrValueIds + , true); // 读取规格时,需要考虑规格是否被禁用 if (validAttrResult.isError()) { return CommonResult.error(validAttrResult); } @@ -126,7 +128,8 @@ public class ProductSpuServiceImpl implements ProductSpuService { // 校验规格是否存在 Set productAttrValueIds = new HashSet<>(); productSpuUpdateDTO.getSkus().forEach(productSkuAddDTO -> productAttrValueIds.addAll(productSkuAddDTO.getAttrs())); - CommonResult> validAttrResult = productAttrService.validProductAttrAndValue(productAttrValueIds); + CommonResult> validAttrResult = productAttrService.validProductAttrAndValue(productAttrValueIds, + true); // 读取规格时,需要考虑规格是否被禁用 if (validAttrResult.isError()) { return CommonResult.error(validAttrResult); } @@ -203,10 +206,10 @@ public class ProductSpuServiceImpl implements ProductSpuService { return CommonResult.success(productSpuPage); } - private CommonResult validProductSku(List productSkuAddDTOs, List productAttrDetailBOs) { + private CommonResult validProductSku(List productSkuAddDTOs, List productAttrDetailBOs) { // 创建 ProductAttrDetailBO 的映射。其中,KEY 为 ProductAttrDetailBO.attrValueId ,即规格值的编号 - Map productAttrDetailBOMap = productAttrDetailBOs.stream().collect( - Collectors.toMap(ProductAttrDetailBO::getAttrValueId, productAttrDetailBO -> productAttrDetailBO)); + Map productAttrDetailBOMap = productAttrDetailBOs.stream().collect( + Collectors.toMap(ProductAttrAndValuePairBO::getAttrValueId, productAttrDetailBO -> productAttrDetailBO)); // 1. 先校验,一个 Sku 下,没有重复的规格。校验方式是,遍历每个 Sku ,看看是否有重复的规格 attrId for (ProductSkuAddOrUpdateDTO sku : productSkuAddDTOs) { Set attrIds = sku.getAttrs().stream().map(attrValueId -> productAttrDetailBOMap.get(attrValueId).getAttrId()).collect(Collectors.toSet()); diff --git a/product/product-service-impl/src/main/resources/mapper/ProductAttrMapper.xml b/product/product-service-impl/src/main/resources/mapper/ProductAttrMapper.xml index 0116915c0..b6c377b01 100644 --- a/product/product-service-impl/src/main/resources/mapper/ProductAttrMapper.xml +++ b/product/product-service-impl/src/main/resources/mapper/ProductAttrMapper.xml @@ -70,4 +70,41 @@ AND deleted = 0 + + + + + + \ No newline at end of file diff --git a/product/product-service-impl/src/main/resources/mapper/ProductAttrValueMapper.xml b/product/product-service-impl/src/main/resources/mapper/ProductAttrValueMapper.xml index 4063869cc..32891661c 100644 --- a/product/product-service-impl/src/main/resources/mapper/ProductAttrValueMapper.xml +++ b/product/product-service-impl/src/main/resources/mapper/ProductAttrValueMapper.xml @@ -70,4 +70,27 @@ AND deleted = 0 + + + + \ No newline at end of file