bug: 导入文件功能输入限制
This commit is contained in:
+6
-7
@@ -329,14 +329,14 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
|
|||||||
if (CellType.NUMERIC == cell.getCellType() && HSSFDateUtil.isCellDateFormatted(cell)) {
|
if (CellType.NUMERIC == cell.getCellType() && HSSFDateUtil.isCellDateFormatted(cell)) {
|
||||||
Date d = cell.getDateCellValue();
|
Date d = cell.getDateCellValue();
|
||||||
if (d.before(sdf.parse("1900-01-01")) || d.after(sdf.parse("2500-01-01"))) {
|
if (d.before(sdf.parse("1900-01-01")) || d.after(sdf.parse("2500-01-01"))) {
|
||||||
return Result.error("输入的日期异常,请按照实际日期填写");
|
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入的日期异常,请按照实际日期填写");
|
||||||
}
|
}
|
||||||
// 将单元格数据存入Map中
|
// 将单元格数据存入Map中
|
||||||
rowMap.put(headerCell.getStringCellValue(), sdf.format(d));
|
rowMap.put(headerCell.getStringCellValue(), sdf.format(d));
|
||||||
} else {
|
} else {
|
||||||
cell.setCellType(CellType.STRING);
|
cell.setCellType(CellType.STRING);
|
||||||
if (cell.getStringCellValue().length() > 500) {
|
if (cell.getStringCellValue().length() > 500) {
|
||||||
return Result.error("单元格输入过长");
|
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入过长");
|
||||||
}
|
}
|
||||||
rowMap.put(headerCell.getStringCellValue(), cell.getStringCellValue());
|
rowMap.put(headerCell.getStringCellValue(), cell.getStringCellValue());
|
||||||
}
|
}
|
||||||
@@ -346,6 +346,9 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
|
|||||||
}
|
}
|
||||||
importDataList.add(rowMap);
|
importDataList.add(rowMap);
|
||||||
}
|
}
|
||||||
|
if (importDataList.size() < 1) {
|
||||||
|
return Result.error("您输入的数据为空");
|
||||||
|
}
|
||||||
|
|
||||||
// 获取需要校验的字段
|
// 获取需要校验的字段
|
||||||
List<TsDicType> firstMeetingTypeList = dicTypeService.selectAllDicTypeNameByDicCode("firstMeetingType");
|
List<TsDicType> firstMeetingTypeList = dicTypeService.selectAllDicTypeNameByDicCode("firstMeetingType");
|
||||||
@@ -373,11 +376,7 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
|
|||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
insideOutsideMeeting.setMeetingName(meetingName);
|
insideOutsideMeeting.setMeetingName(meetingName);
|
||||||
if (StringUtils.isNotBlank(dataMap.get("课题名称"))) {
|
insideOutsideMeeting.setTopicName(dataMap.get("课题名称"));
|
||||||
insideOutsideMeeting.setTopicName(dataMap.get("课题名称"));
|
|
||||||
} else {
|
|
||||||
return Result.error("第"+ (count+1) +"行课题名称不能为空");
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotBlank(dataMap.get("*会议主办单位"))) {
|
if (StringUtils.isNotBlank(dataMap.get("*会议主办单位"))) {
|
||||||
insideOutsideMeeting.setMeetingOrganizer(dataMap.get("*会议主办单位"));
|
insideOutsideMeeting.setMeetingOrganizer(dataMap.get("*会议主办单位"));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+45
-5
@@ -32,10 +32,8 @@ import com.adc.da.slrs.sarLawsInformation.dao.SarLawsInformationDao;
|
|||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
|
||||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -478,7 +476,46 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
|
|||||||
FileUnZip.deleteDir(saveDirectory);
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("fail", "读取失败,请严格按照模板文件导入数据");
|
return Result.error("fail", "读取失败,请严格按照模板文件导入数据");
|
||||||
}
|
}
|
||||||
|
// 获取总行数
|
||||||
|
int rowNum = sheet.getPhysicalNumberOfRows();
|
||||||
|
List<Map<String,String>> importDataList = new ArrayList<>();
|
||||||
|
for (int rowIndex = 2; rowIndex < rowNum; rowIndex++) {
|
||||||
|
// 获取每一行
|
||||||
|
Row row = sheet.getRow(rowIndex);
|
||||||
|
// 用于存储每行的键值对数据,对应一条数据
|
||||||
|
Map<String, String> rowMap = new LinkedHashMap<>();
|
||||||
|
// 总列数
|
||||||
|
int columnNum = 9;
|
||||||
|
// 遍历每个单元格
|
||||||
|
for (int columnIndex = 0; columnIndex < columnNum; columnIndex++) {
|
||||||
|
// 获取单元格
|
||||||
|
Cell cell = row.getCell(columnIndex);
|
||||||
|
// 获取表头单元格
|
||||||
|
Cell headerCell = headerRow.getCell(columnIndex);
|
||||||
|
if (cell != null) {
|
||||||
|
if (CellType.NUMERIC == cell.getCellType() && HSSFDateUtil.isCellDateFormatted(cell)) {
|
||||||
|
Date d = cell.getDateCellValue();
|
||||||
|
if (d.before(sdf.parse("1900-01-01")) || d.after(sdf.parse("2500-01-01"))) {
|
||||||
|
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入的日期异常,请按照实际日期填写");
|
||||||
|
}
|
||||||
|
// 将单元格数据存入Map中
|
||||||
|
rowMap.put(headerCell.getStringCellValue(), sdf.format(d));
|
||||||
|
} else {
|
||||||
|
cell.setCellType(CellType.STRING);
|
||||||
|
if (cell.getStringCellValue().length() > 500) {
|
||||||
|
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入过长");
|
||||||
|
}
|
||||||
|
rowMap.put(headerCell.getStringCellValue(), cell.getStringCellValue());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rowMap.put(headerCell.getStringCellValue(), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
importDataList.add(rowMap);
|
||||||
|
}
|
||||||
|
if (importDataList.size() < 1) {
|
||||||
|
return Result.error("您输入的数据为空");
|
||||||
|
}
|
||||||
ImportParams importParams = new ImportParams();
|
ImportParams importParams = new ImportParams();
|
||||||
importParams.setTitleRows(1);
|
importParams.setTitleRows(1);
|
||||||
List<SarLawsInformation> sarLawsInformationList = ExcelImportUtil.importExcel(readImpExcelFile(zipEntryName).get(0), SarLawsInformation.class, importParams);
|
List<SarLawsInformation> sarLawsInformationList = ExcelImportUtil.importExcel(readImpExcelFile(zipEntryName).get(0), SarLawsInformation.class, importParams);
|
||||||
@@ -500,6 +537,9 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
|
|||||||
sarLawsInformationListNew.add(sarLawsInformation);
|
sarLawsInformationListNew.add(sarLawsInformation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// if (sarLawsInformationListNew.size() < 1) {
|
||||||
|
// return Result.error("您输入的数据为空");
|
||||||
|
// }
|
||||||
for (SarLawsInformation sarLawsInformation : sarLawsInformationListNew){
|
for (SarLawsInformation sarLawsInformation : sarLawsInformationListNew){
|
||||||
if (StringUtils.isBlank(sarLawsInformation.getDepartment())) {
|
if (StringUtils.isBlank(sarLawsInformation.getDepartment())) {
|
||||||
return Result.error("第" + index + "条记录的资料归属部门不能为空");
|
return Result.error("第" + index + "条记录的资料归属部门不能为空");
|
||||||
|
|||||||
+48
-4
@@ -28,10 +28,8 @@ import com.adc.da.slrs.sarLawsTopic.dao.SarLawsTopicMapper;
|
|||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
|
||||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -44,6 +42,7 @@ import java.io.IOException;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -350,6 +349,51 @@ public class SarLawsTopicServiceImpl extends ServiceImpl<SarLawsTopicMapper, Sar
|
|||||||
return Result.error("fail", "读取失败,请严格按照模板文件导入数据");
|
return Result.error("fail", "读取失败,请严格按照模板文件导入数据");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取总行数
|
||||||
|
int rowNum = sheet.getPhysicalNumberOfRows();
|
||||||
|
List<Map<String,String>> importDataList = new ArrayList<>();
|
||||||
|
for (int rowIndex = 3; rowIndex < rowNum; rowIndex++) {
|
||||||
|
// 获取每一行
|
||||||
|
Row row = sheet.getRow(rowIndex);
|
||||||
|
// 用于存储每行的键值对数据,对应一条数据
|
||||||
|
Map<String, String> rowMap = new LinkedHashMap<>();
|
||||||
|
// 总列数
|
||||||
|
int columnNum = 32;
|
||||||
|
// 遍历每个单元格
|
||||||
|
for (int columnIndex = 0; columnIndex < columnNum; columnIndex++) {
|
||||||
|
// 获取单元格
|
||||||
|
Cell cell = row.getCell(columnIndex);
|
||||||
|
// 获取表头单元格
|
||||||
|
Cell headerCell = headerRow.getCell(columnIndex);
|
||||||
|
if (cell != null) {
|
||||||
|
if (CellType.NUMERIC == cell.getCellType() && HSSFDateUtil.isCellDateFormatted(cell)) {
|
||||||
|
Date d = cell.getDateCellValue();
|
||||||
|
try {
|
||||||
|
if (d.before(sdf.parse("1900-01-01")) || d.after(sdf.parse("2500-01-01"))) {
|
||||||
|
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入的日期异常,请按照实际日期填写");
|
||||||
|
}
|
||||||
|
} catch (ParseException e) {
|
||||||
|
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入的日期异常,请按照实际日期填写");
|
||||||
|
}
|
||||||
|
// 将单元格数据存入Map中
|
||||||
|
rowMap.put(headerCell.getStringCellValue(), sdf.format(d));
|
||||||
|
} else {
|
||||||
|
cell.setCellType(CellType.STRING);
|
||||||
|
if (cell.getStringCellValue().length() > 500) {
|
||||||
|
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入过长");
|
||||||
|
}
|
||||||
|
rowMap.put(headerCell.getStringCellValue(), cell.getStringCellValue());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rowMap.put(headerCell.getStringCellValue(), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
importDataList.add(rowMap);
|
||||||
|
}
|
||||||
|
if (importDataList.size() < 1) {
|
||||||
|
return Result.error("您输入的数据为空");
|
||||||
|
}
|
||||||
|
|
||||||
ImportParams importParams = new ImportParams();
|
ImportParams importParams = new ImportParams();
|
||||||
importParams.setTitleRows(1);
|
importParams.setTitleRows(1);
|
||||||
importParams.setHeadRows(2);
|
importParams.setHeadRows(2);
|
||||||
|
|||||||
Reference in New Issue
Block a user