添加不感兴趣接口
This commit is contained in:
@@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import org.jiayunet.pojo.PageResult;
|
import org.jiayunet.pojo.PageResult;
|
||||||
import org.jiayunet.pojo.dto.job.JobDetailDto;
|
import org.jiayunet.pojo.dto.job.JobDetailDto;
|
||||||
import org.jiayunet.pojo.dto.job.JobDto;
|
import org.jiayunet.pojo.dto.job.JobDto;
|
||||||
|
import org.jiayunet.pojo.param.job.JobDislikeParam;
|
||||||
import org.jiayunet.pojo.param.job.JobQueryParam;
|
import org.jiayunet.pojo.param.job.JobQueryParam;
|
||||||
import org.jiayunet.service.JobService;
|
import org.jiayunet.service.JobService;
|
||||||
import org.jiayunet.tool.UserSecurityTool;
|
import org.jiayunet.tool.UserSecurityTool;
|
||||||
@@ -59,4 +60,13 @@ public class JobController {
|
|||||||
Long userId = UserSecurityTool.getUserId();
|
Long userId = UserSecurityTool.getUserId();
|
||||||
jobService.unfavoriteJob(jobId, userId);
|
jobService.unfavoriteJob(jobId, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标记岗位不感兴趣
|
||||||
|
*/
|
||||||
|
@PostMapping("/{jobId}/dislike")
|
||||||
|
public void dislikeJob(@PathVariable Long jobId, @Validated @RequestBody JobDislikeParam param) {
|
||||||
|
Long userId = UserSecurityTool.getUserId();
|
||||||
|
jobService.dislikeJob(jobId, param.getReason(), userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.jiayunet.pojo.param.job;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Max;
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标记岗位不感兴趣参数
|
||||||
|
*
|
||||||
|
* @author zk
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class JobDislikeParam {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不感兴趣原因
|
||||||
|
* <p>0=对公司不感兴趣 1=对岗位不感兴趣 2=对行业不感兴趣 3=技能不符合 4=地点不合适 5=其他</p>
|
||||||
|
*/
|
||||||
|
@NotNull(message = "原因不能为空")
|
||||||
|
@Min(value = 0, message = "原因值范围0-5")
|
||||||
|
@Max(value = 5, message = "原因值范围0-5")
|
||||||
|
private Integer reason;
|
||||||
|
}
|
||||||
@@ -21,9 +21,9 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 岗位服务
|
* 岗位服务
|
||||||
* <p>主要功能:岗位列表查询、岗位详情查询、岗位收藏管理、匹配度计算</p>
|
* <p>主要功能:岗位列表查询、岗位详情查询、岗位收藏管理、岗位不感兴趣管理、匹配度计算</p>
|
||||||
* <p>依赖服务:JobMatchService(匹配度计算)</p>
|
* <p>依赖服务:JobMatchService(匹配度计算)</p>
|
||||||
* <p>使用的表:bg_job、bg_company、bg_user_job_dislike、bg_user_job_favorite、bg_china_regions_code、bg_job_category、bg_industry</p>
|
* <p>使用的表:bg_job、bg_company、bg_user_job_dislike、bg_user_job_favorite、bg_job_region、bg_china_regions_code、bg_job_category、bg_industry</p>
|
||||||
*
|
*
|
||||||
* @author zk
|
* @author zk
|
||||||
*/
|
*/
|
||||||
@@ -52,6 +52,9 @@ public class JobService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CompanyMapper companyMapper;
|
private CompanyMapper companyMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JobRegionRelationMapper jobRegionRelationMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private JobMatchService jobMatchService;
|
private JobMatchService jobMatchService;
|
||||||
|
|
||||||
@@ -294,4 +297,57 @@ public class JobService {
|
|||||||
public void unfavoriteJob(Long jobId, Long userId) {
|
public void unfavoriteJob(Long jobId, Long userId) {
|
||||||
userJobFavoriteMapper.delete(new LambdaQueryWrapper<UserJobFavorite>().eq(UserJobFavorite::getUserId, userId).eq(UserJobFavorite::getJobId, jobId));
|
userJobFavoriteMapper.delete(new LambdaQueryWrapper<UserJobFavorite>().eq(UserJobFavorite::getUserId, userId).eq(UserJobFavorite::getJobId, jobId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标记岗位不感兴趣
|
||||||
|
* <p>方法逻辑流程:</p>
|
||||||
|
* <p>1. 查询岗位信息(获取 companyId、requiredIndustryId)</p>
|
||||||
|
* <p>2. 查询岗位关联的地区列表</p>
|
||||||
|
* <p>3. 检查是否已标记</p>
|
||||||
|
* <p>4. 根据 reason 构建插入记录列表</p>
|
||||||
|
* <p>5. 批量插入记录</p>
|
||||||
|
*/
|
||||||
|
public void dislikeJob(Long jobId, Integer reason, Long userId) {
|
||||||
|
// 1. 查询岗位
|
||||||
|
Job job = jobMapper.selectOne(new LambdaQueryWrapper<Job>().eq(Job::getId, jobId).eq(Job::getStatus, 0));
|
||||||
|
if (job == null) throw new RuntimeException("岗位不存在或已下架");
|
||||||
|
|
||||||
|
// 2. 查询岗位关联的地区
|
||||||
|
List<JobRegionRelation> regions = jobRegionRelationMapper.selectList(new LambdaQueryWrapper<JobRegionRelation>().eq(JobRegionRelation::getJobId, jobId));
|
||||||
|
|
||||||
|
// 3. 检查是否已标记
|
||||||
|
Long count = userJobDislikeMapper.selectCount(new LambdaQueryWrapper<UserJobDislike>().eq(UserJobDislike::getUserId, userId).eq(UserJobDislike::getJobId, jobId));
|
||||||
|
if (count > 0) throw new RuntimeException("已标记该岗位不感兴趣");
|
||||||
|
|
||||||
|
// 4. 根据 reason 构建插入记录
|
||||||
|
List<UserJobDislike> records = new ArrayList<>();
|
||||||
|
if (reason == 4 && !regions.isEmpty()) {
|
||||||
|
// reason=4(地点不合适):每个地区一条
|
||||||
|
for (JobRegionRelation region : regions) {
|
||||||
|
UserJobDislike dislike = new UserJobDislike();
|
||||||
|
dislike.setUserId(userId);
|
||||||
|
dislike.setJobId(jobId);
|
||||||
|
dislike.setCompanyId(job.getCompanyId());
|
||||||
|
dislike.setRegionCode(region.getRegionCode());
|
||||||
|
dislike.setIndustryId(job.getRequiredIndustryId());
|
||||||
|
dislike.setReason(reason);
|
||||||
|
dislike.setCreateTime(Instant.now());
|
||||||
|
records.add(dislike);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 其他 reason:插入一条
|
||||||
|
UserJobDislike dislike = new UserJobDislike();
|
||||||
|
dislike.setUserId(userId);
|
||||||
|
dislike.setJobId(jobId);
|
||||||
|
dislike.setCompanyId(reason == 0 ? job.getCompanyId() : null);
|
||||||
|
dislike.setRegionCode(null);
|
||||||
|
dislike.setIndustryId(reason == 2 ? job.getRequiredIndustryId() : null);
|
||||||
|
dislike.setReason(reason);
|
||||||
|
dislike.setCreateTime(Instant.now());
|
||||||
|
records.add(dislike);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 批量插入
|
||||||
|
userJobDislikeMapper.batchInsert(records);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user