Merge remote-tracking branch 'origin/develop' into develop

# Conflicts:
#	yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/history/AppProductBrowseHistoryController.java
This commit is contained in:
owen
2024-01-11 11:11:05 +08:00
112 changed files with 1679 additions and 1051 deletions

View File

@ -67,8 +67,8 @@ public class ProductCategoryController {
@GetMapping("/list")
@Operation(summary = "获得商品分类列表")
@PreAuthorize("@ss.hasPermission('product:category:query')")
public CommonResult<List<ProductCategoryRespVO>> getCategoryList(@Valid ProductCategoryListReqVO treeListReqVO) {
List<ProductCategoryDO> list = categoryService.getEnableCategoryList(treeListReqVO);
public CommonResult<List<ProductCategoryRespVO>> getCategoryList(@Valid ProductCategoryListReqVO listReqVO) {
List<ProductCategoryDO> list = categoryService.getCategoryList(listReqVO);
list.sort(Comparator.comparing(ProductCategoryDO::getSort));
return success(ProductCategoryConvert.INSTANCE.convertList(list));
}

View File

@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.product.controller.admin.category.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.Collection;
@Schema(description = "管理后台 - 商品分类列表查询 Request VO")
@Data
public class ProductCategoryListReqVO {
@ -16,4 +18,7 @@ public class ProductCategoryListReqVO {
@Schema(description = "父分类编号", example = "1")
private Long parentId;
@Schema(description = "父分类编号数组", example = "1,2,3")
private Collection<Long> parentIds;
}

View File

@ -28,6 +28,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
// TODO 芋艿:后面再看
@Tag(name = "用户 APP - 商品浏览记录")
@RestController
@RequestMapping("/product/browse-history")
@ -65,10 +66,9 @@ public class AppProductBrowseHistoryController {
@Operation(summary = "获得商品浏览记录分页")
@PreAuthenticated
public CommonResult<PageResult<AppProductBrowseHistoryRespVO>> getBrowseHistoryPage(AppProductBrowseHistoryPageReqVO reqVO) {
ProductBrowseHistoryPageReqVO pageReqVO = BeanUtils.toBean(reqVO, ProductBrowseHistoryPageReqVO.class);
pageReqVO.setUserId(getLoginUserId());
// 排除用户已删除的(隐藏的)
pageReqVO.setUserDeleted(false);
ProductBrowseHistoryPageReqVO pageReqVO = BeanUtils.toBean(reqVO, ProductBrowseHistoryPageReqVO.class)
.setUserId(getLoginUserId())
.setUserDeleted(false); // 排除用户已删除的(隐藏的)
PageResult<ProductBrowseHistoryDO> pageResult = productBrowseHistoryService.getBrowseHistoryPage(pageReqVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty());
@ -77,15 +77,9 @@ public class AppProductBrowseHistoryController {
// 得到商品 spu 信息
Set<Long> spuIds = convertSet(pageResult.getList(), ProductBrowseHistoryDO::getSpuId);
Map<Long, ProductSpuDO> spuMap = convertMap(productSpuService.getSpuList(spuIds), ProductSpuDO::getId);
// 转换 VO 结果
PageResult<AppProductBrowseHistoryRespVO> result = BeanUtils.toBean(pageResult, AppProductBrowseHistoryRespVO.class,
vo -> Optional.ofNullable(spuMap.get(vo.getSpuId())).ifPresent(spu -> {
vo.setSpuName(spu.getName())
.setPicUrl(spu.getPicUrl())
.setPrice(spu.getPrice());
}));
return success(result);
return success(BeanUtils.toBean(pageResult, AppProductBrowseHistoryRespVO.class,
vo -> Optional.ofNullable(spuMap.get(vo.getSpuId()))
.ifPresent(spu -> vo.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl()).setPrice(spu.getPrice()))));
}
}

View File

@ -16,6 +16,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class AppProductBrowseHistoryPageReqVO extends PageParam {
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;

View File

@ -4,11 +4,12 @@ import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.AssertTrue;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import jakarta.validation.constraints.AssertTrue;
import java.util.List;
@Schema(description = "用户 App - 商品 SPU 分页 Request VO")
@Data
@ -26,9 +27,15 @@ public class AppProductSpuPageReqVO extends PageParam {
public static final String RECOMMEND_TYPE_NEW = "new";
public static final String RECOMMEND_TYPE_GOOD = "good";
@Schema(description = "商品 SPU 编号数组", example = "1,3,5")
private List<Long> ids;
@Schema(description = "分类编号", example = "1")
private Long categoryId;
@Schema(description = "分类编号数组", example = "1,2,3")
private List<Long> categoryIds;
@Schema(description = "关键字", example = "好看")
private String keyword;

View File

@ -21,6 +21,7 @@ public interface ProductCategoryMapper extends BaseMapperX<ProductCategoryDO> {
return selectList(new LambdaQueryWrapperX<ProductCategoryDO>()
.likeIfPresent(ProductCategoryDO::getName, listReqVO.getName())
.eqIfPresent(ProductCategoryDO::getParentId, listReqVO.getParentId())
.inIfPresent(ProductCategoryDO::getId, listReqVO.getParentIds())
.eqIfPresent(ProductCategoryDO::getStatus, listReqVO.getStatus())
.orderByDesc(ProductCategoryDO::getId));
}

View File

@ -67,7 +67,7 @@ public interface ProductCategoryService {
* @param listReqVO 查询条件
* @return 商品分类列表
*/
List<ProductCategoryDO> getEnableCategoryList(ProductCategoryListReqVO listReqVO);
List<ProductCategoryDO> getCategoryList(ProductCategoryListReqVO listReqVO);
/**
* 获得开启状态的商品分类列表

View File

@ -161,7 +161,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
}
@Override
public List<ProductCategoryDO> getEnableCategoryList(ProductCategoryListReqVO listReqVO) {
public List<ProductCategoryDO> getCategoryList(ProductCategoryListReqVO listReqVO) {
return productCategoryMapper.selectList(listReqVO);
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.product.service.history;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.history.vo.ProductBrowseHistoryPageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.history.ProductBrowseHistoryDO;
import org.springframework.scheduling.annotation.Async;
import java.util.Collection;
@ -20,6 +21,7 @@ public interface ProductBrowseHistoryService {
* @param spuId SPU 编号
* @return 编号
*/
@Async
Long createBrowseHistory(Long userId, Long spuId);
/**
@ -30,14 +32,6 @@ public interface ProductBrowseHistoryService {
*/
void hideUserBrowseHistory(Long userId, Collection<Long> spuId);
/**
* 获得商品浏览记录
*
* @param id 编号
* @return 商品浏览记录
*/
ProductBrowseHistoryDO getBrowseHistory(Long id);
/**
* 获取用户记录数量
*

View File

@ -50,7 +50,6 @@ public class ProductBrowseHistoryServiceImpl implements ProductBrowseHistoryServ
.setUserId(userId)
.setSpuId(spuId);
browseHistoryMapper.insert(browseHistory);
// 返回
return browseHistory.getId();
}
@ -59,11 +58,6 @@ public class ProductBrowseHistoryServiceImpl implements ProductBrowseHistoryServ
browseHistoryMapper.updateUserDeletedByUserId(userId, spuIds, true);
}
@Override
public ProductBrowseHistoryDO getBrowseHistory(Long id) {
return browseHistoryMapper.selectById(id);
}
@Override
public Long getBrowseHistoryCount(Long userId, Boolean userDeleted) {
return browseHistoryMapper.selectCountByUserIdAndUserDeleted(userId, userDeleted);

View File

@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageRe
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import jakarta.validation.Valid;
import org.springframework.scheduling.annotation.Async;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@ -154,6 +156,7 @@ public interface ProductSpuService {
* @param id 商品 SPU 编号
* @param incrCount 增加的数量
*/
@Async
void updateBrowseCount(Long id, int incrCount);
}

View File

@ -18,17 +18,16 @@ import cn.iocoder.yudao.module.product.service.brand.ProductBrandService;
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import com.google.common.collect.Maps;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.util.*;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getMinValue;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO.CATEGORY_LEVEL;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
@ -220,9 +219,15 @@ public class ProductSpuServiceImpl implements ProductSpuService {
Set<Long> categoryIds = new HashSet<>();
if (pageReqVO.getCategoryId() != null && pageReqVO.getCategoryId() > 0) {
categoryIds.add(pageReqVO.getCategoryId());
List<ProductCategoryDO> categoryChildren = categoryService.getEnableCategoryList(new ProductCategoryListReqVO()
.setParentId(pageReqVO.getCategoryId()).setStatus(CommonStatusEnum.ENABLE.getStatus()));
categoryIds.addAll(CollectionUtils.convertList(categoryChildren, ProductCategoryDO::getId));
List<ProductCategoryDO> categoryChildren = categoryService.getCategoryList(new ProductCategoryListReqVO()
.setStatus(CommonStatusEnum.ENABLE.getStatus()).setParentId(pageReqVO.getCategoryId()));
categoryIds.addAll(convertList(categoryChildren, ProductCategoryDO::getId));
}
if (CollUtil.isNotEmpty(pageReqVO.getCategoryIds())) {
categoryIds.addAll(pageReqVO.getCategoryIds());
List<ProductCategoryDO> categoryChildren = categoryService.getCategoryList(new ProductCategoryListReqVO()
.setStatus(CommonStatusEnum.ENABLE.getStatus()).setParentIds(pageReqVO.getCategoryIds()));
categoryIds.addAll(convertList(categoryChildren, ProductCategoryDO::getId));
}
// 分页查询
return productSpuMapper.selectPage(pageReqVO, categoryIds);