From ac9a7c884012a4571b58f075fa2c6647b2f9886f Mon Sep 17 00:00:00 2001
From: "DESKTOP-G8BCEP0\\HP" <2037158277@qq.com>
Date: Tue, 14 Sep 2021 13:56:49 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=8A=E4=BC=A0?=
=?UTF-8?q?=E5=9B=BE=E7=89=87=E5=88=B0=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=9A=84?=
=?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=92=8C=E6=9F=A5=E7=9C=8B=E5=9B=BE=E7=89=87?=
=?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9A=84=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 17 +
.../xkrs/common/config/WebSecurityConfig.java | 2 +
.../com/xkrs/controller/FileController.java | 116 +++++
src/main/java/com/xkrs/dao/FilePathDao.java | 21 +
.../java/com/xkrs/model/entity/FilePath.java | 135 +++++
.../xkrs/service/impl/SysUserServiceImpl.java | 2 -
.../java/com/xkrs/utils/DateTimeUtil.java | 8 +
src/main/java/com/xkrs/utils/FileFastDfs.java | 477 ++++++++++++++++++
src/main/java/com/xkrs/utils/FileUtil.java | 314 ++++++++----
src/main/resources/application.properties | 7 +-
10 files changed, 1000 insertions(+), 99 deletions(-)
create mode 100644 src/main/java/com/xkrs/controller/FileController.java
create mode 100644 src/main/java/com/xkrs/dao/FilePathDao.java
create mode 100644 src/main/java/com/xkrs/model/entity/FilePath.java
create mode 100644 src/main/java/com/xkrs/utils/FileFastDfs.java
diff --git a/pom.xml b/pom.xml
index 23bc21a..e959735 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,6 +33,8 @@
5.0.0
5.0.0
2.0.4
+ 4.4.3
+ 0.4.0
@@ -214,6 +216,21 @@
aliyun-java-sdk-dysmsapi
1.1.0
+
+ cn.hutool
+ hutool-all
+ ${hutool-all.version}
+
+
+ io.tus.java.client
+ tus-java-client
+ ${tus-client.version}
+
+
+ org.springframework.kafka
+ spring-kafka
+ 2.5.10.RELEASE
+
diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java
index 7943196..601e796 100644
--- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java
+++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java
@@ -55,6 +55,8 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers(HttpMethod.GET,"/selectFirePoint").permitAll()
.antMatchers(HttpMethod.POST,"/updateTypeByFireCode").permitAll()
.antMatchers(HttpMethod.GET,"/api/user/verificationCode").permitAll()
+ .antMatchers(HttpMethod.POST,"/uploadFileMore").permitAll()
+ .antMatchers(HttpMethod.POST,"/uploadFile").permitAll()
// 所有其它请求需要身份认证
.anyRequest().authenticated()
.and()
diff --git a/src/main/java/com/xkrs/controller/FileController.java b/src/main/java/com/xkrs/controller/FileController.java
new file mode 100644
index 0000000..1e63f62
--- /dev/null
+++ b/src/main/java/com/xkrs/controller/FileController.java
@@ -0,0 +1,116 @@
+package com.xkrs.controller;
+
+import com.xkrs.common.encapsulation.PromptMessageEnum;
+import com.xkrs.dao.FilePathDao;
+import com.xkrs.model.entity.FilePath;
+import com.xkrs.utils.FileFastDfs;
+import com.xkrs.utils.FileUtil;
+import org.springframework.context.i18n.LocaleContextHolder;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
+import static com.xkrs.utils.FileUtil.getUploadInfo;
+
+/**
+ * @author XinYi Song
+ * 文件上传
+ */
+@RestController
+public class FileController {
+
+ @Resource
+ private FileFastDfs fileFastDfs;
+
+ @Resource
+ private FilePathDao filePathDao;
+
+ /**
+ * 上传多张图片
+ * @param files
+ * @return
+ */
+ @PostMapping("/uploadFileMore")
+ public String uploadFileMore(MultipartFile[] files){
+ Locale locale = LocaleContextHolder.getLocale();
+ if (null == files || files.length == 0){
+ return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "result or fileType is null", locale);
+ }
+ List list = new ArrayList();
+ for (MultipartFile file :
+ files) {
+ boolean m = FileUtil.checkFileSize(file.getSize(), 100, "M");
+ if(m == false){
+ return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "图片大小不能超过100M", locale);
+ }
+ String dir = "fire_point";
+ String info = fileFastDfs.uploadFile(file, dir);
+ Map map = getUploadInfo(info);
+ FilePath filePath = new FilePath();
+ filePath.setFilePath(map.get("path"));
+ filePath.setFileName(map.get("fileName"));
+ filePath.setSize(map.get("size"));
+ filePath.setMtime(map.get("mtime"));
+ filePath.setUrl(map.get("url"));
+ filePath.setMd5(map.get("md5"));
+ filePath.setScene(map.get("scene"));
+ filePathDao.save(filePath);
+ }
+ //List