From d20d38e22b06559d758c568769017e2acf632583 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 23 四月 2025 14:06:48 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
---
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/webCtrls/WebFileCtrl.java | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 251 insertions(+), 0 deletions(-)
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/webCtrls/WebFileCtrl.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/webCtrls/WebFileCtrl.java
new file mode 100644
index 0000000..6f26cd1
--- /dev/null
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/webCtrls/WebFileCtrl.java
@@ -0,0 +1,251 @@
+package com.dy.pipIrrGlobal.webCtrls;
+
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.pipIrrGlobal.dyFile.FileConstant;
+import com.dy.pipIrrGlobal.dyFile.FileOperate;
+import com.dy.pipIrrGlobal.dyFile.FileRestVo;
+import com.dy.pipIrrGlobal.dyFile.FileVo;
+import com.dy.pipIrrGlobal.pojoFi.WebFile;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.PostMapping;
+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鏂囦欢涓婁紶
+ */
+@Slf4j
+@RestController
+@RequestMapping(path="webFile")
+public class WebFileCtrl {
+
+ @Autowired
+ private FileOperate fileOp ;
+
+ @Autowired
+ private WebFileSv sv ;
+
+ @Value("${dy.webFile.fmUrl}")
+ private String fmUrl ;
+
+ //鏀寔鐨勬枃浠剁被鍨�
+ @Value("${dy.webFile.supportedFileTypes}")
+ private String supportedFileTypes ;
+
+ //瑙嗛鐨勭缉鐣ュ浘鐨勬墿灞曞悕
+ private static final String VideoZipPicFileType = "jpg";
+
+ /**
+ * 涓婁紶鐓х墖鍥剧墖鏂囦欢 锛堝綋鍓嶅彧瀵筽ng jpg鏍煎紡鍥剧墖鏀寔缂╃暐鍥撅級
+ * @param file web绔笂浼犳枃浠剁殑post瀵硅薄
+ * @return 杩斿洖缁撴灉
+ */
+ @PostMapping("/upPhoto")
+ //鍙傝�冿細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) {
+ String[] fileNameGrp = fileOp.splitFileName(file) ;
+ if(fileNameGrp != null && fileNameGrp[0] != null && fileNameGrp[1] != null){
+ if(!fileNameGrp[1].trim().equals("")){
+ FileRestVo frVo = fileOp.saveFile(file,
+ fmUrl,
+ FileConstant.fileRequestMapping,
+ FileConstant.filePostMapping_photo,
+ FileConstant.NotRegionNum,
+ fileNameGrp[1],
+ 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.getFileWebPath(),
+ (frVo.getFileWebUrl() + frVo.getFileWebPath()),
+ fileOp.getFileZipPath(frVo.getFileWebUrl() + frVo.getFileWebPath()),
+ frVo.fileWebDownloadPath + id) ;
+ return BaseResponseUtils.buildSuccess(fvo) ;
+ }else {
+ return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�");
+ }
+ }else {
+ return BaseResponseUtils.buildError("鏈兘鎷嗗垎涓婁紶鏂囦欢鍚嶇О");
+ }
+ } else {
+ return BaseResponseUtils.buildError("鏈笂浼犳枃浠�");
+ }
+ } catch (Exception e) {
+ log.error("涓婁紶鐓х墖鏂囦欢寮傚父", e);
+ return BaseResponseUtils.buildException(e.getMessage());
+ }
+ }
+
+ /**
+ * 涓婁紶褰曢煶闊抽鏂囦欢
+ * @param file web绔笂浼犳枃浠剁殑post瀵硅薄
+ * @return 杩斿洖缁撴灉
+ */
+ @PostMapping("/upPhone")
+ public BaseResponse<?> upPhone(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("")){
+ FileRestVo frVo = fileOp.saveFile(file,
+ fmUrl,
+ FileConstant.fileRequestMapping,
+ FileConstant.filePostMapping_phone,
+ FileConstant.NotRegionNum,
+ fileNameGrp[1],
+ 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.getFileWebPath(),
+ frVo.getFileWebUrl() + frVo.getFileWebPath(),
+ null,
+ frVo.fileWebDownloadPath + id) ;
+ return BaseResponseUtils.buildSuccess(fvo) ;
+ }else {
+ return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�");
+ }
+ }else {
+ return BaseResponseUtils.buildError("鏈兘鎷嗗垎涓婁紶鏂囦欢鍚嶇О");
+ }
+ } else {
+ return BaseResponseUtils.buildError("鏈笂浼犳枃浠�");
+ }
+ } catch (Exception e) {
+ log.error("涓婁紶鐓х墖鏂囦欢寮傚父", e);
+ return BaseResponseUtils.buildException(e.getMessage());
+ }
+ }
+
+
+ /**
+ * 涓婁紶褰曞儚瑙嗛鏂囦欢
+ * @param file web绔笂浼犳枃浠剁殑post瀵硅薄
+ * @return 杩斿洖缁撴灉
+ */
+ @PostMapping("/upVideo")
+ public BaseResponse<?> upVideo(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("")){
+ FileRestVo frVo = fileOp.saveFile(file,
+ fmUrl,
+ FileConstant.fileRequestMapping,
+ FileConstant.filePostMapping_video,
+ FileConstant.NotRegionNum,
+ fileNameGrp[1],
+ 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.getFileWebPath(),
+ frVo.getFileWebUrl() + frVo.getFileWebPath(),
+ fileOp.getFileZipPath(frVo.getFileWebUrl() + frVo.getFileWebPath(), VideoZipPicFileType),
+ frVo.fileWebDownloadPath + id) ;
+ return BaseResponseUtils.buildSuccess(fvo) ;
+ }else {
+ return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�");
+ }
+ }else {
+ return BaseResponseUtils.buildError("鏈兘鎷嗗垎涓婁紶鏂囦欢鍚嶇О");
+ }
+ } else {
+ return BaseResponseUtils.buildError("鏈笂浼犳枃浠�");
+ }
+ } catch (Exception e) {
+ log.error("涓婁紶鐓х墖鏂囦欢寮傚父", e);
+ return BaseResponseUtils.buildException(e.getMessage());
+ }
+ }
+
+
+ /**
+ * 涓婁紶鏂囨。鏂囦欢
+ * @param file web绔笂浼犳枃浠剁殑post瀵硅薄
+ * @return 杩斿洖缁撴灉
+ */
+ @PostMapping("/upDocument")
+ 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,
+ FileConstant.filePostMapping_document,
+ FileConstant.NotRegionNum,
+ fileNameGrp[1],
+ 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.getFileWebPath(),
+ frVo.getFileWebUrl() + frVo.getFileWebPath(),
+ null,
+ frVo.fileWebDownloadPath + id) ;
+ return BaseResponseUtils.buildSuccess(fvo) ;
+ }else {
+ return BaseResponseUtils.buildError("鏈緱鍒颁笂浼犳枃浠剁殑鎵╁睍鍚�");
+ }
+ }else {
+ return BaseResponseUtils.buildError("鏈兘鎷嗗垎涓婁紶鏂囦欢鍚嶇О");
+ }
+ } else {
+ return BaseResponseUtils.buildError("鏈笂浼犳枃浠�");
+ }
+ } catch (Exception e) {
+ log.error("涓婁紶鐓х墖鏂囦欢寮傚父", e);
+ return BaseResponseUtils.buildException(e.getMessage());
+ }
+ }
+
+
+ /**
+ * 鏁版嵁搴撳瓨鍌�
+ * @param orgName 鏂囦欢鍘熷悕绉�
+ * @param extName 鏂囦欢鎵╁睍鍚�
+ * @param newName 鏂囦欢鏂板悕绉�
+ * @param hash 鏂囦欢鏂板悕绉扮殑鍝堝笇鍊�
+ * @param filePath 鏂囦欢鏈嶅姟绔瓨鍌ㄧ浉瀵硅矾寰�
+ * @return 鏁版嵁璁板綍涓婚敭
+ */
+ private Long saveFileInfo(String orgName, String extName, String newName, Integer hash, String filePath){
+ WebFile po = new WebFile() ;
+ po.orgName = orgName ;
+ po.extName = extName ;
+ po.newName = newName ;
+ po.hash = hash ;
+ po.filePath = filePath ;
+ po.dt = new Date() ;
+ return this.sv.save(po) ;
+ }
+
+}
--
Gitblit v1.8.0