|  | @@ -2,11 +2,14 @@ package com.ruoyi.project.system.service.impl;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  import java.util.ArrayList;
 |  |  import java.util.ArrayList;
 | 
											
												
													
														|  |  import java.util.List;
 |  |  import java.util.List;
 | 
											
												
													
														|  | 
 |  | +import org.slf4j.Logger;
 | 
											
												
													
														|  | 
 |  | +import org.slf4j.LoggerFactory;
 | 
											
												
													
														|  |  import org.springframework.beans.factory.annotation.Autowired;
 |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
											
												
													
														|  |  import org.springframework.stereotype.Service;
 |  |  import org.springframework.stereotype.Service;
 | 
											
												
													
														|  |  import org.springframework.transaction.annotation.Transactional;
 |  |  import org.springframework.transaction.annotation.Transactional;
 | 
											
												
													
														|  |  import com.ruoyi.common.constant.UserConstants;
 |  |  import com.ruoyi.common.constant.UserConstants;
 | 
											
												
													
														|  |  import com.ruoyi.common.exception.CustomException;
 |  |  import com.ruoyi.common.exception.CustomException;
 | 
											
												
													
														|  | 
 |  | +import com.ruoyi.common.utils.SecurityUtils;
 | 
											
												
													
														|  |  import com.ruoyi.common.utils.StringUtils;
 |  |  import com.ruoyi.common.utils.StringUtils;
 | 
											
												
													
														|  |  import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
 |  |  import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
 | 
											
												
													
														|  |  import com.ruoyi.project.system.domain.SysPost;
 |  |  import com.ruoyi.project.system.domain.SysPost;
 | 
											
										
											
												
													
														|  | @@ -19,6 +22,7 @@ import com.ruoyi.project.system.mapper.SysRoleMapper;
 | 
											
												
													
														|  |  import com.ruoyi.project.system.mapper.SysUserMapper;
 |  |  import com.ruoyi.project.system.mapper.SysUserMapper;
 | 
											
												
													
														|  |  import com.ruoyi.project.system.mapper.SysUserPostMapper;
 |  |  import com.ruoyi.project.system.mapper.SysUserPostMapper;
 | 
											
												
													
														|  |  import com.ruoyi.project.system.mapper.SysUserRoleMapper;
 |  |  import com.ruoyi.project.system.mapper.SysUserRoleMapper;
 | 
											
												
													
														|  | 
 |  | +import com.ruoyi.project.system.service.ISysConfigService;
 | 
											
												
													
														|  |  import com.ruoyi.project.system.service.ISysUserService;
 |  |  import com.ruoyi.project.system.service.ISysUserService;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  /**
 |  |  /**
 | 
											
										
											
												
													
														|  | @@ -29,6 +33,8 @@ import com.ruoyi.project.system.service.ISysUserService;
 | 
											
												
													
														|  |  @Service
 |  |  @Service
 | 
											
												
													
														|  |  public class SysUserServiceImpl implements ISysUserService
 |  |  public class SysUserServiceImpl implements ISysUserService
 | 
											
												
													
														|  |  {
 |  |  {
 | 
											
												
													
														|  | 
 |  | +    private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  |      private SysUserMapper userMapper;
 |  |      private SysUserMapper userMapper;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -44,6 +50,9 @@ public class SysUserServiceImpl implements ISysUserService
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  |      private SysUserPostMapper userPostMapper;
 |  |      private SysUserPostMapper userPostMapper;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private ISysConfigService configService;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  |       * 根据条件分页查询用户列表
 |  |       * 根据条件分页查询用户列表
 | 
											
												
													
														|  |       * 
 |  |       * 
 | 
											
										
											
												
													
														|  | @@ -375,4 +384,72 @@ public class SysUserServiceImpl implements ISysUserService
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |          return userMapper.deleteUserByIds(userIds);
 |  |          return userMapper.deleteUserByIds(userIds);
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    /**
 | 
											
												
													
														|  | 
 |  | +     * 导入用户数据
 | 
											
												
													
														|  | 
 |  | +     * 
 | 
											
												
													
														|  | 
 |  | +     * @param userList 用户数据列表
 | 
											
												
													
														|  | 
 |  | +     * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
 | 
											
												
													
														|  | 
 |  | +     * @param operName 操作用户
 | 
											
												
													
														|  | 
 |  | +     * @return 结果
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  | 
 |  | +    @Override
 | 
											
												
													
														|  | 
 |  | +    public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName)
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  | 
 |  | +        if (StringUtils.isNull(userList) || userList.size() == 0)
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            throw new CustomException("导入用户数据不能为空!");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        int successNum = 0;
 | 
											
												
													
														|  | 
 |  | +        int failureNum = 0;
 | 
											
												
													
														|  | 
 |  | +        StringBuilder successMsg = new StringBuilder();
 | 
											
												
													
														|  | 
 |  | +        StringBuilder failureMsg = new StringBuilder();
 | 
											
												
													
														|  | 
 |  | +        String password = configService.selectConfigByKey("sys.user.initPassword");
 | 
											
												
													
														|  | 
 |  | +        for (SysUser user : userList)
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            try
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                // 验证是否存在这个用户
 | 
											
												
													
														|  | 
 |  | +                SysUser u = userMapper.selectUserByUserName(user.getUserName());
 | 
											
												
													
														|  | 
 |  | +                if (StringUtils.isNull(u))
 | 
											
												
													
														|  | 
 |  | +                {
 | 
											
												
													
														|  | 
 |  | +                    user.setPassword(SecurityUtils.encryptPassword(password));
 | 
											
												
													
														|  | 
 |  | +                    user.setCreateBy(operName);
 | 
											
												
													
														|  | 
 |  | +                    this.insertUser(user);
 | 
											
												
													
														|  | 
 |  | +                    successNum++;
 | 
											
												
													
														|  | 
 |  | +                    successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +                else if (isUpdateSupport)
 | 
											
												
													
														|  | 
 |  | +                {
 | 
											
												
													
														|  | 
 |  | +                    user.setUpdateBy(operName);
 | 
											
												
													
														|  | 
 |  | +                    this.updateUser(user);
 | 
											
												
													
														|  | 
 |  | +                    successNum++;
 | 
											
												
													
														|  | 
 |  | +                    successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 更新成功");
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +                else
 | 
											
												
													
														|  | 
 |  | +                {
 | 
											
												
													
														|  | 
 |  | +                    failureNum++;
 | 
											
												
													
														|  | 
 |  | +                    failureMsg.append("<br/>" + failureNum + "、账号 " + user.getUserName() + " 已存在");
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            catch (Exception e)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                failureNum++;
 | 
											
												
													
														|  | 
 |  | +                String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败:";
 | 
											
												
													
														|  | 
 |  | +                failureMsg.append(msg + e.getMessage());
 | 
											
												
													
														|  | 
 |  | +                log.error(msg, e);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        if (failureNum > 0)
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
 | 
											
												
													
														|  | 
 |  | +            throw new CustomException(failureMsg.toString());
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        else
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        return successMsg.toString();
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  }
 |  |  }
 |