添加收藏列表
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.jiayunet.controller;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.jiayunet.pojo.PageParam;
|
||||
import org.jiayunet.pojo.PageResult;
|
||||
import org.jiayunet.pojo.dto.job.JobDetailDto;
|
||||
import org.jiayunet.pojo.dto.job.JobDto;
|
||||
@@ -69,4 +70,13 @@ public class JobController {
|
||||
Long userId = UserSecurityTool.getUserId();
|
||||
jobService.dislikeJob(jobId, param.getReason(), userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收藏列表
|
||||
*/
|
||||
@PostMapping("/favorite/list")
|
||||
public PageResult<JobDto> listFavoriteJobs(@Validated @RequestBody PageParam param) {
|
||||
Long userId = UserSecurityTool.getUserId();
|
||||
return jobService.listFavoriteJobs(param, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,4 +26,7 @@ public class JobQueryParam extends PageParam {
|
||||
|
||||
/** 工作类型 0=全职 1=兼职 */
|
||||
private Integer employmentType;
|
||||
|
||||
/** 指定岗位ID列表(用于收藏列表) */
|
||||
private List<Long> jobIds;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jiayunet.mapper.*;
|
||||
import org.jiayunet.pojo.PageParam;
|
||||
import org.jiayunet.pojo.PageResult;
|
||||
import org.jiayunet.pojo.dto.job.JobDetailDto;
|
||||
import org.jiayunet.pojo.dto.job.JobDto;
|
||||
@@ -89,7 +90,7 @@ public class JobService {
|
||||
List<Long> excludeIndustryIds = dislikes.stream().map(UserJobDislike::getIndustryId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
||||
|
||||
// 6. 执行分页查询
|
||||
Page<JobListItemVo> page = jobMapper.selectJobPage(param.toPage(), expandedRegionCodes, expandedCategoryIds, expandedIndustryIds, param.getEmploymentType(), excludeJobIds, excludeCompanyIds, excludeRegionCodes, excludeIndustryIds);
|
||||
Page<JobListItemVo> page = jobMapper.selectJobPage(param.toPage(), param.getJobIds(), expandedRegionCodes, expandedCategoryIds, expandedIndustryIds, param.getEmploymentType(), excludeJobIds, excludeCompanyIds, excludeRegionCodes, excludeIndustryIds);
|
||||
|
||||
// 7. 查询收藏状态
|
||||
List<Long> jobIds = page.getRecords().stream().map(JobListItemVo::getId).collect(Collectors.toList());
|
||||
@@ -350,4 +351,31 @@ public class JobService {
|
||||
// 5. 批量插入
|
||||
userJobDislikeMapper.batchInsert(records);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收藏列表查询
|
||||
* <p>方法逻辑流程:</p>
|
||||
* <p>1. 分页查询收藏记录(按创建时间倒序)</p>
|
||||
* <p>2. 提取岗位ID列表</p>
|
||||
* <p>3. 复用岗位列表查询逻辑</p>
|
||||
*/
|
||||
public PageResult<JobDto> listFavoriteJobs(PageParam param, Long userId) {
|
||||
// 1. 分页查询收藏记录
|
||||
Page<UserJobFavorite> favPage = new Page<>(param.getPageNum(), param.getPageNum());
|
||||
Page<UserJobFavorite> favorites = userJobFavoriteMapper.selectPage(favPage, new LambdaQueryWrapper<UserJobFavorite>().eq(UserJobFavorite::getUserId, userId).orderByDesc(UserJobFavorite::getCreateTime));
|
||||
|
||||
// 2. 提取 jobId 列表
|
||||
List<Long> jobIds = favorites.getRecords().stream().map(UserJobFavorite::getJobId).collect(Collectors.toList());
|
||||
if (jobIds.isEmpty()) {
|
||||
return new PageResult<>(param.getPageNum().longValue(), param.getPageSize().longValue(), 0L, Collections.emptyList());
|
||||
}
|
||||
|
||||
// 3. 构造查询参数,复用岗位列表逻辑
|
||||
JobQueryParam queryParam = new JobQueryParam();
|
||||
queryParam.setPageNum(param.getPageNum());
|
||||
queryParam.setPageSize(param.getPageSize());
|
||||
queryParam.setJobIds(jobIds);
|
||||
|
||||
return listJobs(queryParam, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,5 +19,5 @@ public interface JobMapper extends CommonMapper<Job> {
|
||||
/**
|
||||
* 分页查询岗位列表
|
||||
*/
|
||||
Page<JobListItemVo> selectJobPage(Page<JobListItemVo> page, @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);
|
||||
Page<JobListItemVo> selectJobPage(Page<JobListItemVo> page, @Param("jobIds") List<Long> jobIds, @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);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,13 @@
|
||||
INNER JOIN bg_job_category cat ON j.category_id = cat.id
|
||||
WHERE j.status = 0
|
||||
AND c.status = 1
|
||||
<!-- 指定岗位ID列表(用于收藏列表) -->
|
||||
<if test="jobIds != null and jobIds.size() > 0">
|
||||
AND j.id IN
|
||||
<foreach collection="jobIds" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<!-- 排除不感兴趣的岗位 -->
|
||||
<if test="excludeJobIds != null and excludeJobIds.size() > 0">
|
||||
AND j.id NOT IN
|
||||
|
||||
Reference in New Issue
Block a user