bug: 政策法规资料导入带附件,内外部会议导入带附件

This commit is contained in:
wxyclub
2023-11-23 18:14:57 +08:00
parent 6065017dff
commit 9e0aca4304
8 changed files with 284 additions and 29 deletions
@@ -169,9 +169,9 @@ public class InsideOutSideMeetingController extends BaseController<InsideOutside
nowFile.mkdirs(); nowFile.mkdirs();
String fileName2 = "导入模板.xls"; String fileName2 = "导入模板.xls";
HSSFSheet sheetItems = workbook.createSheet("模板"); HSSFSheet sheetItems = workbook.createSheet("模板");
sheetItems.setDefaultColumnWidth(12); sheetItems.setDefaultColumnWidth(14);
Row rowHeader = sheetItems.createRow(1);//开始创建标题行 Row rowHeader = sheetItems.createRow(1);//开始创建标题行
sheetItems.addMergedRegion(new CellRangeAddress(0, 0, 0, 12)); sheetItems.addMergedRegion(new CellRangeAddress(0, 0, 0, 14));
Row row2 = sheetItems.createRow(0);//开始创建填写说明 Row row2 = sheetItems.createRow(0);//开始创建填写说明
String exportFieldName = FieldConvertUtil.exportFieldNamesInsideOutsideMeeting + "," + FieldConvertUtil.exportFieldNamesMeetingTopic; String exportFieldName = FieldConvertUtil.exportFieldNamesInsideOutsideMeeting + "," + FieldConvertUtil.exportFieldNamesMeetingTopic;
if (StringUtils.isNotBlank(exportFieldName)) { if (StringUtils.isNotBlank(exportFieldName)) {
@@ -1,6 +1,7 @@
package com.adc.da.slrs.InsideOntSideMeeting.entity; package com.adc.da.slrs.InsideOntSideMeeting.entity;
import cn.afterturn.easypoi.excel.annotation.Excel; import cn.afterturn.easypoi.excel.annotation.Excel;
import com.adc.da.att.entity.AttFileEO;
import com.adc.da.base.entity.BaseEntity; import com.adc.da.base.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
@@ -13,6 +14,7 @@ import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* @author tjzdw * @author tjzdw
@@ -42,6 +44,7 @@ public class MeetingTopic extends BaseEntity {
@ApiModelProperty(value = "议题材料") @ApiModelProperty(value = "议题材料")
@TableField("AGENDA_MATERIALS") @TableField("AGENDA_MATERIALS")
private String agendaMaterials; private String agendaMaterials;
private List<AttFileEO> agendaMaterialsList;
@ApiModelProperty(value = "汇报人") @ApiModelProperty(value = "汇报人")
@TableField("REPORTER") @TableField("REPORTER")
@@ -2,6 +2,7 @@ package com.adc.da.slrs.InsideOntSideMeeting.service.impl;
import com.adc.da.att.entity.AttFileEO; import com.adc.da.att.entity.AttFileEO;
import com.adc.da.att.service.IAttFileEOService; import com.adc.da.att.service.IAttFileEOService;
import com.adc.da.att.vo.AttFileVo;
import com.adc.da.common.FileUnZip; import com.adc.da.common.FileUnZip;
import com.adc.da.http.ResponseMessage; import com.adc.da.http.ResponseMessage;
import com.adc.da.http.Result; import com.adc.da.http.Result;
@@ -83,6 +84,16 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
wrapper.eq(MeetingTopic::getMeetingId, meetingId); wrapper.eq(MeetingTopic::getMeetingId, meetingId);
wrapper.orderByAsc(MeetingTopic::getCreateTime); wrapper.orderByAsc(MeetingTopic::getCreateTime);
List<MeetingTopic> meetingTopicList = meetingTopicService.list(wrapper); List<MeetingTopic> meetingTopicList = meetingTopicService.list(wrapper);
for (MeetingTopic meetingTopic : meetingTopicList) {
if (StringUtils.isNotBlank(meetingTopic.getAgendaMaterials())) {
List<AttFileEO> agendaMaterialsList = new ArrayList<>();
for (String attId : meetingTopic.getAgendaMaterials().split(",")) {
AttFileEO fileInfo = attFileEOService.getFileInfo(attId);
agendaMaterialsList.add(fileInfo);
}
meetingTopic.setAgendaMaterialsList(agendaMaterialsList);
}
}
insideOutsideMeeting.setMeetingTopicList(meetingTopicList); insideOutsideMeeting.setMeetingTopicList(meetingTopicList);
} }
return insideOutsideMeeting; return insideOutsideMeeting;
@@ -244,19 +255,32 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
//获取文件信息 //获取文件信息
List<File> fileList = readImpExcelFile(zipEntryName); List<File> fileList = readImpExcelFile(zipEntryName);
//判断获取到的文件数量 //判断获取到的文件数量
if (fileList.size() != 1) { if (fileList.size() < 1) {
return Result.error("上传的文件只能有一个"); return Result.error("上传的文件不能为空");
} }
File importFile = fileList.get(0); File excelFile = null;
if (!importFile.getName().contains(".xls") && !importFile.getName().contains(".xlsx")) { int excelCount = 0;
return Result.error("文件必须是EXCEL文件"); // 将文件转换为Map,文件名为建,文件为值
Map<String, File> fileMap = new HashMap<>();
for (File file1 : fileList) {
fileMap.put(file1.getName(), file1);
if (file1.getName().toLowerCase().contains(".xls") || file1.getName().toLowerCase().contains(".xlsx")) {
excelFile = file1;
excelCount ++;
}
}
if (excelCount > 1) {
return Result.error("导入了多个Excel文件");
}
if (excelCount < 1){
return Result.error("文件必须包含一个EXCEL文件");
} }
Workbook workbook = null; Workbook workbook = null;
try { try {
workbook = WorkbookFactory.create(importFile); workbook = WorkbookFactory.create(excelFile);
} catch (IOException e) { } catch (IOException e) {
FileUnZip.deleteDir(saveDirectory); FileUnZip.deleteDir(saveDirectory);
return Result.error("导入失败,需要导入的数据有问题或导入的企标标号和企标名称已存在"); return Result.error("导入失败,需要导入的数据有问题");
} }
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Sheet sheet = workbook.getSheetAt(0); Sheet sheet = workbook.getSheetAt(0);
@@ -267,7 +291,7 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
List<String> headerList = new ArrayList<>(); List<String> headerList = new ArrayList<>();
// 获取excel表头 // 获取excel表头
Row headerRow = sheet.getRow(1); Row headerRow = sheet.getRow(1);
for (int i = 0; i <= 12; i++) { for (int i = 0; i <= 14; i++) {
headerList.add(headerRow.getCell(i).getStringCellValue()); headerList.add(headerRow.getCell(i).getStringCellValue());
} }
@@ -292,7 +316,7 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
// 用于存储每行的键值对数据,对应一条数据 // 用于存储每行的键值对数据,对应一条数据
Map<String, String> rowMap = new LinkedHashMap<>(); Map<String, String> rowMap = new LinkedHashMap<>();
// 总列数 // 总列数
int columnNum = 13; int columnNum = 15;
// 遍历每个单元格 // 遍历每个单元格
for (int columnIndex = 0; columnIndex < columnNum; columnIndex++) { for (int columnIndex = 0; columnIndex < columnNum; columnIndex++) {
// 获取单元格 // 获取单元格
@@ -349,9 +373,25 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
insideOutsideMeeting.setMeetingName(meetingName); insideOutsideMeeting.setMeetingName(meetingName);
insideOutsideMeeting.setTopicName(dataMap.get("课题名称")); insideOutsideMeeting.setTopicName(dataMap.get("课题名称"));
insideOutsideMeeting.setMeetingOrganizer(dataMap.get("会议主办单位")); insideOutsideMeeting.setMeetingOrganizer(dataMap.get("会议主办单位"));
Date meetingTime = null;
try {
meetingTime = sdf.parse(dataMap.get("会议时间"));
} catch (ParseException e) {
return Result.error("第"+ (count+1) +"行会议时间格式必须为年-月-日");
}
insideOutsideMeeting.setMeetingTime(sdf.parse(dataMap.get("会议时间"))); insideOutsideMeeting.setMeetingTime(sdf.parse(dataMap.get("会议时间")));
insideOutsideMeeting.setMeetingAddress(dataMap.get("会议地点")); insideOutsideMeeting.setMeetingAddress(dataMap.get("会议地点"));
insideOutsideMeeting.setParticipants(dataMap.get("参会人员")); insideOutsideMeeting.setParticipants(dataMap.get("参会人员"));
String meetingMinutesFileNameStr = dataMap.get("会议纪要");
String meetingMinutesFileAtt = null;
try {
meetingMinutesFileAtt = getFileAtt(meetingMinutesFileNameStr, fileMap, count);
} catch (Exception e) {
return Result.error(e.getMessage());
}
if (StringUtils.isNotBlank(meetingMinutesFileAtt)) {
insideOutsideMeeting.setMeetingMinutes(meetingMinutesFileAtt);
}
insideOutsideMeeting.setMeetingContent(dataMap.get("会议主要内容")); insideOutsideMeeting.setMeetingContent(dataMap.get("会议主要内容"));
if (StringUtils.isNotBlank(dataMap.get("一级会议类别"))) { if (StringUtils.isNotBlank(dataMap.get("一级会议类别"))) {
if (!firstMeetingTypeNameSet.contains(dataMap.get("一级会议类别"))){ if (!firstMeetingTypeNameSet.contains(dataMap.get("一级会议类别"))){
@@ -376,6 +416,16 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
// 会议课题信息 // 会议课题信息
MeetingTopic meetingTopic = new MeetingTopic(); MeetingTopic meetingTopic = new MeetingTopic();
meetingTopic.setAgendaName(dataMap.get("议题名称")); meetingTopic.setAgendaName(dataMap.get("议题名称"));
String agendaMaterialsFileNameStr = dataMap.get("议题材料");
String agendaMaterialsFileNameAtt = null;
try {
agendaMaterialsFileNameAtt = getFileAtt(agendaMaterialsFileNameStr, fileMap, count);
} catch (Exception e) {
return Result.error(e.getMessage());
}
if (StringUtils.isNotBlank(agendaMaterialsFileNameAtt)) {
meetingTopic.setAgendaMaterials(agendaMaterialsFileNameAtt);
}
meetingTopic.setReporter(dataMap.get("汇报人")); meetingTopic.setReporter(dataMap.get("汇报人"));
meetingTopic.setReportingUnit(dataMap.get("汇报单位")); meetingTopic.setReportingUnit(dataMap.get("汇报单位"));
meetingTopic.setAgendaContent(dataMap.get("议题主要内容")); meetingTopic.setAgendaContent(dataMap.get("议题主要内容"));
@@ -385,6 +435,16 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
// 进入else 表示该行是会议课题行 // 进入else 表示该行是会议课题行
MeetingTopic meetingTopic = new MeetingTopic(); MeetingTopic meetingTopic = new MeetingTopic();
meetingTopic.setAgendaName(dataMap.get("议题名称")); meetingTopic.setAgendaName(dataMap.get("议题名称"));
String agendaMaterialsFileNameStr = dataMap.get("议题材料");
String agendaMaterialsFileNameAtt = null;
try {
agendaMaterialsFileNameAtt = getFileAtt(agendaMaterialsFileNameStr, fileMap, count);
} catch (Exception e) {
return Result.error(e.getMessage());
}
if (StringUtils.isNotBlank(agendaMaterialsFileNameAtt)) {
meetingTopic.setAgendaMaterials(agendaMaterialsFileNameAtt);
}
meetingTopic.setReporter(dataMap.get("汇报人")); meetingTopic.setReporter(dataMap.get("汇报人"));
meetingTopic.setReportingUnit(dataMap.get("汇报单位")); meetingTopic.setReportingUnit(dataMap.get("汇报单位"));
meetingTopic.setAgendaContent(dataMap.get("议题主要内容")); meetingTopic.setAgendaContent(dataMap.get("议题主要内容"));
@@ -507,4 +567,33 @@ public class InsideOutsideMeetingServiceImpl extends ServiceImpl<InsideOutsideMe
meeting.setSecondMeetingTypeName(dicTypeService.getDicTypeNameByDicCode(meeting.getSecondMeetingType())); meeting.setSecondMeetingTypeName(dicTypeService.getDicTypeNameByDicCode(meeting.getSecondMeetingType()));
} }
} }
public String getFileAtt(String fileNameStr, Map<String, File> fileMap, int count) throws Exception {
if (fileNameStr != null) {
List<String> fileAttList = new ArrayList<>();
for (String meetingMinutesFileName : fileNameStr.split(",")) {
int lastIndexOf = meetingMinutesFileName.lastIndexOf(".");
if (meetingMinutesFileName.lastIndexOf(".") != -1) {
String lastName = meetingMinutesFileName.substring(lastIndexOf + 1).toLowerCase();
if (lastName.equals("pdf") || lastName.equals("ppt") || lastName.equals("pptx") || lastName.equals("doc") || lastName.equals("docx")) {
File file1 = fileMap.get(meetingMinutesFileName);
if (file1 == null) {
throw new Exception("会议纪要中第" + (count+1) +"行" + meetingMinutesFileName + "文件不存在,请上传pdf/ppt/pptx/doc/docx格式的附件");
}
AttFileVo attFileVo = attFileEOService.saveFileInfo(file1);
if (StringUtils.isNotBlank(attFileVo.getId())) {
fileAttList.add(attFileVo.getAttId());
}
} else {
throw new Exception("会议纪要中第" + (count+1) +"行" + meetingMinutesFileName + "格式不正确,请上传pdf/ppt/pptx/doc/docx格式的附件");
}
} else {
throw new Exception("会议纪要中第" + (count+1) +"行" + meetingMinutesFileName + "格式不正确,请上传pdf/ppt/pptx/doc/docx格式的附件");
}
}
return String.join(",", fileAttList);
}
return null;
}
} }
@@ -12,6 +12,7 @@ import com.adc.da.http.PageInfo;
import com.adc.da.http.ResponseMessage; import com.adc.da.http.ResponseMessage;
import com.adc.da.http.Result; import com.adc.da.http.Result;
import com.adc.da.slrs.sarLawsInformation.entity.SarLawsInformation; import com.adc.da.slrs.sarLawsInformation.entity.SarLawsInformation;
import com.adc.da.slrs.sarLawsInformation.entity.SarLawsInformationExport;
import com.adc.da.slrs.sarLawsInformation.service.SarLawsInformationService; import com.adc.da.slrs.sarLawsInformation.service.SarLawsInformationService;
import com.adc.da.util.UUIDUtils; import com.adc.da.util.UUIDUtils;
import com.adc.da.utils.util.FieldConvertUtil; import com.adc.da.utils.util.FieldConvertUtil;
@@ -26,6 +27,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@@ -35,6 +37,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -124,10 +127,16 @@ public class SarLawsInformationController extends BaseController<SarLawsInformat
// 导出所有数据 // 导出所有数据
datas = informationService.getAllLawsInformation(sarLawsInformation); datas = informationService.getAllLawsInformation(sarLawsInformation);
} }
List<SarLawsInformationExport> datasExport = new ArrayList<>();
for (SarLawsInformation data : datas) {
SarLawsInformationExport dataExport = new SarLawsInformationExport();
BeanUtils.copyProperties(data,dataExport);
datasExport.add(dataExport);
}
ExportParams exportParams = new ExportParams(); ExportParams exportParams = new ExportParams();
exportParams.setType(ExcelType.XSSF); exportParams.setType(ExcelType.XSSF);
exportParams.setSheetName(sarLawsInformation.getExportName()); exportParams.setSheetName(sarLawsInformation.getExportName());
workbook = ExcelExportUtil.exportExcel(exportParams,SarLawsInformation.class,datas); workbook = ExcelExportUtil.exportExcel(exportParams, SarLawsInformationExport.class,datasExport);
os = response.getOutputStream(); os = response.getOutputStream();
workbook.write(os); workbook.write(os);
os.flush(); os.flush();
@@ -170,7 +179,7 @@ public class SarLawsInformationController extends BaseController<SarLawsInformat
nowFile.mkdirs(); nowFile.mkdirs();
String fileName2 = "导入模板.xls"; String fileName2 = "导入模板.xls";
HSSFSheet sheetItems = workbook.createSheet("模板"); HSSFSheet sheetItems = workbook.createSheet("模板");
sheetItems.setDefaultColumnWidth(13); sheetItems.setDefaultColumnWidth(12);
Row rowHeader = sheetItems.createRow(1);//开始创建标题行 Row rowHeader = sheetItems.createRow(1);//开始创建标题行
sheetItems.addMergedRegion(new CellRangeAddress(0, 0, 0, 8)); sheetItems.addMergedRegion(new CellRangeAddress(0, 0, 0, 8));
Row row2 = sheetItems.createRow(0);//开始创建填写说明 Row row2 = sheetItems.createRow(0);//开始创建填写说明
@@ -141,6 +141,7 @@ public class SarLawsInformation extends BasePage implements Serializable {
*/ */
@ApiModelProperty(value = "资料文件") @ApiModelProperty(value = "资料文件")
@TableField(value = "INFORMATION_FILE") @TableField(value = "INFORMATION_FILE")
@Excel(name = "资料文件", orderNum = "9")
private String informationFile; private String informationFile;
/** /**
@@ -0,0 +1,102 @@
package com.adc.da.slrs.sarLawsInformation.entity;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.util.Date;
/**
* @author tjzdw
* @description
* @date 2023/11/23
*/
@Data
public class SarLawsInformationExport {
/**
* 主键
*/
@TableId(value = "ID", type = IdType.ID_WORKER_STR)
private String id;
/**
* 一级资料类别
*/
@TableField(value = "FIRST_TYPE")
private String firstType;
/**
* 一级资料类别名称
*/
@Excel(name = "1级资料分类", orderNum = "0")
private String firstTypeName;
/**
* 二级资料类别
*/
@TableField(value = "SECOND_TYPE")
private String secondType;
/**
* 二级资料类别名称
*/
@Excel(name = "2级资料分类", orderNum = "1")
private String secondTypeName;
/**
* 三级资料类别
*/
@TableField(value = "THIRD_TYPE")
private String thirdType;
/**
* 三级资料类别名称
*/
@Excel(name = "3级资料分类", orderNum = "2")
private String thirdTypeName;
/**
* 四级资料类别
*/
@TableField(value = "FOURTH_TYPE")
private String fourthType;
/**
* 四级资料类别名称
*/
@Excel(name = "4级资料分类", orderNum = "3")
private String fourthTypeName;
/**
* 资料名称
*/
@Excel(name = "资料名称", orderNum = "4")
private String name;
/**
* 资料归属部门
*/
@Excel(name = "资料归属部门", orderNum = "5")
private String department;
/**
* 作者
*/
@Excel(name = "作者", orderNum = "6")
private String author;
/**
* 上传时间
*/
@Excel(name = "上传时间", orderNum = "7", exportFormat = "yyyy-MM-dd")
private Date uploadTime;
/**
* 资料说明
*/
@Excel(name = "资料说明", orderNum = "8")
private String description;
}
@@ -4,6 +4,7 @@ import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams; import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.adc.da.att.entity.AttFileEO; import com.adc.da.att.entity.AttFileEO;
import com.adc.da.att.service.IAttFileEOService; import com.adc.da.att.service.IAttFileEOService;
import com.adc.da.att.vo.AttFileVo;
import com.adc.da.common.FileUnZip; import com.adc.da.common.FileUnZip;
import com.adc.da.http.ResponseMessage; import com.adc.da.http.ResponseMessage;
import com.adc.da.http.Result; import com.adc.da.http.Result;
@@ -28,6 +29,7 @@ import com.adc.da.slrs.sarLawsInformation.entity.SarLawsInformation;
import com.adc.da.slrs.sarLawsInformation.service.SarLawsInformationService; import com.adc.da.slrs.sarLawsInformation.service.SarLawsInformationService;
import com.adc.da.slrs.sarLawsInformation.dao.SarLawsInformationDao; import com.adc.da.slrs.sarLawsInformation.dao.SarLawsInformationDao;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
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.ss.usermodel.Row;
@@ -348,10 +350,10 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
LambdaQueryWrapper<SarLawsInformation> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SarLawsInformation> wrapper = new LambdaQueryWrapper<>();
wrapper.in(SarLawsInformation::getId, idList); wrapper.in(SarLawsInformation::getId, idList);
List<SarLawsInformation> sarLawsInformationList = this.baseMapper.selectList(wrapper); List<SarLawsInformation> sarLawsInformationList = this.baseMapper.selectList(wrapper);
// for (SarLawsInformation sarLawsInformation : sarLawsInformationList) { for (SarLawsInformation sarLawsInformation : sarLawsInformationList) {
// // 将字典编号变更为字典值 // 将字典编号变更为字典值
// convertCodeToName(sarLawsInformation); convertCodeToName(sarLawsInformation);
// } }
return sarLawsInformationList; return sarLawsInformationList;
} }
@@ -372,7 +374,7 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
List<SarLawsInformation> sarLawsInformationList = this.baseMapper.getAllLawsInformation(sarLawsInformation); List<SarLawsInformation> sarLawsInformationList = this.baseMapper.getAllLawsInformation(sarLawsInformation);
for (SarLawsInformation lawsInformation : sarLawsInformationList) { for (SarLawsInformation lawsInformation : sarLawsInformationList) {
// 将字典编号变更为字典值 // 将字典编号变更为字典值
// convertCodeToName(lawsInformation); convertCodeToName(lawsInformation);
// 查询文件信息 // 查询文件信息
if (StringUtils.isNotBlank(lawsInformation.getInformationFile())) { if (StringUtils.isNotBlank(lawsInformation.getInformationFile())) {
String[] split = lawsInformation.getInformationFile().split(","); String[] split = lawsInformation.getInformationFile().split(",");
@@ -387,6 +389,7 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
return sarLawsInformationList; return sarLawsInformationList;
} }
@SneakyThrows
@Override @Override
public ResponseMessage<?> importLawsInformationInfo(MultipartFile file) { public ResponseMessage<?> importLawsInformationInfo(MultipartFile file) {
//获取文件全称 //获取文件全称
@@ -427,19 +430,32 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
//获取文件信息 //获取文件信息
List<File> fileList = readImpExcelFile(zipEntryName); List<File> fileList = readImpExcelFile(zipEntryName);
//判断获取到的文件数量 //判断获取到的文件数量
if (fileList.size() != 1) { if (fileList.size() < 1) {
return Result.error("上传的文件只能有一个"); return Result.error("上传的文件不能为空");
} }
File importFile = fileList.get(0); File excelFile = null;
if (!importFile.getName().contains(".xls") && !importFile.getName().contains(".xlsx")) { int excelCount = 0;
return Result.error("文件必须是EXCEL文件"); // 将文件转换为Map,文件名为建,文件为值
Map<String, File> fileMap = new HashMap<>();
for (File file1 : fileList) {
fileMap.put(file1.getName(), file1);
if (file1.getName().toLowerCase().contains(".xls") || file1.getName().toLowerCase().contains(".xlsx")) {
excelFile = file1;
excelCount ++;
}
}
if (excelCount > 1) {
return Result.error("导入了多个Excel文件");
}
if (excelCount < 1){
return Result.error("文件必须包含一个EXCEL文件");
} }
Workbook workbook = null; Workbook workbook = null;
try { try {
workbook = WorkbookFactory.create(importFile); workbook = WorkbookFactory.create(excelFile);
} catch (IOException e) { } catch (IOException e) {
FileUnZip.deleteDir(saveDirectory); FileUnZip.deleteDir(saveDirectory);
return Result.error("导入失败,需要导入的数据有问题或导入的企标标号和企标名称已存在"); return Result.error("导入失败,需要导入的数据有问题");
} }
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Sheet sheet = workbook.getSheetAt(0); Sheet sheet = workbook.getSheetAt(0);
@@ -450,7 +466,7 @@ 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);
for (int i = 0; i < 8; i++) { for (int i = 0; i < 9; i++) {
headerList.add(headerRow.getCell(i).getStringCellValue()); headerList.add(headerRow.getCell(i).getStringCellValue());
} }
@@ -545,6 +561,13 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
} }
sarLawsInformation.setFourthType(String.join(",", fourthTypeCodeList)); sarLawsInformation.setFourthType(String.join(",", fourthTypeCodeList));
} }
String informationFileAtt = null;
try {
informationFileAtt = getFileAtt(sarLawsInformation.getInformationFile(), fileMap, index);
} catch (Exception e) {
return Result.error(e.getMessage());
}
sarLawsInformation.setInformationFile(informationFileAtt);
// 索引 +1 // 索引 +1
index++; index++;
// 存入数据库 // 存入数据库
@@ -698,6 +721,34 @@ public class SarLawsInformationServiceImpl extends ServiceImpl<SarLawsInformatio
} }
return results; return results;
} }
public String getFileAtt(String fileNameStr, Map<String, File> fileMap, int count) throws Exception {
if (fileNameStr != null) {
List<String> fileAttList = new ArrayList<>();
for (String meetingMinutesFileName : fileNameStr.split(",")) {
int lastIndexOf = meetingMinutesFileName.lastIndexOf(".");
if (meetingMinutesFileName.lastIndexOf(".") != -1) {
String lastName = meetingMinutesFileName.substring(lastIndexOf + 1).toLowerCase();
if (lastName.equals("pdf") || lastName.equals("ppt") || lastName.equals("pptx") || lastName.equals("doc") || lastName.equals("docx")) {
File file1 = fileMap.get(meetingMinutesFileName);
if (file1 == null) {
throw new Exception("会议纪要中第" + (count+1) +"行" + meetingMinutesFileName + "文件不存在,请上传pdf/ppt/pptx/doc/docx格式的附件");
}
AttFileVo attFileVo = attFileEOService.saveFileInfo(file1);
if (StringUtils.isNotBlank(attFileVo.getId())) {
fileAttList.add(attFileVo.getAttId());
}
} else {
throw new Exception("会议纪要中第" + (count+1) +"行" + meetingMinutesFileName + "格式不正确,请上传pdf/ppt/pptx/doc/docx格式的附件");
}
} else {
throw new Exception("会议纪要中第" + (count+1) +"行" + meetingMinutesFileName + "格式不正确,请上传pdf/ppt/pptx/doc/docx格式的附件");
}
}
return String.join(",", fileAttList);
}
return null;
}
} }
@@ -65,12 +65,12 @@ public class FieldConvertUtil {
public static String exportFieldNamesEsRevisePlan = "企标类别,企标编号,企标名称,计划状态,制修订类型,起草人,内部评审责任人,技术委员会评审负责人,计划标准初稿完成时间,计划标准发布时间,起草责任单位,实际标准发布时间,质量评分"; public static String exportFieldNamesEsRevisePlan = "企标类别,企标编号,企标名称,计划状态,制修订类型,起草人,内部评审责任人,技术委员会评审负责人,计划标准初稿完成时间,计划标准发布时间,起草责任单位,实际标准发布时间,质量评分";
// 内外部会议 表头 // 内外部会议 表头
public static String exportFieldNamesInsideOutsideMeeting = "会议名称,课题名称,会议主办单位,会议时间,会议地点,参会人员,会议主要内容,一级会议类别,二级会议类别"; public static String exportFieldNamesInsideOutsideMeeting = "会议名称,课题名称,会议主办单位,会议时间,会议地点,参会人员,会议纪要,会议主要内容,一级会议类别,二级会议类别";
// 内外部会议关联表 表头 // 内外部会议关联表 表头
public static String exportFieldNamesMeetingTopic = "议题名称,汇报人,汇报单位,议题主要内容"; public static String exportFieldNamesMeetingTopic = "议题名称,议题材料,汇报人,汇报单位,议题主要内容";
// 政策法规资料 表头 // 政策法规资料 表头
public static String exportFieldLawsInformation = "1级资料分类,2级资料分类,3级资料分类,4级资料分类,资料名称,资料归属部门,作者,资料说明"; public static String exportFieldLawsInformation = "1级资料分类,2级资料分类,3级资料分类,4级资料分类,资料名称,资料归属部门,作者,资料说明,资料文件";
// 政策课题 表头 // 政策课题 表头
public static String exportFieldLawsTopic = "课题名称,课题承办单位,课题指导单位,课题参与单位,开始时间,结题时间,课题费用(万元),课题组会议列表,课题组联系方式,内部联系方式"; public static String exportFieldLawsTopic = "课题名称,课题承办单位,课题指导单位,课题参与单位,开始时间,结题时间,课题费用(万元),课题组会议列表,课题组联系方式,内部联系方式";