| 
					
				 | 
			
			
				@@ -3,17 +3,17 @@ package com.flyer.foster.service.impl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.dev33.satoken.session.SaSession; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.dev33.satoken.stp.StpUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.core.bean.BeanUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import cn.hutool.core.util.StrUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import cn.hutool.core.convert.Convert; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.crypto.SecureUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.crypto.asymmetric.KeyType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.crypto.asymmetric.RSA; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import cn.hutool.setting.dialect.Props; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.core.metadata.IPage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.flyer.exception.BusinessException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.flyer.foster.consts.LoginDevice; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.flyer.foster.consts.RedisKeyConst; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.flyer.foster.dto.LoginDTO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.flyer.foster.dto.UserAddDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.flyer.foster.dto.UserAddOrUpdateDTO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.flyer.foster.dto.UserSearchDTO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.flyer.foster.entity.Role; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -26,16 +26,12 @@ import com.flyer.foster.service.IUserService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.flyer.util.RedisUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.springframework.core.env.Environment; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -118,7 +114,7 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public IPage<UserSearchDTO> selectByPage(IPage<User> page, UserSearchDTO searchDTO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        int tenantId = Integer.parseInt(StpUtil.getTokenSession().get("tenantId").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int tenantId = StpUtil.getTokenSession().getInt("tenantId"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         searchDTO.setTenantId(tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 查询管理员角色的账号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Role adminRole = iRoleService.lambdaQuery().eq(Role::getIsAdmin, 1).eq(Role::getTenantId, tenantId).one(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -141,34 +137,45 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public boolean addUserAndRole(UserAddOrUpdateDTO addDTO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        log.info("UserServiceImpl--->addUserAndRole params is {}", JSON.toJSONString(addDTO)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        int tenantId = Integer.parseInt(StpUtil.getTokenSession().get("tenantId").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // 查看用户名是否存在 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        String userName = addDTO.getUsername(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        long count = this.lambdaQuery().eq(User::getUsername, userName).count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (count != 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            throw new BusinessException("用户已存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        User user = new User(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        BeanUtil.copyProperties(addDTO, user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // 密码MD5加密存入 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        user.setPassword(SecureUtil.md5(user.getPassword())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        user.setTenantId(tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        boolean saveResult = this.save(user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (!saveResult) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            throw new BusinessException("新增用户失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public boolean removeByIdList(List<Integer> idList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int tenantId = StpUtil.getTokenSession().getInt("tenantId"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 删除用户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        baseMapper.deleteByIdList(idList, tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 删除用户的角色 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        iUserRoleService.deleteByUserIdList(idList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public boolean addUser(UserAddDto addDto) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        addDto.setUsername(addDto.getUsername().trim()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int tenantId = StpUtil.getTokenSession().getInt("tenantId"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User user; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (addDto.getRoleId() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new BusinessException("请选择角色"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        UserRole insertEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        for (Integer roleId : addDTO.getRoleIdList()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            insertEntity = new UserRole(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            insertEntity.setUserId(user.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            insertEntity.setRoleId(roleId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            boolean saveRoleResult = iUserRoleService.save(insertEntity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (!saveRoleResult) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                throw new BusinessException("新增用户角色关系数据失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        user = this.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(User::getUsername, addDto.getUsername()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(User::getTenantId, tenantId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .one(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (user != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new BusinessException("用户名已存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        user = new User(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BeanUtil.copyProperties(addDto, user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        user.setTenantId(tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // md5加密 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        user.setPassword(SecureUtil.md5(user.getPassword())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 1.添加用户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        this.save(user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        UserRole userRole = new UserRole(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userRole.setUserId(user.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userRole.setRoleId(addDto.getRoleId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userRole.setTenantId(tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 2.添加用户角色 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        iUserRoleService.save(userRole); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |