diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/controller/ProjectLawsInventoryEOController.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/controller/ProjectLawsInventoryEOController.java index 7b40dfa2a..65145cb74 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/controller/ProjectLawsInventoryEOController.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/controller/ProjectLawsInventoryEOController.java @@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; @@ -330,4 +331,37 @@ public class ProjectLawsInventoryEOController extends JeroController importData(@RequestParam(value = "file", required = false) MultipartFile file, + ProjectLawsInventoryEO projectLawsInventoryEO) { + projectLawsInventoryEOService.importData(file,projectLawsInventoryEO); + return Result.OK("导入成功"); + } + } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/service/IProjectLawsInventoryEOService.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/service/IProjectLawsInventoryEOService.java index 76e135215..7a9a73770 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/service/IProjectLawsInventoryEOService.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/service/IProjectLawsInventoryEOService.java @@ -4,8 +4,10 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.IService; import com.jero.common.api.vo.Result; import com.jero.modules.project.entity.ProjectLawsInventoryEO; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Map; @@ -97,4 +99,19 @@ public interface IProjectLawsInventoryEOService extends IService list = Arrays.asList(titleOne.split(",")); + int index = 0; + if(CutEnum.CN.getValue().equals(projectLawsInventoryEO.getCut())){ + index = list.indexOf("备注") + 1; + }else{ + index = list.indexOf("remarks") + 1; + } + + //创建临时文件夹 + File nowFile = new File(filePath); + if (nowFile.exists()) { + nowFile.delete(); + } + nowFile.mkdirs(); + HSSFSheet sheet = workbook.createSheet("虚拟清单导入模板"); + sheet.setDefaultColumnWidth(16);//列宽 + HSSFCellStyle cellStyle = workbook.createCellStyle(); + cellStyle.setWrapText(true);//自动换行 + cellStyle.setAlignment(HorizontalAlignment.CENTER);//垂直居中 + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//水平居中 + + HSSFCellStyle cellStyleTemp = workbook.createCellStyle(); + cellStyleTemp.setWrapText(true);//自动换行 + + + int count = 1; + int startLine = 0; + int endLine = 0; + int line = 4; + for (int i = 0; i < index; i++) { + //合并单元格 + CellRangeAddress region1 = + new CellRangeAddress(0, 1, i, i); + sheet.addMergedRegion(region1); + } + for (int i = index; i < 15; i++) { + if(count > 1){ + startLine = startLine + line + 1; + endLine = startLine + line; + }else{ + startLine = i; + endLine = i + line; + } + //合并单元格 + CellRangeAddress region1 = + new CellRangeAddress(0, 0, startLine, endLine); //参数1:起始行 参数2:终止行 参数3:起始列 参数4:终止列 + sheet.addMergedRegion(region1); + count ++; + } + CellRangeAddress region = + new CellRangeAddress(2, 2, 0, 25); //参数1:起始行 参数2:终止行 参数3:起始列 参数4:终止列 + sheet.addMergedRegion(region); + String explain= ""; + if(CutEnum.CN.getValue().equals(projectLawsInventoryEO.getCut())){ + explain = "填写说明\n" + + "1.导入数据从第四行开始\n" + + "2.所有带*号的字段必须填写\n"+ + "3.认证类型,认证级别,实施类别,交付物类型,发起人,责任人,字段是单选属性,必须和系统中的对应字段选项相匹配\n" + + "4.责任领域,字段是多选属性,必须和系统中的对应字段选项相匹配,填写多个时采用英文或中文逗号分割\n" + + "5.编号,子标题,WVTA ID,备注,填写文本内容\n" + + "6.交付物模板字段为文件属性,填写时需要在本文件同级目录下以标准号为名称建立文件夹,并在文件夹下放置文件,假设在AAA标准号下放置了B.docx,则应填写AAA/B.docx"; + }else{ + explain = "filling explanation\n" + + "1.import data starts at the fourth line\n" + + "2.all fields marked with * must be filled in\n"+ + "3.certification type,certification level,implementation category,type of deliverables,initiator,person liable,Fields are radio attributes that must match the corresponding field option in the system\n" + + "4.area of responsibility, field is a multi-select attribute and must match the corresponding field in the system. If multiple fields are filled in, separate them by commas (,)\n" + + "5.serial number,subtitle,WVTA ID,remarks,Fill in the text\n" + + "6.deliverable template,When filling in the field, you need to create a folder in the directory of the same level as the file with the name of the standard number and place the file in the folder. If b. diocx is stored under the AAA standard number, enter AAA/B. diocx"; + } + + + for (int i = 0; i < 3; i++) { + //表头 + Row row = sheet.createRow(i);//开始创建标题行 + String[] headerArr = titleOne.split(","); + int lineTemp = index; + if (i == 0) { + for (int m = 0; m < headerArr.length; m++) { + if(m < index){ + row.createCell(m).setCellValue(headerArr[m]); + }else{ + row.createCell(lineTemp).setCellValue(headerArr[m]); + Cell cell = row.getCell(lineTemp); + cell.setCellStyle(cellStyle); + lineTemp = lineTemp + 5; + } + } + + }else if(i == 1){ + //titleTwo + String[] headerArrTwo = titleTwo.split(","); + for (int j = 0; j < headerArrTwo.length; j++) { + row.createCell(11+j).setCellValue(headerArrTwo[j]); + } + }else{ + short height = (short) (7 * 252); + row.setHeight((short) height); + Cell cell = row.createCell(0); + cell.setCellStyle(cellStyleTemp); + cell.setCellValue(new HSSFRichTextString(explain)); + } + } + response.setHeader("Content-Disposition", + "attachment; filename=\"" + fileOriName + ".xls"); + response.setContentType("application/force-download"); + response.flushBuffer(); + os = response.getOutputStream(); + workbook.write(os); + } catch (Exception e) { + e.printStackTrace(); + throw new JeroBootException("下载文件失败,请重试"); + } finally { + IOUtils.closeQuietly(os); + } + + } + + @Override + public void exportData(HttpServletResponse response, HttpServletRequest request, ProjectLawsInventoryEO projectLawsInventoryEO) { + + } + + @Override + public void importData(MultipartFile file, ProjectLawsInventoryEO projectLawsInventoryEO) { } }