From 59c0d05b90ecd347ece75332bcee1dd9a32bfb8a Mon Sep 17 00:00:00 2001 From: 刘小明 <liuxm_a@163.com> Date: 星期二, 23 七月 2024 11:27:30 +0800 Subject: [PATCH] 修改提示 --- pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileCtrl.java | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 38 insertions(+), 11 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 7472b24..bf1fa9b 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 @@ -9,7 +9,6 @@ import com.dy.pmsGlobal.dyFile.FileRestVo; import com.dy.pmsGlobal.dyFile.FileVo; import com.dy.pmsGlobal.pojoOth.OthFile; -import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -17,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; + +import java.util.Date; /** * web鏂囦欢涓婁紶绀轰緥 @@ -35,11 +36,19 @@ @Value("${dy.webFile.fmUrl}") private String fmUrl ; + //鏀寔鐨勬枃浠剁被鍨� + @Value("${dy.webFile.supportedFileTypes}") + private String supportedFileTypes ; + /** + * 涓婁紶鐓х墖鍥剧墖鏂囦欢 锛堝綋鍓嶅彧瀵筽ng jpg鏍煎紡鍥剧墖鏀寔缂╃暐鍥撅級 + * @param file + * @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 - public BaseResponse<?> upPhoto(MultipartFile file, HttpServletRequest req) { + public BaseResponse<?> upPhoto(MultipartFile file) { try { if (file != null) { String[] fileNameGrp = fileOp.splitFileName(file) ; @@ -54,7 +63,7 @@ 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())) ; + 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) ; return BaseResponseUtils.buildSuccess(fvo) ; }else { return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�"); @@ -71,9 +80,14 @@ } } + /** + * 涓婁紶褰曢煶闊抽鏂囦欢 + * @param file + * @return + */ @PostMapping("/upPhone") @SsoPowerAop(power = "-1") - public BaseResponse<?> upPhone(MultipartFile file, HttpServletRequest req) { + public BaseResponse<?> upPhone(MultipartFile file) { try { if (file != null) { String[] fileNameGrp = fileOp.splitFileName(file) ; @@ -88,7 +102,7 @@ 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) ; + FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ; return BaseResponseUtils.buildSuccess(fvo) ; }else { return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�"); @@ -106,10 +120,14 @@ } - + /** + * 涓婁紶褰曞儚瑙嗛鏂囦欢 + * @param file + * @return + */ @PostMapping("/upVideo") @SsoPowerAop(power = "-1") - public BaseResponse<?> upVideo(MultipartFile file, HttpServletRequest req) { + public BaseResponse<?> upVideo(MultipartFile file) { try { if (file != null) { String[] fileNameGrp = fileOp.splitFileName(file) ; @@ -124,7 +142,7 @@ 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) ; + FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ; return BaseResponseUtils.buildSuccess(fvo) ; }else { return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�"); @@ -142,15 +160,23 @@ } - + /** + * 涓婁紶鏂囨。鏂囦欢 + * @param file + * @return + */ @PostMapping("/upDocument") @SsoPowerAop(power = "-1") - public BaseResponse<?> upDocument(MultipartFile file, HttpServletRequest req) { + public BaseResponse<?> upDocument(MultipartFile file) { try { if (file != null) { 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, @@ -160,7 +186,7 @@ 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) ; + FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ; return BaseResponseUtils.buildSuccess(fvo) ; }else { return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�"); @@ -194,6 +220,7 @@ po.newName = newName ; po.hash = hash ; po.filePath = filePath ; + po.dt = new Date() ; return this.sv.save(po) ; } -- Gitblit v1.8.0