diff --git a/src/main/java/io/v/nutz/jdh/controller/two/Jdh2GzzlglController.java b/src/main/java/io/v/nutz/jdh/controller/two/Jdh2GzzlglController.java index 63ee6ff..8118a92 100644 --- a/src/main/java/io/v/nutz/jdh/controller/two/Jdh2GzzlglController.java +++ b/src/main/java/io/v/nutz/jdh/controller/two/Jdh2GzzlglController.java @@ -13,6 +13,8 @@ import io.v.nutz.sys.models.Sys_file; import io.v.nutz.sys.models.Sys_union; import io.v.nutz.sys.models.Sys_user_role; import io.v.nutz.util.ShiroUtil; +import io.v.nutz.web.commons.utils.FileUtil; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.nutz.aop.interceptor.ioc.TransAop; @@ -33,6 +35,11 @@ import org.nutz.mvc.annotation.At; import org.nutz.mvc.annotation.Ok; import org.nutz.mvc.annotation.Param; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.net.URLEncoder; import java.util.List; import java.util.stream.Collectors; @@ -73,9 +80,9 @@ public class Jdh2GzzlglController { @At @ViReturn @RequiresPermissions("sys.jdh2.gzzl.gl") - public Object getTreeData(@Param(value = "year",required = false) String year, - @Param(value = "jdhid",required = false) String jdhid, - @Param(value = "zllx",required = false) String zllx) { + public Object getTreeData(@Param(value = "year", required = false) String year, + @Param(value = "jdhid", required = false) String jdhid, + @Param(value = "zllx", required = false) String zllx) { NutMap nutMap = NutMap.NEW(); nutMap.setv("unionname", "工会委员会"); Sql sql = Sqls.create(""" @@ -114,15 +121,15 @@ public class Jdh2GzzlglController { @At @RequiresPermissions("sys.jdh2.gzzl.gl") - public Object pageData(@Param(value = "pageNumber",required = false) Integer pageNumber, - @Param(value = "pageSize",required = false) Integer pageSize, - @Param(value = "pageOrderName",required = false) String pageOrderName, - @Param(value = "pageOrderBy",required = false) String pageOrderBy, - @Param(value = "year",required = false) String year, - @Param(value = "zlname",required = false) String zlname, - @Param(value = "jdhid",required = false) String jdhid, - @Param(value = "zllx",required = false) String zllx, - @Param(value = "unionId",required = false) String unionId) { + public Object pageData(@Param(value = "pageNumber", required = false) Integer pageNumber, + @Param(value = "pageSize", required = false) Integer pageSize, + @Param(value = "pageOrderName", required = false) String pageOrderName, + @Param(value = "pageOrderBy", required = false) String pageOrderBy, + @Param(value = "year", required = false) String year, + @Param(value = "zlname", required = false) String zlname, + @Param(value = "jdhid", required = false) String jdhid, + @Param(value = "zllx", required = false) String zllx, + @Param(value = "unionId", required = false) String unionId) { try { Sql sql = Sqls.create(""" SELECT @@ -249,4 +256,56 @@ public class Jdh2GzzlglController { dao.updateIgnoreNull(jdhLevel2); return null; } + + @At + @Ok("void") + @RequiresPermissions("sys.jdh2.gzzl.gl") + public void doDownload(String id, HttpServletResponse response) { + + try { + Jdh2_gzzl gzzl = dao.fetch(Jdh2_gzzl.class, id); + + response.reset(); + response.setContentType("application/x-msdownload;charset=utf-8"); + String fileName = gzzl.getUsername() + "_" + gzzl.getZlname(); + /** + * 创建临时文件夹 + */ + String tmpPath = "tmp/" + R.UU32(); + File tmpDir = new File(tmpPath + "/" + fileName); + tmpDir.mkdirs(); + + List files = gzzl.getFiles(); + if (files != null) { + for (Sys_file file : files) { + File targetFile = new File(tmpDir, file.getFilename()); + try (FileOutputStream outputStream = new FileOutputStream(targetFile)) { + ftpService.download(file.getFilepath(), outputStream); + } + } + } +// 压缩到zip文件 + String zipFileName = fileName + ".zip"; + String zipFilePath = tmpPath + "/" + zipFileName; + FileUtil.compressToZip(tmpDir.getPath(), tmpPath, zipFileName); + + response.setHeader("content-disposition", "attachment;filename=" + + URLEncoder.encode(zipFileName, "UTF-8")); + +// 读取并输出zip文件 + File zipFile = new File(zipFilePath); + try (FileInputStream inputStream = new FileInputStream(zipFile)) { + IOUtils.copy(inputStream, response.getOutputStream()); + } + +// 清理临时文件 + FileUtil.deleteDir(new File(tmpPath)); // 删除整个临时目录 + + + } catch (Exception e) { + e.printStackTrace(); + } + + + } } diff --git a/src/main/resources/static/components/plugins/FileUpload.vue b/src/main/resources/static/components/plugins/FileUpload.vue index d62b004..4f55530 100644 --- a/src/main/resources/static/components/plugins/FileUpload.vue +++ b/src/main/resources/static/components/plugins/FileUpload.vue @@ -459,7 +459,7 @@ module.exports = { files: Array, type: { type: Array, - default: ['jpg', 'jpeg', 'png', 'doc', 'docx', 'xls', 'xlsx', 'pdf'] + default: ['jpg', 'jpeg', 'png', 'doc', 'docx', 'xls', 'xlsx', 'pdf', 'zip', 'war'] }, max: { type: Number, @@ -768,4 +768,4 @@ module.exports = { line-height: 0; } - \ No newline at end of file + diff --git a/src/main/resources/static/components/plugins/ImageUpload.vue b/src/main/resources/static/components/plugins/ImageUpload.vue index aafa702..9da8b47 100644 --- a/src/main/resources/static/components/plugins/ImageUpload.vue +++ b/src/main/resources/static/components/plugins/ImageUpload.vue @@ -239,4 +239,4 @@ module.exports = { .el-upload__tip { text-align: left; } - \ No newline at end of file + diff --git a/src/main/resources/views/platform/jdh/two/apply.html b/src/main/resources/views/platform/jdh/two/apply.html index 26797ad..15d100f 100644 --- a/src/main/resources/views/platform/jdh/two/apply.html +++ b/src/main/resources/views/platform/jdh/two/apply.html @@ -193,9 +193,9 @@ layout("/layouts/platform.html"){ - + diff --git a/src/main/resources/views/platform/jdh/two/zlgl.html b/src/main/resources/views/platform/jdh/two/zlgl.html index 6b9f215..fcc4244 100644 --- a/src/main/resources/views/platform/jdh/two/zlgl.html +++ b/src/main/resources/views/platform/jdh/two/zlgl.html @@ -148,6 +148,9 @@ layout("/layouts/platform.html"){ 预览 + + 下载 + @@ -217,7 +220,13 @@ layout("/layouts/platform.html"){ --> - + + + @@ -266,7 +275,13 @@ layout("/layouts/platform.html"){ --> - + + + @@ -416,8 +431,14 @@ layout("/layouts/platform.html"){ this.openEdit(data) } else if (type == 'delete') { this.doDelete(data.id) + }else if (type == 'download') { + this.doDownload(data.id) } }, + doDownload(id){ + window.location.href = "/platform/jdh2/gzzlgl/doDownload?id=" + id + + }, handleChange: function (file, filelist) { this.fileList = filelist; }, @@ -454,7 +475,7 @@ layout("/layouts/platform.html"){ const formData = clone(this.formData) formData.files = JSON.stringify(formData.files) const resp = await $.post('/platform/jdh2/gzzlgl/doEdit', formData) - if (resp.code===0){ + if (resp.code === 0) { this.editDialogVisible = false this.doSearch() } @@ -518,7 +539,7 @@ layout("/layouts/platform.html"){ formData.files = JSON.stringify(formData.files) const resp = await $.post('/platform/jdh2/gzzlgl/doAdd', formData) - if (resp.code===0){ + if (resp.code === 0) { this.addDialogVisible = false this.doSearch() loading.close()