轮循取值算法数据库

场景

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

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;
    }
相关推荐
Robot25128 分钟前
「华为」人形机器人赛道投资首秀!
大数据·人工智能·科技·microsoft·华为·机器人
孙克旭_4 小时前
PXE_Kickstart_无人值守自动化安装系统
linux·运维·自动化
皓月盈江5 小时前
Linux电脑本机使用小皮面板集成环境开发调试WEB项目
linux·php·web开发·phpstudy·小皮面板·集成环境·www.xp.cn
深井冰水5 小时前
mac M2能安装的虚拟机和linux系统系统
linux·macos
leoufung5 小时前
内核内存锁定机制与用户空间内存锁定的交互分析
linux·kernel
IT专业服务商7 小时前
联想 SR550 服务器,配置 RAID 5教程!
运维·服务器·windows·microsoft·硬件架构
海尔辛7 小时前
学习黑客5 分钟小白弄懂Windows Desktop GUI
windows·学习
星空寻流年7 小时前
CSS3(BFC)
前端·microsoft·css3
gushansanren7 小时前
基于WSL用MSVC编译ffmpeg7.1
windows·ffmpeg
忧虑的乌龟蛋7 小时前
嵌入式Linux I2C驱动开发详解
linux·驱动开发·嵌入式·iic·i2c·读数据·写数据