当前位置: 首页 > article >正文

轮循取值算法数据库

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

   
/**
     * 获取审批人员
     * @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;
    }


http://www.kler.cn/a/613737.html

相关文章:

  • TwinCAT3-Udp点对点自由协议通信
  • 自动驾驶---打造自动驾驶系统之参考线平滑(四)
  • gitee 常用指令
  • springboot的跨域是什么?遇到跨域问题如何解决?
  • 华宇TAS应用中间件与晓窗科技智慧校园管理一体化平台完成兼容互认证
  • linux ACL权限控制之用户权限控制程序设计
  • 使用Python和OpenCV进行指纹识别与验证
  • Resume全栈项目(二)(.React+Ts)
  • 【漫话机器学习系列】166.向量(Vectors)
  • ubuntu 创建新用户
  • Flink Credit-based机制解析
  • 数字化攻防战场的进化论:红蓝对抗训练如何重塑网络安全范式
  • PTA 7-16 一元多项式求导
  • Axure项目实战:智慧城市APP(六)市民互动(动态面板、显示与隐藏)
  • 【Linux-驱动开发-模块的加载和卸载】
  • 【深度学习】训练集、测试集、验证集、过拟合、欠拟合详解
  • WebRTC简介及应用
  • 【Git】--- Git远程操作 标签管理
  • Anaconda Jupyter 默认启动位置修改
  • javaWeb Router