| 
					
				 | 
			
			
				@@ -4,6 +4,7 @@ package com.huaxu.service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.core.metadata.IPage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.huaxu.common.ToolUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.huaxu.dao.UserMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.huaxu.dto.UserListDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.huaxu.entity.UserEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.huaxu.entity.UserRoleEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.huaxu.entity.UserTagEntity; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -20,9 +21,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import javax.annotation.Resource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Arrays; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * 用户Service接口 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -114,15 +115,15 @@ public class UserService extends ServiceImpl<UserMapper,UserEntity> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		if (userEntity != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			//將禁用的角色放入redis,作为登出判断 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			if (userEntity.getEnableState().equals("0")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				String roleKey = "disableUser:" + id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				redisUtil.setExpire(roleKey.getBytes(), ByteArrayUtils.objectToBytes("1").get(), 60 * 60 * 24);//15分钟过期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			String roleKey = "disableUser:" + id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			redisUtil.setExpire(roleKey.getBytes(), ByteArrayUtils.objectToBytes("1").get(), 60 * 60 * 24);//15分钟过期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			if (userEntity.getEnableState().equals("1")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				String roleKey = "disableUser:" + id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				redisUtil.del(roleKey.getBytes()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (userEntity.getEnableState().equals("1")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			String roleKey = "disableUser:" + id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			redisUtil.del(roleKey.getBytes()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return this.removeById(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -268,12 +269,65 @@ public class UserService extends ServiceImpl<UserMapper,UserEntity> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return userEntities; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public List<UserListDto> findUserList() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<UserListDto> userListDtos = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		LoginUser currentUser = UserUtil.getCurrentUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		UserEntity userEntity=new UserEntity(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		userEntity.setTenantId(currentUser.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		userEntity.setProgramItems(currentUser.getProgramItemList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		userEntity.setUserType(currentUser.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//1是公司,2是公司及以下,3部门,4部门及以下,5自定义 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		userEntity.setPermissonType(currentUser.getPermissonType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<UserEntity>userEntities=userMapper.findUserList(userEntity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<UserEntity>companyUser=new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<UserEntity>departmentUser=new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		userEntities.forEach(user->{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if(user.getDeptOrgId()!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				departmentUser.add(user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			}else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				companyUser.add(user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Map<Long, List<UserEntity>> companyGroup = companyUser.stream() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.collect(Collectors.groupingBy(d -> d.getCompanyOrgId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Map<Long, List<UserEntity>> departMentGroup = departmentUser.stream() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.collect(Collectors.groupingBy(d -> d.getDeptOrgId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Iterator<List<UserEntity>> companyIterator = companyGroup.values().iterator(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Iterator<List<UserEntity>> departmentIterator = departMentGroup.values().iterator(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		while(companyIterator.hasNext()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<UserEntity> users = companyIterator.next(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			UserListDto userListDto=new UserListDto(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			UserEntity user = users.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			userListDto.setLabel(user.getCompanyOrgName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			userListDto.setId(user.getCompanyOrgId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			userListDto.setValue(user.getCompanyOrgName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			userListDto.setChildren(setChildrens(users)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			userListDtos.add(userListDto); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	public List<UserEntity> findUserIdsByUserIds(List<Integer> userIds) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		List<UserEntity> userEntities = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		if(userIds.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			userEntities=userMapper.findUserIdsByUserIds(userIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		return userEntities; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		while(departmentIterator.hasNext()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<UserEntity> users = departmentIterator.next(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			UserListDto userListDto=new UserListDto(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			UserEntity user = users.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			userListDto.setLabel(user.getDeptOrgName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			userListDto.setId(user.getDeptOrgId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			userListDto.setValue(user.getDeptOrgName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			userListDto.setChildren(setChildrens(users)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			userListDtos.add(userListDto); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return userListDtos; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private List<UserListDto> setChildrens(List<UserEntity> users){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<UserListDto> childrens=new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		users.forEach(u->{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			UserListDto children=new UserListDto(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			children.setLabel(u.getUsername()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			children.setId(u.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			children.setValue(u.getUsername()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			childrens.add(children); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return childrens; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |