From 0f9e6d8e94faf445fa025ac96a688b73cb24bcee Mon Sep 17 00:00:00 2001 From: dingbingqing Date: Fri, 10 Mar 2023 10:55:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A4=E8=AF=81=E8=99=9A=E6=8B=9F=E6=B8=85?= =?UTF-8?q?=E5=8D=95=E6=A8=A1=E6=9D=BF=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuthDummyInventoryInfoEOController.java | 9 + .../IAuthDummyInventoryInfoEOService.java | 12 ++ .../AuthDummyInventoryInfoEOServiceImpl.java | 179 ++++++++++++++++++ 3 files changed, 200 insertions(+) diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/authDummy/controller/AuthDummyInventoryInfoEOController.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/authDummy/controller/AuthDummyInventoryInfoEOController.java index 267283442..6169bfe99 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/authDummy/controller/AuthDummyInventoryInfoEOController.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/authDummy/controller/AuthDummyInventoryInfoEOController.java @@ -13,8 +13,10 @@ import com.jero.modules.authDummy.service.IAuthDummyInventoryInfoEOService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.jero.modules.dummy.entity.DummyInventoryInfoEO; import lombok.extern.slf4j.Slf4j; import com.jero.common.system.base.controller.JeroController; +import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -191,4 +193,11 @@ public class AuthDummyInventoryInfoEOController extends JeroController batchAdd(@RequestBody JSONObject json) { return this.authDummyInventoryInfoEOService.batchAdd(json); } + + @ApiOperation(value = "模板下载") + @GetMapping(value = "/exportTemplate") +// @RequiresPermissions("authDummyInventoryInfo:exportTemplate") + public void exportTemplate(AuthDummyInventoryInfoEO authDummyInventoryInfoEO, HttpServletResponse response, HttpServletRequest request) throws Exception { + authDummyInventoryInfoEOService.exportTemplate(authDummyInventoryInfoEO,response,request); + } } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/authDummy/service/IAuthDummyInventoryInfoEOService.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/authDummy/service/IAuthDummyInventoryInfoEOService.java index 81ad84b8f..27ea1b30e 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/authDummy/service/IAuthDummyInventoryInfoEOService.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/authDummy/service/IAuthDummyInventoryInfoEOService.java @@ -4,6 +4,10 @@ import com.alibaba.fastjson.JSONObject; import com.jero.common.api.vo.Result; import com.jero.modules.authDummy.entity.AuthDummyInventoryInfoEO; import com.baomidou.mybatisplus.extension.service.IService; +import com.jero.modules.dummy.entity.DummyInventoryInfoEO; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.List; /** @@ -82,4 +86,12 @@ public interface IAuthDummyInventoryInfoEOService extends IService batchAdd(JSONObject json); + + /** + * 模板下载 + * @param authDummyInventoryInfoEO + * @param response + * @param request + */ + void exportTemplate(AuthDummyInventoryInfoEO authDummyInventoryInfoEO, HttpServletResponse response, HttpServletRequest request); } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/authDummy/service/impl/AuthDummyInventoryInfoEOServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/authDummy/service/impl/AuthDummyInventoryInfoEOServiceImpl.java index bd78fe5bb..646b9c8dc 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/authDummy/service/impl/AuthDummyInventoryInfoEOServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/authDummy/service/impl/AuthDummyInventoryInfoEOServiceImpl.java @@ -2,6 +2,7 @@ package com.jero.modules.authDummy.service.impl; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.aliyuncs.utils.IOUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.jero.common.api.vo.Result; import com.jero.common.constant.enums.CutEnum; @@ -11,11 +12,24 @@ import com.jero.modules.authDummy.entity.AuthDummyInventoryInfoEO; import com.jero.modules.authDummy.mapper.AuthDummyInventoryInfoEOMapper; import com.jero.modules.authDummy.service.IAuthDummyInventoryBaseEOService; import com.jero.modules.authDummy.service.IAuthDummyInventoryInfoEOService; +import com.jero.modules.dummy.entity.DummyInventoryInfoEO; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; +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.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.HorizontalAlignment; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.VerticalAlignment; +import org.apache.poi.ss.util.CellRangeAddress; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.io.File; +import java.io.OutputStream; import java.util.*; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -23,6 +37,9 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + /** * @Description: 认证虚拟清单详情表 * @Author: jero-boot @@ -36,6 +53,8 @@ public class AuthDummyInventoryInfoEOServiceImpl extends ServiceImpl list = Arrays.asList(titleOne.split(",")); + int index = 0; + if(CutEnum.CN.getValue().equals(authDummyInventoryInfoEO.getCut())){ + index = list.indexOf("备注") + 1; + }else{ + index = list.indexOf("Comments") + 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 < 12; 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, 23); //参数1:起始行 参数2:终止行 参数3:起始列 参数4:终止列 + sheet.addMergedRegion(region); +// String explain= ""; +// if(CutEnum.CN.getValue().equals(authDummyInventoryInfoEO.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.Implementation category,Type of deliverables,Initiator,Person liable,Fields are radio attributes that must match the corresponding field option in the system\n" + +// "4.Certification Type,Certification Level,Responsible Field, 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.Number,Sub-Title,WVTA ID,Comments,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(9+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); + } + + } }