commit
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<Sys_file> 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -193,9 +193,9 @@ layout("/layouts/platform.html"){
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="files" label="请示附件" class="is-required">
|
||||
<file-upload :max="1" :files.sync="formData.files">
|
||||
<file-upload :max="10" :files.sync="formData.files">
|
||||
<template #el-upload__tip>
|
||||
<div class="el-upload__tip" slot="tip">图片类请上传jpg/png/jpeg等格式,文档类请上传doc/docx/xls/xlsx/pdf等格式,上传数量为1个</div>
|
||||
<div class="el-upload__tip" slot="tip">图片类请上传jpg/png/jpeg等格式,文档类请上传doc/docx/xls/xlsx/pdf等格式,上传数量为10个</div>
|
||||
</template>
|
||||
</file-upload>
|
||||
</el-form-item>
|
||||
|
||||
@@ -148,6 +148,9 @@ layout("/layouts/platform.html"){
|
||||
<el-dropdown-item :command="{type:'view',data:scope.row}">
|
||||
预览
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type:'download',data:scope.row}">
|
||||
下载
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
v-if="(${@shiro.hasRole('sysadmin')||@shiro.hasRole('A06')}) || scope.row.state == 0"
|
||||
:command="{type:'edit',data:scope.row}">
|
||||
@@ -217,7 +220,13 @@ layout("/layouts/platform.html"){
|
||||
</template>
|
||||
</el-form-item>-->
|
||||
<el-form-item prop="files" label="附件上传">
|
||||
<file-upload :files.sync="formData.files"></file-upload>
|
||||
<file-upload :files.sync="formData.files">
|
||||
<template #el-upload__tip>
|
||||
<div class="el-upload__tip" slot="tip">
|
||||
图片类请上传jpg/png/jpeg等格式,文档类请上传doc/docx/xls/xlsx/pdf等格式,压缩包请上传zip/war,上传数量为10个
|
||||
</div>
|
||||
</template>
|
||||
</file-upload>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-form>
|
||||
@@ -266,7 +275,13 @@ layout("/layouts/platform.html"){
|
||||
</el-form-item>-->
|
||||
|
||||
<el-form-item prop="files" label="附件上传">
|
||||
<file-upload :files.sync="formData.files"></file-upload>
|
||||
<file-upload :files.sync="formData.files" :max="10">
|
||||
<template #el-upload__tip>
|
||||
<div class="el-upload__tip" slot="tip">
|
||||
图片类请上传jpg/png/jpeg等格式,文档类请上传doc/docx/xls/xlsx/pdf等格式,压缩包请上传zip/war,上传数量为10个
|
||||
</div>
|
||||
</template>
|
||||
</file-upload>
|
||||
</el-form-item>
|
||||
|
||||
</el-form>
|
||||
@@ -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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user