From e2f50b32e6d65dee29d3f4f9e16772da24d92de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E7=91=9E=E8=B6=85?= <281809423@qq.com> Date: Tue, 3 Nov 2020 18:25:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=90=8C=E5=A2=9E=E5=8A=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8D=E7=A7=B0=E5=AD=97=E6=AE=B5=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=8B=E8=BD=BD=E9=99=84=E4=BB=B6=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/common/CommonController.java | 32 +++++++++++++++++++ .../src/main/resources/application.yml | 4 +-- .../main/resources/static/ruoyi/js/common.js | 2 +- .../ruoyi/front/domain/ContractTemplate.java | 13 +++++++- .../mapper/front/ContractTemplateMapper.xml | 6 +++- .../front/contract_template/edit.html | 1 + .../front/contract_template/template.html | 7 ++-- sql/business_20201010.sql | 3 +- 8 files changed, 59 insertions(+), 9 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java index 9b2a6af8c..24d0c07f5 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java @@ -110,4 +110,36 @@ public class CommonController FileUtils.writeBytes(downloadPath, response.getOutputStream()); } + + /** + * 通用下载请求 + * + * @param filePath 文件路径 + * @param realFileName 文件名称 + * @param delete 是否删除 + */ + @GetMapping("common/download2") + public void fileDownload(String filePath, String realFileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) + { + try + { + if (!FileUtils.isValidFilename(realFileName)) + { + throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", realFileName)); + } + + response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); + FileUtils.setAttachmentResponseHeader(response, realFileName); + + FileUtils.writeBytes(filePath, response.getOutputStream()); + if (delete) + { + FileUtils.deleteFile(filePath); + } + } + catch (Exception e) + { + log.error("下载文件失败", e); + } + } } diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index e46f8be01..7e2a33fe7 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -96,9 +96,9 @@ shiro: # 首页地址 indexUrl: /index # 验证码开关 - captchaEnabled: true + captchaEnabled: false # 验证码类型 math 数组计算 char 字符 - captchaType: math + captchaType: char cookie: # 设置Cookie的域名 默认空,即当前访问的域名 domain: diff --git a/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js b/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js index 06e0c90dd..26a5603e5 100644 --- a/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js +++ b/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js @@ -482,7 +482,7 @@ function uploadFile(async, filePathId, fileNameId) { $('#' + filePathId).val(result.url); } if (fileNameId) { - $('#' + fileNameId).val(result.fileName); + $('#' + fileNameId).val(result.originalFilename); } } else { diff --git a/ruoyi-front/src/main/java/com/ruoyi/front/domain/ContractTemplate.java b/ruoyi-front/src/main/java/com/ruoyi/front/domain/ContractTemplate.java index e10e448c9..83c1bdc54 100644 --- a/ruoyi-front/src/main/java/com/ruoyi/front/domain/ContractTemplate.java +++ b/ruoyi-front/src/main/java/com/ruoyi/front/domain/ContractTemplate.java @@ -39,9 +39,12 @@ public class ContractTemplate extends BaseEntity private Integer hits; /** 附件下载(多个地址用,分隔) */ - @Excel(name = "附件下载", readConverterExp = "多=个地址用,分隔") + @Excel(name = "附件地址") private String enclosureUrl; + @Excel(name = "附件名称") + private String enclosureName; + /** 状态(0正常 1停用) */ @Excel(name = "状态", readConverterExp = "0=正常,1=停用") private String status; @@ -131,6 +134,14 @@ public class ContractTemplate extends BaseEntity return delFlag; } + public String getEnclosureName() { + return enclosureName; + } + + public void setEnclosureName(String enclosureName) { + this.enclosureName = enclosureName; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-front/src/main/resources/mapper/front/ContractTemplateMapper.xml b/ruoyi-front/src/main/resources/mapper/front/ContractTemplateMapper.xml index 832d1c261..063af4fd3 100644 --- a/ruoyi-front/src/main/resources/mapper/front/ContractTemplateMapper.xml +++ b/ruoyi-front/src/main/resources/mapper/front/ContractTemplateMapper.xml @@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -22,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, type, title, introduction, content, hits, enclosure_url, status, del_flag, create_by, create_time, update_by, update_time, remark from contract_template + select id, type, title, introduction, content, hits,enclosure_name, enclosure_url, status, del_flag, create_by, create_time, update_by, update_time, remark from contract_template +
diff --git a/ruoyi-front/src/main/resources/templates/front/contract_template/template.html b/ruoyi-front/src/main/resources/templates/front/contract_template/template.html index 0f496c3ae..5a220eb48 100644 --- a/ruoyi-front/src/main/resources/templates/front/contract_template/template.html +++ b/ruoyi-front/src/main/resources/templates/front/contract_template/template.html @@ -126,7 +126,7 @@ actions.push('编辑 '); actions.push('删除'); if (row.enclosureUrl) { - actions.push('下载附件'); + actions.push('下载附件'); } return actions.join(''); } @@ -135,8 +135,9 @@ $.table.init(options); }); - function downLoad(url) { - window.location.href = ctx + "common/download?fileName=" + encodeURI(url) + "&delete=" + true; + function downLoad(fileUrl,realFileName) { + alert(ctx + "common/download2?filePath = " + fileUrl + "&realFileName=" + encodeURI(realFileName) + "&delete=" + false); + window.location.href = ctx + "common/download2?filePath = " + fileUrl + "&realFileName=" + encodeURI(realFileName) + "&delete=" + false; } diff --git a/sql/business_20201010.sql b/sql/business_20201010.sql index eae43744e..40bd0e93e 100644 --- a/sql/business_20201010.sql +++ b/sql/business_20201010.sql @@ -48,7 +48,8 @@ create table contract_template ( introduction text not null comment '简介', content text not null comment '详情内容', hits int (6) default 0 comment '点击量', - enclosure_url varchar(500) not null comment '附件下载(多个地址用,分隔)', + enclosure_name varchar(60) not null comment '附件名称', + enclosure_url varchar(500) not null comment '附件地址', status char(1) default '0' comment '状态(0正常 1停用)', del_flag char(1) default '0' comment '删除标志(0代表存在 2代表删除)', create_by varchar(64) default '' comment '创建者',