商品 SPU + SKU 添加
This commit is contained in:
@@ -8,7 +8,7 @@ import cn.iocoder.mall.product.api.constant.ProductCategoryConstants;
|
||||
import cn.iocoder.mall.product.api.dto.ProductCategoryAddDTO;
|
||||
import cn.iocoder.mall.product.api.dto.ProductCategoryUpdateDTO;
|
||||
import cn.iocoder.mall.product.application.convert.ProductCategoryConvert;
|
||||
import cn.iocoder.mall.product.application.vo.admins.AdminProductCategoryTreeNodeVO;
|
||||
import cn.iocoder.mall.product.application.vo.admins.AdminsProductCategoryTreeNodeVO;
|
||||
import cn.iocoder.mall.product.application.vo.admins.AdminsProductCategoryVO;
|
||||
import com.alibaba.dubbo.config.annotation.Reference;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -33,16 +33,16 @@ public class AdminsProductCategoryController {
|
||||
|
||||
@GetMapping("/tree")
|
||||
@ApiOperation("获得分类树结构")
|
||||
public CommonResult<List<AdminProductCategoryTreeNodeVO>> tree() {
|
||||
public CommonResult<List<AdminsProductCategoryTreeNodeVO>> tree() {
|
||||
List<ProductCategoryBO> productCategories = productCategoryService.getAll().getData();
|
||||
// 创建 ProductCategoryTreeNodeVO Map
|
||||
Map<Integer, AdminProductCategoryTreeNodeVO> treeNodeMap = productCategories.stream().collect(Collectors.toMap(ProductCategoryBO::getId, ProductCategoryConvert.INSTANCE::convert));
|
||||
Map<Integer, AdminsProductCategoryTreeNodeVO> treeNodeMap = productCategories.stream().collect(Collectors.toMap(ProductCategoryBO::getId, ProductCategoryConvert.INSTANCE::convert));
|
||||
// 处理父子关系
|
||||
treeNodeMap.values().stream()
|
||||
.filter(node -> !node.getPid().equals(ProductCategoryConstants.PID_ROOT))
|
||||
.forEach((childNode) -> {
|
||||
// 获得父节点
|
||||
AdminProductCategoryTreeNodeVO parentNode = treeNodeMap.get(childNode.getPid());
|
||||
AdminsProductCategoryTreeNodeVO parentNode = treeNodeMap.get(childNode.getPid());
|
||||
if (parentNode.getChildren() == null) { // 初始化 children 数组
|
||||
parentNode.setChildren(new ArrayList<>());
|
||||
}
|
||||
@@ -50,9 +50,9 @@ public class AdminsProductCategoryController {
|
||||
parentNode.getChildren().add(childNode);
|
||||
});
|
||||
// 获得到所有的根节点
|
||||
List<AdminProductCategoryTreeNodeVO> rootNodes = treeNodeMap.values().stream()
|
||||
List<AdminsProductCategoryTreeNodeVO> rootNodes = treeNodeMap.values().stream()
|
||||
.filter(node -> node.getPid().equals(ProductCategoryConstants.PID_ROOT))
|
||||
.sorted(Comparator.comparing(AdminProductCategoryTreeNodeVO::getSort))
|
||||
.sorted(Comparator.comparing(AdminsProductCategoryTreeNodeVO::getSort))
|
||||
.collect(Collectors.toList());
|
||||
return CommonResult.success(rootNodes);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import com.alibaba.dubbo.config.annotation.Reference;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -35,6 +37,16 @@ public class AdminsProductSpuController {
|
||||
|
||||
@PostMapping("/spu/add")
|
||||
@ApiOperation("创建商品")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "name", value = "SPU 名字", required = true, example = "厮大牛逼"),
|
||||
@ApiImplicitParam(name = "sellPoint", value = "卖点", required = true, example = "各种 MQ 骚操作"),
|
||||
@ApiImplicitParam(name = "description", value = "描述", required = true, example = "你就说强不强 MQ 骚操作"),
|
||||
@ApiImplicitParam(name = "cid", value = "分类编号", required = true, example = "反正我是信了"),
|
||||
@ApiImplicitParam(name = "picUrls", value = "商品主图地址的数组", required = true, example = "http://www.iocoder.cn"),
|
||||
@ApiImplicitParam(name = "visible", value = "是否上架商品(是否可见)", required = true, example = "true"),
|
||||
@ApiImplicitParam(name = "skuStr", value = "SKU 字符串", required = true, example = "[{\"attrs\": [1,3 ], \"price\": 1, \"quantity\": 100, \"picUrl\": \"http://www.iocoder.cn\"}]"),
|
||||
|
||||
})
|
||||
public CommonResult<AdminsProductSpuDetailVO> add(@RequestParam("name") String name,
|
||||
@RequestParam("sellPoint") String sellPoint,
|
||||
@RequestParam("description") String description,
|
||||
@@ -54,6 +66,17 @@ public class AdminsProductSpuController {
|
||||
|
||||
@PostMapping("/spu/update")
|
||||
@ApiOperation("更新商品")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "SPU 编号", required = true, example = "100"),
|
||||
@ApiImplicitParam(name = "name", value = "SPU 名字", required = true, example = "厮大牛逼"),
|
||||
@ApiImplicitParam(name = "sellPoint", value = "卖点", required = true, example = "各种 MQ 骚操作"),
|
||||
@ApiImplicitParam(name = "description", value = "描述", required = true, example = "你就说强不强 MQ 骚操作"),
|
||||
@ApiImplicitParam(name = "cid", value = "分类编号", required = true, example = "反正我是信了"),
|
||||
@ApiImplicitParam(name = "picUrls", value = "商品主图地址的数组", required = true, example = "http://www.iocoder.cn"),
|
||||
@ApiImplicitParam(name = "visible", value = "是否上架商品(是否可见)", required = true, example = "true"),
|
||||
@ApiImplicitParam(name = "skuStr", value = "SKU 字符串", required = true, example = "[{\"attrs\": [1,3 ], \"price\": 1, \"quantity\": 100, \"picUrl\": \"http://www.iocoder.cn\"}]"),
|
||||
|
||||
})
|
||||
public CommonResult<Boolean> update(@RequestParam("id") Integer id,
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("sellPoint") String sellPoint,
|
||||
|
||||
@@ -3,7 +3,7 @@ package cn.iocoder.mall.product.application.convert;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.product.api.bo.ProductCategoryBO;
|
||||
import cn.iocoder.mall.product.application.vo.users.UsersProductCategoryVO;
|
||||
import cn.iocoder.mall.product.application.vo.admins.AdminProductCategoryTreeNodeVO;
|
||||
import cn.iocoder.mall.product.application.vo.admins.AdminsProductCategoryTreeNodeVO;
|
||||
import cn.iocoder.mall.product.application.vo.admins.AdminsProductCategoryVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
@@ -21,7 +21,7 @@ public interface ProductCategoryConvert {
|
||||
|
||||
List<UsersProductCategoryVO> convertToVO(List<ProductCategoryBO> categoryList);
|
||||
|
||||
AdminProductCategoryTreeNodeVO convert(ProductCategoryBO category);
|
||||
AdminsProductCategoryTreeNodeVO convert(ProductCategoryBO category);
|
||||
|
||||
CommonResult<AdminsProductCategoryVO> convert(CommonResult<ProductCategoryBO> result);
|
||||
|
||||
|
||||
@@ -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 AdminsProductAttrDetailVO {
|
||||
|
||||
@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 AdminsProductAttrDetailVO setAttrId(Integer attrId) {
|
||||
this.attrId = attrId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getAttrName() {
|
||||
return attrName;
|
||||
}
|
||||
|
||||
public AdminsProductAttrDetailVO setAttrName(String attrName) {
|
||||
this.attrName = attrName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getAttrValueId() {
|
||||
return attrValueId;
|
||||
}
|
||||
|
||||
public AdminsProductAttrDetailVO setAttrValueId(Integer attrValueId) {
|
||||
this.attrValueId = attrValueId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getAttrValueName() {
|
||||
return attrValueName;
|
||||
}
|
||||
|
||||
public AdminsProductAttrDetailVO setAttrValueName(String attrValueName) {
|
||||
this.attrValueName = attrValueName;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel("产品分类树节点 VO")
|
||||
public class AdminProductCategoryTreeNodeVO {
|
||||
public class AdminsProductCategoryTreeNodeVO {
|
||||
|
||||
@ApiModelProperty(value = "分类编号", required = true, example = "1")
|
||||
private Integer id;
|
||||
@@ -26,13 +26,13 @@ public class AdminProductCategoryTreeNodeVO {
|
||||
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳")
|
||||
private Date createTime;
|
||||
@ApiModelProperty(value = "子节点数组")
|
||||
private List<AdminProductCategoryTreeNodeVO> children;
|
||||
private List<AdminsProductCategoryTreeNodeVO> children;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public AdminProductCategoryTreeNodeVO setId(Integer id) {
|
||||
public AdminsProductCategoryTreeNodeVO setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class AdminProductCategoryTreeNodeVO {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public AdminProductCategoryTreeNodeVO setPid(Integer pid) {
|
||||
public AdminsProductCategoryTreeNodeVO setPid(Integer pid) {
|
||||
this.pid = pid;
|
||||
return this;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class AdminProductCategoryTreeNodeVO {
|
||||
return name;
|
||||
}
|
||||
|
||||
public AdminProductCategoryTreeNodeVO setName(String name) {
|
||||
public AdminsProductCategoryTreeNodeVO setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class AdminProductCategoryTreeNodeVO {
|
||||
return description;
|
||||
}
|
||||
|
||||
public AdminProductCategoryTreeNodeVO setDescription(String description) {
|
||||
public AdminsProductCategoryTreeNodeVO setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class AdminProductCategoryTreeNodeVO {
|
||||
return picUrl;
|
||||
}
|
||||
|
||||
public AdminProductCategoryTreeNodeVO setPicUrl(String picUrl) {
|
||||
public AdminsProductCategoryTreeNodeVO setPicUrl(String picUrl) {
|
||||
this.picUrl = picUrl;
|
||||
return this;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class AdminProductCategoryTreeNodeVO {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public AdminProductCategoryTreeNodeVO setSort(Integer sort) {
|
||||
public AdminsProductCategoryTreeNodeVO setSort(Integer sort) {
|
||||
this.sort = sort;
|
||||
return this;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class AdminProductCategoryTreeNodeVO {
|
||||
return status;
|
||||
}
|
||||
|
||||
public AdminProductCategoryTreeNodeVO setStatus(Integer status) {
|
||||
public AdminsProductCategoryTreeNodeVO setStatus(Integer status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
@@ -95,16 +95,16 @@ public class AdminProductCategoryTreeNodeVO {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public AdminProductCategoryTreeNodeVO setCreateTime(Date createTime) {
|
||||
public AdminsProductCategoryTreeNodeVO setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<AdminProductCategoryTreeNodeVO> getChildren() {
|
||||
public List<AdminsProductCategoryTreeNodeVO> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public AdminProductCategoryTreeNodeVO setChildren(List<AdminProductCategoryTreeNodeVO> children) {
|
||||
public AdminsProductCategoryTreeNodeVO setChildren(List<AdminsProductCategoryTreeNodeVO> children) {
|
||||
this.children = children;
|
||||
return this;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package cn.iocoder.mall.product.application.vo.admins;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品 Sku 明细 BO
|
||||
*/
|
||||
public class AdminsProductSkuDetailVO {
|
||||
|
||||
@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<AdminsProductAttrDetailVO> 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 AdminsProductSkuDetailVO setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getSpuId() {
|
||||
return spuId;
|
||||
}
|
||||
|
||||
public AdminsProductSkuDetailVO setSpuId(Integer spuId) {
|
||||
this.spuId = spuId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPicURL() {
|
||||
return picURL;
|
||||
}
|
||||
|
||||
public AdminsProductSkuDetailVO setPicURL(String picURL) {
|
||||
this.picURL = picURL;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public AdminsProductSkuDetailVO setPrice(Integer price) {
|
||||
this.price = price;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public AdminsProductSkuDetailVO setQuantity(Integer quantity) {
|
||||
this.quantity = quantity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<AdminsProductAttrDetailVO> getAttrs() {
|
||||
return attrs;
|
||||
}
|
||||
|
||||
public AdminsProductSkuDetailVO setAttrs(List<AdminsProductAttrDetailVO> attrs) {
|
||||
this.attrs = attrs;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,120 @@
|
||||
package cn.iocoder.mall.product.application.vo.admins;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "商品 SPU 详细 VO", description = "包括 SKU 信息 VO")
|
||||
public class AdminsProductSpuDetailVO {
|
||||
|
||||
@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<String> picUrls;
|
||||
|
||||
}
|
||||
// ========== 其他信息 =========
|
||||
@ApiModelProperty(value = "是否上架商品(是否可见)", required = true, example = "true")
|
||||
private Boolean visible;
|
||||
@ApiModelProperty(value = "排序字段", required = true, example = "10")
|
||||
private Integer sort;
|
||||
|
||||
// ========== SKU =========
|
||||
|
||||
/**
|
||||
* SKU 数组
|
||||
*/
|
||||
private List<AdminsProductSkuDetailVO> skus;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public AdminsProductSpuDetailVO setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public AdminsProductSpuDetailVO setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getSellPoint() {
|
||||
return sellPoint;
|
||||
}
|
||||
|
||||
public AdminsProductSpuDetailVO setSellPoint(String sellPoint) {
|
||||
this.sellPoint = sellPoint;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public AdminsProductSpuDetailVO setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getCid() {
|
||||
return cid;
|
||||
}
|
||||
|
||||
public AdminsProductSpuDetailVO setCid(Integer cid) {
|
||||
this.cid = cid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<String> getPicUrls() {
|
||||
return picUrls;
|
||||
}
|
||||
|
||||
public AdminsProductSpuDetailVO setPicUrls(List<String> picUrls) {
|
||||
this.picUrls = picUrls;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Boolean getVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
public AdminsProductSpuDetailVO setVisible(Boolean visible) {
|
||||
this.visible = visible;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public AdminsProductSpuDetailVO setSort(Integer sort) {
|
||||
this.sort = sort;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<AdminsProductSkuDetailVO> getSkus() {
|
||||
return skus;
|
||||
}
|
||||
|
||||
public AdminsProductSpuDetailVO setSkus(List<AdminsProductSkuDetailVO> skus) {
|
||||
this.skus = skus;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user