案例萃取,收藏数组回收

This commit is contained in:
yang
2024-09-09 19:40:39 +08:00
parent a8a31d7d86
commit 05629b721d
4 changed files with 49 additions and 22 deletions

View File

@@ -14,6 +14,7 @@ import com.xboe.module.boecase.service.ICasesRecommendPushRecordService;
import com.xboe.module.boecase.vo.CaseExportVo; import com.xboe.module.boecase.vo.CaseExportVo;
import com.xboe.module.boecase.vo.CaseRankingVo; import com.xboe.module.boecase.vo.CaseRankingVo;
import com.xboe.module.boecase.vo.CasesQueryRecommendRankVo; import com.xboe.module.boecase.vo.CasesQueryRecommendRankVo;
import com.xboe.module.boecase.vo.FavoriteCaseOfIndexVo;
import com.xboe.module.dict.entity.DictItem; import com.xboe.module.dict.entity.DictItem;
import com.xboe.module.excel.ExportsExcelSenderUtil; import com.xboe.module.excel.ExportsExcelSenderUtil;
@@ -739,16 +740,21 @@ public class CasesApi extends ApiBaseController {
/** /**
* 查询收藏 * 查询收藏
* @param pageIndex
* @param pageSize
* @param orderField
* @param orderAsc
* @return
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@GetMapping("/queryFavoriteCaseOfIndex") @GetMapping("/queryFavoriteCaseOfIndex")
public JsonResponse<PageList<FavoriteCaseDto>> queryFavoriteCaseOfIndex(@RequestParam(required = false,defaultValue = "1") Integer pageIndex, public JsonResponse<PageList<FavoriteCaseOfIndexVo>> queryFavoriteCaseOfIndex(@RequestParam(required = false,defaultValue = "1") Integer pageIndex,
@RequestParam(required = false,defaultValue = "5") Integer pageSize, @RequestParam(required = false,defaultValue = "5") Integer pageSize,
@RequestParam(required = false) String orderField, @RequestParam(required = false) String orderField,
@RequestParam(required = false) Boolean orderAsc) { @RequestParam(required = false) Boolean orderAsc) {
// String accountId = this.getCurrent().getAccountId(); // String accountId = this.getCurrent().getAccountId();
String accountId = "965342027497607168"; String accountId = "965342027497607168";
PageList<FavoriteCaseDto> casesList = casesService.queryFavoriteCaseOfIndex(pageIndex,pageSize,accountId,orderField,orderAsc); PageList<FavoriteCaseOfIndexVo> casesList = casesService.queryFavoriteCaseOfIndex(pageIndex,pageSize,accountId,orderField,orderAsc);
return success(casesList); return success(casesList);
} }

View File

@@ -6,6 +6,7 @@ import com.xboe.module.boecase.dto.*;
import com.xboe.module.boecase.entity.Cases; import com.xboe.module.boecase.entity.Cases;
import com.xboe.module.boecase.vo.CaseRankingVo; import com.xboe.module.boecase.vo.CaseRankingVo;
import com.xboe.module.boecase.vo.CasesQueryRecommendRankVo; import com.xboe.module.boecase.vo.CasesQueryRecommendRankVo;
import com.xboe.module.boecase.vo.FavoriteCaseOfIndexVo;
import com.xboe.module.dict.entity.DictItem; import com.xboe.module.dict.entity.DictItem;
import com.xboe.module.interaction.dto.FavoriteCaseDto; import com.xboe.module.interaction.dto.FavoriteCaseDto;
import com.xboe.school.vo.CasesVo; import com.xboe.school.vo.CasesVo;
@@ -132,6 +133,6 @@ public interface ICasesService{
List<Cases> queryPopularityOfMajor(Integer pageSize, Long majorId, LocalDateTime month, String accountId); List<Cases> queryPopularityOfMajor(Integer pageSize, Long majorId, LocalDateTime month, String accountId);
PageList<FavoriteCaseDto> queryFavoriteCaseOfIndex(Integer pageIndex, Integer pageSize, String accountId, String orderField, Boolean orderAsc); PageList<FavoriteCaseOfIndexVo> queryFavoriteCaseOfIndex(Integer pageIndex, Integer pageSize, String accountId, String orderField, Boolean orderAsc);
} }

View File

@@ -21,9 +21,9 @@ import com.xboe.module.boecase.service.ICasesService;
import com.xboe.module.boecase.vo.CaseRankingVo; import com.xboe.module.boecase.vo.CaseRankingVo;
import com.xboe.module.boecase.vo.CaseViewRankingItemVo; import com.xboe.module.boecase.vo.CaseViewRankingItemVo;
import com.xboe.module.boecase.vo.CasesQueryRecommendRankVo; import com.xboe.module.boecase.vo.CasesQueryRecommendRankVo;
import com.xboe.module.boecase.vo.FavoriteCaseOfIndexVo;
import com.xboe.module.dict.dao.SysDictionaryDao; import com.xboe.module.dict.dao.SysDictionaryDao;
import com.xboe.module.dict.entity.DictItem; import com.xboe.module.dict.entity.DictItem;
import com.xboe.module.interaction.dto.FavoriteCaseDto;
import com.xboe.module.interaction.entity.Favorites; import com.xboe.module.interaction.entity.Favorites;
import com.xboe.orm.CustomFieldInFilter; import com.xboe.orm.CustomFieldInFilter;
import com.xboe.school.vo.CasesVo; import com.xboe.school.vo.CasesVo;
@@ -31,6 +31,7 @@ import com.xboe.standard.enums.BoedxResourceType;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
@@ -44,7 +45,6 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
@@ -1227,7 +1227,7 @@ public class CasesServiceImpl implements ICasesService {
// 缓存不存在数据,数据库中不存在数据,重建缓存 // 缓存不存在数据,数据库中不存在数据,重建缓存
List<String> serializedCases = casesList.stream().map(item -> JSONUtil.toJsonStr(item)).collect(Collectors.toList()); List<String> serializedCases = casesList.stream().map(item -> JSONUtil.toJsonStr(item)).collect(Collectors.toList());
stringRedisTemplate.opsForList().rightPushAll(cacheKey, serializedCases); stringRedisTemplate.opsForList().rightPushAll(cacheKey, serializedCases);
stringRedisTemplate.expire(cacheKey, 10000, TimeUnit.SECONDS); stringRedisTemplate.expire(cacheKey, 600, TimeUnit.SECONDS);
return casesList; return casesList;
} }
return Collections.emptyList(); return Collections.emptyList();
@@ -1360,7 +1360,7 @@ public class CasesServiceImpl implements ICasesService {
} }
@Override @Override
public PageList<FavoriteCaseDto> queryFavoriteCaseOfIndex(Integer pageIndex, Integer pageSize, String accountId, String orderField, Boolean orderAsc) { public PageList<FavoriteCaseOfIndexVo> queryFavoriteCaseOfIndex(Integer pageIndex, Integer pageSize, String accountId, String orderField, Boolean orderAsc) {
String from = Favorites.class.getSimpleName()+" f,"+ Cases.class.getSimpleName()+" c"; String from = Favorites.class.getSimpleName()+" f,"+ Cases.class.getSimpleName()+" c";
QueryBuilder builder = QueryBuilder.from(from); QueryBuilder builder = QueryBuilder.from(from);
builder.addFields("f.id","f.sysCreateTime","c"); builder.addFields("f.id","f.sysCreateTime","c");
@@ -1396,25 +1396,27 @@ public class CasesServiceImpl implements ICasesService {
} }
List<Object[]> list = pageFields.getList(); List<Object[]> list = pageFields.getList();
// 提取出 Cases 对象,添加标签 // 提取出 Cases 对象,添加标签
List<Cases> casesList = list.stream().map(o -> (Cases) o[2]).collect(Collectors.toList()); List<Cases> casesList = list.stream().map(o -> {
Cases cases = (Cases) o[2];
FavoriteCaseOfIndexVo favoriteCaseOfIndexVo = new FavoriteCaseOfIndexVo();
BeanUtils.copyProperties(cases, favoriteCaseOfIndexVo);
favoriteCaseOfIndexVo.setFavoriteId(o[0].toString());
favoriteCaseOfIndexVo.setFavoriteTime(LocalDateTime.parse(o[1].toString()));
return favoriteCaseOfIndexVo;
}).collect(Collectors.toList());
casesList = caseListCommonHandle(casesList, accountId); casesList = caseListCommonHandle(casesList, accountId);
Map<String, Cases> caseMap = casesList.stream().collect(Collectors.toMap(Cases::getId, Function.identity()));
PageList<FavoriteCaseDto> favoriteCaseDtoPageList = new PageList<>(); List<FavoriteCaseOfIndexVo> collect = casesList.stream().map(cases -> (FavoriteCaseOfIndexVo) cases).collect(Collectors.toList());
favoriteCaseDtoPageList.setList(new ArrayList<>());
favoriteCaseDtoPageList.setPageSize(pageSize);
favoriteCaseDtoPageList.setCount(pageFields.getCount());
for (Object[] o: list) {
FavoriteCaseDto favoriteCaseDto = new FavoriteCaseDto();
favoriteCaseDto.setId(o[0].toString());
favoriteCaseDto.setTime(LocalDateTime.parse(o[1].toString()));
Cases cases = caseMap.get(((Cases) o[2]).getId());
favoriteCaseDto.setCases(cases);
favoriteCaseDtoPageList.getList().add(favoriteCaseDto);
}
return favoriteCaseDtoPageList; PageList<FavoriteCaseOfIndexVo> favoriteCaseOfIndexVoPageList = new PageList<>();
favoriteCaseOfIndexVoPageList.setList(collect);
favoriteCaseOfIndexVoPageList.setPageSize(pageSize);
favoriteCaseOfIndexVoPageList.setCount(pageFields.getCount());
return favoriteCaseOfIndexVoPageList;
} }

View File

@@ -0,0 +1,18 @@
package com.xboe.module.boecase.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.xboe.module.boecase.entity.Cases;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class FavoriteCaseOfIndexVo extends Cases{
private String favoriteId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime favoriteTime;
}