From 42ccf1da495016bf4574f631faad41f586613df9 Mon Sep 17 00:00:00 2001
From: shicf <shi_chongfu@163.com>
Date: 星期三, 15 十月 2025 09:32:18 +0800
Subject: [PATCH] 附件支持存放数据库,读取从数据库获取

---
 src/main/java/com/product/file/service/FileManagerService.java |   64 ++++++++++++++++++++++++++++----
 1 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/product/file/service/FileManagerService.java b/src/main/java/com/product/file/service/FileManagerService.java
index b20eae9..2e15c93 100644
--- a/src/main/java/com/product/file/service/FileManagerService.java
+++ b/src/main/java/com/product/file/service/FileManagerService.java
@@ -18,6 +18,7 @@
 import com.product.core.spring.context.SpringMVCContextHolder;
 import com.product.file.config.CmnConst;
 import com.product.file.config.FileCode;
+import com.product.file.util.AsposeUtil;
 import com.product.file.util.CreateDocumentIndexThread;
 import com.product.file.util.FileUtil;
 import com.product.file.util.FileUtils;
@@ -50,6 +51,15 @@
 	public BaseDao baseDao;
 	@Autowired
 	FileUtils fileUtils;
+	
+	/**
+	 *  鏍囪鏂囦欢宸茶淇敼
+	 * @param uuid
+	 * @param userId
+	 */
+	public void signUpdateAttachment(String uuid, int userId) {
+		baseDao.executeUpdate("UPDATE product_sys_attachments SET updated_by = ?, updated_utc_datetime = NOW() WHERE uuid = ?", new Object[] {userId, uuid});
+	}
 
 	/**
 	 * 鑾峰彇闈欐�佽祫婧�
@@ -351,9 +361,17 @@
 					}
 				}
 
-
+				
 				final String fileFinalName = FileUtils.uploadFile(tempFile, templateType, clientUuid);
-
+				///鍒ゆ柇闄勪欢瀛楁鐨勭被鍨嬩负FileAttachment鏃讹紝瑕佹妸鏂囨。鍐呭鏀惧埌闄勪欢琛ㄤ腑鐨刦ile_content瀛楁涓�
+				
+				///璇诲彇闄勪欢鏃讹紝鏍规嵁瀛楁绫诲瀷FileAttachment鍒ゆ柇鏄粠鐩綍涓繕鏄暟鎹簱涓幏鍙栨枃浠�
+				
+				//寰呮敼......
+				//闆嗙兢甯冪讲鏃讹紝闄勪欢淇℃伅瑕佸悓姝ュ埌鍏跺畠鏈嶅姟鍣ㄤ笂
+				//寰呮敼
+				
+				
 				// 璁板綍闄勪欢淇℃伅鍒版暟鎹簱
 				logger.info("姝e湪璁板綍闄勪欢淇℃伅鍒版暟鎹簱...");
 				FieldSetEntity dictFse = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_DICT,
@@ -445,16 +463,17 @@
 			}
 		}
 	}
+
 	/**
 	 * 绉诲姩绔崌绾э紝瀹夎鍖呬笅杞�
 	 *
 	 * @param fse
 	 * @param response
 	 */
-	public void getFileContent(FieldSetEntity fse, HttpServletResponse response,boolean isUpgrade) throws IOException {
-		if(isUpgrade) {
+	public void getFileContent(FieldSetEntity fse, HttpServletResponse response, boolean isUpgrade) throws IOException {
+		if (isUpgrade) {
 			FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, fse.getUUID(), false);
-			if (attachmentFse == null || !"product_sys_app_version".equals(attachmentFse.getString("attachment_data_table")) ) {
+			if (attachmentFse == null || !"product_sys_app_version".equals(attachmentFse.getString("attachment_data_table"))) {
 				return;
 			}
 			logger.info("姝e湪鑾峰彇鏂囦欢娴�...");
@@ -466,8 +485,8 @@
 			String viewOnlineSign = attachmentFse.getString(CmnConst.VIEW_ONLINE_SIGN);
 			boolean encrptSignFlag = "1".equals(attachmentFse.getString(CmnConst.ENCRPT_SIGN));
 			boolean needOnlineViewFlag = "1".equals(fse.getString(CmnConst.NEED_ONLINE_VIEW)) && "1".equals(viewOnlineSign);
-			
-			String clientType =CoreConst.CLIENT_TYPE_APP;
+
+			String clientType = CoreConst.CLIENT_TYPE_APP;
 
 			String contentType = "multipart/form-data";
 			boolean isExcel = realFileName.endsWith(".xlsx") || realFileName.endsWith(".xls");
@@ -582,8 +601,9 @@
 			}
 			logger.info("鏂囦欢娴佽幏鍙栨垚鍔�");
 		}
-	
+
 	}
+
 	/**
 	 * 鎻愬彇鏂囦欢淇℃伅-涓嬭浇鏂囦欢鎴栬�呭湪绾块瑙堟枃浠�
 	 *
@@ -656,6 +676,19 @@
 					tempOs.flush();
 					tempOs.close();
 				}
+				boolean delete = false;
+				if (realFileName.endsWith(".xls") && needOnlineViewFlag && localTempFile.exists() && !CoreConst.CLIENT_TYPE_APP.equals(clientType)) {
+					//杞崲涓簒lsx
+					AsposeUtil.xls2xlsx(localTempFile.getPath(), getSystemConfig("temp.dir", "/attachment/temp") + "/" + localTempFile.getName(), "xls");
+					File oldFile = localTempFile;
+					localTempFile = new File(getSystemConfig("temp.dir", "/attachment/temp") + "/" + localTempFile.getName());
+					if (!localTempFile.isFile()) {
+						localTempFile = oldFile;
+					} else {
+						delete = true;
+						oldFile.delete();
+					}
+				}
 				response.setContentLengthLong(localTempFile.length());
 				InputStream is = new FileInputStream(localTempFile);
 				int len;
@@ -695,6 +728,18 @@
 				FileUtils.convertPdf(false, false, encrptSignFlag, true, tempSourceFile, dir, fileName, attachmentFse.getString(CmnConst.FILE_NAME));
 				tempSourceFile.delete();
 			}
+			boolean delete = false;
+			if (realFileName.endsWith(".xls") && needOnlineViewFlag && file.exists() && !CoreConst.CLIENT_TYPE_APP.equals(clientType)) {
+				//杞崲涓簒lsx
+				AsposeUtil.xls2xlsx(file.getPath(), getSystemConfig("temp.dir", "/attachment/temp") + "/" + file.getName(), "xls");
+				File oldFile = file;
+				file = new File(getSystemConfig("temp.dir", "/attachment/temp") + "/" + file.getName());
+				if (!file.isFile()) {
+					file = oldFile;
+				} else {
+					delete = true;
+				}
+			}
 			int len;
 			byte[] b = new byte[1024];
 			InputStream is = new FileInputStream(file);
@@ -717,6 +762,9 @@
 				os.flush();
 			}
 			is.close();
+			if (delete) {
+				file.delete();
+			}
 		}
 		logger.info("鏂囦欢娴佽幏鍙栨垚鍔�");
 	}

--
Gitblit v1.9.2