提交 d67e324a 作者: xiaowang

新增推荐

上级 2a149a99
......@@ -2,10 +2,9 @@ package com.mmc.pms.controller.mall;
import com.mmc.pms.common.ResultBody;
import com.mmc.pms.controller.BaseController;
import com.mmc.pms.entity.mall.MallGoodsDO;
import com.mmc.pms.entity.mall.ProductBrowseDO;
import com.mmc.pms.model.mall.GoodsListVO;
import com.mmc.pms.model.mall.MallGoodsVO;
import com.mmc.pms.model.mall.RecommendVO;
import com.mmc.pms.model.mall.UavCartDTO;
import com.mmc.pms.model.qo.mall.PriceStockQO;
import com.mmc.pms.model.sale.qo.MallGoodsInfoQO;
......@@ -71,10 +70,11 @@ public class AppMallGoodsController extends BaseController {
public ResultBody<MallGoodsVO> listMallGoodsBySearch(@ApiParam("商品查询条件QO") @RequestBody MallGoodsInfoQO param, HttpServletRequest request) {
return ResultBody.success(mallGoodsService.listMallGoodsBySearch(param, this.getUserLoginInfoFromRedis(request)));
}
@ApiOperation(value = "商品浏览排行榜")
@PostMapping("browseMallGoods")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = MallGoodsVO.class)})
public ResultBody<MallGoodsVO> browseMallGoods(@RequestBody MallGoodsDO mallGoodsDO, ProductBrowseDO productBrowseDO, HttpServletRequest request){
return appMallGoodsService.browseMallGoods(mallGoodsDO,productBrowseDO,this.getUserLoginInfoFromRedis(request));
@ApiOperation(value = "推荐商品")
@GetMapping("recommend")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = RecommendVO.class)})
public ResultBody<RecommendVO> recommend() {
return appMallGoodsService.recommend();
}
}
......@@ -57,4 +57,6 @@ public interface CategoryDao {
Integer selectSubMallGoods(Integer id);
Integer selectPrimary(Integer id);
List<CategoryPrimaryDO> selectPrimaryListByIds(List<Integer> ids);
}
......@@ -66,4 +66,6 @@ public interface MallGoodsDao {
void updateSpecAttrValue(SpecAttrVO attrVO);
int getMallGoodsCount();
List<MallGoodsDO> recommendMallGoods();
}
package com.mmc.pms.model.mall;
import com.mmc.pms.model.category.dto.CategoryPrimaryDTO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* @Author LW
* @date 2023/10/17 14:03
* 概要:
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class RecommendVO implements Serializable {
private CategoryPrimaryDTO categoryPrimaryDTO;
private List<MallGoodsVO> mallGoodsList;
}
package com.mmc.pms.service.mall;
import com.mmc.pms.auth.dto.LoginSuccessDTO;
import com.mmc.pms.common.ResultBody;
import com.mmc.pms.entity.mall.MallGoodsDO;
import com.mmc.pms.entity.mall.ProductBrowseDO;
import com.mmc.pms.model.mall.GoodsListVO;
import com.mmc.pms.model.mall.MallGoodsVO;
import com.mmc.pms.model.mall.RecommendVO;
import com.mmc.pms.model.mall.UavCartDTO;
import com.mmc.pms.model.qo.mall.PriceStockQO;
......@@ -25,5 +23,6 @@ public interface AppMallGoodsService {
List<UavCartDTO> listPriceStock(List<PriceStockQO> priceStockQOS);
ResultBody<MallGoodsVO> browseMallGoods(MallGoodsDO mallGoodsDO, ProductBrowseDO productBrowseDO, LoginSuccessDTO userLoginInfoFromRedis);
ResultBody<RecommendVO> recommend();
}
package com.mmc.pms.service.mall.impl;
import com.mmc.pms.auth.dto.LoginSuccessDTO;
import com.mmc.pms.common.ResultBody;
import com.mmc.pms.dao.category.CategoryDao;
import com.mmc.pms.dao.mall.AppMallGoodsDao;
import com.mmc.pms.dao.mall.MallGoodsDao;
import com.mmc.pms.entity.category.CategoryPrimaryDO;
import com.mmc.pms.entity.mall.MallGoodsDO;
import com.mmc.pms.entity.mall.PriceStockDO;
import com.mmc.pms.entity.mall.ProductBrowseDO;
import com.mmc.pms.model.category.dto.CategoryPrimaryDTO;
import com.mmc.pms.model.mall.GoodsListVO;
import com.mmc.pms.model.mall.MallGoodsVO;
import com.mmc.pms.model.mall.RecommendVO;
import com.mmc.pms.model.mall.UavCartDTO;
import com.mmc.pms.model.qo.mall.PriceStockQO;
import com.mmc.pms.service.mall.AppMallGoodsService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
......@@ -31,6 +33,10 @@ import java.util.stream.Collectors;
public class AppMallGoodsServiceImpl implements AppMallGoodsService {
@Resource
private AppMallGoodsDao appMallGoodsDao;
@Resource
private MallGoodsDao mallGoodsDao;
@Resource
private CategoryDao categoryDao;
@Override
public ResultBody<MallGoodsVO> queryBrandGoods(Integer userAccountId) {
......@@ -91,18 +97,28 @@ public class AppMallGoodsServiceImpl implements AppMallGoodsService {
}
@Override
@Transactional
public ResultBody<MallGoodsVO> browseMallGoods(MallGoodsDO mallGoodsDO, ProductBrowseDO productBrowseDO, LoginSuccessDTO userLoginInfoFromRedis) {
//获取当前用户id
Integer userAccountId = userLoginInfoFromRedis.getUserAccountId();
//记录查看商品的用户id
productBrowseDO.setUserId(userAccountId);
if(productBrowseDO.getUserId() != null){
Integer hot = mallGoodsDO.getHot();
hot++;
public ResultBody<RecommendVO> recommend() {
// 获取所有属于推荐的商品
List<MallGoodsDO> mallGoodsList = mallGoodsDao.recommendMallGoods();
if (mallGoodsList.size() == 0) {
return ResultBody.success();
}
return null;
List<RecommendVO> recommendList = new ArrayList<>();
// 获取所有一级分类
List<Integer> categoryPrimaryIdList = mallGoodsList.stream().map(MallGoodsDO::getCategoryPrimaryId).distinct().collect(Collectors.toList());
// 根据一级分类的id进行分组
Map<Integer, List<MallGoodsDO>> goodMap = mallGoodsList.stream().collect(Collectors.groupingBy(MallGoodsDO::getCategoryPrimaryId));
// 根据一级分类集合查询分类信息
List<CategoryPrimaryDO> categoryPrimaryList = categoryDao.selectPrimaryListByIds(categoryPrimaryIdList);
List<CategoryPrimaryDTO> primaryList = categoryPrimaryList.stream()
.map(CategoryPrimaryDO::buildCategoryPrimaryDTO).collect(Collectors.toList());
primaryList.forEach(categoryPrimaryDTO -> {
List<MallGoodsDO> goodsDOList = goodMap.get(categoryPrimaryDTO.getId());
RecommendVO recommendVO = new RecommendVO();
recommendVO.setCategoryPrimaryDTO(categoryPrimaryDTO);
recommendVO.setMallGoodsList(goodsDOList.stream().map(MallGoodsDO::buildListMallGoodsVO).collect(Collectors.toList()));
recommendList.add(recommendVO);
});
return ResultBody.success(recommendList);
}
}
......@@ -225,5 +225,20 @@
from mall_goods
where category_primary_id = #{id}
</select>
<select id="selectPrimaryListByIds" resultType="com.mmc.pms.entity.category.CategoryPrimaryDO">
select id,
`name`,
description,
create_time,
icon,
sort
from category_primary
<where>
<foreach collection="list" item="item" open="id in (" close=")" separator=",">
#{item}
</foreach>
</where>
order by sort desc, update_time desc, create_time desc
</select>
</mapper>
......@@ -274,4 +274,24 @@
FROM mall_goods
WHERE is_deleted = 0
</select>
<select id="recommendMallGoods" resultType="com.mmc.pms.entity.mall.MallGoodsDO">
SELECT mg.id,
mg.trade_name,
mg.shelf_status,
mg.create_time,
mg.category_primary_id,
mg.category_sub_id,
mg.user_account_id,
mg.description,
mg.price_show,
mg.recommend,
img.id as imgId,
img.url,
img.type
FROM mall_goods mg
INNER JOIN mall_goods_resources img ON mg.id = img.mall_goods_id
AND img.type = 0
where mg.is_deleted = 0
and mg.recommend = 1
</select>
</mapper>
......@@ -37,3 +37,4 @@ data-filter:
- /pms/company-inspection/listInspectionPriceUnit
- /pms/lease/goods/feignLeaseGoodsInfoByAddressId
- /pms/industry/listIndustry
- /pms/app/goods/recommend
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论