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 68f6940..cdd4b9d 100644 --- a/client-api/src/main/java/org/jiayunet/controller/JobController.java +++ b/client-api/src/main/java/org/jiayunet/controller/JobController.java @@ -41,4 +41,22 @@ public class JobController { Long userId = UserSecurityTool.getUserId(); return jobService.getJobDetail(jobId, userId); } + + /** + * 收藏岗位 + */ + @PostMapping("/{jobId}/favorite") + public void favoriteJob(@PathVariable Long jobId) { + Long userId = UserSecurityTool.getUserId(); + jobService.favoriteJob(jobId, userId); + } + + /** + * 取消收藏岗位 + */ + @DeleteMapping("/{jobId}/favorite") + public void unfavoriteJob(@PathVariable Long jobId) { + Long userId = UserSecurityTool.getUserId(); + jobService.unfavoriteJob(jobId, userId); + } } 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 14a3dcd..e2d6a9b 100644 --- a/client-api/src/main/java/org/jiayunet/service/JobService.java +++ b/client-api/src/main/java/org/jiayunet/service/JobService.java @@ -15,12 +15,13 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.time.Instant; import java.util.*; import java.util.stream.Collectors; /** * 岗位服务 - *

主要功能:岗位列表查询、岗位详情查询、匹配度计算

+ *

主要功能:岗位列表查询、岗位详情查询、岗位收藏管理、匹配度计算

*

依赖服务:JobMatchService(匹配度计算)

*

使用的表:bg_job、bg_company、bg_user_job_dislike、bg_user_job_favorite、bg_china_regions_code、bg_job_category、bg_industry

* @@ -261,4 +262,36 @@ public class JobService { return dto; } + /** + * 收藏岗位 + *

方法逻辑流程:

+ *

1. 检查岗位是否存在

+ *

2. 检查是否已收藏(避免重复)

+ *

3. 插入收藏记录

+ */ + public void favoriteJob(Long jobId, Long userId) { + // 1. 检查岗位是否存在 + Job job = jobMapper.selectOne(new LambdaQueryWrapper().eq(Job::getId, jobId).eq(Job::getStatus, 0)); + if (job == null) throw new RuntimeException("岗位不存在或已下架"); + + // 2. 检查是否已收藏 + Long count = userJobFavoriteMapper.selectCount(new LambdaQueryWrapper().eq(UserJobFavorite::getUserId, userId).eq(UserJobFavorite::getJobId, jobId)); + if (count > 0) throw new RuntimeException("已收藏该岗位"); + + // 3. 插入收藏记录 + UserJobFavorite favorite = new UserJobFavorite(); + favorite.setUserId(userId); + favorite.setJobId(jobId); + favorite.setCreateTime(Instant.now()); + userJobFavoriteMapper.insert(favorite); + } + + /** + * 取消收藏岗位 + *

方法逻辑流程:

+ *

1. 删除收藏记录

+ */ + public void unfavoriteJob(Long jobId, Long userId) { + userJobFavoriteMapper.delete(new LambdaQueryWrapper().eq(UserJobFavorite::getUserId, userId).eq(UserJobFavorite::getJobId, jobId)); + } }