From 02d038387df02b1e4dcf140c3e78c6f95719155e Mon Sep 17 00:00:00 2001
From: 许鹏程 <1821349743@qq.com>
Date: 星期二, 11 二月 2025 10:50:53 +0800
Subject: [PATCH] excel文件预览app端特殊处理

---
 src/main/java/com/product/file/service/FileManagerService.java |   40 +++++++++++++++++++---------------------
 1 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/src/main/java/com/product/file/service/FileManagerService.java b/src/main/java/com/product/file/service/FileManagerService.java
index 9dd7f0b..e8d3efe 100644
--- a/src/main/java/com/product/file/service/FileManagerService.java
+++ b/src/main/java/com/product/file/service/FileManagerService.java
@@ -1,9 +1,11 @@
 package com.product.file.service;
 
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.product.common.lang.StringUtils;
+import com.product.core.config.CoreConst;
 import com.product.core.config.Global;
 import com.product.core.connection.ConnectionManager;
 import com.product.core.dao.BaseDao;
@@ -465,13 +467,17 @@
 		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);
-//		if (needOnlineViewFlag && !realFileName.endsWith(".xlsx") && !realFileName.endsWith(".xls")) {
-//			// 闇�瑕佸湪绾块瑙堜笖杞崲涔嬪悗鎵嶈兘鍦ㄧ嚎棰勮 excel 鏂囦欢涓嶉渶瑕佽浆鎹㈢洿鎺ヨ緭鍑洪瑙�
-//			dir += File.separator + CmnConst.TRANSFER_DIR_NAME;
-//		}
+		String clientType = SpringMVCContextHolder.getCurrentUser().getClientType();
+
+		String contentType = "multipart/form-data";
+		boolean isExcel = realFileName.endsWith(".xlsx") || realFileName.endsWith(".xls");
 		if (needOnlineViewFlag) {
-			// 闇�瑕佸湪绾块瑙堜笖杞崲涔嬪悗鎵嶈兘鍦ㄧ嚎棰勮 excel 鏂囦欢涓嶉渶瑕佽浆鎹㈢洿鎺ヨ緭鍑洪瑙�
-			dir += File.separator + CmnConst.TRANSFER_DIR_NAME;
+			//鐗规畩澶勭悊锛� 濡傛灉瀹㈡埛绔笉鏄疉pp 浣嗛瑙堢殑鏂囦欢鏄疎xcel 鐩存帴杩斿洖excel婧愭枃浠� content澶存爣璇嗘槸excel cheng 2025骞�2鏈�11鏃�10:41:41
+			if (isExcel && !CoreConst.CLIENT_TYPE_APP.equals(clientType)) {
+				contentType = "application/vnd.ms-excel";
+			} else {
+				dir += File.separator + CmnConst.TRANSFER_DIR_NAME;
+			}
 		}
 
 		String path = dir + File.separator + fileName;
@@ -480,13 +486,8 @@
 			FTPService ftpService = new FTPService();
 			logger.info("闇�瑕佷粠闄勪欢鏈嶅姟鍣ㄤ笂鍙栨枃浠�...");
 			response.setHeader("Access-Control-Expose-Headers", "*");
-//			if (realFileName.endsWith(".xlsx") || realFileName.endsWith(".xls")) {
-//				response.setContentType("application/vnd.ms-excel");
-//			} else {
-//				response.setContentType("multipart/form-data");
-//			}
 
-			response.setContentType("multipart/form-data");
+			response.setContentType(contentType);
 			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(realFileName, "UTF-8"));
 			//璁剧疆澶翠腑鐨勬枃浠剁被鍨�
 			if (!needOnlineViewFlag && !encrptSignFlag) {
@@ -537,12 +538,14 @@
 			String localBasePath = Global.getSystemConfig("local.dir", "");
 			path = localBasePath + File.separator + path;
 			File file = new File(path);
-			if (needOnlineViewFlag && file.exists() && (realFileName.endsWith(".xlsx") || realFileName.endsWith(".xls"))) {
-				//鑾峰彇鏂囦欢鐨勪慨鏀规椂闂�
+			if (needOnlineViewFlag && file.exists() && CoreConst.CLIENT_TYPE_APP.equals(clientType)) {
+				//鐗规畩澶勭悊锛� 鏄疉pp 浣嗛瑙堢殑鏂囦欢鏄疎xcel 闇�瑕佸皢涔嬪墠宸茶浆鎹负鐨勬枃浠跺垹闄ゆ帀閲嶆柊杞崲锛堝洜杞崲鍚庣殑鏍煎紡涓嶆槸pdf)
+				String changeTime = "2025-02-11 23:59:59";
+				Date changeDate = DateUtil.parse(changeTime, "yyyy-MM-dd HH:mm:ss");
 				long fileTime = file.lastModified();
 				//濡傛灉鏃堕棿鏄� 2025骞�2鏈�10鏃�23:59:59锛岄偅涔堝氨閲嶆柊杞崲
 				//鍒犻櫎鏂囦欢
-				if (fileTime <= 1739203198000L) {
+				if (fileTime <= changeDate.getTime()) {
 					file.delete();
 				}
 			}
@@ -558,13 +561,8 @@
 			byte[] b = new byte[1024];
 			InputStream is = new FileInputStream(file);
 			response.setHeader("Access-Control-Expose-Headers", "*");
-//			if (realFileName.endsWith(".xlsx") || realFileName.endsWith(".xls")) {
-//				response.setContentType("application/vnd.ms-excel");
-//			} else {
-//				response.setContentType("multipart/form-data");
-//			}
 
-			response.setContentType("multipart/form-data");
+			response.setContentType(contentType);
 			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(realFileName, "UTF-8"));
 			response.setContentLengthLong(file.length());
 			try (ServletOutputStream os = response.getOutputStream()) {

--
Gitblit v1.9.2