Banner 的迁移
商品推荐的迁移
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package cn.iocoder.mall.shopweb.controller.promotion;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.shopweb.controller.promotion.vo.brand.BannerRespVO;
|
||||
import cn.iocoder.mall.shopweb.manager.promotion.BannerManager;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/promotion/banner")
|
||||
@Api(tags = "Banner API")
|
||||
@Validated
|
||||
public class BannerController {
|
||||
|
||||
@Autowired
|
||||
private BannerManager bannerManager;
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得所有 Banner 列表")
|
||||
public CommonResult<List<BannerRespVO>> listBanners() {
|
||||
return success(bannerManager.listBanners());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package cn.iocoder.mall.shopweb.controller.promotion;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuRespVO;
|
||||
import cn.iocoder.mall.shopweb.manager.promotion.ProductRecommendManager;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/promotion/product-recommend")
|
||||
@Api(tags = "商品推荐 API")
|
||||
@Validated
|
||||
public class ProductRecommendController {
|
||||
|
||||
@Autowired
|
||||
private ProductRecommendManager productRecommendManager;
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得所有商品推荐列表")
|
||||
public CommonResult<Map<Integer, Collection<ProductSpuRespVO>>> list() {
|
||||
return success(productRecommendManager.listProductRecommends());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.iocoder.mall.shopweb.controller.promotion.vo.brand;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@ApiModel("Banner Response VO")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class BannerRespVO {
|
||||
|
||||
@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;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.iocoder.mall.shopweb.convert.promotion;
|
||||
|
||||
import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerRespDTO;
|
||||
import cn.iocoder.mall.shopweb.controller.promotion.vo.brand.BannerRespVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface BannerConvert {
|
||||
|
||||
BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class);
|
||||
|
||||
List<BannerRespVO> convertList(List<BannerRespDTO> list);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.iocoder.mall.shopweb.convert.promotion;
|
||||
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuRespVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface ProductRecommendConvert {
|
||||
|
||||
ProductRecommendConvert INSTANCE = Mappers.getMapper(ProductRecommendConvert.class);
|
||||
|
||||
ProductSpuRespVO convert(ProductSpuRespDTO bean);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package cn.iocoder.mall.shopweb.manager.promotion;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.promotion.api.rpc.banner.BannerRpc;
|
||||
import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerListReqDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerRespDTO;
|
||||
import cn.iocoder.mall.shopweb.controller.promotion.vo.brand.BannerRespVO;
|
||||
import cn.iocoder.mall.shopweb.convert.promotion.BannerConvert;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Banner Manager
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class BannerManager {
|
||||
|
||||
@DubboReference(version = "${dubbo.consumer.BannerRpc.version}")
|
||||
private BannerRpc bannerRpc;
|
||||
|
||||
public List<BannerRespVO> listBanners() {
|
||||
// 获取 Banner 列表
|
||||
CommonResult<List<BannerRespDTO>> listBannersResult = bannerRpc.listBanners(
|
||||
new BannerListReqDTO().setStatus(CommonStatusEnum.ENABLE.getValue()));
|
||||
listBannersResult.checkError();
|
||||
// 排序返回
|
||||
listBannersResult.getData().sort(Comparator.comparing(BannerRespDTO::getSort));
|
||||
return BannerConvert.INSTANCE.convertList(listBannersResult.getData());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package cn.iocoder.mall.shopweb.manager.promotion;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.util.CollectionUtils;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
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.ProductRecommendListReqDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendRespDTO;
|
||||
import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuRespVO;
|
||||
import cn.iocoder.mall.shopweb.convert.promotion.ProductRecommendConvert;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
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;
|
||||
|
||||
public Map<Integer, Collection<ProductSpuRespVO>> listProductRecommends() {
|
||||
// 查询商品推荐列表
|
||||
CommonResult<List<ProductRecommendRespDTO>> listProductRecommendsResult = productRecommendRpc.listProductRecommends(
|
||||
new ProductRecommendListReqDTO().setStatus(CommonStatusEnum.ENABLE.getValue()));
|
||||
listProductRecommendsResult.checkError();
|
||||
listProductRecommendsResult.getData().sort(Comparator.comparing(ProductRecommendRespDTO::getSort)); // 排序,按照 sort 升序
|
||||
// 获得商品集合
|
||||
Map<Integer, ProductSpuRespDTO> spuMap = this.getProductSkuMap(listProductRecommendsResult.getData());
|
||||
// 组合结果,返回
|
||||
Multimap<Integer, ProductSpuRespVO> result = HashMultimap.create();
|
||||
listProductRecommendsResult.getData().forEach(productRecommendBO -> result.put(productRecommendBO.getType(),
|
||||
ProductRecommendConvert.INSTANCE.convert(spuMap.get(productRecommendBO.getProductSpuId()))));
|
||||
return result.asMap();
|
||||
}
|
||||
|
||||
private Map<Integer, ProductSpuRespDTO> getProductSkuMap(List<ProductRecommendRespDTO> productRecommends) {
|
||||
CommonResult<List<ProductSpuRespDTO>> listProductSpusResult = productSpuRpc.listProductSpus(
|
||||
CollectionUtils.convertSet(productRecommends, ProductRecommendRespDTO::getProductSpuId));
|
||||
listProductSpusResult.checkError();
|
||||
return CollectionUtils.convertMap(listProductSpusResult.getData(), ProductSpuRespDTO::getId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,6 +49,10 @@ dubbo:
|
||||
version: 1.0.0
|
||||
CouponTemplateRpc:
|
||||
version: 1.0.0
|
||||
BannerRpc:
|
||||
version: 1.0.0
|
||||
ProductRecommendRpc:
|
||||
version: 1.0.0
|
||||
|
||||
# Swagger 配置项
|
||||
swagger:
|
||||
|
||||
Reference in New Issue
Block a user