|
@@ -20,6 +20,7 @@ import java.util.Collection;
|
|
|
@Service
|
|
|
@Validated
|
|
|
public class ProductBrowseHistoryServiceImpl implements ProductBrowseHistoryService {
|
|
|
+
|
|
|
private static final int USER_STORE_MAXIMUM = 100;
|
|
|
|
|
|
@Resource
|
|
@@ -33,14 +34,14 @@ public class ProductBrowseHistoryServiceImpl implements ProductBrowseHistoryServ
|
|
|
}
|
|
|
|
|
|
// 情况一:同一个商品,只保留最新的一条记录
|
|
|
- ProductBrowseHistoryDO historyDO = browseHistoryMapper.selectOne(ProductBrowseHistoryDO::getUserId, userId, ProductBrowseHistoryDO::getSpuId, spuId);
|
|
|
- if (historyDO != null) {
|
|
|
- browseHistoryMapper.deleteById(historyDO);
|
|
|
+ ProductBrowseHistoryDO history = browseHistoryMapper.selectByUserIdAndSpuId(userId, spuId);
|
|
|
+ if (history != null) {
|
|
|
+ browseHistoryMapper.deleteById(history);
|
|
|
} else {
|
|
|
// 情况二:限制每个用户的浏览记录的条数(只查一条最早地记录、记录总数)
|
|
|
+ // TODO @疯狂:这里最好先查询一次数量。如果发现超过了,再删除;主要考虑,可能有部分不超过,提前就多了一次 sql 查询了
|
|
|
Page<ProductBrowseHistoryDO> pageResult = browseHistoryMapper.selectPageByUserIdOrderByCreateTimeAsc(userId, 1, 1);
|
|
|
if (pageResult.getTotal() >= USER_STORE_MAXIMUM) {
|
|
|
- // 删除最早的一条
|
|
|
browseHistoryMapper.deleteById(CollUtil.getFirst(pageResult.getRecords()));
|
|
|
}
|
|
|
}
|
|
@@ -57,11 +58,6 @@ public class ProductBrowseHistoryServiceImpl implements ProductBrowseHistoryServ
|
|
|
browseHistoryMapper.updateUserDeletedByUserId(userId, spuIds, true);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Long getBrowseHistoryCount(Long userId, Boolean userDeleted) {
|
|
|
- return browseHistoryMapper.selectCountByUserIdAndUserDeleted(userId, userDeleted);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public PageResult<ProductBrowseHistoryDO> getBrowseHistoryPage(ProductBrowseHistoryPageReqVO pageReqVO) {
|
|
|
return browseHistoryMapper.selectPage(pageReqVO);
|