商品规格 key 的迁移
This commit is contained in:
parent
75876682fb
commit
7dbbd412d8
@ -0,0 +1,67 @@
|
||||
package cn.iocoder.mall.managementweb.controller.product;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyCreateReqVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyPageReqVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyRespVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyUpdateReqVO;
|
||||
import cn.iocoder.mall.managementweb.manager.product.ProductAttrKeyManager;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 商品规格键 Controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/product-attr/")
|
||||
@Api(tags = "商品规格键")
|
||||
@Validated
|
||||
public class ProductAttrController {
|
||||
|
||||
@Autowired
|
||||
private ProductAttrKeyManager productAttrKeyManager;
|
||||
|
||||
@PostMapping("/key/create")
|
||||
@ApiOperation("创建商品规格键")
|
||||
public CommonResult<Integer> createProductAttrKey(@Valid ProductAttrKeyCreateReqVO createVO) {
|
||||
return success(productAttrKeyManager.createProductAttrKey(createVO));
|
||||
}
|
||||
|
||||
@PostMapping("/key/update")
|
||||
@ApiOperation("更新商品规格键")
|
||||
public CommonResult<Boolean> updateProductAttrKey(@Valid ProductAttrKeyUpdateReqVO updateVO) {
|
||||
productAttrKeyManager.updateProductAttrKey(updateVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/key/get")
|
||||
@ApiOperation("获得商品规格键")
|
||||
@ApiImplicitParam(name = "productAttrKeyId", value = "商品规格键编号", required = true)
|
||||
public CommonResult<ProductAttrKeyRespVO> getProductAttrKey(@RequestParam("productAttrKeyId") Integer productAttrKeyId) {
|
||||
return success(productAttrKeyManager.getProductAttrKey(productAttrKeyId));
|
||||
}
|
||||
|
||||
@GetMapping("/key/list")
|
||||
@ApiOperation("获得商品规格键列表")
|
||||
@ApiImplicitParam(name = "productAttrKeyIds", value = "商品规格键编号列表", required = true)
|
||||
public CommonResult<List<ProductAttrKeyRespVO>> listProductAttrKeys(@RequestParam("productAttrKeyIds") List<Integer> productAttrKeyIds) {
|
||||
return success(productAttrKeyManager.listProductAttrKeys(productAttrKeyIds));
|
||||
}
|
||||
|
||||
@GetMapping("/key/page")
|
||||
@ApiOperation("获得商品规格键分页")
|
||||
public CommonResult<PageResult<ProductAttrKeyRespVO>> pageProductAttrKey(ProductAttrKeyPageReqVO pageVO) {
|
||||
return success(productAttrKeyManager.pageProductAttrKey(pageVO));
|
||||
}
|
||||
|
||||
}
|
@ -61,10 +61,14 @@ public class ProductSpuController {
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得商品 SPU 分页")
|
||||
public CommonResult<PageResult<ProductSpuRespVO>> pageProductSpu(ProductSpuPageReqVO pageVO) {
|
||||
//
|
||||
//
|
||||
//
|
||||
// 全部:无搜索条件
|
||||
// 在售中:visible = true && hasQuantity = true
|
||||
// 已售罄:visible = true && hasQuantity = false
|
||||
// 仓库中:visible = false
|
||||
return success(productSpuManager.pageProductSpu(pageVO));
|
||||
}
|
||||
|
||||
// TODO 芋艿,删除功能暂时不做。主要原因是,关联的数据太多。删除带来的问题会比较大
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package cn.iocoder.mall.managementweb.controller.product.vo.attr;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("商品规格键创建 Request VO")
|
||||
@Data
|
||||
public class ProductAttrKeyCreateReqVO {
|
||||
|
||||
@ApiModelProperty(value = "规格键名称", required = true, example = "尺寸")
|
||||
@NotEmpty(message = "规格键名称不能为空")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举")
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package cn.iocoder.mall.managementweb.controller.product.vo.attr;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@ApiModel("商品规格键分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ProductAttrKeyPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "规格键名称", required = true, example = "尺寸", notes = "模糊匹配")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "状态", example = "1", notes = "见 CommonStatusEnum 枚举")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package cn.iocoder.mall.managementweb.controller.product.vo.attr;
|
||||
|
||||
import lombok.*;
|
||||
import io.swagger.annotations.*;
|
||||
import java.util.*;
|
||||
|
||||
@ApiModel("商品规格键 Response VO")
|
||||
@Data
|
||||
public class ProductAttrKeyRespVO {
|
||||
|
||||
@ApiModelProperty(value = "规格键编号", required = true, example = "1")
|
||||
private Integer id;
|
||||
@ApiModelProperty(value = "规格键名称", required = true, example = "尺寸")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举")
|
||||
private Integer status;
|
||||
@ApiModelProperty(value = "创建时间", required = true)
|
||||
private Date createTime;
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package cn.iocoder.mall.managementweb.controller.product.vo.attr;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("商品规格键更新 Request VO")
|
||||
@Data
|
||||
public class ProductAttrKeyUpdateReqVO {
|
||||
|
||||
@ApiModelProperty(value = "规格键编号", required = true, example = "1")
|
||||
@NotNull(message = "规格键编号不能为空")
|
||||
private Integer id;
|
||||
@ApiModelProperty(value = "规格键名称", required = true, example = "尺寸")
|
||||
@NotEmpty(message = "规格键名称不能为空")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举")
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package cn.iocoder.mall.managementweb.convert.product;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyCreateReqVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyPageReqVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyRespVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyUpdateReqVO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyUpdateReqDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductAttrKeyConvert {
|
||||
|
||||
ProductAttrKeyConvert INSTANCE = Mappers.getMapper(ProductAttrKeyConvert.class);
|
||||
|
||||
ProductAttrKeyCreateReqDTO convert(ProductAttrKeyCreateReqVO bean);
|
||||
|
||||
ProductAttrKeyUpdateReqDTO convert(ProductAttrKeyUpdateReqVO bean);
|
||||
|
||||
ProductAttrKeyRespVO convert(ProductAttrKeyRespDTO bean);
|
||||
|
||||
List<ProductAttrKeyRespVO> convertList(List<ProductAttrKeyRespDTO> list);
|
||||
|
||||
PageResult<ProductAttrKeyRespVO> convertPage(PageResult<ProductAttrKeyRespDTO> page);
|
||||
|
||||
ProductAttrKeyPageReqDTO convert(ProductAttrKeyPageReqVO bean);
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package cn.iocoder.mall.managementweb.manager.product;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyCreateReqVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyPageReqVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyRespVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.attr.ProductAttrKeyUpdateReqVO;
|
||||
import cn.iocoder.mall.managementweb.convert.product.ProductAttrKeyConvert;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.ProductAttrRpc;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyRespDTO;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品规格 Manager
|
||||
*/
|
||||
@Service
|
||||
public class ProductAttrKeyManager {
|
||||
|
||||
@DubboReference(version = "${dubbo.consumer.ProductAttrRpc.version}")
|
||||
private ProductAttrRpc productAttrKeyRpc;
|
||||
|
||||
/**
|
||||
* 创建商品规格键
|
||||
*
|
||||
* @param createVO 创建商品规格键 VO
|
||||
* @return 商品规格键
|
||||
*/
|
||||
public Integer createProductAttrKey(ProductAttrKeyCreateReqVO createVO) {
|
||||
CommonResult<Integer> createProductAttrKeyResult = productAttrKeyRpc.createProductAttrKey(
|
||||
ProductAttrKeyConvert.INSTANCE.convert(createVO));
|
||||
createProductAttrKeyResult.checkError();
|
||||
return createProductAttrKeyResult.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品规格键
|
||||
*
|
||||
* @param updateVO 更新商品规格键 VO
|
||||
*/
|
||||
public void updateProductAttrKey(ProductAttrKeyUpdateReqVO updateVO) {
|
||||
CommonResult<Boolean> updateProductAttrKeyResult = productAttrKeyRpc.updateProductAttrKey(
|
||||
ProductAttrKeyConvert.INSTANCE.convert(updateVO));
|
||||
updateProductAttrKeyResult.checkError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品规格键
|
||||
*
|
||||
* @param productAttrKeyId 商品规格键编号
|
||||
*/
|
||||
public void deleteProductAttrKey(Integer productAttrKeyId) {
|
||||
CommonResult<Boolean> deleteProductAttrKeyResult = productAttrKeyRpc.deleteProductAttrKey(productAttrKeyId);
|
||||
deleteProductAttrKeyResult.checkError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键
|
||||
*
|
||||
* @param productAttrKeyId 商品规格键编号
|
||||
* @return 商品规格键
|
||||
*/
|
||||
public ProductAttrKeyRespVO getProductAttrKey(Integer productAttrKeyId) {
|
||||
CommonResult<ProductAttrKeyRespDTO> getProductAttrKeyResult = productAttrKeyRpc.getProductAttrKey(productAttrKeyId);
|
||||
getProductAttrKeyResult.checkError();
|
||||
return ProductAttrKeyConvert.INSTANCE.convert(getProductAttrKeyResult.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键列表
|
||||
*
|
||||
* @param productAttrKeyIds 商品规格键编号列表
|
||||
* @return 商品规格键列表
|
||||
*/
|
||||
public List<ProductAttrKeyRespVO> listProductAttrKeys(List<Integer> productAttrKeyIds) {
|
||||
CommonResult<List<ProductAttrKeyRespDTO>> listProductAttrKeyResult = productAttrKeyRpc.listProductAttrKeys(productAttrKeyIds);
|
||||
listProductAttrKeyResult.checkError();
|
||||
return ProductAttrKeyConvert.INSTANCE.convertList(listProductAttrKeyResult.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键分页
|
||||
*
|
||||
* @param pageVO 商品规格键分页查询
|
||||
* @return 商品规格键分页结果
|
||||
*/
|
||||
public PageResult<ProductAttrKeyRespVO> pageProductAttrKey(ProductAttrKeyPageReqVO pageVO) {
|
||||
CommonResult<PageResult<ProductAttrKeyRespDTO>> pageProductAttrKeyResult = productAttrKeyRpc.pageProductAttrKey(
|
||||
ProductAttrKeyConvert.INSTANCE.convert(pageVO));
|
||||
pageProductAttrKeyResult.checkError();
|
||||
return ProductAttrKeyConvert.INSTANCE.convertPage(pageProductAttrKeyResult.getData());
|
||||
}
|
||||
|
||||
}
|
@ -55,6 +55,8 @@ dubbo:
|
||||
version: 1.0.0
|
||||
ProductSpuRpc:
|
||||
version: 1.0.0
|
||||
ProductAttrRpc:
|
||||
version: 1.0.0
|
||||
|
||||
# Swagger 配置项
|
||||
swagger:
|
||||
|
@ -26,11 +26,9 @@ public interface ProductErrorCodeConstants {
|
||||
|
||||
// ========== PRODUCT ATTR + ATTR_VALUE 模块 ==========
|
||||
ErrorCode PRODUCT_ATTR_VALUE_NOT_EXIST = new ErrorCode(1003003000, "商品属性值不存在");
|
||||
ErrorCode PRODUCT_ATTR_KEY_NOT_EXIST = new ErrorCode(1003003001, "商品属性值不存在");
|
||||
ErrorCode PRODUCT_ATTR_EXISTS = new ErrorCode(1003003002, "商品规格已经存在");
|
||||
ErrorCode PRODUCT_ATTR_STATUS_EQUALS = new ErrorCode(1003003003, "商品规格已经是该状态");
|
||||
ErrorCode PRODUCT_ATTR_KEY_NOT_EXIST = new ErrorCode(1003003001, "商品属性键不存在");
|
||||
ErrorCode PRODUCT_ATTR_KEY_EXISTS = new ErrorCode(1003003002, "商品规格键已经存在");
|
||||
ErrorCode PRODUCT_ATTR_VALUE_EXISTS = new ErrorCode(1003003004, "商品规格值已经存在");
|
||||
ErrorCode PRODUCT_ATTR_VALUE_STATUS_EQUALS = new ErrorCode(1003003005, "商品规格值已经是该状态");
|
||||
|
||||
// ========== PRODUCT BRAND模块 ==========
|
||||
ErrorCode PRODUCT_BRAND_NAME_EXIST = new ErrorCode(1003004000,"商品品牌的名字已经存在");
|
||||
|
@ -0,0 +1,63 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyUpdateReqDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品规格 Rpc 接口
|
||||
*/
|
||||
public interface ProductAttrRpc {
|
||||
|
||||
/**
|
||||
* 创建商品规格键
|
||||
*
|
||||
* @param createDTO 创建商品规格键 DTO
|
||||
* @return 商品规格键编号
|
||||
*/
|
||||
CommonResult<Integer> createProductAttrKey(ProductAttrKeyCreateReqDTO createDTO);
|
||||
|
||||
/**
|
||||
* 更新商品规格键
|
||||
*
|
||||
* @param updateDTO 更新商品规格键 DTO
|
||||
*/
|
||||
CommonResult<Boolean> updateProductAttrKey(ProductAttrKeyUpdateReqDTO updateDTO);
|
||||
|
||||
/**
|
||||
* 删除商品规格键
|
||||
*
|
||||
* @param productAttrKeyId 商品规格键编号
|
||||
*/
|
||||
CommonResult<Boolean> deleteProductAttrKey(Integer productAttrKeyId);
|
||||
|
||||
/**
|
||||
* 获得商品规格键
|
||||
*
|
||||
* @param productAttrKeyId 商品规格键编号
|
||||
* @return 商品规格键
|
||||
*/
|
||||
CommonResult<ProductAttrKeyRespDTO> getProductAttrKey(Integer productAttrKeyId);
|
||||
|
||||
/**
|
||||
* 获得商品规格键列表
|
||||
*
|
||||
* @param productAttrKeyIds 商品规格键编号列表
|
||||
* @return 商品规格键列表
|
||||
*/
|
||||
CommonResult<List<ProductAttrKeyRespDTO>> listProductAttrKeys(List<Integer> productAttrKeyIds);
|
||||
|
||||
/**
|
||||
* 获得商品规格键分页
|
||||
*
|
||||
* @param pageDTO 商品规格键分页查询
|
||||
* @return 商品规格键分页结果
|
||||
*/
|
||||
CommonResult<PageResult<ProductAttrKeyRespDTO>> pageProductAttrKey(ProductAttrKeyPageReqDTO pageDTO);
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品规格键创建 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyCreateReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 规格键名称
|
||||
*/
|
||||
@NotEmpty(message = "规格键名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr.dto;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品规格键分页 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyPageReqDTO extends PageParam {
|
||||
|
||||
/**
|
||||
* 规格键名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品规格键 Response DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyRespDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 规格键编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 规格键名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 商品规格键更新 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyUpdateReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 规格键编号
|
||||
*/
|
||||
@NotNull(message = "规格键编号不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 规格键名称
|
||||
*/
|
||||
@NotEmpty(message = "规格键名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package cn.iocoder.mall.productservice.convert.attr;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.attr.ProductAttrKeyDO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyUpdateReqDTO;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyBO;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyCreateBO;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyPageBO;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyUpdateBO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductAttrConvert {
|
||||
|
||||
ProductAttrConvert INSTANCE = Mappers.getMapper(ProductAttrConvert.class);
|
||||
|
||||
ProductAttrKeyDO convert(ProductAttrKeyCreateBO bean);
|
||||
|
||||
ProductAttrKeyBO convert(ProductAttrKeyDO bean);
|
||||
|
||||
ProductAttrKeyDO convert(ProductAttrKeyUpdateBO bean);
|
||||
|
||||
List<ProductAttrKeyBO> convertList(List<ProductAttrKeyDO> list);
|
||||
|
||||
PageResult<ProductAttrKeyBO> convertPage(IPage<ProductAttrKeyDO> page);
|
||||
|
||||
ProductAttrKeyCreateBO convert(ProductAttrKeyCreateReqDTO bean);
|
||||
|
||||
ProductAttrKeyUpdateBO convert(ProductAttrKeyUpdateReqDTO bean);
|
||||
|
||||
ProductAttrKeyRespDTO convert(ProductAttrKeyBO bean);
|
||||
|
||||
List<ProductAttrKeyRespDTO> convertList02(List<ProductAttrKeyBO> list);
|
||||
|
||||
ProductAttrKeyPageBO convert(ProductAttrKeyPageReqDTO bean);
|
||||
|
||||
PageResult<ProductAttrKeyRespDTO> convertPage(PageResult<ProductAttrKeyBO> page);
|
||||
|
||||
}
|
@ -1,10 +1,25 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.mapper.attr;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.attr.ProductAttrKeyDO;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyPageBO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ProductAttrKeyMapper extends BaseMapper<ProductAttrKeyDO> {
|
||||
|
||||
default IPage<ProductAttrKeyDO> selectPage(ProductAttrKeyPageBO pageBO) {
|
||||
return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()),
|
||||
new QueryWrapperX<ProductAttrKeyDO>().likeIfPresent("name", pageBO.getName())
|
||||
.eqIfPresent("status", pageBO.getStatus()));
|
||||
}
|
||||
|
||||
default ProductAttrKeyDO selectByName(String name) {
|
||||
return selectOne(new QueryWrapper<ProductAttrKeyDO>().eq("name", name));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,87 @@
|
||||
package cn.iocoder.mall.productservice.manager.attr;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.convert.attr.ProductAttrConvert;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyUpdateReqDTO;
|
||||
import cn.iocoder.mall.productservice.service.attr.ProductAttrService;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyBO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品规格 Manager
|
||||
*/
|
||||
@Service
|
||||
public class ProductAttrManager {
|
||||
|
||||
@Autowired
|
||||
private ProductAttrService productAttrService;
|
||||
|
||||
/**
|
||||
* 创建商品规格键
|
||||
*
|
||||
* @param createDTO 创建商品规格键 DTO
|
||||
* @return 商品规格键
|
||||
*/
|
||||
public Integer createProductAttrKey(ProductAttrKeyCreateReqDTO createDTO) {
|
||||
ProductAttrKeyBO productAttrKeyBO = productAttrService.createProductAttrKey(ProductAttrConvert.INSTANCE.convert(createDTO));
|
||||
return productAttrKeyBO.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品规格键
|
||||
*
|
||||
* @param updateDTO 更新商品规格键 DTO
|
||||
*/
|
||||
public void updateProductAttrKey(ProductAttrKeyUpdateReqDTO updateDTO) {
|
||||
productAttrService.updateProductAttrKey(ProductAttrConvert.INSTANCE.convert(updateDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品规格键
|
||||
*
|
||||
* @param productAttrKeyId 商品规格键编号
|
||||
*/
|
||||
public void deleteProductAttrKey(Integer productAttrKeyId) {
|
||||
productAttrService.deleteProductAttrKey(productAttrKeyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键
|
||||
*
|
||||
* @param productAttrKeyId 商品规格键编号
|
||||
* @return 商品规格键
|
||||
*/
|
||||
public ProductAttrKeyRespDTO getProductAttrKey(Integer productAttrKeyId) {
|
||||
ProductAttrKeyBO productAttrKeyBO = productAttrService.getProductAttrKey(productAttrKeyId);
|
||||
return ProductAttrConvert.INSTANCE.convert(productAttrKeyBO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键列表
|
||||
*
|
||||
* @param productAttrKeyIds 商品规格键编号列表
|
||||
* @return 商品规格键列表
|
||||
*/
|
||||
public List<ProductAttrKeyRespDTO> listProductAttrKeys(List<Integer> productAttrKeyIds) {
|
||||
List<ProductAttrKeyBO> productAttrKeyBOs = productAttrService.listProductAttrKeys(productAttrKeyIds);
|
||||
return ProductAttrConvert.INSTANCE.convertList02(productAttrKeyBOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键分页
|
||||
*
|
||||
* @param pageDTO 商品规格键分页查询
|
||||
* @return 商品规格键分页结果
|
||||
*/
|
||||
public PageResult<ProductAttrKeyRespDTO> pageProductAttrKey(ProductAttrKeyPageReqDTO pageDTO) {
|
||||
PageResult<ProductAttrKeyBO> pageResultBO = productAttrService.pageProductAttrKey(ProductAttrConvert.INSTANCE.convert(pageDTO));
|
||||
return ProductAttrConvert.INSTANCE.convertPage(pageResultBO);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package cn.iocoder.mall.productservice.rpc.attr;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.manager.attr.ProductAttrManager;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyUpdateReqDTO;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 商品规格 Rpc 实现类
|
||||
*/
|
||||
@DubboService
|
||||
public class ProductAttrRpcImpl implements ProductAttrRpc {
|
||||
|
||||
@Autowired
|
||||
private ProductAttrManager productAttrManager;
|
||||
|
||||
@Override
|
||||
public CommonResult<Integer> createProductAttrKey(ProductAttrKeyCreateReqDTO createDTO) {
|
||||
return success(productAttrManager.createProductAttrKey(createDTO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> updateProductAttrKey(ProductAttrKeyUpdateReqDTO updateDTO) {
|
||||
productAttrManager.updateProductAttrKey(updateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> deleteProductAttrKey(Integer productAttrKeyId) {
|
||||
productAttrManager.deleteProductAttrKey(productAttrKeyId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<ProductAttrKeyRespDTO> getProductAttrKey(Integer productAttrKeyId) {
|
||||
return success(productAttrManager.getProductAttrKey(productAttrKeyId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<ProductAttrKeyRespDTO>> listProductAttrKeys(List<Integer> productAttrKeyIds) {
|
||||
return success(productAttrManager.listProductAttrKeys(productAttrKeyIds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<PageResult<ProductAttrKeyRespDTO>> pageProductAttrKey(ProductAttrKeyPageReqDTO pageDTO) {
|
||||
return success(productAttrManager.pageProductAttrKey(pageDTO));
|
||||
}
|
||||
|
||||
}
|
@ -7,7 +7,7 @@ import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandUpdateReqDTO;
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
@ -17,7 +17,7 @@ import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
/**
|
||||
* 商品品牌 Rpc 实现类
|
||||
*/
|
||||
@Service(version = "${dubbo.provider.ProductBrandRpc.version}")
|
||||
@DubboService
|
||||
public class ProductBrandRpcImpl implements ProductBrandRpc {
|
||||
|
||||
@Autowired
|
||||
|
@ -16,7 +16,7 @@ import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
/**
|
||||
* 商品分类 Rpc 实现类
|
||||
*/
|
||||
@DubboService(version = "${dubbo.provider.ProductCategoryRpc.version}")
|
||||
@DubboService
|
||||
public class ProductCategoryRpcImpl implements ProductCategoryRpc {
|
||||
|
||||
@Autowired
|
||||
|
@ -7,7 +7,7 @@ import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuAndSkuCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuAndSkuUpdateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
@ -17,7 +17,7 @@ import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
/**
|
||||
* 商品 SPU Rpc 实现类
|
||||
*/
|
||||
@Service(version = "${dubbo.provider.ProductSpuRpc.version}")
|
||||
@DubboService
|
||||
public class ProductSpuRpcImpl implements ProductSpuRpc {
|
||||
|
||||
@Autowired
|
||||
|
@ -3,23 +3,32 @@ package cn.iocoder.mall.productservice.service.attr;
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.util.CollectionUtils;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.convert.attr.ProductAttrConvert;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.attr.ProductAttrKeyDO;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.attr.ProductAttrValueDO;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.mapper.attr.ProductAttrKeyMapper;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.mapper.attr.ProductAttrValueMapper;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyValueBO;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.*;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.PRODUCT_ATTR_KEY_NOT_EXIST;
|
||||
import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.PRODUCT_ATTR_VALUE_NOT_EXIST;
|
||||
import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 商品规格 Service
|
||||
*
|
||||
* 包括商品键和值
|
||||
*/
|
||||
@Service
|
||||
@Valid
|
||||
public class ProductAttrService {
|
||||
|
||||
@Autowired
|
||||
@ -54,11 +63,97 @@ public class ProductAttrService {
|
||||
}
|
||||
}
|
||||
// 返回成功
|
||||
Map<Integer, ProductAttrKeyDO> attrKeyMap = CollectionUtils.convertMap(attrKeys, ProductAttrKeyDO::getId, attrKeyDO -> attrKeyDO); // ProductAttrDO 的映射,方便查找。
|
||||
Map<Integer, ProductAttrKeyDO> attrKeyMap = CollectionUtils.convertMap(attrKeys,
|
||||
ProductAttrKeyDO::getId, attrKeyDO -> attrKeyDO); // ProductAttrDO 的映射,方便查找。
|
||||
return attrValues.stream().map(attrValueDO -> new ProductAttrKeyValueBO()
|
||||
.setAttrKeyId(attrValueDO.getAttrId()).setAttrKeyName(attrKeyMap.get(attrValueDO.getAttrId()).getName())
|
||||
.setAttrValueId(attrValueDO.getId()).setAttrValueName(attrValueDO.getName()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建商品规格键
|
||||
*
|
||||
* @param createBO 创建商品规格键 BO
|
||||
* @return 商品规格键
|
||||
*/
|
||||
public ProductAttrKeyBO createProductAttrKey(@Valid ProductAttrKeyCreateBO createBO) {
|
||||
// 校验规格键的名字是否重复
|
||||
if (productAttrKeyMapper.selectByName(createBO.getName()) != null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_KEY_EXISTS);
|
||||
}
|
||||
// 插入到数据库
|
||||
ProductAttrKeyDO productAttrKeyDO = ProductAttrConvert.INSTANCE.convert(createBO);
|
||||
productAttrKeyMapper.insert(productAttrKeyDO);
|
||||
// 返回
|
||||
return ProductAttrConvert.INSTANCE.convert(productAttrKeyDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品规格键
|
||||
*
|
||||
* @param updateBO 更新商品规格键 BO
|
||||
*/
|
||||
public void updateProductAttrKey(@Valid ProductAttrKeyUpdateBO updateBO) {
|
||||
// 校验规格键的名字是否重复
|
||||
ProductAttrKeyDO attrKeyDOByName = productAttrKeyMapper.selectByName(updateBO.getName());
|
||||
if (attrKeyDOByName != null && !attrKeyDOByName.getId().equals(updateBO.getId())) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_KEY_EXISTS);
|
||||
}
|
||||
// 校验更新的商品规格键是否存在
|
||||
if (productAttrKeyMapper.selectById(updateBO.getId()) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_KEY_NOT_EXIST);
|
||||
}
|
||||
// 更新到数据库
|
||||
ProductAttrKeyDO updateObject = ProductAttrConvert.INSTANCE.convert(updateBO);
|
||||
productAttrKeyMapper.updateById(updateObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品规格键
|
||||
*
|
||||
* @param productAttrKeyId 商品规格键编号
|
||||
*/
|
||||
public void deleteProductAttrKey(Integer productAttrKeyId) {
|
||||
// 校验删除的商品规格键是否存在
|
||||
if (productAttrKeyMapper.selectById(productAttrKeyId) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_KEY_NOT_EXIST);
|
||||
}
|
||||
// 标记删除
|
||||
productAttrKeyMapper.deleteById(productAttrKeyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键
|
||||
*
|
||||
* @param productAttrKeyId 商品规格键编号
|
||||
* @return 商品规格键
|
||||
*/
|
||||
public ProductAttrKeyBO getProductAttrKey(Integer productAttrKeyId) {
|
||||
ProductAttrKeyDO productAttrKeyDO = productAttrKeyMapper.selectById(productAttrKeyId);
|
||||
return ProductAttrConvert.INSTANCE.convert(productAttrKeyDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键列表
|
||||
*
|
||||
* @param productAttrKeyIds 商品规格键编号列表
|
||||
* @return 商品规格键列表
|
||||
*/
|
||||
public List<ProductAttrKeyBO> listProductAttrKeys(List<Integer> productAttrKeyIds) {
|
||||
List<ProductAttrKeyDO> productAttrKeyDOs = productAttrKeyMapper.selectBatchIds(productAttrKeyIds);
|
||||
return ProductAttrConvert.INSTANCE.convertList(productAttrKeyDOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品规格键分页
|
||||
*
|
||||
* @param pageBO 商品规格键分页查询
|
||||
* @return 商品规格键分页结果
|
||||
*/
|
||||
public PageResult<ProductAttrKeyBO> pageProductAttrKey(ProductAttrKeyPageBO pageBO) {
|
||||
IPage<ProductAttrKeyDO> productAttrKeyDOPage = productAttrKeyMapper.selectPage(pageBO);
|
||||
return ProductAttrConvert.INSTANCE.convertPage(productAttrKeyDOPage);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package cn.iocoder.mall.productservice.service.attr.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品规格键 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyBO {
|
||||
|
||||
/**
|
||||
* 规格键编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 规格键名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package cn.iocoder.mall.productservice.service.attr.bo;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 商品规格键创建 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyCreateBO {
|
||||
|
||||
/**
|
||||
* 规格键名称
|
||||
*/
|
||||
@NotEmpty(message = "规格键名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.mall.productservice.service.attr.bo;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品规格键分页 BO
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyPageBO extends PageParam {
|
||||
|
||||
/**
|
||||
* 规格键名称,模糊匹配
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package cn.iocoder.mall.productservice.service.attr.bo;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 商品规格键更新 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrKeyUpdateBO {
|
||||
|
||||
/**
|
||||
* 规格键编号
|
||||
*/
|
||||
@NotNull(message = "规格键编号不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 规格键名称
|
||||
*/
|
||||
@NotEmpty(message = "规格键名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
@ -34,12 +34,7 @@ dubbo:
|
||||
provider:
|
||||
filter: -exception
|
||||
validation: true # 开启 Provider 参数校验
|
||||
ProductCategoryRpc:
|
||||
version: 1.0.0
|
||||
ProductBrandRpc:
|
||||
version: 1.0.0
|
||||
ProductSpuRpc:
|
||||
version: 1.0.0
|
||||
version: 1.0.0 # 服务的版本号
|
||||
# Dubbo 服务消费者的配置
|
||||
consumer:
|
||||
ErrorCodeRpc:
|
||||
|
@ -0,0 +1,93 @@
|
||||
package cn.iocoder.mall.product.rest.controller.brand;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.product.biz.bo.brand.ProductBrandBO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandAddDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandPageDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandUpdateDTO;
|
||||
import cn.iocoder.mall.product.biz.service.brand.ProductBrandService;
|
||||
import cn.iocoder.mall.product.rest.convert.brand.ProductBrandConvert;
|
||||
import cn.iocoder.mall.product.rest.request.brand.ProductBrandAddRequest;
|
||||
import cn.iocoder.mall.product.rest.request.brand.ProductBrandPageRequest;
|
||||
import cn.iocoder.mall.product.rest.request.brand.ProductBrandUpdateRequest;
|
||||
import cn.iocoder.mall.product.rest.response.brand.AdminsProductBrandResponse;
|
||||
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("admins/brand")
|
||||
@Api("管理员 - 商品品牌 API")
|
||||
@AllArgsConstructor
|
||||
public class AdminsProductBrandController {
|
||||
|
||||
private final ProductBrandService productBrandService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("创建品牌")
|
||||
public CommonResult<AdminsProductBrandResponse> add(@Validated ProductBrandAddRequest addRequest) {
|
||||
// 创建 ProductBrandAddDTO 对象
|
||||
ProductBrandAddDTO productBrandAddDTO = ProductBrandConvert.INSTANCE.convertAdd(addRequest);
|
||||
// 保存品牌
|
||||
ProductBrandBO result = productBrandService.addProductBrand(AdminSecurityContextHolder.getContext().getAdminId(), productBrandAddDTO);
|
||||
// 返回结果
|
||||
return success(ProductBrandConvert.INSTANCE.convert(result));
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("更新商品")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "品牌主键", required = true, example = "1"),
|
||||
@ApiImplicitParam(name = "name", value = "品牌名称", required = true, example = "安踏"),
|
||||
@ApiImplicitParam(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋"),
|
||||
@ApiImplicitParam(name = "picUrl", value = "品牌图片", required = true, example = "http://www.iocoder.cn"),
|
||||
@ApiImplicitParam(name = "status", value = "状态 1开启 2禁用", required = true, example = "1")
|
||||
})
|
||||
// TODO FROM 芋艿 to q2118cs:只要改成了 bean 接收,就不用在写 @ApiImplicitParam 注解啦,直接在 bean 里写就 ok 啦
|
||||
public CommonResult<Boolean> update(@Validated ProductBrandUpdateRequest updateRequest) {
|
||||
// 创建 productBrandUpdateDTO 对象
|
||||
ProductBrandUpdateDTO productBrandUpdateDTO = ProductBrandConvert.INSTANCE.convertUpdate(updateRequest);
|
||||
// 更新商品
|
||||
return success(productBrandService.updateProductBrand(AdminSecurityContextHolder.getContext().getAdminId(), productBrandUpdateDTO));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获取品牌")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "品牌主键", required = true, example = "1")
|
||||
})
|
||||
public CommonResult<AdminsProductBrandResponse> add(@RequestParam("id") Integer id) {
|
||||
// 保存商品
|
||||
ProductBrandBO result = productBrandService.getProductBrand(id);
|
||||
// 返回结果
|
||||
return success(ProductBrandConvert.INSTANCE.convert(result));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得品牌分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "name", value = "品牌名称", required = true, example = "安踏"),
|
||||
@ApiImplicitParam(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋"),
|
||||
@ApiImplicitParam(name = "status", value = "状态 1开启 2禁用", required = true, example = "1"),
|
||||
@ApiImplicitParam(name = "pageNo", value = "页码", required = true, example = "1"),
|
||||
@ApiImplicitParam(name = "pageSize", value = "页面大小", required = true, example = "10")
|
||||
})
|
||||
public CommonResult<PageResult<AdminsProductBrandResponse>> attrPage(ProductBrandPageRequest pageRequest) {
|
||||
// 创建 ProductBrandPageDTO 对象
|
||||
ProductBrandPageDTO productBrandPageDTO = ProductBrandConvert.INSTANCE.convertPageRequest(pageRequest);
|
||||
// 查询分页
|
||||
PageResult<ProductBrandBO> productBrandPage = productBrandService.getProductBrandPage(productBrandPageDTO);
|
||||
PageResult<AdminsProductBrandResponse> adminPageResponse = ProductBrandConvert.INSTANCE.convertPage(productBrandPage);
|
||||
return CommonResult.success(adminPageResponse);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -23,13 +23,6 @@ public interface ProductAttrService {
|
||||
*/
|
||||
List<ProductAttrSimpleBO> getProductAttrList();
|
||||
|
||||
ProductAttrBO addProductAttr(Integer adminId, ProductAttrAddDTO productAttrAddDTO);
|
||||
|
||||
Boolean updateProductAttr(Integer adminId, ProductAttrUpdateDTO productAttrUpdateDTO);
|
||||
|
||||
Boolean updateProductAttrStatus(Integer adminId, Integer productAttrId,
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status);
|
||||
|
||||
ProductAttrValueBO addProductAttrValue(Integer adminId, ProductAttrValueAddDTO productAttrValueAddDTO);
|
||||
|
||||
Boolean updateProductAttrValue(Integer adminId, ProductAttrValueUpdateDTO productAttrValueUpdateDTO);
|
||||
|
@ -74,58 +74,6 @@ public class ProductAttrServiceImpl implements ProductAttrService {
|
||||
return attrs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductAttrBO addProductAttr(Integer adminId, ProductAttrAddDTO productAttrAddDTO) {
|
||||
// 校验规格名不重复
|
||||
if (productAttrMapper.selectByName(productAttrAddDTO.getName()) != null) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_EXISTS.getCode());
|
||||
}
|
||||
// 插入到数据库
|
||||
ProductAttrDO productAttrDO = ProductAttrConvert.INSTANCE.convert(productAttrAddDTO)
|
||||
.setStatus(ProductAttrConstants.ATTR_STATUS_ENABLE);
|
||||
productAttrDO.setCreateTime(new Date());
|
||||
productAttrDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
|
||||
productAttrMapper.insert(productAttrDO);
|
||||
// 返回成功
|
||||
return ProductAttrConvert.INSTANCE.convert(productAttrDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateProductAttr(Integer adminId, ProductAttrUpdateDTO productAttrUpdateDTO) {
|
||||
// 校验存在
|
||||
if (productAttrMapper.selectById(productAttrUpdateDTO.getId()) == null) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_NOT_EXIST.getCode());
|
||||
}
|
||||
// 校验规格名不重复
|
||||
ProductAttrDO existsAttrDO = productAttrMapper.selectByName(productAttrUpdateDTO.getName());
|
||||
if (existsAttrDO != null && !existsAttrDO.getId().equals(productAttrUpdateDTO.getId())) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_EXISTS.getCode());
|
||||
}
|
||||
// 更新到数据库
|
||||
ProductAttrDO updateProductAttr = ProductAttrConvert.INSTANCE.convert(productAttrUpdateDTO);
|
||||
productAttrMapper.update(updateProductAttr);
|
||||
// 返回成功
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateProductAttrStatus(Integer adminId, Integer productAttrId, Integer status) {
|
||||
// 校验存在
|
||||
ProductAttrDO productAttrDO = productAttrMapper.selectById(productAttrId);
|
||||
if (productAttrDO == null) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_NOT_EXIST.getCode());
|
||||
}
|
||||
// 校验状态
|
||||
if (productAttrDO.getStatus().equals(status)) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_STATUS_EQUALS.getCode());
|
||||
}
|
||||
// 更新到数据库
|
||||
ProductAttrDO updateProductAttr = new ProductAttrDO().setId(productAttrId).setStatus(status);
|
||||
productAttrMapper.update(updateProductAttr);
|
||||
// 返回成功
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductAttrValueBO addProductAttrValue(Integer adminId, ProductAttrValueAddDTO productAttrValueAddDTO) {
|
||||
// 校验规格名不重复
|
||||
|
@ -29,66 +29,6 @@ import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
@Api("商品 SPU + SKU")
|
||||
public class AdminsProductSpuController {
|
||||
|
||||
@Reference(validation = "true", version = "${dubbo.provider.ProductSpuService.version}")
|
||||
private ProductSpuService productSpuService;
|
||||
|
||||
@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,
|
||||
@RequestParam("cid") Integer cid,
|
||||
@RequestParam("picUrls") List<String> picUrls,
|
||||
@RequestParam("visible") Boolean visible,
|
||||
@RequestParam("skuStr") String skuStr) { // TODO 芋艿,因为考虑不使用 json 接受参数,所以这里手动转。
|
||||
// 创建 ProductSpuAddDTO 对象
|
||||
ProductSpuAddDTO productSpuAddDTO = new ProductSpuAddDTO().setName(name).setSellPoint(sellPoint)
|
||||
.setDescription(description).setCid(cid).setPicUrls(picUrls).setVisible(visible)
|
||||
.setSkus(parseSkus(skuStr, ProductSkuAddOrUpdateDTO.class));
|
||||
// 保存商品
|
||||
ProductSpuDetailBO result = productSpuService.addProductSpu(AdminSecurityContextHolder.getContext().getAdminId(), productSpuAddDTO);
|
||||
// 返回结果
|
||||
return success(ProductSpuConvert.INSTANCE.convert(result));
|
||||
}
|
||||
|
||||
@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,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam("cid") Integer cid,
|
||||
@RequestParam("picUrls") List<String> picUrls,
|
||||
@RequestParam("visible") Boolean visible,
|
||||
@RequestParam("skuStr") String skuStr) { // TODO 芋艿,因为考虑不使用 json 接受参数,所以这里手动转。
|
||||
// 创建 ProductSpuUpdateDTO 对象
|
||||
ProductSpuUpdateDTO productSpuUpdateDTO = new ProductSpuUpdateDTO().setId(id).setName(name).setSellPoint(sellPoint)
|
||||
.setDescription(description).setCid(cid).setPicUrls(picUrls).setVisible(visible)
|
||||
.setSkus(parseSkus(skuStr, ProductSkuAddOrUpdateDTO.class));
|
||||
// 更新商品
|
||||
productSpuService.updateProductSpu(AdminSecurityContextHolder.getContext().getAdminId(), productSpuUpdateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/spu/update_sort")
|
||||
@ApiOperation("更新商品的排序")
|
||||
public CommonResult<Boolean> updateSort(@RequestParam("id") Integer id,
|
||||
@ -96,39 +36,6 @@ public class AdminsProductSpuController {
|
||||
return success(productSpuService.updateProductSpuSort(AdminSecurityContextHolder.getContext().getAdminId(), id, sort));
|
||||
}
|
||||
|
||||
// TODO 芋艿,删除功能暂时不做。主要原因是,关联的数据太多。删除带来的问题会比较大
|
||||
|
||||
@GetMapping("/spu/page")
|
||||
@ApiOperation("商品 SPU 分页列表")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "name", value = "商品名称,模糊匹配", example = "小王"),
|
||||
@ApiImplicitParam(name = "status", value = "状态", example = "可选值:1-在售中;2-已售罄;3-仓库中;"),
|
||||
@ApiImplicitParam(name = "cid", value = "商品分类编号", example = "10"),
|
||||
@ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"),
|
||||
@ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"),
|
||||
})
|
||||
public CommonResult<AdminsProductSpuPageVO> spuPage(@RequestParam(value = "name", required = false) String name,
|
||||
@RequestParam(value = "status") Integer status,
|
||||
@RequestParam(value = "cid", required = false) Integer cid,
|
||||
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||
// 创建 ProductSpuPageDTO 对象
|
||||
ProductSpuPageDTO productSpuPageDTO = new ProductSpuPageDTO().setName(name).setCid(cid).setPageNo(pageNo).setPageSize(pageSize);
|
||||
switch (status) {
|
||||
case 1:
|
||||
productSpuPageDTO.setVisible(true).setHasQuantity(true);
|
||||
break;
|
||||
case 2:
|
||||
productSpuPageDTO.setVisible(true).setHasQuantity(false);
|
||||
break;
|
||||
case 3:
|
||||
productSpuPageDTO.setVisible(false);
|
||||
break;
|
||||
}
|
||||
ProductSpuPageBO result = productSpuService.getProductSpuPage(productSpuPageDTO);
|
||||
return success(ProductSpuConvert.INSTANCE.convert2(result));
|
||||
}
|
||||
|
||||
@GetMapping("/spu/search_list")
|
||||
@ApiOperation("商品 SPU 搜索列表")
|
||||
@ApiImplicitParams({
|
||||
|
Loading…
Reference in New Issue
Block a user