diff --git a/hw-modules/hw-dms/pom.xml b/hw-modules/hw-dms/pom.xml index 2138820..9872b70 100644 --- a/hw-modules/hw-dms/pom.xml +++ b/hw-modules/hw-dms/pom.xml @@ -87,6 +87,11 @@ com.hw hw-api-system + + net.sf.jxls + jxls-core + 1.0.3 + diff --git a/hw-modules/hw-dms/src/main/java/com/hw/dms/controller/DmsBillsFaultInstanceController.java b/hw-modules/hw-dms/src/main/java/com/hw/dms/controller/DmsBillsFaultInstanceController.java index ff776d6..68df1c8 100644 --- a/hw-modules/hw-dms/src/main/java/com/hw/dms/controller/DmsBillsFaultInstanceController.java +++ b/hw-modules/hw-dms/src/main/java/com/hw/dms/controller/DmsBillsFaultInstanceController.java @@ -6,9 +6,8 @@ import java.util.List; import java.io.IOException; import java.util.Map; import javax.servlet.http.HttpServletResponse; - -import com.hw.dms.TemplateExcelUtils; import com.hw.dms.domain.DmsFaultInstanceActivity; +import com.hw.dms.utils.TemplateExcelUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; diff --git a/hw-modules/hw-dms/src/main/java/com/hw/dms/domain/DmsFaultCompentsParts.java b/hw-modules/hw-dms/src/main/java/com/hw/dms/domain/DmsFaultCompentsParts.java new file mode 100644 index 0000000..3ca7f02 --- /dev/null +++ b/hw-modules/hw-dms/src/main/java/com/hw/dms/domain/DmsFaultCompentsParts.java @@ -0,0 +1,12 @@ +package com.hw.dms.domain; + +import lombok.Data; + +@Data +public class DmsFaultCompentsParts { + private Long compentsPartsId; + private Long faultId; + private String partName; + private String partSpecifications; + private Integer amount; +} diff --git a/hw-modules/hw-dms/src/main/java/com/hw/dms/utils/TemplateExcelUtils.java b/hw-modules/hw-dms/src/main/java/com/hw/dms/utils/TemplateExcelUtils.java new file mode 100644 index 0000000..aa4a525 --- /dev/null +++ b/hw-modules/hw-dms/src/main/java/com/hw/dms/utils/TemplateExcelUtils.java @@ -0,0 +1,63 @@ +package com.hw.dms.utils; + + +import net.sf.jxls.transformer.XLSTransformer; +import org.apache.poi.ss.usermodel.Workbook; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URLEncoder; +import java.util.Map; + +public class TemplateExcelUtils { + + /** + * 根据模板导出数据 + * @param fileName + * @param sourcePath resource/template文件夹下路径 + * @param beanParams + * @param response + * @throws Exception + */ + public static void downLoadExcel(String fileName,String sourcePath, Map beanParams, HttpServletResponse response) + throws Exception { + try{ + OutputStream os = getOutputStream(fileName,response); + //读取模板 + InputStream is = TemplateExcelUtils.class.getResourceAsStream("/weixiu.xlsx"); + XLSTransformer transformer = new XLSTransformer(); +// beanParams.put("title","titl"); + //向模板中写入内容 + Workbook workbook = transformer.transformXLS(is, beanParams); + //写入成功后转化为输出流 + workbook.write(os); + }catch (Exception e){ + e.printStackTrace(); + throw e; + } + } + + /** + * 导出文件时为Writer生成OutputStream. + * @param fileName 文件名 + * @param response response + * @return "" + */ + private static OutputStream getOutputStream(String fileName, + HttpServletResponse response) throws Exception { + try { + fileName = URLEncoder.encode(fileName, "UTF-8"); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("utf8"); + response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xls"); + response.setHeader("Pragma", "public"); + response.setHeader("Cache-Control", "no-store"); + response.addHeader("Cache-Control", "max-age=0"); + return response.getOutputStream(); + } catch (IOException e) { + throw new Exception("导出excel表格失败!", e); + } + } +} diff --git a/hw-modules/hw-dms/src/main/resources/weixiu.xlsx b/hw-modules/hw-dms/src/main/resources/weixiu.xlsx new file mode 100644 index 0000000..a61e6fa Binary files /dev/null and b/hw-modules/hw-dms/src/main/resources/weixiu.xlsx differ