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

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>