添加岗位列表数量统计接口

This commit is contained in:
zk
2026-08-05 11:23:23 +08:00
parent 9ce99ab3d7
commit 243b1ffc5a
4 changed files with 114 additions and 31 deletions
@@ -47,6 +47,23 @@ public class JobController {
return jobService.listJobs(param, userId);
}
/**
* 岗位列表总数查询
* <p>筛选条件与 /job/list 一致,仅返回符合条件的岗位总数,接口允许不登录访问</p>
*/
@PostMapping("/list/count")
public Long countJobs(@Validated @RequestBody JobQueryParam param) {
Long userId = 0L;
try {
userId = UserSecurityTool.getUserId();
} catch (Exception e) {
// 接口允许不登录,不处理
}
return jobService.countJobs(param, userId);
}
/**
* 岗位详情
* <p>返回岗位完整信息、公司信息、匹配度、收藏状态</p>
@@ -161,6 +161,49 @@ public class JobService {
return new PageResult<>(page.getCurrent(), page.getSize(), page.getTotal(), dtoList);
}
/**
* 岗位列表总数查询
* <p>过滤条件与 listJobs 完全一致(SQL 层共用 jobPageWhere 片段),不分页、不查收藏/投递状态、不算匹配度</p>
* <p>方法逻辑流程:</p>
* <p>1. 扩展筛选条件的子级(地区/岗位类型/行业)</p>
* <p>2. 查询用户不感兴趣记录</p>
* <p>3. 提取排除列表(岗位/公司/地区/行业)</p>
* <p>4. 执行统计查询</p>
*/
public Long countJobs(JobQueryParam param, Long userId) {
// 默认只查有效岗位
if (param.getStatusFilter() == null) {
param.setStatusFilter(Collections.singletonList(0));
}
// 1. 扩展筛选条件的子级
List<String> expandedRegionCodes = expandRegionCodes(param.getRegionCodes());
List<Long> expandedCategoryIds = expandCategoryIds(param.getCategoryIds());
List<Long> expandedIndustryIds = expandIndustryIds(param.getIndustryIds());
// 2. 查询用户不感兴趣记录
List<UserJobDislike> dislikes = userJobDislikeMapper.selectList(new LambdaQueryWrapper<UserJobDislike>().eq(UserJobDislike::getUserId, userId));
// 3. 提取排除列表
List<Long> excludeJobIds = dislikes.stream().map(UserJobDislike::getJobId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
if (param.getExcludeJobIds() != null && !param.getExcludeJobIds().isEmpty()) {
excludeJobIds.addAll(param.getExcludeJobIds());
}
List<Long> excludeCompanyIds = dislikes.stream().map(UserJobDislike::getCompanyId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
// 4. 提取不感兴趣的地区(直接使用,不扩展子级)
List<String> excludeRegionCodes = dislikes.stream().map(UserJobDislike::getRegionCode).filter(Objects::nonNull).distinct().collect(Collectors.toList());
// 5. 提取不感兴趣的行业(直接使用,不扩展子级)
List<Long> excludeIndustryIds = dislikes.stream().map(UserJobDislike::getIndustryId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
// 6. 执行统计查询
Long total = jobMapper.countJobPage(param.getJobIds(), param.getStatusFilter(), param.getKeyword(), expandedRegionCodes, expandedCategoryIds, expandedIndustryIds, param.getEmploymentType(), excludeJobIds, excludeCompanyIds, excludeRegionCodes, excludeIndustryIds, param.getRecruitCategory(), param.getCompanyTypes(), param.getCompanyId(), param.getEducations(), param.getPublishStartTime(), param.getPublishEndTime());
return total == null ? 0L : total;
}
/**
* 扩展地区编码(包含自身和所有子级)
* <p>一次查询:code本身 + provinceCode匹配 + cityCode匹配</p>
@@ -21,4 +21,10 @@ public interface JobMapper extends CommonMapper<Job> {
* 分页查询岗位列表
*/
Page<JobListItemVo> selectJobPage(Page<JobListItemVo> page, @Param("jobIds") List<Long> jobIds, @Param("statusFilter") List<Integer> statusFilter, @Param("keyword") String keyword, @Param("regionCodes") List<String> regionCodes, @Param("categoryIds") List<Long> categoryIds, @Param("industryIds") List<Long> industryIds, @Param("employmentType") Integer employmentType, @Param("excludeJobIds") List<Long> excludeJobIds, @Param("excludeCompanyIds") List<Long> excludeCompanyIds, @Param("excludeRegionCodes") List<String> excludeRegionCodes, @Param("excludeIndustryIds") List<Long> excludeIndustryIds, @Param("recruitCategory") Integer recruitCategory, @Param("companyTypes") List<String> companyTypes, @Param("companyId") Long companyId, @Param("educations") List<Integer> educations, @Param("publishStartTime") Instant publishStartTime, @Param("publishEndTime") Instant publishEndTime);
/**
* 统计岗位列表总数
* <p>过滤条件与 selectJobPage 共用同一段 SQLjobPageWhere),保证列表与总数口径一致</p>
*/
Long countJobPage(@Param("jobIds") List<Long> jobIds, @Param("statusFilter") List<Integer> statusFilter, @Param("keyword") String keyword, @Param("regionCodes") List<String> regionCodes, @Param("categoryIds") List<Long> categoryIds, @Param("industryIds") List<Long> industryIds, @Param("employmentType") Integer employmentType, @Param("excludeJobIds") List<Long> excludeJobIds, @Param("excludeCompanyIds") List<Long> excludeCompanyIds, @Param("excludeRegionCodes") List<String> excludeRegionCodes, @Param("excludeIndustryIds") List<Long> excludeIndustryIds, @Param("recruitCategory") Integer recruitCategory, @Param("companyTypes") List<String> companyTypes, @Param("companyId") Long companyId, @Param("educations") List<Integer> educations, @Param("publishStartTime") Instant publishStartTime, @Param("publishEndTime") Instant publishEndTime);
}
+48 -31
View File
@@ -30,37 +30,11 @@
<result column="company_industry_id" property="companyIndustryId"/>
</resultMap>
<select id="selectJobPage" resultMap="JobListItemVoMap">
SELECT
j.id,
j.title,
j.salary,
j.education,
j.tags,
j.source_url,
j.required_industry_id,
j.min_experience,
j.required_major_ids,
j.major_sensitivity,
j.status,
j.expire_at,
j.pyname,
j.recruit_category,
c.id AS company_id,
c.name AS company_name,
c.short_name AS company_short_name,
c.company_type,
c.logo_url AS company_logo_url,
c.tags AS company_tags,
c.industry_id AS company_industry_id,
c.region_code,
r.name AS region_name,
cat.id AS category_id,
cat.name AS category_name
FROM bg_job j force index (`PRIMARY`)
INNER JOIN bg_company c ON j.company_id = c.id
INNER JOIN bg_china_regions_code r ON c.region_code = r.code
INNER JOIN bg_job_category cat ON j.category_id = cat.id
<!--
岗位查询过滤条件(selectJobPage 与 countJobPage 共用)
新增/修改筛选条件只需改这里,保证列表与总数口径一致
-->
<sql id="jobPageWhere">
WHERE c.status = 1
<!-- 岗位状态过滤 -->
<if test="statusFilter != null and statusFilter.size() > 0">
@@ -168,7 +142,50 @@
<if test="publishEndTime != null">
AND j.expire_at &lt;= #{publishEndTime}
</if>
</sql>
<select id="selectJobPage" resultMap="JobListItemVoMap">
SELECT
j.id,
j.title,
j.salary,
j.education,
j.tags,
j.source_url,
j.required_industry_id,
j.min_experience,
j.required_major_ids,
j.major_sensitivity,
j.status,
j.expire_at,
j.pyname,
j.recruit_category,
c.id AS company_id,
c.name AS company_name,
c.short_name AS company_short_name,
c.company_type,
c.logo_url AS company_logo_url,
c.tags AS company_tags,
c.industry_id AS company_industry_id,
c.region_code,
r.name AS region_name,
cat.id AS category_id,
cat.name AS category_name
FROM bg_job j force index (`PRIMARY`)
INNER JOIN bg_company c ON j.company_id = c.id
INNER JOIN bg_china_regions_code r ON c.region_code = r.code
INNER JOIN bg_job_category cat ON j.category_id = cat.id
<include refid="jobPageWhere"/>
ORDER BY j.id DESC
</select>
<select id="countJobPage" resultType="java.lang.Long">
SELECT COUNT(*)
FROM bg_job j
INNER JOIN bg_company c ON j.company_id = c.id
INNER JOIN bg_china_regions_code r ON c.region_code = r.code
INNER JOIN bg_job_category cat ON j.category_id = cat.id
<include refid="jobPageWhere"/>
</select>
</mapper>