From a0f4d01559785001e7b16b21025cc6a42e65d167 Mon Sep 17 00:00:00 2001
From: sgj <1442489573@qq.com>
Date: 星期五, 05 十二月 2025 17:36:31 +0800
Subject: [PATCH] 添加ai事件管理页面

---
 fzzy-igdss-web/src/main/java/com/fzzy/sys/manager/file/FileManager.java |  133 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 133 insertions(+), 0 deletions(-)

diff --git a/fzzy-igdss-web/src/main/java/com/fzzy/sys/manager/file/FileManager.java b/fzzy-igdss-web/src/main/java/com/fzzy/sys/manager/file/FileManager.java
new file mode 100644
index 0000000..6318747
--- /dev/null
+++ b/fzzy-igdss-web/src/main/java/com/fzzy/sys/manager/file/FileManager.java
@@ -0,0 +1,133 @@
+package com.fzzy.sys.manager.file;
+
+import com.fzzy.igds.constant.RespCodeEnum;
+import com.fzzy.igds.data.PageResponse;
+import com.fzzy.igds.domain.Dept;
+import com.fzzy.igds.service.CoreDeptService;
+import com.fzzy.igds.service.FileService;
+import com.fzzy.igds.utils.ContextUtil;
+import com.ruoyi.common.utils.StringUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+import javax.annotation.Resource;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Date;
+
+/**
+ * @Description 鍑哄叆搴撹澶囩浉鍏冲姛鑳�
+ * @Author CZT
+ * @Date 2025/12/4 9:27
+ */
+@Slf4j
+@Component("file.fileManager")
+public class FileManager {
+	@Resource
+	private CoreDeptService coreDeptService;
+	@Resource
+	private FileService fileService;
+
+	/**
+	 * 鏍规嵁鍗曚綅ID鑾峰彇鍗曚綅淇℃伅
+	 *
+	 * @param deptId
+	 * @return
+	 */
+	public String getDeptFile(String deptId) {
+		if (StringUtils.isEmpty(deptId)) {
+			return null;
+		}
+		String imgBathPath = "鏈笂浼�";
+		Dept dept = coreDeptService.getDeptById(deptId);
+
+		if (StringUtils.isNotEmpty(dept.getImgName())) {
+			File imgFile = new File(dept.getImgName());
+			if (imgFile.exists()) {
+				imgBathPath = dept.getImgName();
+			}
+		}
+		return imgBathPath;
+	}
+
+	/**
+	 * 鍑哄叆搴撶殑闄勪欢涓婃锛屽弬鏁版槸杞︾墝鍙�
+	 *
+	 * @param file
+	 * @return
+	 * @throws IOException
+	 */
+	public PageResponse<String> upLoadInoutHandleImg(MultipartFile file, String plateNum)
+			throws IOException {
+
+		log.debug("涓婁紶鍑哄叆搴撶殑闄勪欢鈥︹��");
+
+		// 鑾峰彇榛樿缂栫爜鐨勫瓧鑺傛暟缁�
+		byte[] fileByte = file.getBytes();
+
+		// 鑾峰彇鏂囦欢鐨勬簮鏂囦欢鍚嶇О
+		String oldFileName = file.getOriginalFilename();
+
+		// 鑾峰彇鏂囦欢淇濆瓨璺緞
+		String filePath = fileService.getFileSavePath("INOUT");
+
+		// 鑾峰彇鏂扮殑ID
+		String newFileName = ContextUtil.generateId();
+
+		// 鏂囦欢鍚庣紑鍚�
+		String suffixName = oldFileName.substring(oldFileName.lastIndexOf("."));
+
+		// 鍚堟垚鏂扮殑鏂囦欢鍚�
+		if (StringUtils.isEmpty(plateNum)) {
+			newFileName = newFileName + suffixName;
+		} else {
+			newFileName = plateNum + "_" + newFileName + suffixName;
+		}
+
+		// 鏂囦欢涓婁紶
+		boolean flag = uploadFile(fileByte, filePath, newFileName);
+
+		// 鍒ゆ柇鏂囦欢涓婁紶鏄惁鎴愬姛,鎴愬姛杩斿洖鏂囦欢鍚�
+		if (flag) {
+			return new PageResponse<String>(RespCodeEnum.CODE_0000.getCode(),
+					newFileName);
+		} else {
+			return new PageResponse<String>(RespCodeEnum.CODE_1111.getCode(),
+					"涓婁紶澶辫触");
+		}
+	}
+
+	/**
+	 * 鏂囦欢娴佷笂浼犳枃浠�
+	 *
+	 * @param file
+	 * @param filePath
+	 * @param fileName
+	 * @return
+	 */
+	private static boolean uploadFile(byte[] file, String filePath, String fileName) throws IOException {
+		// 榛樿鏂囦欢涓婁紶鎴愬姛
+		boolean flag = true;
+		// new涓�涓枃浠跺璞″疄渚�
+		File targetFile = new File(filePath);
+		// 濡傛灉褰撳墠鏂囦欢鐩綍涓嶅瓨鍦ㄥ氨鑷姩鍒涘缓璇ユ枃浠舵垨鑰呯洰褰�
+		if (!targetFile.exists()) {
+			targetFile.mkdirs();
+		}
+		// 鍒涘缓鏂囦欢娴�
+		FileOutputStream fileOutputStream = new FileOutputStream(filePath + fileName);
+		try {
+			fileOutputStream.write(file);
+		} catch (FileNotFoundException e) {
+			flag = false;
+		} catch (IOException ioException) {
+			flag = false;
+		} finally {
+			fileOutputStream.flush();
+			fileOutputStream.close();
+		}
+		return flag;
+	}
+}

--
Gitblit v1.9.3