|
|
@@ -1,10 +1,13 @@
|
|
|
package com.dk.mdm.controller;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.dk.common.infrastructure.constant.Constant;
|
|
|
import com.dk.common.infrastructure.enums.ErrorCodeEnum;
|
|
|
import com.dk.common.response.ResponseResultUtil;
|
|
|
import com.dk.common.response.ResponseResultVO;
|
|
|
+import com.dk.mdm.infrastructure.util.AuthUtils;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
@@ -21,10 +24,13 @@ public class FileController {
|
|
|
@Value("${upload-path}")
|
|
|
private String uploadPath;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AuthUtils authUtils;
|
|
|
+
|
|
|
/**
|
|
|
- * @desc : 上传文件
|
|
|
+ * @desc : 上传文件
|
|
|
* @author : 洪旭东
|
|
|
- * @date : 2023-06-26 14:09
|
|
|
+ * @date : 2023-06-26 14:09
|
|
|
*/
|
|
|
@ApiOperation(value = "上传文件", notes = "上传文件")
|
|
|
@PostMapping("upload")
|
|
|
@@ -45,7 +51,7 @@ public class FileController {
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("path", filePath.replace(uploadPath, ""));
|
|
|
json.put("name", fileName);
|
|
|
- json.put("type",getFileType(fileName));
|
|
|
+ json.put("type", getFileType(fileName));
|
|
|
json.put("createTime", LocalDateTime.now());
|
|
|
return ResponseResultUtil.success(json);
|
|
|
} catch (IOException e) {
|
|
|
@@ -55,37 +61,51 @@ public class FileController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @desc : 获取文件类型
|
|
|
+ * @desc : 获取文件类型
|
|
|
* @author : 周兴
|
|
|
- * @date : 2024-03-27 14:09
|
|
|
+ * @date : 2024-03-27 14:09
|
|
|
*/
|
|
|
private String getFileType(String fileName) {
|
|
|
- if(fileName.indexOf(".")>=0 ){
|
|
|
+ if (fileName.indexOf(".") >= 0) {
|
|
|
+ String appCode = authUtils.getStaff().getAppCode();
|
|
|
String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
|
|
|
fileType = fileType.toLowerCase();
|
|
|
|
|
|
- if ("jpg".equals(fileType) || "jepg".equals(fileType) || "png".equals(fileType)) {
|
|
|
- return "img";
|
|
|
- }
|
|
|
if ("mp4".equals(fileType) || "avi".equals(fileType) || "mov".equals(fileType)) {
|
|
|
return "video";
|
|
|
}
|
|
|
- if ("xls".equals(fileType) || "xlsx".equals(fileType)) {
|
|
|
- return "excel";
|
|
|
- }
|
|
|
- if ("pdf".equals(fileType)) {
|
|
|
- return "pdf";
|
|
|
+ // 小程序
|
|
|
+ if (Constant.AppCode.WEIXIN.getCode().equals(appCode)) {
|
|
|
+ if ("xls".equals(fileType) || "xlsx".equals(fileType)) {
|
|
|
+ return "file";
|
|
|
+ }
|
|
|
+ if ("pdf".equals(fileType)) {
|
|
|
+ return "file";
|
|
|
+ }
|
|
|
+ if ("jpg".equals(fileType) || "jepg".equals(fileType) || "png".equals(fileType)) {
|
|
|
+ return "image";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ("xls".equals(fileType) || "xlsx".equals(fileType)) {
|
|
|
+ return "excel";
|
|
|
+ }
|
|
|
+ if ("pdf".equals(fileType)) {
|
|
|
+ return "pdf";
|
|
|
+ }
|
|
|
+ if ("jpg".equals(fileType) || "jepg".equals(fileType) || "png".equals(fileType)) {
|
|
|
+ return "img";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @desc : 根据类型创建目录文件夹
|
|
|
+ * @desc : 根据类型创建目录文件夹
|
|
|
* @author : 洪旭东
|
|
|
- * @date : 2023-06-26 14:10
|
|
|
+ * @date : 2023-06-26 14:10
|
|
|
*/
|
|
|
- private String createDirByPath(String folder){
|
|
|
+ private String createDirByPath(String folder) {
|
|
|
//斜线
|
|
|
final String diagonal = "/";
|
|
|
|
|
|
@@ -103,6 +123,6 @@ public class FileController {
|
|
|
dir.mkdir();
|
|
|
}
|
|
|
}
|
|
|
- return base+diagonal;
|
|
|
+ return base + diagonal;
|
|
|
}
|
|
|
}
|