修改pc端查询推荐岗位逻辑
1.添加过期时间 2.限制条数
This commit is contained in:
@@ -47,6 +47,8 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 岗位Service业务层处理
|
* 岗位Service业务层处理
|
||||||
*
|
*
|
||||||
@@ -925,30 +927,55 @@ public class JobServiceImpl extends ServiceImpl<JobMapper,Job> implements IJobSe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ESJobDocument> sysRecommend(ESJobSearch esJobSearch) {
|
public List<ESJobDocument> sysRecommend(ESJobSearch esJobSearch) {
|
||||||
Long userId=SecurityUtils.isLogin()?SecurityUtils.getUserId():null;
|
Long userId = SecurityUtils.isLogin() ? SecurityUtils.getUserId() : null;
|
||||||
List<Long> jobList=new ArrayList<>();
|
List<Long> viewedJobIds = new ArrayList<>();
|
||||||
String jobKey="";
|
String jobCacheKey = "";
|
||||||
AppUser appUser=null;
|
AppUser appUser = null;
|
||||||
if(userId!=null){
|
|
||||||
jobKey=CacheConstants.SYS_JOB_IDS+ userId;
|
if (userId != null) {
|
||||||
RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
|
jobCacheKey = CacheConstants.SYS_JOB_IDS + userId;
|
||||||
JSONArray cacheObject = redisCache.getCacheObject(jobKey);
|
try {
|
||||||
jobList = new ArrayList<>();
|
JSONArray cacheObject = redisCache.getCacheObject(jobCacheKey);
|
||||||
if(Objects.isNull(cacheObject)){
|
if (Objects.isNull(cacheObject)) {
|
||||||
ArrayList<Long> longs = new ArrayList<>();
|
cacheObject = new JSONArray();
|
||||||
jobList =longs;
|
|
||||||
}else {
|
|
||||||
jobList = cacheObject.toList(Long.class);
|
|
||||||
}
|
}
|
||||||
appUser=appUserService.selectAppuserByIdcard(RoleUtils.getCurrentUseridCard());
|
viewedJobIds = cacheObject.stream()
|
||||||
|
.map(o -> Long.parseLong(o.toString()))
|
||||||
|
.distinct().limit(100).collect(Collectors.toList());
|
||||||
|
|
||||||
|
String idCard = RoleUtils.getCurrentUseridCard();
|
||||||
|
if (StringUtils.isNotEmpty(idCard)) {
|
||||||
|
appUser = appUserService.selectAppuserByIdcard(idCard);
|
||||||
}
|
}
|
||||||
//从es中查询
|
} catch (Exception e) {
|
||||||
List<ESJobDocument> jobListResult = iesJobSearchService.selectSysTextListExceptJobId(esJobSearch,jobList,appUser);
|
log.error("获取用户已查看岗位缓存失败", e);
|
||||||
//存入当前session中查看的岗位 避免重复 todo 定时删除 key上保存用户信息
|
viewedJobIds = new ArrayList<>();
|
||||||
jobList.addAll(jobListResult.stream().map(ESJobDocument::getJobId).collect(Collectors.toList()));
|
|
||||||
if(StringUtils.isNotEmpty(jobKey)){
|
|
||||||
redisCache.setCacheObject(jobKey,jobList);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ESJobDocument> jobListResult = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
jobListResult = iesJobSearchService.selectSysTextListExceptJobId(esJobSearch, viewedJobIds, appUser);
|
||||||
|
//降级策略:如果过滤后无数据,忽略已查看记录重新查询
|
||||||
|
if (CollectionUtils.isEmpty(jobListResult) && !viewedJobIds.isEmpty()) {
|
||||||
|
log.warn("用户{}已查看岗位过多,忽略过滤条件重新查询");
|
||||||
|
jobListResult = iesJobSearchService.selectSysTextListExceptJobId(esJobSearch, new ArrayList<>(), appUser);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("ES推荐岗位查询失败", e);
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userId != null && !CollectionUtils.isEmpty(jobListResult)) {
|
||||||
|
try {
|
||||||
|
List<Long> newJobIds = jobListResult.stream().map(ESJobDocument::getJobId).distinct().collect(Collectors.toList());
|
||||||
|
List<Long> updatedJobIds = Stream.concat(viewedJobIds.stream(), newJobIds.stream()).distinct().limit(100).collect(Collectors.toList());
|
||||||
|
redisCache.setCacheObject(jobCacheKey, updatedJobIds, 24, TimeUnit.HOURS);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("更新用户已查看岗位缓存失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<ESJobDocument> esJobDocuments = sysUserCollection(jobListResult);
|
List<ESJobDocument> esJobDocuments = sysUserCollection(jobListResult);
|
||||||
return esJobDocuments;
|
return esJobDocuments;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user