Banner 的迁移

商品推荐的迁移
This commit is contained in:
YunaiV
2020-08-24 20:14:06 +08:00
parent c94fae173e
commit f0999eac46
65 changed files with 1195 additions and 1448 deletions

View File

@@ -0,0 +1,65 @@
package cn.iocoder.mall.managementweb.controller.promotion.brand;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerCreateReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerPageReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerRespVO;
import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerUpdateReqVO;
import cn.iocoder.mall.managementweb.manager.promotion.brand.BannerManager;
import cn.iocoder.security.annotations.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* Banner Controller
*/
@RestController
@RequestMapping("/promotion/banner")
@Api(tags = "Banner API")
@Validated
public class BannerController {
@Autowired
private BannerManager bannerManager;
@PostMapping("/create")
@ApiOperation("创建 Banner")
@RequiresPermissions("promotion:banner:create")
public CommonResult<Integer> createBanner(@Valid BannerCreateReqVO createVO) {
return success(bannerManager.createBanner(createVO));
}
@PostMapping("/update")
@ApiOperation("更新 Banner")
@RequiresPermissions("promotion:banner:update")
public CommonResult<Boolean> updateBanner(@Valid BannerUpdateReqVO updateVO) {
bannerManager.updateBanner(updateVO);
return success(true);
}
@PostMapping("/delete")
@ApiOperation("删除 Banner")
@ApiImplicitParam(name = "bannerId", value = " Banner 编号", required = true)
@RequiresPermissions("promotion:banner:delete")
public CommonResult<Boolean> deleteBanner(@RequestParam("bannerId") Integer bannerId) {
bannerManager.deleteBanner(bannerId);
return success(true);
}
@GetMapping("/page")
@ApiOperation("获得 Banner 分页")
@RequiresPermissions("promotion:banner:page")
public CommonResult<PageResult<BannerRespVO>> pageBanner(BannerPageReqVO pageVO) {
return success(bannerManager.pageBanner(pageVO));
}
}

View File

@@ -0,0 +1,43 @@
package cn.iocoder.mall.managementweb.controller.promotion.brand.vo;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.validator.InEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.URL;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@ApiModel("Banner 创建 Request VO")
@Data
public class BannerCreateReqVO {
@ApiModelProperty(value = "标题", required = true, example = "活动 A")
@NotEmpty(message = "标题不能为空")
@Length(min = 2, max = 32, message = "标题长度为 2-32 位")
private String title;
@ApiModelProperty(value = "跳转链接", required = true, example = "http://www.baidu.com")
@NotEmpty(message = "跳转链接不能为空")
@URL(message = "跳转链接格式不正确")
@Length(max = 255, message = "跳转链接最大长度为 255 位")
private String url;
@ApiModelProperty(value = "跳转链接", required = true, example = "http://www.iocoder.cn/01.jpg")
@NotEmpty(message = "跳转链接不能为空")
@URL(message = "图片链接格式不正确")
@Length(max = 255, message = "图片链接最大长度为 255 位")
private String picUrl;
@ApiModelProperty(value = "排序", required = true, example = "10")
@NotNull(message = "排序不能为空")
private Integer sort;
@ApiModelProperty(value = "状态", required = true, example = "1")
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
@ApiModelProperty(value = "备注", example = "这个活动很牛逼")
@Length(max = 255, message = "备注最大长度为 255 位")
private String memo;
}

View File

@@ -0,0 +1,17 @@
package cn.iocoder.mall.managementweb.controller.promotion.brand.vo;
import cn.iocoder.common.framework.vo.PageParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ApiModel("Banner 分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class BannerPageReqVO extends PageParam {
@ApiModelProperty(value = "标题", required = true, example = "活动 A")
private String title;
}

View File

@@ -0,0 +1,32 @@
package cn.iocoder.mall.managementweb.controller.promotion.brand.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
@ApiModel("Banner VO")
@Data
@Accessors(chain = true)
public class BannerRespVO {
@ApiModelProperty(value = "Banner 编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "标题", required = true, example = "活动 A")
private String title;
@ApiModelProperty(value = "跳转链接", required = true, example = "http://www.baidu.com")
private String url;
@ApiModelProperty(value = "图片链接", required = true, example = "http://www.iocoder.cn/01.jpg")
private String picUrl;
@ApiModelProperty(value = "排序", required = true, example = "10")
private Integer sort;
@ApiModelProperty(value = "状态", required = true, example = "1")
private Integer status;
@ApiModelProperty(value = "备注", example = "这个活动很牛逼")
private String memo;
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
private Date createTime;
}

View File

@@ -0,0 +1,43 @@
package cn.iocoder.mall.managementweb.controller.promotion.brand.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.URL;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@ApiModel("Banner 更新 Request VO")
@Data
public class BannerUpdateReqVO {
@ApiModelProperty(value = "Banner 编号", required = true, example = "1")
@NotNull(message = "编号不能为空")
private Integer id;
@ApiModelProperty(value = "标题", required = true, example = "活动 A")
@NotEmpty(message = "标题不能为空")
@Length(min = 2, max = 32, message = "标题长度为 2-32 位")
private String title;
@ApiModelProperty(value = "跳转链接", required = true, example = "http://www.baidu.com")
@NotEmpty(message = "跳转链接不能为空")
@URL(message = "跳转链接格式不正确")
@Length(max = 255, message = "跳转链接最大长度为 255 位")
private String url;
@ApiModelProperty(value = "跳转链接", required = true, example = "http://www.iocoder.cn/01.jpg")
@NotEmpty(message = "跳转链接不能为空")
@URL(message = "图片链接格式不正确")
@Length(max = 255, message = "图片链接最大长度为 255 位")
private String picUrl;
@ApiModelProperty(value = "排序", required = true, example = "10")
@NotNull(message = "排序不能为空")
private Integer sort;
@ApiModelProperty(value = "状态", required = true, example = "1")
@NotNull(message = "状态不能为空")
private Integer status;
@ApiModelProperty(value = "备注", example = "这个活动很牛逼")
@Length(max = 255, message = "备注最大长度为 255 位")
private String memo;
}

View File

@@ -0,0 +1,60 @@
package cn.iocoder.mall.managementweb.controller.promotion.recommend;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendCreateReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendDetailVO;
import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendPageReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendUpdateReqVO;
import cn.iocoder.mall.managementweb.manager.promotion.recommend.ProductRecommendManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* 商品推荐 Controller
*/
@RestController
@RequestMapping("/promotion/product-recommend")
@Api(tags = "商品推荐")
@Validated
public class ProductRecommendController {
@Autowired
private ProductRecommendManager productRecommendManager;
@PostMapping("/create")
@ApiOperation("创建商品推荐")
public CommonResult<Integer> createProductRecommend(@Valid ProductRecommendCreateReqVO createVO) {
return success(productRecommendManager.createProductRecommend(createVO));
}
@PostMapping("/update")
@ApiOperation("更新商品推荐")
public CommonResult<Boolean> updateProductRecommend(@Valid ProductRecommendUpdateReqVO updateVO) {
productRecommendManager.updateProductRecommend(updateVO);
return success(true);
}
@PostMapping("/delete")
@ApiOperation("删除商品推荐")
@ApiImplicitParam(name = "productRecommendId", value = "商品推荐编号", required = true)
public CommonResult<Boolean> deleteProductRecommend(@RequestParam("productRecommendId") Integer productRecommendId) {
productRecommendManager.deleteProductRecommend(productRecommendId);
return success(true);
}
@GetMapping("/page")
@ApiOperation("获得商品推荐分页")
public CommonResult<PageResult<ProductRecommendDetailVO>> pageProductRecommend(ProductRecommendPageReqVO pageVO) {
return success(productRecommendManager.pageProductRecommend(pageVO));
}
}

View File

@@ -0,0 +1,33 @@
package cn.iocoder.mall.managementweb.controller.promotion.recommend.vo;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
@ApiModel("商品推荐创建 Request VO")
@Data
public class ProductRecommendCreateReqVO {
@ApiModelProperty(value = "类型", example = "1", required = true, notes = "参见 ProductRecommendTypeEnum 枚举")
@NotNull(message = "类型不能为空")
@InEnum(value = ProductRecommendTypeEnum.class, message = "推荐类型必须是 {value}")
private Integer type;
@ApiModelProperty(value = "商品 Spu 编号", required = true, example = "1")
@NotNull(message = "商品 Spu 编号不能为空")
private Integer productSpuId;
@ApiModelProperty(value = "排序", required = true, example = "1")
@NotNull(message = "排序不能为空")
private Integer sort;
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举")
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
@ApiModelProperty(value = "备注", example = "我是备注")
private String memo;
}

View File

@@ -0,0 +1,43 @@
package cn.iocoder.mall.managementweb.controller.promotion.recommend.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
@ApiModel("商品推荐明细 VO")
@Data
@Accessors(chain = true)
public class ProductRecommendDetailVO {
@ApiModelProperty(value = "编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "推荐类型", required = true, example = "1", notes = "参见 ProductRecommendTypeEnum 枚举")
private Integer type;
@ApiModelProperty(value = "商品编号", required = true, example = "1")
private Integer productSpuId;
@ApiModelProperty(value = "排序", required = true, example = "10")
private Integer sort;
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举")
private Integer status;
@ApiModelProperty(value = "备注", required = true, example = "这个活动很牛逼")
private String memo;
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
private Date createTime;
/**
* 商品信息
*/
private Spu spu;
@ApiModel("商品信息")
@Data
public static class Spu {
@ApiModelProperty(value = "SPU 名字", required = true, example = "厮大牛逼")
private String name;
}
}

View File

@@ -0,0 +1,20 @@
package cn.iocoder.mall.managementweb.controller.promotion.recommend.vo;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.common.framework.vo.PageParam;
import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ApiModel("商品推荐分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class ProductRecommendPageReqVO extends PageParam {
@ApiModelProperty(value = "类型", example = "1", notes = "参见 ProductRecommendTypeEnum 枚举")
@InEnum(value = ProductRecommendTypeEnum.class, message = "推荐类型必须是 {value}")
private Integer type;
}

View File

@@ -0,0 +1,36 @@
package cn.iocoder.mall.managementweb.controller.promotion.recommend.vo;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
@ApiModel("商品推荐更新 Request VO")
@Data
public class ProductRecommendUpdateReqVO {
@ApiModelProperty(value = "编号", required = true, example = "1")
@NotNull(message = "编号不能为空")
private Integer id;
@ApiModelProperty(value = "类型", example = "1", required = true, notes = "参见 ProductRecommendTypeEnum 枚举")
@NotNull(message = "类型不能为空")
@InEnum(value = ProductRecommendTypeEnum.class, message = "推荐类型必须是 {value}")
private Integer type;
@ApiModelProperty(value = "商品 Spu 编号", required = true, example = "1")
@NotNull(message = "商品 Spu 编号不能为空")
private Integer productSpuId;
@ApiModelProperty(value = "排序", required = true, example = "1")
@NotNull(message = "排序不能为空")
private Integer sort;
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举")
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
@ApiModelProperty(value = "备注", example = "我是备注")
private String memo;
}

View File

@@ -0,0 +1,28 @@
package cn.iocoder.mall.managementweb.convert.promotion;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerCreateReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerPageReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerRespVO;
import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerUpdateReqVO;
import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerCreateReqDTO;
import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerPageReqDTO;
import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerRespDTO;
import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerUpdateReqDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface BannerConvert {
BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class);
BannerCreateReqDTO convert(BannerCreateReqVO bean);
BannerUpdateReqDTO convert(BannerUpdateReqVO bean);
BannerPageReqDTO convert(BannerPageReqVO bean);
PageResult<BannerRespVO> convertPage(PageResult<BannerRespDTO> page);
}

View File

@@ -1,4 +1,4 @@
package cn.iocoder.mall.managementweb.convert.promotion.coupon;
package cn.iocoder.mall.managementweb.convert.promotion;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardCreateReqVO;

View File

@@ -0,0 +1,31 @@
package cn.iocoder.mall.managementweb.convert.promotion;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendCreateReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendDetailVO;
import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendPageReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendUpdateReqVO;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendCreateReqDTO;
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendPageReqDTO;
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendRespDTO;
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendUpdateReqDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface ProductRecommendConvert {
ProductRecommendConvert INSTANCE = Mappers.getMapper(ProductRecommendConvert.class);
ProductRecommendCreateReqDTO convert(ProductRecommendCreateReqVO bean);
ProductRecommendUpdateReqDTO convert(ProductRecommendUpdateReqVO bean);
ProductRecommendPageReqDTO convert(ProductRecommendPageReqVO bean);
PageResult<ProductRecommendDetailVO> convertPage(PageResult<ProductRecommendRespDTO> page);
ProductRecommendDetailVO.Spu convert(ProductSpuRespDTO bean);
}

View File

@@ -1,4 +1,4 @@
package cn.iocoder.mall.managementweb.convert.promotion.activity;
package cn.iocoder.mall.managementweb.convert.promotion;
import cn.iocoder.mall.managementweb.controller.promotion.activity.vo.PromotionActivityPageReqVO;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityPageReqDTO;

View File

@@ -3,7 +3,7 @@ package cn.iocoder.mall.managementweb.manager.promotion.activity;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.promotion.activity.vo.PromotionActivityPageReqVO;
import cn.iocoder.mall.managementweb.convert.promotion.activity.PromotionActivityConvert;
import cn.iocoder.mall.managementweb.convert.promotion.PromotionActivityConvert;
import cn.iocoder.mall.promotion.api.rpc.activity.PromotionActivityRpc;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
import org.apache.dubbo.config.annotation.DubboReference;

View File

@@ -0,0 +1,68 @@
package cn.iocoder.mall.managementweb.manager.promotion.brand;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerCreateReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerPageReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerRespVO;
import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerUpdateReqVO;
import cn.iocoder.mall.managementweb.convert.promotion.BannerConvert;
import cn.iocoder.mall.promotion.api.rpc.banner.BannerRpc;
import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerRespDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
/**
* Banner Manager
*/
@Service
public class BannerManager {
@DubboReference(version = "${dubbo.consumer.BannerRpc.version}")
private BannerRpc bannerRpc;
/**
* 创建 Banner
*
* @param createVO 创建 Banner VO
* @return Banner
*/
public Integer createBanner(BannerCreateReqVO createVO) {
CommonResult<Integer> createBannerResult = bannerRpc.createBanner(BannerConvert.INSTANCE.convert(createVO));
createBannerResult.checkError();
return createBannerResult.getData();
}
/**
* 更新 Banner
*
* @param updateVO 更新 Banner VO
*/
public void updateBanner(BannerUpdateReqVO updateVO) {
CommonResult<Boolean> updateBannerResult = bannerRpc.updateBanner(BannerConvert.INSTANCE.convert(updateVO));
updateBannerResult.checkError();
}
/**
* 删除 Banner
*
* @param bannerId Banner 编号
*/
public void deleteBanner(Integer bannerId) {
CommonResult<Boolean> deleteBannerResult = bannerRpc.deleteBanner(bannerId);
deleteBannerResult.checkError();
}
/**
* 获得 Banner 分页
*
* @param pageVO Banner 分页查询
* @return Banner 分页结果
*/
public PageResult<BannerRespVO> pageBanner(BannerPageReqVO pageVO) {
CommonResult<PageResult<BannerRespDTO>> pageBannerResult = bannerRpc.pageBanner(BannerConvert.INSTANCE.convert(pageVO));
pageBannerResult.checkError();
return BannerConvert.INSTANCE.convertPage(pageBannerResult.getData());
}
}

View File

@@ -6,7 +6,7 @@ import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.Cou
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardUpdateReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplatePageReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateRespVO;
import cn.iocoder.mall.managementweb.convert.promotion.coupon.CouponTemplateConvert;
import cn.iocoder.mall.managementweb.convert.promotion.CouponTemplateConvert;
import cn.iocoder.mall.promotion.api.rpc.coupon.CouponTemplateRpc;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponCardTemplateUpdateStatusReqDTO;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponTemplateRespDTO;

View File

@@ -0,0 +1,91 @@
package cn.iocoder.mall.managementweb.manager.promotion.recommend;
import cn.iocoder.common.framework.util.CollectionUtils;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendCreateReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendDetailVO;
import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendPageReqVO;
import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendUpdateReqVO;
import cn.iocoder.mall.managementweb.convert.promotion.ProductRecommendConvert;
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
import cn.iocoder.mall.promotion.api.rpc.recommend.ProductRecommendRpc;
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendRespDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.List;
import java.util.Map;
/**
* 商品推荐 Manager
*/
@Service
@Validated
public class ProductRecommendManager {
@DubboReference(version = "${dubbo.consumer.ProductRecommendRpc.version}")
private ProductRecommendRpc productRecommendRpc;
@DubboReference(version = "${dubbo.consumer.ProductSpuRpc.version}")
private ProductSpuRpc productSpuRpc;
/**
* 创建商品推荐
*
* @param createVO 创建商品推荐 VO
* @return 商品推荐
*/
public Integer createProductRecommend(ProductRecommendCreateReqVO createVO) {
CommonResult<Integer> createProductRecommendResult = productRecommendRpc.createProductRecommend(
ProductRecommendConvert.INSTANCE.convert(createVO));
createProductRecommendResult.checkError();
return createProductRecommendResult.getData();
}
/**
* 更新商品推荐
*
* @param updateVO 更新商品推荐 VO
*/
public void updateProductRecommend(ProductRecommendUpdateReqVO updateVO) {
CommonResult<Boolean> updateProductRecommendResult = productRecommendRpc.updateProductRecommend(
ProductRecommendConvert.INSTANCE.convert(updateVO));
updateProductRecommendResult.checkError();
}
/**
* 删除商品推荐
*
* @param productRecommendId 商品推荐编号
*/
public void deleteProductRecommend(Integer productRecommendId) {
CommonResult<Boolean> deleteProductRecommendResult = productRecommendRpc.deleteProductRecommend(productRecommendId);
deleteProductRecommendResult.checkError();
}
/**
* 获得商品推荐分页
*
* @param pageVO 商品推荐分页查询
* @return 商品推荐分页结果
*/
public PageResult<ProductRecommendDetailVO> pageProductRecommend(ProductRecommendPageReqVO pageVO) {
CommonResult<PageResult<ProductRecommendRespDTO>> pageProductRecommendResult = productRecommendRpc.pageProductRecommend(ProductRecommendConvert.INSTANCE.convert(pageVO));
pageProductRecommendResult.checkError();
// 拼接结果
PageResult<ProductRecommendDetailVO> pageResult = ProductRecommendConvert.INSTANCE.convertPage(pageProductRecommendResult.getData());
if (!CollectionUtils.isEmpty(pageResult.getList())) {
// 获取商品信息,并进行拼接
CommonResult<List<ProductSpuRespDTO>> listProductSpusResult = productSpuRpc.listProductSpus(
CollectionUtils.convertSet(pageResult.getList(), ProductRecommendDetailVO::getProductSpuId));
listProductSpusResult.checkError();
Map<Integer, ProductSpuRespDTO> productSpuMap = CollectionUtils.convertMap(listProductSpusResult.getData(), ProductSpuRespDTO::getId);
pageResult.getList().forEach(detailVO ->
detailVO.setSpu(ProductRecommendConvert.INSTANCE.convert(productSpuMap.get(detailVO.getProductSpuId()))));
}
return pageResult;
}
}