轮循取值算法数据库

场景

公司有十个人,有可能离职还有新来员工,工作任务需要在职员工轮循去工作,有的工作需要几个人去完成

java 复制代码
   
/**
     * 获取审批人员
     * @param userIdList 全部的员工
     * @param userRoleType 角色类型 (业务需要) 
     * @param userType 人员类型    (业务需要) 
     * @param shType  审核类型(业务需要) 
     * @param num  需要返回几个人去工作
     * @return
     */

 public List<String> getUserIdList(List<String> userIdList, String userRoleType, String userType, String shType,int num) {
        //全部已经干活人员
        List<YwRoundUser> list = this.baseMapper.selectList(new LambdaQueryWrapper<YwRoundUser>()
                .eq(YwRoundUser::getUserRoleType, userRoleType)
                .eq(YwRoundUser::getUserType, userType)
                .eq(YwRoundUser::getShType, shType)
                .eq(YwRoundUser::getDelFlag, YesNo.NO.getValue())
        );
        List<String> idList = list.stream().map(YwRoundUser::getUserId).collect(Collectors.toList());
        //求差集 需要插入的(新入职的)
        Set<String> difference = userIdList.stream().filter(e -> !idList.contains(e)).collect(Collectors.toSet());
        //求差集 需要删除的(离职的)
        Set<String> difference2 = idList.stream().filter(e -> !userIdList.contains(e)).collect(Collectors.toSet());
        //删除
        if(difference2.size()!=0){
            YwRoundUser user = new YwRoundUser();
            user.setDelFlag("1");
            this.baseMapper.update(user,new LambdaQueryWrapper<YwRoundUser>().in(YwRoundUser::getUserId,difference2));
        }
        //需要增加的
        for (String userId : difference){
                YwRoundUser ywRoundUser = new YwRoundUser();
                ywRoundUser.setTimeStamp(BigDecimal.valueOf(System.currentTimeMillis()));
                ywRoundUser.setUserId(userId);
                ywRoundUser.setUserType(userType);
                ywRoundUser.setUserRoleType(userRoleType);
                ywRoundUser.setDelFlag(YesNo.NO.getValue());
                ywRoundUser.setShType(shType);
                this.baseMapper.insert(ywRoundUser);
        }
      //按照时间戳查询需要的个数
        List<YwRoundUser> resultList = this.baseMapper.selectList(new LambdaQueryWrapper<YwRoundUser>()
                .eq(YwRoundUser::getUserRoleType, userRoleType)
                .eq(YwRoundUser::getUserType, userType)
                .eq(YwRoundUser::getShType, shType)
                .eq(YwRoundUser::getDelFlag, YesNo.NO.getValue())
                .orderByAsc(YwRoundUser::getTimeStamp)
                .last(" limit "+ num)
        );
        //获取Id
        List<String> resultIdList = resultList.stream().map(YwRoundUser::getUserId).collect(Collectors.toList());
        //更新选中人的时间戳
        for (YwRoundUser user : resultList){
            user.setTimeStamp(BigDecimal.valueOf(System.currentTimeMillis()));
            this.baseMapper.updateById(user);
        }
        return resultIdList;
    }
相关推荐
什么半岛铁盒4 分钟前
MySQL数据库的基础操作
linux·运维·服务器·mysql
乌萨奇也要立志学C++16 分钟前
【Linux】基本指令详解(一) 树状文件结构、家目录、绝对/相对路径、linux文件类型
linux
marconiho17 分钟前
FRP Ubuntu 服务端 + MacOS 客户端配置
linux·ubuntu·macos
DARLING Zero two♡22 分钟前
【Linux操作系统】简学深悟启示录:Linux权限
linux·运维·服务器
CHANG_THE_WORLD35 分钟前
libimagequant windows 编译
windows·libimagequant
is081538 分钟前
vim扩展
linux·编辑器·vim
特种加菲猫2 小时前
构建完整工具链:GCC/G++ + Makefile + Git 自动化开发流程
linux·笔记·git·自动化
李少兄5 小时前
CentOS系统下前后端项目部署攻略
linux·运维·centos
Two_brushes.7 小时前
【Linux】线程机制深度实践:创建、等待、互斥与同步
linux·运维·服务器·多线程
江沉晚呤时9 小时前
在 C# 中调用 Python 脚本:实现跨语言功能集成
python·microsoft·c#·.net·.netcore·.net core