From 2f1913cbfd84fe580cdd48b810251fdf2ad29112 Mon Sep 17 00:00:00 2001
From: 6c <420680616@qq.com>
Date: 星期五, 17 四月 2026 14:22:52 +0800
Subject: [PATCH] 组件-个人签名

---
 src/main/java/com/product/file/service/FileManagerService.java |   79 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 69 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/product/file/service/FileManagerService.java b/src/main/java/com/product/file/service/FileManagerService.java
index db4ae7e..9d4b832 100644
--- a/src/main/java/com/product/file/service/FileManagerService.java
+++ b/src/main/java/com/product/file/service/FileManagerService.java
@@ -31,6 +31,7 @@
 import okhttp3.MediaType;
 import okhttp3.MultipartBody;
 import okhttp3.RequestBody;
+import org.apache.commons.codec.binary.Base64;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -266,6 +267,11 @@
 			return false;
 		}
 
+        // 瀛樻斁鍦ㄦ暟鎹簱涓殑鏂囦欢锛岀洿鎺ュ垽瀹氭槸鍚︽湁鍊�
+        if (attachmentFse.getValue(CmnConst.FILE_CONTENT) != null) {
+            return true;
+        }
+
 		//鍒ゆ柇鏂囦欢瀛樻斁鍦ㄦ湇鍔″櫒杩樻槸鏈湴
 		boolean needDownloadFromServerFlag = "1".equals(attachmentFse.getString(CmnConst.UPLOAD_SIGN));
 		String dir = attachmentFse.getString(CmnConst.ATTACHMENT_URL);
@@ -467,7 +473,7 @@
         String fileFinalName = "";
 		for (Map.Entry<Object, Object> entry : map.entrySet()) {
 			fieldFse = fieldMetaEntity.getFieldMeta(fieldName);
-            if (fieldFse == null || !Arrays.asList(CmnConst.ATTACHMENT_TYPE, "file-image", FieldType.FILE_ATTACHMENT.getDictValue()).contains(fieldFse.getString(CmnConst.FIELD_TYPE))) {
+            if (fieldFse == null || !Arrays.asList(CmnConst.ATTACHMENT_TYPE, "file-image", FieldType.FILE_ATTACHMENT.getDictValue(), FieldType.SIGNATURE.getDictValue()).contains(fieldFse.getString(CmnConst.FIELD_TYPE))) {
                 fse.setValue(entry.getKey().toString(), null);
 				continue;
 			}
@@ -499,7 +505,7 @@
 					}
 				}
 
-                boolean saveInDbFlag = FieldType.FILE_ATTACHMENT.getDictValue().equals(fieldFse.getString("field_type"));
+                boolean saveInDbFlag = FieldType.checkSaveInDB(fieldFse.getString("field_type"));
                 if (!saveInDbFlag) {
                     fileFinalName = FileUtils.uploadFile(tempFile, templateType, clientUuid);
                 } else {
@@ -886,6 +892,7 @@
                     if (saveInDb) {
                         File localFile = new File(Global.getSystemConfig("local.dir", "") + File.separator + attachmentFse.getString(CmnConst.ATTACHMENT_URL) + File.separator + fileName);
                         if (!localFile.exists()) {
+                            localFile.getParentFile().mkdirs();
                             Files.copy(is, localFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                         }
                     }
@@ -947,6 +954,19 @@
 		FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false);
 		return this.getFileContent(attachmentFse);
 	}
+
+    /**
+     * 鑾峰彇鐢ㄦ埛绛惧悕
+     * @return
+     * @throws BaseException
+     */
+    public String getSignature(FieldSetEntity fse) throws BaseException {
+        String bytes = Base64.encodeBase64String(getFileContent(fse.getUUID()));
+        if (bytes == null) {
+            return null;
+        }
+        return "data:image/png;base64," + bytes;
+    }
 
 	/**
 	 * 鏍规嵁闄勪欢uuid鑾峰彇鏂囦欢
@@ -1024,13 +1044,22 @@
 					ftpService.downloadFile(path, os);
 				}
 			} else {
-				// 鐩存帴鍦ㄦ湰鍦扮殑鐩綍涓壘鏂囦欢
-				String localBasePath = Global.getSystemConfig("local.dir", "");
-				path = localBasePath + File.separator + path;
-				File file = new File(path);
-				int len;
-				byte[] b = new byte[1024];
-				try (InputStream is = new FileInputStream(file)) {
+                InputStream is = null;
+                try {
+                    Object fileContent = attachmentFse.getValue("file_content");
+                    boolean saveInDb = fileContent != null;
+                    if (saveInDb) {
+                        // 瀛樺偍鍒版暟鎹簱
+                        is = (InputStream) fileContent;
+                    } else {
+                        // 鐩存帴鍦ㄦ湰鍦扮殑鐩綍涓壘鏂囦欢
+                        String localBasePath = Global.getSystemConfig("local.dir", "");
+                        path = localBasePath + File.separator + path;
+                        File file = new File(path);
+                        is = Files.newInputStream(file.toPath());
+                    }
+                    int len;
+                    byte[] b = new byte[1024];
 					while ((len = is.read(b)) > 0) {
 						if (Global.getPropertyToBoolean("file.encrypt", "true")) {
 							// 闇�瑕佽В瀵�
@@ -1040,7 +1069,13 @@
 							os.write(b, 0, len);
 						}
 					}
-				}
+				} catch (Exception e) {
+                    throw new BaseException(FileCode.GET_FILE_BYTES_FAIL);
+                } finally {
+                    if (is != null) {
+                        is.close();
+                    }
+                }
 			}
 
 			return os.toByteArray();
@@ -1229,4 +1264,28 @@
 		return flag;
 	}
 
+    /**
+     * 楠岃瘉鏄惁鍙互棰勮
+     * @param fse
+     * @return
+     */
+    public Object checkPreview(FieldSetEntity fse) {
+        String fileName = fse.getString("file_name");
+        boolean allowPreviewFlag = Global.getPropertyToBoolean("file.view.online", "true");
+        List<String> canTransferFormatList = Lists.newArrayList(Arrays.asList(Global.getSystemConfig("can.transfer.format", "").split(",")));
+        List<String> canDirectPreviewList = Lists.newArrayList(Arrays.asList(Global.getSystemConfig("can.direct.view.online.format", "").split(",")));
+        List<String> canPreviewList = Lists.newArrayList();
+        canPreviewList.addAll(canTransferFormatList);
+        canPreviewList.addAll(canDirectPreviewList);
+        if (StringUtils.isEmpty(fileName)) {
+            if (allowPreviewFlag) {
+                return BaseUtil.collection2String(canPreviewList);
+            } else {
+                return "";
+            }
+        } else {
+            String tail = fileName.substring(fileName.lastIndexOf(".") + 1);
+            return allowPreviewFlag && canPreviewList.contains(tail);
+        }
+    }
 }

--
Gitblit v1.9.2