This commit is contained in:
chenyanchang
2026-06-28 17:47:52 +08:00
5 changed files with 1431 additions and 7 deletions

View File

@@ -117,6 +117,7 @@ public class ESJobDocument
private String industry;
@ApiModelProperty("岗位分类")
@IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
private String jobCategory;
@JsonIgnore

View File

@@ -9,7 +9,9 @@ import com.ruoyi.cms.domain.Job;
import com.ruoyi.cms.domain.query.ESJobSearch;
import com.ruoyi.cms.mapper.es.EsJobDocumentMapper;
import com.ruoyi.cms.mapper.JobMapper;
import com.ruoyi.cms.mapper.JobTitleMapper;
import com.ruoyi.cms.service.IESJobSearchService;
import com.ruoyi.common.core.domain.entity.JobTitle;
import com.ruoyi.cms.util.ListUtil;
import com.ruoyi.cms.util.StringUtil;
import com.ruoyi.common.core.domain.entity.Company;
@@ -68,6 +70,8 @@ public class ESJobSearchImpl implements IESJobSearchService
@Autowired
private BussinessDictDataServiceImpl bussinessDictDataServicel;
@Autowired
private JobTitleMapper jobTitleMapper;
Logger logger = LoggerFactory.getLogger(JobServiceImpl.class);
/**
* 项目启动时,初始化索引及数据
@@ -181,6 +185,7 @@ public class ESJobSearchImpl implements IESJobSearchService
for (Job job : jobList) {
ESJobDocument esJobDocument = new ESJobDocument();
BeanUtils.copyBeanProp(esJobDocument, job);
esJobDocument.setJobCategory(resolveJobCategoryLabel(job.getJobCategory()));
//类型转换导致赋值问题,重新赋值
esJobDocument.setScale(org.apache.commons.lang3.StringUtils.isNotEmpty(job.getScale()) ? Integer.parseInt(job.getScale()) : 0);
CompanyVo vo=job.getCompanyVo();
@@ -260,14 +265,13 @@ public class ESJobSearchImpl implements IESJobSearchService
List<ESJobDocument> esJobDocuments = esJobDocumentMapper.selectList(wrapper);
if (!isCompanyUser &&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);
@@ -513,13 +517,20 @@ public class ESJobSearchImpl implements IESJobSearchService
String[] words = titleStr.split(",");
for (String w : words) {
if (!first) sub.or();
// 同时匹配岗位名称和岗位分类jobCategory 已存储为标签文字)
sub.match(ESJobDocument::getJobTitle, w, 5.0f);
sub.or();
sub.match(ESJobDocument::getJobCategory, w, 5.0f);
first = false;
}
}
if (!StringUtil.isEmptyOrNull(cateStr)) {
// category 搜索时同时匹配 jobCategory 和 jobTitle避免因 jobCategory 字段为空而搜不到
if (!first) sub.or();
sub.eq(ESJobDocument::getJobCategory, cateStr);
sub.match(ESJobDocument::getJobCategory, cateStr, 5.0f);
first = false;
sub.or();
sub.match(ESJobDocument::getJobTitle, cateStr, 5.0f);
}
});
}
@@ -854,6 +865,7 @@ public class ESJobSearchImpl implements IESJobSearchService
}
BeanUtils.copyBeanProp(esJobDocument, job);
esJobDocument.setJobCategory(resolveJobCategoryLabel(job.getJobCategory()));
esJobDocument.setAppJobUrl("https://www.xjksly.cn/app#/packageA/pages/post/post?jobId="+ Base64.getEncoder().encodeToString(String.valueOf(job.getJobId()).getBytes()));
if(!StringUtil.isEmptyOrNull(job.getScale())){
esJobDocument.setScale(Integer.valueOf(job.getScale()));
@@ -997,15 +1009,13 @@ public class ESJobSearchImpl implements IESJobSearchService
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.setJobCategory(null));
relaxConditions.add(()-> newSearch.setJobTitle(null));
// 保存所有查询到的文档
List<ESJobDocument> allDocuments = new ArrayList<>(esJobDocuments);
@@ -1044,4 +1054,24 @@ public class ESJobSearchImpl implements IESJobSearchService
return esJobDocuments;
}
/**
* 将 jobCategory 从数字ID解析为标签文字如 "45" → "销售顾问"
* 如果已经是文字标签或解析失败,返回原值
*/
private String resolveJobCategoryLabel(String jobCategory) {
if (StringUtils.isEmpty(jobCategory)) {
return jobCategory;
}
try {
Long categoryId = Long.parseLong(jobCategory);
JobTitle jobTitle = jobTitleMapper.selectById(categoryId);
if (jobTitle != null && StringUtils.isNotEmpty(jobTitle.getJobName())) {
return jobTitle.getJobName();
}
} catch (NumberFormatException e) {
// 已经是文字标签,直接返回原值
}
return jobCategory;
}
}

View File

@@ -419,7 +419,7 @@ public class JobServiceImpl extends ServiceImpl<JobMapper,Job> implements IJobSe
if(!longs.isEmpty()){
fileMapper.updateBussinessids(longs,job.getJobId());
}
if (job.getIsPublish() == 1) {
if (Integer.valueOf(1).equals(job.getIsPublish())) {
//同步到es
iesJobSearchService.updateJob(job.getJobId());
}