From 9cb1f5cf9cc383d8f09b0735e75ee7a0ef181804 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期六, 19 十月 2024 11:11:00 +0800
Subject: [PATCH] 优化代码,修改注解信息

---
 pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileCtrl.java |   62 +++++++++++++++++++++++--------
 1 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileCtrl.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileCtrl.java
index a3d3641..def09e9 100644
--- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileCtrl.java
+++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileCtrl.java
@@ -20,12 +20,11 @@
 import java.util.Date;
 
 /**
- * web鏂囦欢涓婁紶绀轰緥
+ * web鏂囦欢涓婁紶
  */
 @Slf4j
 @RestController
 @RequestMapping(path="webFile")
-@SuppressWarnings("unchecked")//java鐗堟湰瓒婇珮锛屽娉涘瀷绾︽潫瓒婁弗锛屾墍浠ラ厤缃甋uppressWarnings("unchecked"
 public class WebFileCtrl {
 
     @Autowired
@@ -37,14 +36,18 @@
     @Value("${dy.webFile.fmUrl}")
     private String fmUrl ;
 
+    //鏀寔鐨勬枃妗f枃浠剁被鍨�
+    @Value("${dy.webFile.supportedFileTypes}")
+    private String supportedFileTypes ;
+
     /**
      * 涓婁紶鐓х墖鍥剧墖鏂囦欢 锛堝綋鍓嶅彧瀵筽ng jpg鏍煎紡鍥剧墖鏀寔缂╃暐鍥撅級
-     * @param file
-     * @return
+     * @param file web绔笂浼犳枃浠剁殑post瀵硅薄
+     * @return 杩斿洖缁撴灉
      */
     @PostMapping("/upPhoto")
     @SsoPowerAop(power = "-1") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
-    //https://blog.zhengru.top/posts/33486.html#%E5%8D%95%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0
+    //鍙傝�冿細 https://blog.zhengru.top/posts/33486.html#%E5%8D%95%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0
     public BaseResponse<?> upPhoto(MultipartFile file) {
         try {
             if (file != null) {
@@ -60,7 +63,13 @@
                                 null);
                         String fileMainName = fileOp.getFileMainName(frVo.fileName) ;
                         Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath);
-                        FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1], (frVo.getFileWebUrl() + frVo.getFileWebPath()), fileOp.getImgFileZipPath(frVo.getFileWebUrl() + frVo.getFileWebPath()), frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ;
+                        FileVo fvo = new FileVo(id,
+                                frVo.fileNameHash,
+                                fileNameGrp[0],
+                                fileNameGrp[1],
+                                (frVo.getFileWebUrl() + frVo.getFileWebPath()),
+                                fileOp.getImgFileZipPath(frVo.getFileWebUrl() + frVo.getFileWebPath()),
+                                frVo.fileWebDownloadPath + id) ;
                         return  BaseResponseUtils.buildSuccess(fvo) ;
                     }else {
                         return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�");
@@ -79,8 +88,8 @@
 
     /**
      * 涓婁紶褰曢煶闊抽鏂囦欢
-     * @param file
-     * @return
+     * @param file web绔笂浼犳枃浠剁殑post瀵硅薄
+     * @return 杩斿洖缁撴灉
      */
     @PostMapping("/upPhone")
     @SsoPowerAop(power = "-1")
@@ -99,7 +108,13 @@
                                 null);
                         String fileMainName = fileOp.getFileMainName(frVo.fileName) ;
                         Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath);
-                        FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ;
+                        FileVo fvo = new FileVo(id,
+                                frVo.fileNameHash,
+                                fileNameGrp[0],
+                                fileNameGrp[1],
+                                frVo.getFileWebUrl() + frVo.getFileWebPath(),
+                                null,
+                                frVo.fileWebDownloadPath + id) ;
                         return  BaseResponseUtils.buildSuccess(fvo) ;
                     }else {
                         return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�");
@@ -119,8 +134,8 @@
 
     /**
      * 涓婁紶褰曞儚瑙嗛鏂囦欢
-     * @param file
-     * @return
+     * @param file web绔笂浼犳枃浠剁殑post瀵硅薄
+     * @return 杩斿洖缁撴灉
      */
     @PostMapping("/upVideo")
     @SsoPowerAop(power = "-1")
@@ -139,7 +154,13 @@
                                 null);
                         String fileMainName = fileOp.getFileMainName(frVo.fileName) ;
                         Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath);
-                        FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ;
+                        FileVo fvo = new FileVo(id,
+                                frVo.fileNameHash,
+                                fileNameGrp[0],
+                                fileNameGrp[1],
+                                frVo.getFileWebUrl() + frVo.getFileWebPath(),
+                                null,
+                                frVo.fileWebDownloadPath + id) ;
                         return  BaseResponseUtils.buildSuccess(fvo) ;
                     }else {
                         return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�");
@@ -159,8 +180,8 @@
 
     /**
      * 涓婁紶鏂囨。鏂囦欢
-     * @param file
-     * @return
+     * @param file web绔笂浼犳枃浠剁殑post瀵硅薄
+     * @return 杩斿洖缁撴灉
      */
     @PostMapping("/upDocument")
     @SsoPowerAop(power = "-1")
@@ -170,6 +191,10 @@
                 String[] fileNameGrp = fileOp.splitFileName(file) ;
                 if(fileNameGrp != null && fileNameGrp[0] != null && fileNameGrp[1] != null){
                     if(!fileNameGrp[1].trim().equals("")){
+                       String fileExtName = fileNameGrp[1];
+                       if(!supportedFileTypes.contains(fileExtName)){
+                           return BaseResponseUtils.buildError("璇蜂笂浼燱ord,Excel,PDF绫诲瀷鏂囨。");
+                       }
                         FileRestVo frVo = fileOp.saveFile(file,
                                 fmUrl,
                                 FileConstant.fileRequestMapping,
@@ -179,7 +204,12 @@
                                 null);
                         String fileMainName = fileOp.getFileMainName(frVo.fileName) ;
                         Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath);
-                        FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ;
+                        FileVo fvo = new FileVo(id,
+                                frVo.fileNameHash,
+                                fileNameGrp[0], fileNameGrp[1],
+                                frVo.getFileWebUrl() + frVo.getFileWebPath(),
+                                null,
+                                frVo.fileWebDownloadPath + id) ;
                         return  BaseResponseUtils.buildSuccess(fvo) ;
                     }else {
                         return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�");
@@ -204,7 +234,7 @@
      * @param newName 鏂囦欢鏂板悕绉�
      * @param hash  鏂囦欢鏂板悕绉扮殑鍝堝笇鍊�
      * @param filePath 鏂囦欢鏈嶅姟绔瓨鍌ㄧ浉瀵硅矾寰�
-     * @return
+     * @return 鏁版嵁璁板綍涓婚敭
      */
     private Long saveFileInfo(String orgName, String extName, String newName, Integer hash, String filePath){
         OthFile po = new OthFile() ;

--
Gitblit v1.8.0