|
@@ -16,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.catalina.User;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.apache.shiro.authz.annotation.RequiresRoles;
|
|
@@ -34,8 +35,10 @@ import org.jeecg.config.mybatis.MybatisPlusSaasConfig;
|
|
|
import org.jeecg.modules.base.service.BaseCommonService;
|
|
|
import org.jeecg.modules.system.entity.*;
|
|
|
import org.jeecg.modules.system.model.DepartIdModel;
|
|
|
+import org.jeecg.modules.system.model.SysDepartTreeModel;
|
|
|
import org.jeecg.modules.system.model.SysUserSysDepartModel;
|
|
|
import org.jeecg.modules.system.service.*;
|
|
|
+import org.jeecg.modules.system.util.ExcelImportHandleUtil;
|
|
|
import org.jeecg.modules.system.vo.SysDepartUsersVO;
|
|
|
import org.jeecg.modules.system.vo.SysUserRoleVO;
|
|
|
import org.jeecg.modules.system.vo.lowapp.DepartAndUserInfo;
|
|
@@ -45,6 +48,7 @@ import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
|
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
|
|
import org.jeecgframework.poi.excel.entity.ImportParams;
|
|
|
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
|
|
+import org.jeecgframework.poi.util.PoiPublicUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -54,7 +58,7 @@ import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.IOException;
|
|
|
+import java.io.*;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -110,7 +114,8 @@ public class SysUserController {
|
|
|
|
|
|
@Autowired
|
|
|
private JeecgRedisClient jeecgRedisClient;
|
|
|
-
|
|
|
+ private StringBuilder deptStr;
|
|
|
+
|
|
|
/**
|
|
|
* 获取租户下用户数据(支持租户隔离)
|
|
|
* @param user
|
|
@@ -621,15 +626,22 @@ public class SysUserController {
|
|
|
String[] expectedHeaders = {"登录账号", "真实姓名", "性别", "电话", "工号", "所属部门"};
|
|
|
boolean isHeaderValid = checkHeader(headerRow, expectedHeaders);
|
|
|
|
|
|
+ InputStream inputStream = ExcelImportHandleUtil.fileStreamProcessing(file, 3, 0);
|
|
|
+
|
|
|
+
|
|
|
+ List<SysUser> listSysUsers = ExcelImportUtil.importExcel(inputStream, SysUser.class, params);
|
|
|
|
|
|
- List<SysUser> listSysUsers = ExcelImportUtil.importExcel(file.getInputStream(), SysUser.class, params);
|
|
|
if (!isHeaderValid) {
|
|
|
errorMessage.add("文件 " + fileName + " 格式不正确");
|
|
|
errorLines =listSysUsers.size();
|
|
|
throw new IllegalArgumentException("文件格式不正确");
|
|
|
}
|
|
|
for (int i = 0; i < listSysUsers.size(); i++) {
|
|
|
+
|
|
|
SysUser sysUserExcel = listSysUsers.get(i);
|
|
|
+ String depart = sysUserExcel.getDepartmentId();
|
|
|
+
|
|
|
+
|
|
|
if (StringUtils.isBlank(sysUserExcel.getPassword())) {
|
|
|
// 密码默认为 “123456”
|
|
|
sysUserExcel.setPassword("123456");
|
|
@@ -644,6 +656,15 @@ public class SysUserController {
|
|
|
String passwordEncode = PasswordUtil.encrypt(sysUserExcel.getUsername(), sysUserExcel.getPassword(), salt);
|
|
|
sysUserExcel.setPassword(passwordEncode);
|
|
|
try {
|
|
|
+ if (depart.contains("/")) {
|
|
|
+ String[] departNames = depart.split("/");
|
|
|
+ List<SysDepartTreeModel> list = sysDepartService.queryMyDeptTreeList(null);
|
|
|
+ SysDepartTreeModel nodeByPath = findNodeByPath(list, departNames);
|
|
|
+ if (ObjectUtil.isEmpty(nodeByPath)) {
|
|
|
+ throw new IllegalArgumentException("组织不存在");
|
|
|
+ }
|
|
|
+ sysUserExcel.setDepartmentId(nodeByPath.getId());
|
|
|
+ }
|
|
|
|
|
|
if (ObjectUtil.isNull(sysUserExcel.getUsername()) || sysUserExcel.getUsername().isEmpty()) {
|
|
|
// errorMessage.add("第 " + i+1 + " 行:用户名为空。");
|
|
@@ -676,7 +697,16 @@ public class SysUserController {
|
|
|
int lineNumber = i + 1;
|
|
|
// 通过索引名判断出错信息
|
|
|
if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_USER_USERNAME)) {
|
|
|
- errorMessage.add("第 " + lineNumber + " 行:用户名已经存在,忽略导入。");
|
|
|
+ String errMessage = "第 " + lineNumber + " 行:用户名已经存在,忽略导入。";
|
|
|
+ List<SysUser> logicDeletedUserList = sysUserService.queryLogicDeleted();
|
|
|
+ if (logicDeletedUserList.size() > 0) {
|
|
|
+ List<String> usernames = logicDeletedUserList.stream().map(SysUser::getUsername).collect(Collectors.toList());
|
|
|
+ //sysUserExcel的username是否在usernames中
|
|
|
+ if (usernames.contains(sysUserExcel.getUsername())) {
|
|
|
+ errMessage = errMessage + "用户在回收站中存在。";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ errorMessage.add(errMessage);
|
|
|
} else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_USER_WORK_NO)) {
|
|
|
errorMessage.add("第 " + lineNumber + " 行:工号已经存在,忽略导入。");
|
|
|
} else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_USER_PHONE)) {
|
|
@@ -688,7 +718,9 @@ public class SysUserController {
|
|
|
} else if (message.contains("用户名为空")) {
|
|
|
errorMessage.add("第 " + lineNumber + " 行:用户名为空。");
|
|
|
} else if (message.contains("用户真实姓名为空")) {
|
|
|
- errorMessage.add("第 " + lineNumber + " 行:用户真实姓名为空。");
|
|
|
+ errorMessage.add("第 " + lineNumber + " 行:用户真实姓名为空。用户名:" + sysUserExcel.getUsername());
|
|
|
+ } else if (message.contains("组织不存在")) {
|
|
|
+ errorMessage.add("第 " + lineNumber + " 行:组织不存在。用户名:" + sysUserExcel.getUsername());
|
|
|
} else {
|
|
|
errorMessage.add("第 " + lineNumber + " 行:未知错误,忽略导入");
|
|
|
log.error(e.getMessage(), e);
|
|
@@ -2103,5 +2135,28 @@ public class SysUserController {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+// 递归查找指定路径对应的节点
|
|
|
+ public static SysDepartTreeModel findNodeByPath(List<SysDepartTreeModel> tree, String[] path) {
|
|
|
+ if (path == null || path.length == 0 || tree == null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
+ for (SysDepartTreeModel node : tree) {
|
|
|
+ if (node.getDepartName().equals(path[0])) {
|
|
|
+ if (path.length == 1) {
|
|
|
+ // 找到了路径的最后一部分
|
|
|
+ return node;
|
|
|
+ } else {
|
|
|
+ String[] paths = Arrays.copyOfRange(path, 1, path.length);
|
|
|
+ // 递归查找子节点
|
|
|
+ SysDepartTreeModel result = findNodeByPath(node.getChildren(), paths);
|
|
|
+ if (result != null) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果没有找到匹配的节点,返回null
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|