添加个人屏蔽企业,并且推荐岗位时,并且企业对应的岗位

This commit is contained in:
chenshaohua
2026-07-08 23:10:24 +08:00
parent 041a5b696e
commit 8a152a2854
9 changed files with 457 additions and 6 deletions

View File

@@ -0,0 +1,82 @@
package com.ruoyi.cms.controller.app;
import com.ruoyi.cms.domain.AppUserBlockCompany;
import com.ruoyi.cms.service.AppUserBlockCompanyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SiteSecurityUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/app/blockCompany")
public class AppUserBlockCompanyController extends BaseController {
@Resource
private AppUserBlockCompanyService blockCompanyService;
/**
* 新增屏蔽企业
*/
@ApiOperation("新增屏蔽企业")
@PostMapping
public AjaxResult add(@RequestBody AppUserBlockCompany entity) {
if(!SiteSecurityUtils.isLogin()){
return error("未登录!");
}
if(entity.getUserId()==null){
entity.setUserId(SiteSecurityUtils.getUserId());
}
return toAjax(blockCompanyService.addBlockCompany(entity));
}
/**
* 取消屏蔽企业
*/
@ApiOperation("取消屏蔽企业")
@DeleteMapping("/{userIds}")
public AjaxResult cancel(@PathVariable Long[] userIds) {
if(!SiteSecurityUtils.isLogin()){
return error("未登录!");
}
return toAjax(blockCompanyService.cancelBlock(userIds));
}
/**
* 获取当前用户屏蔽企业列表
*/
@ApiOperation("获取当前用户屏蔽企业列表")
@GetMapping("/list")
public TableDataInfo list(AppUserBlockCompany appUserBlockCompany){
if(appUserBlockCompany.getUserId()==null){
appUserBlockCompany.setUserId(SiteSecurityUtils.getUserId());
}
startPage();
List<AppUserBlockCompany> list=blockCompanyService.listByUserId(appUserBlockCompany.getUserId());
return getDataTable(list);
}
/**
* 查询当前用户屏蔽的企业ID集合用于过滤职位
*/
@ApiOperation("查询当前用户屏蔽的企业ID集合")
@GetMapping("/ids")
public AjaxResult getBlockIds() {
List<Long> ids = blockCompanyService.getBlockCompanyIds(SiteSecurityUtils.getUserId());
return AjaxResult.success(ids);
}
/**
* 校验是否屏蔽该企业
*/
@ApiOperation("校验是否屏蔽该企业")
@GetMapping("/check")
public AjaxResult check(@RequestParam Long companyId) {
boolean blocked = blockCompanyService.isBlocked(SiteSecurityUtils.getUserId(), companyId);
return AjaxResult.success(blocked);
}
}

View File

@@ -0,0 +1,105 @@
package com.ruoyi.cms.controller.cms;
import com.ruoyi.cms.domain.AppUserBlockCompany;
import com.ruoyi.cms.service.AppUserBlockCompanyService;
import com.ruoyi.cms.util.RoleUtils;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/cms/blockCompany")
public class CmsUserBlockCompanyController extends BaseController {
@Resource
private AppUserBlockCompanyService blockCompanyService;
/**
* 新增屏蔽企业
*/
@ApiOperation("新增屏蔽企业")
@PreAuthorize("@ss.hasPermi('cms:blockCompany:add')")
@PostMapping
public AjaxResult add(@RequestBody AppUserBlockCompany entity) {
if(!SecurityUtils.isLogin()){
return error("未登录!");
}
if(entity.getUserId()==null){
Long userId=RoleUtils.getSysAppuserId();
if(userId==null){
return error("未绑定移动端用户");
}
entity.setUserId(userId);
}
return toAjax(blockCompanyService.addBlockCompany(entity));
}
/**
* 取消屏蔽企业
*/
@ApiOperation("取消屏蔽企业")
@PreAuthorize("@ss.hasPermi('cms:blockCompany:cancel')")
@DeleteMapping("/{userIds}")
public AjaxResult cancel(@PathVariable Long[] userIds) {
if(!SecurityUtils.isLogin()){
return error("未登录!");
}
return toAjax(blockCompanyService.cancelBlock(userIds));
}
/**
* 获取当前用户屏蔽企业列表
*/
@ApiOperation("获取当前用户屏蔽企业列表")
@PreAuthorize("@ss.hasPermi('cms:blockCompany:list')")
@GetMapping("/list")
public TableDataInfo list(AppUserBlockCompany appUserBlockCompany){
if(!SecurityUtils.isLogin()){
return getDataTable(new ArrayList<>());
}
if(appUserBlockCompany.getUserId()==null){
appUserBlockCompany.setUserId(RoleUtils.getSysAppuserId());
}
startPage();
List<AppUserBlockCompany> list=blockCompanyService.listByUserId(appUserBlockCompany.getUserId());
return getDataTable(list);
}
/**
* 查询当前用户屏蔽的企业ID集合用于过滤职位
*/
@ApiOperation("查询当前用户屏蔽的企业ID集合")
@PreAuthorize("@ss.hasPermi('cms:blockCompany:ids')")
@GetMapping("/ids")
public AjaxResult getBlockIds() {
Long userId=RoleUtils.getSysAppuserId();
if(RoleUtils.getSysAppuserId()==null){
return error("未绑定移动端用户");
}
List<Long> ids = blockCompanyService.getBlockCompanyIds(userId);
return AjaxResult.success(ids);
}
/**
* 校验是否屏蔽该企业
*/
@ApiOperation("校验是否屏蔽该企业")
@PreAuthorize("@ss.hasPermi('cms:blockCompany:check')")
@GetMapping("/check")
public AjaxResult check(@RequestParam Long companyId) {
Long userId=RoleUtils.getSysAppuserId();
if(userId==null){
return error("未绑定移动端用户");
}
boolean blocked = blockCompanyService.isBlocked(userId, companyId);
return AjaxResult.success(blocked);
}
}

View File

@@ -0,0 +1,25 @@
package com.ruoyi.cms.domain;
import com.baomidou.mybatisplus.annotation.*;
import com.ruoyi.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import lombok.Data;
@Data
@ApiModel("用户屏蔽企业表")
@TableName("app_user_block_company")
public class AppUserBlockCompany extends BaseEntity {
@TableField(exist = false)
private static final long serialVersionUID = 1L;
/** 主键ID */
@TableId(type = IdType.AUTO)
private Long id;
/** APP用户ID */
private Long userId;
/** 被屏蔽企业ID */
private Long companyId;
}

View File

@@ -0,0 +1,32 @@
package com.ruoyi.cms.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.cms.domain.AppUserBlockCompany;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface AppUserBlockCompanyMapper extends BaseMapper<AppUserBlockCompany> {
/**
* 查询用户屏蔽的企业ID列表
*/
List<Long> selectBlockCompanyIdsByUserId(@Param("userId") Long userId);
/**
* 判断用户是否已屏蔽该企业
*/
int checkUserBlockCompany(@Param("userId") Long userId, @Param("companyId") Long companyId);
/**
* 根据用户ID查询全部屏蔽记录
*/
List<AppUserBlockCompany> selectListByUserId(@Param("userId") Long userId);
/**
* 根据用户id查询屏蔽的企业及企业的岗位
* @param userId
* @return
*/
List<Long> selectBlockCompanyIdsByUserIdJobs(@Param("userId") Long userId);
}

View File

@@ -0,0 +1,38 @@
package com.ruoyi.cms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.cms.domain.AppUserBlockCompany;
import java.util.List;
public interface AppUserBlockCompanyService extends IService<AppUserBlockCompany> {
/**
* 新增屏蔽企业(去重校验)
*/
int addBlockCompany(AppUserBlockCompany entity);
/**
* 取消屏蔽(逻辑删除)
*/
int cancelBlock(Long[] ids);
/**
* 获取用户所有屏蔽企业ID
*/
List<Long> getBlockCompanyIds(Long userId);
/**
* 校验是否已屏蔽
*/
boolean isBlocked(Long userId, Long companyId);
/**
* 查询用户屏蔽列表
*/
List<AppUserBlockCompany> listByUserId(Long userId);
int batchCancelBlock(Long userId,List<Long> companyIdList);
List<AppUserBlockCompany> selectListByUserId(Long userId);
}

View File

@@ -0,0 +1,70 @@
package com.ruoyi.cms.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.cms.domain.AppUserBlockCompany;
import com.ruoyi.cms.mapper.AppUserBlockCompanyMapper;
import com.ruoyi.cms.service.AppUserBlockCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
@Service
public class AppUserBlockCompanyServiceImpl extends ServiceImpl<AppUserBlockCompanyMapper, AppUserBlockCompany>
implements AppUserBlockCompanyService {
@Autowired
private AppUserBlockCompanyMapper appUserBlockCompanyMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public int addBlockCompany(AppUserBlockCompany entity) {
if (isBlocked(entity.getUserId(), entity.getCompanyId())) {
throw new RuntimeException("已屏蔽该企业,无需重复操作");
}
return baseMapper.insert(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int cancelBlock(Long[] ids) {
return appUserBlockCompanyMapper.deleteBatchIds(Arrays.asList(ids));
}
@Override
public List<Long> getBlockCompanyIds(Long userId) {
return baseMapper.selectBlockCompanyIdsByUserId(userId);
}
@Override
public boolean isBlocked(Long userId, Long companyId) {
return baseMapper.checkUserBlockCompany(userId, companyId) > 0;
}
@Override
public List<AppUserBlockCompany> listByUserId(Long userId) {
LambdaQueryWrapper<AppUserBlockCompany> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AppUserBlockCompany::getUserId, userId)
.orderByDesc(AppUserBlockCompany::getCreateTime);
return baseMapper.selectList(wrapper);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int batchCancelBlock(Long userId, List<Long> companyIdList) {
LambdaQueryWrapper<AppUserBlockCompany> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AppUserBlockCompany::getUserId, userId)
.eq(AppUserBlockCompany::getDelFlag, "0")
.in(AppUserBlockCompany::getCompanyId, companyIdList);
AppUserBlockCompany updateEntity = new AppUserBlockCompany();
updateEntity.setDelFlag("2");
return baseMapper.update(updateEntity, wrapper);
}
public List<AppUserBlockCompany> selectListByUserId(Long userId){
return appUserBlockCompanyMapper.selectListByUserId(userId);
}
}

View File

@@ -2,6 +2,7 @@ package com.ruoyi.cms.service.impl;
import com.alibaba.fastjson.JSON;
import com.ruoyi.cms.domain.vo.CompanyVo;
import com.ruoyi.cms.mapper.AppUserBlockCompanyMapper;
import com.ruoyi.cms.service.ICompanyService;
import com.ruoyi.common.core.domain.entity.AppUser;
import com.ruoyi.cms.domain.ESJobDocument;
@@ -58,6 +59,8 @@ public class ESJobSearchImpl implements IESJobSearchService
private ICompanyService iCompanyService;
@Autowired
private RedisCache redisCache;
@Autowired
private AppUserBlockCompanyMapper appUserBlockCompanyMapper;
// 锁的key唯一标识ES索引初始化
private static final String ES_INIT_LOCK_KEY = "es:job_document:init:lock";
@@ -241,6 +244,10 @@ public class ESJobSearchImpl implements IESJobSearchService
//查询
if(SiteSecurityUtils.isLogin()){
AppUser appUser = appUserService.selectAppUserByUserId(SiteSecurityUtils.getUserId());
List<Long> jobs=appUserBlockCompanyMapper.selectBlockCompanyIdsByUserIdJobs(appUser.getUserId());
if (jobs != null) {
jobIds.addAll(jobs.stream().distinct().collect(Collectors.toList()));
}
if (!StringUtil.isEmptyOrNull(esJobSearch.getCode())) {
newSearch.setCode(esJobSearch.getCode());
}
@@ -423,7 +430,13 @@ public class ESJobSearchImpl implements IESJobSearchService
public EsPageInfo<ESJobDocument> nearJob(ESJobSearch jobQuery) {
Integer pageNum = jobQuery.getCurrent();
Integer pageSize = jobQuery.getPageSize();
LambdaEsQueryWrapper<ESJobDocument> wrapper = getWrapper(jobQuery,null);
//添加屏蔽的企业
List<Long> jobIds=null;
if(SiteSecurityUtils.isLogin()) {
AppUser appUser = appUserService.selectAppUserByUserId(SiteSecurityUtils.getUserId());
jobIds = appUserBlockCompanyMapper.selectBlockCompanyIdsByUserIdJobs(appUser.getUserId());
}
LambdaEsQueryWrapper<ESJobDocument> wrapper = getWrapper(jobQuery,jobIds);
EsPageInfo<ESJobDocument> esJobDocumentEsPageInfo = esJobDocumentMapper.pageQuery(wrapper, pageNum, pageSize);
return esJobDocumentEsPageInfo;
}
@@ -433,6 +446,13 @@ public class ESJobSearchImpl implements IESJobSearchService
Integer pageNum = jobQuery.getCurrent();
Integer pageSize = jobQuery.getPageSize();
LambdaEsQueryWrapper<ESJobDocument> wrapper = getWrapper(jobQuery, null);
//添加屏蔽的企业
List<Long> jobIds=null;
if(SiteSecurityUtils.isLogin()) {
AppUser appUser = appUserService.selectAppUserByUserId(SiteSecurityUtils.getUserId());
jobIds = appUserBlockCompanyMapper.selectBlockCompanyIdsByUserIdJobs(appUser.getUserId());
wrapper.not().in(ESJobDocument::getJobId, jobIds);
}
if(jobQuery.getCountyIds()!=null){
wrapper.and(x->x.in(ESJobDocument::getJobLocationAreaCode,jobQuery.getCountyIds()));
}
@@ -444,7 +464,12 @@ public class ESJobSearchImpl implements IESJobSearchService
public EsPageInfo<ESJobDocument> subway(ESJobSearch jobQuery) {
Integer pageNum = jobQuery.getCurrent();
Integer pageSize = jobQuery.getPageSize();
LambdaEsQueryWrapper<ESJobDocument> wrapper = getWrapper(jobQuery,null);
List<Long> jobIds=null;
if(SiteSecurityUtils.isLogin()) {
AppUser appUser = appUserService.selectAppUserByUserId(SiteSecurityUtils.getUserId());
jobIds = appUserBlockCompanyMapper.selectBlockCompanyIdsByUserIdJobs(appUser.getUserId());
}
LambdaEsQueryWrapper<ESJobDocument> wrapper = getWrapper(jobQuery,jobIds);
EsPageInfo<ESJobDocument> esJobDocumentEsPageInfo = esJobDocumentMapper.pageQuery(wrapper, pageNum, pageSize);
return esJobDocumentEsPageInfo;
}
@@ -453,7 +478,12 @@ public class ESJobSearchImpl implements IESJobSearchService
public EsPageInfo<ESJobDocument> commercialArea(ESJobSearch jobQuery) {
Integer pageNum = jobQuery.getCurrent();
Integer pageSize = jobQuery.getPageSize();
LambdaEsQueryWrapper<ESJobDocument> wrapper = getWrapper(jobQuery,null);
List<Long> jobIds=null;
if(SiteSecurityUtils.isLogin()) {
AppUser appUser = appUserService.selectAppUserByUserId(SiteSecurityUtils.getUserId());
jobIds = appUserBlockCompanyMapper.selectBlockCompanyIdsByUserIdJobs(appUser.getUserId());
}
LambdaEsQueryWrapper<ESJobDocument> wrapper = getWrapper(jobQuery,jobIds);
if(jobQuery.getLongitude()!=null){
wrapper.geoDistance(ESJobDocument::getLatAndLon,Double.valueOf(jobQuery.getRadius()), DistanceUnit.KILOMETERS,new GeoPoint(Double.parseDouble(jobQuery.getLatitude().toString()), Double.parseDouble(jobQuery.getLongitude().toString())));
}
@@ -652,13 +682,17 @@ public class ESJobSearchImpl implements IESJobSearchService
Integer pageNum = jobQuery.getCurrent();
Integer pageSize = jobQuery.getPageSize();
LambdaEsQueryWrapper<ESJobDocument> wrapper = new LambdaEsQueryWrapper<>();
// if(SiteSecurityUtils.isLogin()){
// AppUser appUser = appUserService.selectAppUserByUserId(SiteSecurityUtils.getUserId());
if(SiteSecurityUtils.isLogin()){
AppUser appUser = appUserService.selectAppUserByUserId(SiteSecurityUtils.getUserId());
List<Long> jobs=appUserBlockCompanyMapper.selectBlockCompanyIdsByUserIdJobs(appUser.getUserId());
if (ListUtil.isListEmptyOrNull(jobs)) {
wrapper.not().in(ESJobDocument::getJobId, jobs);
}
// if(!ListUtil.isEmptyOrNull(appUser.getJobTitle())){
// List<String> jobTitle = appUser.getJobTitle();
// jobQuery.setJobTitle(String.join(",", jobTitle));
// }
// }
}
if(hasText(jobQuery.getJobTitle())){
wrapper.and(a->a.match(ESJobDocument::getJobTitle,jobQuery.getJobTitle().trim(),5.0f)
.or()

View File

@@ -111,4 +111,17 @@ public class RoleUtils {
}
return null;
}
/**
* 获取app_user_id
* @return
*/
public static Long getSysAppuserId(){
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser sysUser = loginUser.getUser();
if (sysUser == null) {
throw new IllegalArgumentException("用户信息为空,无法获取个人信息");
}
return sysUser.getAppUserId();
}
}

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.cms.mapper.AppUserBlockCompanyMapper">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="AppUserBlockCompany" id="AppUserBlockCompanyResult">
<result property="id" column="id"/>
<result property="userId" column="user_id"/>
<result property="companyId" column="company_id"/>
<result property="delFlag" column="del_flag"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
</resultMap>
<sql id="selectAppUserBlockCompanyVo">
select id, user_id, company_id, del_flag, create_by, create_time, update_by, update_time, remark from app_user_block_company
</sql>
<select id="selectBlockCompanyIdsByUserId" resultType="java.lang.Long">
SELECT company_id
FROM app_user_block_company
WHERE user_id = #{userId} AND del_flag = '0'
</select>
<select id="checkUserBlockCompany" resultType="int">
SELECT COUNT(1)
FROM app_user_block_company
WHERE user_id = #{userId}
AND company_id = #{companyId}
AND del_flag = '0'
</select>
<select id="selectListByUserId" resultMap="AppUserBlockCompanyResult">
<include refid="selectAppUserBlockCompanyVo"/>
FROM app_user_block_company
WHERE user_id = #{userId} AND del_flag = '0'
ORDER BY create_time DESC
</select>
<select id="selectBlockCompanyIdsByUserIdJobs" resultType="java.lang.Long">
SELECT distinct j.job_id
FROM app_user_block_company a
inner join company b on a.company_id=b.company_id and b.del_flag='0'
inner join job j on b.company_id =j.company_id and j.del_flag='0'
WHERE user_id = #{userId} AND a.del_flag = '0'
</select>
</mapper>