📖 MALL:code review 商品统计的代码

This commit is contained in:
YunaiV
2024-01-07 16:23:02 +08:00
parent eb048532f7
commit bbba83ef61
14 changed files with 77 additions and 147 deletions

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,14 +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());
vo.setPicUrl(spu.getPicUrl());
}));
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()))));
}
}

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

@@ -30,14 +30,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);