|
|
|
@ -31,6 +31,7 @@ import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiModel;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
|
import org.redisson.api.RLock;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -48,6 +49,7 @@ import java.io.*;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.nio.file.attribute.PosixFileAttributes;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@ -486,9 +488,9 @@ public class SysUserInfoController extends CoreBaseController {
|
|
|
|
|
ExcelTool excelTool = new ExcelTool(entityManager, redisRes);
|
|
|
|
|
try {
|
|
|
|
|
String filename = "userImportTemplate.xls";
|
|
|
|
|
SysPosition positionBean = new SysPosition();
|
|
|
|
|
positionBean.setOrganizeCode(AuthUtil.getOrganizeCode());
|
|
|
|
|
List<SysPosition> positionList = positionService.findAllByBaseBean(positionBean);
|
|
|
|
|
// SysPosition positionBean = new SysPosition();
|
|
|
|
|
// positionBean.setOrganizeCode(AuthUtil.getOrganizeCode());
|
|
|
|
|
List<SysPosition> positionList = positionService.findAllByBaseBean();
|
|
|
|
|
Map<String, String> positionMap = positionList.stream().collect(Collectors.toMap(position -> position.getPositionCode(), position -> position.getName(), (oldKey, newkey) -> oldKey));
|
|
|
|
|
|
|
|
|
|
Map<String, Map<String, String>> relatefildMap = new HashMap<>();
|
|
|
|
@ -520,83 +522,175 @@ public class SysUserInfoController extends CoreBaseController {
|
|
|
|
|
@PostMapping("/import")
|
|
|
|
|
@ApiOperation(value = "导用入户信息", notes = "导入用户信息")
|
|
|
|
|
public ResultBean importUserInfo(@RequestParam MultipartFile file) {
|
|
|
|
|
ExcelTool excelTool = new ExcelTool(entityManager, redisRes);
|
|
|
|
|
|
|
|
|
|
String lockKey = "REDISLOCK:IMPP:IMPORT_USER:" + AuthUtil.getSessionUser().getUserId();
|
|
|
|
|
RLock rLock = (RLock) redisRes.getLock(lockKey);
|
|
|
|
|
try {
|
|
|
|
|
//1.读取数据
|
|
|
|
|
List<UserInfoImportModel> importModelList = excelTool.importDataAndConver(file.getOriginalFilename(), file.getInputStream(), UserInfoImportModel.class, UserInfoImportModel.class.getSimpleName());
|
|
|
|
|
List<ResultBean> faildList = new ArrayList<>();
|
|
|
|
|
LOGGER.debug("导入用户信息: 共读取数据{}条", importModelList.size());
|
|
|
|
|
if (ObjectUtils.isEmpty(importModelList)) {
|
|
|
|
|
return ResultBean.success();
|
|
|
|
|
}
|
|
|
|
|
//2.数据格式校验并去重
|
|
|
|
|
List<UserInfoImportModel> userInfoList = validateAndDistinc(importModelList, faildList);
|
|
|
|
|
|
|
|
|
|
//3.某些数据字段转换
|
|
|
|
|
SysPosition positionBean = new SysPosition();
|
|
|
|
|
String organizationCode = AuthUtil.getOrganizeCode();
|
|
|
|
|
positionBean.setOrganizeCode(organizationCode);
|
|
|
|
|
List<SysPosition> positionList = positionService.findAllByBaseBean(positionBean);
|
|
|
|
|
|
|
|
|
|
Map<String, String> positionMap = positionList.stream().collect(Collectors.toMap(position -> position.getPositionCode(), position -> String.valueOf(position.getId()), (oldKey, newkey) -> oldKey));
|
|
|
|
|
|
|
|
|
|
SysDepartment departmentBean = new SysDepartment();
|
|
|
|
|
departmentBean.setOrganizeCode(organizationCode);
|
|
|
|
|
List<SysDepartment> departmentList = departmentService.findAllByBaseBean(departmentBean);
|
|
|
|
|
//部门树
|
|
|
|
|
List<SysDepartment> departmentTree = new ArrayList<>();
|
|
|
|
|
//部门id的映射
|
|
|
|
|
Map<Long, SysDepartment> parentMap = departmentList.stream().collect(Collectors.toMap(el -> el.getId(), Function.identity()));
|
|
|
|
|
//构造全部部门的部门树
|
|
|
|
|
departmentList.forEach(el -> {
|
|
|
|
|
if (!ObjectUtils.isEmpty(el.getParentId())) {
|
|
|
|
|
if (CommonEnumUtil.PARENT.DEFAULT.getValue().longValue() == el.getParentId().longValue()) {
|
|
|
|
|
departmentTree.add(el);
|
|
|
|
|
} else {
|
|
|
|
|
SysDepartment parentSys = parentMap.get(el.getParentId());
|
|
|
|
|
if (!ObjectUtils.isEmpty(parentSys)) {
|
|
|
|
|
if (null == parentSys.getChildList()) {
|
|
|
|
|
parentSys.setChildList(new ArrayList<>());
|
|
|
|
|
if (rLock.tryLock(0, TimeUnit.MINUTES)) {
|
|
|
|
|
ExcelTool excelTool = new ExcelTool(entityManager, redisRes);
|
|
|
|
|
//1.读取数据
|
|
|
|
|
List<UserInfoImportModel> importModelList = excelTool.importDataAndConver(file.getOriginalFilename(), file.getInputStream(), UserInfoImportModel.class, UserInfoImportModel.class.getSimpleName());
|
|
|
|
|
List<ResultBean> faildList = new ArrayList<>();
|
|
|
|
|
LOGGER.debug("导入用户信息: 共读取数据{}条", importModelList.size());
|
|
|
|
|
if (ObjectUtils.isEmpty(importModelList)) {
|
|
|
|
|
return ResultBean.success();
|
|
|
|
|
}
|
|
|
|
|
//2.数据格式校验并去重
|
|
|
|
|
List<UserInfoImportModel> userInfoList = validateAndDistinc(importModelList, faildList);
|
|
|
|
|
|
|
|
|
|
//3.某些数据字段转换
|
|
|
|
|
// SysPosition positionBean = new SysPosition();
|
|
|
|
|
// String organizationCode = AuthUtil.getOrganizeCode();
|
|
|
|
|
// positionBean.setOrganizeCode(organizationCode);
|
|
|
|
|
List<SysPosition> positionList = positionService.findAllByBaseBean();
|
|
|
|
|
|
|
|
|
|
Map<String, String> positionMap = positionList.stream().collect(Collectors.toMap(position -> position.getPositionCode(), position -> String.valueOf(position.getId()), (oldKey, newkey) -> oldKey));
|
|
|
|
|
|
|
|
|
|
// SysDepartment departmentBean = new SysDepartment();
|
|
|
|
|
// departmentBean.setOrganizeCode(organizationCode);
|
|
|
|
|
// List<SysDepartment> departmentList = departmentService.findAllByBaseBean(departmentBean);
|
|
|
|
|
List<SysDepartment> departmentList = departmentService.findAllByBaseBean();
|
|
|
|
|
//部门树
|
|
|
|
|
List<SysDepartment> departmentTree = new ArrayList<>();
|
|
|
|
|
//部门id的映射
|
|
|
|
|
Map<Long, SysDepartment> parentMap = departmentList.stream().collect(Collectors.toMap(el -> el.getId(), Function.identity()));
|
|
|
|
|
//构造全部部门的部门树
|
|
|
|
|
departmentList.forEach(el -> {
|
|
|
|
|
if (!ObjectUtils.isEmpty(el.getParentId())) {
|
|
|
|
|
if (CommonEnumUtil.PARENT.DEFAULT.getValue().longValue() == el.getParentId().longValue()) {
|
|
|
|
|
departmentTree.add(el);
|
|
|
|
|
} else {
|
|
|
|
|
SysDepartment parentSys = parentMap.get(el.getParentId());
|
|
|
|
|
if (!ObjectUtils.isEmpty(parentSys)) {
|
|
|
|
|
if (null == parentSys.getChildList()) {
|
|
|
|
|
parentSys.setChildList(new ArrayList<>());
|
|
|
|
|
}
|
|
|
|
|
parentSys.getChildList().add(el);
|
|
|
|
|
}
|
|
|
|
|
parentSys.getChildList().add(el);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
// SysRole roleBean = new SysRole();
|
|
|
|
|
// roleBean.setOrganizeCode(organizationCode);
|
|
|
|
|
List<SysRole> roleList = sysRoleService.findAll();
|
|
|
|
|
Map<String, String> roleMap = roleList.stream().collect(Collectors.toMap(sysRole -> sysRole.getName(), sysRole -> String.valueOf(sysRole.getId()), (oldKey, newkey) -> oldKey));
|
|
|
|
|
|
|
|
|
|
List<ResultBean> successList = new ArrayList<>();
|
|
|
|
|
//4.插入数据
|
|
|
|
|
for (int i = 0; i < userInfoList.size(); i++) {
|
|
|
|
|
UserInfoImportModel el = userInfoList.get(i);
|
|
|
|
|
ResultBean<UserDetailModel> resultBean = converImportData(el, departmentTree, positionMap, roleMap);
|
|
|
|
|
if (ObjectUtils.isEmpty(resultBean) || !resultBean.success) {
|
|
|
|
|
faildList.add(resultBean);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
resultBean = personnelController.insertUserDetailModel(resultBean.getResultObject());
|
|
|
|
|
if (ObjectUtils.isEmpty(resultBean) || !resultBean.success) {
|
|
|
|
|
faildList.add(resultBean);
|
|
|
|
|
continue;
|
|
|
|
|
List<SysRole> roleList = sysRoleService.findAll();
|
|
|
|
|
Map<String, String> roleMap = roleList.stream().collect(Collectors.toMap(sysRole -> sysRole.getName(), sysRole -> String.valueOf(sysRole.getId()), (oldKey, newkey) -> oldKey));
|
|
|
|
|
|
|
|
|
|
List<ResultBean> successList = new ArrayList<>();
|
|
|
|
|
//4.插入数据
|
|
|
|
|
for (int i = 0; i < userInfoList.size(); i++) {
|
|
|
|
|
UserInfoImportModel el = userInfoList.get(i);
|
|
|
|
|
ResultBean<UserDetailModel> resultBean = converImportData(el, departmentTree, positionMap, roleMap);
|
|
|
|
|
if (ObjectUtils.isEmpty(resultBean) || !resultBean.success) {
|
|
|
|
|
faildList.add(resultBean);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
resultBean = personnelController.insertUserDetailModel(resultBean.getResultObject());
|
|
|
|
|
if (ObjectUtils.isEmpty(resultBean) || !resultBean.success) {
|
|
|
|
|
faildList.add(resultBean);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
successList.add(resultBean);
|
|
|
|
|
}
|
|
|
|
|
successList.add(resultBean);
|
|
|
|
|
}
|
|
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
resultMap.put("total", importModelList.size());
|
|
|
|
|
resultMap.put("success", successList.size());
|
|
|
|
|
resultMap.put("fail", faildList.size());
|
|
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
resultMap.put("total", importModelList.size());
|
|
|
|
|
resultMap.put("success", successList.size());
|
|
|
|
|
resultMap.put("fail", faildList.size());
|
|
|
|
|
// resultMap.put("successList", successList);
|
|
|
|
|
resultMap.put("failList", faildList);
|
|
|
|
|
return new ResultBean().setSuccess(true).setResultMap(resultMap).build();
|
|
|
|
|
resultMap.put("failList", faildList);
|
|
|
|
|
return new ResultBean().setSuccess(true).setResultMap(resultMap).build();
|
|
|
|
|
}
|
|
|
|
|
return ResultBean.fail("当前账号有正在上传的任务进行,请等待上传完毕");
|
|
|
|
|
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
LOGGER.error("导入人员数据出错", e);
|
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
LOGGER.error("导入人员数据出错", busExcep);
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOGGER.error("导入人员数据出错", e);
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
} finally {
|
|
|
|
|
if (rLock.isHeldByCurrentThread()) {
|
|
|
|
|
rLock.unlock();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
// //1.读取数据
|
|
|
|
|
// List<UserInfoImportModel> importModelList = excelTool.importDataAndConver(file.getOriginalFilename(), file.getInputStream(), UserInfoImportModel.class, UserInfoImportModel.class.getSimpleName());
|
|
|
|
|
// List<ResultBean> faildList = new ArrayList<>();
|
|
|
|
|
// LOGGER.debug("导入用户信息: 共读取数据{}条", importModelList.size());
|
|
|
|
|
// if (ObjectUtils.isEmpty(importModelList)) {
|
|
|
|
|
// return ResultBean.success();
|
|
|
|
|
// }
|
|
|
|
|
// //2.数据格式校验并去重
|
|
|
|
|
// List<UserInfoImportModel> userInfoList = validateAndDistinc(importModelList, faildList);
|
|
|
|
|
//
|
|
|
|
|
// //3.某些数据字段转换
|
|
|
|
|
// SysPosition positionBean = new SysPosition();
|
|
|
|
|
// String organizationCode = AuthUtil.getOrganizeCode();
|
|
|
|
|
// positionBean.setOrganizeCode(organizationCode);
|
|
|
|
|
// List<SysPosition> positionList = positionService.findAllByBaseBean(positionBean);
|
|
|
|
|
//
|
|
|
|
|
// Map<String, String> positionMap = positionList.stream().collect(Collectors.toMap(position -> position.getPositionCode(), position -> String.valueOf(position.getId()), (oldKey, newkey) -> oldKey));
|
|
|
|
|
//
|
|
|
|
|
// SysDepartment departmentBean = new SysDepartment();
|
|
|
|
|
// departmentBean.setOrganizeCode(organizationCode);
|
|
|
|
|
// List<SysDepartment> departmentList = departmentService.findAllByBaseBean(departmentBean);
|
|
|
|
|
// //部门树
|
|
|
|
|
// List<SysDepartment> departmentTree = new ArrayList<>();
|
|
|
|
|
// //部门id的映射
|
|
|
|
|
// Map<Long, SysDepartment> parentMap = departmentList.stream().collect(Collectors.toMap(el -> el.getId(), Function.identity()));
|
|
|
|
|
// //构造全部部门的部门树
|
|
|
|
|
// departmentList.forEach(el -> {
|
|
|
|
|
// if (!ObjectUtils.isEmpty(el.getParentId())) {
|
|
|
|
|
// if (CommonEnumUtil.PARENT.DEFAULT.getValue().longValue() == el.getParentId().longValue()) {
|
|
|
|
|
// departmentTree.add(el);
|
|
|
|
|
// } else {
|
|
|
|
|
// SysDepartment parentSys = parentMap.get(el.getParentId());
|
|
|
|
|
// if (!ObjectUtils.isEmpty(parentSys)) {
|
|
|
|
|
// if (null == parentSys.getChildList()) {
|
|
|
|
|
// parentSys.setChildList(new ArrayList<>());
|
|
|
|
|
// }
|
|
|
|
|
// parentSys.getChildList().add(el);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
//// SysRole roleBean = new SysRole();
|
|
|
|
|
//// roleBean.setOrganizeCode(organizationCode);
|
|
|
|
|
// List<SysRole> roleList = sysRoleService.findAll();
|
|
|
|
|
// Map<String, String> roleMap = roleList.stream().collect(Collectors.toMap(sysRole -> sysRole.getName(), sysRole -> String.valueOf(sysRole.getId()), (oldKey, newkey) -> oldKey));
|
|
|
|
|
//
|
|
|
|
|
// List<ResultBean> successList = new ArrayList<>();
|
|
|
|
|
// //4.插入数据
|
|
|
|
|
// for (int i = 0; i < userInfoList.size(); i++) {
|
|
|
|
|
// UserInfoImportModel el = userInfoList.get(i);
|
|
|
|
|
// ResultBean<UserDetailModel> resultBean = converImportData(el, departmentTree, positionMap, roleMap);
|
|
|
|
|
// if (ObjectUtils.isEmpty(resultBean) || !resultBean.success) {
|
|
|
|
|
// faildList.add(resultBean);
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// resultBean = personnelController.insertUserDetailModel(resultBean.getResultObject());
|
|
|
|
|
// if (ObjectUtils.isEmpty(resultBean) || !resultBean.success) {
|
|
|
|
|
// faildList.add(resultBean);
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// successList.add(resultBean);
|
|
|
|
|
// }
|
|
|
|
|
// Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
// resultMap.put("total", importModelList.size());
|
|
|
|
|
// resultMap.put("success", successList.size());
|
|
|
|
|
// resultMap.put("fail", faildList.size());
|
|
|
|
|
//// resultMap.put("successList", successList);
|
|
|
|
|
// resultMap.put("failList", faildList);
|
|
|
|
|
// return new ResultBean().setSuccess(true).setResultMap(resultMap).build();
|
|
|
|
|
// } catch (ImppBusiException busExcep) {
|
|
|
|
|
// return ResultBean.fail(busExcep);
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/find-position-ref-user")
|
|
|
|
@ -773,6 +867,7 @@ public class SysUserInfoController extends CoreBaseController {
|
|
|
|
|
|
|
|
|
|
return ResultBean.success().setResultObject(userDetailModel).build();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
LOGGER.error("导入人员数据转换出错", e);
|
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
|
}
|
|
|
|
|