From 7412b917b674d2d541acae9f4333acbb5b1c5033 Mon Sep 17 00:00:00 2001 From: FLYPHT <1035748121@qq.com> Date: Sat, 17 Sep 2022 20:13:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spring/controller/FileDownloadController.java | 6 ++++-- .../system/bpm/web/sys/base/dict/DictService.java | 24 +++++++++++++++++++++- .../static/event/bpm/sys/base/dict/dictList.js | 8 ++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/FileDownloadController.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/FileDownloadController.java index 6e3df50..c8401d6 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/FileDownloadController.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/FileDownloadController.java @@ -38,10 +38,11 @@ public class FileDownloadController { @GetMapping("/fs/files/**") public ResponseEntity files(@RequestParam(value = "name", required = false) String name, @RequestParam(value = "noCache", required = false) Boolean noCache, + @RequestParam(value = "absolutePath", required = false) Boolean absolutePath, HttpServletRequest request ) throws FileNotFoundException { String filePath = request.getRequestURI().substring(10); - return download(filePath, name, noCache, request); + return download(filePath, name, noCache,absolutePath, request); } /** @@ -51,9 +52,10 @@ public class FileDownloadController { public ResponseEntity download(@RequestParam(value = "path") String path, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "noCache", required = false) Boolean noCache, + @RequestParam(value = "absolutePath", required = false) Boolean absolutePath, HttpServletRequest request ) throws FileNotFoundException { - File file = new File(filePathGenerator.getFileDiskPath(path)); + File file = new File(absolutePath? path:filePathGenerator.getFileDiskPath(path)); if (!file.exists()) { return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictService.java index 15ab778..23d6f33 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictService.java @@ -1,9 +1,18 @@ package cc.smtweb.system.bpm.web.sys.base.dict; +import cc.smtweb.framework.core.annotation.SwBody; import cc.smtweb.framework.core.annotation.SwService; +import cc.smtweb.framework.core.common.R; +import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.mvc.service.AbstractHandler; +import cc.smtweb.framework.core.session.UserSession; +import cc.smtweb.system.bpm.web.engine.dynPage.DynPageLoadHandler; import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; +import java.io.File; +import java.io.FileOutputStream; +import java.nio.charset.StandardCharsets; + /** * Created by 1 at 2022-07-28 09:23:54 * 页面【[数据字典]的服务类 @@ -19,5 +28,18 @@ public class DictService extends DynPageService { } return super.createHandler(type); } - + //新增 + public R exportExcel(@SwBody SwMap params, UserSession us) { + try { + File tempFile = File.createTempFile("xls_", ".txt", new File(System.getProperty("java.io.tmpdir"))); + FileOutputStream fs = new FileOutputStream(tempFile); + fs.write("flypht-唐海鹏".getBytes(StandardCharsets.UTF_8)); + SwMap swMap = new SwMap(); + swMap.put("fileName",tempFile.getName()); + swMap.put("filePath",tempFile.getAbsolutePath()); + return R.success(swMap); + }catch (Exception e){ + return R.error("导出失败!"); + } + } } diff --git a/smtweb-framework/bpm/src/main/resources/static/event/bpm/sys/base/dict/dictList.js b/smtweb-framework/bpm/src/main/resources/static/event/bpm/sys/base/dict/dictList.js index a0e46f8..2327a8a 100644 --- a/smtweb-framework/bpm/src/main/resources/static/event/bpm/sys/base/dict/dictList.js +++ b/smtweb-framework/bpm/src/main/resources/static/event/bpm/sys/base/dict/dictList.js @@ -14,9 +14,17 @@ window.$swEvent.setup("bpm.sys.base.dict.dictList", { const afterDelDict = () => { $api.loadOne("dictList"); }; + const exportExcel = () => { + $$http.post("bpm/dict/exportExcel").then( (rt) => { + console.info("exportExcel:",rt); + const url = $$http.downloadFileUrl(rt.data.filePath,rt.data.fileName,true); + $$http.downloadFile(url,{fileName: rt.data.fileName}); + }); + } return { afterDelDictType, afterDelDict, + exportExcel, } } });