商品规格 value 的迁移

pull/4/MERGE
YunaiV 2020-07-28 23:58:09 +08:00
parent 7dbbd412d8
commit 90047c10d7
24 changed files with 630 additions and 185 deletions

View File

@ -2,10 +2,7 @@ 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.controller.product.vo.attr.*;
import cn.iocoder.mall.managementweb.manager.product.ProductAttrKeyManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@ -24,7 +21,7 @@ import static cn.iocoder.common.framework.vo.CommonResult.success;
*/
@RestController
@RequestMapping("/product-attr/")
@Api(tags = "商品规格")
@Api(tags = "商品规格")
@Validated
public class ProductAttrController {
@ -64,4 +61,31 @@ public class ProductAttrController {
return success(productAttrKeyManager.pageProductAttrKey(pageVO));
}
@PostMapping("/value/create")
@ApiOperation("创建商品规格值")
public CommonResult<Integer> createProductAttrValue(@Valid ProductAttrValueCreateReqVO createVO) {
return success(productAttrKeyManager.createProductAttrValue(createVO));
}
@PostMapping("/value/update")
@ApiOperation("更新商品规格值")
public CommonResult<Boolean> updateProductAttrValue(@Valid ProductAttrValueUpdateReqVO updateVO) {
productAttrKeyManager.updateProductAttrValue(updateVO);
return success(true);
}
@GetMapping("/value/get")
@ApiOperation("获得商品规格值")
@ApiImplicitParam(name = "productAttrValueId", value = "商品规格值编号", required = true)
public CommonResult<ProductAttrValueRespVO> getProductAttrValue(@RequestParam("productAttrValueId") Integer productAttrValueId) {
return success(productAttrKeyManager.getProductAttrValue(productAttrValueId));
}
@GetMapping("/value/list")
@ApiOperation("获得商品规格值列表")
@ApiImplicitParam(name = "productAttrValueIds", value = "商品规格值编号列表", required = true)
public CommonResult<List<ProductAttrValueRespVO>> listProductAttrValues(@RequestParam("productAttrValueIds") List<Integer> productAttrValueIds) {
return success(productAttrKeyManager.listProductAttrValues(productAttrValueIds));
}
}

View File

@ -0,0 +1,28 @@
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 ProductAttrValueCreateReqVO {
@ApiModelProperty(value = "规格键编号", required = true, example = "2")
@NotNull(message = "规格键编号不能为空")
private Integer attrKeyId;
@ApiModelProperty(value = "规格值名字", required = true, example = "XXL")
@NotEmpty(message = "规格值名字不能为空")
private String name;
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举")
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
}

View File

@ -0,0 +1,22 @@
package cn.iocoder.mall.managementweb.controller.product.vo.attr;
import lombok.*;
import io.swagger.annotations.*;
import java.util.*;
@ApiModel("商品规格值 Response VO")
@Data
public class ProductAttrValueRespVO {
@ApiModelProperty(value = "规格值编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "规格键编号", required = true, example = "2")
private Integer attrKeyId;
@ApiModelProperty(value = "规格值名字", required = true, example = "XXL")
private String name;
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举")
private Integer status;
@ApiModelProperty(value = "创建时间", required = true)
private Date createTime;
}

View File

@ -0,0 +1,28 @@
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 ProductAttrValueUpdateReqVO {
@ApiModelProperty(value = "规格值编号", required = true, example = "1")
@NotNull(message = "规格值编号不能为空")
private Integer id;
@ApiModelProperty(value = "规格值名字", required = true, example = "XXL")
@NotEmpty(message = "规格值名字不能为空")
private String name;
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举")
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
}

View File

@ -0,0 +1,37 @@
package cn.iocoder.mall.managementweb.convert.product;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.product.vo.attr.*;
import cn.iocoder.mall.productservice.rpc.attr.dto.*;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface ProductAttrConvert {
ProductAttrConvert INSTANCE = Mappers.getMapper(ProductAttrConvert.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);
ProductAttrValueCreateReqDTO convert(ProductAttrValueCreateReqVO bean);
ProductAttrValueUpdateReqDTO convert(ProductAttrValueUpdateReqVO bean);
ProductAttrValueRespVO convert(ProductAttrValueRespDTO bean);
List<ProductAttrValueRespVO> convertList02(List<ProductAttrValueRespDTO> list);
}

View File

@ -1,34 +0,0 @@
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);
}

View File

@ -2,13 +2,11 @@ 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.managementweb.controller.product.vo.attr.*;
import cn.iocoder.mall.managementweb.convert.product.ProductAttrConvert;
import cn.iocoder.mall.productservice.rpc.attr.ProductAttrRpc;
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyRespDTO;
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrValueRespDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
@ -31,7 +29,7 @@ public class ProductAttrKeyManager {
*/
public Integer createProductAttrKey(ProductAttrKeyCreateReqVO createVO) {
CommonResult<Integer> createProductAttrKeyResult = productAttrKeyRpc.createProductAttrKey(
ProductAttrKeyConvert.INSTANCE.convert(createVO));
ProductAttrConvert.INSTANCE.convert(createVO));
createProductAttrKeyResult.checkError();
return createProductAttrKeyResult.getData();
}
@ -43,20 +41,10 @@ public class ProductAttrKeyManager {
*/
public void updateProductAttrKey(ProductAttrKeyUpdateReqVO updateVO) {
CommonResult<Boolean> updateProductAttrKeyResult = productAttrKeyRpc.updateProductAttrKey(
ProductAttrKeyConvert.INSTANCE.convert(updateVO));
ProductAttrConvert.INSTANCE.convert(updateVO));
updateProductAttrKeyResult.checkError();
}
/**
*
*
* @param productAttrKeyId
*/
public void deleteProductAttrKey(Integer productAttrKeyId) {
CommonResult<Boolean> deleteProductAttrKeyResult = productAttrKeyRpc.deleteProductAttrKey(productAttrKeyId);
deleteProductAttrKeyResult.checkError();
}
/**
*
*
@ -66,7 +54,7 @@ public class ProductAttrKeyManager {
public ProductAttrKeyRespVO getProductAttrKey(Integer productAttrKeyId) {
CommonResult<ProductAttrKeyRespDTO> getProductAttrKeyResult = productAttrKeyRpc.getProductAttrKey(productAttrKeyId);
getProductAttrKeyResult.checkError();
return ProductAttrKeyConvert.INSTANCE.convert(getProductAttrKeyResult.getData());
return ProductAttrConvert.INSTANCE.convert(getProductAttrKeyResult.getData());
}
/**
@ -78,7 +66,7 @@ public class ProductAttrKeyManager {
public List<ProductAttrKeyRespVO> listProductAttrKeys(List<Integer> productAttrKeyIds) {
CommonResult<List<ProductAttrKeyRespDTO>> listProductAttrKeyResult = productAttrKeyRpc.listProductAttrKeys(productAttrKeyIds);
listProductAttrKeyResult.checkError();
return ProductAttrKeyConvert.INSTANCE.convertList(listProductAttrKeyResult.getData());
return ProductAttrConvert.INSTANCE.convertList(listProductAttrKeyResult.getData());
}
/**
@ -89,9 +77,57 @@ public class ProductAttrKeyManager {
*/
public PageResult<ProductAttrKeyRespVO> pageProductAttrKey(ProductAttrKeyPageReqVO pageVO) {
CommonResult<PageResult<ProductAttrKeyRespDTO>> pageProductAttrKeyResult = productAttrKeyRpc.pageProductAttrKey(
ProductAttrKeyConvert.INSTANCE.convert(pageVO));
ProductAttrConvert.INSTANCE.convert(pageVO));
pageProductAttrKeyResult.checkError();
return ProductAttrKeyConvert.INSTANCE.convertPage(pageProductAttrKeyResult.getData());
return ProductAttrConvert.INSTANCE.convertPage(pageProductAttrKeyResult.getData());
}
/**
*
*
* @param createVO VO
* @return
*/
public Integer createProductAttrValue(ProductAttrValueCreateReqVO createVO) {
CommonResult<Integer> createProductAttrValueResult = productAttrKeyRpc.createProductAttrValue(
ProductAttrConvert.INSTANCE.convert(createVO));
createProductAttrValueResult.checkError();
return createProductAttrValueResult.getData();
}
/**
*
*
* @param updateVO VO
*/
public void updateProductAttrValue(ProductAttrValueUpdateReqVO updateVO) {
CommonResult<Boolean> updateProductAttrValueResult = productAttrKeyRpc.updateProductAttrValue(
ProductAttrConvert.INSTANCE.convert(updateVO));
updateProductAttrValueResult.checkError();
}
/**
*
*
* @param productAttrValueId
* @return
*/
public ProductAttrValueRespVO getProductAttrValue(Integer productAttrValueId) {
CommonResult<ProductAttrValueRespDTO> getProductAttrValueResult = productAttrKeyRpc.getProductAttrValue(productAttrValueId);
getProductAttrValueResult.checkError();
return ProductAttrConvert.INSTANCE.convert(getProductAttrValueResult.getData());
}
/**
*
*
* @param productAttrValueIds
* @return
*/
public List<ProductAttrValueRespVO> listProductAttrValues(List<Integer> productAttrValueIds) {
CommonResult<List<ProductAttrValueRespDTO>> listProductAttrValueResult = productAttrKeyRpc.listProductAttrValues(productAttrValueIds);
listProductAttrValueResult.checkError();
return ProductAttrConvert.INSTANCE.convertList02(listProductAttrValueResult.getData());
}
}

View File

@ -2,10 +2,7 @@ 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 cn.iocoder.mall.productservice.rpc.attr.dto.*;
import java.util.List;
@ -29,13 +26,6 @@ public interface ProductAttrRpc {
*/
CommonResult<Boolean> updateProductAttrKey(ProductAttrKeyUpdateReqDTO updateDTO);
/**
*
*
* @param productAttrKeyId
*/
CommonResult<Boolean> deleteProductAttrKey(Integer productAttrKeyId);
/**
*
*
@ -60,4 +50,35 @@ public interface ProductAttrRpc {
*/
CommonResult<PageResult<ProductAttrKeyRespDTO>> pageProductAttrKey(ProductAttrKeyPageReqDTO pageDTO);
/**
*
*
* @param createDTO DTO
* @return
*/
CommonResult<Integer> createProductAttrValue(ProductAttrValueCreateReqDTO createDTO);
/**
*
*
* @param updateDTO DTO
*/
CommonResult<Boolean> updateProductAttrValue(ProductAttrValueUpdateReqDTO updateDTO);
/**
*
*
* @param productAttrValueId
* @return
*/
CommonResult<ProductAttrValueRespDTO> getProductAttrValue(Integer productAttrValueId);
/**
*
*
* @param productAttrValueIds
* @return
*/
CommonResult<List<ProductAttrValueRespDTO>> listProductAttrValues(List<Integer> productAttrValueIds);
}

View File

@ -1,5 +1,7 @@
package cn.iocoder.mall.productservice.rpc.attr.dto;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.validator.InEnum;
import lombok.Data;
import lombok.experimental.Accessors;
@ -23,6 +25,7 @@ public class ProductAttrKeyCreateReqDTO implements Serializable {
*
*/
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
}

View File

@ -1,5 +1,7 @@
package cn.iocoder.mall.productservice.rpc.attr.dto;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.validator.InEnum;
import lombok.Data;
import lombok.experimental.Accessors;
@ -28,6 +30,7 @@ public class ProductAttrKeyUpdateReqDTO implements Serializable {
*
*/
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
}

View File

@ -0,0 +1,36 @@
package cn.iocoder.mall.productservice.rpc.attr.dto;
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;
import java.io.Serializable;
/**
* Request DTO
*/
@Data
@Accessors(chain = true)
public class ProductAttrValueCreateReqDTO implements Serializable {
/**
*
*/
@NotNull(message = "规格键编号不能为空")
private Integer attrKeyId;
/**
*
*/
@NotEmpty(message = "规格值名字不能为空")
private String name;
/**
*
*/
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
}

View File

@ -0,0 +1,37 @@
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 ProductAttrValueRespDTO implements Serializable {
/**
*
*/
private Integer id;
/**
*
*/
private Integer attrKeyId;
/**
*
*/
private String name;
/**
*
*/
private Integer status;
/**
*
*/
private Date createTime;
}

View File

@ -0,0 +1,44 @@
package cn.iocoder.mall.productservice.rpc.attr.dto;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.validator.InEnum;
import lombok.*;
import lombok.experimental.*;
import io.swagger.annotations.*;
import java.util.*;
import java.io.Serializable;
import javax.validation.constraints.*;
/**
* Request DTO
*/
@Data
@Accessors(chain = true)
public class ProductAttrValueUpdateReqDTO implements Serializable {
/**
*
*/
@NotNull(message = "规格值编号不能为空")
private Integer id;
/**
*
*/
@NotNull(message = "规格键编号不能为空")
private Integer attrKeyId;
/**
*
*/
@NotEmpty(message = "规格值名字不能为空")
private String name;
/**
*
*/
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
}

View File

@ -2,14 +2,9 @@ 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 cn.iocoder.mall.productservice.dal.mysql.dataobject.attr.ProductAttrValueDO;
import cn.iocoder.mall.productservice.rpc.attr.dto.*;
import cn.iocoder.mall.productservice.service.attr.bo.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -43,4 +38,20 @@ public interface ProductAttrConvert {
PageResult<ProductAttrKeyRespDTO> convertPage(PageResult<ProductAttrKeyBO> page);
ProductAttrValueDO convert(ProductAttrValueCreateBO bean);
ProductAttrValueBO convert(ProductAttrValueDO bean);
ProductAttrValueDO convert(ProductAttrValueUpdateBO bean);
List<ProductAttrValueBO> convertList03(List<ProductAttrValueDO> list);
ProductAttrValueCreateBO convert(ProductAttrValueCreateReqDTO bean);
ProductAttrValueUpdateBO convert(ProductAttrValueUpdateReqDTO bean);
ProductAttrValueRespDTO convert(ProductAttrValueBO bean);
List<ProductAttrValueRespDTO> convertList04(List<ProductAttrValueBO> list);
}

View File

@ -21,11 +21,13 @@ public class ProductAttrValueDO extends DeletableDO {
*/
private Integer id;
/**
*
*
*
* {@link ProductAttrKeyDO#getId()}
*/
private Integer attrId;
private Integer attrKeyId;
/**
*
*
*/
private String name;
/**

View File

@ -1,11 +1,15 @@
package cn.iocoder.mall.productservice.dal.mysql.mapper.attr;
import cn.iocoder.mall.productservice.dal.mysql.dataobject.attr.ProductAttrValueDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
@Repository
public interface ProductAttrValueMapper extends BaseMapper<ProductAttrValueDO> {
default ProductAttrValueDO selectByAttrKeyIdAndName(Integer attrKeyId, String name) {
return selectOne(new QueryWrapper<ProductAttrValueDO>().eq("attrKeyId", attrKeyId).eq("name", name));
}
}

View File

@ -2,12 +2,10 @@ 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.rpc.attr.dto.*;
import cn.iocoder.mall.productservice.service.attr.ProductAttrService;
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyBO;
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrValueBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -42,15 +40,6 @@ public class ProductAttrManager {
productAttrService.updateProductAttrKey(ProductAttrConvert.INSTANCE.convert(updateDTO));
}
/**
*
*
* @param productAttrKeyId
*/
public void deleteProductAttrKey(Integer productAttrKeyId) {
productAttrService.deleteProductAttrKey(productAttrKeyId);
}
/**
*
*
@ -84,4 +73,46 @@ public class ProductAttrManager {
return ProductAttrConvert.INSTANCE.convertPage(pageResultBO);
}
/**
*
*
* @param createDTO DTO
* @return
*/
public Integer createProductAttrValue(ProductAttrValueCreateReqDTO createDTO) {
ProductAttrValueBO productAttrValueBO = productAttrService.createProductAttrValue(ProductAttrConvert.INSTANCE.convert(createDTO));
return productAttrValueBO.getId();
}
/**
*
*
* @param updateDTO DTO
*/
public void updateProductAttrValue(ProductAttrValueUpdateReqDTO updateDTO) {
productAttrService.updateProductAttrValue(ProductAttrConvert.INSTANCE.convert(updateDTO));
}
/**
*
*
* @param productAttrValueId
* @return
*/
public ProductAttrValueRespDTO getProductAttrValue(Integer productAttrValueId) {
ProductAttrValueBO productAttrValueBO = productAttrService.getProductAttrValue(productAttrValueId);
return ProductAttrConvert.INSTANCE.convert(productAttrValueBO);
}
/**
*
*
* @param productAttrValueIds
* @return
*/
public List<ProductAttrValueRespDTO> listProductAttrValues(List<Integer> productAttrValueIds) {
List<ProductAttrValueBO> productAttrValueBOs = productAttrService.listProductAttrValues(productAttrValueIds);
return ProductAttrConvert.INSTANCE.convertList04(productAttrValueBOs);
}
}

View File

@ -3,10 +3,7 @@ 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 cn.iocoder.mall.productservice.rpc.attr.dto.*;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
@ -34,12 +31,6 @@ public class ProductAttrRpcImpl implements ProductAttrRpc {
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));
@ -55,4 +46,25 @@ public class ProductAttrRpcImpl implements ProductAttrRpc {
return success(productAttrManager.pageProductAttrKey(pageDTO));
}
@Override
public CommonResult<Integer> createProductAttrValue(ProductAttrValueCreateReqDTO createDTO) {
return success(productAttrManager.createProductAttrValue(createDTO));
}
@Override
public CommonResult<Boolean> updateProductAttrValue(ProductAttrValueUpdateReqDTO updateDTO) {
productAttrManager.updateProductAttrValue(updateDTO);
return success(true);
}
@Override
public CommonResult<ProductAttrValueRespDTO> getProductAttrValue(Integer productAttrValueId) {
return success(productAttrManager.getProductAttrValue(productAttrValueId));
}
@Override
public CommonResult<List<ProductAttrValueRespDTO>> listProductAttrValues(List<Integer> productAttrValueIds) {
return success(productAttrManager.listProductAttrValues(productAttrValueIds));
}
}

View File

@ -50,7 +50,7 @@ public class ProductAttrService {
}
}
// 然后,校验规 Key
Set<Integer> attrKeyIds = CollectionUtils.convertSet(attrValues, ProductAttrValueDO::getAttrId);
Set<Integer> attrKeyIds = CollectionUtils.convertSet(attrValues, ProductAttrValueDO::getAttrKeyId);
List<ProductAttrKeyDO> attrKeys = productAttrKeyMapper.selectBatchIds(attrKeyIds);
if (attrKeys.size() != attrKeyIds.size()) {
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_KEY_NOT_EXIST);
@ -66,7 +66,7 @@ public class ProductAttrService {
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())
.setAttrKeyId(attrValueDO.getAttrKeyId()).setAttrKeyName(attrKeyMap.get(attrValueDO.getAttrKeyId()).getName())
.setAttrValueId(attrValueDO.getId()).setAttrValueName(attrValueDO.getName()))
.collect(Collectors.toList());
}
@ -109,20 +109,6 @@ public class ProductAttrService {
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);
}
/**
*
*
@ -156,4 +142,70 @@ public class ProductAttrService {
return ProductAttrConvert.INSTANCE.convertPage(productAttrKeyDOPage);
}
/**
*
*
* @param createBO BO
* @return
*/
public ProductAttrValueBO createProductAttrValue(@Valid ProductAttrValueCreateBO createBO) {
// 校验规格键是否存在
if (productAttrKeyMapper.selectById(createBO.getAttrKeyId()) == null) {
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_KEY_NOT_EXIST);
}
// 校验规格值的名字是否重复
if (productAttrValueMapper.selectByAttrKeyIdAndName(createBO.getAttrKeyId(), createBO.getName()) != null) {
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_VALUE_EXISTS);
}
// 插入到数据库
ProductAttrValueDO productAttrValueDO = ProductAttrConvert.INSTANCE.convert(createBO);
productAttrValueMapper.insert(productAttrValueDO);
// 返回
return ProductAttrConvert.INSTANCE.convert(productAttrValueDO);
}
/**
*
*
* @param updateBO BO
*/
public void updateProductAttrValue(@Valid ProductAttrValueUpdateBO updateBO) {
// 校验更新的商品规格值是否存在
ProductAttrValueDO attrValueDO = productAttrValueMapper.selectById(updateBO.getId());
if (attrValueDO == null) {
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_VALUE_NOT_EXIST);
}
// 校验规格值的名字是否重复
ProductAttrValueDO attrValueDOByName = productAttrValueMapper.selectByAttrKeyIdAndName(
attrValueDO.getAttrKeyId(), updateBO.getName());
if (attrValueDOByName != null && !attrValueDOByName.getId().equals(updateBO.getId())) {
throw ServiceExceptionUtil.exception(PRODUCT_ATTR_VALUE_EXISTS);
}
// 更新到数据库
ProductAttrValueDO updateObject = ProductAttrConvert.INSTANCE.convert(updateBO);
productAttrValueMapper.updateById(updateObject);
}
/**
*
*
* @param productAttrValueId
* @return
*/
public ProductAttrValueBO getProductAttrValue(Integer productAttrValueId) {
ProductAttrValueDO productAttrValueDO = productAttrValueMapper.selectById(productAttrValueId);
return ProductAttrConvert.INSTANCE.convert(productAttrValueDO);
}
/**
*
*
* @param productAttrValueIds
* @return
*/
public List<ProductAttrValueBO> listProductAttrValues(List<Integer> productAttrValueIds) {
List<ProductAttrValueDO> productAttrValueDOs = productAttrValueMapper.selectBatchIds(productAttrValueIds);
return ProductAttrConvert.INSTANCE.convertList03(productAttrValueDOs);
}
}

View File

@ -0,0 +1,36 @@
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 ProductAttrValueBO {
/**
*
*/
private Integer id;
/**
*
*/
private Integer attrKeyId;
/**
*
*/
private String name;
/**
*
*/
private Integer status;
/**
*
*/
private Date createTime;
}

View File

@ -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 ProductAttrValueCreateBO {
/**
*
*/
@NotNull(message = "规格键编号不能为空")
private Integer attrKeyId;
/**
*
*/
@NotEmpty(message = "规格值名字不能为空")
private String name;
/**
*
*/
@NotNull(message = "状态")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
}

View File

@ -0,0 +1,41 @@
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 ProductAttrValueUpdateBO {
/**
*
*/
@NotNull(message = "规格值编号不能为空")
private Integer id;
/**
*
*/
@NotNull(message = "规格键编号不能为空")
private Integer attrKeyId;
/**
*
*/
@NotEmpty(message = "规格值名字不能为空")
private String name;
/**
*
*/
@NotNull(message = "状态")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
}

View File

@ -1,30 +0,0 @@
package cn.iocoder.mall.product.dataobject;
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* Product
*/
@Data
@Accessors(chain = true)
public class ProductAttrDO extends DeletableDO {
/**
*
*/
private Integer id;
/**
*
*/
private String name;
/**
*
*
* 1-
* 2-
*/
private Integer status;
}

View File

@ -1,34 +0,0 @@
package cn.iocoder.mall.product.dataobject;
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* Product
*/
@Data
@Accessors(chain = true)
public class ProductAttrValueDO extends DeletableDO {
/**
*
*/
private Integer id;
/**
*
*/
private Integer attrId;
/**
*
*/
private String name;
/**
*
*
* 1-
* 2-
*/
private Integer status;
}