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

轮循取值算法数据库

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

   
/**
     * 获取审批人员
     * @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.dtcms.com/a/95580.html

相关文章:

  • 记录vite引入sass预编译报错问题
  • 支持 MCP 协议的开源 AI Agent 项目
  • HTML跑酷
  • android 何如查找内网设备 IP
  • JavaScript 读取电脑复制的内容
  • android音效算法集成框架(3)
  • Spring容器生命周期详解
  • XHR.readyState详解
  • markdown 文件转 word
  • nginx反向代理示例
  • 爬虫面试题
  • HarmonyOS NEXT 关于鸿蒙的一多开发(一次开发,多端部署) 1+8+N
  • 前端技术(28) : 拖拽、粘贴和点击浏览文件上传
  • iOS rootless无根越狱检测方案
  • Python中的JSON转换:全面指南与最佳实践
  • ESLint报错:Could not find config file.
  • Git合并删除原理
  • Centos与Ubuntu系统的对比分析
  • C++进制转换的方法
  • LinuxI/O多路转接(select、poll、epoll)
  • 23种设计模式-模板方法(Template Method)设计模式
  • 基于无线的分布式温度采集报警系统设计(论文+源码)
  • SpringCould微服务架构之Docker(3)
  • QML学习 —— 17、“DelayButton 延迟按钮“之“一键三连“示例(附完整源码)
  • vue2项目eslint提示<template v-for> key should be placed on the <template> tag
  • vue 3 深度指南:从基础到全栈开发实践
  • Git 基础入门:从概念到实践的版本控制指南
  • 【PostgreSQL内核学习 —— (sort算子)】
  • 练习:求质数
  • Nacos Config Service 和 Naming Service 各自的核心功能是什么?