提交 19916d19 authored 作者: wangmenglong's avatar wangmenglong

增加岗位交接

上级 9355e869
package data.recruit;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import data.parent.IdentityObj;
import lombok.Data;
/**
* @author wangmenglong
* @description: 岗位交接记录
* user_id / user_name 记录操作人(执行交接的人)
* old_user_id / old_user_name 记录原账号(被交接走的发布人)
* new_user_id / new_user_name 记录新账号(接手岗位的发布人)
* @date 2026/08/24
*/
@Data
@TableName(value = "tb_handover_log")
public class HandoverLog extends IdentityObj {
/**
* 原用户id(被交接走的发布人)
**/
@TableField("old_user_id")
private String oldUserId;
/**
* 原用户名称
**/
@TableField("old_user_name")
private String oldUserName;
/**
* 新用户id(接手岗位的发布人)
**/
@TableField("new_user_id")
private String newUserId;
/**
* 新用户名称(随机交接时为多个接收人名称,逗号隔开)
**/
@TableField("new_user_name")
private String newUserName;
/**
* 交接类型:user 指定交接给一人,random 随机分配给多人
**/
@TableField("type")
private String type;
}
......@@ -7,7 +7,7 @@ import lombok.Data;
/**
* @author wangmenglong
* @description: 报名记录
* @description: 岗位发布
* @date 2023/12/11 10:50
*/
@Data
......
package com.jfb.recruit.controller;
import base.controller.BaseController;
import base.result.BaseResult;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.jfb.recruit.bean.auth.UserContext;
import com.jfb.recruit.service.HandoverService;
import com.jfb.recruit.util.auth.UserUtils;
import data.recruit.HandoverLog;
import data.user.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
* @author wangmenglong
* @description: 岗位交接(发布人岗位转移 / 交接记录查询)
* @date 2026/08/24
*/
@RestController
@RequestMapping("/handover")
public class HandoverController extends BaseController {
@Resource
HandoverService handoverService;
@Autowired
ThreadPoolTaskExecutor taskExecutor;
/**
* @description: 获取状态正常的用户列表(用于选择交接目标)
* @author: wangmenglong
* @date; 2026/08/24
* @param: [req, user] user 可带 name/account 模糊查询
* @return: base.result.BaseResult
**/
@GetMapping("/user/normalList")
public BaseResult normalUserList(HttpServletRequest req, User user) {
PageInit(req);
if (user == null) {
user = new User();
}
PageInfo<User> pageInfo = handoverService.normalUserList(pageNum, pageSize, user);
return BaseResult.success(pageInfo);
}
/**
* @description: 将原发布人的全部岗位交接给指定新发布人
* @author: wangmenglong
* @date; 2026/08/24
* @param: [jsonObject] 需包含 originalUserId/originalUserName/newUserId/newUserName
* @return: base.result.BaseResult
**/
@PostMapping("/all")
public BaseResult handoverAll(@RequestBody JSONObject jsonObject) {
String originalUserId = jsonObject.getString("originalUserId");
String originalUserName = jsonObject.getString("originalUserName");
String newUserId = jsonObject.getString("newUserId");
String newUserName = jsonObject.getString("newUserName");
if (StringUtils.isBlank(originalUserId) || StringUtils.isBlank(newUserId)) {
return BaseResult.error("error_002");
}
boolean result = handoverService.handoverAll(originalUserId, originalUserName, newUserId, newUserName);
// 原账号没有岗位时返回 error_009
return result ? BaseResult.success("normal_002") : BaseResult.error("error_009");
}
/**
* @description: 将原发布人的岗位均分给库里所有正常用户(排除原账号本人),后台异步执行,接口立即返回
* @author: wangmenglong
* @date; 2026/08/24
* @param: [jsonObject] 需包含 originalUserId/originalUserName,接收人由系统从库里正常用户中均分选取
* @return: base.result.BaseResult 仅表示任务已提交,实际分配进度请看交接记录
**/
@PostMapping("/random")
public BaseResult handoverRandom(@RequestBody JSONObject jsonObject) {
String originalUserId = jsonObject.getString("originalUserId");
String originalUserName = jsonObject.getString("originalUserName");
if (StringUtils.isBlank(originalUserId)) {
return BaseResult.error("error_002");
}
// 在同步线程取出登录上下文,传给异步任务(异步线程池拿不到 ThreadLocal 里的 UserContext,会 NPE)
UserContext operator = UserUtils.getUserContext();
if (operator == null) {
return BaseResult.error("error_002");
}
// 同步预校验:原账号没有岗位、或库里没有其它正常用户,直接返回 error_009,不提交后台任务
if (!handoverService.canRandomHandover(originalUserId, operator)) {
return BaseResult.error("error_009");
}
final String oName = originalUserName;
// 提交异步任务到线程池(后台慢慢分,前端不阻塞)
taskExecutor.execute(() -> handoverService.handoverRandom(originalUserId, oName, operator));
return BaseResult.success("normal_003");
}
/**
* @description: 查询岗位交接记录列表,支持按操作人/原账号/新账号名称模糊查询
* @author: wangmenglong
* @date; 2026/08/24
* @param: [req, handoverLog] 可带 userName(操作人)/oldUserName(原账号)/newUserName(新账号)/type(交接类型:user 指定交接/random 随机分配)
* @return: base.result.BaseResult
**/
@GetMapping("/log/list")
public BaseResult logList(HttpServletRequest req, HandoverLog handoverLog) {
PageInit(req);
if (handoverLog == null) {
handoverLog = new HandoverLog();
}
PageInfo<HandoverLog> pageInfo = handoverService.logList(pageNum, pageSize, handoverLog);
return BaseResult.success(pageInfo);
}
}
package com.jfb.recruit.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import data.recruit.HandoverLog;
import org.apache.ibatis.annotations.Mapper;
/**
* @author wangmenglong
* @description: 岗位交接记录 Mapper
* @date 2026/08/24
*/
@Mapper
public interface HandoverLogMapper extends BaseMapper<HandoverLog> {
}
package com.jfb.recruit.service;
import com.github.pagehelper.PageInfo;
import com.jfb.recruit.bean.auth.UserContext;
import data.recruit.HandoverLog;
import data.user.User;
/**
* @author wangmenglong
* @description: 岗位交接服务
* @date 2026/08/24
*/
public interface HandoverService {
/**
* @description: 获取状态正常的用户列表(不含被交接目标时排除原账号,由调用方控制)
* @param: [pageNum, pageSize, user] user 可带 name/account 模糊查询条件,state 固定为 normal
* @return: com.github.pagehelper.PageInfo<data.user.User>
**/
PageInfo<User> normalUserList(int pageNum, int pageSize, User user);
/**
* @description: 将某发布人的全部岗位交接给指定新发布人
* 把所有 user_id = originalUserId 的岗位(del=false)的 user_id/user_name 改为新用户,
* 整笔交接只写 1 条记录(type=user 指定交接,新账号=指定人)
* @param: [originalUserId, originalUserName, newUserId, newUserName]
* @return: boolean 是否交接成功(存在可交接岗位且更新成功)
**/
boolean handoverAll(String originalUserId, String originalUserName, String newUserId, String newUserName);
/**
* @description: 将某发布人的岗位均分给库里所有正常用户(排除原账号本人),按轮询均分使每人数量尽量相等(相差不超过 1)。
* 整笔随机交接只写 1 条记录(type=random,新账号=实际分到的多个接收人逗号隔开)。
* 注意:该方法是纯数据操作,由 Controller 层用线程池异步调用,方法本身不负责异步。
* @param: [originalUserId, originalUserName] 原账号(被交接走的发布人);接收人由方法内部从库里正常用户中排除本人后均分选取
* @return: boolean 是否交接成功(存在可交接岗位且库里除本人外有正常用户)
**/
boolean handoverRandom(String originalUserId, String originalUserName, UserContext operator);
/**
* @description: 随机交接前的同步校验:原账号是否存在未删除岗位,且库里除本人外是否存在其它正常用户。
* 任一不满足则返回 false(用于异步提交前在同步线程拦截,避免无意义地提交后台任务)。
* @param: [originalUserId, operator] operator 为操作人上下文,含 baseCode,用于限定数据范围
* @return: boolean 是否可以发起随机交接
**/
boolean canRandomHandover(String originalUserId, UserContext operator);
/**
* @description: 查询岗位交接记录列表,支持按操作人/原账号/新账号名称模糊查询
* @param: [pageNum, pageSize, handoverLog] 可带 userName(操作人)/oldUserName(原账号)/newUserName(新账号) 查询条件
* @return: com.github.pagehelper.PageInfo<data.recruit.HandoverLog>
**/
PageInfo<HandoverLog> logList(int pageNum, int pageSize, HandoverLog handoverLog);
}
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论