From 939d5f3d5e17e5ca0bfeec9c23c7c926b4cb1684 Mon Sep 17 00:00:00 2001 From: Fancy <Fancy.fx@outlook.com> Date: 星期二, 10 九月 2024 15:47:33 +0800 Subject: [PATCH] plan rate --- pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileCtrl.java | 77 +++++++++++++++++++++++++++++++------- 1 files changed, 63 insertions(+), 14 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 97470ab..3228be2 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 @@ -17,13 +17,14 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import java.util.Date; + /** * web鏂囦欢涓婁紶绀轰緥 */ @Slf4j @RestController @RequestMapping(path="webFile") -@SuppressWarnings("unchecked")//java鐗堟湰瓒婇珮锛屽娉涘瀷绾︽潫瓒婁弗锛屾墍浠ラ厤缃甋uppressWarnings("unchecked" public class WebFileCtrl { @Autowired @@ -34,7 +35,15 @@ @Value("${dy.webFile.fmUrl}") private String fmUrl ; + //鏀寔鐨勬枃浠剁被鍨� + @Value("${dy.webFile.supportedFileTypes}") + private String supportedFileTypes ; + /** + * 涓婁紶鐓х墖鍥剧墖鏂囦欢 锛堝綋鍓嶅彧瀵筽ng jpg鏍煎紡鍥剧墖鏀寔缂╃暐鍥撅級 + * @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 @@ -52,8 +61,14 @@ fileNameGrp[1], null); String fileMainName = fileOp.getFileMainName(frVo.fileName) ; - Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath, frVo.fileWebDownloadUrl); - FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1], (frVo.getFileWebUrl() + frVo.getFileWebPath()), fileOp.getImgFileZipPath(frVo.getFileWebUrl() + frVo.getFileWebPath()), frVo.fileWebDownloadUrl) ; + 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.fileWebDownloadPath + id) ; return BaseResponseUtils.buildSuccess(fvo) ; }else { return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�"); @@ -70,6 +85,11 @@ } } + /** + * 涓婁紶褰曢煶闊抽鏂囦欢 + * @param file web绔笂浼犳枃浠剁殑post瀵硅薄 + * @return 杩斿洖缁撴灉 + */ @PostMapping("/upPhone") @SsoPowerAop(power = "-1") public BaseResponse<?> upPhone(MultipartFile file) { @@ -86,8 +106,14 @@ fileNameGrp[1], null); String fileMainName = fileOp.getFileMainName(frVo.fileName) ; - Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath, frVo.fileWebDownloadUrl); - FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileWebDownloadUrl) ; + 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.fileWebDownloadPath + id) ; return BaseResponseUtils.buildSuccess(fvo) ; }else { return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�"); @@ -105,7 +131,11 @@ } - + /** + * 涓婁紶褰曞儚瑙嗛鏂囦欢 + * @param file web绔笂浼犳枃浠剁殑post瀵硅薄 + * @return 杩斿洖缁撴灉 + */ @PostMapping("/upVideo") @SsoPowerAop(power = "-1") public BaseResponse<?> upVideo(MultipartFile file) { @@ -122,8 +152,14 @@ fileNameGrp[1], null); String fileMainName = fileOp.getFileMainName(frVo.fileName) ; - Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath, frVo.fileWebDownloadUrl); - FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileWebDownloadUrl) ; + 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.fileWebDownloadPath + id) ; return BaseResponseUtils.buildSuccess(fvo) ; }else { return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�"); @@ -141,7 +177,11 @@ } - + /** + * 涓婁紶鏂囨。鏂囦欢 + * @param file web绔笂浼犳枃浠剁殑post瀵硅薄 + * @return 杩斿洖缁撴灉 + */ @PostMapping("/upDocument") @SsoPowerAop(power = "-1") public BaseResponse<?> upDocument(MultipartFile file) { @@ -150,6 +190,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, @@ -158,8 +202,13 @@ fileNameGrp[1], null); String fileMainName = fileOp.getFileMainName(frVo.fileName) ; - Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath, frVo.fileWebDownloadUrl); - FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileWebDownloadUrl) ; + 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.fileWebDownloadPath + id) ; return BaseResponseUtils.buildSuccess(fvo) ; }else { return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�"); @@ -184,16 +233,16 @@ * @param newName 鏂囦欢鏂板悕绉� * @param hash 鏂囦欢鏂板悕绉扮殑鍝堝笇鍊� * @param filePath 鏂囦欢鏈嶅姟绔瓨鍌ㄧ浉瀵硅矾寰� - * @return + * @return 鏁版嵁璁板綍涓婚敭 */ - private Long saveFileInfo(String orgName, String extName, String newName, Integer hash, String filePath, String downloadPath){ + private Long saveFileInfo(String orgName, String extName, String newName, Integer hash, String filePath){ OthFile po = new OthFile() ; po.orgName = orgName ; po.extName = extName ; po.newName = newName ; po.hash = hash ; po.filePath = filePath ; - po.downloadPath = downloadPath ; + po.dt = new Date() ; return this.sv.save(po) ; } -- Gitblit v1.8.0