Commit c14f1a83 authored by shiyu's avatar shiyu

藏品交换列表随机排序

parent b19d216b
...@@ -28,6 +28,14 @@ public interface SupplierItemDao { ...@@ -28,6 +28,14 @@ public interface SupplierItemDao {
*/ */
List<SupplierItem> findListForSort(SupplierItemRequestDto supplierItemRequestDto); List<SupplierItem> findListForSort(SupplierItemRequestDto supplierItemRequestDto);
/**
* 换藏商品列表,随机排序
* @param supplierItemRequestDto
* @return
*/
List<SupplierItem> findListForRandomSort(SupplierItemRequestDto supplierItemRequestDto);
/** /**
* 查询用户上传的已经售罄的商品 * 查询用户上传的已经售罄的商品
* @param dto * @param dto
......
...@@ -76,6 +76,29 @@ public class SupplierItemDaoImpl implements SupplierItemDao { ...@@ -76,6 +76,29 @@ public class SupplierItemDaoImpl implements SupplierItemDao {
return supplierItemMapper.selectByExampleWithBLOBs(supplierItemExample); return supplierItemMapper.selectByExampleWithBLOBs(supplierItemExample);
} }
@Override
public List<SupplierItem> findListForRandomSort(SupplierItemRequestDto dto) {
SupplierItemExample supplierItemExample = new SupplierItemExample();
SupplierItemExample.Criteria criteria = supplierItemExample.createCriteria();
JdbcHelper.ifPresent(dto.getCreatorId(), criteria::andCreatorIdEqualTo);
JdbcHelper.ifPresent(dto.getId(), criteria::andIdEqualTo);
JdbcHelper.ifPresent(dto.getIds(), criteria::andIdIn);
JdbcHelper.ifPresent(dto.getFilterIds(), criteria::andIdNotIn);
if (StringUtils.hasLength(dto.getName())) {
criteria.andNameLike("%" + dto.getName() + "%");
}
JdbcHelper.ifPresent(dto.getType(), criteria::andTypeEqualTo);
JdbcHelper.ifPresent(dto.getFilterType(), criteria::andTypeNotIn);
JdbcHelper.ifPresent(dto.getStock(), criteria::andStockGreaterThan);
JdbcHelper.ifPresent(dto.getIsOnSale(), criteria::andIsOnSaleEqualTo);
// JdbcHelper.ifPresent(dto.getIsDeleted(), criteria::andIsDeletedEqualTo);
criteria.andIsDeletedEqualTo(false);
supplierItemExample.setOrderByClause(" rand()");
PageHelper.startPage(dto.getPage(), dto.getLimit());
return supplierItemMapper.selectByExampleWithBLOBs(supplierItemExample);
}
@Override @Override
public List<SupplierItem> findSellOutList(SupplierItemRequestDto dto) { public List<SupplierItem> findSellOutList(SupplierItemRequestDto dto) {
SupplierItemExample supplierItemExample = new SupplierItemExample(); SupplierItemExample supplierItemExample = new SupplierItemExample();
......
...@@ -219,8 +219,26 @@ public class SupplierItemServiceImpl implements SupplierItemService { ...@@ -219,8 +219,26 @@ public class SupplierItemServiceImpl implements SupplierItemService {
//必须要有官方估价才能展示在交换列表 //必须要有官方估价才能展示在交换列表
dto.setOfficialEstimatedPriceNotNull(true); dto.setOfficialEstimatedPriceNotNull(true);
} }
List<SupplierItem> supplierItemList = supplierItemDao.findListForSort(dto); String viewKey = dto.getUserId() + ":exchangeItemList";
if (dto.getPage() == 1) {
if (redisUtils.hasKey(viewKey)) {
redisUtils.delete(viewKey);
}
}
if (redisUtils.hasKey(viewKey)) {
List<Long> searchItemIds = (List<Long>) redisUtils.get(viewKey);
dto.setFilterIds(searchItemIds);
}
List<SupplierItem> supplierItemList = supplierItemDao.findListForRandomSort(dto);
PageInfo pageInfo = new PageInfo(supplierItemList); PageInfo pageInfo = new PageInfo(supplierItemList);
List<Long> filterItemIds = supplierItemList.stream().map(SupplierItem::getId).collect(Collectors.toList());
if (redisUtils.hasKey(viewKey)) {
List<Long> searchItemIds = (List<Long>) redisUtils.get(viewKey);
searchItemIds.addAll(filterItemIds);
redisUtils.set(viewKey, searchItemIds, 60 * 60 * 2);
} else {
redisUtils.set(viewKey, filterItemIds, 60 * 60 * 2);
}
for (SupplierItem supplierItem : supplierItemList) { for (SupplierItem supplierItem : supplierItemList) {
SupplierItemVo supplierItemVo = new SupplierItemVo(); SupplierItemVo supplierItemVo = new SupplierItemVo();
EntityMapper.copyAttribute(supplierItem, supplierItemVo); EntityMapper.copyAttribute(supplierItem, supplierItemVo);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment