diff --git a/client-api/src/main/java/org/jiayunet/controller/JobController.java b/client-api/src/main/java/org/jiayunet/controller/JobController.java index 46d5efc..7a8b528 100644 --- a/client-api/src/main/java/org/jiayunet/controller/JobController.java +++ b/client-api/src/main/java/org/jiayunet/controller/JobController.java @@ -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 listFavoriteJobs(@Validated @RequestBody PageParam param) { + Long userId = UserSecurityTool.getUserId(); + return jobService.listFavoriteJobs(param, userId); + } } diff --git a/client-api/src/main/java/org/jiayunet/pojo/param/job/JobQueryParam.java b/client-api/src/main/java/org/jiayunet/pojo/param/job/JobQueryParam.java index 684c3a5..44d3f4b 100644 --- a/client-api/src/main/java/org/jiayunet/pojo/param/job/JobQueryParam.java +++ b/client-api/src/main/java/org/jiayunet/pojo/param/job/JobQueryParam.java @@ -26,4 +26,7 @@ public class JobQueryParam extends PageParam { /** 工作类型 0=全职 1=兼职 */ private Integer employmentType; + + /** 指定岗位ID列表(用于收藏列表) */ + private List jobIds; } diff --git a/client-api/src/main/java/org/jiayunet/service/JobService.java b/client-api/src/main/java/org/jiayunet/service/JobService.java index b69930f..98d8a4e 100644 --- a/client-api/src/main/java/org/jiayunet/service/JobService.java +++ b/client-api/src/main/java/org/jiayunet/service/JobService.java @@ -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 excludeIndustryIds = dislikes.stream().map(UserJobDislike::getIndustryId).filter(Objects::nonNull).distinct().collect(Collectors.toList()); // 6. 执行分页查询 - Page page = jobMapper.selectJobPage(param.toPage(), expandedRegionCodes, expandedCategoryIds, expandedIndustryIds, param.getEmploymentType(), excludeJobIds, excludeCompanyIds, excludeRegionCodes, excludeIndustryIds); + Page page = jobMapper.selectJobPage(param.toPage(), param.getJobIds(), expandedRegionCodes, expandedCategoryIds, expandedIndustryIds, param.getEmploymentType(), excludeJobIds, excludeCompanyIds, excludeRegionCodes, excludeIndustryIds); // 7. 查询收藏状态 List jobIds = page.getRecords().stream().map(JobListItemVo::getId).collect(Collectors.toList()); @@ -350,4 +351,31 @@ public class JobService { // 5. 批量插入 userJobDislikeMapper.batchInsert(records); } + + /** + * 收藏列表查询 + *

方法逻辑流程:

+ *

1. 分页查询收藏记录(按创建时间倒序)

+ *

2. 提取岗位ID列表

+ *

3. 复用岗位列表查询逻辑

+ */ + public PageResult listFavoriteJobs(PageParam param, Long userId) { + // 1. 分页查询收藏记录 + Page favPage = new Page<>(param.getPageNum(), param.getPageNum()); + Page favorites = userJobFavoriteMapper.selectPage(favPage, new LambdaQueryWrapper().eq(UserJobFavorite::getUserId, userId).orderByDesc(UserJobFavorite::getCreateTime)); + + // 2. 提取 jobId 列表 + List 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); + } } diff --git a/manager/src/main/java/org/jiayunet/mapper/JobMapper.java b/manager/src/main/java/org/jiayunet/mapper/JobMapper.java index d36d1a2..0398895 100644 --- a/manager/src/main/java/org/jiayunet/mapper/JobMapper.java +++ b/manager/src/main/java/org/jiayunet/mapper/JobMapper.java @@ -19,5 +19,5 @@ public interface JobMapper extends CommonMapper { /** * 分页查询岗位列表 */ - Page selectJobPage(Page page, @Param("regionCodes") List regionCodes, @Param("categoryIds") List categoryIds, @Param("industryIds") List industryIds, @Param("employmentType") Integer employmentType, @Param("excludeJobIds") List excludeJobIds, @Param("excludeCompanyIds") List excludeCompanyIds, @Param("excludeRegionCodes") List excludeRegionCodes, @Param("excludeIndustryIds") List excludeIndustryIds); + Page selectJobPage(Page page, @Param("jobIds") List jobIds, @Param("regionCodes") List regionCodes, @Param("categoryIds") List categoryIds, @Param("industryIds") List industryIds, @Param("employmentType") Integer employmentType, @Param("excludeJobIds") List excludeJobIds, @Param("excludeCompanyIds") List excludeCompanyIds, @Param("excludeRegionCodes") List excludeRegionCodes, @Param("excludeIndustryIds") List excludeIndustryIds); } diff --git a/manager/src/main/resources/mapper/JobMapper.xml b/manager/src/main/resources/mapper/JobMapper.xml index eb6bd85..d0c5395 100644 --- a/manager/src/main/resources/mapper/JobMapper.xml +++ b/manager/src/main/resources/mapper/JobMapper.xml @@ -26,6 +26,13 @@ INNER JOIN bg_job_category cat ON j.category_id = cat.id WHERE j.status = 0 AND c.status = 1 + + + AND j.id IN + + #{id} + + AND j.id NOT IN