Merge remote-tracking branch 'origin/master'

pull/2/MERGE
wuwenbin 2020-05-11 22:11:51 +08:00
commit cce62c43f4
118 changed files with 2166 additions and 472 deletions

View File

@ -35,6 +35,7 @@ public class OrderApplication {
* @return
*/
@Bean
// TODO FROM 芋艿 to 芋艿:这个不太了解,可能后续要放到 starter 里,统一处理。
public ConfigurableServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {

View File

@ -1,11 +1,12 @@
package cn.iocoder.mall.order.rest.request.users;
import java.io.Serializable;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
/**
*
*
@ -26,6 +27,8 @@ public class OrderReturnApplyRequest implements Serializable {
*
* - 1退退
* - 2退
*
* / TODO FROM to xiaofeng @InEnum 退
*/
@NotNull(message = "退货类型不能为空!")
private Integer returnType;

View File

@ -12,6 +12,7 @@
<artifactId>product</artifactId>
<name>product</name>
<packaging>pom</packaging>
<modules>
<module>product-application</module>
<module>product-rpc-api</module>

View File

@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>system</artifactId>
<artifactId>product</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

View File

@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>system</artifactId>
<artifactId>product</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

View File

@ -3,12 +3,12 @@ package cn.iocoder.mall.product.biz.bo.attr;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Data
@Accessors(chain = true)
public class ProductAttrBO {
public class ProductAttrBO implements Serializable {
/**
*
@ -26,8 +26,5 @@ public class ProductAttrBO {
*
*/
private Date createTime;
/**
*
*/
private List<ProductAttrValueBO> values;
}

View File

@ -0,0 +1,25 @@
package cn.iocoder.mall.product.biz.bo.attr;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* VO
*/
@Data
@Accessors(chain = true)
public class ProductAttrSimpleBO implements Serializable {
/**
*
*/
private Integer id;
/**
*
*/
private String name;
}

View File

@ -0,0 +1,18 @@
package cn.iocoder.mall.product.biz.bo.attr;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class ProductAttrSimpleWithValueBO extends ProductAttrSimpleBO {
/**
*
*/
private List<ProductAttrValueSimpleBO> values;
}

View File

@ -17,6 +17,10 @@ public class ProductAttrValueBO implements Serializable {
*
*/
private Integer id;
/**
*
*/
private Integer attrId;
/**
*
*/

View File

@ -0,0 +1,24 @@
package cn.iocoder.mall.product.biz.bo.attr;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* VO
*/
@Data
@Accessors(chain = true)
public class ProductAttrValueSimpleBO implements Serializable {
/**
*
*/
private Integer id;
/**
*
*/
private String name;
}

View File

@ -0,0 +1,18 @@
package cn.iocoder.mall.product.biz.bo.attr;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class ProductAttrWithValueBO extends ProductAttrBO {
/**
*
*/
private List<ProductAttrValueBO> values;
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.biz.bo.product;
package cn.iocoder.mall.product.biz.bo.brand;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -2,7 +2,7 @@ package cn.iocoder.mall.product.biz.bo.category;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
@ -12,7 +12,6 @@ import java.util.Date;
*/
@Data
@Accessors(chain = true)
// TODO FROM 芋艿 to 伟帆BO 可以不加 Serializable 接口,因为没序列化的诉求哈。一般 BO 可以创建一个统一的 ProductCategory可以把 ProductCategoryAllListBO 合并过来 [DONE]
public class ProductCategoryBO {
/**

View File

@ -1,5 +1,6 @@
package cn.iocoder.mall.product.biz.bo.product;
import cn.iocoder.mall.product.biz.bo.brand.ProductBrandBO;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,10 +1,12 @@
package cn.iocoder.mall.product.biz.convert.attr;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrValueBO;
import cn.iocoder.mall.product.biz.bo.attr.*;
import cn.iocoder.mall.product.biz.dataobject.product.ProductAttrDO;
import cn.iocoder.mall.product.biz.dataobject.product.ProductAttrValueDO;
import cn.iocoder.mall.product.biz.dto.attr.ProductAttrUpdateDTO;
import cn.iocoder.mall.product.biz.dto.attr.ProductAttrValueAddDTO;
import cn.iocoder.mall.product.biz.dto.attr.ProductAttrValueUpdateDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@ -19,8 +21,29 @@ public interface ProductAttrConvert {
ProductAttrConvert INSTANCE = Mappers.getMapper(ProductAttrConvert.class);
@Mapping(source = "records", target = "list")
PageResult<ProductAttrBO> convertPage(IPage<ProductAttrDO> bean);
PageResult<ProductAttrWithValueBO> convertPage(IPage<ProductAttrDO> bean);
@Mappings({})
List<ProductAttrValueBO> convertAttrValue(List<ProductAttrValueDO> values);
ProductAttrBO convertAttr(ProductAttrDO values);
@Mappings({})
ProductAttrValueBO convertAttrValue(ProductAttrValueDO productAttrValueDO);
@Mappings({})
List<ProductAttrValueBO> convertAttrValues(List<ProductAttrValueDO> values);
@Mappings({})
List<ProductAttrSimpleWithValueBO> convertAttrSimple(List<ProductAttrDO> attrs);
@Mappings({})
List<ProductAttrValueSimpleBO> convertAttrValueSimple(List<ProductAttrValueDO> values);
@Mappings({})
ProductAttrDO convertUpdate(ProductAttrUpdateDTO productAttrUpdateDTO);
@Mappings({})
ProductAttrValueDO convertValueAdd(ProductAttrValueAddDTO productAttrValueAddDTO);
@Mappings({})
ProductAttrValueDO convertValueUpdate(ProductAttrValueUpdateDTO productAttrValueUpdateDTO);
}

View File

@ -1,10 +1,13 @@
package cn.iocoder.mall.product.biz.convert.product;
package cn.iocoder.mall.product.biz.convert.brand;
import cn.iocoder.mall.product.biz.bo.product.ProductBrandBO;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.product.biz.bo.brand.ProductBrandBO;
import cn.iocoder.mall.product.biz.dataobject.product.ProductBrandDO;
import cn.iocoder.mall.product.biz.dto.product.ProductBrandAddDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductBrandUpdateDTO;
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandAddDTO;
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandUpdateDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@ -15,6 +18,9 @@ public interface ProductBrandConvert {
ProductBrandConvert INSTANCE = Mappers.getMapper(ProductBrandConvert.class);
@Mapping(source = "records", target = "list")
PageResult<ProductBrandBO> convertPage(IPage<ProductBrandDO> bean);
@Mappings({})
List<ProductBrandBO> convert(List<ProductBrandDO> brands);
@ -26,5 +32,4 @@ public interface ProductBrandConvert {
@Mappings({})
ProductBrandDO convert(ProductBrandAddDTO brand);
}

View File

@ -1,58 +0,0 @@
package cn.iocoder.mall.product.biz.convert.product;
import cn.iocoder.mall.product.biz.bo.product.*;
import cn.iocoder.mall.product.biz.dataobject.product.ProductAttrDO;
import cn.iocoder.mall.product.biz.dataobject.product.ProductAttrValueDO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrAddDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrUpdateDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrValueAddDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrValueUpdateDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface ProductAttrConvert2 {
ProductAttrConvert2 INSTANCE = Mappers.getMapper(ProductAttrConvert2.class);
@Mappings({})
List<ProductAttrDetailBO> convert(List<ProductAttrDO> attrs);
@Mappings({})
ProductAttrValueDetailBO convert(ProductAttrValueDO value);
@Mappings({})
List<ProductAttrValueDetailBO> convert2(List<ProductAttrValueDO> values);
@Mappings({})
List<ProductAttrSimpleBO> convert3(List<ProductAttrDO> attrs);
@Mappings({})
ProductAttrValueSimpleBO convert3(ProductAttrValueDO value); // 保证 convert4 能够映射到这个方法
@Mappings({})
List<ProductAttrValueSimpleBO> convert4(List<ProductAttrValueDO> values);
@Mappings({})
ProductAttrDO convert(ProductAttrAddDTO productAttrAddDTO);
@Mappings({})
ProductAttrDO convert(ProductAttrUpdateDTO productAttrUpdateDTO);
@Mappings({})
ProductAttrValueDO convert(ProductAttrValueAddDTO productAttrValueAddDTO);
@Mappings({})
ProductAttrValueDO convert(ProductAttrValueUpdateDTO productAttrValueUpdateDTO);
@Mappings({})
ProductAttrBO2 convert(ProductAttrDO productAttrDO);
@Mappings({})
ProductAttrValueBO convert2(ProductAttrValueDO productAttrValueDO);
}

View File

@ -130,6 +130,4 @@ public interface ProductSpuConvert {
return spuDetailList;
}
}

View File

@ -1,11 +1,25 @@
package cn.iocoder.mall.product.biz.dao.product;
import cn.iocoder.mall.product.biz.dataobject.product.ProductBrandDO;
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandPageDTO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
@Repository
public interface ProductBrandMapper extends BaseMapper<ProductBrandDO> {
default IPage<ProductBrandDO> selectPageByParams(ProductBrandPageDTO productBrandPageDTO) {
Page<ProductBrandDO> page = new Page<>(productBrandPageDTO.getPageNo(), productBrandPageDTO.getPageSize());
LambdaQueryWrapper<ProductBrandDO> queryWrapper = Wrappers.<ProductBrandDO>query().lambda()
.like(StringUtils.isNotBlank(productBrandPageDTO.getName()), ProductBrandDO::getName, productBrandPageDTO.getName())
.like(StringUtils.isNotBlank(productBrandPageDTO.getDescription()), ProductBrandDO::getName, productBrandPageDTO.getDescription())
.eq(null != productBrandPageDTO.getStatus(), ProductBrandDO::getName, productBrandPageDTO.getStatus())
.eq(ProductBrandDO::getDeleted, false);
return selectPage(page, queryWrapper);
}
}

View File

@ -1,10 +1,19 @@
package cn.iocoder.mall.product.biz.dao.product;
import cn.iocoder.mall.product.biz.dataobject.product.ProductBrandDO;
import cn.iocoder.mall.product.biz.dataobject.product.ProductSkuDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Repository;
@Repository
public interface ProductSkuMapper extends BaseMapper<ProductBrandDO> {
import java.util.List;
@Repository
public interface ProductSkuMapper extends BaseMapper<ProductSkuDO> {
default List<ProductSkuDO> selectListBySpuIdAndStatus(Integer spuId, Integer status) {
return selectList(Wrappers.<ProductSkuDO>query().lambda()
.eq(ProductSkuDO::getSpuId, spuId)
.eq(ProductSkuDO::getStatus, status)
.eq(ProductSkuDO::getDeleted, false));
}
}

View File

@ -1,11 +1,11 @@
package cn.iocoder.mall.product.biz.dao.product;
import cn.iocoder.mall.product.biz.dataobject.product.ProductBrandDO;
import cn.iocoder.mall.product.biz.dataobject.product.ProductSpuDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
@Repository
public interface ProductSpuMapper extends BaseMapper<ProductBrandDO> {
public interface ProductSpuMapper extends BaseMapper<ProductSpuDO> {
}

View File

@ -2,12 +2,14 @@ package cn.iocoder.mall.product.biz.dataobject.product;
import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* Product
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class ProductAttrValueDO extends DeletableDO {
@ -25,7 +27,7 @@ public class ProductAttrValueDO extends DeletableDO {
private String name;
/**
*
*
* <p>
* 1-
* 2-
*/

View File

@ -2,12 +2,14 @@ package cn.iocoder.mall.product.biz.dataobject.product;
import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* Product
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class ProductBrandDO extends DeletableDO {
@ -32,7 +34,7 @@ public class ProductBrandDO extends DeletableDO {
/**
*
*
* <p>
* 1-
* 2-
*/

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.biz.dto.product;
package cn.iocoder.mall.product.biz.dto.attr;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -11,7 +11,7 @@ import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
public class AdminProductAttrPageDTO extends PageParam {
public class ProductAttrPageDTO extends PageParam {
/**
*
*/

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.biz.dto.product;
package cn.iocoder.mall.product.biz.dto.attr;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.biz.dto.product;
package cn.iocoder.mall.product.biz.dto.attr;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.biz.dto.product;
package cn.iocoder.mall.product.biz.dto.attr;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.biz.dto.product;
package cn.iocoder.mall.product.biz.dto.brand;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,16 +1,17 @@
package cn.iocoder.mall.product.biz.dto.product;
package cn.iocoder.mall.product.biz.dto.brand;
import cn.iocoder.common.framework.vo.PageParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
/**
* DTO
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class ProductBrandPageDTO {
public class ProductBrandPageDTO extends PageParam {
/**
*
@ -27,10 +28,4 @@ public class ProductBrandPageDTO {
*/
private Integer status;
@NotNull(message = "页码不能为空")
private Integer pageNo;
@NotNull(message = "每页条数不能为空")
private Integer pageSize;
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.biz.dto.product;
package cn.iocoder.mall.product.biz.dto.brand;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -17,7 +17,6 @@ public class ProductCategoryAddDTO {
/**
* id
*/
// TODO FROM 芋艿 to 伟帆:传入 Service 的,要加下 Validation 的注解,虽然 Controller 那也添加了 Validation但是相比来说Service 更应该被保护嘿嘿。因为一些时候Service 也会被别人所调用,所以要保护好自己。[DONE]
@NotNull(message = "管理员id不能为空")
private Integer adminId;

View File

@ -1,22 +0,0 @@
package cn.iocoder.mall.product.biz.dto.product;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
/**
* DTO
*/
@Data
@Accessors(chain = true)
public class ProductAttrPageDTO {
private String name;
@NotNull(message = "页码不能为空")
private Integer pageNo;
@NotNull(message = "每页条数不能为空")
private Integer pageSize;
}

View File

@ -4,16 +4,14 @@ import cn.iocoder.common.framework.constant.CommonStatusEnum;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrBO;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrBO2;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrSimpleBO;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrValueBO;
import cn.iocoder.mall.product.biz.dto.attr.AdminProductAttrPageDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrAddDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrUpdateDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrValueAddDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrValueUpdateDTO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrSimpleWithValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrWithValueBO;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrAndValuePairBO;
import cn.iocoder.mall.product.biz.dto.attr.*;
import java.util.List;
import java.util.Set;
public interface ProductAttrService {
/**
@ -22,7 +20,7 @@ public interface ProductAttrService {
* @param productAttrPageDTO
* @return
*/
PageResult<ProductAttrBO> getProductAttrPage(AdminProductAttrPageDTO productAttrPageDTO);
PageResult<ProductAttrWithValueBO> getProductAttrPage(ProductAttrPageDTO productAttrPageDTO);
/**
*
@ -31,14 +29,35 @@ public interface ProductAttrService {
*
* @return
*/
List<ProductAttrSimpleBO> getProductAttrList();
List<ProductAttrSimpleWithValueBO> getProductAttrList();
ProductAttrBO2 addProductAttr(Integer adminId, ProductAttrAddDTO productAttrAddDTO);
/**
*
*
* @param adminId ID
* @param productAttrAddDTO
* @return
*/
ProductAttrBO addProductAttr(Integer adminId, ProductAttrAddDTO productAttrAddDTO);
/**
*
*
* @param adminId
* @param productAttrUpdateDTO
* @return
*/
Boolean updateProductAttr(Integer adminId, ProductAttrUpdateDTO productAttrUpdateDTO);
Boolean updateProductAttrStatus(Integer adminId, Integer productAttrId,
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status);
/**
*
*
* @param adminId
* @param productAttrId ID
* @param status
* @return
*/
Boolean updateProductAttrStatus(Integer adminId, Integer productAttrId, Integer status);
ProductAttrValueBO addProductAttrValue(Integer adminId, ProductAttrValueAddDTO productAttrValueAddDTO);
@ -47,4 +66,5 @@ public interface ProductAttrService {
Boolean updateProductAttrValueStatus(Integer adminId, Integer productAttrValueId,
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status);
List<ProductAttrAndValuePairBO> validProductAttrAndValue(Set<Integer> productAttrValueIds, boolean validStatus);
}

View File

@ -0,0 +1,45 @@
package cn.iocoder.mall.product.biz.service.product;
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;
public interface ProductBrandService {
/**
*
*
* @param productBrandPageDTO
* @return
*/
PageResult<ProductBrandBO> getProductBrandPage(ProductBrandPageDTO productBrandPageDTO);
/**
*
*
* @param id
* @return
*/
ProductBrandBO getProductBrand(Integer id);
/**
*
*
* @param productBrandAddDTO
* @return
*/
ProductBrandBO addProductBrand(Integer adminId, ProductBrandAddDTO productBrandAddDTO);
/**
*
*
* @param productBrandUpdateDTO
* @return
*/
Boolean updateProductBrand(Integer adminId, ProductBrandUpdateDTO productBrandUpdateDTO);
}

View File

@ -0,0 +1,15 @@
package cn.iocoder.mall.product.biz.service.product;
import cn.iocoder.mall.product.biz.bo.product.ProductSpuDetailBO;
public interface ProductSpuService {
/**
* SPU
*
* @param id spuId
* @return SPU
*/
ProductSpuDetailBO getProductSpuDetail(Integer id);
}

View File

@ -5,21 +5,16 @@ import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrSimpleWithValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrWithValueBO;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrAndValuePairBO;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrBO2;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrSimpleBO;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrValueBO;
import cn.iocoder.mall.product.biz.convert.attr.ProductAttrConvert;
import cn.iocoder.mall.product.biz.convert.product.ProductAttrConvert2;
import cn.iocoder.mall.product.biz.dao.product.ProductAttrMapper;
import cn.iocoder.mall.product.biz.dao.product.ProductAttrValueMapper;
import cn.iocoder.mall.product.biz.dataobject.product.ProductAttrDO;
import cn.iocoder.mall.product.biz.dataobject.product.ProductAttrValueDO;
import cn.iocoder.mall.product.biz.dto.attr.AdminProductAttrPageDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrAddDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrUpdateDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrValueAddDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrValueUpdateDTO;
import cn.iocoder.mall.product.biz.dto.attr.*;
import cn.iocoder.mall.product.biz.enums.ProductErrorCodeEnum;
import cn.iocoder.mall.product.biz.enums.product.ProductAttrConstants;
import cn.iocoder.mall.product.biz.service.product.ProductAttrService;
@ -27,8 +22,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Multimaps;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -51,14 +44,14 @@ public class ProductAttrServiceImpl implements ProductAttrService {
private ProductAttrValueMapper productAttrValueMapper;
@Override
public PageResult<ProductAttrBO> getProductAttrPage(AdminProductAttrPageDTO productAttrPageDTO) {
public PageResult<ProductAttrWithValueBO> getProductAttrPage(ProductAttrPageDTO productAttrPageDTO) {
//查询分页
Page<ProductAttrDO> page = new Page<>(productAttrPageDTO.getPageNo(), productAttrPageDTO.getPageSize());
LambdaQueryWrapper<ProductAttrDO> queryWrapper = Wrappers.<ProductAttrDO>query().lambda()
.like(StringUtils.isNotBlank(productAttrPageDTO.getName()), ProductAttrDO::getName, productAttrPageDTO.getName())
.eq(ProductAttrDO::getDeleted, false);
IPage<ProductAttrDO> attrPage = productAttrMapper.selectPage(page, queryWrapper);
PageResult<ProductAttrBO> productAttrPage = ProductAttrConvert.INSTANCE.convertPage(attrPage);
PageResult<ProductAttrWithValueBO> productAttrPage = ProductAttrConvert.INSTANCE.convertPage(attrPage);
// 将规格值拼接上去
if (!CollectionUtil.isEmpty(productAttrPage.getList())) {
Set<Integer> attrIds = productAttrPage.getList().stream().map(ProductAttrBO::getId).collect(Collectors.toSet());
@ -66,14 +59,152 @@ public class ProductAttrServiceImpl implements ProductAttrService {
.in(ProductAttrValueDO::getAttrId, attrIds)
.eq(ProductAttrValueDO::getDeleted, false));
Map<Integer, List<ProductAttrValueDO>> attrValueMap = attrValues.stream().collect(Collectors.groupingBy(ProductAttrValueDO::getAttrId));
for (ProductAttrBO productAttrBO : productAttrPage.getList()) {
productAttrBO.setValues(ProductAttrConvert.INSTANCE.convertAttrValue(attrValueMap.get(productAttrBO.getId())));
for (ProductAttrWithValueBO item : productAttrPage.getList()) {
item.setValues(ProductAttrConvert.INSTANCE.convertAttrValues(attrValueMap.get(item.getId())));
}
}
// 返回结果
return productAttrPage;
}
@Override
public List<ProductAttrSimpleWithValueBO> getProductAttrList() {
// 查询所有开启的规格数组
List<ProductAttrDO> attrDos = productAttrMapper.selectList(Wrappers.<ProductAttrDO>query().lambda()
.in(ProductAttrDO::getStatus, ProductAttrConstants.ATTR_STATUS_ENABLE)
.eq(ProductAttrDO::getDeleted, false));
// 如果为空,则返回空
if (attrDos.isEmpty()) {
return Collections.emptyList();
}
List<ProductAttrSimpleWithValueBO> attrs = ProductAttrConvert.INSTANCE.convertAttrSimple(attrDos);
// 将规格值拼接上去
List<ProductAttrValueDO> attrValues = productAttrValueMapper.selectList(Wrappers.<ProductAttrValueDO>query().lambda()
.in(ProductAttrValueDO::getStatus, ProductAttrConstants.ATTR_STATUS_ENABLE)
.eq(ProductAttrValueDO::getDeleted, false));
Map<Integer, List<ProductAttrValueDO>> attrValueMap = attrValues.stream().collect(Collectors.groupingBy(ProductAttrValueDO::getAttrId));
for (ProductAttrSimpleWithValueBO item : attrs) {
item.setValues(ProductAttrConvert.INSTANCE.convertAttrValueSimple(attrValueMap.get(item.getId())));
}
return attrs;
}
@Override
public ProductAttrBO addProductAttr(Integer adminId, ProductAttrAddDTO productAttrAddDTO) {
// 校验规格名不重复
int count = productAttrMapper.selectCount(Wrappers.<ProductAttrDO>query().lambda()
.eq(ProductAttrDO::getName, productAttrAddDTO.getName())
.eq(ProductAttrDO::getDeleted, false));
if (count > 0) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_EXISTS.getCode());
}
// 插入到数据库
ProductAttrDO productAttrDO = new ProductAttrDO().setName(productAttrAddDTO.getName())
.setStatus(ProductAttrConstants.ATTR_STATUS_ENABLE);
productAttrDO.setCreateTime(new Date());
productAttrDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
productAttrMapper.insert(productAttrDO);
// 返回成功
return ProductAttrConvert.INSTANCE.convertAttr(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.selectOne(Wrappers.<ProductAttrDO>query().lambda()
.eq(ProductAttrDO::getName, productAttrUpdateDTO.getName())
.eq(ProductAttrDO::getDeleted, false));
if (existsAttrDO != null && !existsAttrDO.getId().equals(productAttrUpdateDTO.getId())) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_EXISTS.getCode());
}
// 更新到数据库
ProductAttrDO updateProductAttr = ProductAttrConvert.INSTANCE.convertUpdate(productAttrUpdateDTO);
updateProductAttr.setUpdateTime(new Date());
int i = productAttrMapper.updateById(updateProductAttr);
// 返回成功
return i > 0;
}
@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);
int i = productAttrMapper.updateById(updateProductAttr);
return i > 0;
}
@Override
public ProductAttrValueBO addProductAttrValue(Integer adminId, ProductAttrValueAddDTO productAttrValueAddDTO) {
// 校验规格名不重复
int count = productAttrValueMapper.selectCount(Wrappers.<ProductAttrValueDO>query().lambda()
.eq(ProductAttrValueDO::getName, productAttrValueAddDTO.getName())
.eq(ProductAttrValueDO::getAttrId, productAttrValueAddDTO.getAttrId())
.eq(ProductAttrValueDO::getDeleted, false));
if (count > 0) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_EXISTS.getCode());
}
// 插入到数据库
ProductAttrValueDO productAttrValueDO = ProductAttrConvert.INSTANCE.convertValueAdd(productAttrValueAddDTO)
.setStatus(ProductAttrConstants.ATTR_VALUE_STATUS_ENABLE);
productAttrValueDO.setCreateTime(new Date());
productAttrValueDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
productAttrValueMapper.insert(productAttrValueDO);
return ProductAttrConvert.INSTANCE.convertAttrValue(productAttrValueDO);
}
@Override
public Boolean updateProductAttrValue(Integer adminId, ProductAttrValueUpdateDTO productAttrValueUpdateDTO) {
// 校验存在
ProductAttrValueDO productAttrValueDO = productAttrValueMapper.selectById(productAttrValueUpdateDTO.getId());
if (productAttrValueDO == null) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_NOT_EXIST.getCode());
}
// 校验规格名不重复
ProductAttrValueDO existsAttrDO = productAttrValueMapper.selectOne(Wrappers.<ProductAttrValueDO>query().lambda()
.eq(ProductAttrValueDO::getName, productAttrValueDO.getName())
.eq(ProductAttrValueDO::getAttrId, productAttrValueDO.getAttrId())
.eq(ProductAttrValueDO::getDeleted, false));
if (existsAttrDO != null && !existsAttrDO.getId().equals(productAttrValueUpdateDTO.getId())) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_EXISTS.getCode());
}
// 更新到数据库
ProductAttrValueDO updateProductValue = ProductAttrConvert.INSTANCE.convertValueUpdate(productAttrValueUpdateDTO);
updateProductValue.setUpdateTime(new Date());
int i = productAttrValueMapper.updateById(updateProductValue);
return i > 0;
}
@Override
public Boolean updateProductAttrValueStatus(Integer adminId, Integer productAttrValueId, Integer status) {
// 校验存在
ProductAttrValueDO productAttrValueDO = productAttrValueMapper.selectById(productAttrValueId);
if (productAttrValueDO == null) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_NOT_EXIST.getCode());
}
// 校验状态
if (productAttrValueDO.getStatus().equals(status)) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_STATUS_EQUALS.getCode());
}
// 更新到数据库
ProductAttrValueDO updateProductAttrValue = new ProductAttrValueDO().setId(productAttrValueId).setStatus(status);
int i = productAttrValueMapper.updateById(updateProductAttrValue);
return i > 0;
}
@Override
public List<ProductAttrAndValuePairBO> validProductAttrAndValue(Set<Integer> productAttrValueIds, boolean validStatus) {
// 首先,校验规格值
List<ProductAttrValueDO> attrValues = productAttrValueMapper.selectBatchIds(productAttrValueIds);
@ -110,146 +241,4 @@ public class ProductAttrServiceImpl implements ProductAttrService {
.setAttrValueId(productAttrValueDO.getId()).setAttrValueName(productAttrValueDO.getName())).collect(Collectors.toList());
}
@Override
public List<ProductAttrSimpleBO> getProductAttrList() {
// 查询所有开启的规格数组
List<ProductAttrDO> attrDos = productAttrMapper.selectList(Wrappers.<ProductAttrDO>query().lambda()
.in(ProductAttrDO::getStatus, ProductAttrConstants.ATTR_STATUS_ENABLE)
.eq(ProductAttrDO::getDeleted, false));
List<ProductAttrSimpleBO> attrs = ProductAttrConvert2.INSTANCE.convert3(attrDos);
// 如果为空,则返回空
if (attrs.isEmpty()) {
return Collections.emptyList();
}
// 将规格值拼接上去
List<ProductAttrValueDO> attrValues = productAttrValueMapper.selectList(Wrappers.<ProductAttrValueDO>query().lambda()
.in(ProductAttrValueDO::getStatus, ProductAttrConstants.ATTR_STATUS_ENABLE)
.eq(ProductAttrValueDO::getDeleted, false));
// KEY 是 attrId VALUE 是 ProductAttrValueDO 数组
ImmutableListMultimap<Integer, ProductAttrValueDO> attrValueMap = Multimaps.index(attrValues, ProductAttrValueDO::getAttrId);
for (ProductAttrSimpleBO productAttrSimpleBO : attrs) {
productAttrSimpleBO.setValues(ProductAttrConvert2.INSTANCE.convert4(((attrValueMap).get(productAttrSimpleBO.getId()))));
}
return attrs;
}
@Override
public ProductAttrBO2 addProductAttr(Integer adminId, ProductAttrAddDTO productAttrAddDTO) {
// 校验规格名不重复
int count = productAttrMapper.selectCount(Wrappers.<ProductAttrDO>query().lambda()
.eq(ProductAttrDO::getName, productAttrAddDTO.getName())
.eq(ProductAttrDO::getDeleted, false));
if (count > 0) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_EXISTS.getCode());
}
// 插入到数据库
ProductAttrDO productAttrDO = ProductAttrConvert2.INSTANCE.convert(productAttrAddDTO)
.setStatus(ProductAttrConstants.ATTR_STATUS_ENABLE);
productAttrDO.setCreateTime(new Date());
productAttrDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
productAttrMapper.insert(productAttrDO);
// 返回成功
return ProductAttrConvert2.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.selectOne(Wrappers.<ProductAttrDO>query().lambda()
.eq(ProductAttrDO::getName, productAttrUpdateDTO.getName())
.eq(ProductAttrDO::getDeleted, false));
if (existsAttrDO != null && !existsAttrDO.getId().equals(productAttrUpdateDTO.getId())) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_EXISTS.getCode());
}
// 更新到数据库
ProductAttrDO updateProductAttr = ProductAttrConvert2.INSTANCE.convert(productAttrUpdateDTO);
productAttrMapper.updateById(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.updateById(updateProductAttr);
// 返回成功
return true;
}
@Override
public ProductAttrValueBO addProductAttrValue(Integer adminId, ProductAttrValueAddDTO productAttrValueAddDTO) {
// 校验规格名不重复
int count = productAttrValueMapper.selectCount(Wrappers.<ProductAttrValueDO>query().lambda()
.eq(ProductAttrValueDO::getName, productAttrValueAddDTO.getName())
.eq(ProductAttrValueDO::getAttrId, productAttrValueAddDTO.getAttrId())
.eq(ProductAttrValueDO::getDeleted, false));
if (count > 0) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_EXISTS.getCode());
}
// 插入到数据库
ProductAttrValueDO productAttrValueDO = ProductAttrConvert2.INSTANCE.convert(productAttrValueAddDTO)
.setStatus(ProductAttrConstants.ATTR_VALUE_STATUS_ENABLE);
productAttrValueDO.setCreateTime(new Date());
productAttrValueDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
productAttrValueMapper.insert(productAttrValueDO);
// 返回成功
return ProductAttrConvert2.INSTANCE.convert2(productAttrValueDO);
}
@Override
public Boolean updateProductAttrValue(Integer adminId, ProductAttrValueUpdateDTO productAttrValueUpdateDTO) {
// 校验存在
ProductAttrValueDO productAttrValueDO = productAttrValueMapper.selectById(productAttrValueUpdateDTO.getId());
if (productAttrValueDO == null) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_NOT_EXIST.getCode());
}
// 校验规格名不重复
ProductAttrValueDO existsAttrDO = productAttrValueMapper.selectOne(Wrappers.<ProductAttrValueDO>query().lambda()
.eq(ProductAttrValueDO::getName, productAttrValueDO.getName())
.eq(ProductAttrValueDO::getAttrId, productAttrValueDO.getAttrId())
.eq(ProductAttrValueDO::getDeleted, false));
if (existsAttrDO != null && !existsAttrDO.getId().equals(productAttrValueUpdateDTO.getId())) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_EXISTS.getCode());
}
// 更新到数据库
ProductAttrValueDO updateProductValue = ProductAttrConvert2.INSTANCE.convert(productAttrValueUpdateDTO);
productAttrValueMapper.updateById(updateProductValue);
// 返回成功
return true;
}
@Override
public Boolean updateProductAttrValueStatus(Integer adminId, Integer productAttrValueId, Integer status) {
// 校验存在
ProductAttrValueDO productAttrValueDO = productAttrValueMapper.selectById(productAttrValueId);
if (productAttrValueDO == null) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_NOT_EXIST.getCode());
}
// 校验状态
if (productAttrValueDO.getStatus().equals(status)) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_STATUS_EQUALS.getCode());
}
// 更新到数据库
ProductAttrValueDO updateProductAttrValue = new ProductAttrValueDO().setId(productAttrValueId).setStatus(status);
productAttrValueMapper.updateById(updateProductAttrValue);
// 返回成功
return true;
}
}

View File

@ -0,0 +1,67 @@
package cn.iocoder.mall.product.biz.service.product.impl;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
import cn.iocoder.mall.product.biz.bo.brand.ProductBrandBO;
import cn.iocoder.mall.product.biz.convert.brand.ProductBrandConvert;
import cn.iocoder.mall.product.biz.dao.product.ProductBrandMapper;
import cn.iocoder.mall.product.biz.dataobject.product.ProductBrandDO;
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.enums.ProductErrorCodeEnum;
import cn.iocoder.mall.product.biz.service.product.ProductBrandService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
/**
* Service
*
* @see ProductBrandDO
*/
@Service
public class ProductBrandServiceImpl implements ProductBrandService {
@Autowired
private ProductBrandMapper productBrandMapper;
@Override
public PageResult<ProductBrandBO> getProductBrandPage(ProductBrandPageDTO productBrandPageDTO) {
IPage<ProductBrandDO> brandPage = productBrandMapper.selectPageByParams(productBrandPageDTO);
return ProductBrandConvert.INSTANCE.convertPage(brandPage);
}
@Override
public ProductBrandBO getProductBrand(Integer brandId) {
return ProductBrandConvert.INSTANCE.convert(productBrandMapper.selectById(brandId));
}
@Override
public ProductBrandBO addProductBrand(Integer adminId, ProductBrandAddDTO productBrandAddDTO) {
// 校验品牌名不重复
int count = productBrandMapper.selectCount(Wrappers.<ProductBrandDO>query().lambda()
.eq(ProductBrandDO::getName, productBrandAddDTO.getName())
.eq(ProductBrandDO::getDeleted, false));
if (count > 0) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_BRAND_EXIST.getCode());
}
ProductBrandDO productBrandDO = ProductBrandConvert.INSTANCE.convert(productBrandAddDTO);
productBrandDO.setCreateTime(new Date());
productBrandDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
productBrandMapper.insert(productBrandDO);
return ProductBrandConvert.INSTANCE.convert(productBrandDO);
}
@Override
public Boolean updateProductBrand(Integer adminId, ProductBrandUpdateDTO productBrandUpdateDTO) {
ProductBrandDO productBrandDO = ProductBrandConvert.INSTANCE.convert(productBrandUpdateDTO);
productBrandDO.setUpdateTime(new Date());
productBrandMapper.updateById(productBrandDO);
return true;
}
}

View File

@ -16,11 +16,12 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import static cn.iocoder.mall.product.biz.enums.ProductErrorCodeEnum.*;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;
import static cn.iocoder.mall.product.biz.enums.ProductErrorCodeEnum.*;
/**
* @Author: jiangweifan
* @Date: 2020/5/6
@ -166,7 +167,6 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
}
// 父分类必须是一级分类
if (!ProductCategoryConstants.PID_ROOT.equals(parentCategory.getPid())) {
// TODO FROM 芋艿 to 伟帆ProductErrorCodeEnum 去实现下 ServiceExceptionUtil.Enumerable 接口,酱紫就不用 .getCode() 方法,代码会更简洁。同时,可以把 ProductErrorCodeEnum static import 下,[DONE]
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_CAN_NOT_BE_LEVEL2);
}
}

View File

@ -0,0 +1,59 @@
package cn.iocoder.mall.product.biz.service.product.impl;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.util.StringUtil;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrAndValuePairBO;
import cn.iocoder.mall.product.biz.bo.product.ProductSpuDetailBO;
import cn.iocoder.mall.product.biz.convert.product.ProductSpuConvert;
import cn.iocoder.mall.product.biz.dao.product.ProductCategoryMapper;
import cn.iocoder.mall.product.biz.dao.product.ProductSkuMapper;
import cn.iocoder.mall.product.biz.dao.product.ProductSpuMapper;
import cn.iocoder.mall.product.biz.dataobject.product.ProductCategoryDO;
import cn.iocoder.mall.product.biz.dataobject.product.ProductSkuDO;
import cn.iocoder.mall.product.biz.dataobject.product.ProductSpuDO;
import cn.iocoder.mall.product.biz.enums.ProductErrorCodeEnum;
import cn.iocoder.mall.product.biz.enums.product.ProductSpuConstants;
import cn.iocoder.mall.product.biz.service.product.ProductAttrService;
import cn.iocoder.mall.product.biz.service.product.ProductSpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Service
public class ProductSpuServiceImpl implements ProductSpuService {
@Autowired
private ProductSpuMapper productSpuMapper;
@Autowired
private ProductSkuMapper productSkuMapper;
@Autowired
private ProductCategoryMapper productCategoryMapper;
@Autowired
private ProductAttrService productAttrService;
@Override
public ProductSpuDetailBO getProductSpuDetail(Integer spuId) {
// 校验商品 spu 存在
ProductSpuDO spu = productSpuMapper.selectById(spuId);
if (spu == null) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_SPU_NOT_EXISTS.getCode());
}
// 获得商品分类分类
ProductCategoryDO category = productCategoryMapper.selectById(spu.getCid());
Assert.notNull(category, String.format("分类编号(%d) 对应", spu.getCid()));
// 获得商品 sku 数组
List<ProductSkuDO> skus = productSkuMapper.selectListBySpuIdAndStatus(spuId, ProductSpuConstants.SKU_STATUS_ENABLE);
// 获得规格
Set<Integer> productAttrValueIds = new HashSet<>();
skus.forEach(sku -> productAttrValueIds.addAll(StringUtil.splitToInt(sku.getAttrs(), ",")));
// 读取规格时,不考虑规格是否被禁用
List<ProductAttrAndValuePairBO> attrAndValuePairList = productAttrService.validProductAttrAndValue(productAttrValueIds, false);
// 返回成功
return ProductSpuConvert.INSTANCE.convert2(spu, skus, attrAndValuePairList, category);
}
}

View File

@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>system</artifactId>
<artifactId>product</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

View File

@ -3,17 +3,30 @@ package cn.iocoder.mall.product.rest.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrBO;
import cn.iocoder.mall.product.biz.dto.attr.AdminProductAttrPageDTO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrSimpleWithValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrWithValueBO;
import cn.iocoder.mall.product.biz.dto.attr.*;
import cn.iocoder.mall.product.biz.service.product.ProductAttrService;
import cn.iocoder.mall.product.rest.convert.attr.ProductAttrConvert;
import cn.iocoder.mall.product.rest.request.attr.AdminProductAttrPageRequest;
import cn.iocoder.mall.product.rest.request.attr.ProductAttrPageRequest;
import cn.iocoder.mall.product.rest.request.attr.ProductAttrAddRequest;
import cn.iocoder.mall.product.rest.request.attr.ProductAttrUpdateRequest;
import cn.iocoder.mall.product.rest.request.attr.ProductAttrValueAddRequest;
import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrPageResponse;
import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrSimpleResponse;
import cn.iocoder.mall.product.rest.response.attr.AdminsProdutAttrResponse;
import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrValueResponse;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
*
@ -32,102 +45,90 @@ public class AdminsProductAttrController {
@GetMapping("/attr/page")
@ApiOperation("获得规格分页")
public CommonResult<PageResult<AdminsProductAttrPageResponse>> attrPage(AdminProductAttrPageRequest request) {
AdminProductAttrPageDTO pageDTO = ProductAttrConvert.INSTANCE.convert(request);
PageResult<ProductAttrBO> productAttrPage = productAttrService.getProductAttrPage(pageDTO);
public CommonResult<PageResult<AdminsProductAttrPageResponse>> attrPage(ProductAttrPageRequest request) {
ProductAttrPageDTO pageDTO = ProductAttrConvert.INSTANCE.convert(request);
PageResult<ProductAttrWithValueBO> productAttrPage = productAttrService.getProductAttrPage(pageDTO);
PageResult<AdminsProductAttrPageResponse> adminPageResponse = ProductAttrConvert.INSTANCE.convertPage(productAttrPage);
return CommonResult.success(adminPageResponse);
}
// @GetMapping("/attr/tree")
// @ApiOperation(value = "获得规格树结构", notes = "该接口返回的信息更为精简。一般用于前端缓存数据字典到本地。")
// public CommonResult<List<AdminsProductAttrSimpleVO>> tree() {
// // 查询全列表
// List<ProductAttrSimpleBO> result = productAttrService.getProductAttrList();
// // 返回结果
// return success(ProductAttrConvert.INSTANCE.convert(result));
// }
//
// @PostMapping("/attr/add")
// @ApiOperation(value = "创建商品规格")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "name", value = "规格名", required = true, example = "颜色")
// })
// public CommonResult<AdminsProductAttrVO> addAttr(@RequestParam("name") String name) {
// // 创建 ProductAttrAddDTO 对象
// ProductAttrAddDTO productAttrAddDTO = new ProductAttrAddDTO().setName(name);
// // 添加
// ProductAttrBO result = productAttrService.addProductAttr(AdminSecurityContextHolder.getContext().getAdminId(), productAttrAddDTO);
// // 返回结果
// return success(ProductAttrConvert.INSTANCE.convert3(result));
// }
//
// @PostMapping("/attr/update")
// @ApiOperation(value = "修改商品规格")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "id", value = "规格编号", required = true, example = "1"),
// @ApiImplicitParam(name = "name", value = "规格名", required = true, example = "颜色")
// })
// public CommonResult<Boolean> updateAttr(@RequestParam("id") Integer id,
// @RequestParam("name") String name) {
// // 创建 ProductAttrUpdateDTO 对象
// ProductAttrUpdateDTO productAttrUpdateDTO = new ProductAttrUpdateDTO().setId(id).setName(name);
// // 更新
// return success(productAttrService.updateProductAttr(AdminSecurityContextHolder.getContext().getAdminId(), productAttrUpdateDTO));
// }
//
// @PostMapping("/attr/update_status")
// @ApiOperation(value = "修改商品规格状态")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "id", value = "规格编号", required = true, example = "100"),
// @ApiImplicitParam(name = "status", value = "状态", required = true, example = "1")
// })
// public CommonResult<Boolean> updateAttrStatus(@RequestParam("id") Integer id,
// @RequestParam("status") Integer status) {
// return success(productAttrService.updateProductAttrStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status));
// }
//
// // TODO 芋艿 暂时不考虑 delete Attr 。因为关联逻辑比较多
//
// @PostMapping("/attr_value/add")
// @ApiOperation(value = "创建商品规格值")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "attrId", value = "规格编号", required = true, example = "100"),
// @ApiImplicitParam(name = "name", value = "规格值", required = true, example = "蓝色")
// })
// public CommonResult<AdminsProductAttrValueVO> addAttrValue(@RequestParam("attrId") Integer attrId,
// @RequestParam("name") String name) {
// // 创建 ProductAttrValueAddDTO 对象
// ProductAttrValueAddDTO productAttrValueAddDTO = new ProductAttrValueAddDTO().setAttrId(attrId).setName(name);
// // 添加
// ProductAttrValueBO result = productAttrService.addProductAttrValue(AdminSecurityContextHolder.getContext().getAdminId(), productAttrValueAddDTO);
// // 返回结果
// return success(ProductAttrConvert.INSTANCE.convert4(result));
// }
//
// @PostMapping("/attr_value/update")
// @ApiOperation(value = "修改商品规格值")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "id", value = "规格值编号", required = true, example = "100"),
// @ApiImplicitParam(name = "name", value = "规格值", required = true, example = "蓝色")
// })
// public CommonResult<Boolean> updateAttrValue(@RequestParam("id") Integer id,
// @RequestParam("name") String name) {
// // 创建 ProductAttrValueUpdateDTO 对象
// ProductAttrValueUpdateDTO productAttrValueUpdateDTO = new ProductAttrValueUpdateDTO().setId(id).setName(name);
// // 更新
// return success(productAttrService.updateProductAttrValue(AdminSecurityContextHolder.getContext().getAdminId(), productAttrValueUpdateDTO));
// }
//
// @PostMapping("/attr_value/update_status")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "id", value = "规格编号", required = true, example = "100"),
// @ApiImplicitParam(name = "status", value = "状态", required = true, example = "1")
// })
// public CommonResult<Boolean> updateAttrValueStatus(@RequestParam("id") Integer id,
// @RequestParam("status") Integer status) {
// return success(productAttrService.updateProductAttrValueStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status));
// }
@GetMapping("/attr/tree")
@ApiOperation(value = "获得规格树结构", notes = "该接口返回的信息更为精简。一般用于前端缓存数据字典到本地。")
public CommonResult<List<AdminsProductAttrSimpleResponse>> tree() {
// 查询全列表
List<ProductAttrSimpleWithValueBO> result = productAttrService.getProductAttrList();
return CommonResult.success(ProductAttrConvert.INSTANCE.convertSimple(result));
}
@PostMapping("/attr/add")
@ApiOperation(value = "创建商品规格")
public CommonResult<AdminsProdutAttrResponse> addAttr(@Validated ProductAttrAddRequest addRequest) {
// 创建 ProductAttrAddDTO 对象
ProductAttrAddDTO productAttrAddDTO = new ProductAttrAddDTO().setName(addRequest.getName());
// 添加
ProductAttrBO result = productAttrService.addProductAttr(AdminSecurityContextHolder.getContext().getAdminId(), productAttrAddDTO);
return CommonResult.success(ProductAttrConvert.INSTANCE.convertAttr(result));
}
@PostMapping("/attr/update")
@ApiOperation(value = "修改商品规格")
public CommonResult<Boolean> updateAttr(@Validated ProductAttrUpdateRequest updateRequest) {
ProductAttrUpdateDTO productAttrUpdateDTO = ProductAttrConvert.INSTANCE.convertUpdate(updateRequest);
// 更新
return CommonResult.success(productAttrService.updateProductAttr(AdminSecurityContextHolder.getContext().getAdminId(), productAttrUpdateDTO));
}
@PostMapping("/attr/update_status")
@ApiOperation(value = "修改商品规格状态")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "规格编号", required = true, example = "100"),
@ApiImplicitParam(name = "status", value = "状态", required = true, example = "1")
})
public CommonResult<Boolean> updateAttrStatus(@RequestParam("id") Integer id,
@RequestParam("status") Integer status) {
return CommonResult.success(productAttrService.updateProductAttrStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status));
}
// TODO 芋艿 暂时不考虑 delete Attr 。因为关联逻辑比较多
@PostMapping("/attr_value/add")
@ApiOperation(value = "创建商品规格值")
@ApiImplicitParams({
@ApiImplicitParam(name = "attrId", value = "规格编号", required = true, example = "100"),
@ApiImplicitParam(name = "name", value = "规格值", required = true, example = "蓝色")
})
public CommonResult<AdminsProductAttrValueResponse> addAttrValue(@Validated ProductAttrValueAddRequest addRequest) {
// 创建 ProductAttrValueAddDTO 对象
ProductAttrValueAddDTO productAttrValueAddDTO = new ProductAttrValueAddDTO().setAttrId(addRequest.getAttrId()).setName(addRequest.getName());
// 添加
ProductAttrValueBO result = productAttrService.addProductAttrValue(AdminSecurityContextHolder.getContext().getAdminId(), productAttrValueAddDTO);
// 返回结果
return CommonResult.success(ProductAttrConvert.INSTANCE.convertAddResponse(result));
}
@PostMapping("/attr_value/update")
@ApiOperation(value = "修改商品规格值")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "规格值编号", required = true, example = "100"),
@ApiImplicitParam(name = "name", value = "规格值", required = true, example = "蓝色")
})
public CommonResult<Boolean> updateAttrValue(@RequestParam("id") Integer id,
@RequestParam("name") String name) {
// 创建 ProductAttrValueUpdateDTO 对象
ProductAttrValueUpdateDTO productAttrValueUpdateDTO = new ProductAttrValueUpdateDTO().setId(id).setName(name);
// 更新
return CommonResult.success(productAttrService.updateProductAttrValue(AdminSecurityContextHolder.getContext().getAdminId(), productAttrValueUpdateDTO));
}
@PostMapping("/attr_value/update_status")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "规格编号", required = true, example = "100"),
@ApiImplicitParam(name = "status", value = "状态", required = true, example = "1")
})
public CommonResult<Boolean> updateAttrValueStatus(@RequestParam("id") Integer id,
@RequestParam("status") Integer status) {
return CommonResult.success(productAttrService.updateProductAttrValueStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status));
}
// TODO 芋艿 暂时不考虑 delete Attr Value 。因为关联逻辑比较多

View File

@ -0,0 +1,93 @@
package cn.iocoder.mall.product.rest.controller.admins;
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.product.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);
}
}

View File

@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("users/favorite")
@Api("用户收藏")
// TODO FROM 芋艿 to ilnhjcontroller 分包的话,还是按照模块。然后通过 Admins 和 Users 前缀,区分不同的 Controlller
public class UserFavoriteController {
}

View File

@ -2,18 +2,44 @@ package cn.iocoder.mall.product.rest.convert.attr;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrBO;
import cn.iocoder.mall.product.biz.dto.attr.AdminProductAttrPageDTO;
import cn.iocoder.mall.product.rest.request.attr.AdminProductAttrPageRequest;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrSimpleWithValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrWithValueBO;
import cn.iocoder.mall.product.biz.dto.attr.ProductAttrPageDTO;
import cn.iocoder.mall.product.biz.dto.attr.ProductAttrUpdateDTO;
import cn.iocoder.mall.product.rest.request.attr.ProductAttrPageRequest;
import cn.iocoder.mall.product.rest.request.attr.ProductAttrUpdateRequest;
import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrPageResponse;
import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrSimpleResponse;
import cn.iocoder.mall.product.rest.response.attr.AdminsProdutAttrResponse;
import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrValueResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface ProductAttrConvert {
ProductAttrConvert INSTANCE = Mappers.getMapper(ProductAttrConvert.class);
AdminProductAttrPageDTO convert(AdminProductAttrPageRequest bean);
@Mappings({})
ProductAttrPageDTO convert(ProductAttrPageRequest bean);
PageResult<AdminsProductAttrPageResponse> convertPage(PageResult<ProductAttrBO> productAttrPage);
@Mappings({})
PageResult<AdminsProductAttrPageResponse> convertPage(PageResult<ProductAttrWithValueBO> productAttrPage);
@Mappings({})
List<AdminsProductAttrSimpleResponse> convertSimple(List<ProductAttrSimpleWithValueBO> simpleList);
@Mappings({})
AdminsProdutAttrResponse convertAttr(ProductAttrBO attrBO);
@Mappings({})
ProductAttrUpdateDTO convertUpdate(ProductAttrUpdateRequest updateRequest);
@Mappings({})
AdminsProductAttrValueResponse convertAddResponse(ProductAttrValueBO result);
}

View File

@ -0,0 +1,35 @@
package cn.iocoder.mall.product.rest.convert.brand;
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.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 org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper
public interface ProductBrandConvert {
ProductBrandConvert INSTANCE = Mappers.getMapper(ProductBrandConvert.class);
@Mappings({})
AdminsProductBrandResponse convert(ProductBrandBO brand);
@Mappings({})
ProductBrandAddDTO convertAdd(ProductBrandAddRequest addRequest);
@Mappings({})
ProductBrandUpdateDTO convertUpdate(ProductBrandUpdateRequest updateRequest);
@Mappings({})
ProductBrandPageDTO convertPageRequest(ProductBrandPageRequest pageRequest);
@Mappings({})
PageResult<AdminsProductBrandResponse> convertPage(PageResult<ProductBrandBO> productBrandPage);
}

View File

@ -0,0 +1,19 @@
package cn.iocoder.mall.product.rest.request.attr;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
@ApiModel("商品 - 规格模块 - 商品规格添加 Request")
@Data
@Accessors(chain = true)
public class ProductAttrAddRequest {
@ApiModelProperty(name = "name", value = "规格名", required = true, example = "颜色")
@NotEmpty(message = "规格名不能为空")
private String name;
}

View File

@ -11,7 +11,7 @@ import lombok.experimental.Accessors;
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class AdminProductAttrPageRequest extends PageParam {
public class ProductAttrPageRequest extends PageParam {
@ApiModelProperty(value = "商品规格名字,模糊匹配", example = "材料")
private String name;

View File

@ -0,0 +1,25 @@
package cn.iocoder.mall.product.rest.request.attr;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@ApiModel("商品 - 规格模块 - 商品规格修改 Request")
@Data
@Accessors(chain = true)
public class ProductAttrUpdateRequest {
@ApiModelProperty(name = "id", value = "规格编号", required = true, example = "1")
@NotNull(message = "规格编号不能为空")
private Integer id;
@ApiModelProperty(name = "name", value = "规格名", required = true, example = "颜色")
@NotEmpty(message = "规格名不能为空")
private String name;
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.mall.product.rest.request.attr;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@ApiModel("商品 - 规格模块 - 商品规格值添加 Request")
@Data
@Accessors(chain = true)
public class ProductAttrValueAddRequest {
@ApiModelProperty(name = "attrId", value = "规格编号", required = true, example = "1")
@NotNull(message = "规格编号不能为空")
private Integer attrId;
/**
*
*/
@ApiModelProperty(name = "name", value = "规格值名", required = true, example = "红色")
@NotEmpty(message = "规格值名不能为空")
private String name;
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.mall.product.rest.request.attr;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* Product DTO
* <p>
*
*/
@ApiModel("商品 - 规格模块 - 商品规格值修改 Request")
@Data
@Accessors(chain = true)
public class ProductAttrValueUpdateRequest {
@ApiModelProperty(name = "id", value = "规格值编号", required = true, example = "1")
@NotNull(message = "规格值编号不能为空")
private Integer id;
@ApiModelProperty(name = "id", value = "规格值编号", required = true, example = "1")
@NotEmpty(message = "规格名不能为空")
private String name;
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.mall.product.rest.request.brand;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
@ApiModel("商品 - 品牌模块 - 商品品牌新增 Request")
@Data
@Accessors(chain = true)
public class ProductBrandAddRequest {
@ApiModelProperty(name = "name", value = "品牌名称", required = true, example = "安踏")
@NotEmpty(message = "品牌名称不能为空")
private String name;
@ApiModelProperty(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋")
private String description;
@ApiModelProperty(name = "picUrl", value = "品牌图片", required = true, example = "http://www.iocoder.cn")
private String picUrl;
@ApiModelProperty(name = "status", value = "状态 1开启 2禁用", required = true, example = "1")
private Integer status;
}

View File

@ -0,0 +1,24 @@
package cn.iocoder.mall.product.rest.request.brand;
import cn.iocoder.common.framework.vo.PageParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
@ApiModel("商品 - 品牌模块 - 品牌分页 Request")
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class ProductBrandPageRequest extends PageParam {
@ApiModelProperty(name = "name", value = "品牌名称", required = true, example = "安踏")
private String name;
@ApiModelProperty(name = "name", value = "品牌描述", required = true, example = "安踏拖鞋")
private String description;
@ApiModelProperty(name = "name", value = "状态 1开启 2禁用", required = true, example = "1")
private String status;
}

View File

@ -0,0 +1,32 @@
package cn.iocoder.mall.product.rest.request.brand;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@ApiModel("商品 - 品牌模块 - 商品品牌更新 Request")
@Data
@Accessors(chain = true)
public class ProductBrandUpdateRequest {
@ApiModelProperty(name = "id", value = "规格编号", required = true, example = "1")
@NotNull(message = "品牌编号不能为空")
private Integer id;
@ApiModelProperty(name = "name", value = "品牌名称", required = true, example = "安踏")
@NotEmpty(message = "品牌名称不能为空")
private String name;
@ApiModelProperty(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋")
private String description;
@ApiModelProperty(name = "picUrl", value = "品牌图片", required = true, example = "http://www.iocoder.cn")
private String picUrl;
@ApiModelProperty(name = "status", value = "状态 1开启 2禁用", required = true, example = "1")
private Integer status;
}

View File

@ -17,7 +17,6 @@ import javax.validation.constraints.NotNull;
@Accessors(chain = true)
public class AdminsProductCategoryAddRequest {
// TODO FROM 芋艿 to 伟帆:写了 swagger 注解,我们可以少写一份 Java 注释。[DONE]
@ApiModelProperty(name = "pid", value = "父级分类编号", required = true, example = "1")
@NotNull(message = "父分类编号不能为空")
private Integer pid;

View File

@ -0,0 +1,38 @@
package cn.iocoder.mall.product.rest.response.attr;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@ApiModel(value = "商品规格精简 VO", description = "带有规格值数组")
@Data
@Accessors(chain = true)
public class AdminsProductAttrSimpleResponse {
@ApiModelProperty(value = "规格编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "规格名", required = true, example = "颜色")
private String name;
@ApiModelProperty(value = "规格值数组", required = true)
private List<ProductAttrValue> values;
@ApiModel("规格值")
@Data
@Accessors(chain = true)
public static class ProductAttrValue {
/**
*
*/
@ApiModelProperty(value = "规格值编号", required = true, example = "1")
private Integer id;
/**
*
*/
@ApiModelProperty(value = "规格值名", required = true, example = "小")
private String name;
}
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.mall.product.rest.response.attr;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
@ApiModel(value = "商品规格值 VO")
@Data
@Accessors(chain = true)
public class AdminsProductAttrValueResponse {
@ApiModelProperty(value = "规格值编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "规格编号", required = true, example = "1")
private Integer attrId;
@ApiModelProperty(value = "规格名", required = true, example = "颜色")
private String name;
@ApiModelProperty(value = "状态", required = true, example = "1")
private Integer status;
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳")
private Date createTime;
}

View File

@ -1,4 +1,24 @@
package cn.iocoder.mall.product.rest.response.attr;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
@ApiModel(value = "商品规格 VO", description = "不带有规格值数组")
@Data
@Accessors(chain = true)
public class AdminsProdutAttrResponse {
@ApiModelProperty(value = "规格编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "规格名", required = true, example = "颜色")
private String name;
@ApiModelProperty(value = "状态", required = true, example = "1")
private Integer status;
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳")
private Date createTime;
}

View File

@ -0,0 +1,36 @@
package cn.iocoder.mall.product.rest.response.brand;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
/**
* VO
*/
@ApiModel(value = "商品品牌", description = "商品品牌")
@Data
@Accessors(chain = true)
public class AdminsProductBrandResponse {
/**
*
*/
@ApiModelProperty(value = "品牌编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(name = "name", value = "品牌名称", required = true, example = "安踏")
@NotEmpty(message = "品牌名称不能为空")
private String name;
@ApiModelProperty(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋")
private String description;
@ApiModelProperty(name = "picUrl", value = "品牌图片", required = true, example = "http://www.iocoder.cn")
private String picUrl;
@ApiModelProperty(name = "status", value = "状态 1开启 2禁用", required = true, example = "1")
private Integer status;
}

View File

@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>system</artifactId>
<artifactId>product</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

View File

@ -0,0 +1,12 @@
package cn.iocoder.mall.product.rpc.api;
import cn.iocoder.mall.product.rpc.response.ProductSpuDetailResponse;
/**
* @author Rai
*/
public interface ProductSpuRpc {
ProductSpuDetailResponse getProductSpuDetail(Integer spuId);
}

View File

@ -0,0 +1,127 @@
package cn.iocoder.mall.product.rpc.response;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.List;
/**
* Spu BO Sku
*/
@Data
@Accessors(chain = true)
public class ProductSpuDetailResponse implements Serializable {
/**
* SPU
*/
private Integer id;
// ========== 基本信息 =========
/**
* SPU
*/
private String name;
/**
*
*/
private String sellPoint;
/**
*
*/
private String description;
/**
*
*/
private Integer cid;
/**
*
*/
private String categoryName;
/**
*
* <p>
*
* <p>
* 800*80015
*/
private List<String> picUrls;
// ========== 其他信息 =========
/**
*
* <p>
* true
* false
*/
private Boolean visible;
/**
*
*/
private Integer sort;
// ========== SKU =========
/**
* SKU
*/
private List<Sku> skus;
/**
* Sku BO
*/
@Data
@Accessors(chain = true)
public static class Sku implements Serializable {
/**
* sku
*/
private Integer id;
/**
*
*/
private Integer spuId;
/**
*
*/
private String picURL;
/**
*
*/
private List<ProductAttrAndValuePair> attrs;
/**
*
*/
private Integer price;
/**
*
*/
private Integer quantity;
}
@Data
@Accessors(chain = true)
public static class ProductAttrAndValuePair implements Serializable {
/**
*
*/
private Integer attrId;
/**
*
*/
private String attrName;
/**
*
*/
private Integer attrValueId;
/**
*
*/
private String attrValueName;
}
}

View File

@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>system</artifactId>
<artifactId>product</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

View File

@ -0,0 +1,16 @@
package cn.iocoder.mall.product.rpc.convert;
import cn.iocoder.mall.product.biz.bo.product.ProductSpuDetailBO;
import cn.iocoder.mall.product.rpc.response.ProductSpuDetailResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper
public interface ProductSpuConvert {
ProductSpuConvert INSTANCE = Mappers.getMapper(ProductSpuConvert.class);
@Mappings({})
ProductSpuDetailResponse convertDetail(ProductSpuDetailBO productSpuDetail);
}

View File

@ -0,0 +1,24 @@
package cn.iocoder.mall.product.rpc.rpc;
import cn.iocoder.mall.product.biz.bo.product.ProductSpuDetailBO;
import cn.iocoder.mall.product.biz.service.product.ProductSpuService;
import cn.iocoder.mall.product.rpc.api.ProductSpuRpc;
import cn.iocoder.mall.product.rpc.convert.ProductSpuConvert;
import cn.iocoder.mall.product.rpc.response.ProductSpuDetailResponse;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
@Service(validation = "true", version = "${dubbo.provider.ProductSpuService.version}")
public class ProductSpuRpcImpl implements ProductSpuRpc {
@Autowired
private ProductSpuService productSpuService;
@Override
public ProductSpuDetailResponse getProductSpuDetail(Integer spuId) {
ProductSpuDetailBO productSpuDetail = productSpuService.getProductSpuDetail(spuId);
return ProductSpuConvert.INSTANCE.convertDetail(productSpuDetail);
}
}

View File

@ -2,39 +2,21 @@
dubbo:
# Spring Cloud Alibaba Dubbo 专属配置
cloud:
subscribed-services: 'system-application' # 设置订阅的应用列表,默认为 * 订阅所有应用
subscribed-services: 'product-application' # 设置订阅的应用列表,默认为 * 订阅所有应用
# Dubbo 提供者的协议
protocol:
name: dubbo
port: -1
# Dubbo 提供服务的扫描基础包
scan:
base-packages: cn.iocoder.mall.system.rpc.rpc
base-packages: cn.iocoder.mall.product.rpc.rpc
# Dubbo 服务提供者的配置
provider:
filter: -exception
SystemLogRPC:
version: 1.0.0
OAuth2RPC:
version: 1.0.0
AuthorizationRPC:
version: 1.0.0
AdminRPC:
version: 1.0.0
UserRPC:
version: 1.0.0
UserAddressRPC:
ProductSpuService:
version: 1.0.0
# Dubbo 服务消费者的配置
consumer:
SystemLogRPC: # 用于 AccessLogInterceptor 等拦截器,记录 HTTP API 请求的访问日志
version: 1.0.0
OAuth2RPC: # 用于 AccountAuthInterceptor 拦截器,执行认证
version: 1.0.0
AuthorizationRPC: # 用于 AccountAuthInterceptor 拦截器,执行鉴权(权限验证)
version: 1.0.0
AdminRPC:
version: 1.0.0
UserRPC:
ProductSpuService:
version: 1.0.0

View File

@ -49,6 +49,12 @@
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot-starter-mybatis</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- RPC 相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
@ -78,6 +84,12 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>user-biz</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@ -1,6 +1,6 @@
package cn.iocoder.mall.product.dataobject;
import cn.iocoder.common.framework.dataobject.DeletableDO;
import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,6 +1,6 @@
package cn.iocoder.mall.product.dataobject;
import cn.iocoder.common.framework.dataobject.DeletableDO;
import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,6 +1,6 @@
package cn.iocoder.mall.product.dataobject;
import cn.iocoder.common.framework.dataobject.DeletableDO;
import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,6 +1,6 @@
package cn.iocoder.mall.product.dataobject;
import cn.iocoder.common.framework.dataobject.DeletableDO;
import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,6 +1,6 @@
package cn.iocoder.mall.product.dataobject;
import cn.iocoder.common.framework.dataobject.DeletableDO;
import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,6 +1,6 @@
package cn.iocoder.mall.product.dataobject;
import cn.iocoder.common.framework.dataobject.DeletableDO;
import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,7 +1,7 @@
package cn.iocoder.mall.product.message;
import cn.iocoder.common.framework.constant.DeletedStatusEnum;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
import cn.iocoder.mall.product.api.UserProductSpuCollectionsService;
import cn.iocoder.mall.product.api.bo.UserProductSpuCollectionsBO;
import cn.iocoder.mall.product.api.dto.UserProductSpuCollectionsAddDTO;
@ -10,7 +10,7 @@ import cn.iocoder.mall.product.api.message.ProductSpuCollectionMessage;
import cn.iocoder.mall.product.convert.UserProductSpuCollectionsConvert;
import cn.iocoder.mall.user.api.UserService;
import cn.iocoder.mall.user.api.bo.UserBO;
import cn.iocoder.mall.user.api.constant.UserErrorCodeEnum;
import cn.iocoder.mall.user.biz.enums.UserErrorCodeEnum;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;

View File

@ -1,7 +1,7 @@
package cn.iocoder.mall.product.service;
import cn.iocoder.common.framework.constant.DeletedStatusEnum;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
import cn.iocoder.mall.product.api.ProductAttrService;
import cn.iocoder.mall.product.api.bo.*;
import cn.iocoder.mall.product.api.constant.ProductAttrConstants;

View File

@ -1,7 +1,7 @@
package cn.iocoder.mall.product.service;
import cn.iocoder.common.framework.constant.DeletedStatusEnum;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
import cn.iocoder.mall.product.api.ProductCategoryService;
import cn.iocoder.mall.product.api.bo.ProductCategoryBO;
import cn.iocoder.mall.product.api.constant.ProductCategoryConstants;

View File

@ -1,9 +1,9 @@
package cn.iocoder.mall.product.service;
import cn.iocoder.common.framework.constant.DeletedStatusEnum;
import cn.iocoder.common.framework.util.CollectionUtil;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.util.StringUtil;
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
import cn.iocoder.mall.product.api.ProductSpuService;
import cn.iocoder.mall.product.api.bo.*;
import cn.iocoder.mall.product.api.constant.ProductCategoryConstants;

View File

@ -1,7 +1,7 @@
package cn.iocoder.mall.product.service;
import cn.iocoder.common.framework.constant.DeletedStatusEnum;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
import cn.iocoder.mall.product.api.UserProductSpuCollectionsService;
import cn.iocoder.mall.product.api.bo.UserProductSpuCollectionsBO;
import cn.iocoder.mall.product.api.bo.UserProductSpuCollectionsPageBO;

View File

@ -33,14 +33,10 @@
<artifactId>product-service-impl</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>user-sdk</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>system-sdk</artifactId>
<artifactId>mall-spring-boot-starter-mybatis</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
@ -82,6 +78,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot-starter-security</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@ -1,7 +1,6 @@
package cn.iocoder.mall.product.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.sdk.context.AdminSecurityContextHolder;
import cn.iocoder.mall.product.api.ProductAttrService;
import cn.iocoder.mall.product.api.bo.ProductAttrBO;
import cn.iocoder.mall.product.api.bo.ProductAttrPageBO;
@ -13,6 +12,7 @@ import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrPageVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrSimpleVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrValueVO;
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

View File

@ -1,7 +1,6 @@
package cn.iocoder.mall.product.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.sdk.context.AdminSecurityContextHolder;
import cn.iocoder.mall.product.api.ProductBrandService;
import cn.iocoder.mall.product.api.bo.ProductBrandBO;
import cn.iocoder.mall.product.api.bo.ProductBrangPageBO;
@ -11,6 +10,7 @@ import cn.iocoder.mall.product.api.dto.ProductBrandUpdateDTO;
import cn.iocoder.mall.product.application.convert.ProductBrandConvert;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductBrandVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductBrangPageVO;
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

View File

@ -1,7 +1,6 @@
package cn.iocoder.mall.product.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.sdk.context.AdminSecurityContextHolder;
import cn.iocoder.mall.product.api.ProductCategoryService;
import cn.iocoder.mall.product.api.bo.ProductCategoryBO;
import cn.iocoder.mall.product.api.constant.ProductCategoryConstants;
@ -10,6 +9,7 @@ import cn.iocoder.mall.product.api.dto.ProductCategoryUpdateDTO;
import cn.iocoder.mall.product.application.convert.ProductCategoryConvert;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductCategoryTreeNodeVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductCategoryVO;
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

View File

@ -1,7 +1,6 @@
package cn.iocoder.mall.product.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.sdk.context.AdminSecurityContextHolder;
import cn.iocoder.mall.product.api.ProductSpuService;
import cn.iocoder.mall.product.api.bo.ProductSpuBO;
import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO;
@ -11,6 +10,7 @@ import cn.iocoder.mall.product.application.convert.ProductSpuConvert;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductSpuDetailVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductSpuPageVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductSpuVO;
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;

View File

@ -4,8 +4,7 @@ import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.product.api.UserProductSpuCollectionsService;
import cn.iocoder.mall.product.api.bo.UserProductSpuCollectionsPageBO;
import cn.iocoder.mall.product.api.dto.UserProductSpuCollectionsPageDTO;
import cn.iocoder.mall.user.sdk.annotation.RequiresLogin;
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
import cn.iocoder.mall.security.core.context.UserSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
@ -27,7 +26,6 @@ public class UserFavoriteController {
private UserProductSpuCollectionsService userProductSpuCollectionsService;
@GetMapping("page")
@RequiresLogin
@ApiOperation("用户商品收藏列表")
public CommonResult<UserProductSpuCollectionsPageBO> getUserProductSpuCollectionsPage(
@Validated UserProductSpuCollectionsPageDTO userProductSpuCollectionsPageDTO) {
@ -37,7 +35,6 @@ public class UserFavoriteController {
}
@DeleteMapping("remove")
@RequiresLogin
@ApiOperation(value = "用户商品收藏-删除")
public CommonResult<Boolean> removeUserFavorite(@RequestParam("spuId") final Integer spuId) {
final Integer userId = UserSecurityContextHolder.getContext().getUserId();
@ -45,7 +42,6 @@ public class UserFavoriteController {
}
@GetMapping("hasUserFavorite")
@RequiresLogin
@ApiOperation(value = "用户商品收藏-是否收藏")
public CommonResult<Boolean> hasUserSpuFavorite(@RequestParam("spuId") final Integer spuId) {
final Integer userId = UserSecurityContextHolder.getContext().getUserId();

View File

@ -2,8 +2,7 @@ package cn.iocoder.mall.product.application.controller.users;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.product.api.ProductSpuCollectionService;
import cn.iocoder.mall.user.sdk.annotation.RequiresLogin;
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
import cn.iocoder.mall.security.core.context.UserSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
@ -30,7 +29,6 @@ public class UsersProductSpuCollectionController {
@PostMapping("/collection/{spuId}/{hasCollectionType}")
@ApiOperation("商品收藏")
@RequiresLogin
public CommonResult<Boolean> productSpuCollection(@PathVariable("spuId") Integer spuId,
@PathVariable("hasCollectionType") Integer hasCollectionType) {
final Integer userId = UserSecurityContextHolder.getContext().getUserId();

View File

@ -25,7 +25,7 @@
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>product-service-api</artifactId>
<artifactId>product-rpc-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

View File

@ -3,7 +3,7 @@ package cn.iocoder.mall.promotion.biz.service;
import cn.iocoder.common.framework.constant.CommonStatusEnum;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
import cn.iocoder.mall.product.api.ProductSpuService;
import cn.iocoder.mall.product.rpc.api.ProductSpuRpc;
import cn.iocoder.mall.promotion.api.ProductRecommendService;
import cn.iocoder.mall.promotion.api.bo.ProductRecommendBO;
import cn.iocoder.mall.promotion.api.bo.ProductRecommendPageBO;
@ -26,7 +26,7 @@ import java.util.List;
public class ProductRecommendServiceImpl implements ProductRecommendService {
@Reference(validation = "true", version = "${dubbo.consumer.ProductSpuService.version}")
private ProductSpuService productSpuService;
private ProductSpuRpc productSpuRpc;
@Autowired
private ProductRecommendMapper productRecommendMapper;
@ -52,7 +52,7 @@ public class ProductRecommendServiceImpl implements ProductRecommendService {
@Override
public ProductRecommendBO addProductRecommend(Integer adminId, ProductRecommendAddDTO productRecommendAddDTO) {
// 校验商品不存在
if (productSpuService.getProductSpuDetail(productRecommendAddDTO.getProductSpuId()) == null) {
if (productSpuRpc.getProductSpuDetail(productRecommendAddDTO.getProductSpuId()) == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS.getCode());
}
// 校验商品是否已经推荐
@ -74,7 +74,7 @@ public class ProductRecommendServiceImpl implements ProductRecommendService {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode());
}
// 校验商品不存在
if (productSpuService.getProductSpuDetail(productRecommendUpdateDTO.getProductSpuId()) == null) {
if (productSpuRpc.getProductSpuDetail(productRecommendUpdateDTO.getProductSpuId()) == null) {
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS.getCode());
}
// 校验商品是否已经推荐

View File

@ -87,6 +87,11 @@ public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable {
USER_ADDRESS_NOT_EXISTENT(1001004000, "用户地址不存在!"),
USER_ADDRESS_IS_DELETED(1001004001, "用户地址已被删除!"),
USER_GET_ADDRESS_NOT_EXISTS(1001004002, "获取的地址不存在!"),
// ========== 错误码模块 1002009000 ==========
ERROR_CODE_NOT_EXISTS(1002009000, "错误码不存在"),
ERROR_CODE_DUPLICATE(1002009001, "已经存在编码为【{}}】的错误码"),
ERROR_CAN_NOT_UPDATE_SYSTEM_TYPE_ERROR(1002004003, "不能修改类型为系统内置的错误码"),
;

View File

@ -0,0 +1,26 @@
package cn.iocoder.mall.system.biz.enums.errorcode;
/**
*
* @author ding
*/
public enum ErrorCodeTypeEnum {
/**
*
*/
SYSTEM(1),
/**
*
*/
CUSTOM(2);
private final Integer type;
ErrorCodeTypeEnum(Integer type) {
this.type = type;
}
public Integer getType() {
return type;
}
}

View File

@ -0,0 +1,31 @@
package cn.iocoder.mall.system.biz.bo.errorcode;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* - BO
* @author ding
*/
@Data
@Accessors(chain = true)
public class ErrorCodeBO {
/**
*
*/
private Integer id;
/**
*
*/
private Integer code;
/**
*
*/
private String message;
/**
*
*/
private Date createTime;
}

View File

@ -1,19 +1,32 @@
package cn.iocoder.mall.system.biz.config;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.mall.system.biz.bo.errorcode.ErrorCodeBO;
import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum;
import cn.iocoder.mall.system.biz.service.errorcode.ErrorCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import java.util.List;
@Configuration
public class ServiceExceptionConfiguration {
// TODO FROM 芋艿 to 鱿鱼须:这块的实现,微信一起沟通下哈。大体是说,要调用 RPC 接口,不然别的模块无法使用哟。最终,我们是要做成 starter提供给各个模块用。
@Autowired
private ErrorCodeService errorCodeService;
@EventListener(ApplicationReadyEvent.class) // 可参考 https://www.cnblogs.com/ssslinppp/p/7607509.html
public void initMessages() {
List<ErrorCodeBO> list = errorCodeService.getErrorCodeList();
for (SystemErrorCodeEnum item : SystemErrorCodeEnum.values()) {
ServiceExceptionUtil.put(item.getCode(), item.getMessage());
}
for (ErrorCodeBO bo : list) {
ServiceExceptionUtil.put(bo.getCode(),bo.getMessage());
}
}
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.mall.system.biz.convert.errorcode;
import cn.iocoder.mall.system.biz.bo.errorcode.ErrorCodeBO;
import cn.iocoder.mall.system.biz.dataobject.errorcode.ErrorCodeDO;
import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeAddDTO;
import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeDTO;
import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeUpdateDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* @author ding
*/
@Mapper
public interface ErrorCodeConvert {
ErrorCodeConvert INSTANCE = Mappers.getMapper(ErrorCodeConvert.class);
ErrorCodeDO convert(ErrorCodeDTO bean);
ErrorCodeBO convert(ErrorCodeDO bean);
List<ErrorCodeBO> convertList(List<ErrorCodeDO> beans);
// @Mapping(source = "records", target = "list")
// PageResult<ErrorCodeBO> convertPage(IPage<ErrorCodeDO> page);
ErrorCodeDO convert(ErrorCodeAddDTO bean);
ErrorCodeDO convert(ErrorCodeUpdateDTO bean);
}

View File

@ -0,0 +1,31 @@
package cn.iocoder.mall.system.biz.dao.errorcode;
import cn.iocoder.mall.mybatis.query.QueryWrapperX;
import cn.iocoder.mall.system.biz.dataobject.errorcode.ErrorCodeDO;
import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum;
import cn.iocoder.mall.system.biz.enums.errorcode.ErrorCodeTypeEnum;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
/**
* @author ding
*/
@Repository
public interface ErrorCodeMapper extends BaseMapper<ErrorCodeDO> {
default ErrorCodeDO selectByCode(Integer code){
//从db查询
ErrorCodeDO errorCodeDO = selectOne(new QueryWrapperX<ErrorCodeDO>().eqIfPresent("code", code));
if (null == errorCodeDO){
//从enum查询
for (SystemErrorCodeEnum item : SystemErrorCodeEnum.values()) {
if(code.equals(item.getCode())){
return new ErrorCodeDO().setCode(item.getCode()).
setId(0).setType(ErrorCodeTypeEnum.SYSTEM.getType());
}
}
}
return null;
}
}

View File

@ -0,0 +1,37 @@
package cn.iocoder.mall.system.biz.dataobject.errorcode;
import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
*
*/
@TableName(value = "error_code")
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class ErrorCodeDO extends DeletableDO {
/**
*
*/
private Integer id;
/**
*
*/
private Integer code;
/**
*
*/
private String message;
/**
*
*/
private Integer type;
// TODO FROM 芋艿 to 鱿鱼丝:增加一个分组字段。方便做归类
// TODO FROM 芋艿 to 鱿鱼丝:增加个备注字段,方便做备注哈。
}

View File

@ -0,0 +1,21 @@
package cn.iocoder.mall.system.biz.dto.errorcode;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* - DTO
*/
@Data
@Accessors(chain = true)
public class ErrorCodeAddDTO {
@NotNull(message = "错误码编码")
private Integer code;
@NotEmpty(message = "错误码错误信息")
private String message;
}

View File

@ -0,0 +1,28 @@
package cn.iocoder.mall.system.biz.dto.errorcode;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @author ding
*/
@Data
@Accessors(chain = true)
public class ErrorCodeDTO {
/**
*
*/
private Integer id;
/**
*
*/
private Integer code;
/**
*
*/
private String message;
/**
*
*/
private Integer type;
}

View File

@ -0,0 +1,17 @@
package cn.iocoder.mall.system.biz.dto.errorcode;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
/**
*
* @author ding
*/
@Data
@Accessors(chain = true)
public class ErrorCodeDeleteDTO {
@NotNull(message = "错误码编号不能为空")
private Integer id;
}

View File

@ -0,0 +1,21 @@
package cn.iocoder.mall.system.biz.dto.errorcode;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Collection;
/**
* todo
* @author ding
*/
@Data
@Accessors(chain = true)
public class ErrorCodeGetListDTO {
/**
*
*
*
*/
private Collection<Integer> codes;
}

View File

@ -0,0 +1,10 @@
package cn.iocoder.mall.system.biz.dto.errorcode;
import cn.iocoder.common.framework.vo.PageParam;
/**
* @author ding
*/
public class ErrorCodePageDTO extends PageParam {
}

View File

@ -0,0 +1,32 @@
package cn.iocoder.mall.system.biz.dto.errorcode;
import cn.iocoder.mall.system.biz.enums.errorcode.ErrorCodeTypeEnum;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
/**
* @author ding
*/
@Data
@Accessors(chain = true)
public class ErrorCodeUpdateDTO {
/**
* ,id
*/
// TODO FROM 芋艿 to 鱿鱼丝:必要的参数校验噢
private Integer id;
@NotNull(message = "错误码编码不能为空")
private Integer code;
/**
*
*/
private String message;
/**
* {@link ErrorCodeTypeEnum}
*/
private Integer type;
}

Some files were not shown because too many files have changed in this diff Show More