dev:人员导入
parent
b0fdf323b3
commit
af9b0f4b52
|
|
@ -1,6 +1,7 @@
|
|||
package com.zcloud.basic.info.command;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.cola.exception.BizException;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.jjb.saas.config.client.dicttree.facade.ConfDictTreeFacade;
|
||||
|
|
@ -35,7 +36,10 @@ import org.springframework.util.ObjectUtils;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -123,30 +127,26 @@ public class UserAddExe {
|
|||
UserE userE = new UserE();
|
||||
Long corpinfoId = AuthContext.getTenantId();
|
||||
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
queryWrapper.eq("corpinfo_id", corpinfoId);
|
||||
queryWrapper.eq("delete_enum", "FALSE");
|
||||
|
||||
// 部门数据
|
||||
List<DepartmentDO> departmentDOList = departmentRepository.list(queryWrapper);
|
||||
List<DepartmentE> departmentEList = BeanUtil.copyToList(departmentDOList, DepartmentE.class);
|
||||
List<DepartmentDO> departmentDOList = departmentRepository.listByCorpInfoId(corpinfoId);
|
||||
// 岗位数据
|
||||
List<PostDO> postDOList = postRepository.list(queryWrapper);
|
||||
List<PostE> postEList = BeanUtil.copyToList(postDOList, PostE.class);
|
||||
queryWrapper.clear();
|
||||
List<PostDO> postDOList = postRepository.listByCorpInfoId(corpinfoId);
|
||||
// 用户名数据
|
||||
queryWrapper.eq("delete_enum", "FALSE");
|
||||
List<UserDO> userDOList = userRepository.list(queryWrapper);
|
||||
List<UserE> userEList = BeanUtil.copyToList(userDOList, UserE.class);
|
||||
List<UserDO> userDOList = userRepository.listByCorpInfoId(corpinfoId);
|
||||
// 企业端-人员类型字典
|
||||
List<ConfDictTreeCO> confDictCOList = confDictTreeFacade.listByAppKeyAndParentIdTree("0bb989ecada5470c87635018ece9f327", 1986379731994513408L);
|
||||
// if(CollectionUtil)
|
||||
Map<String, String> dictMap = new HashMap<>();
|
||||
if(CollectionUtil.isNotEmpty(confDictCOList)){
|
||||
dictMap = confDictCOList.stream().collect(Collectors.toMap(ConfDictTreeCO::getDictLabel, ConfDictTreeCO::getDictValue));
|
||||
}
|
||||
|
||||
|
||||
List<UserExcelImportEntity> userExcelImportEntityList = userE.parseImportTemplateData(file);
|
||||
List<UserDO> userDOS = userCoConvertor.converExcelEntitysToDOs(userExcelImportEntityList);
|
||||
List<UserE> userEList = userE.parseImportTemplateData(file,
|
||||
BeanUtil.copyToList(departmentDOList, DepartmentE.class),
|
||||
BeanUtil.copyToList(postDOList, PostE.class),
|
||||
BeanUtil.copyToList(userDOList, UserE.class),
|
||||
dictMap);
|
||||
// todo 批量插入用户
|
||||
|
||||
System.out.println(userEList);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import javax.validation.constraints.*;
|
|||
@AllArgsConstructor
|
||||
public class PostAddCmd extends Command {
|
||||
@ApiModelProperty(value = "部门id", name = "departmentId", required = true)
|
||||
@NotEmpty(message = "部门id不能为空")
|
||||
@NotNull(message = "部门id不能为空")
|
||||
private Long departmentId;
|
||||
|
||||
@ApiModelProperty(value = "岗位名称", name = "postName", required = true)
|
||||
|
|
@ -33,11 +33,9 @@ public class PostAddCmd extends Command {
|
|||
private String remarks;
|
||||
|
||||
@ApiModelProperty(value = "企业id", name = "corpinfoId", required = true)
|
||||
@NotEmpty(message = "企业id不能为空")
|
||||
private Long corpinfoId;
|
||||
|
||||
@ApiModelProperty(value = "企业名称", name = "corpinfoName", required = true)
|
||||
@NotEmpty(message = "企业名称不能为空")
|
||||
private String corpinfoName;
|
||||
|
||||
// @ApiModelProperty(value = "是否监管岗位 0-否, 1-是", name = "supervisionFlag")
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class PostListQry {
|
|||
private Long[] postIds;
|
||||
|
||||
@ApiModelProperty(value = "部门id", name = "departmentId", required = true)
|
||||
@NotEmpty(message = "部门id不能为空")
|
||||
@NotNull(message = "部门id不能为空")
|
||||
// 部门id
|
||||
private Long departmentId;
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public class PostPageQry extends PageQuery {
|
|||
private Integer corpFlag;
|
||||
|
||||
@ApiModelProperty(value = "部门id", name = "eqDepartmentId", required = true)
|
||||
@NotEmpty(message = "部门id不能为空")
|
||||
@NotNull(message = "部门id不能为空")
|
||||
// 部门id
|
||||
private Long eqDepartmentId;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import javax.validation.constraints.*;
|
|||
public class PostRemoveCmd extends Command {
|
||||
|
||||
@ApiModelProperty(value = "主键", name = "ids", required = true)
|
||||
@NotEmpty(message = "主键不能为空")
|
||||
@NotNull(message = "主键不能为空")
|
||||
private Long[] ids;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ import javax.validation.constraints.*;
|
|||
@AllArgsConstructor
|
||||
public class PostUpdateCmd extends Command {
|
||||
@ApiModelProperty(value = "主键", name = "id", required = true)
|
||||
@NotEmpty(message = "主键不能为空")
|
||||
@NotNull(message = "主键不能为空")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "部门id", name = "departmentId", required = true)
|
||||
@NotEmpty(message = "部门id不能为空")
|
||||
@NotNull(message = "部门id不能为空")
|
||||
private Long departmentId;
|
||||
|
||||
@ApiModelProperty(value = "岗位名称", name = "postName", required = true)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class UserQualificationInfoAddCmd extends Command {
|
|||
private Long corpinfoId;
|
||||
|
||||
@ApiModelProperty(value = "用户id", name = "userId", required = true)
|
||||
@NotEmpty(message = "用户id不能为空")
|
||||
@NotNull(message = "用户id不能为空")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "资质名称", name = "qualificationName", required = true)
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@ public class UserQualificationInfoPageQry extends PageQuery {
|
|||
* - `le`: 小于等于比较查询
|
||||
* - `ne`: 不等比较查询,对应SQL的!=操作符
|
||||
*/
|
||||
@ApiModelProperty(value = "企业id", name = "eqCorpinfoId", required = true)
|
||||
@NotEmpty(message = "企业id不能为空")
|
||||
@ApiModelProperty(value = "企业id", name = "eqCorpinfoId")
|
||||
private Long eqCorpinfoId;
|
||||
|
||||
@ApiModelProperty(value = "用户id", name = "eqUserId")
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class UserQualificationInfoUpdateCmd extends Command {
|
|||
private String userQualificationinfoId;
|
||||
|
||||
@ApiModelProperty(value = "用户id", name = "userId", required = true)
|
||||
@NotEmpty(message = "用户id不能为空")
|
||||
@NotNull(message = "用户id不能为空")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "资质名称", name = "qualificationName", required = true)
|
||||
|
|
|
|||
|
|
@ -11,13 +11,17 @@ import com.zcloud.gbscommon.utils.ExcelUtils;
|
|||
import com.zcloud.gbscommon.utils.Tools;
|
||||
import com.zcloud.gbscommon.utils.UuidUtil;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* web-domain
|
||||
|
|
@ -178,7 +182,11 @@ public class UserE extends BaseE {
|
|||
}
|
||||
|
||||
// 导入
|
||||
public List<UserExcelImportEntity> parseImportTemplateData(MultipartFile file){
|
||||
public List<UserE> parseImportTemplateData(MultipartFile file,
|
||||
List<DepartmentE> departmentList,
|
||||
List<PostE> postList,
|
||||
List<UserE> userList,
|
||||
Map<String, String> dictMap) {
|
||||
List<UserExcelImportEntity> list = new ArrayList<>();
|
||||
try {
|
||||
ExcelUtils.readBatch(file, UserExcelImportEntity.class, list);
|
||||
|
|
@ -188,12 +196,122 @@ public class UserE extends BaseE {
|
|||
} catch (Exception e) {
|
||||
throw new BizException("文件解析失败");
|
||||
}
|
||||
// todo 校验
|
||||
|
||||
if(CollUtil.isEmpty(departmentList)){
|
||||
throw new BizException("该企业暂未存在部门信息,请添加部门后重新导入");
|
||||
}
|
||||
if(CollUtil.isEmpty(postList)){
|
||||
throw new BizException("该企业暂未存在岗位信息,请添加岗位后重新导入");
|
||||
}
|
||||
Map<String, DepartmentE> departmentEMap = departmentList.stream().collect(Collectors.toMap(DepartmentE::getName, DepartmentE -> DepartmentE));
|
||||
|
||||
|
||||
Map<String, UserE> userEMap = new HashMap<>();
|
||||
if(CollUtil.isNotEmpty(userList)){
|
||||
userEMap = userList.stream().collect(Collectors.toMap(UserE::getUsername, UserE -> UserE));
|
||||
}
|
||||
|
||||
Map<String, String> usernameMap = new HashMap<>();
|
||||
|
||||
|
||||
// 错误消息集合
|
||||
List<String> errList = new ArrayList<>();
|
||||
// 校验
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
UserExcelImportEntity entity = list.get(i);
|
||||
if(entity == null){
|
||||
errList.add("第" + (i+2) + "行数据不能为空。");
|
||||
continue;
|
||||
}
|
||||
if(StringUtils.isEmpty(entity.getRoleName())){
|
||||
errList.add("第" + (i+2) + "行用户角色不能为空。");
|
||||
}
|
||||
if(StringUtils.isEmpty(entity.getDepartmentName())){
|
||||
errList.add("第" + (i+2) + "行所属部门不能为空。");
|
||||
}else {
|
||||
if(departmentEMap.get(entity.getDepartmentName()) == null){
|
||||
errList.add("第" + (i+2) + "行所属部门不存在。");
|
||||
}
|
||||
}
|
||||
// 岗位
|
||||
if(StringUtils.isEmpty(entity.getPostName())){
|
||||
errList.add("第" + (i+2) + "行所属岗位不能为空。");
|
||||
}else{
|
||||
DepartmentE departmentE = departmentEMap.get(entity.getDepartmentName());
|
||||
if(departmentE != null){
|
||||
List<PostE> postListByDepartId = postList.stream().filter(post -> post.getDepartmentId().equals(departmentE.getId())).collect(Collectors.toList());
|
||||
if(CollUtil.isEmpty(postListByDepartId)){
|
||||
errList.add("第" + (i+2) + "行所属部门下不存在岗位信息。");
|
||||
}else {
|
||||
Map<String, PostE> postEMap = postListByDepartId.stream().collect(Collectors.toMap(PostE::getPostName, PostE -> PostE));
|
||||
if(postEMap.get(entity.getPostName()) == null){
|
||||
errList.add("第" + (i+2) + "行所属岗位信息与所属部门信息不匹配。");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 用户名
|
||||
if(StringUtils.isEmpty(entity.getUsername())){
|
||||
errList.add("第" + (i+2) + "行用户名不能为空。");
|
||||
}else {
|
||||
if(CollUtil.isNotEmpty(userEMap)){
|
||||
if(userEMap.get(entity.getUsername()) != null){
|
||||
errList.add("第" + (i+2) + "行用户名重复。");
|
||||
}
|
||||
}
|
||||
if(usernameMap.get(entity.getUsername()) != null){
|
||||
errList.add("第" + (i+2) + "行用户名重复。");
|
||||
}else {
|
||||
usernameMap.put(entity.getUsername(), entity.getUsername());
|
||||
}
|
||||
}
|
||||
if(StringUtils.isEmpty(entity.getName())){
|
||||
errList.add("第" + (i+2) + "行姓名不能为空。");
|
||||
}
|
||||
if(StringUtils.isEmpty(entity.getPersonnelTypeName())){
|
||||
errList.add("第" + (i+2) + "行人员类型不能为空。");
|
||||
}else {
|
||||
if(StringUtils.isEmpty(dictMap.get(entity.getPersonnelTypeName()))){
|
||||
errList.add("第" + (i+2) + "行人员类型与系统不匹配。");
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
||||
if(CollUtil.isNotEmpty(errList)){
|
||||
throw new BizException("导入信息有误,请检查后重新导入。", String.join("", errList));
|
||||
}
|
||||
|
||||
// 映射
|
||||
List<UserE> userEList = new ArrayList<>();
|
||||
for (int i = 0; i < list.size(); i++){
|
||||
UserExcelImportEntity entity = list.get(i);
|
||||
UserE userE = new UserE();
|
||||
|
||||
// 部门
|
||||
Long departmentId = departmentEMap.get(entity.getDepartmentName()).getId();
|
||||
userE.setDepartmentId(departmentId);
|
||||
userE.setDepartmentName(entity.getDepartmentName());
|
||||
|
||||
// 岗位
|
||||
List<PostE> postListByDepartId = postList.stream().filter(post -> post.getDepartmentId().equals(departmentId)).collect(Collectors.toList());
|
||||
Map<String, PostE> postEMap = postListByDepartId.stream().collect(Collectors.toMap(PostE::getPostName, PostE -> PostE));
|
||||
userE.setPostId(postEMap.get(entity.getPostName()).getId());
|
||||
userE.setPostName(entity.getPostName());
|
||||
|
||||
// 用户名
|
||||
userE.setUsername(entity.getUsername());
|
||||
// 姓名
|
||||
userE.setName(entity.getName());
|
||||
|
||||
// 人员类型
|
||||
userE.setPersonnelType(dictMap.get(entity.getPersonnelTypeName()));
|
||||
userE.setPersonnelTypeName(entity.getPersonnelTypeName());
|
||||
|
||||
userEList.add(userE);
|
||||
}
|
||||
|
||||
return userEList;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.zcloud.basic.info.gatewayimpl;
|
|||
|
||||
import com.alibaba.cola.exception.BizException;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.jjb.saas.secure.context.AuthContext;
|
||||
import com.zcloud.basic.info.domain.gateway.PostGateway;
|
||||
import com.zcloud.basic.info.domain.model.PostE;
|
||||
import com.zcloud.basic.info.persistence.dataobject.PostDO;
|
||||
|
|
@ -43,6 +44,12 @@ public class PostGatewayImpl implements PostGateway {
|
|||
if(StringUtils.isEmpty(d.getPostId())){
|
||||
d.setPostId(UuidUtil.get32UUID());
|
||||
}
|
||||
if(d.getCorpinfoId() == null){
|
||||
d.setCorpinfoId(AuthContext.getTenantId());
|
||||
}
|
||||
if(StringUtils.isEmpty(d.getCorpinfoName())){
|
||||
d.setCorpinfoName(AuthContext.getName());
|
||||
}
|
||||
// if(d.getSupervisionFlag() == null){
|
||||
// d.setSupervisionFlag(0);
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -25,5 +25,7 @@ public interface DepartmentRepository extends BaseRepository<DepartmentDO> {
|
|||
|
||||
Long getCountByCorpInfoId(Long id);
|
||||
|
||||
List<DepartmentDO> listByCorpInfoId(Long corpInfoId);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.alibaba.cola.dto.SingleResponse;
|
|||
import com.alibaba.cola.dto.PageResponse;
|
||||
import com.jjb.saas.framework.repository.repo.BaseRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -23,5 +24,7 @@ public interface PostRepository extends BaseRepository<PostDO> {
|
|||
SingleResponse<PostDO> getInfoById(Long id);
|
||||
|
||||
Long getCountByCorpInfoId(Long id);
|
||||
|
||||
List<PostDO> listByCorpInfoId(Long corpInfoId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,5 +30,7 @@ public interface UserRepository extends BaseRepository<UserDO> {
|
|||
List<UserDO> listByPostId(Long postId);
|
||||
List<UserDO> listByPostIds(Long[] postIds);
|
||||
|
||||
List<UserDO> listByCorpInfoId(Long corpInfoId);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,5 +78,13 @@ public class DepartmentRepositoryImpl extends BaseRepositoryImpl<DepartmentMappe
|
|||
queryWrapper.eq("corpinfo_id", id);
|
||||
return departmentMapper.selectCount(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DepartmentDO> listByCorpInfoId(Long corpInfoId) {
|
||||
QueryWrapper<DepartmentDO> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("corpinfo_id", corpInfoId);
|
||||
queryWrapper.eq("delete_enum", "FALSE");
|
||||
return list(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
|
|||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -71,5 +72,13 @@ public class PostRepositoryImpl extends BaseRepositoryImpl<PostMapper, PostDO> i
|
|||
queryWrapper.eq("corpinfo_id", id);
|
||||
return postMapper.selectCount(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PostDO> listByCorpInfoId(Long corpInfoId) {
|
||||
QueryWrapper<PostDO> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("corpinfo_id", corpInfoId);
|
||||
queryWrapper.eq("delete_enum", "FALSE");
|
||||
return list(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.alibaba.cola.dto.MultiResponse;
|
|||
import com.alibaba.cola.dto.SingleResponse;
|
||||
import com.alibaba.cola.exception.BizException;
|
||||
import com.jjb.saas.framework.repository.common.PageHelper;
|
||||
import com.jjb.saas.secure.context.AuthContext;
|
||||
import com.zcloud.basic.info.persistence.dataobject.UserQualificationInfoDO;
|
||||
import com.zcloud.basic.info.persistence.mapper.UserQualificationInfoMapper;
|
||||
import com.zcloud.basic.info.persistence.repository.UserQualificationInfoRepository;
|
||||
|
|
@ -33,6 +34,9 @@ public class UserQualificationInfoRepositoryImpl extends BaseRepositoryImpl<User
|
|||
|
||||
@Override
|
||||
public PageResponse<UserQualificationInfoDO> listPage(Map<String,Object> params) {
|
||||
if(params.get("eqCorpinfoId") == null){
|
||||
params.put("eqCorpinfoId", AuthContext.getTenantId());
|
||||
}
|
||||
IPage<UserQualificationInfoDO> iPage = new Query<UserQualificationInfoDO>().getPage(params);
|
||||
QueryWrapper<UserQualificationInfoDO> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params, "a.");
|
||||
|
|
@ -44,6 +48,9 @@ public class UserQualificationInfoRepositoryImpl extends BaseRepositoryImpl<User
|
|||
|
||||
@Override
|
||||
public MultiResponse<UserQualificationInfoDO> list(Map<String, Object> params) {
|
||||
if(params.get("eqCorpinfoId") == null){
|
||||
params.put("eqCorpinfoId", AuthContext.getTenantId());
|
||||
}
|
||||
QueryWrapper<UserQualificationInfoDO> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
|
||||
queryWrapper.orderByDesc("create_time");
|
||||
|
|
|
|||
|
|
@ -109,5 +109,13 @@ public class UserRepositoryImpl extends BaseRepositoryImpl<UserMapper, UserDO> i
|
|||
List<UserDO> userPostList = this.list(queryWrapper);
|
||||
return userPostList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserDO> listByCorpInfoId(Long corpInfoId) {
|
||||
QueryWrapper<UserDO> queryWrapper = new QueryWrapper();
|
||||
queryWrapper.eq("corpinfo_id", corpInfoId);
|
||||
queryWrapper.eq("delete_enum", "FALSE");
|
||||
return list(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue