fix: 修改内外部会议政策课题政策法规资料的导入
This commit is contained in:
+32
-3
@@ -247,6 +247,7 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
|
|||||||
try {
|
try {
|
||||||
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path + "/" + fileNameStr));
|
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path + "/" + fileNameStr));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("文件存储失败!");
|
return Result.error("文件存储失败!");
|
||||||
}
|
}
|
||||||
//解压缩
|
//解压缩
|
||||||
@@ -255,6 +256,7 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
|
|||||||
zipEntryName = FileUnZip.unZipFiles(path + "/" + fileNameStr, path);
|
zipEntryName = FileUnZip.unZipFiles(path + "/" + fileNameStr, path);
|
||||||
FileUnZip.delete(new File(path + "/" + fileNameStr));
|
FileUnZip.delete(new File(path + "/" + fileNameStr));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("文件解压失败");
|
return Result.error("文件解压失败");
|
||||||
}
|
}
|
||||||
//获取文件信息
|
//获取文件信息
|
||||||
@@ -275,15 +277,17 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (excelCount > 1) {
|
if (excelCount > 1) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("导入了多个Excel文件");
|
return Result.error("导入了多个Excel文件");
|
||||||
}
|
}
|
||||||
if (excelCount < 1){
|
if (excelCount < 1){
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("文件必须包含一个EXCEL文件");
|
return Result.error("文件必须包含一个EXCEL文件");
|
||||||
}
|
}
|
||||||
Workbook workbook = null;
|
Workbook workbook = null;
|
||||||
|
InputStream inputStream = null;
|
||||||
try {
|
try {
|
||||||
@Cleanup
|
inputStream = new FileInputStream(excelFile);
|
||||||
InputStream inputStream = new FileInputStream(excelFile);
|
|
||||||
workbook = WorkbookFactory.create(inputStream);
|
workbook = WorkbookFactory.create(inputStream);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
FileUnZip.deleteDir(saveDirectory);
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
@@ -292,21 +296,28 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
|
|||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
Sheet sheet = workbook.getSheetAt(0);
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
if (sheet == null) {
|
if (sheet == null) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("工作表为空");
|
return Result.error("工作表为空");
|
||||||
}
|
}
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
List<String> headerList = new ArrayList<>();
|
List<String> headerList = new ArrayList<>();
|
||||||
// 获取excel表头
|
// 获取excel表头
|
||||||
Row headerRow = sheet.getRow(1);
|
Row headerRow = sheet.getRow(1);
|
||||||
|
try {
|
||||||
for (int i = 0; i <= 14; i++) {
|
for (int i = 0; i <= 14; i++) {
|
||||||
headerList.add(headerRow.getCell(i).getStringCellValue());
|
headerList.add(headerRow.getCell(i).getStringCellValue());
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error("表头读取失败,请严格按照模板文件导入数据");
|
||||||
|
} finally {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
|
}
|
||||||
// 判断表头字段是否相同
|
// 判断表头字段是否相同
|
||||||
if (!String.join(",",headerList).equals(FieldConvertUtil.exportFieldNamesInsideOutsideMeeting + "," + FieldConvertUtil.exportFieldNamesMeetingTopic)) {
|
if (!String.join(",",headerList).equals(FieldConvertUtil.exportFieldNamesInsideOutsideMeeting + "," + FieldConvertUtil.exportFieldNamesMeetingTopic)) {
|
||||||
try {
|
try {
|
||||||
workbook.close();
|
workbook.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("文件关闭出错");
|
return Result.error("文件关闭出错");
|
||||||
}
|
}
|
||||||
//删除原上传文件
|
//删除原上传文件
|
||||||
@@ -334,6 +345,7 @@ 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"))) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入的日期异常,请按照实际日期填写");
|
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入的日期异常,请按照实际日期填写");
|
||||||
}
|
}
|
||||||
// 将单元格数据存入Map中
|
// 将单元格数据存入Map中
|
||||||
@@ -341,6 +353,7 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
|
|||||||
} else {
|
} else {
|
||||||
cell.setCellType(CellType.STRING);
|
cell.setCellType(CellType.STRING);
|
||||||
if (cell.getStringCellValue().length() > 500) {
|
if (cell.getStringCellValue().length() > 500) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入过长");
|
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入过长");
|
||||||
}
|
}
|
||||||
rowMap.put(headerCell.getStringCellValue(), cell.getStringCellValue());
|
rowMap.put(headerCell.getStringCellValue(), cell.getStringCellValue());
|
||||||
@@ -352,8 +365,20 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
|
|||||||
importDataList.add(rowMap);
|
importDataList.add(rowMap);
|
||||||
}
|
}
|
||||||
if (importDataList.size() < 1) {
|
if (importDataList.size() < 1) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("您输入的数据为空");
|
return Result.error("您输入的数据为空");
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
workbook.close();
|
||||||
|
inputStream.close();
|
||||||
|
FileUnZip.deleteDir(excelFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return Result.error("关闭失败");
|
||||||
|
}finally {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileUnZip.delete(excelFile);
|
||||||
|
|
||||||
// 获取需要校验的字段
|
// 获取需要校验的字段
|
||||||
List<TsDicType> firstMeetingTypeList = dicTypeService.selectAllDicTypeNameByDicCode("firstMeetingType");
|
List<TsDicType> firstMeetingTypeList = dicTypeService.selectAllDicTypeNameByDicCode("firstMeetingType");
|
||||||
@@ -365,6 +390,7 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
|
|||||||
// InsideOutsideMeeting insideOutsideMeetingDB = null;
|
// InsideOutsideMeeting insideOutsideMeetingDB = null;
|
||||||
InsideOutsideMeeting insideOutsideMeeting = new InsideOutsideMeeting();
|
InsideOutsideMeeting insideOutsideMeeting = new InsideOutsideMeeting();
|
||||||
List<MeetingTopic> meetingTopicList = new ArrayList<>();
|
List<MeetingTopic> meetingTopicList = new ArrayList<>();
|
||||||
|
try {
|
||||||
for (Map<String, String> dataMap : importDataList) {
|
for (Map<String, String> dataMap : importDataList) {
|
||||||
String meetingName = dataMap.get("*会议名称");
|
String meetingName = dataMap.get("*会议名称");
|
||||||
// 如果会议名称为空,则表示该行为会议课题行,是之前会议的会议课题,不提交之前的会议信息。不为空则进入
|
// 如果会议名称为空,则表示该行为会议课题行,是之前会议的会议课题,不提交之前的会议信息。不为空则进入
|
||||||
@@ -505,6 +531,9 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
|
|||||||
// 插入最后一条记录
|
// 插入最后一条记录
|
||||||
insideOutsideMeeting.setMeetingTopicList(meetingTopicList);
|
insideOutsideMeeting.setMeetingTopicList(meetingTopicList);
|
||||||
addMeetingInfo(insideOutsideMeeting);
|
addMeetingInfo(insideOutsideMeeting);
|
||||||
|
} finally {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
|
}
|
||||||
return Result.success("导入完成");
|
return Result.success("导入完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+25
-4
@@ -423,12 +423,14 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
|
|||||||
zipEntryName = FileUnZip.unZipFiles(path + "/" + fileNameStr, path);
|
zipEntryName = FileUnZip.unZipFiles(path + "/" + fileNameStr, path);
|
||||||
FileUnZip.delete(new File(path + "/" + fileNameStr));
|
FileUnZip.delete(new File(path + "/" + fileNameStr));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("文件解压失败");
|
return Result.error("文件解压失败");
|
||||||
}
|
}
|
||||||
//获取文件信息
|
//获取文件信息
|
||||||
List<File> fileList = readImpExcelFile(zipEntryName);
|
List<File> fileList = readImpExcelFile(zipEntryName);
|
||||||
//判断获取到的文件数量
|
//判断获取到的文件数量
|
||||||
if (fileList.size() < 1) {
|
if (fileList.size() < 1) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("上传的文件不能为空");
|
return Result.error("上传的文件不能为空");
|
||||||
}
|
}
|
||||||
File excelFile = null;
|
File excelFile = null;
|
||||||
@@ -443,9 +445,11 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (excelCount > 1) {
|
if (excelCount > 1) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("导入了多个Excel文件");
|
return Result.error("导入了多个Excel文件");
|
||||||
}
|
}
|
||||||
if (excelCount < 1){
|
if (excelCount < 1){
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("文件必须包含一个EXCEL文件");
|
return Result.error("文件必须包含一个EXCEL文件");
|
||||||
}
|
}
|
||||||
Workbook workbook = null;
|
Workbook workbook = null;
|
||||||
@@ -464,9 +468,15 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
|
|||||||
List<String> headerList = new ArrayList<>();
|
List<String> headerList = new ArrayList<>();
|
||||||
// 获取excel表头
|
// 获取excel表头
|
||||||
Row headerRow = sheet.getRow(1);
|
Row headerRow = sheet.getRow(1);
|
||||||
|
try {
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
headerList.add(headerRow.getCell(i).getStringCellValue());
|
headerList.add(headerRow.getCell(i).getStringCellValue());
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error("表头读取失败,请严格按照模板文件导入数据");
|
||||||
|
} finally {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
// 判断表头字段是否相同
|
// 判断表头字段是否相同
|
||||||
if (!String.join(",",headerList).equals(FieldConvertUtil.exportFieldLawsInformation)) {
|
if (!String.join(",",headerList).equals(FieldConvertUtil.exportFieldLawsInformation)) {
|
||||||
@@ -499,6 +509,7 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
|
|||||||
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"))) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入的日期异常,请按照实际日期填写");
|
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入的日期异常,请按照实际日期填写");
|
||||||
}
|
}
|
||||||
// 将单元格数据存入Map中
|
// 将单元格数据存入Map中
|
||||||
@@ -506,6 +517,7 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
|
|||||||
} else {
|
} else {
|
||||||
cell.setCellType(CellType.STRING);
|
cell.setCellType(CellType.STRING);
|
||||||
if (cell.getStringCellValue().length() > 500) {
|
if (cell.getStringCellValue().length() > 500) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入过长");
|
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入过长");
|
||||||
}
|
}
|
||||||
rowMap.put(headerCell.getStringCellValue(), cell.getStringCellValue());
|
rowMap.put(headerCell.getStringCellValue(), cell.getStringCellValue());
|
||||||
@@ -517,13 +529,17 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
|
|||||||
importDataList.add(rowMap);
|
importDataList.add(rowMap);
|
||||||
}
|
}
|
||||||
if (importDataList.size() < 1) {
|
if (importDataList.size() < 1) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("您输入的数据为空");
|
return Result.error("您输入的数据为空");
|
||||||
}
|
}
|
||||||
ImportParams importParams = new ImportParams();
|
ImportParams importParams = new ImportParams();
|
||||||
importParams.setTitleRows(1);
|
importParams.setTitleRows(1);
|
||||||
@Cleanup
|
// @Cleanup
|
||||||
InputStream inputStream = new FileInputStream(excelFile);
|
InputStream inputStream = new FileInputStream(excelFile);
|
||||||
List<SarLawsInformation> sarLawsInformationList = ExcelImportUtil.importExcel(inputStream, SarLawsInformation.class, importParams);
|
List<SarLawsInformation> sarLawsInformationList = ExcelImportUtil.importExcel(inputStream, SarLawsInformation.class, importParams);
|
||||||
|
workbook.close();
|
||||||
|
inputStream.close();
|
||||||
|
FileUnZip.delete(excelFile);
|
||||||
// 获取需要校验的字段
|
// 获取需要校验的字段
|
||||||
List<TsDicType> firstMaterialTypeList = dicTypeService.selectAllDicTypeNameByDicCode("firstMaterialType");
|
List<TsDicType> firstMaterialTypeList = dicTypeService.selectAllDicTypeNameByDicCode("firstMaterialType");
|
||||||
Set<String> firstMaterialTypeNameSet = firstMaterialTypeList.stream().map(TsDicType::getDicTypeName).collect(Collectors.toSet());
|
Set<String> firstMaterialTypeNameSet = firstMaterialTypeList.stream().map(TsDicType::getDicTypeName).collect(Collectors.toSet());
|
||||||
@@ -542,9 +558,11 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
|
|||||||
sarLawsInformationListNew.add(sarLawsInformation);
|
sarLawsInformationListNew.add(sarLawsInformation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if (sarLawsInformationListNew.size() < 1) {
|
if (sarLawsInformationListNew.size() < 1) {
|
||||||
// return Result.error("您输入的数据为空");
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
// }
|
return Result.error("您输入的数据为空");
|
||||||
|
}
|
||||||
|
try {
|
||||||
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 + "条记录的资料归属部门不能为空");
|
||||||
@@ -626,6 +644,9 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
|
|||||||
// 存入数据库
|
// 存入数据库
|
||||||
addLawsInformation(sarLawsInformation);
|
addLawsInformation(sarLawsInformation);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
|
}
|
||||||
return Result.success("导入成功");
|
return Result.success("导入成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -196,7 +196,7 @@ public class SarLawsTopicController extends BaseController<SarLawsTopicVO> {
|
|||||||
cell.setCellStyle(cellStyle1);
|
cell.setCellStyle(cellStyle1);
|
||||||
}
|
}
|
||||||
Cell cell = rowHeader.createCell(8);
|
Cell cell = rowHeader.createCell(8);
|
||||||
cell.setCellValue("课题组资料");
|
cell.setCellValue("课题组会议");
|
||||||
sheetItems.addMergedRegion(new CellRangeAddress(1,1,8,12));
|
sheetItems.addMergedRegion(new CellRangeAddress(1,1,8,12));
|
||||||
cell.setCellStyle(cellStyle1);
|
cell.setCellStyle(cellStyle1);
|
||||||
String exportFieldMeetingName = "会议名称,会议时间,会议地点,参会人员(内部),会议主要内容";
|
String exportFieldMeetingName = "会议名称,会议时间,会议地点,参会人员(内部),会议主要内容";
|
||||||
|
|||||||
+29
-7
@@ -265,6 +265,7 @@ public class SarLawsTopicServiceImpl extends ServiceImpl<SarLawsTopicMapper, Sar
|
|||||||
try {
|
try {
|
||||||
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path + "/" + fileNameStr));
|
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path + "/" + fileNameStr));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("文件存储失败!");
|
return Result.error("文件存储失败!");
|
||||||
}
|
}
|
||||||
//解压缩
|
//解压缩
|
||||||
@@ -273,12 +274,14 @@ public class SarLawsTopicServiceImpl extends ServiceImpl<SarLawsTopicMapper, Sar
|
|||||||
zipEntryName = FileUnZip.unZipFiles(path + "/" + fileNameStr, path);
|
zipEntryName = FileUnZip.unZipFiles(path + "/" + fileNameStr, path);
|
||||||
FileUnZip.delete(new File(path + "/" + fileNameStr));
|
FileUnZip.delete(new File(path + "/" + fileNameStr));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("文件解压失败");
|
return Result.error("文件解压失败");
|
||||||
}
|
}
|
||||||
//获取文件信息
|
//获取文件信息
|
||||||
List<File> fileList = readImpExcelFile(zipEntryName);
|
List<File> fileList = readImpExcelFile(zipEntryName);
|
||||||
//判断获取到的文件数量
|
//判断获取到的文件数量
|
||||||
if (fileList.size() < 1) {
|
if (fileList.size() < 1) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("上传的文件不能为空");
|
return Result.error("上传的文件不能为空");
|
||||||
}
|
}
|
||||||
File excelFile = null;
|
File excelFile = null;
|
||||||
@@ -293,9 +296,11 @@ public class SarLawsTopicServiceImpl extends ServiceImpl<SarLawsTopicMapper, Sar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (excelCount > 1) {
|
if (excelCount > 1) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("导入了多个Excel文件");
|
return Result.error("导入了多个Excel文件");
|
||||||
}
|
}
|
||||||
if (excelCount < 1){
|
if (excelCount < 1){
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("文件必须包含一个EXCEL文件");
|
return Result.error("文件必须包含一个EXCEL文件");
|
||||||
}
|
}
|
||||||
Workbook workbook = null;
|
Workbook workbook = null;
|
||||||
@@ -314,6 +319,8 @@ public class SarLawsTopicServiceImpl extends ServiceImpl<SarLawsTopicMapper, Sar
|
|||||||
// 获取excel表头
|
// 获取excel表头
|
||||||
List<String> headerList = new ArrayList<>();
|
List<String> headerList = new ArrayList<>();
|
||||||
Row headerRow = sheet.getRow(1);
|
Row headerRow = sheet.getRow(1);
|
||||||
|
List<String> relationList = null;
|
||||||
|
try {
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
headerList.add(headerRow.getCell(i).getStringCellValue());
|
headerList.add(headerRow.getCell(i).getStringCellValue());
|
||||||
}
|
}
|
||||||
@@ -325,7 +332,7 @@ public class SarLawsTopicServiceImpl extends ServiceImpl<SarLawsTopicMapper, Sar
|
|||||||
}
|
}
|
||||||
// 获取关联表表头
|
// 获取关联表表头
|
||||||
Row relationRow = sheet.getRow(2);
|
Row relationRow = sheet.getRow(2);
|
||||||
List<String> relationList = new ArrayList<>();
|
relationList = new ArrayList<>();
|
||||||
for (int i = 8; i < 13; i++) {
|
for (int i = 8; i < 13; i++) {
|
||||||
relationList.add(relationRow.getCell(i).getStringCellValue());
|
relationList.add(relationRow.getCell(i).getStringCellValue());
|
||||||
}
|
}
|
||||||
@@ -335,10 +342,15 @@ public class SarLawsTopicServiceImpl extends ServiceImpl<SarLawsTopicMapper, Sar
|
|||||||
for (int i = 27; i < 32; i++) {
|
for (int i = 27; i < 32; i++) {
|
||||||
relationList.add(relationRow.getCell(i).getStringCellValue());
|
relationList.add(relationRow.getCell(i).getStringCellValue());
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error("表头读取失败,请严格按照模板文件导入数据");
|
||||||
|
}finally {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
// 判断表头字段是否相同
|
// 判断表头字段是否相同
|
||||||
if (!String.join(",",headerList).equals(FieldConvertUtil.exportFieldLawsTopic)
|
if (!String.join(",",headerList).equals(FieldConvertUtil.exportFieldLawsTopic)
|
||||||
&& !String.join(",",relationList).equals(FieldConvertUtil.exportFieldLawsTopicRelation)) {
|
|| !String.join(",",relationList).equals(FieldConvertUtil.exportFieldLawsTopicRelation)) {
|
||||||
try {
|
try {
|
||||||
workbook.close();
|
workbook.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -370,9 +382,11 @@ public class SarLawsTopicServiceImpl extends ServiceImpl<SarLawsTopicMapper, Sar
|
|||||||
Date d = cell.getDateCellValue();
|
Date d = cell.getDateCellValue();
|
||||||
try {
|
try {
|
||||||
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"))) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入的日期异常,请按照实际日期填写");
|
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入的日期异常,请按照实际日期填写");
|
||||||
}
|
}
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入的日期异常,请按照实际日期填写");
|
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入的日期异常,请按照实际日期填写");
|
||||||
}
|
}
|
||||||
// 将单元格数据存入Map中
|
// 将单元格数据存入Map中
|
||||||
@@ -380,6 +394,7 @@ public class SarLawsTopicServiceImpl extends ServiceImpl<SarLawsTopicMapper, Sar
|
|||||||
} else {
|
} else {
|
||||||
cell.setCellType(CellType.STRING);
|
cell.setCellType(CellType.STRING);
|
||||||
if (cell.getStringCellValue().length() > 500) {
|
if (cell.getStringCellValue().length() > 500) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入过长");
|
return Result.error("第"+(rowIndex-1)+"行第"+(columnIndex + 1)+"个单元格输入过长");
|
||||||
}
|
}
|
||||||
rowMap.put(headerCell.getStringCellValue(), cell.getStringCellValue());
|
rowMap.put(headerCell.getStringCellValue(), cell.getStringCellValue());
|
||||||
@@ -391,18 +406,22 @@ public class SarLawsTopicServiceImpl extends ServiceImpl<SarLawsTopicMapper, Sar
|
|||||||
importDataList.add(rowMap);
|
importDataList.add(rowMap);
|
||||||
}
|
}
|
||||||
if (importDataList.size() < 1) {
|
if (importDataList.size() < 1) {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
return Result.error("您输入的数据为空");
|
return Result.error("您输入的数据为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
ImportParams importParams = new ImportParams();
|
ImportParams importParams = new ImportParams();
|
||||||
importParams.setTitleRows(1);
|
importParams.setTitleRows(1);
|
||||||
importParams.setHeadRows(2);
|
importParams.setHeadRows(2);
|
||||||
@Cleanup
|
// @Cleanup
|
||||||
InputStream inputStream = new FileInputStream(excelFile);
|
InputStream inputStream = new FileInputStream(excelFile);
|
||||||
List<SarLawsTopicVO> lawsTopicVOList = ExcelImportUtil.importExcel(inputStream, SarLawsTopicVO.class, importParams);
|
List<SarLawsTopicVO> lawsTopicVOList = ExcelImportUtil.importExcel(inputStream, SarLawsTopicVO.class, importParams);
|
||||||
excelFile.delete();
|
workbook.close();
|
||||||
|
inputStream.close();
|
||||||
|
FileUnZip.delete(excelFile);
|
||||||
|
try{
|
||||||
// 去除空数据
|
// 去除空数据
|
||||||
int index = 0;
|
int index = 1;
|
||||||
for (SarLawsTopicVO lawsTopicVO : lawsTopicVOList) {
|
for (SarLawsTopicVO lawsTopicVO : lawsTopicVOList) {
|
||||||
if (StringUtils.isNotBlank(lawsTopicVO.getTopicName())) {
|
if (StringUtils.isNotBlank(lawsTopicVO.getTopicName())) {
|
||||||
// 存入数据库
|
// 存入数据库
|
||||||
@@ -493,6 +512,9 @@ public class SarLawsTopicServiceImpl extends ServiceImpl<SarLawsTopicMapper, Sar
|
|||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
}finally {
|
||||||
|
FileUnZip.deleteDir(saveDirectory);
|
||||||
|
}
|
||||||
return Result.success("导入成功");
|
return Result.success("导入成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -676,10 +698,10 @@ public class SarLawsTopicServiceImpl extends ServiceImpl<SarLawsTopicMapper, Sar
|
|||||||
fileAttList.add(attFileVo.getAttId());
|
fileAttList.add(attFileVo.getAttId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Exception(fieldName + "中第" + (count+1) +"行" + fileName + "格式不正确,请上传pdf/ppt/pptx/doc/docx格式的附件");
|
throw new Exception(fieldName + "中第" + (count+1) +"行" + fileName + "文件格式不正确,请上传pdf/ppt/pptx/doc/docx格式的附件");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Exception(fieldName + "中第" + (count+1) +"行" + fileName + "格式不正确,请上传pdf/ppt/pptx/doc/docx格式的附件");
|
throw new Exception(fieldName + "中第" + (count+1) +"行" + fileName + "文件格式不正确,请上传pdf/ppt/pptx/doc/docx格式的附件");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return String.join(",", fileAttList);
|
return String.join(",", fileAttList);
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class FieldConvertUtil {
|
|||||||
public static String exportFieldLawsInformation = "*1级资料分类,*2级资料分类,*3级资料分类,*4级资料分类,*资料名称,*资料归属部门,作者,资料说明,资料文件";
|
public static String exportFieldLawsInformation = "*1级资料分类,*2级资料分类,*3级资料分类,*4级资料分类,*资料名称,*资料归属部门,作者,资料说明,资料文件";
|
||||||
|
|
||||||
// 政策课题 表头
|
// 政策课题 表头
|
||||||
public static String exportFieldLawsTopic = "*课题名称,*课题承办单位,课题指导单位,课题参与单位,*启动时间,结题时间,课题费用(万元),协议,课题组会议列表,课题组研究方案,课题组研究成果,课题组其他,课题组会议资料,课题组联系方式,内部立项报告,内部研究方案,内部会议资料,内部研究成果,内部其他,内部联系方式";
|
public static String exportFieldLawsTopic = "*课题名称,*课题承办单位,课题指导单位,课题参与单位,*启动时间,结题时间,课题费用(万元),协议,课题组会议,课题组研究方案,课题组研究成果,课题组其他,课题组会议资料,课题组联系方式,内部立项报告,内部研究方案,内部会议资料,内部研究成果,内部其他,内部联系方式";
|
||||||
// 政策课题关联表 表头
|
// 政策课题关联表 表头
|
||||||
public static String exportFieldLawsTopicRelation = "会议名称,会议时间,会议地点,参会人员(内部),会议主要内容,姓名,单位,电话,邮箱,身份,姓名,单位,电话,邮箱,身份";
|
public static String exportFieldLawsTopicRelation = "会议名称,会议时间,会议地点,参会人员(内部),会议主要内容,姓名,单位,电话,邮箱,身份,姓名,单位,电话,邮箱,身份";
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ public class FieldConvertUtil {
|
|||||||
"2.所有带*号的字段必须填写\n" +
|
"2.所有带*号的字段必须填写\n" +
|
||||||
"3.会议分类按照系统中的分类填写\n" +
|
"3.会议分类按照系统中的分类填写\n" +
|
||||||
"4.发布日期,企标实施日期字段为年-月-日格式,必须精确到日,例如(2023-04-01)\n" +
|
"4.发布日期,企标实施日期字段为年-月-日格式,必须精确到日,例如(2023-04-01)\n" +
|
||||||
"5.会议议题如果存在多条,则在下面以此填写,新的内外部会议另起一行填写 \n" +
|
"5.会议议题如果存在多条,则在对应列下依次填写,新的内外部会议另起一行填写 \n" +
|
||||||
"6.会议纪要,议题材料为附件文件,需要放在Excel文档同级目录中";
|
"6.会议纪要,议题材料为附件文件,需要放在Excel文档同级目录中";
|
||||||
|
|
||||||
public static String exportLawsInformationDesc = "填写说明\n" +
|
public static String exportLawsInformationDesc = "填写说明\n" +
|
||||||
@@ -117,7 +117,7 @@ public class FieldConvertUtil {
|
|||||||
"1.导入数据从第三行开始,第一行为填写说明,第二行为表头,第三行是正式数据\n" +
|
"1.导入数据从第三行开始,第一行为填写说明,第二行为表头,第三行是正式数据\n" +
|
||||||
"2.所有带*号的字段必须填写 \n" +
|
"2.所有带*号的字段必须填写 \n" +
|
||||||
"3.启动时间,结题时间字段为年-月-日格式,必须精确到日,例如(2023-12-01)\n" +
|
"3.启动时间,结题时间字段为年-月-日格式,必须精确到日,例如(2023-12-01)\n" +
|
||||||
"4.课题组会议、课题组联系方式、内部联系方式如果存在多条,则在下面一行填写,新的课题组会议、课题组联系方式、内部联系方式在下面依次填写 \n" +
|
"4.课题组会议、课题组联系方式、内部联系方式如果存在多条,则在对应列下依次填写,新的课题组会议、课题组联系方式、内部联系方式在下面依次填写 \n" +
|
||||||
"5.协议,研究方案,研究成果,其他,会议资料等为附件文件,需要放在Excel文档同级目录中";
|
"5.协议,研究方案,研究成果,其他,会议资料等为附件文件,需要放在Excel文档同级目录中";
|
||||||
|
|
||||||
public static String exportFieldName = "*企标类别,*企标编号,*标准年份,*企标名称,企标英文名称,*文本状态,发布日期,企标实施日期,起草部门,起草人,适用车型,能源类型,适用产品线,标准体系,关联模块-乘用车VPPS编码,关联模块--卡车VPPS编码,发布稿,编制说明,历史版本,其他文件,修改单,代替企标编号,采用标准,采标程度,引用标准,关联文件,";
|
public static String exportFieldName = "*企标类别,*企标编号,*标准年份,*企标名称,企标英文名称,*文本状态,发布日期,企标实施日期,起草部门,起草人,适用车型,能源类型,适用产品线,标准体系,关联模块-乘用车VPPS编码,关联模块--卡车VPPS编码,发布稿,编制说明,历史版本,其他文件,修改单,代替企标编号,采用标准,采标程度,引用标准,关联文件,";
|
||||||
|
|||||||
Reference in New Issue
Block a user