Explorar el Código

导入导出增加岗们和角色

wuhb hace 7 meses
padre
commit
a200d5a2a3

+ 2 - 1
ygtx-admin/src/main/java/com/ygtx/web/controller/system/SysUserController.java

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 import com.ygtx.common.annotation.Log;
@@ -78,7 +79,7 @@ public class SysUserController extends BaseController
     @Log(title = "用户管理", businessType = BusinessType.IMPORT)
     @PreAuthorize("@ss.hasPermi('system:user:import')")
     @PostMapping("/importData")
-    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
+    public AjaxResult importData(MultipartFile file, @RequestParam(defaultValue = "false") boolean updateSupport) throws Exception
     {
         ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
         List<SysUser> userList = util.importExcel(file.getInputStream());

+ 35 - 12
ygtx-common/src/main/java/com/ygtx/common/core/domain/entity/SysUser.java

@@ -93,8 +93,17 @@ public class SysUser extends BaseEntity
     /** 用户部门岗位信息 */
     private List<UserDeptPost> userDeptPosts;
 
-    /** 角色ID */
-    private Long roleId;
+    /** 部门名称(用于导入) */
+    @Excel(name = "部门名称", type = Type.IMPORT)
+    private String deptName;
+
+    /** 角色名称列表(用于导入导出) */
+    @Excel(name = "角色名称", type = Type.ALL)
+    private String roleNames;
+
+    /** 岗位名称列表(用于导入导出) */
+    @Excel(name = "岗位名称", type = Type.ALL)
+    private String postNames;
 
     public SysUser()
     {
@@ -304,16 +313,6 @@ public class SysUser extends BaseEntity
         this.postIds = postIds;
     }
 
-    public Long getRoleId()
-    {
-        return roleId;
-    }
-
-    public void setRoleId(Long roleId)
-    {
-        this.roleId = roleId;
-    }
-
     public List<UserDeptPost> getUserDeptPosts()
     {
         return userDeptPosts;
@@ -324,6 +323,30 @@ public class SysUser extends BaseEntity
         this.userDeptPosts = userDeptPosts;
     }
 
+    public String getDeptName() {
+        return deptName;
+    }
+
+    public void setDeptName(String deptName) {
+        this.deptName = deptName;
+    }
+
+    public String getRoleNames() {
+        return roleNames;
+    }
+
+    public void setRoleNames(String roleNames) {
+        this.roleNames = roleNames;
+    }
+
+    public String getPostNames() {
+        return postNames;
+    }
+
+    public void setPostNames(String postNames) {
+        this.postNames = postNames;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

+ 8 - 0
ygtx-system/src/main/java/com/ygtx/system/mapper/SysDeptMapper.java

@@ -36,6 +36,14 @@ public interface SysDeptMapper
      */
     public SysDept selectDeptById(Long deptId);
 
+    /**
+     * 根据部门名称查询信息
+     * 
+     * @param deptName 部门名称
+     * @return 部门信息
+     */
+    public SysDept selectDeptByDeptName(String deptName);
+
     /**
      * 根据ID查询所有子部门
      * 

+ 16 - 0
ygtx-system/src/main/java/com/ygtx/system/mapper/SysPostMapper.java

@@ -41,6 +41,14 @@ public interface SysPostMapper
      */
     public List<Long> selectPostListByUserId(Long userId);
 
+    /**
+     * 根据用户ID查询岗位信息
+     * 
+     * @param userId 用户ID
+     * @return 岗位信息列表
+     */
+    public List<SysPost> selectPostsByUserId(Long userId);
+
     /**
      * 查询用户所属岗位组
      * 
@@ -49,6 +57,14 @@ public interface SysPostMapper
      */
     public List<SysPost> selectPostsByUserName(String userName);
 
+    /**
+     * 根据岗位名称查询信息
+     * 
+     * @param postName 岗位名称
+     * @return 岗位信息
+     */
+    public SysPost selectPostByPostName(String postName);
+
     /**
      * 删除岗位信息
      * 

+ 8 - 0
ygtx-system/src/main/java/com/ygtx/system/mapper/SysRoleMapper.java

@@ -57,6 +57,14 @@ public interface SysRoleMapper
      */
     public List<SysRole> selectRolesByUserName(String userName);
 
+    /**
+     * 根据角色名称查询信息
+     * 
+     * @param roleName 角色名称
+     * @return 角色信息
+     */
+    public SysRole selectRoleByRoleName(String roleName);
+
     /**
      * 校验角色名称是否唯一
      * 

+ 8 - 0
ygtx-system/src/main/java/com/ygtx/system/service/ISysDeptService.java

@@ -59,6 +59,14 @@ public interface ISysDeptService
      */
     public SysDept selectDeptById(Long deptId);
 
+    /**
+     * 根据部门名称查询信息
+     * 
+     * @param deptName 部门名称
+     * @return 部门信息
+     */
+    public SysDept selectDeptByDeptName(String deptName);
+
     /**
      * 根据ID查询所有子部门(正常状态)
      * 

+ 16 - 0
ygtx-system/src/main/java/com/ygtx/system/service/ISysPostService.java

@@ -41,6 +41,14 @@ public interface ISysPostService
      */
     public List<Long> selectPostListByUserId(Long userId);
 
+    /**
+     * 根据用户ID查询岗位信息
+     * 
+     * @param userId 用户ID
+     * @return 岗位信息列表
+     */
+    public List<SysPost> selectPostsByUserId(Long userId);
+
     /**
      * 校验岗位名称
      * 
@@ -97,5 +105,13 @@ public interface ISysPostService
      */
     public int updatePost(SysPost post);
 
+    /**
+     * 根据岗位名称查询岗位信息
+     * 
+     * @param postName 岗位名称
+     * @return 岗位信息
+     */
+    public SysPost selectPostByPostName(String postName);
+
     public int getHomePostType(Long userId);
 }

+ 8 - 0
ygtx-system/src/main/java/com/ygtx/system/service/ISysRoleService.java

@@ -59,6 +59,14 @@ public interface ISysRoleService
      */
     public SysRole selectRoleById(Long roleId);
 
+    /**
+     * 根据角色名称查询角色
+     * 
+     * @param roleName 角色名称
+     * @return 角色对象信息
+     */
+    public SysRole selectRoleByRoleName(String roleName);
+
     /**
      * 校验角色名称是否唯一
      * 

+ 12 - 0
ygtx-system/src/main/java/com/ygtx/system/service/impl/SysDeptServiceImpl.java

@@ -126,6 +126,18 @@ public class SysDeptServiceImpl implements ISysDeptService
         return deptMapper.selectDeptById(deptId);
     }
 
+    /**
+     * 根据部门名称查询信息
+     * 
+     * @param deptName 部门名称
+     * @return 部门信息
+     */
+    @Override
+    public SysDept selectDeptByDeptName(String deptName)
+    {
+        return deptMapper.selectDeptByDeptName(deptName);
+    }
+
     /**
      * 根据ID查询所有子部门(正常状态)
      * 

+ 24 - 0
ygtx-system/src/main/java/com/ygtx/system/service/impl/SysPostServiceImpl.java

@@ -78,6 +78,30 @@ public class SysPostServiceImpl implements ISysPostService
         return postMapper.selectPostListByUserId(userId);
     }
 
+    /**
+     * 根据用户ID查询岗位信息
+     * 
+     * @param userId 用户ID
+     * @return 岗位信息列表
+     */
+    @Override
+    public List<SysPost> selectPostsByUserId(Long userId)
+    {
+        return postMapper.selectPostsByUserId(userId);
+    }
+
+    /**
+     * 根据岗位名称查询岗位信息
+     * 
+     * @param postName 岗位名称
+     * @return 岗位信息
+     */
+    @Override
+    public SysPost selectPostByPostName(String postName)
+    {
+        return postMapper.selectPostByPostName(postName);
+    }
+
     /**
      * 校验岗位名称是否唯一
      * 

+ 12 - 0
ygtx-system/src/main/java/com/ygtx/system/service/impl/SysRoleServiceImpl.java

@@ -139,6 +139,18 @@ public class SysRoleServiceImpl implements ISysRoleService
         return roleMapper.selectRoleById(roleId);
     }
 
+    /**
+     * 根据角色名称查询角色
+     * 
+     * @param roleName 角色名称
+     * @return 角色对象信息
+     */
+    @Override
+    public SysRole selectRoleByRoleName(String roleName)
+    {
+        return roleMapper.selectRoleByRoleName(roleName);
+    }
+
     /**
      * 校验角色名称是否唯一
      * 

+ 283 - 38
ygtx-system/src/main/java/com/ygtx/system/service/impl/SysUserServiceImpl.java

@@ -13,6 +13,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import com.ygtx.common.annotation.DataScope;
 import com.ygtx.common.constant.UserConstants;
+import com.ygtx.common.core.domain.entity.SysDept;
 import com.ygtx.common.core.domain.entity.SysRole;
 import com.ygtx.common.core.domain.entity.SysUser;
 import com.ygtx.common.exception.ServiceException;
@@ -32,6 +33,8 @@ import com.ygtx.system.mapper.SysUserPostMapper;
 import com.ygtx.system.mapper.SysUserRoleMapper;
 import com.ygtx.system.service.ISysConfigService;
 import com.ygtx.system.service.ISysDeptService;
+import com.ygtx.system.service.ISysPostService;
+import com.ygtx.system.service.ISysRoleService;
 import com.ygtx.system.service.ISysUserService;
 
 /**
@@ -65,6 +68,12 @@ public class SysUserServiceImpl implements ISysUserService
     @Autowired
     private ISysDeptService deptService;
 
+    @Autowired
+    private ISysPostService postService;
+
+    @Autowired
+    private ISysRoleService roleService;
+
     @Autowired
     protected Validator validator;
 
@@ -78,7 +87,41 @@ public class SysUserServiceImpl implements ISysUserService
     @DataScope(deptAlias = "d", userAlias = "u")
     public List<SysUser> selectUserList(SysUser user)
     {
-        return userMapper.selectUserList(user);
+        List<SysUser> userList = userMapper.selectUserList(user);
+        // 为导出功能加载角色和岗位信息
+        if (userList != null && !userList.isEmpty()) {
+            for (SysUser sysUser : userList) {
+                // 加载角色信息
+                List<SysRole> roles = roleMapper.selectRolePermissionByUserId(sysUser.getUserId());
+                sysUser.setRoles(roles);
+                // 设置角色名称用于导出
+                if (roles != null && !roles.isEmpty()) {
+                    StringBuilder roleNames = new StringBuilder();
+                    for (int i = 0; i < roles.size(); i++) {
+                        if (i > 0) {
+                            roleNames.append(",");
+                        }
+                        roleNames.append(roles.get(i).getRoleName());
+                    }
+                    sysUser.setRoleNames(roleNames.toString());
+                }
+                
+                // 加载岗位信息(从主岗位表获取)
+                List<SysPost> posts = postService.selectPostsByUserId(sysUser.getUserId());
+                // 设置岗位名称用于导出
+                if (posts != null && !posts.isEmpty()) {
+                    StringBuilder postNames = new StringBuilder();
+                    for (int i = 0; i < posts.size(); i++) {
+                        if (i > 0) {
+                            postNames.append(",");
+                        }
+                        postNames.append(posts.get(i).getPostName());
+                    }
+                    sysUser.setPostNames(postNames.toString());
+                }
+            }
+        }
+        return userList;
     }
     @Override
     public List<SysUser> selectUserListByDeptId(SysUser user)
@@ -435,48 +478,86 @@ public class SysUserServiceImpl implements ISysUserService
     }
 
     /**
-     * 新增用户岗位信息
+     * 新增用户角色信息
      * 
-     * @param user 用户对象
+     * @param userId 用户ID
+     * @param roleIds 角色组
      */
-    public void insertUserPost(SysUser user)
+    public void insertUserRole(Long userId, Long[] roleIds)
     {
-        Long[] posts = user.getPostIds();
-        if (StringUtils.isNotEmpty(posts))
+        if (StringUtils.isNotEmpty(roleIds))
         {
-            // 新增用户与岗位管理
-            List<SysUserPost> list = new ArrayList<SysUserPost>(posts.length);
-            for (Long postId : posts)
+            // 新增用户与角色管理
+            List<SysUserRole> list = new ArrayList<SysUserRole>(roleIds.length);
+            for (Long roleId : roleIds)
             {
-                SysUserPost up = new SysUserPost();
-                up.setUserId(user.getUserId());
-                up.setPostId(postId);
-                list.add(up);
+                // 检查角色是否存在
+                try {
+                    SysRole role = roleService.selectRoleById(roleId);
+                    if (role != null) {
+                        SysUserRole ur = new SysUserRole();
+                        ur.setUserId(userId);
+                        ur.setRoleId(roleId);
+                        list.add(ur);
+                    } else {
+                        log.warn("角色不存在,角色ID: {}, 用户ID: {}", roleId, userId);
+                    }
+                } catch (Exception e) {
+                    // 角色不存在,跳过
+                    log.warn("角色ID {} 不存在,跳过关联", roleId);
+                }
             }
-            userPostMapper.batchUserPost(list);
+            if (!list.isEmpty()) {
+                log.info("准备保存用户角色关联,用户ID: {}, 角色数量: {}", userId, list.size());
+                int result = userRoleMapper.batchUserRole(list);
+                log.info("用户角色关联保存结果,用户ID: {}, 保存数量: {}", userId, result);
+            } else {
+                log.info("没有有效的角色关联需要保存,用户ID: {}", userId);
+            }
+        } else {
+            log.info("用户没有角色信息需要保存,用户ID: {}", userId);
         }
     }
 
     /**
-     * 新增用户角色信息
+     * 新增用户岗位信息
      * 
-     * @param userId 用户ID
-     * @param roleIds 角色组
+     * @param user 用户对象
      */
-    public void insertUserRole(Long userId, Long[] roleIds)
+    public void insertUserPost(SysUser user)
     {
-        if (StringUtils.isNotEmpty(roleIds))
+        Long[] posts = user.getPostIds();
+        if (StringUtils.isNotEmpty(posts))
         {
-            // 新增用户与角色管理
-            List<SysUserRole> list = new ArrayList<SysUserRole>(roleIds.length);
-            for (Long roleId : roleIds)
+            // 新增用户与岗位管理
+            List<SysUserPost> list = new ArrayList<SysUserPost>(posts.length);
+            for (Long postId : posts)
             {
-                SysUserRole ur = new SysUserRole();
-                ur.setUserId(userId);
-                ur.setRoleId(roleId);
-                list.add(ur);
+                // 检查岗位是否存在
+                try {
+                    SysPost post = postService.selectPostById(postId);
+                    if (post != null) {
+                        SysUserPost up = new SysUserPost();
+                        up.setUserId(user.getUserId());
+                        up.setPostId(postId);
+                        list.add(up);
+                    } else {
+                        log.warn("岗位不存在,岗位ID: {}, 用户ID: {}", postId, user.getUserId());
+                    }
+                } catch (Exception e) {
+                    // 岗位不存在,跳过
+                    log.warn("岗位ID {} 不存在,跳过关联", postId);
+                }
+            }
+            if (!list.isEmpty()) {
+                log.info("准备保存用户岗位关联,用户ID: {}, 岗位数量: {}", user.getUserId(), list.size());
+                int result = userPostMapper.batchUserPost(list);
+                log.info("用户岗位关联保存结果,用户ID: {}, 保存数量: {}", user.getUserId(), result);
+            } else {
+                log.info("没有有效的岗位关联需要保存,用户ID: {}", user.getUserId());
             }
-            userRoleMapper.batchUserRole(list);
+        } else {
+            log.info("用户没有岗位信息需要保存,用户ID: {}", user.getUserId());
         }
     }
 
@@ -536,37 +617,185 @@ public class SysUserServiceImpl implements ISysUserService
         }
         int successNum = 0;
         int failureNum = 0;
+        int partialSuccessNum = 0;
         StringBuilder successMsg = new StringBuilder();
         StringBuilder failureMsg = new StringBuilder();
+        StringBuilder partialSuccessMsg = new StringBuilder();
         for (SysUser user : userList)
         {
             try
             {
+                // 通过部门名称查找部门ID
+                if (StringUtils.isNotEmpty(user.getDeptName())) {
+                    SysDept dept = deptService.selectDeptByDeptName(user.getDeptName());
+                    if (dept != null) {
+                        user.setDeptId(dept.getDeptId());
+                    }
+                }
+                
+                // 通过角色名称查找角色ID
+                if (StringUtils.isNotEmpty(user.getRoleNames())) {
+                    String[] roleNames = user.getRoleNames().split(",");
+                    List<Long> roleIds = new ArrayList<>();
+                    for (String roleName : roleNames) {
+                        roleName = roleName.trim();
+                        if (StringUtils.isNotEmpty(roleName)) {
+                            SysRole role = roleService.selectRoleByRoleName(roleName);
+                            if (role != null) {
+                                roleIds.add(role.getRoleId());
+                            }
+                        }
+                    }
+                    if (!roleIds.isEmpty()) {
+                        user.setRoleIds(roleIds.toArray(new Long[0]));
+                    }
+                }
+                
+                // 通过岗位名称查找岗位ID
+                if (StringUtils.isNotEmpty(user.getPostNames())) {
+                    String[] postNames = user.getPostNames().split(",");
+                    List<Long> postIds = new ArrayList<>();
+                    for (String postName : postNames) {
+                        postName = postName.trim();
+                        if (StringUtils.isNotEmpty(postName)) {
+                            SysPost post = postService.selectPostByPostName(postName);
+                            if (post != null) {
+                                postIds.add(post.getPostId());
+                            }
+                        }
+                    }
+                    if (!postIds.isEmpty()) {
+                        user.setPostIds(postIds.toArray(new Long[0]));
+                    }
+                }
+                
                 // 验证是否存在这个用户
                 SysUser u = userMapper.selectUserByUserName(user.getUserName());
                 if (StringUtils.isNull(u))
                 {
                     BeanValidators.validateWithException(validator, user);
-                    deptService.checkDeptDataScope(user.getDeptId());
                     String password = configService.selectConfigByKey("sys.user.initPassword");
                     user.setPassword(SecurityUtils.encryptPassword(password));
                     user.setCreateBy(operName);
+                    
+                    // 检查部门是否存在,如果不存在则记录警告但继续导入
+                    boolean deptExists = true;
+                    if (user.getDeptId() != null) {
+                        try {
+                            deptService.checkDeptDataScope(user.getDeptId());
+                        } catch (Exception e) {
+                            deptExists = false;
+                            partialSuccessMsg.append("<br/>" + (partialSuccessNum + 1) + "、账号 " + user.getUserName() + " 部门信息未找到");
+                        }
+                    }
+                    
+                    // 插入用户
                     userMapper.insertUser(user);
                     successNum++;
-                    successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
+                    
+                    // 确保用户ID已被正确设置
+                    if (user.getUserId() == null) {
+                        log.error("用户插入后ID为空,用户名: {}", user.getUserName());
+                        partialSuccessMsg.append("<br/>" + (partialSuccessNum + 1) + "、账号 " + user.getUserName() + " 用户ID为空");
+                        partialSuccessNum++;
+                    } else {
+                        // 处理角色关联
+                        boolean roleProcessed = true;
+                        if (user.getRoleIds() != null && user.getRoleIds().length > 0) {
+                            try {
+                                insertUserRole(user);
+                            } catch (Exception e) {
+                                roleProcessed = false;
+                                log.error("用户角色关联保存失败,用户名: " + user.getUserName(), e);
+                                partialSuccessMsg.append("<br/>" + (partialSuccessNum + 1) + "、账号 " + user.getUserName() + " 角色信息未完全导入");
+                            }
+                        }
+                        
+                        // 处理岗位关联
+                        boolean postProcessed = true;
+                        if (user.getPostIds() != null && user.getPostIds().length > 0) {
+                            try {
+                                insertUserPost(user);
+                            } catch (Exception e) {
+                                postProcessed = false;
+                                log.error("用户岗位关联保存失败,用户名: " + user.getUserName(), e);
+                                partialSuccessMsg.append("<br/>" + (partialSuccessNum + 1) + "、账号 " + user.getUserName() + " 岗位信息未完全导入");
+                            }
+                        }
+                        
+                        if (!deptExists || !roleProcessed || !postProcessed) {
+                            partialSuccessNum++;
+                        }
+                        
+                        if (deptExists && roleProcessed && postProcessed) {
+                            successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
+                        } else {
+                            partialSuccessMsg.append("<br/>" + (partialSuccessNum) + "、账号 " + user.getUserName() + " 已导入,但部分信息缺失");
+                        }
+                    }
                 }
                 else if (isUpdateSupport)
                 {
                     BeanValidators.validateWithException(validator, user);
                     checkUserAllowed(u);
                     checkUserDataScope(u.getUserId());
-                    deptService.checkDeptDataScope(user.getDeptId());
                     user.setUserId(u.getUserId());
-                    user.setDeptId(u.getDeptId());
                     user.setUpdateBy(operName);
+                    
+                    // 检查部门是否存在
+                    boolean deptExists = true;
+                    if (user.getDeptId() != null) {
+                        try {
+                            deptService.checkDeptDataScope(user.getDeptId());
+                        } catch (Exception e) {
+                            deptExists = false;
+                            partialSuccessMsg.append("<br/>" + (partialSuccessNum + 1) + "、账号 " + user.getUserName() + " 部门信息未找到");
+                        }
+                    }
+                    
+                    // 更新用户
                     userMapper.updateUser(user);
                     successNum++;
-                    successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 更新成功");
+                    
+                    // 处理角色关联
+                    boolean roleProcessed = true;
+                    if (user.getRoleIds() != null && user.getRoleIds().length > 0) {
+                        try {
+                            // 删除原有角色关联
+                            userRoleMapper.deleteUserRoleByUserId(user.getUserId());
+                            // 添加新角色关联
+                            insertUserRole(user);
+                        } catch (Exception e) {
+                            roleProcessed = false;
+                            log.error("用户角色关联更新失败,用户名: " + user.getUserName(), e);
+                            partialSuccessMsg.append("<br/>" + (partialSuccessNum + 1) + "、账号 " + user.getUserName() + " 角色信息未完全更新");
+                        }
+                    }
+                    
+                    // 处理岗位关联
+                    boolean postProcessed = true;
+                    if (user.getPostIds() != null && user.getPostIds().length > 0) {
+                        try {
+                            // 删除原有岗位关联
+                            userPostMapper.deleteUserPostByUserId(user.getUserId());
+                            // 添加新岗位关联
+                            insertUserPost(user);
+                        } catch (Exception e) {
+                            postProcessed = false;
+                            log.error("用户岗位关联更新失败,用户名: " + user.getUserName(), e);
+                            partialSuccessMsg.append("<br/>" + (partialSuccessNum + 1) + "、账号 " + user.getUserName() + " 岗位信息未完全更新");
+                        }
+                    }
+                    
+                    if (!deptExists || !roleProcessed || !postProcessed) {
+                        partialSuccessNum++;
+                    }
+                    
+                    if (deptExists && roleProcessed && postProcessed) {
+                        successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 更新成功");
+                    } else {
+                        partialSuccessMsg.append("<br/>" + (partialSuccessNum) + "、账号 " + user.getUserName() + " 已更新,但部分信息缺失");
+                    }
                 }
                 else
                 {
@@ -582,16 +811,32 @@ public class SysUserServiceImpl implements ISysUserService
                 log.error(msg, e);
             }
         }
-        if (failureNum > 0)
+        StringBuilder resultMsg = new StringBuilder();
+        if (successNum > 0)
         {
-            failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
-            throw new ServiceException(failureMsg.toString());
+            resultMsg.append("成功导入完整用户 " + successNum + " 条,数据如下:");
+            resultMsg.append(successMsg);
         }
-        else
+        if (partialSuccessNum > 0)
         {
-            successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
+            if (resultMsg.length() > 0) {
+                resultMsg.append("<br/><br/>");
+            }
+            resultMsg.append("成功导入但信息不完整用户 " + partialSuccessNum + " 条,数据如下:");
+            resultMsg.append(partialSuccessMsg);
+        }
+        if (failureNum > 0)
+        {
+            if (resultMsg.length() > 0) {
+                resultMsg.append("<br/><br/>");
+            }
+            resultMsg.append("导入失败 " + failureNum + " 条,错误如下:");
+            resultMsg.append(failureMsg);
+        }
+        if (resultMsg.length() == 0) {
+            resultMsg.append("没有数据被导入");
         }
-        return successMsg.toString();
+        return resultMsg.toString();
     }
     
     /**

+ 5 - 0
ygtx-system/src/main/resources/mapper/system/SysDeptMapper.xml

@@ -72,6 +72,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		where d.dept_id = #{deptId}
 	</select>
     
+    <select id="selectDeptByDeptName" parameterType="String" resultMap="SysDeptResult">
+        <include refid="selectDeptVo"/>
+        where dept_name = #{deptName} and del_flag = '0' limit 1
+    </select>
+    
     <select id="checkDeptExistUser" parameterType="Long" resultType="int">
 		select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
 	</select>

+ 13 - 0
ygtx-system/src/main/resources/mapper/system/SysPostMapper.xml

@@ -54,6 +54,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	    where u.user_id = #{userId}
 	</select>
 	
+	<select id="selectPostsByUserId" parameterType="Long" resultMap="SysPostResult">
+		select p.post_id, p.post_name, p.post_code, p.post_sort, p.status, p.create_by, p.create_time, p.update_by, p.update_time, p.remark
+		from sys_post p
+			 left join sys_user_post up on up.post_id = p.post_id
+			 left join sys_user u on u.user_id = up.user_id
+		where u.user_id = #{userId}
+	</select>
+	
 	<select id="selectPostsByUserName" parameterType="String" resultMap="SysPostResult">
 		select p.post_id, p.post_name, p.post_code
 		from sys_post p
@@ -62,6 +70,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		where u.user_name = #{userName}
 	</select>
 	
+	<select id="selectPostByPostName" parameterType="String" resultMap="SysPostResult">
+		<include refid="selectPostVo"/>
+		where post_name = #{postName} limit 1
+	</select>
+	
 	<select id="checkPostNameUnique" parameterType="String" resultMap="SysPostResult">
 		<include refid="selectPostVo"/>
 		 where post_name=#{postName} limit 1

+ 5 - 0
ygtx-system/src/main/resources/mapper/system/SysRoleMapper.xml

@@ -83,6 +83,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		WHERE r.del_flag = '0' and u.user_name = #{userName}
 	</select>
 	
+	<select id="selectRoleByRoleName" parameterType="String" resultMap="SysRoleResult">
+		<include refid="selectRoleVo"/>
+		where r.role_name = #{roleName} and r.del_flag = '0' limit 1
+	</select>
+	
 	<select id="checkRoleNameUnique" parameterType="String" resultMap="SysRoleResult">
 		<include refid="selectRoleVo"/>
 		 where r.role_name=#{roleName} and r.del_flag = '0' limit 1

+ 30 - 30
ygtx-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -59,36 +59,36 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </sql>
 
     <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
-		select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
-		left join sys_dept d on u.dept_id = d.dept_id
-		where u.del_flag = '0'
-		<if test="userId != null and userId != 0">
-			AND u.user_id = #{userId}
-		</if>
-		<if test="userName != null and userName != ''">
-			AND u.user_name like concat('%', #{userName}, '%')
-		</if>
-		<if test="nickName != null and nickName != ''">
-			AND u.nick_name like concat('%', #{nickName}, '%')
-		</if>
-		<if test="status != null and status != ''">
-			AND u.status = #{status}
-		</if>
-		<if test="phonenumber != null and phonenumber != ''">
-			AND u.phonenumber like concat('%', #{phonenumber}, '%')
-		</if>
-		<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
-			AND date_format(u.create_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')
-		</if>
-		<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
-			AND date_format(u.create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
-		</if>
-		<if test="deptId != null and deptId != 0">
-			AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) ))
-		</if>
-		<!-- 数据范围过滤 -->
-		${params.dataScope}
-	</select>
+        select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
+        left join sys_dept d on u.dept_id = d.dept_id
+        where u.del_flag = '0'
+        <if test="userId != null and userId != 0">
+            AND u.user_id = #{userId}
+        </if>
+        <if test="userName != null and userName != ''">
+            AND u.user_name like concat('%', #{userName}, '%')
+        </if>
+        <if test="nickName != null and nickName != ''">
+            AND u.nick_name like concat('%', #{nickName}, '%')
+        </if>
+        <if test="status != null and status != ''">
+            AND u.status = #{status}
+        </if>
+        <if test="phonenumber != null and phonenumber != ''">
+            AND u.phonenumber like concat('%', #{phonenumber}, '%')
+        </if>
+        <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
+            AND date_format(u.create_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')
+        </if>
+        <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
+            AND date_format(u.create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
+        </if>
+        <if test="deptId != null and deptId != 0">
+            AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) ))
+        </if>
+        <!-- 数据范围过滤 -->
+        ${params.dataScope}
+    </select>
 
 	<select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
 	    select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time

+ 2 - 2
ygtx-ui/src/views/system/user/index.vue

@@ -241,7 +241,7 @@
 
     <!-- 用户导入对话框 -->
     <el-dialog :title="upload.title" v-model="upload.open" width="400px" append-to-body>
-      <el-upload ref="uploadRef" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :on-change="handleFileChange" :on-remove="handleFileRemove" :auto-upload="false" drag>
+      <el-upload ref="uploadRef" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url + '?updateSupport=' + (upload.updateSupport ? 'true' : 'false')" :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :on-change="handleFileChange" :on-remove="handleFileRemove" :auto-upload="false" drag>
         <el-icon class="el-icon--upload"><upload-filled /></el-icon>
         <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
         <template #tip>
@@ -301,7 +301,7 @@ const upload = reactive({
   // 是否禁用上传
   isUploading: false,
   // 是否更新已经存在的用户数据
-  updateSupport: 0,
+  updateSupport: false,
   // 设置上传的请求头部
   headers: { Authorization: "Bearer " + getToken() },
   // 上传的地址