mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
reafactor: 会员商品收藏
This commit is contained in:
parent
98aae5ed1a
commit
daa7d14b09
@ -133,9 +133,9 @@ public interface BaseMapperX<T> extends MPJBaseMapper<T> {
|
||||
Db.saveOrUpdateBatch(collection);
|
||||
}
|
||||
|
||||
default <DTO> PageResult<DTO> selectJoinPage(PageParam pageParam, @Param("resultTypeClass_Eg1sG") Class<DTO> var2, @Param("ew") MPJBaseJoin<T> queryWrapper) {
|
||||
default <DTO> PageResult<DTO> selectJoinPage(PageParam pageParam, Class<DTO> resultTypeClass, MPJBaseJoin<T> joinQueryWrapper) {
|
||||
IPage<DTO> mpPage = MyBatisUtils.buildPage(pageParam);
|
||||
selectJoinPage(mpPage, var2, queryWrapper);
|
||||
selectJoinPage(mpPage, resultTypeClass, joinQueryWrapper);
|
||||
// 转换返回
|
||||
return new PageResult<>(mpPage.getRecords(), mpPage.getTotal());
|
||||
}
|
||||
|
@ -4,16 +4,15 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.favorite.vo.ProductFavoriteBatchReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.favorite.vo.ProductFavoritePageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.favorite.vo.ProductFavoriteReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.favorite.vo.ProductFavoriteRespVO;
|
||||
import cn.iocoder.yudao.module.product.convert.favorite.ProductFavoriteConvert;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDetailDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
||||
import cn.iocoder.yudao.module.product.service.favorite.ProductFavoriteService;
|
||||
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -24,6 +23,7 @@ import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
|
||||
@Tag(name = "管理后台 - 商品收藏")
|
||||
@RestController
|
||||
@ -34,6 +34,9 @@ public class ProductFavoriteController {
|
||||
@Resource
|
||||
private ProductFavoriteService productFavoriteService;
|
||||
|
||||
@Resource
|
||||
private ProductSpuService productSpuService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "添加单个商品收藏")
|
||||
@PreAuthorize("@ss.hasPermission('product:favorite:create')")
|
||||
@ -41,14 +44,6 @@ public class ProductFavoriteController {
|
||||
return success(productFavoriteService.createFavorite(reqVO.getUserId(), reqVO.getSpuId()));
|
||||
}
|
||||
|
||||
@PostMapping("/create-list")
|
||||
@Operation(summary = "添加多个商品收藏")
|
||||
@PreAuthorize("@ss.hasPermission('product:favorite:create')")
|
||||
public CommonResult<Boolean> createFavoriteList(@Valid @RequestBody ProductFavoriteBatchReqVO reqVO) {
|
||||
// todo @jason:待实现;如果有已经收藏的,不用报错,忽略即可;
|
||||
return success(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "取消单个商品收藏")
|
||||
@PreAuthorize("@ss.hasPermission('product:favorite:delete')")
|
||||
@ -57,26 +52,19 @@ public class ProductFavoriteController {
|
||||
return success(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Operation(summary = "取消单个商品收藏")
|
||||
@PreAuthorize("@ss.hasPermission('product:favorite:delete')")
|
||||
public CommonResult<Boolean> deleteFavoriteList(@Valid @RequestBody ProductFavoriteBatchReqVO reqVO) {
|
||||
// todo @jason:待实现
|
||||
// productFavoriteService.deleteFavorite(getLoginUserId(), reqVO.getSpuId());
|
||||
return success(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得商品收藏分页")
|
||||
@PreAuthorize("@ss.hasPermission('product:favorite:query')")
|
||||
public CommonResult<PageResult<ProductFavoriteRespVO>> getFavoritePage(@Valid ProductFavoritePageReqVO pageVO) {
|
||||
PageResult<ProductFavoriteDetailDO> favoritePage = productFavoriteService.getFavoritePageByFilter(pageVO);
|
||||
PageResult<ProductFavoriteDO> favoritePage = productFavoriteService.getFavoritePage(pageVO);
|
||||
if (CollUtil.isEmpty(favoritePage.getList())) {
|
||||
return success(PageResult.empty());
|
||||
}
|
||||
|
||||
List<ProductSpuDO> list = productSpuService.getSpuList(convertSet(favoritePage.getList(), ProductFavoriteDO::getSpuId));
|
||||
|
||||
// 得到商品 spu 信息
|
||||
List<ProductFavoriteRespVO> favorites = ProductFavoriteConvert.INSTANCE.convertList2admin(favoritePage.getList());
|
||||
List<ProductFavoriteRespVO> favorites = ProductFavoriteConvert.INSTANCE.convertList2admin(favoritePage.getList(), list);
|
||||
|
||||
// 转换 VO 结果
|
||||
PageResult<ProductFavoriteRespVO> pageResult = new PageResult<>(favoritePage.getTotal());
|
||||
@ -92,13 +80,4 @@ public class ProductFavoriteController {
|
||||
ProductFavoriteDO favorite = productFavoriteService.getFavorite(reqVO.getUserId(), reqVO.getSpuId());
|
||||
return success(favorite != null);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/get-count")
|
||||
@Operation(summary = "获得商品收藏数量")
|
||||
@Parameter(name = "userId", description = "用户编号", required = true)
|
||||
@PreAuthenticated
|
||||
public CommonResult<Long> getFavoriteCount(@RequestParam("userId") Long userId) {
|
||||
return success(productFavoriteService.getFavoriteCount(userId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import org.mapstruct.factory.Mappers;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
|
||||
@ -41,13 +42,13 @@ public interface ProductFavoriteConvert {
|
||||
@Mapping(target = "userId", source = "favorite.userId")
|
||||
@Mapping(target = "spuId", source = "favorite.spuId")
|
||||
@Mapping(target = "createTime", source = "favorite.createTime")
|
||||
@Mapping(target = "favoriteStatus", constant = "1")
|
||||
ProductFavoriteRespVO convert2admin(ProductSpuDO spu, ProductFavoriteDO favorite);
|
||||
|
||||
default List<ProductFavoriteRespVO> convertList2admin(List<ProductFavoriteDetailDO> favorites) {
|
||||
List<ProductFavoriteRespVO> resultList = new ArrayList<>(favorites.size());
|
||||
for (ProductFavoriteDetailDO favorite : favorites) {
|
||||
resultList.add(convert2admin(favorite.getSpuDO(), favorite));
|
||||
default List<ProductFavoriteRespVO> convertList2admin(List<ProductFavoriteDO> favorites, List<ProductSpuDO> spus) {
|
||||
List<ProductFavoriteRespVO> resultList = new ArrayList<>(spus.size());
|
||||
for (ProductFavoriteDO favorite : favorites) {
|
||||
Optional<ProductSpuDO> spu = spus.stream().filter(e -> e.getId().equals(favorite.getSpuId())).findFirst();
|
||||
resultList.add(convert2admin(spu.get(), favorite));
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
@ -12,5 +12,4 @@ import lombok.Data;
|
||||
public class ProductFavoriteDetailDO extends ProductFavoriteDO {
|
||||
|
||||
ProductSpuDO spuDO;
|
||||
|
||||
}
|
||||
|
@ -5,12 +5,8 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.favorite.vo.ProductFavoritePageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDetailDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
@ -27,34 +23,11 @@ public interface ProductFavoriteMapper extends BaseMapperX<ProductFavoriteDO> {
|
||||
.orderByDesc(ProductFavoriteDO::getId));
|
||||
}
|
||||
|
||||
default PageResult<ProductFavoriteDetailDO> selectPageByUserAndFields(ProductFavoritePageReqVO reqVO) {
|
||||
MPJLambdaWrapper<ProductFavoriteDO> wrapper = new MPJLambdaWrapper<ProductFavoriteDO>()
|
||||
default PageResult<ProductFavoriteDO> selectPageByUserId(ProductFavoritePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new MPJLambdaWrapper<ProductFavoriteDO>()
|
||||
.selectAll(ProductFavoriteDO.class)
|
||||
.eq(ProductFavoriteDO::getUserId, reqVO.getUserId())
|
||||
.selectAssociation(ProductSpuDO.class, ProductFavoriteDetailDO::getSpuDO);
|
||||
if(StringUtils.isNotEmpty(reqVO.getName())){
|
||||
wrapper.likeRight(ProductSpuDO::getName, reqVO.getName());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(reqVO.getName()) && StringUtils.isNotEmpty(reqVO.getKeyword())){
|
||||
wrapper.or();
|
||||
}
|
||||
if(StringUtils.isNotEmpty(reqVO.getKeyword())){
|
||||
wrapper.likeRight(ProductSpuDO::getKeyword, reqVO.getKeyword());
|
||||
}
|
||||
|
||||
if(reqVO.getCreateTime() != null){
|
||||
if (reqVO.getCreateTime()[0] != null && reqVO.getCreateTime()[1] != null) {
|
||||
wrapper.between(ProductFavoriteDO::getCreateTime, reqVO.getCreateTime()[0], reqVO.getCreateTime()[1]);
|
||||
}
|
||||
if (reqVO.getCreateTime()[0] != null) {
|
||||
wrapper.ge(ProductFavoriteDO::getCreateTime, reqVO.getCreateTime()[0]);
|
||||
}
|
||||
if (reqVO.getCreateTime()[1] != null) {
|
||||
wrapper.le(ProductFavoriteDO::getCreateTime, reqVO.getCreateTime()[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return selectJoinPage(reqVO, ProductFavoriteDetailDO.class, wrapper);
|
||||
.orderByDesc(ProductFavoriteDO::getCreateTime));
|
||||
}
|
||||
|
||||
default Long selectCountByUserId(Long userId) {
|
||||
|
@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.favorite.vo.ProductFavoritePageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDetailDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@ -44,7 +43,7 @@ public interface ProductFavoriteService {
|
||||
*
|
||||
* @param reqVO 请求 vo
|
||||
*/
|
||||
PageResult<ProductFavoriteDetailDO> getFavoritePageByFilter(@Valid ProductFavoritePageReqVO reqVO);
|
||||
PageResult<ProductFavoriteDO> getFavoritePage(@Valid ProductFavoritePageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获取收藏过商品
|
||||
|
@ -5,7 +5,6 @@ import cn.iocoder.yudao.module.product.controller.admin.favorite.vo.ProductFavor
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO;
|
||||
import cn.iocoder.yudao.module.product.convert.favorite.ProductFavoriteConvert;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDetailDO;
|
||||
import cn.iocoder.yudao.module.product.dal.mysql.favorite.ProductFavoriteMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -56,8 +55,8 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ProductFavoriteDetailDO> getFavoritePageByFilter(@Valid ProductFavoritePageReqVO reqVO) {
|
||||
return productFavoriteMapper.selectPageByUserAndFields(reqVO);
|
||||
public PageResult<ProductFavoriteDO> getFavoritePage(@Valid ProductFavoritePageReqVO reqVO) {
|
||||
return productFavoriteMapper.selectPageByUserId(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user