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;
}
}

最新文章

  1. .NET平台开源项目速览(13)机器学习组件Accord.NET框架功能介绍
  2. Java基础(二) ---- 继承(Inheritance)
  3. Java 输入输出流 转载
  4. 使用Visual Studio Code开发Asp.Net Core WebApi学习笔记(六)-- 依赖注入
  5. PHP 概述 特点 基础语法
  6. 项目FAQ
  7. 在Eclipse工具里创建maven的web工程,在建立src/main/java包出现The folder is already a source folder.解决
  8. Android 任何位置的可移动悬浮窗
  9. Python 爬虫实战(一):使用 requests 和 BeautifulSoup
  10. Html鼠标右键菜单代码
  11. 四种方式实现子goroutine与主线程的同步
  12. Android 免Root实现Apk静默安装,覆盖兼容市场主流的98%的机型
  13. Ubuntu编译安装最新的webkit
  14. (笔记)Linux内核学习(一)之内核介绍
  15. 解决在V2.0中子组件使用v-model接收来自父组件的值异常
  16. 洛谷1288 取数游戏II
  17. 最长公共子串(LCS:Longest Common Substring)
  18. Linux本地解析文件/etc/hosts说明【原创】
  19. uestc 360(区间合并)
  20. CSS伪代码

热门文章

  1. Beta冲刺随笔——Day_Four
  2. 欢迎使用CSDN-markdown编辑器(这个只能看到一次保存一下)
  3. 第三十八章、PyQt输入部件:QKeySequenceEdit快捷键输入部件使用案例
  4. Python中的迭代是什么意思?
  5. PyQt(Python+Qt)学习随笔:QDockWidget停靠窗toggleViewAction方法的作用
  6. 深入理解python
  7. POJ_1961
  8. 【软件测试部署基础】npm的认识
  9. DVWA SQL Injection High
  10. NOI Online #2 提高组 游记