相关人员bug修改

This commit is contained in:
xiejunyu
2022-06-10 17:09:01 +08:00
parent db4d3c259a
commit 820006fe18
@@ -3,6 +3,7 @@ package com.jero.modules.project.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.jero.common.api.vo.Result;
import com.jero.common.constant.CommonConstant;
import com.jero.common.constant.enums.CutEnum;
@@ -28,7 +29,10 @@ import com.jero.modules.system.service.ISysUserService;
import com.jero.modules.system.util.StringUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
@@ -742,7 +746,27 @@ public class ProjectRelatedPersonnelServiceImpl extends ServiceImpl<ProjectRelat
List<ProjectRelatedPersonnel> list = new ArrayList<>();
if (workbook != null) {
Sheet sheet = workbook.getSheetAt(0);
deleteBlankRow(sheet);
if (sheet != null) {
if(sheet.getPhysicalNumberOfRows()==0){
if (CutEnum.CN.getValue().equals(cut)) {
throw new JeroBootException("导入的内容为空,请按照模板格式填写内容");
} else {
throw new JeroBootException("The imported content is empty. Please fill in the content according to the template format.");
}
}else if(sheet.getPhysicalNumberOfRows()<2){
if (CutEnum.CN.getValue().equals(cut)) {
throw new JeroBootException("导入的表头有误,请按照模板格式填写内容");
} else {
throw new JeroBootException("The number of imported columns is wrong. Please fill in the contents according to the template format.");
}
}else if(sheet.getPhysicalNumberOfRows()==2){
if (CutEnum.CN.getValue().equals(cut)) {
throw new JeroBootException("导入的数据为空,请按照模板格式填写内容");
} else {
throw new JeroBootException("The number of imported columns is wrong. Please fill in the contents according to the template format.");
}
}
int rowNos = sheet.getPhysicalNumberOfRows();// 得到excel的总记录条数
for (int i = 0; i < rowNos ; i++) {
@@ -765,18 +789,6 @@ public class ProjectRelatedPersonnelServiceImpl extends ServiceImpl<ProjectRelat
}
}
}
}/*else if(i!=1 && columHeadNos != 5) {
if (CutEnum.CN.getValue().equals(cut)) {
throw new JeroBootException("导入的列数不对,请按照模板格式填写内容");
} else {
throw new JeroBootException("The number of imported columns is wrong. Please fill in the contents according to the template format.");
}
}*/
}else{
if (CutEnum.CN.getValue().equals(cut)) {
throw new JeroBootException("导入的数据不能为空,请检查");
} else {
throw new JeroBootException("The imported data of cannot be empty. Please check!");
}
}
if (i == 1) {//校验填写说明
@@ -860,7 +872,44 @@ public class ProjectRelatedPersonnelServiceImpl extends ServiceImpl<ProjectRelat
Result<?> result = oppositeDisposeData(list, projectId, cut);
return result;
}
public void deleteBlankRow(Sheet sheet){
//获取到excel行数
int num = sheet.getLastRowNum();
//删除的空行(包含空白行和带有格式的空行)
int bk = 0;
//记录空白行的集合
List<Integer> nums = Lists.newArrayList();
for (int i = 1; i <= num; i++) {
Row row = sheet.getRow(i);
boolean flag = false;
//带有格式的空白行
if (row != null) {
for (Cell cell : row) {
//判断该单元格是否为空
if (StringUtils.isEmpty(cell.toString())) {
flag = true;
break;
}
}
if (flag) {
nums.add(i);
bk++;
}
//空白行
} else {
nums.add(i);
bk++;
}
}
//删除无效数据行(空白行,带格式的空白行)
for (Integer n : nums) {
if (sheet.getRow(n) != null) {
sheet.removeRow(sheet.getRow(n));
}
}
}
/**
* 把导入的数据翻译成对应的id,校验,不存
* 若除责任领域外的导入数据不能为空
@@ -988,6 +1037,23 @@ public class ProjectRelatedPersonnelServiceImpl extends ServiceImpl<ProjectRelat
List<SysUser> certificationEngineerUsers = new ArrayList<>();
if (StringUtils.isNotBlank(projectRelatedPersonnel.getCertificationEngineerName())){
List<String> certificationEngineerNameList = Arrays.asList(projectRelatedPersonnel.getCertificationEngineerName().split(","));
//校验是否为项目基础表设定的认证工程师
List<ProjectRelatedPersonnel> baseCertificationEngineerList = queryCertificationEngineer(projectId);
List<String> baseCertificationEngineerNameList = baseCertificationEngineerList.stream().map(e -> e.getCertificationEngineerName()).collect(Collectors.toList());
for(String certificationEngineerName : certificationEngineerNameList){
if(!baseCertificationEngineerNameList.contains(certificationEngineerName)){
//中英切换提示语
if(CutEnum.CN.getValue().equals(cut)) {
message.append("导入的认证工程师姓名不属于该项目,请检查第" + row + "");
}else {
message.append("The imported certified engineer name does not belong to this project..Please check line " + row );
}
break;
}
}
if (CollectionUtils.isNotEmpty(certificationEngineerNameList) && StringUtils.isNotBlank(certificationEngineerNameList.get(0))) {
certificationEngineerNameList = certificationEngineerNameList.stream().distinct().collect(Collectors.toList());
certificationEngineerUsers=sysUserService.queryUserIdListByNameList(certificationEngineerNameList);
@@ -1014,6 +1080,7 @@ public class ProjectRelatedPersonnelServiceImpl extends ServiceImpl<ProjectRelat
}
projectRelatedPersonnel.setCertificationEngineer(midId.substring(0,midId.toString().length()-1));
}
}else{
projectRelatedPersonnel.setCertificationEngineer("");
}