后端:增加 H5 需要的商品推荐接口

pull/1/head
YunaiV 2019-03-31 18:43:40 +08:00
parent b333340c20
commit 6699bd34a8
10 changed files with 207 additions and 23 deletions

View File

@ -19,8 +19,8 @@ if (process.env.NODE_ENV == 'development') {
// baseUrl = 'http://127.0.0.1'; // baseUrl = 'http://127.0.0.1';
// baseUrl = 'http://180.167.213.26:18099'; // baseUrl = 'http://180.167.213.26:18099';
dataSources = 'remote'; // dataSources = 'remote';
// dataSources = 'local'; dataSources = 'local';
export { export {
baseUrl, baseUrl,

View File

@ -1,6 +1,10 @@
<template> <template>
<div :style="'background-color:'+((page.BackgroundColor==undefined||page.BackgroundColor=='')?'#fff':page.BackgroundColor)"> <div :style="'background-color:'+((page.BackgroundColor==undefined||page.BackgroundColor=='')?'#fff':page.BackgroundColor)">
<div :style="'height:'+topheight+'px'" ></div> <div :style="'height:'+topheight+'px'" ></div>
<!-- TODO 搜索框 -->
<!-- <search v-if="item.Code=='Search'" :data="item.ParameterDictionary" v-on:settopheight="settopheight($event)" ></search>-->
<van-swipe :autoplay="3000" indicator-color="white" height="160"> <van-swipe :autoplay="3000" indicator-color="white" height="160">
<van-swipe-item v-for="(banner, index) in banners" :key="index" > <van-swipe-item v-for="(banner, index) in banners" :key="index" >
<a :href="banner.url"> <a :href="banner.url">
@ -8,26 +12,17 @@
</a> </a>
</van-swipe-item> </van-swipe-item>
</van-swipe> </van-swipe>
<van-panel title="新品推荐">
<div v-for="(item,index) in page.Sections" :key="index"> <div v-for="(item,index) in page.Sections" :key="index">
<imageText v-if="item.Code=='ImageText'" :data="item.ParameterDictionary"></imageText>
<pageLine v-if="item.Code=='Line'" :data="item.ParameterDictionary" ></pageLine>
<whitespace v-if="item.Code=='Line'" :data="item.ParameterDictionary" />
<pageText v-if="item.Code=='Text'" :data="item.ParameterDictionary" ></pageText>
<notice v-if="item.Code=='Notice'" :data="item.ParameterDictionary" ></notice>
<search v-if="item.Code=='Search'" :data="item.ParameterDictionary" v-on:settopheight="settopheight($event)" ></search>
<pageTitle v-if="item.Code=='Title'" :data="item.ParameterDictionary" ></pageTitle>
<cube v-if="item.Code=='Cube'" :data="item.ParameterDictionary" ></cube>
<product v-if="item.Code=='Product'" :data="item" ></product> <product v-if="item.Code=='Product'" :data="item" ></product>
</div> </div>
</van-panel>
<van-panel title="热卖推荐">
<div v-for="(item,index) in page.Sections" :key="index">
<product v-if="item.Code=='Product'" :data="item" ></product>
</div>
</van-panel>
</div> </div>
</template> </template>

View File

@ -2,12 +2,16 @@ package cn.iocoder.mall.order.biz.mock;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.product.api.ProductSpuService; import cn.iocoder.mall.product.api.ProductSpuService;
import cn.iocoder.mall.product.api.bo.ProductSpuBO;
import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO; import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO;
import cn.iocoder.mall.product.api.bo.ProductSpuPageBO; import cn.iocoder.mall.product.api.bo.ProductSpuPageBO;
import cn.iocoder.mall.product.api.dto.ProductSpuAddDTO; import cn.iocoder.mall.product.api.dto.ProductSpuAddDTO;
import cn.iocoder.mall.product.api.dto.ProductSpuPageDTO; import cn.iocoder.mall.product.api.dto.ProductSpuPageDTO;
import cn.iocoder.mall.product.api.dto.ProductSpuUpdateDTO; import cn.iocoder.mall.product.api.dto.ProductSpuUpdateDTO;
import java.util.Collection;
import java.util.List;
/** /**
* @author Sin * @author Sin
* @time 2019-03-24 15:24 * @time 2019-03-24 15:24
@ -37,4 +41,9 @@ public class ProductSpuServiceMock implements ProductSpuService {
public CommonResult<ProductSpuPageBO> getProductSpuPage(ProductSpuPageDTO productSpuPageDTO) { public CommonResult<ProductSpuPageBO> getProductSpuPage(ProductSpuPageDTO productSpuPageDTO) {
return null; return null;
} }
@Override
public CommonResult<List<ProductSpuBO>> getProductSpuList(Collection<Integer> ids) {
return null;
}
} }

View File

@ -1,12 +1,16 @@
package cn.iocoder.mall.product.api; package cn.iocoder.mall.product.api;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.product.api.bo.ProductSpuBO;
import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO; import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO;
import cn.iocoder.mall.product.api.bo.ProductSpuPageBO; import cn.iocoder.mall.product.api.bo.ProductSpuPageBO;
import cn.iocoder.mall.product.api.dto.ProductSpuAddDTO; import cn.iocoder.mall.product.api.dto.ProductSpuAddDTO;
import cn.iocoder.mall.product.api.dto.ProductSpuPageDTO; import cn.iocoder.mall.product.api.dto.ProductSpuPageDTO;
import cn.iocoder.mall.product.api.dto.ProductSpuUpdateDTO; import cn.iocoder.mall.product.api.dto.ProductSpuUpdateDTO;
import java.util.Collection;
import java.util.List;
public interface ProductSpuService { public interface ProductSpuService {
CommonResult<ProductSpuDetailBO> getProductSpu(Integer id); CommonResult<ProductSpuDetailBO> getProductSpu(Integer id);
@ -19,4 +23,6 @@ public interface ProductSpuService {
CommonResult<ProductSpuPageBO> getProductSpuPage(ProductSpuPageDTO productSpuPageDTO); CommonResult<ProductSpuPageBO> getProductSpuPage(ProductSpuPageDTO productSpuPageDTO);
CommonResult<List<ProductSpuBO>> getProductSpuList(Collection<Integer> ids);
} }

View File

@ -4,6 +4,7 @@ import cn.iocoder.mall.product.dataobject.ProductSpuDO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List; import java.util.List;
@Repository @Repository
@ -11,6 +12,8 @@ public interface ProductSpuMapper {
ProductSpuDO selectById(Integer id); ProductSpuDO selectById(Integer id);
List<ProductSpuDO> selectByIds(Collection<Integer> ids);
void insert(ProductSpuDO productSpuDO); void insert(ProductSpuDO productSpuDO);
void update(ProductSpuDO productSpuDO); void update(ProductSpuDO productSpuDO);

View File

@ -7,6 +7,7 @@ import cn.iocoder.common.framework.util.StringUtil;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.product.api.ProductSpuService; import cn.iocoder.mall.product.api.ProductSpuService;
import cn.iocoder.mall.product.api.bo.ProductAttrAndValuePairBO; import cn.iocoder.mall.product.api.bo.ProductAttrAndValuePairBO;
import cn.iocoder.mall.product.api.bo.ProductSpuBO;
import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO; import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO;
import cn.iocoder.mall.product.api.bo.ProductSpuPageBO; import cn.iocoder.mall.product.api.bo.ProductSpuPageBO;
import cn.iocoder.mall.product.api.constant.ProductErrorCodeEnum; import cn.iocoder.mall.product.api.constant.ProductErrorCodeEnum;
@ -212,6 +213,19 @@ public class ProductSpuServiceImpl implements ProductSpuService {
return CommonResult.success(productSpuPage); return CommonResult.success(productSpuPage);
} }
@Override
public CommonResult<List<ProductSpuBO>> getProductSpuList(Collection<Integer> ids) {
List<ProductSpuDO> spus = productSpuMapper.selectByIds(ids);
return CommonResult.success(ProductSpuConvert.INSTANCE.convert(spus));
}
/**
* sku
*
* @param productSkuAddDTOs sku
* @param productAttrDetailBOs
* @return
*/
private CommonResult<Boolean> validProductSku(List<ProductSkuAddOrUpdateDTO> productSkuAddDTOs, List<ProductAttrAndValuePairBO> productAttrDetailBOs) { private CommonResult<Boolean> validProductSku(List<ProductSkuAddOrUpdateDTO> productSkuAddDTOs, List<ProductAttrAndValuePairBO> productAttrDetailBOs) {
// 创建 ProductAttrDetailBO 的映射。其中KEY 为 ProductAttrDetailBO.attrValueId ,即规格值的编号 // 创建 ProductAttrDetailBO 的映射。其中KEY 为 ProductAttrDetailBO.attrValueId ,即规格值的编号
Map<Integer, ProductAttrAndValuePairBO> productAttrDetailBOMap = productAttrDetailBOs.stream().collect( Map<Integer, ProductAttrAndValuePairBO> productAttrDetailBOMap = productAttrDetailBOs.stream().collect(
@ -241,6 +255,13 @@ public class ProductSpuServiceImpl implements ProductSpuService {
return CommonResult.success(true); return CommonResult.success(true);
} }
/**
* sku sku
*
* @param attrs
* @param skus sku
* @return sku
*/
private ProductSkuDO findProductSku(Collection<Integer> attrs, List<ProductSkuDO> skus) { private ProductSkuDO findProductSku(Collection<Integer> attrs, List<ProductSkuDO> skus) {
if (CollectionUtil.isEmpty(skus)) { if (CollectionUtil.isEmpty(skus)) {
return null; return null;
@ -256,6 +277,12 @@ public class ProductSpuServiceImpl implements ProductSpuService {
return null; return null;
} }
/**
* sku spu
*
* @param spu spu
* @param skus sku
*/
private void initSpuFromSkus(ProductSpuDO spu, List<ProductSkuAddOrUpdateDTO> skus) { private void initSpuFromSkus(ProductSpuDO spu, List<ProductSkuAddOrUpdateDTO> skus) {
assert skus.size() > 0; // 写个断言,避免下面警告 assert skus.size() > 0; // 写个断言,避免下面警告
spu.setPrice(skus.stream().min(Comparator.comparing(ProductSkuAddOrUpdateDTO::getPrice)).get().getPrice()); // 求最小价格 spu.setPrice(skus.stream().min(Comparator.comparing(ProductSkuAddOrUpdateDTO::getPrice)).get().getPrice()); // 求最小价格

View File

@ -16,6 +16,17 @@
AND deleted = 0 AND deleted = 0
</select> </select>
<select id="selectByIds" resultType="ProductSpuDO">
SELECT
<include refid="FIELDS" />
FROM product_spu
WHERE id IN
<foreach item="id" collection="ids" separator="," open="(" close=")" index="">
#{id}
</foreach>
AND deleted = 0
</select>
<insert id="insert" parameterType="ProductSpuDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id"> <insert id="insert" parameterType="ProductSpuDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
INSERT INTO product_spu ( INSERT INTO product_spu (
name, sell_point, description, cid, pic_urls, name, sell_point, description, cid, pic_urls,

View File

@ -0,0 +1,53 @@
package cn.iocoder.mall.promotion.application.controller.users;
import cn.iocoder.common.framework.constant.CommonStatusEnum;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.product.api.ProductSpuService;
import cn.iocoder.mall.product.api.bo.ProductSpuBO;
import cn.iocoder.mall.promotion.api.ProductRecommendService;
import cn.iocoder.mall.promotion.api.bo.ProductRecommendBO;
import cn.iocoder.mall.promotion.application.convert.ProductRecommendConvert;
import cn.iocoder.mall.promotion.application.vo.users.UsersProductRecommendVO;
import com.alibaba.dubbo.config.annotation.Reference;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@RestController
@RequestMapping("users/banner")
@Api("商品推荐模块")
public class UsersProductRecommendController {
@Reference(validation = "true")
private ProductRecommendService productRecommendService;
@Reference(validation = "true")
private ProductSpuService productSpuService;
@GetMapping("/list")
@ApiOperation("获得所有 Banner 列表")
public CommonResult<Multimap<Integer, UsersProductRecommendVO>> list() {
// 查询商品推荐列表
List<ProductRecommendBO> productRecommends = productRecommendService.getProductRecommendList(
null, CommonStatusEnum.ENABLE.getValue()).getData();
// 获得商品集合
List<ProductSpuBO> spus = productSpuService.getProductSpuList(
productRecommends.stream().map(ProductRecommendBO::getProductSpuId).collect(Collectors.toSet())).getData();
Map<Integer, ProductSpuBO> spuMap = spus.stream().collect(Collectors.toMap(ProductSpuBO::getId, account -> account));
// 组合结果,返回
Multimap<Integer, UsersProductRecommendVO> result = new HashMultimap<>();
productRecommends.sort(Comparator.comparing(ProductRecommendBO::getSort)); // 排序,按照 sort 升序
productRecommends.forEach(productRecommendBO -> result.put(productRecommendBO.getType(),
ProductRecommendConvert.INSTANCE.convert(spuMap.get(productRecommendBO.getProductSpuId())))); // 将 ProductSpuBO 添加到 results 中
return CommonResult.success(result);
}
}

View File

@ -1,10 +1,12 @@
package cn.iocoder.mall.promotion.application.convert; package cn.iocoder.mall.promotion.application.convert;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.product.api.bo.ProductSpuBO;
import cn.iocoder.mall.promotion.api.bo.ProductRecommendBO; import cn.iocoder.mall.promotion.api.bo.ProductRecommendBO;
import cn.iocoder.mall.promotion.api.bo.ProductRecommendPageBO; import cn.iocoder.mall.promotion.api.bo.ProductRecommendPageBO;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsProductRecommendPageVO; import cn.iocoder.mall.promotion.application.vo.admins.AdminsProductRecommendPageVO;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsProductRecommendVO; import cn.iocoder.mall.promotion.application.vo.admins.AdminsProductRecommendVO;
import cn.iocoder.mall.promotion.application.vo.users.UsersProductRecommendVO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mappings; import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
@ -23,6 +25,9 @@ public interface ProductRecommendConvert {
@Mappings({}) @Mappings({})
CommonResult<AdminsProductRecommendPageVO> convert(CommonResult<ProductRecommendPageBO> result); CommonResult<AdminsProductRecommendPageVO> convert(CommonResult<ProductRecommendPageBO> result);
@Mappings({})
UsersProductRecommendVO convert(ProductSpuBO productSpu);
// @Mappings({}) // @Mappings({})
// List<UsersProductRecommendVO> convertList(List<ProductRecommendBO> banners); // List<UsersProductRecommendVO> convertList(List<ProductRecommendBO> banners);

View File

@ -0,0 +1,75 @@
package cn.iocoder.mall.promotion.application.vo.users;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
@ApiModel(value = "商品推荐 VO", description = "不包括 SKU 信息 VO")
public class UsersProductRecommendVO {
@ApiModelProperty(value = "商品 SPU 编号", required = true, example = "1")
private Integer id;
// ========== 基本信息 =========
@ApiModelProperty(value = "SPU 名字", required = true, example = "厮大牛逼")
private String name;
@ApiModelProperty(value = "卖点", required = true, example = "各种 MQ 骚操作")
private String sellPoint;
@ApiModelProperty(value = "商品主图地址的数组", required = true, example = "http://www.iocoder.cn")
private List<String> picUrls;
// ========== Sku 相关字段 =========
/**
*
*
* Sku
*/
private Integer price;
public Integer getId() {
return id;
}
public UsersProductRecommendVO setId(Integer id) {
this.id = id;
return this;
}
public String getName() {
return name;
}
public UsersProductRecommendVO setName(String name) {
this.name = name;
return this;
}
public String getSellPoint() {
return sellPoint;
}
public UsersProductRecommendVO setSellPoint(String sellPoint) {
this.sellPoint = sellPoint;
return this;
}
public List<String> getPicUrls() {
return picUrls;
}
public UsersProductRecommendVO setPicUrls(List<String> picUrls) {
this.picUrls = picUrls;
return this;
}
public Integer getPrice() {
return price;
}
public UsersProductRecommendVO setPrice(Integer price) {
this.price = price;
return this;
}
}