fix bug 组织机构导入bug
This commit is contained in:
+22
-7
@@ -13,6 +13,7 @@ import com.jero.common.exception.JeroBootException;
|
|||||||
import com.jero.common.system.vo.SysDepartTreeModel;
|
import com.jero.common.system.vo.SysDepartTreeModel;
|
||||||
import com.jero.common.util.ValidUtil;
|
import com.jero.common.util.ValidUtil;
|
||||||
import com.jero.modules.system.model.SysDepartExcel;
|
import com.jero.modules.system.model.SysDepartExcel;
|
||||||
|
import com.jero.modules.system.model.SysDepartImportExcel;
|
||||||
import com.jero.modules.system.util.FindsDepartsChildrenUtil;
|
import com.jero.modules.system.util.FindsDepartsChildrenUtil;
|
||||||
import io.swagger.models.auth.In;
|
import io.swagger.models.auth.In;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
@@ -390,7 +391,7 @@ public class SysDepartController {
|
|||||||
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
|
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
|
||||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) throws IOException{
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) throws IOException{
|
||||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||||
List<SysDepartExcel> listSysDeparts = null;
|
List<SysDepartImportExcel> listSysDeparts = null;
|
||||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||||
@@ -403,7 +404,7 @@ public class SysDepartController {
|
|||||||
params.setHeadRows(1);
|
params.setHeadRows(1);
|
||||||
params.setNeedSave(true);
|
params.setNeedSave(true);
|
||||||
//导入Excel格式校验,看匹配的字段文本概率
|
//导入Excel格式校验,看匹配的字段文本概率
|
||||||
Boolean t = ExcelImportCheckUtil.check(file.getInputStream(), SysDepartExcel.class, params,1.0);
|
Boolean t = ExcelImportCheckUtil.check(file.getInputStream(), SysDepartImportExcel.class, params,1.0);
|
||||||
if (t == null){
|
if (t == null){
|
||||||
return Result.error("文件导入失败: 导入数据为空");
|
return Result.error("文件导入失败: 导入数据为空");
|
||||||
}
|
}
|
||||||
@@ -413,33 +414,47 @@ public class SysDepartController {
|
|||||||
try {
|
try {
|
||||||
// orgCode编码长度
|
// orgCode编码长度
|
||||||
int codeLength = YouBianCodeUtil.zhanweiLength;
|
int codeLength = YouBianCodeUtil.zhanweiLength;
|
||||||
listSysDeparts = ExcelImportUtil.importExcel(file.getInputStream(), SysDepartExcel.class, params);
|
listSysDeparts = ExcelImportUtil.importExcel(file.getInputStream(), SysDepartImportExcel.class, params);
|
||||||
listSysDeparts = listSysDeparts.stream().filter(i -> !oConvertUtils.checkObjAllFieldsIsNull(i)).collect(Collectors.toList());
|
listSysDeparts = listSysDeparts.stream().filter(i -> !oConvertUtils.checkObjAllFieldsIsNull(i)).collect(Collectors.toList());
|
||||||
if (CollectionUtils.isEmpty(listSysDeparts)){
|
if (CollectionUtils.isEmpty(listSysDeparts)){
|
||||||
return Result.error("文件导入失败: 导入数据为空");
|
return Result.error("文件导入失败: 导入数据为空");
|
||||||
}
|
}
|
||||||
//按长度排序
|
//按长度排序
|
||||||
Collections.sort(listSysDeparts, new Comparator<SysDepartExcel>() {
|
Collections.sort(listSysDeparts, new Comparator<SysDepartImportExcel>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(SysDepartExcel arg0, SysDepartExcel arg1) {
|
public int compare(SysDepartImportExcel arg0, SysDepartImportExcel arg1) {
|
||||||
return arg0.getOrgCode().length() - arg1.getOrgCode().length();
|
return arg0.getOrgCode().length() - arg1.getOrgCode().length();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
List<String> errorMessage = new ArrayList<>();
|
List<String> errorMessage = new ArrayList<>();
|
||||||
int num = 0;
|
int num = 0;
|
||||||
for (SysDepartExcel sysDepart : listSysDeparts) {
|
for (SysDepartImportExcel sysDepart : listSysDeparts) {
|
||||||
int lineNumber = num +1;
|
int lineNumber = num +1;
|
||||||
List<String> errorList = ValidUtil.validateReturnList(sysDepart);
|
List<String> errorList = ValidUtil.validateReturnList(sysDepart);
|
||||||
if (!errorList.isEmpty()){
|
if (!errorList.isEmpty()){
|
||||||
errorMessage.add("第 " + lineNumber + " 行:"+ StringUtils.join(errorList,","));
|
errorMessage.add("第 " + lineNumber + " 行:"+ StringUtils.join(errorList,","));
|
||||||
}
|
}
|
||||||
|
String parentId = sysDepart.getParentId();
|
||||||
|
|
||||||
if (errorMessage.isEmpty()){
|
if (errorMessage.isEmpty()){
|
||||||
String orgCode = sysDepart.getOrgCode();
|
String orgCode = sysDepart.getOrgCode();
|
||||||
|
|
||||||
if(orgCode.length() > codeLength) {
|
if(orgCode.length() > codeLength) {
|
||||||
String parentCode = orgCode.substring(0, orgCode.length()-codeLength);
|
String parentCode = orgCode.substring(0, orgCode.length()-codeLength);
|
||||||
QueryWrapper<SysDepart> queryWrapper = new QueryWrapper<SysDepart>();
|
QueryWrapper<SysDepart> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("org_code", parentCode);
|
queryWrapper.eq("org_code", parentCode);
|
||||||
SysDepart parentDept = sysDepartService.getOne(queryWrapper);
|
SysDepart parentDept = sysDepartService.getOne(queryWrapper);
|
||||||
|
if (StringUtils.isNotBlank(parentId)){
|
||||||
|
QueryWrapper<SysDepart> queryWrapper1 = new QueryWrapper<>();
|
||||||
|
queryWrapper1.eq("depart_name", parentId);
|
||||||
|
SysDepart parentDept1 = sysDepartService.getOne(queryWrapper1);
|
||||||
|
if(parentDept1 == null) {
|
||||||
|
errorMessage.add("第 " + lineNumber + " 行:上级部门不存在");
|
||||||
|
}
|
||||||
|
if (!Objects.equals(parentDept,parentDept1)){
|
||||||
|
errorMessage.add("第 " + lineNumber + " 行:上级部门与机构编码不匹配");
|
||||||
|
}
|
||||||
|
}
|
||||||
if(parentDept != null) {
|
if(parentDept != null) {
|
||||||
sysDepart.setParentId(parentDept.getId());
|
sysDepart.setParentId(parentDept.getId());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
@@ -35,6 +35,7 @@ public class SysDepartExcel {
|
|||||||
/**机构编码*/
|
/**机构编码*/
|
||||||
@Excel(name="机构编码",width=15,orderNum = "2")
|
@Excel(name="机构编码",width=15,orderNum = "2")
|
||||||
@NotBlank(message = "机构编码不能为空")
|
@NotBlank(message = "机构编码不能为空")
|
||||||
|
@Size(max = 50,message = "机构编码最长为50字符")
|
||||||
private String orgCode;
|
private String orgCode;
|
||||||
/**手机号*/
|
/**手机号*/
|
||||||
@Excel(name="手机号",width=15,orderNum = "5")
|
@Excel(name="手机号",width=15,orderNum = "5")
|
||||||
|
|||||||
+61
@@ -0,0 +1,61 @@
|
|||||||
|
package com.jero.modules.system.model;
|
||||||
|
|
||||||
|
import com.jero.common.aspect.annotation.Dict;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||||
|
|
||||||
|
import javax.validation.constraints.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author liJiaRao
|
||||||
|
* @date 2021-11-01 19:28
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SysDepartImportExcel {
|
||||||
|
/**父机构ID*/
|
||||||
|
@Excel(name="上级部门",width=15,orderNum = "1")
|
||||||
|
@Size(max = 50,message = "上级部门最长为50字符")
|
||||||
|
private String parentId;
|
||||||
|
/**机构/部门名称*/
|
||||||
|
@Excel(name="机构名称",width=15)
|
||||||
|
@NotBlank(message = "机构名称不能为空")
|
||||||
|
@Size(max = 50,message = "机构名称最长为50字符")
|
||||||
|
private String departName;
|
||||||
|
/**排序*/
|
||||||
|
@Excel(name="排序",width=15,orderNum = "4")
|
||||||
|
@Min(value = 1,message = "排序最小为1")
|
||||||
|
@Max(value = 99999,message = "排序最大为99999")
|
||||||
|
@Pattern(regexp = "^[1-9]{0,5}(\\.[0-9]{1,2})?$",message = "排序格式错误")
|
||||||
|
private String departOrder;
|
||||||
|
/**描述*/
|
||||||
|
private String description;
|
||||||
|
/**机构类别 1公司,2组织机构,2岗位*/
|
||||||
|
private String orgCategory;
|
||||||
|
|
||||||
|
/**机构编码*/
|
||||||
|
@Excel(name="机构编码",width=15,orderNum = "2")
|
||||||
|
@NotBlank(message = "机构编码不能为空")
|
||||||
|
@Size(max = 50,message = "机构编码最长为50字符")
|
||||||
|
private String orgCode;
|
||||||
|
/**手机号*/
|
||||||
|
@Excel(name="手机号",width=15,orderNum = "5")
|
||||||
|
@Pattern(regexp = "^((13[0-9])|(14[579])|(15([0-3]|[5-9]))|(17[0135678])|(18[0-9])|(19[8|9])|(16[6]))\\d{8}$",message = "手机号格式错误")
|
||||||
|
private String mobile;
|
||||||
|
/**传真*/
|
||||||
|
private String fax;
|
||||||
|
/**地址*/
|
||||||
|
@Excel(name="地址",width=15,orderNum = "6")
|
||||||
|
@Size(max = 50,message = "地址最长为50字符")
|
||||||
|
private String address;
|
||||||
|
/**备注*/
|
||||||
|
@Excel(name="备注",width=15,orderNum = "7")
|
||||||
|
@Size(max = 200,message = "备注最长为200字符")
|
||||||
|
private String memo;
|
||||||
|
|
||||||
|
/**机构类型*/
|
||||||
|
private String orgType;
|
||||||
|
|
||||||
|
/**删除状态(0,正常,1已删除)*/
|
||||||
|
@Dict(dicCode = "del_flag")
|
||||||
|
private String delFlag;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user