From f03bb8c2eef349d3259459763ba40e0153df09ea Mon Sep 17 00:00:00 2001
From: wangsixiang <2970484253@qq.com>
Date: Mon, 17 Jun 2024 10:49:47 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=E4=BF=AE?=
=?UTF-8?q?=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../controller/DcFileDownloadController.java | 22 +++++++++++++
.../zc/business/domain/DcFileDownload.java | 33 +++++++++++++++++++
.../business/mapper/DcFileDownloadMapper.java | 2 ++
.../service/IDcFileDownloadService.java | 2 ++
.../impl/DcFileDownloadServiceImpl.java | 5 +++
.../mapper/business/DcFileDownloadMapper.xml | 15 ++++++++-
6 files changed, 78 insertions(+), 1 deletion(-)
diff --git a/zc-business/src/main/java/com/zc/business/controller/DcFileDownloadController.java b/zc-business/src/main/java/com/zc/business/controller/DcFileDownloadController.java
index a93c64d1..fe581c1c 100644
--- a/zc-business/src/main/java/com/zc/business/controller/DcFileDownloadController.java
+++ b/zc-business/src/main/java/com/zc/business/controller/DcFileDownloadController.java
@@ -6,6 +6,7 @@ import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.exception.file.FileSizeLimitExceededException;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
@@ -16,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
@@ -41,6 +43,10 @@ public class DcFileDownloadController extends BaseController {
private IDcFileDownloadService dcFileDownloadService;
@Autowired
private ServerConfig serverConfig;
+ /**
+ * 默认大小 20M
+ */
+ public static final long DEFAULT_MAX_SIZE = 20 * 1024 * 1024;
/**
* 查询文件管理列表
*/
@@ -114,12 +120,23 @@ public class DcFileDownloadController extends BaseController {
String filePath = RuoYiConfig.getFileManagementPath();
// 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file);
+ //文件后缀
+ String extension = FileUploadUtils.getExtension(file);
+ //文件大小,单位为B
+ long size = file.getSize();
+ //文件大小验证
+ if (size > DEFAULT_MAX_SIZE)
+ {
+ throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
+ }
String url = serverConfig.getUrl() + fileName;
AjaxResult ajax = AjaxResult.success();
ajax.put("url", url);
ajax.put("fileName", fileName);
ajax.put("newFileName", FileUtils.getName(fileName));
ajax.put("originalFilename", file.getOriginalFilename());
+ ajax.put("extension", extension);
+ ajax.put("size", size);
return ajax;
}
catch (Exception e)
@@ -127,5 +144,10 @@ public class DcFileDownloadController extends BaseController {
return AjaxResult.error(e.getMessage());
}
}
+ //下载请求接口-下载数量+1
+ @GetMapping("/downloadIncrease/{id}")
+ public AjaxResult downloadIncrease(@PathVariable Long id) {
+ return toAjax(dcFileDownloadService.downloadIncrease(id));
+ }
}
diff --git a/zc-business/src/main/java/com/zc/business/domain/DcFileDownload.java b/zc-business/src/main/java/com/zc/business/domain/DcFileDownload.java
index 38fbe723..3e89b3b1 100644
--- a/zc-business/src/main/java/com/zc/business/domain/DcFileDownload.java
+++ b/zc-business/src/main/java/com/zc/business/domain/DcFileDownload.java
@@ -25,8 +25,41 @@ public class DcFileDownload extends BaseEntity
/** 文件地址 */
@Excel(name = "文件地址")
private String fileAddress;
+ /** 文件大小 */
+ @Excel(name = "文件大小(单位B)")
+ private Long size;
+ /** 文件后缀 */
+ @Excel(name = "文件后缀")
+ private String extension;
+ /** 文件后缀 */
+ @Excel(name = "文件下载次数")
+ private Integer number;
+
+ public Integer getNumber() {
+ return number;
+ }
+
+ public void setNumber(Integer number) {
+ this.number = number;
+ }
+
+ public Long getSize() {
+ return size;
+ }
+
+ public void setSize(Long size) {
+ this.size = size;
+ }
+
+ public String getExtension() {
+ return extension;
+ }
+
+ public void setExtension(String extension) {
+ this.extension = extension;
+ }
public void setId(Long id)
{
diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcFileDownloadMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcFileDownloadMapper.java
index f17bec7e..8a3bd53b 100644
--- a/zc-business/src/main/java/com/zc/business/mapper/DcFileDownloadMapper.java
+++ b/zc-business/src/main/java/com/zc/business/mapper/DcFileDownloadMapper.java
@@ -58,4 +58,6 @@ public interface DcFileDownloadMapper
* @return 结果
*/
int deleteDcFileDownloadByIds(Long[] ids);
+ //下载请求接口-下载数量+1
+ int downloadIncrease(Long id);
}
diff --git a/zc-business/src/main/java/com/zc/business/service/IDcFileDownloadService.java b/zc-business/src/main/java/com/zc/business/service/IDcFileDownloadService.java
index f5ce7c0a..4da3b554 100644
--- a/zc-business/src/main/java/com/zc/business/service/IDcFileDownloadService.java
+++ b/zc-business/src/main/java/com/zc/business/service/IDcFileDownloadService.java
@@ -58,4 +58,6 @@ public interface IDcFileDownloadService
* @return 结果
*/
int deleteDcFileDownloadById(Long id);
+ //下载请求接口-下载数量+1
+ int downloadIncrease(Long id);
}
diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcFileDownloadServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcFileDownloadServiceImpl.java
index 2ad1c9db..585adf23 100644
--- a/zc-business/src/main/java/com/zc/business/service/impl/DcFileDownloadServiceImpl.java
+++ b/zc-business/src/main/java/com/zc/business/service/impl/DcFileDownloadServiceImpl.java
@@ -96,4 +96,9 @@ public class DcFileDownloadServiceImpl implements IDcFileDownloadService
{
return dcFileDownloadMapper.deleteDcFileDownloadById(id);
}
+ //下载请求接口-下载数量+1
+ @Override
+ public int downloadIncrease(Long id) {
+ return dcFileDownloadMapper.downloadIncrease(id);
+ }
}
diff --git a/zc-business/src/main/resources/mapper/business/DcFileDownloadMapper.xml b/zc-business/src/main/resources/mapper/business/DcFileDownloadMapper.xml
index d780de17..9151919f 100644
--- a/zc-business/src/main/resources/mapper/business/DcFileDownloadMapper.xml
+++ b/zc-business/src/main/resources/mapper/business/DcFileDownloadMapper.xml
@@ -12,10 +12,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+
+
+
- select id, file_name, file_address, create_time, create_by, update_time, update_by from dc_file_download
+ select id,number,size,extension, file_name, file_address, create_time, create_by, update_time, update_by from dc_file_download