diff --git a/src/main/java/io/v/nutz/wakershome/controller/data/WakesHomeDataRevelController.java b/src/main/java/io/v/nutz/wakershome/controller/data/WakesHomeDataRevelController.java index 92de922..4f4e94d 100644 --- a/src/main/java/io/v/nutz/wakershome/controller/data/WakesHomeDataRevelController.java +++ b/src/main/java/io/v/nutz/wakershome/controller/data/WakesHomeDataRevelController.java @@ -14,10 +14,13 @@ import io.v.nutz.sys.models.Sys_user_role; import io.v.nutz.sys.models.User; import io.v.nutz.wakershome.model.WakesHomeDataRevel; import io.v.nutz.wakershome.service.WakesHomeInfoService; +import io.v.nutz.web.commons.utils.FileUtil; import io.v.nutz.web.commons.utils.ShiroUtil; +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; +import org.nutz.boot.starter.ftp.FtpService; import org.nutz.dao.Cnd; import org.nutz.dao.Dao; import org.nutz.dao.Sqls; @@ -26,6 +29,7 @@ import org.nutz.dao.sql.Sql; import org.nutz.ioc.aop.Aop; import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.lang.Lang; import org.nutz.lang.random.R; import org.nutz.lang.util.NutMap; import org.nutz.mvc.annotation.At; @@ -34,6 +38,9 @@ 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.Set; import java.util.stream.Collectors; @@ -56,6 +63,9 @@ public class WakesHomeDataRevelController { @Inject private WakesHomeInfoService wakesHomeInfoService; + @Inject + private FtpService ftpsService; + @At("") @Ok("beetl:/platform/wakeshome/data/revel.html") @RequiresPermissions("wakeshome.data.revel") @@ -202,14 +212,96 @@ public class WakesHomeDataRevelController { response.reset(); response.setContentType("application/x-msdownload;charset=utf-8"); - /** - * 创建临时文件夹 - */ + // 创建临时文件夹 String tmpPath = "tmp/" + R.UU32(); File tmpDir = new File(tmpPath + "/" + unionName + "附件汇总"); tmpDir.mkdirs(); List query = dao.query(WakesHomeDataRevel.class, Cnd.where("belongToUnionId", "=", unionId)); + try { + if (Lang.isNotEmpty(query)) { + for (WakesHomeDataRevel revel : query) { + // 创建资料名称的文件夹 + String fileName = revel.getRevelName(); + + File tDir = new File(tmpDir + "/" + fileName); + tDir.mkdirs(); + + if (Lang.isNotEmpty(revel.getFiles())) { + for (Sys_file file : revel.getFiles()) { + FileOutputStream outputStream = new FileOutputStream(tDir.getPath() + "/" + file.getFilename()); + ftpsService.download(file.getFilepath(), outputStream); + outputStream.close(); + } + } + } + + String aimsDir = "zipTmp/" + R.UU32(); + String aimsName = unionName + "附件汇总.zip"; + String aimsPath = aimsDir + "/" + aimsName; + FileUtil.compressToZip(tmpDir.getPath(), aimsDir, aimsName); + + response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(aimsName, "UTF-8")); + + File aimsFile = new File(aimsPath); + FileInputStream inputStream = new FileInputStream(aimsFile); + IOUtils.copy(inputStream, response.getOutputStream()); + inputStream.close(); + aimsFile.delete(); + + FileUtil.deleteDir(new File(tmpPath)); + FileUtil.deleteDir(new File(aimsDir)); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @At + @Ok("void") + @RequiresPermissions("wakeshome.data.revel") + public void exportAllFileById(String id, HttpServletResponse response) { + response.reset(); + response.setContentType("application/x-msdownload;charset=utf-8"); + + WakesHomeDataRevel dataRevel = dao.fetch(WakesHomeDataRevel.class, Cnd.where("id", "=", id)); + + // 创建临时文件夹 + String tmpPath = "tmp/" + R.UU32(); + File tmpDir = new File(tmpPath + "/" + dataRevel.getBelongToUnionName() + dataRevel.getRevelName() + "附件汇总"); + tmpDir.mkdirs(); + + try { + + if (Lang.isNotEmpty(dataRevel.getFiles())) { + for (Sys_file file : dataRevel.getFiles()) { + FileOutputStream outputStream = new FileOutputStream(tmpDir.getPath() + "/" + file.getFilename()); + ftpsService.download(file.getFilepath(), outputStream); + outputStream.close(); + } + } + + String aimsDir = "zipTmp/" + R.UU32(); + String aimsName = dataRevel.getBelongToUnionName() + dataRevel.getRevelName() + "附件汇总.zip"; + String aimsPath = aimsDir + "/" + aimsName; + FileUtil.compressToZip(tmpDir.getPath(), aimsDir, aimsName); + + response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(aimsName, "UTF-8")); + + File aimsFile = new File(aimsPath); + FileInputStream inputStream = new FileInputStream(aimsFile); + IOUtils.copy(inputStream, response.getOutputStream()); + inputStream.close(); + aimsFile.delete(); + + FileUtil.deleteDir(new File(tmpPath)); + FileUtil.deleteDir(new File(aimsDir)); + + } catch (Exception e) { + e.printStackTrace(); + } } } diff --git a/src/main/resources/views/platform/wakeshome/data/revel.html b/src/main/resources/views/platform/wakeshome/data/revel.html index d384973..d5c8829 100644 --- a/src/main/resources/views/platform/wakeshome/data/revel.html +++ b/src/main/resources/views/platform/wakeshome/data/revel.html @@ -81,7 +81,7 @@ layout("/layouts/platform.html"){ @@ -102,13 +102,17 @@ layout("/layouts/platform.html"){ - 预览 + 预览资料 编辑 + + 导出附件 + @@ -140,8 +144,8 @@ layout("/layouts/platform.html"){ - - + + @@ -167,9 +171,9 @@ layout("/layouts/platform.html"){ - 取 消 - 确 定 - + 取 消 + 确 定 + @@ -177,6 +181,9 @@ layout("/layouts/platform.html"){ + + + @@ -191,7 +198,12 @@ layout("/layouts/platform.html"){ - + + + +
可上传照片、文档等资料
@@ -288,6 +300,8 @@ layout("/layouts/platform.html"){ const url = '/platform/wakeshome/data/revel/exportAllFileByUnionId?unionId=' + unionId + '&unionName=' + unionName window.open(url) }, + exportAllFileById(data) { + window.open('/platform/wakeshome/data/revel/exportAllFileById?id=' + data.id) }, async handleNodeClick(data, node) { this.checkData = data @@ -312,8 +326,8 @@ layout("/layouts/platform.html"){ this.openEdit(data) } else if (type === 'delete') { this.doDelete(data.id) - } else if (type === 'audit') { - this.doAudit(data.id) + } else if (type === 'download') { + this.exportAllFileById(data) } }, doDelete(id) {