Browse Source

导入报错信息修改

gao.qiang 2 years ago
parent
commit
f2736c854c

+ 15 - 5
base-system/src/main/java/com/ozs/system/service/impl/SysUserServiceImpl.java

@@ -41,6 +41,7 @@ import com.ozs.system.mapper.SysUserPostMapper;
 import com.ozs.system.mapper.SysUserRoleMapper;
 import com.ozs.system.service.ISysConfigService;
 import com.ozs.system.service.ISysUserService;
+import org.springframework.util.ObjectUtils;
 
 /**
  * 用户 业务层处理
@@ -530,6 +531,7 @@ public class SysUserServiceImpl extends JoinServiceImpl<SysUserMapper, SysUser>
         int failureNum = 0;
         StringBuilder successMsg = new StringBuilder();
         StringBuilder failureMsg = new StringBuilder();
+        StringBuilder errMsg = new StringBuilder();
         String password = configService.selectConfigByKey("sys.user.initPassword");
         for (SysUsers user : userList) {
             try {
@@ -544,6 +546,9 @@ public class SysUserServiceImpl extends JoinServiceImpl<SysUserMapper, SysUser>
                     sysUser.setUpdateBy(operName);
                     sysUser.setUserId(IdUtils.fastSimpleUUID());
                     SysDept sysDept = deptMapper.selectDeptByDeptName(user.getDeptName());
+                    if (ObjectUtils.isEmpty(sysDept)) {
+                        errMsg.append("部门名称:" + user.getDeptName() + "不存在");
+                    }
                     sysUser.setDeptId(sysDept.getDeptId());
                     sysUser.setPassword(SecurityUtils.encryptPassword(defaultPassword));
                     this.insertUser(sysUser);
@@ -563,7 +568,7 @@ public class SysUserServiceImpl extends JoinServiceImpl<SysUserMapper, SysUser>
                         }
                     }
                     successNum++;
-                    successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
+                    successMsg.append(successNum + "、账号 " + user.getUserName() + " 导入成功");
                 } else if (isUpdateSupport) {
                     BeanValidators.validateWithException(validator, user);
 //                    checkUserAllowed(sysUser);
@@ -573,15 +578,20 @@ public class SysUserServiceImpl extends JoinServiceImpl<SysUserMapper, SysUser>
                     sysUser.setDeptId(sysDept.getDeptId());
                     this.updateUser(sysUser);
                     successNum++;
-                    successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 更新成功");
+                    successMsg.append(successNum + "、账号 " + user.getUserName() + " 更新成功");
                 } else {
                     failureNum++;
-                    failureMsg.append("<br/>" + failureNum + "、账号 " + user.getUserName() + " 已存在");
+                    failureMsg.append(failureNum + "、账号 " + user.getUserName() + " 已存在");
                 }
             } catch (Exception e) {
                 failureNum++;
-                String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败:";
-                failureMsg.append(msg + e.getMessage());
+                String msg = failureNum + "、账号 " + user.getUserName() + " 导入失败:";
+                if (errMsg.length() > 0) {
+                    failureMsg.append(msg + errMsg.toString());
+                    errMsg.setLength(0);
+                } else {
+                    failureMsg.append(msg + e.getMessage());
+                }
                 log.error(msg, e);
             }
         }