| package com.dy.pipIrrWebFile.fm; | 
|   | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.http.MediaType; | 
| import org.springframework.web.bind.annotation.PostMapping; | 
| import org.springframework.web.bind.annotation.RequestMapping; | 
| import org.springframework.web.bind.annotation.RestController; | 
|   | 
| import java.util.ArrayList; | 
| import java.util.List; | 
|   | 
| /** | 
|  * 分布式web文件系统管理系统 | 
|  */ | 
| @Slf4j | 
| @RestController | 
| @RequestMapping(path="fm") | 
| @SuppressWarnings("unchecked")//java版本越高,对泛型约束越严,所以配置SuppressWarnings("unchecked") | 
| public class FmCtrl { | 
|   | 
|     /** | 
|      * 生成文件名,并且计算出该文件名对应的文件服务器属性 | 
|      * 文件名称是不带路径的名称,例如:20170818153254_100000007.jpg,文件名中不能有“/”或“\”字符 | 
|      * @param fileExtName 文件扩展名 | 
|      * @return | 
|      */ | 
|     @PostMapping(path = "create") | 
|     public FileRestVo create(String fileExtName){ | 
|         FileRestVo rvo = new FileRestVo() ; | 
|         if(fileExtName != null && !fileExtName.trim().equals("")){ | 
|             try { | 
|                 String id = new FileNameIdUtil().generate(); | 
|                 if(id != null){ | 
|                     rvo.fileName = FileName.createFileName(false, id, fileExtName) ; | 
|                     rvo = new RestHashDeal().fileTransRest(rvo.fileName, rvo) ; | 
|                 } | 
|             } catch (Exception e) { | 
|                 e.printStackTrace(); | 
|             } | 
|         } | 
|         return rvo ; | 
|     } | 
|   | 
|     /** | 
|      * 解析文件名(带或不带相对路径),计算出该文件名对应的文件服务器属性 | 
|      * 文件名称可以是不带路径的名称,例如:20170818153254_100000007.jpg | 
|      * 文件名称可以是带路径的名称,例如:webFile/photo/20170818153254_100000007.jpg | 
|      * @param filePath | 
|      * @return | 
|      */ | 
|     @PostMapping(path = "parsePath") | 
|     public FileRestVo parsePath(String filePath){ | 
|         FileRestVo rvo = new FileRestVo() ; | 
|         if(filePath != null && !filePath.trim().equals("")){ | 
|             try { | 
|                 int index = filePath.lastIndexOf("\\") ; | 
|                 if(index > 0){ | 
|                     filePath = filePath.substring(index + 1); | 
|                 } | 
|                 index = filePath.lastIndexOf("/") ; | 
|                 if(index > 0){ | 
|                     filePath = filePath.substring(index + 1); | 
|                 } | 
|                 index = filePath.lastIndexOf("?") ; | 
|                 if(index > 0){ | 
|                     filePath = filePath.substring(0, index); | 
|                 } | 
|                 rvo.fileName = filePath ; | 
|                 rvo = new RestHashDeal().fileTransRest(filePath, rvo) ; | 
|             } catch (Exception e) { | 
|                 e.printStackTrace(); | 
|             } | 
|         } | 
|         return rvo ; | 
|     } | 
|     /** | 
|      * 解析文件名,并且计算出该文件名对应的文件服务器属性 | 
|      * 文件名称可以是不带路径的名称,例如:20170818153254_100000007.jpg | 
|      * 文件名称可以是带路径的名称,例如:webFile/photo/20170818153254_100000007.jpg | 
|      * @param filePaths | 
|      * @return | 
|      */ | 
|     @PostMapping(path = "parsePathList", consumes = MediaType.APPLICATION_JSON_VALUE)//前端提交json数据 | 
|     public FileRestVo[] parsePathList(List<String> filePaths){ | 
|         List<FileRestVo> rList = new ArrayList<FileRestVo>() ; | 
|         if(filePaths != null && filePaths.size() > 0){ | 
|             try { | 
|                 for(String filePath : filePaths){ | 
|                     FileRestVo rvo = new FileRestVo() ; | 
|                     int index = filePath.lastIndexOf("\\") ; | 
|                     if(index > 0){ | 
|                         filePath = filePath.substring(index + 1); | 
|                     } | 
|                     index = filePath.lastIndexOf("/") ; | 
|                     if(index > 0){ | 
|                         filePath = filePath.substring(index + 1); | 
|                     } | 
|                     index = filePath.lastIndexOf("?") ; | 
|                     if(index > 0){ | 
|                         filePath = filePath.substring(0, index); | 
|                     } | 
|                     rvo.fileName = filePath ; | 
|                     rvo = new RestHashDeal().fileTransRest(filePath, rvo) ; | 
|                     rList.add(rvo) ; | 
|                 } | 
|             } catch (Exception e) { | 
|                 e.printStackTrace(); | 
|             } | 
|         } | 
|         return rList.toArray(new FileRestVo[0]) ; | 
|     } | 
|   | 
|     /** | 
|      * 解析哈希值,计算出该哈希值对应的文件服务器属性 | 
|      * @param hashCode | 
|      * @return | 
|      */ | 
|     @PostMapping(path = "parseHashcode") | 
|     public FileRestVo parseHashcode(Integer hashCode){ | 
|         FileRestVo rvo = new FileRestVo() ; | 
|         if(hashCode != null){ | 
|             try { | 
|                 rvo.fileName = null ; | 
|                 rvo = new RestHashDeal().fileTransRest(hashCode, rvo) ; | 
|             } catch (Exception e) { | 
|                 e.printStackTrace(); | 
|             } | 
|         } | 
|         return rvo ; | 
|     } | 
|   | 
|     /** | 
|      * 解析哈希值集合,计算出该这些哈希值对应的文件服务器属性 | 
|      * @param hashCodes | 
|      * @return 文件服务器属性对象集合 | 
|      */ | 
|     @PostMapping(path = "parseHashcodeList") | 
|     public FileRestVo[] parseHashcodeList(List<Integer> hashCodes){ | 
|         List<FileRestVo> reList = new ArrayList<>() ; | 
|         if(hashCodes != null && hashCodes.size() > 0){ | 
|             for(Integer hashCode : hashCodes){ | 
|                 reList.add(parseHashcode(hashCode)) ; | 
|             } | 
|         } | 
|         return reList.toArray(new FileRestVo[0]) ; | 
|     } | 
|   | 
|   | 
| } |