From 03f6b2b82c11a6456a7502da7483f26448e1a004 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Thu, 7 Mar 2019 19:36:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20user=20=E7=AB=AF=E7=9A=84?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=86=E7=B1=BB=E6=8E=A5=E5=8F=A3=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20user=20=E7=AB=AF=E7=9A=84=E5=95=86?= =?UTF-8?q?=E5=93=81=20spu=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/AdminsProductAttrController.java | 62 ++++++++++-- .../users/ProductSpuController.java | 32 ------- ...va => UsersProductCategoryController.java} | 2 +- .../users/UsersProductSpuController.java | 54 +++++++++++ .../convert/ProductAttrConvert.java | 5 + .../convert/ProductSpuConvert.java | 8 ++ .../application/vo/ProductSpuListVO.java | 16 ---- .../product/application/vo/ProductSpuVO.java | 4 - .../vo/admins/AdminsProductAttrValueVO.java | 67 +++++++++++++ .../vo/admins/AdminsProductSkuDetailVO.java | 1 - .../users/UsersProductAttrAndValuePairVO.java | 54 +++++++++++ .../vo/users/UsersProductSkuDetailVO.java | 79 +++++++++++++++ .../vo/users/UsersProductSpuDetailVO.java | 95 +++++++++++++++++++ .../vo/users/UsersProductSpuPageVO.java | 34 +++++++ .../vo/users/UsersProductSpuVO.java | 85 +++++++++++++++++ .../product/api/bo/ProductAttrValueBO.java | 13 +++ .../mall/product/api/bo/ProductSpuBO.java | 17 ++++ .../api/constant/ProductErrorCodeEnum.java | 3 +- .../product/api/dto/ProductSpuPageDTO.java | 31 ++++++ .../product/convert/ProductAttrConvert.java | 9 ++ .../product/dao/ProductAttrValueMapper.java | 8 ++ .../mall/product/dao/ProductSpuMapper.java | 7 +- .../mall/product/dataobject/ProductSpuDO.java | 33 +++++++ .../service/ProductAttrServiceImpl.java | 47 ++++++++- .../service/ProductSpuServiceImpl.java | 13 ++- .../mapper/ProductAttrValueMapper.xml | 34 +++++++ .../resources/mapper/ProductSpuMapper.xml | 27 +++++- 27 files changed, 767 insertions(+), 73 deletions(-) delete mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/ProductSpuController.java rename product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/{ProductCategoryController.java => UsersProductCategoryController.java} (96%) create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/UsersProductSpuController.java delete mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductSpuListVO.java delete mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductSpuVO.java create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrValueVO.java create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductAttrAndValuePairVO.java create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSkuDetailVO.java create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuDetailVO.java create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuPageVO.java create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuVO.java 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 index f470bd867..9ffa32a25 100644 --- 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 @@ -6,15 +6,18 @@ import cn.iocoder.mall.product.api.ProductAttrService; import cn.iocoder.mall.product.api.bo.ProductAttrBO; import cn.iocoder.mall.product.api.bo.ProductAttrPageBO; import cn.iocoder.mall.product.api.bo.ProductAttrSimpleBO; -import cn.iocoder.mall.product.api.dto.ProductAttrAddDTO; -import cn.iocoder.mall.product.api.dto.ProductAttrPageDTO; -import cn.iocoder.mall.product.api.dto.ProductAttrUpdateDTO; +import cn.iocoder.mall.product.api.bo.ProductAttrValueBO; +import cn.iocoder.mall.product.api.dto.*; 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 cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrVO; +import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrValueVO; import com.alibaba.dubbo.config.annotation.Reference; 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.List; @@ -28,6 +31,7 @@ public class AdminsProductAttrController { private ProductAttrService productAttrService; @GetMapping("/attr/page") + @ApiOperation("获得规格分页") public CommonResult attrPage(@RequestParam(value = "name", required = false) String name, @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { @@ -40,6 +44,7 @@ public class AdminsProductAttrController { } @GetMapping("/attr/tree") + @ApiOperation(value = "获得规格树结构", notes = "该接口返回的信息更为精简。一般用于前端缓存数据字典到本地。") public CommonResult> tree() { // 查询全列表 CommonResult> result = productAttrService.getProductAttrList(); @@ -48,6 +53,10 @@ public class AdminsProductAttrController { } @PostMapping("/attr/add") + @ApiOperation(value = "创建商品规格") + @ApiImplicitParams({ + @ApiImplicitParam(name = "name", value = "规格名", required = true, example = "颜色") + }) public CommonResult addAttr(@RequestParam("name") String name) { // 创建 ProductAttrAddDTO 对象 ProductAttrAddDTO productAttrAddDTO = new ProductAttrAddDTO().setName(name); @@ -58,6 +67,11 @@ public class AdminsProductAttrController { } @PostMapping("/attr/update") + @ApiOperation(value = "修改商品规格") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "规格编号", required = true, example = "1"), + @ApiImplicitParam(name = "name", value = "规格名", required = true, example = "颜色") + }) public CommonResult updateAttr(@RequestParam("id") Integer id, @RequestParam("name") String name) { // 创建 ProductAttrUpdateDTO 对象 @@ -67,6 +81,11 @@ public class AdminsProductAttrController { } @PostMapping("/attr/update_status") + @ApiOperation(value = "修改商品规格状态") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "规格编号", required = true, example = "100"), + @ApiImplicitParam(name = "status", value = "状态", required = true, example = "1") + }) public CommonResult updateAttrStatus(@RequestParam("id") Integer id, @RequestParam("status") Integer status) { return productAttrService.updateProductAttrStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status); @@ -75,18 +94,43 @@ public class AdminsProductAttrController { // TODO 芋艿 暂时不考虑 delete Attr 。因为关联逻辑比较多 @PostMapping("/attr_value/add") - public CommonResult addAttrValue() { - return null; + @ApiOperation(value = "创建商品规格值") + @ApiImplicitParams({ + @ApiImplicitParam(name = "attrId", value = "规格编号", required = true, example = "100"), + @ApiImplicitParam(name = "name", value = "规格值", required = true, example = "蓝色") + }) + public CommonResult addAttrValue(@RequestParam("attrId") Integer attrId, + @RequestParam("name") String name) { + // 创建 ProductAttrValueAddDTO 对象 + ProductAttrValueAddDTO productAttrValueAddDTO = new ProductAttrValueAddDTO().setAttrId(attrId).setName(name); + // 添加 + CommonResult result = productAttrService.addProductAttrValue(AdminSecurityContextHolder.getContext().getAdminId(), productAttrValueAddDTO); + // 返回结果 + return ProductAttrConvert.INSTANCE.convert4(result); } @PostMapping("/attr_value/update") - public CommonResult updateAttrValue() { - return null; + @ApiOperation(value = "修改商品规格值") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "规格值编号", required = true, example = "100"), + @ApiImplicitParam(name = "name", value = "规格值", required = true, example = "蓝色") + }) + public CommonResult updateAttrValue(@RequestParam("id") Integer id, + @RequestParam("name") String name) { + // 创建 ProductAttrValueUpdateDTO 对象 + ProductAttrValueUpdateDTO productAttrValueUpdateDTO = new ProductAttrValueUpdateDTO().setId(id).setName(name); + // 更新 + return productAttrService.updateProductAttrValue(AdminSecurityContextHolder.getContext().getAdminId(), productAttrValueUpdateDTO); } @PostMapping("/attr_value/update_status") - public CommonResult updateAttrValueStatus() { - return null; + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "规格编号", required = true, example = "100"), + @ApiImplicitParam(name = "status", value = "状态", required = true, example = "1") + }) + public CommonResult updateAttrValueStatus(@RequestParam("id") Integer id, + @RequestParam("status") Integer status) { + return productAttrService.updateProductAttrValueStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status); } // TODO 芋艿 暂时不考虑 delete Attr Value 。因为关联逻辑比较多 diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/ProductSpuController.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/ProductSpuController.java deleted file mode 100644 index 44162ced1..000000000 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/ProductSpuController.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.iocoder.mall.product.application.controller.users; - -import cn.iocoder.mall.product.api.ProductSpuService; -import cn.iocoder.mall.product.api.bo.ProductSpuBO; -import cn.iocoder.mall.product.application.vo.ProductSpuListVO; -import com.alibaba.dubbo.config.annotation.Reference; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("user/product/spu") -public class ProductSpuController { - - @Reference(validation = "true") - private ProductSpuService productSpuService; - - // TODO 详情 - @GetMapping("/info") - public ProductSpuBO info(@RequestParam("id") Integer id) { -// return productSpuService.getProductSpu(id); - return null; - } - - // TODO 分页 - @GetMapping("/list") - public ProductSpuListVO list() { - return null; - } - -} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/ProductCategoryController.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/UsersProductCategoryController.java similarity index 96% rename from product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/ProductCategoryController.java rename to product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/UsersProductCategoryController.java index b925258d6..3d99c007f 100644 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/ProductCategoryController.java +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/UsersProductCategoryController.java @@ -18,7 +18,7 @@ import java.util.List; @RestController("productCategoryController_users") @RequestMapping("users/product/category") @Api("商品分类") -public class ProductCategoryController { +public class UsersProductCategoryController { @Reference(validation = "true") private ProductCategoryService productCategoryService; diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/UsersProductSpuController.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/UsersProductSpuController.java new file mode 100644 index 000000000..d85819d7e --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/UsersProductSpuController.java @@ -0,0 +1,54 @@ +package cn.iocoder.mall.product.application.controller.users; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.product.api.ProductSpuService; +import cn.iocoder.mall.product.api.bo.ProductSpuPageBO; +import cn.iocoder.mall.product.api.dto.ProductSpuPageDTO; +import cn.iocoder.mall.product.application.convert.ProductSpuConvert; +import cn.iocoder.mall.product.application.vo.users.UsersProductSpuDetailVO; +import cn.iocoder.mall.product.application.vo.users.UsersProductSpuPageVO; +import com.alibaba.dubbo.config.annotation.Reference; +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.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("users/spu") +@Api("商品 SPU + SKU") +public class UsersProductSpuController { + + @Reference(validation = "true") + private ProductSpuService productSpuService; + + @GetMapping("/info") + @ApiOperation("商品 SPU 明细") + @ApiImplicitParam(name = "id", value = "SPU 编号", required = true, example = "100") + public CommonResult info(@RequestParam("id") Integer id) { + return ProductSpuConvert.INSTANCE.convert4(productSpuService.getProductSpu(id)); + } + + @GetMapping("/page") + @ApiOperation("商品 SPU 分页列表") + @ApiImplicitParams({ + @ApiImplicitParam(name = "cid", value = "分类编号", example = "1"), + @ApiImplicitParam(name = "pageNo", value = "页码,从 0 开始", example = "0"), + @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), + }) + public CommonResult page(@RequestParam(value = "cid", required = false) Integer cid, + @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { + // 创建 ProductSpuPageDTO 对象 + ProductSpuPageDTO productSpuPageDTO = new ProductSpuPageDTO().setCid(cid).setVisible(true) + .setPageNo(pageNo).setPageSize(pageSize); + // 查询分页 + CommonResult result = productSpuService.getProductSpuPage(productSpuPageDTO); + // 返回结果 + return ProductSpuConvert.INSTANCE.convert3(result); + } + +} \ 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 index 0fc0fcb9f..00201f43a 100644 --- 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 @@ -4,9 +4,11 @@ import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.product.api.bo.ProductAttrBO; import cn.iocoder.mall.product.api.bo.ProductAttrPageBO; import cn.iocoder.mall.product.api.bo.ProductAttrSimpleBO; +import cn.iocoder.mall.product.api.bo.ProductAttrValueBO; import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrPageVO; import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrSimpleVO; import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrVO; +import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrValueVO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -30,4 +32,7 @@ public interface ProductAttrConvert { @Mappings({}) CommonResult convert3(CommonResult productAttrBO); + @Mappings({}) + CommonResult convert4(CommonResult productAttrValueBO); + } \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/convert/ProductSpuConvert.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/convert/ProductSpuConvert.java index 590e6ae66..c566f073d 100644 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/convert/ProductSpuConvert.java +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/convert/ProductSpuConvert.java @@ -5,6 +5,8 @@ import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO; import cn.iocoder.mall.product.api.bo.ProductSpuPageBO; import cn.iocoder.mall.product.application.vo.admins.AdminsProductSpuDetailVO; import cn.iocoder.mall.product.application.vo.admins.AdminsProductSpuPageVO; +import cn.iocoder.mall.product.application.vo.users.UsersProductSpuDetailVO; +import cn.iocoder.mall.product.application.vo.users.UsersProductSpuPageVO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -23,4 +25,10 @@ public interface ProductSpuConvert { @Mappings({}) CommonResult convert2(CommonResult result); + @Mappings({}) + CommonResult convert3(CommonResult result); + + @Mappings({}) + CommonResult convert4(CommonResult result); + } \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductSpuListVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductSpuListVO.java deleted file mode 100644 index 944fd53b3..000000000 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductSpuListVO.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.iocoder.mall.product.application.vo; - -import java.util.List; - -public class ProductSpuListVO { - - /** - * SPU 数组 - */ - private List list; - /** - * 是否还有下一页 - */ - private Boolean hasNext; - -} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductSpuVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductSpuVO.java deleted file mode 100644 index 8f141d860..000000000 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/ProductSpuVO.java +++ /dev/null @@ -1,4 +0,0 @@ -package cn.iocoder.mall.product.application.vo; - -public class ProductSpuVO { -} diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrValueVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrValueVO.java new file mode 100644 index 000000000..187ce2f7a --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/admins/AdminsProductAttrValueVO.java @@ -0,0 +1,67 @@ +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 AdminsProductAttrValueVO { + + @ApiModelProperty(value = "规格值编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "规格编号", required = true, example = "1") + private Integer attrId; + @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 AdminsProductAttrValueVO setId(Integer id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public AdminsProductAttrValueVO setName(String name) { + this.name = name; + return this; + } + + public Integer getStatus() { + return status; + } + + public AdminsProductAttrValueVO setStatus(Integer status) { + this.status = status; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public AdminsProductAttrValueVO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } + + public Integer getAttrId() { + return attrId; + } + + public AdminsProductAttrValueVO setAttrId(Integer attrId) { + this.attrId = attrId; + 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 1c0b270e7..bf35708cc 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 @@ -22,7 +22,6 @@ public class AdminsProductSkuDetailVO { @ApiModelProperty(value = "库存数量", required = true, example = "100") private Integer quantity; - public Integer getId() { return id; } diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductAttrAndValuePairVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductAttrAndValuePairVO.java new file mode 100644 index 000000000..55a59ffdc --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductAttrAndValuePairVO.java @@ -0,0 +1,54 @@ +package cn.iocoder.mall.product.application.vo.users; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "商品规格属性和值对 VO") +public class UsersProductAttrAndValuePairVO { + + @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 UsersProductAttrAndValuePairVO setAttrId(Integer attrId) { + this.attrId = attrId; + return this; + } + + public String getAttrName() { + return attrName; + } + + public UsersProductAttrAndValuePairVO setAttrName(String attrName) { + this.attrName = attrName; + return this; + } + + public Integer getAttrValueId() { + return attrValueId; + } + + public UsersProductAttrAndValuePairVO setAttrValueId(Integer attrValueId) { + this.attrValueId = attrValueId; + return this; + } + + public String getAttrValueName() { + return attrValueName; + } + + public UsersProductAttrAndValuePairVO 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/users/UsersProductSkuDetailVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSkuDetailVO.java new file mode 100644 index 000000000..b1cfc0081 --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSkuDetailVO.java @@ -0,0 +1,79 @@ +package cn.iocoder.mall.product.application.vo.users; + +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +/** + * 商品 Sku 明细 BO + */ +public class UsersProductSkuDetailVO { + + @ApiModelProperty(value = "sku 编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "SPU 编号", required = true, example = "1") + private Integer spuId; + @ApiModelProperty(value = "图片地址", required = true, example = "http://www.iocoder.cn") + private String picURL; + @ApiModelProperty(value = "规格值数组", required = true) + private List attrs; + @ApiModelProperty(value = "价格,单位:分", required = true, example = "100") + private Integer price; + @ApiModelProperty(value = "库存数量", required = true, example = "100") + private Integer quantity; + + public Integer getId() { + return id; + } + + public UsersProductSkuDetailVO setId(Integer id) { + this.id = id; + return this; + } + + public Integer getSpuId() { + return spuId; + } + + public UsersProductSkuDetailVO setSpuId(Integer spuId) { + this.spuId = spuId; + return this; + } + + public String getPicURL() { + return picURL; + } + + public UsersProductSkuDetailVO setPicURL(String picURL) { + this.picURL = picURL; + return this; + } + + public Integer getPrice() { + return price; + } + + public UsersProductSkuDetailVO setPrice(Integer price) { + this.price = price; + return this; + } + + public Integer getQuantity() { + return quantity; + } + + public UsersProductSkuDetailVO setQuantity(Integer quantity) { + this.quantity = quantity; + return this; + } + + public List getAttrs() { + return attrs; + } + + public UsersProductSkuDetailVO setAttrs(List attrs) { + this.attrs = attrs; + return this; + } + +} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuDetailVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuDetailVO.java new file mode 100644 index 000000000..d58ea0b77 --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuDetailVO.java @@ -0,0 +1,95 @@ +package cn.iocoder.mall.product.application.vo.users; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +@ApiModel(value = "商品 SPU 详细 VO", description = "包括 SKU 信息 VO") +public class UsersProductSpuDetailVO { + + @ApiModelProperty(value = "SPU 编号", required = true, example = "1") + private Integer id; + + // ========== 基本信息 ========= + @ApiModelProperty(value = "SPU 名字", required = true, example = "厮大牛逼") + private String name; + @ApiModelProperty(value = "卖点", required = true, example = "各种 MQ 骚操作") + private String sellPoint; + @ApiModelProperty(value = "描述", required = true, example = "你就说强不强") + private String description; + @ApiModelProperty(value = "分类编号", required = true, example = "反正我是信了") + private Integer cid; + @ApiModelProperty(value = "商品主图地址的数组", required = true, example = "http://www.iocoder.cn") + private List picUrls; + + // ========== SKU ========= + + /** + * SKU 数组 + */ + private List skus; + + public Integer getId() { + return id; + } + + public UsersProductSpuDetailVO setId(Integer id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public UsersProductSpuDetailVO setName(String name) { + this.name = name; + return this; + } + + public String getSellPoint() { + return sellPoint; + } + + public UsersProductSpuDetailVO setSellPoint(String sellPoint) { + this.sellPoint = sellPoint; + return this; + } + + public String getDescription() { + return description; + } + + public UsersProductSpuDetailVO setDescription(String description) { + this.description = description; + return this; + } + + public Integer getCid() { + return cid; + } + + public UsersProductSpuDetailVO setCid(Integer cid) { + this.cid = cid; + return this; + } + + public List getPicUrls() { + return picUrls; + } + + public UsersProductSpuDetailVO setPicUrls(List picUrls) { + this.picUrls = picUrls; + return this; + } + + public List getSkus() { + return skus; + } + + public UsersProductSpuDetailVO setSkus(List skus) { + this.skus = skus; + return this; + } +} \ No newline at end of file diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuPageVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuPageVO.java new file mode 100644 index 000000000..55c801cc1 --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuPageVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.product.application.vo.users; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +@ApiModel("商品 SPU 分页 VO") +public class UsersProductSpuPageVO { + + @ApiModelProperty(value = "spu 数组", required = true) + private List spus; + @ApiModelProperty(value = "总数", required = true) + private Integer count; + + public List getSpus() { + return spus; + } + + public UsersProductSpuPageVO setSpus(List spus) { + this.spus = spus; + return this; + } + + public Integer getCount() { + return count; + } + + public UsersProductSpuPageVO 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/users/UsersProductSpuVO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuVO.java new file mode 100644 index 000000000..70b4ff3c2 --- /dev/null +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/vo/users/UsersProductSpuVO.java @@ -0,0 +1,85 @@ +package cn.iocoder.mall.product.application.vo.users; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +@ApiModel(value = "商品 SPU VO", description = "不包括 SKU 信息 VO") +public class UsersProductSpuVO { + + @ApiModelProperty(value = "SPU 编号", required = true, example = "1") + private Integer id; + + // ========== 基本信息 ========= + @ApiModelProperty(value = "SPU 名字", required = true, example = "厮大牛逼") + private String name; + @ApiModelProperty(value = "卖点", required = true, example = "各种 MQ 骚操作") + private String sellPoint; + @ApiModelProperty(value = "分类编号", required = true, example = "反正我是信了") + private Integer cid; + @ApiModelProperty(value = "商品主图地址的数组", required = true, example = "http://www.iocoder.cn") + private List picUrls; + + // ========== Sku 相关字段 ========= + /** + * 价格 + * + * 目前的计算方式是,以 Sku 最小价格为准 + */ + private Integer price; + + public Integer getId() { + return id; + } + + public UsersProductSpuVO setId(Integer id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public UsersProductSpuVO setName(String name) { + this.name = name; + return this; + } + + public String getSellPoint() { + return sellPoint; + } + + public UsersProductSpuVO setSellPoint(String sellPoint) { + this.sellPoint = sellPoint; + return this; + } + + public Integer getCid() { + return cid; + } + + public UsersProductSpuVO setCid(Integer cid) { + this.cid = cid; + return this; + } + + public List getPicUrls() { + return picUrls; + } + + public UsersProductSpuVO setPicUrls(List picUrls) { + this.picUrls = picUrls; + return this; + } + + public Integer getPrice() { + return price; + } + + public UsersProductSpuVO setPrice(Integer price) { + this.price = price; + return this; + } +} \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrValueBO.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrValueBO.java index c908cc218..0cb4a77f0 100644 --- a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrValueBO.java +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductAttrValueBO.java @@ -11,6 +11,10 @@ public class ProductAttrValueBO { * 规格值编号 */ private Integer id; + /** + * 规格编号 + */ + private Integer attrId; /** * 规格值名 */ @@ -59,4 +63,13 @@ public class ProductAttrValueBO { this.createTime = createTime; return this; } + + public Integer getAttrId() { + return attrId; + } + + public ProductAttrValueBO setAttrId(Integer attrId) { + this.attrId = attrId; + return this; + } } \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductSpuBO.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductSpuBO.java index b77874859..b8a97365a 100644 --- a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductSpuBO.java +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductSpuBO.java @@ -48,6 +48,14 @@ public class ProductSpuBO { */ private Integer sort; + // ========== Sku 相关字段 ========= + /** + * 价格 + * + * 目前的计算方式是,以 Sku 最小价格为准 + */ + private Integer price; + public Integer getId() { return id; } @@ -120,4 +128,13 @@ public class ProductSpuBO { return this; } + public Integer getPrice() { + return price; + } + + public ProductSpuBO setPrice(Integer price) { + this.price = price; + return this; + } + } \ No newline at end of file diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/constant/ProductErrorCodeEnum.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/constant/ProductErrorCodeEnum.java index 7d6be43f5..629fde73e 100644 --- a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/constant/ProductErrorCodeEnum.java +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/constant/ProductErrorCodeEnum.java @@ -26,7 +26,8 @@ public enum ProductErrorCodeEnum { PRODUCT_ATTR_NOT_EXIST(1003003001, "商品属性值不存在"), PRODUCT_ATTR_EXISTS(1003003002, "商品规格已经存在"), PRODUCT_ATTR_STATUS_EQUALS(1003003003, "商品规格已经是该状态"), - + PRODUCT_ATTR_VALUE_EXISTS(1003003004, "商品规格值已经存在"), + PRODUCT_ATTR_VALUE_STATUS_EQUALS(1003003005, "商品规格值已经是该状态"), ; private final int code; 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 51f4127f9..a218e56b5 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 @@ -7,7 +7,20 @@ import javax.validation.constraints.NotNull; */ public class ProductSpuPageDTO { + /** + * 商品名 + * + * 模糊匹配 + */ private String name; + /** + * 分类编号 + */ + private Integer cid; + /** + * 是否可见 + */ + private Boolean visible; @NotNull(message = "页码不能为空") private Integer pageNo; @@ -41,4 +54,22 @@ public class ProductSpuPageDTO { return this; } + public Integer getCid() { + return cid; + } + + public ProductSpuPageDTO setCid(Integer cid) { + this.cid = cid; + return this; + } + + public Boolean getVisible() { + return visible; + } + + public ProductSpuPageDTO setVisible(Boolean visible) { + this.visible = visible; + return this; + } + } \ No newline at end of file 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 index 74625ad43..3216268f9 100644 --- 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 @@ -3,6 +3,8 @@ package cn.iocoder.mall.product.convert; import cn.iocoder.mall.product.api.bo.*; import cn.iocoder.mall.product.api.dto.ProductAttrAddDTO; import cn.iocoder.mall.product.api.dto.ProductAttrUpdateDTO; +import cn.iocoder.mall.product.api.dto.ProductAttrValueAddDTO; +import cn.iocoder.mall.product.api.dto.ProductAttrValueUpdateDTO; import cn.iocoder.mall.product.dataobject.ProductAttrDO; import cn.iocoder.mall.product.dataobject.ProductAttrValueDO; import org.mapstruct.Mapper; @@ -40,10 +42,17 @@ public interface ProductAttrConvert { @Mappings({}) ProductAttrDO convert(ProductAttrUpdateDTO productAttrUpdateDTO); + @Mappings({}) + ProductAttrValueDO convert(ProductAttrValueAddDTO productAttrValueAddDTO); + + @Mappings({}) + ProductAttrValueDO convert(ProductAttrValueUpdateDTO productAttrValueUpdateDTO); + @Mappings({}) ProductAttrBO convert(ProductAttrDO productAttrDO); @Mappings({}) ProductAttrValueBO convert2(ProductAttrValueDO productAttrValueDO); + } \ 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 dbeafcae9..1f026f2a2 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 @@ -18,4 +18,12 @@ public interface ProductAttrValueMapper { List selectListByAttrIds(@Param("attrIds") Collection attrIds); + ProductAttrValueDO selectByAttrIdAndName(@Param("attrId") Integer attrId, + @Param("name") String name); + + + void insert(ProductAttrValueDO productAttrValueDO); + + void update(ProductAttrValueDO productAttrValueDO); + } \ No newline at end of file diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductSpuMapper.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductSpuMapper.java index acb590d8d..67973c1b8 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductSpuMapper.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductSpuMapper.java @@ -15,10 +15,15 @@ public interface ProductSpuMapper { void update(ProductSpuDO productSpuDO); + // TODO 芋艿,需要捉摸下,怎么优化下。参数有点多 List selectListByNameLikeOrderBySortAsc(@Param("name") String name, + @Param("cid") Integer cid, + @Param("visible") Boolean visible, @Param("offset") Integer offset, @Param("limit") Integer limit); - Integer selectCountByNameLike(@Param("name") String name); + Integer selectCountByNameLike(@Param("name") String name, + @Param("cid") Integer cid, + @Param("visible") Boolean visible); } \ No newline at end of file diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dataobject/ProductSpuDO.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dataobject/ProductSpuDO.java index 82906c340..ee0243a86 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dataobject/ProductSpuDO.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dataobject/ProductSpuDO.java @@ -57,6 +57,20 @@ public class ProductSpuDO extends BaseDO { */ private Integer sort; + // ========== Sku 相关字段 ========= + /** + * 价格 + * + * 目前的计算方式是,以 Sku 最小价格为准 + */ + private Integer price; + /** + * 库存数量 + * + * 目前的计算方式是,以 Sku 库存累加为准 + */ + private Integer quantity; + public Integer getId() { return id; } @@ -128,4 +142,23 @@ public class ProductSpuDO extends BaseDO { this.sort = sort; return this; } + + public Integer getPrice() { + return price; + } + + public ProductSpuDO setPrice(Integer price) { + this.price = price; + return this; + } + + public Integer getQuantity() { + return quantity; + } + + public ProductSpuDO setQuantity(Integer quantity) { + this.quantity = quantity; + return this; + } + } \ 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 646062c57..49b4bb66a 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 @@ -167,17 +167,58 @@ public class ProductAttrServiceImpl implements ProductAttrService { @Override public CommonResult addProductAttrValue(Integer adminId, ProductAttrValueAddDTO productAttrValueAddDTO) { - return null; + // 校验规格名不重复 + if (productAttrValueMapper.selectByAttrIdAndName(productAttrValueAddDTO.getAttrId(), productAttrValueAddDTO.getName()) != null) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_EXISTS.getCode()); + } + // 插入到数据库 + ProductAttrValueDO productAttrValueDO = ProductAttrConvert.INSTANCE.convert(productAttrValueAddDTO) + .setStatus(ProductAttrConstants.ATTR_VALUE_STATUS_ENABLE); + productAttrValueDO.setCreateTime(new Date()).setDeleted(BaseDO.DELETED_NO); + productAttrValueMapper.insert(productAttrValueDO); + // 返回成功 + return CommonResult.success(ProductAttrConvert.INSTANCE.convert2(productAttrValueDO)); } @Override public CommonResult updateProductAttrValue(Integer adminId, ProductAttrValueUpdateDTO productAttrValueUpdateDTO) { - return null; + // 校验存在 + ProductAttrValueDO productAttrValueDO = productAttrValueMapper.selectById(productAttrValueUpdateDTO.getId()); + if (productAttrValueDO == null) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_NOT_EXIST.getCode()); + } + // 校验规格名不重复 + ProductAttrValueDO existsAttrDO = productAttrValueMapper.selectByAttrIdAndName(productAttrValueDO.getAttrId(), productAttrValueUpdateDTO.getName()); + if (existsAttrDO != null && !existsAttrDO.getId().equals(productAttrValueUpdateDTO.getId())) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_EXISTS.getCode()); + } + // 更新到数据库 + ProductAttrValueDO updateProductValue = ProductAttrConvert.INSTANCE.convert(productAttrValueUpdateDTO); + productAttrValueMapper.update(updateProductValue); + // 返回成功 + return CommonResult.success(true); } @Override public CommonResult updateProductAttrValueStatus(Integer adminId, Integer productAttrValueId, Integer status) { - return null; + // 校验参数 + if (!isValidAttrValueStatus(status)) { + return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "变更状态必须是开启(1)或关闭(2)"); // TODO 有点搓 + } + // 校验存在 + ProductAttrValueDO productAttrValueDO = productAttrValueMapper.selectById(productAttrValueId); + if (productAttrValueDO == null) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_NOT_EXIST.getCode()); + } + // 校验状态 + if (productAttrValueDO.getStatus().equals(status)) { + return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_STATUS_EQUALS.getCode()); + } + // 更新到数据库 + ProductAttrValueDO updateProductAttrValue = new ProductAttrValueDO().setId(productAttrValueId).setStatus(status); + productAttrValueMapper.update(updateProductAttrValue); + // 返回成功 + return CommonResult.success(true); } private boolean isValidAttrStatus(Integer status) { 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 ae3d7daba..603ca6f47 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 @@ -92,6 +92,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { .setPicUrls(StringUtil.join(productSpuAddDTO.getPicUrls(), ",")) .setSort(0); // 排序为 0 spu.setCreateTime(new Date()).setDeleted(BaseDO.DELETED_NO); + initSpuFromSkus(spu, productSpuAddDTO.getSkus()); // 初始化 sku 相关信息到 spu 中 productSpuMapper.insert(spu); // 保存 Sku List skus = productSpuAddDTO.getSkus().stream().map(productSkuAddDTO -> { @@ -141,6 +142,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { // 更新 Spu ProductSpuDO updateSpu = ProductSpuConvert.INSTANCE.convert(productSpuUpdateDTO) .setPicUrls(StringUtil.join(productSpuUpdateDTO.getPicUrls(), ",")); + initSpuFromSkus(updateSpu, productSpuUpdateDTO.getSkus()); // 初始化 sku 相关信息到 spu 中 productSpuMapper.update(updateSpu); // 修改 Sku List existsSkus = productSkuMapper.selectListBySpuIdAndStatus(productSpuUpdateDTO.getId(), ProductSpuConstants.SKU_STATUS_ENABLE); @@ -198,10 +200,11 @@ public class ProductSpuServiceImpl implements ProductSpuService { ProductSpuPageBO productSpuPage = new ProductSpuPageBO(); // 查询分页数据 int offset = productSpuPageDTO.getPageNo() * productSpuPageDTO.getPageSize(); - productSpuPage.setSpus(ProductSpuConvert.INSTANCE.convert(productSpuMapper.selectListByNameLikeOrderBySortAsc(productSpuPageDTO.getName(), + productSpuPage.setSpus(ProductSpuConvert.INSTANCE.convert(productSpuMapper.selectListByNameLikeOrderBySortAsc( + productSpuPageDTO.getName(), productSpuPageDTO.getCid(), productSpuPageDTO.getVisible(), offset, productSpuPageDTO.getPageSize()))); // 查询分页总数 - productSpuPage.setCount(productSpuMapper.selectCountByNameLike(productSpuPageDTO.getName())); + productSpuPage.setCount(productSpuMapper.selectCountByNameLike(productSpuPageDTO.getName(), productSpuPageDTO.getCid(), productSpuPageDTO.getVisible())); // 返回结果 return CommonResult.success(productSpuPage); } @@ -250,4 +253,10 @@ public class ProductSpuServiceImpl implements ProductSpuService { return null; } + private void initSpuFromSkus(ProductSpuDO spu, List skus) { + assert skus.size() > 0; // 写个断言,避免下面警告 + spu.setPrice(skus.stream().min(Comparator.comparing(ProductSkuAddOrUpdateDTO::getPrice)).get().getPrice()); // 求最小价格 + spu.setQuantity(skus.stream().mapToInt(ProductSkuAddOrUpdateDTO::getQuantity).sum()); // 求库存之和 + } + } \ 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 32891661c..17ad319f8 100644 --- a/product/product-service-impl/src/main/resources/mapper/ProductAttrValueMapper.xml +++ b/product/product-service-impl/src/main/resources/mapper/ProductAttrValueMapper.xml @@ -93,4 +93,38 @@ + + + + INSERT INTO product_attr_value ( + attr_id, name, status, create_time, deleted + ) VALUES ( + #{attrId}, #{name}, #{status}, #{createTime}, #{deleted} + ) + + + + UPDATE product_attr_value + + + name = #{name}, + + + status = #{status}, + + + deleted = #{deleted} + + + WHERE id = #{id} + + + \ No newline at end of file diff --git a/product/product-service-impl/src/main/resources/mapper/ProductSpuMapper.xml b/product/product-service-impl/src/main/resources/mapper/ProductSpuMapper.xml index 2389a1634..918049ff1 100644 --- a/product/product-service-impl/src/main/resources/mapper/ProductSpuMapper.xml +++ b/product/product-service-impl/src/main/resources/mapper/ProductSpuMapper.xml @@ -4,7 +4,8 @@ id, name, sell_point, description, cid, - pic_urls, visible, sort, create_time + pic_urls, visible, sort, price, quantity, + create_time