轮循取值算法数据库

场景

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

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;
    }
相关推荐
集成显卡2 小时前
PlayWright | 初识微软出品的 WEB 应用自动化测试框架
前端·chrome·测试工具·microsoft·自动化·edge浏览器
Gaoithe3 小时前
ubuntu 端口复用
linux·运维·ubuntu
德先生&赛先生3 小时前
Linux编程:1、文件编程
linux
程序猿小D4 小时前
第16节 Node.js 文件系统
linux·服务器·前端·node.js·编辑器·vim
多多*5 小时前
微服务网关SpringCloudGateway+SaToken鉴权
linux·开发语言·redis·python·sql·log4j·bootstrap
南林yan6 小时前
DLL动态库实现文件遍历功能(Windows编程)
windows
Mike_6666 小时前
win10安装WSL2、Ubuntu24.04
windows·ubuntu·wsl2
IT界小黑的对象6 小时前
virtualBox部署ubuntu22.04虚拟机 NAT+host only 宿主机ping不通虚拟机
linux·运维·服务器
SilentCodeY6 小时前
Ubuntu 系统通过防火墙管控 Docker 容器
linux·安全·ubuntu·系统防火墙
weixin_527550407 小时前
Linux 环境下高效视频切帧的实用指南
linux·运维·音视频