添加pc端es查询岗位方法
This commit is contained in:
@@ -57,4 +57,6 @@ public interface IAppUserService
|
||||
AppUser selectByOpenid(String openid);
|
||||
|
||||
public AppUser registerAppUser(RegisterBody registerBody);
|
||||
|
||||
public AppUser selectAppuserByIdcard(String idCard);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.ruoyi.cms.service;
|
||||
|
||||
import com.ruoyi.cms.domain.ESJobDocument;
|
||||
import com.ruoyi.cms.domain.Job;
|
||||
import com.ruoyi.cms.domain.query.ESJobSearch;
|
||||
import com.ruoyi.common.core.domain.entity.AppUser;
|
||||
import org.dromara.easyes.core.biz.EsPageInfo;
|
||||
|
||||
import java.util.List;
|
||||
@@ -69,4 +69,6 @@ public interface IESJobSearchService
|
||||
void deleteJob(Long jobId);
|
||||
|
||||
List<ESJobDocument> selectByIds(Long[] jobIds);
|
||||
|
||||
List<ESJobDocument> selectSysTextListExceptJobId(ESJobSearch esJobSearch, List<Long> jobIds, AppUser appUser);
|
||||
}
|
||||
|
||||
@@ -92,4 +92,6 @@ public interface IJobService
|
||||
void publishJob(Job job);
|
||||
|
||||
List<AppUser> selectApplyJobUserList(Long jobId);
|
||||
|
||||
List<ESJobDocument> sysRecommend(ESJobSearch esJobSearch);
|
||||
}
|
||||
|
||||
@@ -210,4 +210,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper,AppUser> imple
|
||||
appUserMapper.updateById(appUser);
|
||||
return appUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppUser selectAppuserByIdcard(String idCard) {
|
||||
return appUserMapper.selectOne(Wrappers.<AppUser>lambdaQuery().eq(AppUser::getIdCard, idCard).orderByDesc(AppUser::getUpdateTime).last("LIMIT 1"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import com.ruoyi.cms.service.IESJobSearchService;
|
||||
import com.ruoyi.cms.util.ListUtil;
|
||||
import com.ruoyi.cms.util.StringUtil;
|
||||
import com.ruoyi.common.core.domain.entity.Company;
|
||||
import com.ruoyi.common.core.domain.model.LoginSiteUser;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.SiteSecurityUtils;
|
||||
import com.ruoyi.common.utils.bean.BeanUtils;
|
||||
import org.dromara.easyes.core.biz.EsPageInfo;
|
||||
@@ -441,11 +441,7 @@ public class ESJobSearchImpl implements IESJobSearchService
|
||||
}
|
||||
//企业用户排除es去除jobIds
|
||||
boolean needExclude = true;
|
||||
if (SiteSecurityUtils.isLogin()) {
|
||||
LoginSiteUser siteUser = SiteSecurityUtils.getLoginSiteUser();
|
||||
AppUser appUser = siteUser.getUser();
|
||||
needExclude = !StringUtil.IS_COMPANY_USER.equals(appUser.getIsCompanyUser());
|
||||
}
|
||||
needExclude = !StringUtil.IS_COMPANY_USER.equals(esJobSearch.getUserType());
|
||||
if(needExclude && !ListUtil.isListEmptyOrNull(jobIds)){
|
||||
wrapper.not().in(ESJobDocument::getJobId, jobIds);
|
||||
}
|
||||
@@ -595,4 +591,123 @@ public class ESJobSearchImpl implements IESJobSearchService
|
||||
wrapper.in(ESJobDocument::getJobId,jobIds);
|
||||
return esJobDocumentMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* pc端查询es
|
||||
* @param esJobSearch
|
||||
* @param jobIds
|
||||
* @param appUser
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<ESJobDocument> selectSysTextListExceptJobId(ESJobSearch esJobSearch, List<Long> jobIds,AppUser appUser) {
|
||||
|
||||
ESJobSearch newSearch = new ESJobSearch();
|
||||
BeanUtils.copyProperties(esJobSearch,newSearch);
|
||||
//查询
|
||||
if(SecurityUtils.isLogin()){
|
||||
if(appUser!=null){
|
||||
if(!ListUtil.isEmptyOrNull(appUser.getJobTitle())){
|
||||
List<String> jobTitle = appUser.getJobTitle();
|
||||
newSearch.setJobTitle(String.join(",", jobTitle));
|
||||
}
|
||||
if(!StringUtil.isEmptyOrNull(appUser.getEducation())){
|
||||
newSearch.setEducation(appUser.getEducation());
|
||||
}
|
||||
if(!StringUtil.isEmptyOrNull(appUser.getArea())){
|
||||
newSearch.setArea(appUser.getArea());
|
||||
}
|
||||
if(!StringUtil.isEmptyOrNull(appUser.getExperience())){
|
||||
newSearch.setExperience(appUser.getExperience());
|
||||
}
|
||||
if(!StringUtil.isEmptyOrNull(esJobSearch.getExperience())){
|
||||
newSearch.setExperience(esJobSearch.getExperience());
|
||||
}
|
||||
if(!StringUtil.isEmptyOrNull(appUser.getSalaryMax())){
|
||||
newSearch.setMaxSalary(Long.valueOf(appUser.getSalaryMax()));
|
||||
}
|
||||
if(!StringUtil.isEmptyOrNull(appUser.getSalaryMin())){
|
||||
newSearch.setMinSalary(Long.valueOf(appUser.getSalaryMin()));
|
||||
}
|
||||
}
|
||||
|
||||
if(!StringUtil.isEmptyOrNull(esJobSearch.getArea())){
|
||||
newSearch.setArea(esJobSearch.getArea());
|
||||
}
|
||||
if(!StringUtil.isEmptyOrNull(esJobSearch.getEducation())){
|
||||
newSearch.setEducation(esJobSearch.getEducation());
|
||||
}
|
||||
if(!StringUtil.isEmptyOrNull(esJobSearch.getJobTitle())){
|
||||
newSearch.setJobTitle(esJobSearch.getJobTitle());
|
||||
}
|
||||
if(!StringUtil.isEmptyOrNull(esJobSearch.getJobType())){
|
||||
newSearch.setJobType(esJobSearch.getJobType());
|
||||
}
|
||||
if(!StringUtil.isEmptyOrNull(esJobSearch.getType())){
|
||||
newSearch.setType(esJobSearch.getType());
|
||||
}
|
||||
if(!StringUtil.isEmptyOrNull(esJobSearch.getDescription())){
|
||||
newSearch.setDescription(esJobSearch.getDescription());
|
||||
}
|
||||
if(!StringUtil.isEmptyOrNull(esJobSearch.getCompanyNature())){
|
||||
newSearch.setCompanyNature(esJobSearch.getCompanyNature());
|
||||
}
|
||||
if(!StringUtil.isEmptyOrNull(esJobSearch.getCode())){
|
||||
newSearch.setCode(esJobSearch.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
LambdaEsQueryWrapper<ESJobDocument> wrapper = getWrapper(newSearch,jobIds);
|
||||
|
||||
//todo 暂时
|
||||
wrapper.limit(esJobSearch.getPageSize());
|
||||
List<ESJobDocument> esJobDocuments = esJobDocumentMapper.selectList(wrapper);
|
||||
|
||||
if (esJobDocuments.size() < esJobSearch.getPageSize()) {
|
||||
// 定义要逐步放宽的搜索条件字段
|
||||
List<Runnable> relaxConditions = new ArrayList<>();
|
||||
relaxConditions.add(() -> newSearch.setArea(null));
|
||||
relaxConditions.add(() -> newSearch.setExperience(null));
|
||||
relaxConditions.add(() -> newSearch.setMaxSalary(null));
|
||||
relaxConditions.add(() -> newSearch.setMinSalary(null));
|
||||
relaxConditions.add(() -> newSearch.setEducation(null));
|
||||
relaxConditions.add(()-> newSearch.setJobTitle(null));
|
||||
// 保存所有查询到的文档
|
||||
List<ESJobDocument> allDocuments = new ArrayList<>(esJobDocuments);
|
||||
|
||||
// 记录已经放宽的条件数量
|
||||
int relaxedConditions = 0;
|
||||
|
||||
// 继续放宽条件直到满足分页或所有条件都已放宽
|
||||
while (allDocuments.size() < esJobSearch.getPageSize()
|
||||
&& relaxedConditions < relaxConditions.size()) {
|
||||
// 放宽下一个条件
|
||||
relaxConditions.get(relaxedConditions).run();
|
||||
relaxedConditions++;
|
||||
|
||||
// 查询新增的文档(不包含之前已经查询到的)
|
||||
wrapper = getWrapper(newSearch, jobIds);
|
||||
wrapper.limit(esJobSearch.getPageSize() - allDocuments.size());
|
||||
if (!allDocuments.isEmpty()) {
|
||||
// 排除已经查询到的文档ID
|
||||
Set<String> existingIds = allDocuments.stream()
|
||||
.map(ESJobDocument::getId)
|
||||
.collect(Collectors.toSet());
|
||||
wrapper.not().in(ESJobDocument::getId, existingIds);
|
||||
}
|
||||
|
||||
List<ESJobDocument> newDocuments = esJobDocumentMapper.selectList(wrapper);
|
||||
allDocuments.addAll(newDocuments);
|
||||
}
|
||||
|
||||
// 如果总数超过分页大小,截取所需数量
|
||||
if (allDocuments.size() > esJobSearch.getPageSize()) {
|
||||
esJobDocuments = allDocuments.subList(0, esJobSearch.getPageSize());
|
||||
} else {
|
||||
esJobDocuments = allDocuments;
|
||||
}
|
||||
}
|
||||
|
||||
return esJobDocuments;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.ruoyi.cms.domain.vo.CandidateVO;
|
||||
import com.ruoyi.cms.mapper.*;
|
||||
import com.ruoyi.cms.service.*;
|
||||
import com.ruoyi.cms.util.*;
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.TreeSelect;
|
||||
import com.ruoyi.common.core.domain.entity.AppUser;
|
||||
@@ -22,6 +23,7 @@ import com.ruoyi.common.core.domain.entity.Company;
|
||||
import com.ruoyi.common.core.domain.entity.JobTitle;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.SiteSecurityUtils;
|
||||
import com.ruoyi.common.utils.bean.BeanUtils;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
@@ -79,6 +81,8 @@ public class JobServiceImpl extends ServiceImpl<JobMapper,Job> implements IJobSe
|
||||
private JobContactMapper jobContactMapper;
|
||||
@Autowired
|
||||
private FileMapper fileMapper;
|
||||
@Autowired
|
||||
private IAppUserService appUserService;
|
||||
|
||||
/**
|
||||
* 更新工作地址的经纬度信息
|
||||
@@ -786,6 +790,23 @@ public class JobServiceImpl extends ServiceImpl<JobMapper,Job> implements IJobSe
|
||||
return jobs;
|
||||
}
|
||||
|
||||
private List<ESJobDocument> sysUserCollection(List<ESJobDocument> jobs){
|
||||
if(jobs.isEmpty()){return new ArrayList<>();}
|
||||
if(SecurityUtils.isLogin()){
|
||||
//收藏
|
||||
Set<Long> collectionIds = jobCollectionMapper.selectList(Wrappers.<JobCollection>lambdaQuery()
|
||||
.eq(JobCollection::getUserId, SecurityUtils.getUserId())
|
||||
.in(JobCollection::getJobId, jobs.stream().map(ESJobDocument::getJobId).collect(Collectors.toList())))
|
||||
.stream().map(JobCollection::getJobId).collect(Collectors.toSet());
|
||||
for (ESJobDocument j : jobs) {
|
||||
if (collectionIds.contains(j.getJobId())) {
|
||||
j.setIsCollection(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return jobs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publishJob(Job job) {
|
||||
job.setIsPublish(0);
|
||||
@@ -809,4 +830,27 @@ public class JobServiceImpl extends ServiceImpl<JobMapper,Job> implements IJobSe
|
||||
public List<AppUser> selectApplyJobUserList(Long jobId) {
|
||||
return jobMapper.selectApplyJobUserList(jobId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ESJobDocument> sysRecommend(ESJobSearch esJobSearch) {
|
||||
String jobKey=CacheConstants.SYS_JOB_IDS+ SecurityUtils.getUserId();
|
||||
RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
|
||||
JSONArray cacheObject = redisCache.getCacheObject(jobKey);
|
||||
List<Long> jobList = new ArrayList<>();
|
||||
if(Objects.isNull(cacheObject)){
|
||||
ArrayList<Long> longs = new ArrayList<>();
|
||||
jobList =longs;
|
||||
}else {
|
||||
jobList = cacheObject.toList(Long.class);
|
||||
}
|
||||
AppUser appUser=appUserService.selectAppuserByIdcard(RoleUtils.getCurrentUseridCard());
|
||||
|
||||
//从es中查询
|
||||
List<ESJobDocument> jobListResult = iesJobSearchService.selectSysTextListExceptJobId(esJobSearch,jobList,appUser);
|
||||
//存入当前session中查看的岗位 避免重复 todo 定时删除 key上保存用户信息
|
||||
jobList.addAll(jobListResult.stream().map(ESJobDocument::getJobId).collect(Collectors.toList()));
|
||||
redisCache.setCacheObject(jobKey,jobList);
|
||||
List<ESJobDocument> esJobDocuments = sysUserCollection(jobListResult);
|
||||
return esJobDocuments;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user