@@ -67,7 +67,7 @@ public class ESJobSearchImpl implements IESJobSearchService
/**
* 项目启动时,初始化索引及数据
*/
@PostConstruct
// @PostConstruct
public void init ( )
{
boolean isLockAcquired = false ;
@@ -574,20 +574,20 @@ public class ESJobSearchImpl implements IESJobSearchService
// jobQuery.setJobTitle(String.join(",", jobTitle));
// }
// }
if ( ! StringUtil . isEmptyOrNull ( jobQuery . getJobTitle ( ) ) ) {
wrapper . and ( a - > a . match ( ESJobDocument : : getJobTitle , jobQuery . getJobTitle ( ) , 5 . 0f )
if ( hasText ( jobQuery . getJobTitle ( ) ) ) {
wrapper . and ( a - > a . match ( ESJobDocument : : getJobTitle , jobQuery . getJobTitle ( ) . trim ( ) ,5 . 0f )
. or ( )
. match ( ESJobDocument : : getDescription , jobQuery . getJobTitle ( ) , 1 . 0f ) ) ;
. match ( ESJobDocument : : getDescription , jobQuery . getJobTitle ( ) . trim ( ) ,1 . 0f ) ) ;
}
if ( ! StringUtil . isEmptyOrNull ( jobQuery . getEducation ( ) ) ) {
wrapper . and ( a - > a . le ( ESJobDocument : : getEducation , jobQuery . getEducation ( ) ) ) ;
if ( hasText ( jobQuery . getEducation ( ) ) ) {
wrapper . and ( a - > a . le ( ESJobDocument : : getEducation , jobQuery . getEducation ( ) . trim ( ) )) ;
}
if ( ! StringUtil . isEmptyOrNull ( jobQuery . getArea ( ) ) ) {
List < Integer > integers = StringUtil . convertStringToIntegerList ( jobQuery . getArea ( ) ) ;
if ( hasText ( jobQuery . getArea ( ) ) ) {
List < Integer > integers = StringUtil . convertStringToIntegerList ( jobQuery . getArea ( ) . trim ( ) );
wrapper . and ( x - > x . in ( ESJobDocument : : getJobLocationAreaCode , integers ) ) ;
}
if ( ! StringUtil . isEmptyOrNull ( jobQuery . getExperience ( ) ) ) {
wrapper . and ( a - > a . le ( ESJobDocument : : getExperience , jobQuery . getExperience ( ) ) ) ;
if ( hasText ( jobQuery . getExperience ( ) ) ) {
wrapper . and ( a - > a . le ( ESJobDocument : : getExperience , jobQuery . getExperience ( ) . trim ( ) )) ;
}
if ( Objects . nonNull ( jobQuery . getMaxSalary ( ) ) ) {
wrapper . and ( x - > x . le ( ESJobDocument : : getMaxSalary , jobQuery . getMaxSalary ( ) ) ) ;
@@ -595,11 +595,11 @@ public class ESJobSearchImpl implements IESJobSearchService
if ( Objects . nonNull ( jobQuery . getMinSalary ( ) ) ) {
wrapper . and ( x - > x . ge ( ESJobDocument : : getMinSalary , jobQuery . getMinSalary ( ) ) ) ;
}
if ( ! StringUtil . isEmptyOrNull ( jobQuery . getScaleDictCode ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getScaleDictCode , jobQuery . getScaleDictCode ( ) ) ) ;
if ( hasText ( jobQuery . getScaleDictCode ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getScaleDictCode , jobQuery . getScaleDictCode ( ) . trim ( ) )) ;
}
if ( ! StringUtil . isEmptyOrNull ( jobQuery . getIndustry ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getIndustry , jobQuery . getIndustry ( ) ) ) ;
if ( hasText ( jobQuery . getIndustry ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getIndustry , jobQuery . getIndustry ( ) . trim ( ) )) ;
}
if ( jobQuery . getLongitude ( ) ! = null ) {
wrapper . geoDistance ( ESJobDocument : : getLatAndLon , Double . valueOf ( jobQuery . getRadius ( ) ) , DistanceUnit . KILOMETERS , new GeoPoint ( Double . parseDouble ( jobQuery . getLatitude ( ) . toString ( ) ) , Double . parseDouble ( jobQuery . getLongitude ( ) . toString ( ) ) ) ) ;
@@ -607,17 +607,17 @@ public class ESJobSearchImpl implements IESJobSearchService
if ( jobQuery . getJobLocationAreaCode ( ) ! = null ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getJobLocationAreaCode , jobQuery . getJobLocationAreaCode ( ) ) ) ;
}
if ( ! StringUtil . isEmptyOrNull ( jobQuery . getScale ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getScale , jobQuery . getScale ( ) ) ) ;
if ( hasText ( jobQuery . getScale ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getScale , jobQuery . getScale ( ) . trim ( ) )) ;
}
if ( ! StringUtil . isEmptyOrNull ( jobQuery . getSearchValue ( ) ) ) {
wrapper . and ( a - > a . match ( ESJobDocument : : getDescription , jobQuery . getSearchValue ( ) , 4 . 0f ) ) ;
if ( hasText ( jobQuery . getSearchValue ( ) ) ) {
wrapper . and ( a - > a . match ( ESJobDocument : : getDescription , jobQuery . getSearchValue ( ) . trim ( ) ,4 . 0f ) ) ;
}
if ( ! StringUtil . isEmptyOrNull ( jobQuery . getCompanyNature ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getCompanyNature , jobQuery . getCompanyNature ( ) ) ) ;
if ( hasText ( jobQuery . getCompanyNature ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getCompanyNature , jobQuery . getCompanyNature ( ) . trim ( ) )) ;
}
if ( ! StringUtil . isEmptyOrNull ( jobQuery . getType ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getType , jobQuery . getType ( ) ) ) ;
if ( hasText ( jobQuery . getType ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getType , jobQuery . getType ( ) . trim ( ) )) ;
}
if ( Objects . nonNull ( jobQuery . getOrder ( ) ) ) {
if ( jobQuery . getOrder ( ) = = 2 ) {
@@ -632,6 +632,99 @@ public class ESJobSearchImpl implements IESJobSearchService
EsPageInfo < ESJobDocument > esJobDocumentEsPageInfo = esJobDocumentMapper . pageQuery ( wrapper , pageNum , pageSize ) ;
return esJobDocumentEsPageInfo ;
}
@Override
public EsPageInfo < ESJobDocument > aiList ( ESJobSearch jobQuery ) {
Integer pageNum = jobQuery . getCurrent ( ) ;
Integer pageSize = jobQuery . getPageSize ( ) ;
// 第一次查询:包含区域条件
EsPageInfo < ESJobDocument > result = doAiListQuery ( jobQuery , pageNum , pageSize , true ) ;
// 降级查询:如果没有找到岗位且有区域条件,忽略区域重新查询
if ( ( result . getList ( ) = = null | | result . getList ( ) . isEmpty ( ) )
& & ( hasText ( jobQuery . getArea ( ) ) | | jobQuery . getJobLocationAreaCode ( ) ! = null ) ) {
logger . info ( " AI岗位查询降级: 忽略区域条件重新查询 " ) ;
result = doAiListQuery ( jobQuery , pageNum , pageSize , false ) ;
}
return result ;
}
/**
* AI岗位查询核心逻辑
* @param jobQuery 查询条件
* @param pageNum 页码
* @param pageSize 每页大小
* @param includeArea 是否包含区域条件
*/
private EsPageInfo < ESJobDocument > doAiListQuery ( ESJobSearch jobQuery , Integer pageNum , Integer pageSize , boolean includeArea ) {
LambdaEsQueryWrapper < ESJobDocument > wrapper = new LambdaEsQueryWrapper < > ( ) ;
if ( hasText ( jobQuery . getJobTitle ( ) ) ) {
wrapper . and ( a - > a . match ( ESJobDocument : : getJobTitle , jobQuery . getJobTitle ( ) . trim ( ) , 5 . 0f )
. or ( )
. match ( ESJobDocument : : getDescription , jobQuery . getJobTitle ( ) . trim ( ) , 1 . 0f ) ) ;
}
if ( hasText ( jobQuery . getEducation ( ) ) ) {
wrapper . and ( a - > a . le ( ESJobDocument : : getEducation , jobQuery . getEducation ( ) . trim ( ) ) ) ;
}
// 区域条件:根据 includeArea 决定是否加入
if ( includeArea & & hasText ( jobQuery . getArea ( ) ) ) {
List < Integer > integers = StringUtil . convertStringToIntegerList ( jobQuery . getArea ( ) . trim ( ) ) ;
wrapper . and ( x - > x . in ( ESJobDocument : : getJobLocationAreaCode , integers ) ) ;
}
if ( hasText ( jobQuery . getExperience ( ) ) ) {
wrapper . and ( a - > a . le ( ESJobDocument : : getExperience , jobQuery . getExperience ( ) . trim ( ) ) ) ;
}
if ( Objects . nonNull ( jobQuery . getMaxSalary ( ) ) ) {
wrapper . and ( x - > x . le ( ESJobDocument : : getMaxSalary , jobQuery . getMaxSalary ( ) ) ) ;
}
if ( Objects . nonNull ( jobQuery . getMinSalary ( ) ) ) {
wrapper . and ( x - > x . ge ( ESJobDocument : : getMinSalary , jobQuery . getMinSalary ( ) ) ) ;
}
if ( hasText ( jobQuery . getScaleDictCode ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getScaleDictCode , jobQuery . getScaleDictCode ( ) . trim ( ) ) ) ;
}
if ( hasText ( jobQuery . getIndustry ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getIndustry , jobQuery . getIndustry ( ) . trim ( ) ) ) ;
}
if ( jobQuery . getLongitude ( ) ! = null ) {
wrapper . geoDistance ( ESJobDocument : : getLatAndLon , Double . valueOf ( jobQuery . getRadius ( ) ) , DistanceUnit . KILOMETERS , new GeoPoint ( Double . parseDouble ( jobQuery . getLatitude ( ) . toString ( ) ) , Double . parseDouble ( jobQuery . getLongitude ( ) . toString ( ) ) ) ) ;
}
// 区域编码条件:根据 includeArea 决定是否加入
if ( includeArea & & jobQuery . getJobLocationAreaCode ( ) ! = null ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getJobLocationAreaCode , jobQuery . getJobLocationAreaCode ( ) ) ) ;
}
if ( hasText ( jobQuery . getScale ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getScale , jobQuery . getScale ( ) . trim ( ) ) ) ;
}
if ( hasText ( jobQuery . getSearchValue ( ) ) ) {
wrapper . and ( a - > a . match ( ESJobDocument : : getDescription , jobQuery . getSearchValue ( ) . trim ( ) , 4 . 0f ) ) ;
}
if ( hasText ( jobQuery . getCompanyNature ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getCompanyNature , jobQuery . getCompanyNature ( ) . trim ( ) ) ) ;
}
if ( hasText ( jobQuery . getType ( ) ) ) {
wrapper . and ( a - > a . eq ( ESJobDocument : : getType , jobQuery . getType ( ) . trim ( ) ) ) ;
}
if ( Objects . nonNull ( jobQuery . getOrder ( ) ) ) {
if ( jobQuery . getOrder ( ) = = 2 ) {
wrapper . orderByDesc ( ESJobDocument : : getPostingDate ) ;
}
if ( jobQuery . getOrder ( ) = = 1 ) {
wrapper . orderByDesc ( ESJobDocument : : getIsHot ) ;
wrapper . orderByDesc ( ESJobDocument : : getApplyNum ) ;
wrapper . orderByDesc ( ESJobDocument : : getView ) ;
}
}
return esJobDocumentMapper . pageQuery ( wrapper , pageNum , pageSize ) ;
}
/**
* 判断字符串是否有实际内容( 非null、非空、非纯空白)
*/
private boolean hasText ( String str ) {
return str ! = null & & ! str . trim ( ) . isEmpty ( ) ;
}
@Override
public ESJobDocument selectById ( Long jobId ) {