package org.springblade.desk.utils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.entity.Dept;
import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.stereotype.Component; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; /***/
@Slf4j
@Component
@AllArgsConstructor
public class DeptUserUtil {
private ISysClient sysClient ;
private IUserClient userClient; /**
* 获取职位postId
* @param postName
* @param tenantId
* @return
*/
public String getPostId(String postName,String tenantId){
R<String> rPost = sysClient.getPostIds(Func.toStr(tenantId,"000000"),postName);
return rPost.getData();
} /**
* 根据角色roleName获取roleId
*/
public String getRoleId(String tenantId,String roleName){
R<String> rRole = sysClient.getRoleIds(tenantId,roleName);
return rRole.getData();
} /**
* 根据部门deptName获取deptId
*/
public String getDeptId(String tenantId,String deptName){
R<String> rDept = sysClient.getDeptIds(Func.toStr(tenantId,"000000"),deptName);
return rDept.getData();
} /**
* 根据UserId,获取用户信息User
*/
public User getUserById(Long userId){
R<User> rUser = userClient.userInfoById(userId);
return rUser.getData();
} /**
* 根据RoleId,获取用户列表
*/
public List<User> getUserListByRoleId(String roleId){
HashMap<String ,Object> map = new HashMap<String,Object>();
map.put("roleId",roleId);
R<List<User>> rUsers = userClient.getUserList(map);
return rUsers.getData();
} /**
* 根据postId,获取用户列表
*/
public List<User> getUserListByPostId(String postId){
HashMap<String ,Object> map = new HashMap<String,Object>();
map.put("postId",postId);
R<List<User>> rUsers = userClient.getUserList(map);
return rUsers.getData();
} /**
* 根据RoleId、deptId,获取用户列表
*/
public List<User> getUserListByRoleIdAndDeptId(String roleId,String deptId){
HashMap<String ,Object> map = new HashMap<String,Object>();
map.put("deptId",deptId);
map.put("roleId",roleId);
R<List<User>> rUsers = userClient.getUserList(map);
return rUsers.getData();
} /**
* 根据RoleId、deptId,获取用户列表
*/
public List<User> getUserListByPostIdAndDeptId(String postId,String deptId){
HashMap<String ,Object> map = new HashMap<String,Object>();
map.put("deptId",deptId);
map.put("postId",postId);
R<List<User>> rUsers = userClient.getUserList(map);
return rUsers.getData();
} /**
* 根据RoleId、deptId,获取用户列表,向上级部门查询
*/
public List<User> getUserListByRoleIdAndDeptId(String roleId,String deptId,boolean isParent){
List<User> list = getUserListByRoleIdAndDeptId(roleId,deptId);
if(isParent&&Func.isEmpty(list)) {
Dept dept = getDeptById(Long.parseLong(deptId));
if (Func.isEmpty(dept)) {
return null;
}
list = getUserListByRoleIdAndDeptId(roleId, String.valueOf(dept.getParentId()), true);
}
return list;
} /**
* 根据postId、deptId,获取用户列表,向上级部门查询
*/
public List<User> getUserListByPostIdAndDeptId(String postId,String deptId,boolean isParent){
List<User> list = getUserListByPostIdAndDeptId(postId,deptId);
if(isParent&&Func.isEmpty(list)) {
Dept dept = getDeptById(Long.parseLong(deptId));
if (Func.isEmpty(dept)) {
return null;
}
list = getUserListByPostIdAndDeptId(postId, String.valueOf(dept.getParentId()), true);
}
return list;
} /**
* 根据部门deptId,获取部门信息Dept(包含部门主管managerUser)
*/
public Dept getDeptById(Long deptId){
R<Dept> rDept = sysClient.getDept(deptId);
return rDept.getData();
} /**
* 根据部门deptId,获取所有子部门信息Dept
*/
public List<Dept> getChildDeptsById(Long deptId){
R<List<Dept>> rDept = sysClient.getDeptChild(deptId);
return rDept.getData();
} /**
* 根据部门deptIds,获取所有部门信息Dept
*/
public List<Dept> getChildDeptsById(String deptIds){
R<List<Dept>> rDept = sysClient.getDepts(deptIds);
return rDept.getData();
} /**
* 根据部门deptId,获取上级部门(包含上级主管managerUser),区分用户userId
*/
public Dept getManagerDept(Long deptId,Long distinctUserId){
if(Func.isEmpty(distinctUserId)){
return null;
}
Dept dept = getDeptById(deptId);
if(dept==null){
return null;
}
Long managerUserId = dept.getManagerUser();
if(Func.isEmpty(managerUserId)){
dept = getManagerDept(dept.getParentId(),distinctUserId);
}
if(!Func.isEmpty(dept)&&distinctUserId.equals(dept.getManagerUser())){
dept = getManagerDept(dept.getParentId(),distinctUserId);
}
return dept;
} /**
* 根据部门deptId,获取上级部门(包含上级主管managerUser),区分用户userId,设置上级部门上限
* 部门等级 level : 1 -> 10 最高级 -> 最低级
*/
public Dept getManagerDept(Long deptId,Long distinctUserId,Integer level){
if(Func.isEmpty(distinctUserId) || Func.isEmpty(level)){
return null;
}
Dept dept = getDeptById(deptId);
if(dept==null){
return null;
}
Long managerUserId = dept.getManagerUser();
if(Func.isEmpty(managerUserId)){
dept = getManagerDept(dept.getParentId(),distinctUserId,level);
}
Integer managerDeptLevel = dept.getLevel();
if(Func.isEmpty(managerDeptLevel) || managerDeptLevel.compareTo(level)<0){
return null;
}
if(!Func.isEmpty(dept)&&distinctUserId.equals(dept.getManagerUser())){
dept = getManagerDept(dept.getParentId(),distinctUserId,level);
}
return dept;
} /**
* 根据部门deptId及职位postId,获取上级部门(包含上级主管managerUser),区分用户userId
*/
public Dept getManagerDept(Long deptId,Long distinctUserId,Long postId){
if(Func.isEmpty(postId) || Func.isEmpty(distinctUserId)|| Func.isEmpty(deptId)){
return null;
}
Dept dept = getDeptById(deptId);
if(dept==null){
return null;
}
Long managerUserId = dept.getManagerUser();
if(Func.isEmpty(managerUserId)){
dept = getManagerDept(dept.getParentId(),distinctUserId,postId);
}
if(!Func.isEmpty(dept)&&!distinctUserId.equals(dept.getManagerUser())){
R<User> rUser = userClient.userInfoById(dept.getManagerUser());
User user = rUser.getData();
if(user==null || !postId.equals(user.getPostId())){
dept = getManagerDept(dept.getParentId(),distinctUserId,postId);
}
}
else if(!Func.isEmpty(dept)&&distinctUserId.equals(dept.getManagerUser())){
dept = getManagerDept(dept.getParentId(),distinctUserId,postId);
}
return dept;
} /**
* 判断是否是部门主管
*/
public boolean isManagerUser(Long deptId,Long userId){
if(Func.isEmpty(deptId) || Func.isEmpty(userId)){
return false;
}
Dept dept = getDeptById(deptId);
if(dept==null){
return false;
}
Long managerUserId = dept.getManagerUser();
if(userId.compareTo(managerUserId)==0){
return true;
}
return false;
} public String isStrManagerUser(Long deptId,Long userId){
if(Func.isEmpty(deptId) || Func.isEmpty(userId)){
return "N";
}
Dept dept = getDeptById(deptId);
if(dept==null){
return "N";
}
Long managerUserId = dept.getManagerUser();
if(userId.compareTo(managerUserId)==0){
return "Y";
}
return "N";
} /**
* 判断是否是某个部门
*/
public boolean isOneDept(String deptName,Long deptId){
if(Func.isEmpty(deptName) || Func.isEmpty(deptId)){
return false;
}
String deptIds = getDeptId(AuthUtil.getTenantId(),deptName);
if(deptIds==null){
return false;
}
if(deptId.equals(deptIds)){
return true;
}
return false;
} public String isStrOneDept(String deptName,Long deptId){
if(Func.isEmpty(deptName) || Func.isEmpty(deptId)){
return "N";
}
String deptIds = getDeptId(AuthUtil.getTenantId(),deptName);
if(Func.isEmpty(deptIds)){
return "N";
}
if(deptIds.equals(deptId)){
return "Y";
}
return "N";
} /**
* 判断是否最高主管
*/
public boolean isHighManagerUser(){
return false;
} /**
* 判断是分公司,还是总部
*/
public String SubStrCompany(Long deptId){
String result ="速品";
if(Func.isEmpty(deptId)){
return result;
}
Dept dept = getDeptById(deptId);
if(dept==null){
return result;
}
R<List<String>> rDeptNames = sysClient.getDeptNames(dept.getAncestors());
if(Func.isNotEmpty(rDeptNames) && Func.isNotEmpty(rDeptNames.getData())){
for(String deptName : rDeptNames.getData()){
if(deptName.contains("福州")){
result = "福州";
return result;
}
if(deptName.contains("厦门")){
result = "厦门";
return result;
}
if(deptName.contains("泉州")){
result = "泉州";
return result;
}
}
}
return result;
} /**
* 判断是否分公司
*/
public boolean isSubCompany(Long deptId){
if(Func.isEmpty(deptId)){
return false;
}
Dept dept = getDeptById(deptId);
if(dept==null){
return false;
}
if(dept.getDeptCategory().equals(1)){
return true;
}
if(!Func.isEmpty(dept.getParentId())){
return isSubCompany(dept.getParentId());
}
return false;
} /**
* 根据租户id获取部门列表
* @param tenantId
* @return
*/
public List<Dept>getDeptList(String tenantId){
List<Dept>list=sysClient.getDeptList(tenantId).getData();
return list;
} /**
* 获取用户列表
* @param tenantId
* @return
*/
public List<User> getUserList(String tenantId){
HashMap<String,Object>map=new HashMap<String,Object>();
map.put("tenant_id",tenantId);
return userClient.getUserList(map).getData();
} /**
* 根据部门id,租户id 获取本部门人员list;
* @param deptId
* @return
*/
public List<User>getDeptUser(String deptId,String tenantId){
HashMap<String,Object>map=new HashMap<String,Object>();
map.put("tenant_id",tenantId);
List<User>users=userClient.getUserList(map).getData();
List<User>list=new ArrayList<User>();
//根据部门id筛选,本部门下人员
for(User user:users){
if(deptId.equals(user.getDeptId())){
list.add(user);
}
}
return list;
}
}

flowable中使用到的一些方法。获取人员部门信息的更多相关文章

  1. 【转载】C#中List集合使用GetRange方法获取指定索引范围内的所有值

    在C#的List集合中有时候需要获取指定索引位置范围的元素对象来组成一个新的List集合,此时就可使用到List集合的扩展方法GetRange方法,GetRange方法专门用于获取List集合指定范围 ...

  2. 【转载】C#中List集合使用Last方法获取最后一个元素

    在C#的List集合操作过程中,如果要获取List集合中的最后一个元素对象,则一般会先通过获取到list集合的个数Count属性,然后再使用索引的方式获取到该集合的最后一个位置的元素信息.其实在Lis ...

  3. 【转载】 C#中List集合使用First()方法获取第一个元素

    在C#的List集合操作过程中,如果要获取List集合中的第一个元素对象,则一般会先通过获取到list[0]这种方式来获取第一个元素.其实在List集合中提供了获取最后一个元素的First()方法,调 ...

  4. PHP中的__get()和__set()方法获取设置私有属性

    在类的封装中,获取属性可以自定义getXXX()和setXXX()方法,当一个类中有多个属性时,使用这种方式就会很麻烦.为此PHP5中预定义了__get()和__set()方法,其中__get()方法 ...

  5. 在SharePoint中无代码开发InfoPath应用: 获取当前用户信息

    很多种不同的场景下,会需要得到当前的用户信息,例如需要根据当前用户判断组,进而控制权限. 首先InfoPath提供了一个userName方法,来实现这个目的,不过这个方法的问题是只能获得不包含域名的用 ...

  6. Ecshop在模板中判断用户是否登陆,获取用户等级信息

    ecshop模板中smarty怎样判断用户等级.用户id.用户昵称用户名,请看以下方法,使用全局变量 <!-- {if $smarty.session.user_rank gt 1}--> ...

  7. Asp.net Request方法获取客户端的信息

    Response.Write("客户端计算机名:" + Request.UserHostName + "<BR />"); Response.Wri ...

  8. C# 获取word批注信息

    今天在Silverlight 应用程序中实现了 获取word文档批注信息 的功能. 在wcf服务继承接口类中编写的函数如下 /// <summary> /// 获取word批注信息 /// ...

  9. EasyUI treegrid 获取编辑状态中某字段的值 [getEditor方法获取不到editor]

    如题,在treegrid里,按照api里getEditor方法的说明, getEditoroptionsGet the specified editor, the options contains t ...

随机推荐

  1. 决胜IT十八招-前言

    决胜IT十八招 走资讯这一行转眼间八年多了,从大学的时候,我有长达十年的时间思索在从事软体开發这一行到底怎麽存活下来,这思考下来,为自己总算找到一个出口来,这十八招只是其一的绝学,见阵这一行干软体开發 ...

  2. day99:MoFang:Flask-JSONRPC提供RPC接口&在APP进行窗口页面操作(窗口-帧-帧组)

    目录 1.服务端基于Flask-JSONRPC提供RPC接口 1.Flask-JSONRPC简介 2.安装Flask-JSONRPC模块 3.快速实现一个测试的RPC接口 4.移动端访问测试接口 2. ...

  3. Hybrid接口应用

    简介:VLAN10内通信,VLAN20内通信,VLAN30与VLAN10.VLAN20.VLAN30皆可通信 Hybrid接口应用拓扑图: 一.配置PC机 ip 并测试相互能否ping通 PC名称 I ...

  4. 半监督伪标签方法:Feature Space Regularization和Joint-Distance

    原文链接 小样本学习与智能前沿 . 在这个公众号后台回复"200706",即可获得课件电子资源. @ 目录 Abstract I. INTRODUCTION Framework. ...

  5. 网络拓扑实例10:MSTP+VRRP组合组网

    组网图形 MSTP+VRRP组合简介 网络中部署VRRP负载分担时,多台设备同时承担业务,每个虚拟设备都包括一个Master设备和若干个Backup设备.如果为了接入备份需要同时部署冗余链路,则需要部 ...

  6. Python学习随笔:使用xlwings读取和操作Execl文件的数字需要注意的问题

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 在使用xlwings读取Excel文件中的数据时,所有的数字不论是整数.浮点数还是文本存放的数字,在 ...

  7. 第15.19节 PyQt(Python+Qt)入门学习:自定义信号与槽连接

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 一.引言 本文利用中介绍了PyQt中的信号和槽机制,除了使用PyQt组件的已有信号外,PyQt和Qt ...

  8. PyQt(Python+Qt)学习随笔:Qt Designer中主窗口对象的animated属性

    animated属性用于设置在操作可浮动部件和工具栏时是否设置动画. 当一个可浮动部件或工具栏被拖到主窗口上时,主窗口将调整其内容,以显示浮动部件或工具栏应该放置的位置.设置此属性后主窗口将使用平滑动 ...

  9. PyQt(Python+Qt)学习随笔:desktop的frameGeometry、frameSize、availableGeometry,screenGeometry

    frameGeometry:返回窗口相对于父窗口的几何形状的大小,包括窗口的框架,当窗口是顶级窗口时,返回的实际上是屏幕的大小: frameSize:返回窗口的几何形状的大小,包括窗口的框架,当窗口是 ...

  10. VS Code 搭建 Rust 开发环境

    VS Code 搭建 Rust 开发环境 上一篇文章安装和配置好了 Rust 环境后,我们是使用的是简单的文本工具编写 Hello World 入门代码,但是为了提高我们的学习效率,下面安利大家 VS ...