From 1d2d17d86747995f14ac36b46029c413a686c853 Mon Sep 17 00:00:00 2001 From: zk Date: Fri, 20 Mar 2026 19:29:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=94=B6=E8=97=8F=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jiayunet/controller/JobController.java | 18 ++++++++++ .../java/org/jiayunet/service/JobService.java | 35 ++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) 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)); + } }