From c15fe6d34afc94c95a1c9f496649b405163337a2 Mon Sep 17 00:00:00 2001
From: 杜洪波 <1074825718@qq.com>
Date: 星期一, 18 八月 2025 15:51:14 +0800
Subject: [PATCH] java代码转PDF
---
src/main/java/com/product/file/service/FileManagerService.java | 1657 ++++++++++++++++++++++++++++++++++------------------------
1 files changed, 958 insertions(+), 699 deletions(-)
diff --git a/src/main/java/com/product/file/service/FileManagerService.java b/src/main/java/com/product/file/service/FileManagerService.java
index e1fd43b..144a958 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;
@@ -16,23 +18,21 @@
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;
import com.product.module.sys.entity.SystemUser;
+import com.product.util.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
+import java.net.URLEncoder;
import java.text.SimpleDateFormat;
-import java.time.OffsetDateTime;
import java.util.*;
-import java.util.concurrent.TimeUnit;
/**
* Copyright LX-BASE
@@ -47,749 +47,1008 @@
@Service("fileManagerService")
public class FileManagerService extends AbstractBaseService {
- @Autowired
- public BaseDao baseDao;
- @Autowired
- FileUtils fileUtils;
+ @Autowired
+ 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});
+ }
- /**
- * 鑾峰彇闈欐�佽祫婧�
- *
- * @param uuid
- * @param response
- * @throws IOException
- * @throws BaseException
- */
- public void getStaticFile(String uuid, HttpServletResponse response) throws IOException, BaseException {
- String systemConfig = Global.getSystemConfig("file.static", "");
- if (StringUtils.isEmpty(uuid) || StringUtils.isEmpty(systemConfig)) {
- throw new BaseException(FileCode.GET_FILE_FAIL);
- }
- FieldSetEntity fs = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false);
- if (fs == null || StringUtils.isEmpty(fs.getString("attachment_data_table")) || StringUtils.isEmpty(fs.getString("attachment_data_field"))) {
- throw new BaseException(FileCode.GET_FILE_FAIL);
- }
- List<String> list = new ArrayList<>(Arrays.asList(systemConfig.split(",")));
- if (list != null && list.size() > 0) {
- if (list.contains((fs.getString("attachment_data_table") + "." + fs.getString("attachment_data_field")))) {
- // 鍏佽鐨勯潤鎬佽祫婧�
- this.getFileContent(fs, response);
- return;
- }
- }
- throw new BaseException(FileCode.GET_FILE_FAIL);
- }
+ /**
+ * 鑾峰彇闈欐�佽祫婧�
+ *
+ * @param uuid
+ * @param response
+ * @throws IOException
+ * @throws BaseException
+ */
+ public void getStaticFile(String uuid, HttpServletResponse response) throws IOException, BaseException {
+ String systemConfig = Global.getSystemConfig("file.static", "");
+ if (StringUtils.isEmpty(uuid) || StringUtils.isEmpty(systemConfig)) {
+ throw new BaseException(FileCode.GET_FILE_FAIL);
+ }
+ FieldSetEntity fs = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false);
+ if (fs == null || StringUtils.isEmpty(fs.getString("attachment_data_table")) || StringUtils.isEmpty(fs.getString("attachment_data_field"))) {
+ throw new BaseException(FileCode.GET_FILE_FAIL);
+ }
+ List<String> list = new ArrayList<>(Arrays.asList(systemConfig.split(",")));
+ if (list != null && list.size() > 0) {
+ if (list.contains((fs.getString("attachment_data_table") + "." + fs.getString("attachment_data_field")))) {
+ // 鍏佽鐨勯潤鎬佽祫婧�
+ this.getFileContent(fs, response);
+ return;
+ }
+ }
+ throw new BaseException(FileCode.GET_FILE_FAIL);
+ }
- /**
- * 鏂囦欢璁板綍-鏂囦欢鏂板缁撴灉鍥炶皟锛�
- * result-1 鏈嶅姟鍣ㄦ柊澧炴垚鍔燂紝淇敼鐘舵��
- * result-鍏朵粬 鏈嶅姟鍣ㄦ柊澧炲け璐ワ紝鍒犻櫎鍑嗗鏂板鐨勮褰�
- *
- * @param fse 鍙傛暟瀵硅薄
- * @return 缁撴灉
- * @throws BaseException 鍩烘湰寮傚父
- */
- public JSONObject addFileCallback(FieldSetEntity fse) throws BaseException {
- String result = fse.getString(CmnConst.RESULT);
- JSONObject returnResult = new JSONObject();
- if ("1".equals(result)) {
- returnResult.put(CmnConst.TYPE, "update");
- returnResult.put(CmnConst.RESULT, updateFileStatus(fse.getString("uuid"), 2) != null);
- } else {
- returnResult.put(CmnConst.TYPE, "del");
- returnResult.put(CmnConst.RESULT, baseDao.delete(CmnConst.PRODUCT_SYS_ATTACHMENTS, new String[]{fse.getString("uuid")}));
- }
- return returnResult;
- }
+ /**
+ * 鏂囦欢璁板綍-鏂囦欢鏂板缁撴灉鍥炶皟锛�
+ * result-1 鏈嶅姟鍣ㄦ柊澧炴垚鍔燂紝淇敼鐘舵��
+ * result-鍏朵粬 鏈嶅姟鍣ㄦ柊澧炲け璐ワ紝鍒犻櫎鍑嗗鏂板鐨勮褰�
+ *
+ * @param fse 鍙傛暟瀵硅薄
+ * @return 缁撴灉
+ * @throws BaseException 鍩烘湰寮傚父
+ */
+ public JSONObject addFileCallback(FieldSetEntity fse) throws BaseException {
+ String result = fse.getString(CmnConst.RESULT);
+ JSONObject returnResult = new JSONObject();
+ if ("1".equals(result)) {
+ returnResult.put(CmnConst.TYPE, "update");
+ returnResult.put(CmnConst.RESULT, updateFileStatus(fse.getString("uuid"), 2) != null);
+ } else {
+ returnResult.put(CmnConst.TYPE, "del");
+ returnResult.put(CmnConst.RESULT, baseDao.delete(CmnConst.PRODUCT_SYS_ATTACHMENTS, new String[]{fse.getString("uuid")}));
+ }
+ return returnResult;
+ }
- /**
- * 鏂囦欢璁板綍-鍒犻櫎鍑嗗锛堢姸鎬佷慨鏀癸級
- *
- * @param fse 鍙傛暟瀵硅薄
- * @return 寰呭垹闄ょ殑鏂囦欢璁板綍fse
- * @throws BaseException 鍩烘湰寮傚父
- */
- public FieldSetEntity delFileRecordPlan(FieldSetEntity fse) throws BaseException {
- return updateFileStatus(fse.getString("uuid"), 3);
- }
+ /**
+ * 鏂囦欢璁板綍-鍒犻櫎鍑嗗锛堢姸鎬佷慨鏀癸級
+ *
+ * @param fse 鍙傛暟瀵硅薄
+ * @return 寰呭垹闄ょ殑鏂囦欢璁板綍fse
+ * @throws BaseException 鍩烘湰寮傚父
+ */
+ public FieldSetEntity delFileRecordPlan(FieldSetEntity fse) throws BaseException {
+ return updateFileStatus(fse.getString("uuid"), 3);
+ }
- /**
- * 鏂囦欢璁板綍-鏂囦欢鍒犻櫎鍥炶皟锛�
- * result-1 鏈嶅姟鍣ㄥ垹闄ゆ垚鍔燂紝鍒犻櫎鏈湴璁板綍
- * result-鍏朵粬 鏈嶅姟鍣ㄥ垹闄ゅけ璐ワ紝杩樺師鏈湴璁板綍
- *
- * @param fse 鍙傛暟瀵硅薄
- * @return 缁撴灉
- * @throws BaseException 鍩烘湰寮傚父
- */
- public JSONObject delFileCallback(FieldSetEntity fse) throws BaseException {
- String result = fse.getString(CmnConst.RESULT);
- JSONObject returnResult = new JSONObject();
- if ("1".equals(result)) {
- returnResult.put(CmnConst.TYPE, "del");
- returnResult.put(CmnConst.RESULT, baseDao.delete(CmnConst.PRODUCT_SYS_ATTACHMENTS, new String[]{fse.getString("uuid")}));
- } else {
- returnResult.put(CmnConst.TYPE, "update");
- returnResult.put(CmnConst.RESULT, updateFileStatus(fse.getString("uuid"), 2) != null);
- }
- return returnResult;
- }
+ /**
+ * 鏂囦欢璁板綍-鏂囦欢鍒犻櫎鍥炶皟锛�
+ * result-1 鏈嶅姟鍣ㄥ垹闄ゆ垚鍔燂紝鍒犻櫎鏈湴璁板綍
+ * result-鍏朵粬 鏈嶅姟鍣ㄥ垹闄ゅけ璐ワ紝杩樺師鏈湴璁板綍
+ *
+ * @param fse 鍙傛暟瀵硅薄
+ * @return 缁撴灉
+ * @throws BaseException 鍩烘湰寮傚父
+ */
+ public JSONObject delFileCallback(FieldSetEntity fse) throws BaseException {
+ String result = fse.getString(CmnConst.RESULT);
+ JSONObject returnResult = new JSONObject();
+ if ("1".equals(result)) {
+ returnResult.put(CmnConst.TYPE, "del");
+ returnResult.put(CmnConst.RESULT, baseDao.delete(CmnConst.PRODUCT_SYS_ATTACHMENTS, new String[]{fse.getString("uuid")}));
+ } else {
+ returnResult.put(CmnConst.TYPE, "update");
+ returnResult.put(CmnConst.RESULT, updateFileStatus(fse.getString("uuid"), 2) != null);
+ }
+ return returnResult;
+ }
- /**
- * 淇敼鏂囦欢鐘舵��
- *
- * @param fileUUID 鏂囦欢UUID
- * @param status 寰呬慨鏀圭殑鐘舵��
- * @return 鏄惁鎴愬姛
- * @throws BaseException 鍩烘湰寮傚父
- */
- private FieldSetEntity updateFileStatus(String fileUUID, int status) throws BaseException {
- FieldSetEntity fse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, fileUUID, false);
- fse.setValue("opt_flat", status);
- fse.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
- fse.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date());
- baseDao.update(fse);
+ /**
+ * 淇敼鏂囦欢鐘舵��
+ *
+ * @param fileUUID 鏂囦欢UUID
+ * @param status 寰呬慨鏀圭殑鐘舵��
+ * @return 鏄惁鎴愬姛
+ * @throws BaseException 鍩烘湰寮傚父
+ */
+ private FieldSetEntity updateFileStatus(String fileUUID, int status) throws BaseException {
+ FieldSetEntity fse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, fileUUID, false);
+ fse.setValue("opt_flat", status);
+ fse.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
+ fse.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date());
+ baseDao.update(fse);
- fse.setValue(CmnConst.SOURCE_DOMAIN, Global.getSystemConfig(CmnConst.SOURCE_DOMAIN, ""));
- return fse;
- }
+ fse.setValue(CmnConst.SOURCE_DOMAIN, Global.getSystemConfig(CmnConst.SOURCE_DOMAIN, ""));
+ return fse;
+ }
- /**
- * 鑾峰彇瀹㈡埛涓婁紶鐨勬枃浠舵�诲ぇ灏�
- *
- * @param clientUUID 瀹㈡埛UUID
- * @return 宸蹭笂浼犳枃浠舵�诲ぇ灏�
- * @throws BaseException 鍩烘湰寮傚父
- */
- public long findClientFileUsedCapacity(String clientUUID) throws BaseException {
- StringBuilder sql = new StringBuilder()
- .append("\nselect sum(attachment_size) usedCapacity from ").append(CmnConst.PRODUCT_SYS_ATTACHMENTS)
- .append("\nwhere client_uuid=?");
- DataTableEntity dt = baseDao.listTable(sql.toString(), new Object[]{clientUUID});
- FieldSetEntity fse;
- long usedCapacity = 0;
- if (dt.getRows() == 1) {
- fse = dt.getFieldSetEntity(0);
- usedCapacity = fse.getLong("usedCapacity") == null ? 0 : fse.getLong("usedCapacity");
- }
- return usedCapacity;
- }
+ /**
+ * 鑾峰彇瀹㈡埛涓婁紶鐨勬枃浠舵�诲ぇ灏�
+ *
+ * @param clientUUID 瀹㈡埛UUID
+ * @return 宸蹭笂浼犳枃浠舵�诲ぇ灏�
+ * @throws BaseException 鍩烘湰寮傚父
+ */
+ public long findClientFileUsedCapacity(String clientUUID) throws BaseException {
+ StringBuilder sql = new StringBuilder()
+ .append("\nselect sum(attachment_size) usedCapacity from ").append(CmnConst.PRODUCT_SYS_ATTACHMENTS)
+ .append("\nwhere client_uuid=?");
+ DataTableEntity dt = baseDao.listTable(sql.toString(), new Object[]{clientUUID});
+ FieldSetEntity fse;
+ long usedCapacity = 0;
+ if (dt.getRows() == 1) {
+ fse = dt.getFieldSetEntity(0);
+ usedCapacity = fse.getLong("usedCapacity") == null ? 0 : fse.getLong("usedCapacity");
+ }
+ return usedCapacity;
+ }
- /**
- * 鑾峰彇瀹㈡埛鍓╀綑鐨勬枃浠舵�诲ぇ灏�
- *
- * @return 鍓╀綑绌洪棿澶у皬
- */
- public long findClientFileResidueCapacity(String CLIENT_UUID) throws BaseException {
- FieldSetEntity clientFse = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_CLIENTS, "uuid=?", new String[]{CLIENT_UUID}, false);
- return findClientFileResidueCapacity(clientFse);
- }
+ /**
+ * 鑾峰彇瀹㈡埛鍓╀綑鐨勬枃浠舵�诲ぇ灏�
+ *
+ * @return 鍓╀綑绌洪棿澶у皬
+ */
+ public long findClientFileResidueCapacity(String CLIENT_UUID) throws BaseException {
+ FieldSetEntity clientFse = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_CLIENTS, "uuid=?", new String[]{CLIENT_UUID}, false);
+ return findClientFileResidueCapacity(clientFse);
+ }
- /**
- * 鑾峰彇瀹㈡埛鍓╀綑鐨勬枃浠舵�诲ぇ灏�
- *
- * @param fse 瀹㈡埛fse
- * @return 鍓╀綑绌洪棿澶у皬
- */
- public long findClientFileResidueCapacity(FieldSetEntity fse) throws BaseException {
- long clientCapacity = fse.getLong(CmnConst.ATTACHMENT_CAPACITY) == null ? 0 : fse.getInteger(CmnConst.ATTACHMENT_CAPACITY);
- long usedCapacity = findClientFileUsedCapacity(fse.getString("uuid"));
- return clientCapacity - usedCapacity;
- }
+ /**
+ * 鑾峰彇瀹㈡埛鍓╀綑鐨勬枃浠舵�诲ぇ灏�
+ *
+ * @param fse 瀹㈡埛fse
+ * @return 鍓╀綑绌洪棿澶у皬
+ */
+ public long findClientFileResidueCapacity(FieldSetEntity fse) throws BaseException {
+ long clientCapacity = fse.getLong(CmnConst.ATTACHMENT_CAPACITY) == null ? 0 : fse.getInteger(CmnConst.ATTACHMENT_CAPACITY);
+ long usedCapacity = findClientFileUsedCapacity(fse.getString("uuid"));
+ return clientCapacity - usedCapacity;
+ }
- /**
- * 楠岃瘉鏄惁鍏佽涓婁紶鐨勬枃浠剁被鍨�
- *
- * @param attachmentTitle 鏂囦欢鍚嶇О
- * @return 鏄惁
- */
- public boolean checkIsAllowedFileType(String attachmentTitle) {
- if (StringUtils.isEmpty(attachmentTitle) || attachmentTitle.lastIndexOf(".") < 0 || attachmentTitle.length() < 1) {
- return false;
- }
- String curFileTail = attachmentTitle.substring(attachmentTitle.lastIndexOf(".") + 1, attachmentTitle.length());
- String allowedFileTypes = Global.getSystemConfig("allowed_file_type", "").toLowerCase(Locale.ROOT);
- return allowedFileTypes != null && ("," + allowedFileTypes + ",").contains("," + curFileTail.toLowerCase() + ",");
- }
+ /**
+ * 楠岃瘉鏄惁鍏佽涓婁紶鐨勬枃浠剁被鍨�
+ *
+ * @param attachmentTitle 鏂囦欢鍚嶇О
+ * @return 鏄惁
+ */
+ public boolean checkIsAllowedFileType(String attachmentTitle) {
+ if (StringUtils.isEmpty(attachmentTitle) || attachmentTitle.lastIndexOf(".") < 0 || attachmentTitle.length() < 1) {
+ return false;
+ }
+ String curFileTail = attachmentTitle.substring(attachmentTitle.lastIndexOf(".") + 1, attachmentTitle.length());
+ String allowedFileTypes = Global.getSystemConfig("allowed_file_type", "").toLowerCase(Locale.ROOT);
+ return allowedFileTypes != null && ("," + allowedFileTypes + ",").contains("," + curFileTail.toLowerCase() + ",");
+ }
- /**
- * 鑾峰彇鍘熷鍩熷悕
- *
- * @return 鍘熷鍩熷悕
- */
- public String findSourceDomain() {
- return Global.getSystemConfig(CmnConst.SOURCE_DOMAIN, "");
- }
+ /**
+ * 鑾峰彇鍘熷鍩熷悕
+ *
+ * @return 鍘熷鍩熷悕
+ */
+ public String findSourceDomain() {
+ return Global.getSystemConfig(CmnConst.SOURCE_DOMAIN, "");
+ }
- /**
- * 瀹氭椂浠诲姟锛氳嚜鍔ㄦ竻鐞嗘棤鐢ㄦ暟鎹�
- */
- public boolean autoClearNoUsedData() throws BaseException {
- StringBuilder sql = new StringBuilder()
- .append("\ndelete from ").append(CmnConst.PRODUCT_SYS_ATTACHMENTS)
- .append("\nwhere opt_flat in (1,3)")
- .append("\nand ").append(CmnConst.CREATED_BY).append("<=date_format(adddate(now(),-1),'%Y-%m-%d')");
- return baseDao.executeUpdate(sql.toString());
- }
+ /**
+ * 瀹氭椂浠诲姟锛氳嚜鍔ㄦ竻鐞嗘棤鐢ㄦ暟鎹�
+ */
+ public boolean autoClearNoUsedData() throws BaseException {
+ StringBuilder sql = new StringBuilder()
+ .append("\ndelete from ").append(CmnConst.PRODUCT_SYS_ATTACHMENTS)
+ .append("\nwhere opt_flat in (1,3)")
+ .append("\nand ").append(CmnConst.CREATED_BY).append("<=date_format(adddate(now(),-1),'%Y-%m-%d')");
+ return baseDao.executeUpdate(sql.toString());
+ }
+ /**
+ * 鏍规嵁闄勪欢uuid鍒ゆ柇鏂囦欢鏄惁瀛樺湪
+ *
+ * @param uuid
+ * @return
+ */
+ public boolean fileExist(String uuid) {
+ if (StringUtils.isEmpty(uuid)) {
+ return false;
+ }
+ FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false);
+ if (attachmentFse == null) {
+ return false;
+ }
- /**
- * 涓婁紶鏂囦欢鍒版湰鍦版湇鍔″櫒
- * 绂佹淇敼浠讳綍閫昏緫锛侊紒锛侊紒锛侊紒
- *
- * @param rpe
- * @return
- */
- public FieldSetEntity uploadFile(RequestParameterEntity rpe) {
- FieldSetEntity fse = rpe.getFormData().clones();
+ //鍒ゆ柇鏂囦欢瀛樻斁鍦ㄦ湇鍔″櫒杩樻槸鏈湴
+ boolean needDownloadFromServerFlag = "1".equals(attachmentFse.getString(CmnConst.UPLOAD_SIGN));
+ String dir = attachmentFse.getString(CmnConst.ATTACHMENT_URL);
+ String fileName = attachmentFse.getString(CmnConst.ATTACHMENT_TITLE);
+ boolean encrptSignFlag = "1".equals(attachmentFse.getString(CmnConst.ENCRPT_SIGN));
- Map<String, File> fileMap = rpe.getFiles();
+ if (needDownloadFromServerFlag) {
+ // 闇�瑕佷粠闄勪欢鏈嶅姟鍣ㄤ笂鍙栨枃浠�
+ FTPService ftpService = new FTPService();
+ return ftpService.fileIsExist(dir, fileName);
+ } else {
+ // 鐩存帴鍦ㄦ湰鍦扮殑鐩綍涓壘鏂囦欢
+ String localBasePath = Global.getSystemConfig("local.dir", "");
+ String path = localBasePath + File.separator + dir + File.separator + fileName;
+ File file = new File(path);
+ return file.isFile();
+ }
+ }
- SystemUser user = SpringMVCContextHolder.getCurrentUser();
- String clientUuid = user == null ? fse.getString("client_uuid") : user.getClient_uuid();
+ /**
+ * 涓婁紶鏂囦欢鍒版湰鍦版湇鍔″櫒
+ * 绂佹淇敼浠讳綍閫昏緫锛侊紒锛侊紒锛侊紒
+ *
+ * @param rpe
+ * @return
+ */
+ public FieldSetEntity uploadFile(RequestParameterEntity rpe) {
+ FieldSetEntity fse = rpe.getFormData().clones();
+
+ Map<String, File> fileMap = rpe.getFiles();
+
+ SystemUser user = SpringMVCContextHolder.getCurrentUser();
+ String clientUuid = user == null ? fse.getString("client_uuid") : user.getClient_uuid();
// long residueCapacity = findClientFileResidueCapacity(clientUuid);
// long fileTotalSize = 0;
- for (Map.Entry<String, File> entry : fileMap.entrySet()) {
- // 鏍煎紡楠岃瘉
- if (!checkIsAllowedFileType(entry.getKey())) {
- throw new BaseException(FileCode.ADD_FILE_NOT_ALLOWED.getValue(), FileCode.ADD_FILE_NOT_ALLOWED.getText() + ":" + entry.getKey().substring(entry.getKey().indexOf(".") + 1));
- }
+ for (Map.Entry<String, File> entry : fileMap.entrySet()) {
+ // 鏍煎紡楠岃瘉
+ if (!checkIsAllowedFileType(entry.getKey())) {
+ throw new BaseException(FileCode.ADD_FILE_NOT_ALLOWED.getValue(), FileCode.ADD_FILE_NOT_ALLOWED.getText() + ":" + entry.getKey().substring(entry.getKey().indexOf(".") + 1));
+ }
// fileTotalSize += (int) entry.getValue().length();
- }
- // 鍓╀綑绌洪棿鍒ゅ畾
+ }
+ // 鍓╀綑绌洪棿鍒ゅ畾
// if (residueCapacity < fileTotalSize) {
// throw new BaseException(FileCode.ADD_FILE_NO_CAPACITY.getValue(), FileCode.ADD_FILE_NO_CAPACITY.getText());
// }
- Map<Object, Object> map = new HashMap<>(fse.getValues());
- ConnectionManager.getConnection();
- FieldMetaEntity fieldMetaEntity = fse.getMeta();
- Object o;
- String fieldName = fse.getString("~field_name~");
- Object value;
- String fileNames;
- FieldSetEntity fieldFse;
- File tempFile;
- File localTempFile = null;
- long fileLength = 0;
+ Map<Object, Object> map = new HashMap<>(fse.getValues());
+ ConnectionManager.getConnection();
+ FieldMetaEntity fieldMetaEntity = fse.getMeta();
+ Object o;
+ String fieldName = fse.getString("~field_name~");
+ Object value;
+ String fileNames;
+ FieldSetEntity fieldFse;
+ File tempFile;
+ File localTempFile = null;
+ long fileLength = 0;
- FTPService ftpService;
- boolean needUpload2FileServerFlag = FTPService.needUpload2FileServer();
- String templateType = fse.getString("template_type");
- String dir;
- if (StringUtils.isEmpty(templateType)) {
- String timeStr = new SimpleDateFormat("yyyyMMdd").format(new Date());
- dir = clientUuid + File.separator + timeStr;
- } else {
- dir = CmnConst.DIR_TEMPLATE + File.separator + ("1".equals(templateType) ? CmnConst.DIR_IMPORT : ("2".equals(templateType) ? CmnConst.DIR_PRINT : CmnConst.DIR_OTHER));
- }
+ FTPService ftpService;
+ boolean needUpload2FileServerFlag = FTPService.needUpload2FileServer();
+ String templateType = fse.getString("template_type");
+ String dir;
+ if (StringUtils.isEmpty(templateType)) {
+ String timeStr = new SimpleDateFormat("yyyyMMdd").format(new Date());
+ dir = clientUuid + File.separator + timeStr;
+ } else {
+ dir = CmnConst.DIR_TEMPLATE + File.separator + ("1".equals(templateType) ? CmnConst.DIR_IMPORT : ("2".equals(templateType) ? CmnConst.DIR_PRINT : CmnConst.DIR_OTHER));
+ }
- String uuids = "";
- for (Map.Entry<Object, Object> entry : map.entrySet()) {
- fieldFse = fieldMetaEntity.getFieldMeta(fieldName);
- if (fieldFse == null || !CmnConst.ATTACHMENT_TYPE.equals(fieldFse.getString(CmnConst.FIELD_TYPE))) {
- fse.setValue(entry.getKey().toString(), null);
- continue;
- }
- // 宸茬粡鍒ゅ畾涓洪檮浠讹紝杩涜鎿嶄綔
- value = entry.getValue();
- if (value == null || StringUtils.isEmpty(fileNames = value.toString())) {
- fse.setValue(entry.getKey().toString(), null);
- continue;
- }
- for (String fileName : fileNames.split(",")) {
- if (StringUtils.isEmpty(fieldName)) {
- fse.setValue(entry.getKey().toString(), null);
- continue;
- }
+ String uuids = "";
+ for (Map.Entry<Object, Object> entry : map.entrySet()) {
+ fieldFse = fieldMetaEntity.getFieldMeta(fieldName);
+ if (fieldFse == null || (!CmnConst.ATTACHMENT_TYPE.equals(fieldFse.getString(CmnConst.FIELD_TYPE)) && !"file-image".equals(fieldFse.getString(CmnConst.FIELD_TYPE)))) {
+ fse.setValue(entry.getKey().toString(), null);
+ continue;
+ }
+ // 宸茬粡鍒ゅ畾涓洪檮浠讹紝杩涜鎿嶄綔
+ value = entry.getValue();
+ if (value == null || StringUtils.isEmpty(fileNames = value.toString())) {
+ fse.setValue(entry.getKey().toString(), null);
+ continue;
+ }
+ for (String fileName : fileNames.split(",")) {
+ if (StringUtils.isEmpty(fieldName)) {
+ fse.setValue(entry.getKey().toString(), null);
+ continue;
+ }
- tempFile = fileMap.get(fileName);
- if (tempFile == null) {
- //涓嶆槸鏂囦欢 璺宠繃
- continue;
- }
- fileLength = tempFile.length();
- String tail = fileName.substring(fileName.lastIndexOf(".") + 1);
- int viewOnlineSign = 0;
- if (("," + Global.getSystemConfig("can.direct.view.online.format", "") + ",").contains("," + tail + ",")) {
- viewOnlineSign = 2;
- } else {
- if (Global.getPropertyToBoolean("file.view.online", "true") && ("," + Global.getSystemConfig("can.transfer.format", "") + ",").contains("," + tail + ",") && StringUtils.isEmpty(templateType)) {
- viewOnlineSign = 1;
- }
- }
+ tempFile = fileMap.get(fileName);
+ if (tempFile == null) {
+ //涓嶆槸鏂囦欢 璺宠繃
+ continue;
+ }
+ fileLength = tempFile.length();
+ String tail = fileName.substring(fileName.lastIndexOf(".") + 1);
+ int viewOnlineSign = 0;
+ if (("," + Global.getSystemConfig("can.direct.view.online.format", "") + ",").contains("," + tail + ",")) {
+ viewOnlineSign = 2;
+ } else {
+ if (Global.getPropertyToBoolean("file.view.online", "true") && ("," + Global.getSystemConfig("can.transfer.format", "") + ",").contains("," + tail + ",") && StringUtils.isEmpty(templateType)) {
+ viewOnlineSign = 1;
+ }
+ }
- final String fileFinalName = FileUtils.uploadFile(tempFile, templateType, clientUuid);
+ final String fileFinalName = FileUtils.uploadFile(tempFile, templateType, clientUuid);
- // 璁板綍闄勪欢淇℃伅鍒版暟鎹簱
- logger.info("姝e湪璁板綍闄勪欢淇℃伅鍒版暟鎹簱...");
- FieldSetEntity dictFse = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_DICT,
- new String[]{CmnConst.UUID, CmnConst.DICT_VALUE}, "lower( " + CmnConst.DICT_VALUE + ")=lower(?) and dict_name='upload_file_format' and is_used=1", new Object[]{tail}, false, "");
- FieldSetEntity attachmentFse = new FieldSetEntity();
- attachmentFse.setTableName(CmnConst.PRODUCT_SYS_ATTACHMENTS);
- String fileType;
- if (dictFse != null && !StringUtils.isEmpty(dictFse.getString(CmnConst.UUID))) {
- attachmentFse.setValue(CmnConst.ATTACHMENT_TYPE_UUID, dictFse.getUUID());
- fileType = dictFse.getString(CmnConst.DICT_VALUE);
- } else {
- fileType = tail;
- attachmentFse.setValue(CmnConst.ATTACHMENT_TYPE_UUID, tail);
- }
- //鍏佽缂栬緫
- int allowEdit = ("," + Global.getSystemConfig("can.web.online.edit", "doc,docx,xls,xlsx.ppt,pptx,wps,cvs,wps,wpt,et,eet") + ",").indexOf("," + fileType + ",") != -1 ? 1 : 0;
- attachmentFse.setValue(CmnConst.OPT_FLAT, 2);
- attachmentFse.setValue(CmnConst.FILE_NAME, fileName);
- attachmentFse.setValue(CmnConst.ATTACHMENT_TITLE, fileFinalName);
- attachmentFse.setValue(CmnConst.CLIENT_UUID, clientUuid);
- attachmentFse.setValue(CmnConst.VIEW_ONLINE_SIGN, viewOnlineSign);
- attachmentFse.setValue(CmnConst.ATTACHMENT_DATA_TABLE, fse.getTableName());
- attachmentFse.setValue(CmnConst.ATTACHMENT_DATA_FIELD, fieldName);
- attachmentFse.setValue(CmnConst.ATTACHMENT_URL, dir.replaceAll("\\\\", "/"));
- attachmentFse.setValue(CmnConst.ENCRPT_SIGN, Global.getPropertyToBoolean("file.encrypt", "true") ? 1 : 0);
- attachmentFse.setValue(CmnConst.ATTACHMENT_SIZE, fileLength);
- attachmentFse.setValue(CmnConst.UPLOAD_SIGN, needUpload2FileServerFlag ? 1 : 0);
+ // 璁板綍闄勪欢淇℃伅鍒版暟鎹簱
+ logger.info("姝e湪璁板綍闄勪欢淇℃伅鍒版暟鎹簱...");
+ FieldSetEntity dictFse = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_DICT,
+ new String[]{CmnConst.UUID, CmnConst.DICT_VALUE}, "lower( " + CmnConst.DICT_VALUE + ")=lower(?) and dict_name='upload_file_format' and is_used=1", new Object[]{tail}, false, "");
+ FieldSetEntity attachmentFse = new FieldSetEntity();
+ attachmentFse.setTableName(CmnConst.PRODUCT_SYS_ATTACHMENTS);
+ String fileType;
+ if (dictFse != null && !StringUtils.isEmpty(dictFse.getString(CmnConst.UUID))) {
+ attachmentFse.setValue(CmnConst.ATTACHMENT_TYPE_UUID, dictFse.getUUID());
+ fileType = dictFse.getString(CmnConst.DICT_VALUE);
+ } else {
+ fileType = tail;
+ attachmentFse.setValue(CmnConst.ATTACHMENT_TYPE_UUID, tail);
+ }
+ //鍏佽缂栬緫
+ int allowEdit = ("," + Global.getSystemConfig("can.web.online.edit", "doc,docx,xls,xlsx.ppt,pptx,wps,cvs,wps,wpt,et,eet") + ",").indexOf("," + fileType + ",") != -1 ? 1 : 0;
+ attachmentFse.setValue(CmnConst.OPT_FLAT, 2);
+ attachmentFse.setValue(CmnConst.FILE_NAME, fileName);
+ attachmentFse.setValue(CmnConst.ATTACHMENT_TITLE, fileFinalName);
+ attachmentFse.setValue(CmnConst.CLIENT_UUID, clientUuid);
+ attachmentFse.setValue(CmnConst.VIEW_ONLINE_SIGN, viewOnlineSign);
+ attachmentFse.setValue(CmnConst.ATTACHMENT_DATA_TABLE, fse.getTableName());
+ attachmentFse.setValue(CmnConst.ATTACHMENT_DATA_FIELD, fieldName);
+ attachmentFse.setValue(CmnConst.ATTACHMENT_URL, dir.replaceAll("\\\\", "/"));
+ attachmentFse.setValue(CmnConst.ENCRPT_SIGN, Global.getPropertyToBoolean("file.encrypt", "true") ? 1 : 0);
+ attachmentFse.setValue(CmnConst.ATTACHMENT_SIZE, fileLength);
+ attachmentFse.setValue(CmnConst.UPLOAD_SIGN, needUpload2FileServerFlag ? 1 : 0);
+ attachmentFse.setValue(CmnConst.FUNCTION_UUID, fse.getString(CmnConst.FUNCTION_UUID));
+ attachmentFse.setValue(CmnConst.ATTACHMENT_CONTAINER, fse.getString(CmnConst.ATTACHMENT_CONTAINER));
+ attachmentFse.setValue(CmnConst.ATTACHMENT_DOMAIN, fse.getString(CmnConst.ATTACHMENT_DOMAIN));
+ attachmentFse.setValue(CmnConst.MODULE_UUID, fse.getString(CmnConst.MODULE_UUID));
+ //luoxin 鏈幏鍙栧綋鍓嶄汉id 灏辩洿鎺ヨ1
+ try {
+ attachmentFse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
+ } catch (Exception e) {
+ e.getStackTrace();
+ attachmentFse.setValue(CmnConst.CREATED_BY, 1);
+ }
- attachmentFse.setValue(CmnConst.ATTACHMENT_CONTAINER, fse.getString(CmnConst.ATTACHMENT_CONTAINER));
- attachmentFse.setValue(CmnConst.ATTACHMENT_DOMAIN, fse.getString(CmnConst.ATTACHMENT_DOMAIN));
- attachmentFse.setValue(CmnConst.MODULE_UUID, fse.getString(CmnConst.MODULE_UUID));
- //luoxin 鏈幏鍙栧綋鍓嶄汉id 灏辩洿鎺ヨ1
- try {
- attachmentFse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
- } catch (Exception e) {
- e.getStackTrace();
- attachmentFse.setValue(CmnConst.CREATED_BY, 1);
- }
+ attachmentFse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
+ baseDao.saveFieldSetEntity(attachmentFse);
+ logger.info("璁板綍鎴愬姛");
+ String uuid = attachmentFse.getUUID();
+ FieldSetEntity fseIndex = new FieldSetEntity();
+ fseIndex.setTableName("fseIndex");
+ fseIndex.setValue("function_uuid", fse.getString("function_uuid"));
+ fseIndex.setValue("attachment_uuid", uuid);
+ CreateDocumentIndexThread.getInstance().appendAttaInfo(fseIndex);
+ fse.setValue(uuid, fileName);
+ fse.setValue(entry.getKey().toString(), uuid);
+ fse.setValue(entry.getKey().toString() + "_edit", allowEdit);
+ fse.setValue(entry.getKey().toString() + "_type", fileType);
+ if (!StringUtils.isEmpty(uuids)) {
+ uuids += ",";
+ }
+ uuids += uuid;
+ }
+ logger.info("姝e湪鍥炲啓uuid...");
+ System.out.println(uuids);
+ fse.setValue(fieldName, uuids);
+ }
+ return fse;
+ }
- attachmentFse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
- baseDao.saveFieldSetEntity(attachmentFse);
- logger.info("璁板綍鎴愬姛");
- String uuid = attachmentFse.getUUID();
- FieldSetEntity fseIndex = new FieldSetEntity();
- fseIndex.setTableName("fseIndex");
- fseIndex.setValue("function_uuid", fse.getString("function_uuid"));
- fseIndex.setValue("attachment_uuid", uuid);
- CreateDocumentIndexThread.getInstance().appendAttaInfo(fseIndex);
- fse.setValue(uuid, fileName);
- fse.setValue(entry.getKey().toString(), uuid);
- fse.setValue(entry.getKey().toString() + "_edit", allowEdit);
- fse.setValue(entry.getKey().toString() + "_type", fileType);
- if (!StringUtils.isEmpty(uuids)) {
- uuids += ",";
- }
- uuids += uuid;
- }
- logger.info("姝e湪鍥炲啓uuid...");
- System.out.println(uuids);
- fse.setValue(fieldName, uuids);
- }
- return fse;
- }
+ /**
+ * 鏍规嵁闄勪欢琛ㄦ暟鎹敓鎴愭枃妗g储寮�
+ */
+ public void readAttachmentCreateIndex() {
+ // 閬嶅巻闄勪欢琛�
+ DataTableEntity dtAttachment = baseDao.listTable(CmnConst.PRODUCT_SYS_ATTACHMENTS);
+ if (BaseUtil.dataTableIsEmpty(dtAttachment)) {
+ return;
+ }
+ for (int i = 0; i < dtAttachment.getRows(); i++) {
+ // 鑾峰彇闄勪欢淇℃伅锛屽苟鍒ゆ柇鏄惁鏈夎〃鍜屽瓧娈�
+ FieldSetEntity fseAttachment = dtAttachment.getFieldSetEntity(i);
+ if (BaseUtil.strIsNull(fseAttachment.getString("attachment_data_field")) || BaseUtil.strIsNull(fseAttachment.getString("attachment_data_field"))) {
+ continue;
+ }
+ // 鏌ヨ鍘熸暟鎹紝鏈夊師鏁版嵁鍐嶇敓鎴愭枃妗f绱�
+ FieldSetEntity fseRecord = baseDao.getFieldSetEntityByFilter(fseAttachment.getString("attachment_data_table"), fseAttachment.getString("attachment_data_field") + " LIKE ?", new Object[]{"%" + fseAttachment.getUUID() + "%"}, false);
+ if (fseRecord != null) {
+ // 鐢熸垚鏂囨。妫�绱俊鎭�
+ FieldSetEntity fseIndex = new FieldSetEntity();
+ fseIndex.setTableName("fseIndex");
+ fseIndex.setValue("function_uuid", fseAttachment.getString("function_uuid"));
+ fseIndex.setValue("attachment_uuid", fseAttachment.getUUID());
+ CreateDocumentIndexThread.getInstance().appendAttaInfo(fseIndex);
+ }
+ }
+ }
- /**
- * 鎻愬彇鏂囦欢淇℃伅-涓嬭浇鏂囦欢鎴栬�呭湪绾块瑙堟枃浠�
- *
- * @param fse
- * @param response
- */
- public void getFileContent(FieldSetEntity fse, HttpServletResponse response) throws IOException {
- logger.info("姝e湪鑾峰彇鏂囦欢娴�...");
- String uuid = fse.getUUID();
- FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false);
- if (attachmentFse == null) {
- return;
- }
- boolean needDownloadFromServerFlag = "1".equals(attachmentFse.getString(CmnConst.UPLOAD_SIGN));
- String dir = attachmentFse.getString(CmnConst.ATTACHMENT_URL);
- String fileName = attachmentFse.getString(CmnConst.ATTACHMENT_TITLE);
- 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) {
- // 闇�瑕佸湪绾块瑙堜笖杞崲涔嬪悗鎵嶈兘鍦ㄧ嚎棰勮
- dir += File.separator + CmnConst.TRANSFER_DIR_NAME;
- }
+ /**
+ * 绉诲姩绔崌绾э紝瀹夎鍖呬笅杞�
+ *
+ * @param fse
+ * @param response
+ */
+ 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"))) {
+ return;
+ }
+ logger.info("姝e湪鑾峰彇鏂囦欢娴�...");
+ boolean needDownloadFromServerFlag = "1".equals(attachmentFse.getString(CmnConst.UPLOAD_SIGN));
+ String dir = attachmentFse.getString(CmnConst.ATTACHMENT_URL);
+ String fileName = attachmentFse.getString(CmnConst.ATTACHMENT_TITLE);
+ //鐪熷疄鏂囦欢鍚�
+ String realFileName = attachmentFse.getString(CmnConst.FILE_NAME);
+ 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);
- HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
- String userAgent = request.getHeader("User-Agent");
- String file_name = attachmentFse.getString("file_name");
- if (userAgent.contains("MSIE") || userAgent.contains("Trident")) {
- file_name = java.net.URLEncoder.encode(file_name, "UTF-8");
- } else {
- // 闈濱E娴忚鍣ㄧ殑澶勭悊锛�
- file_name = new String(file_name.getBytes("UTF-8"), "ISO-8859-1");
- }
- String path = dir + File.separator + fileName;
- if (needDownloadFromServerFlag) {
- // 闇�瑕佷粠闄勪欢鏈嶅姟鍣ㄤ笂鍙栨枃浠�
- FTPService ftpService = new FTPService();
- logger.info("闇�瑕佷粠闄勪欢鏈嶅姟鍣ㄤ笂鍙栨枃浠�...");
- response.setContentType("multipart/form-data");
- response.setHeader("Content-disposition",
- String.format("attachment; filename=\"%s\"", file_name));
- if (!needOnlineViewFlag && !encrptSignFlag) {
- logger.info("涓嶉渶瑕佽В瀵嗕笖鑾峰彇鍘熸枃浠�...");
- try (ServletOutputStream os = response.getOutputStream()) {
- ftpService.downloadFile(path, os);
- }
- } else {
- logger.info("闇�瑕佽В瀵嗘垨鑰呰幏鍙栬浆鎹㈠悗鐨勬枃浠�...");
- String localTempPath = Global.getSystemConfig("temp.dir", "") + File.separator + fileName;
- File localTempFile = new File(localTempPath);
- OutputStream tempOs = new FileOutputStream(localTempFile);
- ftpService.downloadFile(path, tempOs);
- tempOs.flush();
- tempOs.close();
- if (needOnlineViewFlag && localTempFile.length() == 0L) {
- // 鑻ユ槸棰勮锛屼絾鏄浆鎹㈠悗鐨勬枃浠朵笉瀛樺湪锛岄偅涔堥噸鏂版墽琛岃浆鎹㈡搷浣�
- File sourceFile = fileUtils.getFile(true, attachmentFse.getString(CmnConst.ATTACHMENT_URL), fileName, encrptSignFlag);
- File tempSourceFile = new File(sourceFile.getParentFile().getAbsolutePath() + File.separator + attachmentFse.getString(CmnConst.FILE_NAME));
- sourceFile.renameTo(tempSourceFile);
- FileUtils.convertPdf(false, true, encrptSignFlag, true, tempSourceFile, dir, fileName, attachmentFse.getString(CmnConst.FILE_NAME));
- tempSourceFile.delete();
+ String clientType = CoreConst.CLIENT_TYPE_APP;
- // 閲嶆柊鎷夋枃浠�
- tempOs = new FileOutputStream(localTempFile);
- ftpService = new FTPService();
- ftpService.downloadFile(path, tempOs);
- tempOs.flush();
- tempOs.close();
- }
- response.setContentLengthLong(localTempFile.length());
- InputStream is = new FileInputStream(localTempFile);
- int len;
- byte[] b = new byte[1024];
- try (ServletOutputStream os = response.getOutputStream()) {
- while ((len = is.read(b)) > 0) {
- os.write(encrptSignFlag ? FileUtil.decryption(b) : b, 0, len);
- }
- os.flush();
- is.close();
- }
- // 鍒犻櫎涓存椂鏂囦欢
- localTempFile.delete();
- }
- } else {
- // 鐩存帴鍦ㄦ湰鍦扮殑鐩綍涓壘鏂囦欢
- logger.info("鐩存帴鍦ㄦ湰鍦扮殑鐩綍涓壘鏂囦欢...");
- String localBasePath = Global.getSystemConfig("local.dir", "");
- path = localBasePath + File.separator + path;
- File file = new File(path);
- if (needOnlineViewFlag && !file.exists()) {
- // 鑻ユ槸棰勮锛屼絾鏄浆鎹㈠悗鐨勬枃浠朵笉瀛樺湪锛岄偅涔堥噸鏂版墽琛岃浆鎹㈡搷浣�
- File sourceFile = fileUtils.getFile(false, attachmentFse.getString(CmnConst.ATTACHMENT_URL), fileName, encrptSignFlag);
- File tempSourceFile = new File(sourceFile.getParentFile().getAbsolutePath() + File.separator + attachmentFse.getString(CmnConst.FILE_NAME));
- sourceFile.renameTo(tempSourceFile);
- FileUtils.convertPdf(false, false, encrptSignFlag, true, tempSourceFile, dir, fileName, attachmentFse.getString(CmnConst.FILE_NAME));
- tempSourceFile.delete();
- }
- int len;
- byte[] b = new byte[1024];
- response.setContentType("multipart/form-data");
- InputStream is = new FileInputStream(file);
- response.setHeader("Content-disposition", String.format("attachment; filename=\"%s\"", file_name));
- response.setContentLengthLong(file.length());
- try (ServletOutputStream os = response.getOutputStream()) {
- while ((len = is.read(b)) > 0) {
- if (encrptSignFlag) {
- // 闇�瑕佽В瀵�
- logger.info("闇�瑕佽В瀵�...");
- os.write(FileUtil.decryption(b), 0, len);
- } else {
- // 鏃犻渶瑙e瘑
- os.write(b, 0, len);
- }
- }
- os.flush();
- }
+ String contentType = "multipart/form-data";
+ boolean isExcel = realFileName.endsWith(".xlsx") || realFileName.endsWith(".xls");
+ if (needOnlineViewFlag) {
+ //鐗规畩澶勭悊锛� 濡傛灉瀹㈡埛绔笉鏄疉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;
+ }
+ }
- }
- logger.info("鏂囦欢娴佽幏鍙栨垚鍔�");
- }
+ String path = dir + File.separator + fileName;
+ if (needDownloadFromServerFlag) {
+ // 闇�瑕佷粠闄勪欢鏈嶅姟鍣ㄤ笂鍙栨枃浠�
+ FTPService ftpService = new FTPService();
+ logger.info("闇�瑕佷粠闄勪欢鏈嶅姟鍣ㄤ笂鍙栨枃浠�...");
+ response.setHeader("Access-Control-Expose-Headers", "*");
+
+ response.setContentType(contentType);
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(realFileName, "UTF-8"));
+ //璁剧疆澶翠腑鐨勬枃浠剁被鍨�
+ if (!needOnlineViewFlag && !encrptSignFlag) {
+ logger.info("涓嶉渶瑕佽В瀵嗕笖鑾峰彇鍘熸枃浠�...");
+ try (ServletOutputStream os = response.getOutputStream()) {
+ ftpService.downloadFile(path, os);
+ }
+ } else {
+ logger.info("闇�瑕佽В瀵嗘垨鑰呰幏鍙栬浆鎹㈠悗鐨勬枃浠�...");
+ String localTempPath = Global.getSystemConfig("temp.dir", "") + File.separator + fileName;
+ File localTempFile = new File(localTempPath);
+ OutputStream tempOs = new FileOutputStream(localTempFile);
+ ftpService.downloadFile(path, tempOs);
+ tempOs.flush();
+ tempOs.close();
+ if (needOnlineViewFlag && localTempFile.length() == 0L) {
+ // 鑻ユ槸棰勮锛屼絾鏄浆鎹㈠悗鐨勬枃浠朵笉瀛樺湪锛岄偅涔堥噸鏂版墽琛岃浆鎹㈡搷浣�
+ File sourceFile = fileUtils.getFile(true, attachmentFse.getString(CmnConst.ATTACHMENT_URL), fileName, encrptSignFlag);
+ File tempSourceFile = new File(sourceFile.getParentFile().getAbsolutePath() + File.separator + attachmentFse.getString(CmnConst.FILE_NAME));
+ sourceFile.renameTo(tempSourceFile);
+ FileUtils.convertPdf(false, true, encrptSignFlag, true, tempSourceFile, dir, fileName, attachmentFse.getString(CmnConst.FILE_NAME));
+ tempSourceFile.delete();
+
+ // 閲嶆柊鎷夋枃浠�
+ tempOs = new FileOutputStream(localTempFile);
+ ftpService = new FTPService();
+ ftpService.downloadFile(path, tempOs);
+ tempOs.flush();
+ tempOs.close();
+ }
+ response.setContentLengthLong(localTempFile.length());
+ InputStream is = new FileInputStream(localTempFile);
+ int len;
+ byte[] b = new byte[1024];
+ try (ServletOutputStream os = response.getOutputStream()) {
+ while ((len = is.read(b)) > 0) {
+ os.write(encrptSignFlag ? FileUtil.decryption(b) : b, 0, len);
+ }
+ os.flush();
+ is.close();
+ }
+ // 鍒犻櫎涓存椂鏂囦欢
+ localTempFile.delete();
+ }
+ } else {
+ // 鐩存帴鍦ㄦ湰鍦扮殑鐩綍涓壘鏂囦欢
+ logger.info("鐩存帴鍦ㄦ湰鍦扮殑鐩綍涓壘鏂囦欢...");
+ String localBasePath = Global.getSystemConfig("local.dir", "");
+ path = localBasePath + File.separator + path;
+ File file = new File(path);
+ 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 <= changeDate.getTime()) {
+ file.delete();
+ }
+ }
+ if (needOnlineViewFlag && !file.exists()) {
+ // 鑻ユ槸棰勮锛屼絾鏄浆鎹㈠悗鐨勬枃浠朵笉瀛樺湪锛岄偅涔堥噸鏂版墽琛岃浆鎹㈡搷浣�
+ File sourceFile = fileUtils.getFile(false, attachmentFse.getString(CmnConst.ATTACHMENT_URL), fileName, encrptSignFlag);
+ File tempSourceFile = new File(sourceFile.getParentFile().getAbsolutePath() + File.separator + attachmentFse.getString(CmnConst.FILE_NAME));
+ sourceFile.renameTo(tempSourceFile);
+ FileUtils.convertPdf(false, false, encrptSignFlag, true, tempSourceFile, dir, fileName, attachmentFse.getString(CmnConst.FILE_NAME));
+ tempSourceFile.delete();
+ }
+ int len;
+ byte[] b = new byte[1024];
+ InputStream is = new FileInputStream(file);
+ response.setHeader("Access-Control-Expose-Headers", "*");
+
+ response.setContentType(contentType);
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(realFileName, "UTF-8"));
+ response.setContentLengthLong(file.length());
+ try (ServletOutputStream os = response.getOutputStream()) {
+ while ((len = is.read(b)) > 0) {
+ if (encrptSignFlag) {
+ // 闇�瑕佽В瀵�
+ logger.info("闇�瑕佽В瀵�...");
+ os.write(FileUtil.decryption(b), 0, len);
+ } else {
+ // 鏃犻渶瑙e瘑
+ os.write(b, 0, len);
+ }
+ }
+ os.flush();
+ }
+ is.close();
+ }
+ logger.info("鏂囦欢娴佽幏鍙栨垚鍔�");
+ }
+
+ }
+
+ /**
+ * 鎻愬彇鏂囦欢淇℃伅-涓嬭浇鏂囦欢鎴栬�呭湪绾块瑙堟枃浠�
+ *
+ * @param fse
+ * @param response
+ */
+ public void getFileContent(FieldSetEntity fse, HttpServletResponse response) throws IOException {
+ logger.info("姝e湪鑾峰彇鏂囦欢娴�...");
+ String uuid = fse.getUUID();
+ FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false);
+ if (attachmentFse == null) {
+ return;
+ }
+ boolean needDownloadFromServerFlag = "1".equals(attachmentFse.getString(CmnConst.UPLOAD_SIGN));
+ String dir = attachmentFse.getString(CmnConst.ATTACHMENT_URL);
+ String fileName = attachmentFse.getString(CmnConst.ATTACHMENT_TITLE);
+ //鐪熷疄鏂囦欢鍚�
+ String realFileName = attachmentFse.getString(CmnConst.FILE_NAME);
+ 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 = SpringMVCContextHolder.getCurrentUser().getClientType();
+
+ String contentType = "multipart/form-data";
+ boolean isExcel = realFileName.endsWith(".xlsx") || realFileName.endsWith(".xls");
+ if (needOnlineViewFlag) {
+ //鐗规畩澶勭悊锛� 濡傛灉瀹㈡埛绔笉鏄疉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;
+ if (needDownloadFromServerFlag) {
+ // 闇�瑕佷粠闄勪欢鏈嶅姟鍣ㄤ笂鍙栨枃浠�
+ FTPService ftpService = new FTPService();
+ logger.info("闇�瑕佷粠闄勪欢鏈嶅姟鍣ㄤ笂鍙栨枃浠�...");
+ response.setHeader("Access-Control-Expose-Headers", "*");
+
+ response.setContentType(contentType);
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(realFileName, "UTF-8"));
+ //璁剧疆澶翠腑鐨勬枃浠剁被鍨�
+ if (!needOnlineViewFlag && !encrptSignFlag) {
+ logger.info("涓嶉渶瑕佽В瀵嗕笖鑾峰彇鍘熸枃浠�...");
+ try (ServletOutputStream os = response.getOutputStream()) {
+ ftpService.downloadFile(path, os);
+ }
+ } else {
+ logger.info("闇�瑕佽В瀵嗘垨鑰呰幏鍙栬浆鎹㈠悗鐨勬枃浠�...");
+ String localTempPath = Global.getSystemConfig("temp.dir", "") + File.separator + fileName;
+ File localTempFile = new File(localTempPath);
+ OutputStream tempOs = new FileOutputStream(localTempFile);
+ ftpService.downloadFile(path, tempOs);
+ tempOs.flush();
+ tempOs.close();
+ if (needOnlineViewFlag && localTempFile.length() == 0L) {
+ // 鑻ユ槸棰勮锛屼絾鏄浆鎹㈠悗鐨勬枃浠朵笉瀛樺湪锛岄偅涔堥噸鏂版墽琛岃浆鎹㈡搷浣�
+ File sourceFile = fileUtils.getFile(true, attachmentFse.getString(CmnConst.ATTACHMENT_URL), fileName, encrptSignFlag);
+ File tempSourceFile = new File(sourceFile.getParentFile().getAbsolutePath() + File.separator + attachmentFse.getString(CmnConst.FILE_NAME));
+ sourceFile.renameTo(tempSourceFile);
+ FileUtils.convertPdf(false, true, encrptSignFlag, true, tempSourceFile, dir, fileName, attachmentFse.getString(CmnConst.FILE_NAME));
+ tempSourceFile.delete();
+
+ // 閲嶆柊鎷夋枃浠�
+ tempOs = new FileOutputStream(localTempFile);
+ ftpService = new FTPService();
+ ftpService.downloadFile(path, tempOs);
+ 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;
+ byte[] b = new byte[1024];
+ try (ServletOutputStream os = response.getOutputStream()) {
+ while ((len = is.read(b)) > 0) {
+ os.write(encrptSignFlag ? FileUtil.decryption(b) : b, 0, len);
+ }
+ os.flush();
+ is.close();
+ }
+ // 鍒犻櫎涓存椂鏂囦欢
+ localTempFile.delete();
+ }
+ } else {
+ // 鐩存帴鍦ㄦ湰鍦扮殑鐩綍涓壘鏂囦欢
+ logger.info("鐩存帴鍦ㄦ湰鍦扮殑鐩綍涓壘鏂囦欢...");
+ String localBasePath = Global.getSystemConfig("local.dir", "");
+ path = localBasePath + File.separator + path;
+ File file = new File(path);
+ 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 <= changeDate.getTime()) {
+ file.delete();
+ }
+ }
+ if (needOnlineViewFlag && !file.exists()) {
+ // 鑻ユ槸棰勮锛屼絾鏄浆鎹㈠悗鐨勬枃浠朵笉瀛樺湪锛岄偅涔堥噸鏂版墽琛岃浆鎹㈡搷浣�
+ File sourceFile = fileUtils.getFile(false, attachmentFse.getString(CmnConst.ATTACHMENT_URL), fileName, encrptSignFlag);
+ File tempSourceFile = new File(sourceFile.getParentFile().getAbsolutePath() + File.separator + attachmentFse.getString(CmnConst.FILE_NAME));
+ sourceFile.renameTo(tempSourceFile);
+ 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);
+ response.setHeader("Access-Control-Expose-Headers", "*");
+
+ response.setContentType(contentType);
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(realFileName, "UTF-8"));
+ response.setContentLengthLong(file.length());
+ try (ServletOutputStream os = response.getOutputStream()) {
+ while ((len = is.read(b)) > 0) {
+ if (encrptSignFlag) {
+ // 闇�瑕佽В瀵�
+ logger.info("闇�瑕佽В瀵�...");
+ os.write(FileUtil.decryption(b), 0, len);
+ } else {
+ // 鏃犻渶瑙e瘑
+ os.write(b, 0, len);
+ }
+ }
+ os.flush();
+ }
+ is.close();
+ if (delete) {
+ file.delete();
+ }
+ }
+ logger.info("鏂囦欢娴佽幏鍙栨垚鍔�");
+ }
- /**
- * 鑾峰彇鏂囦欢瀛楄妭 鏍规嵁鏂囦欢uuid
- */
- public byte[] getFileContent(String uuid) throws BaseException {
- FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false);
- return this.getFileContent(attachmentFse);
- }
+ /**
+ * 鑾峰彇鏂囦欢瀛楄妭 鏍规嵁鏂囦欢uuid
+ */
+ public byte[] getFileContent(String uuid) throws BaseException {
+ FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false);
+ return this.getFileContent(attachmentFse);
+ }
- /**
- * 鏍规嵁闄勪欢uuid鑾峰彇鏂囦欢
- * 鐢ㄥ畬涔嬪悗闇�瑕佸垹闄よ繑鍥炵殑 file 锛堜复鏃舵枃浠讹級
- *
- * @param uuid
- * @return
- * @throws BaseException
- */
- public File getFile(String uuid) throws BaseException {
- FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false);
- byte[] fileContent = getFileContent(attachmentFse);
- if (fileContent != null && fileContent.length > 0) {
- String localTempPath = Global.getSystemConfig("temp.dir", "") + File.separator + new Date().getTime() + attachmentFse.getString(CmnConst.ATTACHMENT_TITLE) + attachmentFse.getString("file_name");
- File temp = new File(localTempPath);
- File td = new File(Global.getSystemConfig("temp.dir", ""));
- if (!td.exists()) td.mkdirs();
- try {
- temp.createNewFile();
- } catch (IOException e) {
- throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + (e.getMessage() != null ? e.getMessage() : ""));
- }
- try (FileOutputStream fos = new FileOutputStream(temp); BufferedOutputStream out = new BufferedOutputStream(fos)) {
+ /**
+ * 鏍规嵁闄勪欢uuid鑾峰彇鏂囦欢
+ * 鐢ㄥ畬涔嬪悗闇�瑕佸垹闄よ繑鍥炵殑 file 锛堜复鏃舵枃浠讹級
+ *
+ * @param uuid
+ * @return
+ * @throws BaseException
+ */
+ public File getFile(String uuid) throws BaseException {
+ FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false);
+ return getFile(attachmentFse);
+ }
- out.write(fileContent);
- return temp;
- } catch (Exception e) {
- e.printStackTrace();
- throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + (e.getMessage() != null ? e.getMessage() : ""));
- }
- }
- throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText());
- }
+ public File getFile(FieldSetEntity attachmentFse) throws BaseException {
+ byte[] fileContent = getFileContent(attachmentFse);
+ if (fileContent != null && fileContent.length > 0) {
+ String localTempPath = Global.getSystemConfig("temp.dir", "") + File.separator + new Date().getTime() + attachmentFse.getString(CmnConst.ATTACHMENT_TITLE) + attachmentFse.getString("file_name");
+ File temp = new File(localTempPath);
+ File td = new File(Global.getSystemConfig("temp.dir", ""));
+ if (!td.exists()) td.mkdirs();
+ try {
+ temp.createNewFile();
+ } catch (IOException e) {
+ throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + (e.getMessage() != null ? e.getMessage() + ",uuid:" + attachmentFse.getUUID() : ""));
+ }
+ try (FileOutputStream fos = new FileOutputStream(temp); BufferedOutputStream out = new BufferedOutputStream(fos)) {
- /**
- * 鑾峰彇鏂囦欢瀛楄妭 鏍规嵁闄勪欢field
- */
- public byte[] getFileContent(FieldSetEntity attachmentFse) throws BaseException {
- if (attachmentFse == null || !CmnConst.PRODUCT_SYS_ATTACHMENTS.equals(attachmentFse.getTableName())) {
- return new byte[16];
- }
- try (ByteArrayOutputStream os = new ByteArrayOutputStream();) {
- FTPService ftpService = new FTPService();
- boolean needDownloadFromServerFlag = "1".equals(attachmentFse.getString(CmnConst.UPLOAD_SIGN));
- String dir = attachmentFse.getString(CmnConst.ATTACHMENT_URL);
- String fileName = attachmentFse.getString(CmnConst.ATTACHMENT_TITLE);
- boolean encrptSignFlag = "1".equals(attachmentFse.getString(CmnConst.ENCRPT_SIGN));
- String path = dir + File.separator + fileName;
- if (needDownloadFromServerFlag) {
- // 闇�瑕佷粠闄勪欢鏈嶅姟鍣ㄤ笂鍙栨枃浠�
- if (encrptSignFlag) {
- // 闇�瑕佽В瀵�
- String localTempPath = Global.getSystemConfig("temp.dir", "") + File.separator + fileName;
- File localTempFile = new File(localTempPath);
- OutputStream tempOs = new FileOutputStream(localTempFile);
- ftpService.downloadFile(path, tempOs);
- tempOs.flush();
- tempOs.close();
- InputStream is = new FileInputStream(localTempFile);
- int len;
- byte[] b = new byte[1024];
- while ((len = is.read(b)) > 0) {
- os.write(FileUtil.decryption(b), 0, len);
- }
- os.flush();
- is.close();
- // 鍒犻櫎涓存椂鏂囦欢
- localTempFile.delete();
- } else {
- 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)) {
- while ((len = is.read(b)) > 0) {
- if (Global.getPropertyToBoolean("file.encrypt", "true")) {
- // 闇�瑕佽В瀵�
- os.write(FileUtil.decryption(b), 0, len);
- } else {
- // 鏃犻渶瑙e瘑
- os.write(b, 0, len);
- }
- }
- }
- }
+ out.write(fileContent);
+ return temp;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + (e.getMessage() != null ? e.getMessage() + ",uuid:" + attachmentFse.getUUID() : ""));
+ }
+ }
+ throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + ",uuid:" + attachmentFse.getUUID());
+ }
- return os.toByteArray();
- } catch (Exception e) {
- SpringMVCContextHolder.getSystemLogger().error(FileCode.GET_FILE_BYTES_FAIL.getValue(), FileCode.GET_FILE_BYTES_FAIL.getText() + "," + e.getMessage());
- throw new BaseException(FileCode.GET_FILE_BYTES_FAIL.getValue(), FileCode.GET_FILE_BYTES_FAIL.getText() + "," + e.getMessage());
- }
- }
+ /**
+ * 鑾峰彇鏂囦欢瀛楄妭 鏍规嵁闄勪欢field
+ */
+ public byte[] getFileContent(FieldSetEntity attachmentFse) throws BaseException {
+ if (attachmentFse == null || !CmnConst.PRODUCT_SYS_ATTACHMENTS.equals(attachmentFse.getTableName())) {
+ //杩斿洖涓�涓┖鐨勫瓧鑺傛暟缁�
+ return new byte[0];
+ }
+ try (ByteArrayOutputStream os = new ByteArrayOutputStream();) {
+ FTPService ftpService = new FTPService();
+ boolean needDownloadFromServerFlag = "1".equals(attachmentFse.getString(CmnConst.UPLOAD_SIGN));
+ String dir = attachmentFse.getString(CmnConst.ATTACHMENT_URL);
+ String fileName = attachmentFse.getString(CmnConst.ATTACHMENT_TITLE);
+ boolean encrptSignFlag = "1".equals(attachmentFse.getString(CmnConst.ENCRPT_SIGN));
+ String path = dir + File.separator + fileName;
+ if (needDownloadFromServerFlag) {
+ // 闇�瑕佷粠闄勪欢鏈嶅姟鍣ㄤ笂鍙栨枃浠�
+ if (encrptSignFlag) {
+ // 闇�瑕佽В瀵�
+ String localTempPath = Global.getSystemConfig("temp.dir", "") + File.separator + fileName;
+ File localTempFile = new File(localTempPath);
+ OutputStream tempOs = new FileOutputStream(localTempFile);
+ ftpService.downloadFile(path, tempOs);
+ tempOs.flush();
+ tempOs.close();
+ InputStream is = new FileInputStream(localTempFile);
+ int len;
+ byte[] b = new byte[1024];
+ while ((len = is.read(b)) > 0) {
+ os.write(FileUtil.decryption(b), 0, len);
+ }
+ os.flush();
+ is.close();
+ // 鍒犻櫎涓存椂鏂囦欢
+ localTempFile.delete();
+ } else {
+ 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)) {
+ while ((len = is.read(b)) > 0) {
+ if (Global.getPropertyToBoolean("file.encrypt", "true")) {
+ // 闇�瑕佽В瀵�
+ os.write(FileUtil.decryption(b), 0, len);
+ } else {
+ // 鏃犻渶瑙e瘑
+ os.write(b, 0, len);
+ }
+ }
+ }
+ }
- /**
- * 鑾峰彇鏂囦欢瀛楄妭,鍐嶈浆鎹㈡垚瀛楃涓� 鏍规嵁鏂囦欢uuid
- */
- public String getFileContentString(String uuid) {
- byte[] b = getFileContent(uuid);
- if (b == null) {
- return null;
- }
- String str = new String(b);
- return str;
- }
+ return os.toByteArray();
+ } catch (Exception e) {
+ SpringMVCContextHolder.getSystemLogger().error(FileCode.GET_FILE_BYTES_FAIL.getValue(), FileCode.GET_FILE_BYTES_FAIL.getText() + "," + e.getMessage());
+ throw new BaseException(FileCode.GET_FILE_BYTES_FAIL.getValue(), FileCode.GET_FILE_BYTES_FAIL.getText() + "," + e.getMessage());
+ }
+ }
- /**
- * 鎻愬彇鏂囦欢淇℃伅-鎵归噺鎵撳寘涓嬭浇鏂囦欢
- *
- * @param fse
- * @param
- */
- public void downLoadFileZip(FieldSetEntity fse, HttpServletResponse response) throws IOException, BaseException {
- logger.info("姝e湪鎵撳寘涓嬭浇鏂囦欢...");
- response.setContentType("multipart/form-data");
- try (ServletOutputStream os = response.getOutputStream()) {
- String uuids = fse.getString("uuids");
- if (StringUtils.isEmpty(uuids)) {
- throw new BaseException(FileCode.GET_DATA_FAIL.getValue(), FileCode.GET_DATA_FAIL.getText() + ":uuids");
- }
- DataTableEntity attachmentDte = baseDao.listTable(CmnConst.PRODUCT_SYS_ATTACHMENTS,
- new Object[]{CmnConst.ATTACHMENT_URL, CmnConst.FILE_NAME, CmnConst.VIEW_ONLINE_SIGN, CmnConst.FILE_NAME, CmnConst.ENCRPT_SIGN, CmnConst.ATTACHMENT_TITLE, CmnConst.UPLOAD_SIGN},
- uuids.split(","));
- FieldSetEntity attachmentFse;
- String fileName;
- String dir;
- String sourcePath;
- String localTempPath;
- FTPService ftpService;
- boolean needDownloadFromServerFlag;
- List<Map<String, String>> pathList = Lists.newArrayList();
- Map<String, String> pathMap;
- for (int i = 0; i < attachmentDte.getRows(); i++) {
- pathMap = Maps.newHashMap();
- attachmentFse = attachmentDte.getFieldSetEntity(i);
- needDownloadFromServerFlag = "1".equals(attachmentFse.getString(CmnConst.UPLOAD_SIGN));
- fileName = attachmentFse.getString(CmnConst.ATTACHMENT_TITLE);
- dir = attachmentFse.getString(CmnConst.ATTACHMENT_URL);
- sourcePath = dir + File.separator + fileName;
- localTempPath = Global.getSystemConfig("temp.dir", "") + File.separator + fileName;
- pathMap.put(CmnConst.REAL_FILE_NAME, attachmentFse.getString(CmnConst.FILE_NAME));
- pathMap.put(CmnConst.ENCRPT_SIGN, attachmentFse.getString(CmnConst.ENCRPT_SIGN));
- if (needDownloadFromServerFlag) {
- ftpService = new FTPService();
- ftpService.downloadFile(sourcePath, localTempPath);
- pathMap.put(CmnConst.NEED_LOCAL_TEMP_FILE_SIGN, "1");
- pathMap.put(CmnConst.SOURCE_PATH, localTempPath);
- } else {
- pathMap.put(CmnConst.NEED_LOCAL_TEMP_FILE_SIGN, "0");
- pathMap.put(CmnConst.SOURCE_PATH, Global.getSystemConfig("local.dir", "") + File.separator + sourcePath);
- }
- pathList.add(pathMap);
- }
+ /**
+ * 鑾峰彇鏂囦欢瀛楄妭,鍐嶈浆鎹㈡垚瀛楃涓� 鏍规嵁鏂囦欢uuid
+ */
+ public String getFileContentString(String uuid) {
+ byte[] b = getFileContent(uuid);
+ if (b == null) {
+ return null;
+ }
+ String str = new String(b);
+ return str;
+ }
- long fileSize = FileUtil.createZip(pathList, os);
- response.setContentLengthLong(fileSize);
+ /**
+ * 鎻愬彇鏂囦欢淇℃伅-鎵归噺鎵撳寘涓嬭浇鏂囦欢
+ *
+ * @param fse
+ * @param
+ */
+ public void downLoadFileZip(FieldSetEntity fse, HttpServletResponse response) throws IOException, BaseException {
+ logger.info("姝e湪鎵撳寘涓嬭浇鏂囦欢...");
+ response.setContentType("multipart/form-data");
+ try (ServletOutputStream os = response.getOutputStream()) {
+ String uuids = fse.getString("uuids");
+ if (StringUtils.isEmpty(uuids)) {
+ throw new BaseException(FileCode.GET_DATA_FAIL.getValue(), FileCode.GET_DATA_FAIL.getText() + ":uuids");
+ }
+ DataTableEntity attachmentDte = baseDao.listTable(CmnConst.PRODUCT_SYS_ATTACHMENTS,
+ new Object[]{CmnConst.ATTACHMENT_URL, CmnConst.FILE_NAME, CmnConst.VIEW_ONLINE_SIGN, CmnConst.FILE_NAME, CmnConst.ENCRPT_SIGN, CmnConst.ATTACHMENT_TITLE, CmnConst.UPLOAD_SIGN},
+ uuids.split(","));
+ FieldSetEntity attachmentFse;
+ String fileName;
+ String dir;
+ String sourcePath;
+ String localTempPath;
+ FTPService ftpService;
+ boolean needDownloadFromServerFlag;
+ List<Map<String, String>> pathList = Lists.newArrayList();
+ Map<String, String> pathMap;
+ for (int i = 0; i < attachmentDte.getRows(); i++) {
+ pathMap = Maps.newHashMap();
+ attachmentFse = attachmentDte.getFieldSetEntity(i);
+ needDownloadFromServerFlag = "1".equals(attachmentFse.getString(CmnConst.UPLOAD_SIGN));
+ fileName = attachmentFse.getString(CmnConst.ATTACHMENT_TITLE);
+ dir = attachmentFse.getString(CmnConst.ATTACHMENT_URL);
+ sourcePath = dir + File.separator + fileName;
+ localTempPath = Global.getSystemConfig("temp.dir", "") + File.separator + fileName;
+ pathMap.put(CmnConst.REAL_FILE_NAME, attachmentFse.getString(CmnConst.FILE_NAME));
+ pathMap.put(CmnConst.ENCRPT_SIGN, attachmentFse.getString(CmnConst.ENCRPT_SIGN));
+ if (needDownloadFromServerFlag) {
+ ftpService = new FTPService();
+ ftpService.downloadFile(sourcePath, localTempPath);
+ pathMap.put(CmnConst.NEED_LOCAL_TEMP_FILE_SIGN, "1");
+ pathMap.put(CmnConst.SOURCE_PATH, localTempPath);
+ } else {
+ pathMap.put(CmnConst.NEED_LOCAL_TEMP_FILE_SIGN, "0");
+ pathMap.put(CmnConst.SOURCE_PATH, Global.getSystemConfig("local.dir", "") + File.separator + sourcePath);
+ }
+ pathList.add(pathMap);
+ }
- File file;
- for (Map<String, String> map : pathList) {
- for (String key : map.keySet()) {
- if ("1".equals(map.get(CmnConst.NEED_LOCAL_TEMP_FILE_SIGN)) && !CmnConst.SOURCE_PATH.equals(key)) {
- continue;
- }
- file = new File(key);
- file.delete();
- }
- }
- logger.info("鏂囦欢娴佽幏鍙栨垚鍔�");
- } catch (IOException e) {
- throw e;
- }
- }
+ long fileSize = FileUtil.createZip(pathList, os);
+ response.setContentLengthLong(fileSize);
- /**
- * 鍒犻櫎鏈湴鎴栫嚎涓婃湇鍔″櫒鏂囦欢
- *
- * @param fse
- * @return
- */
- public boolean delFiles(FieldSetEntity fse) {
- FTPService ftpService = new FTPService();
- boolean needUpload2FileServerFlag = FTPService.needUpload2FileServer();
- String uuid = fse.getString(CmnConst.UUID);
- boolean needOnlineViewFlag = "1".equals(fse.getString(CmnConst.UPLOAD_SIGN));
- FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false);
- String path = attachmentFse.getString(CmnConst.ATTACHMENT_URL);
- if (needUpload2FileServerFlag) {
- //鍒犻櫎绾夸笂鏈嶅姟鍣ㄦ枃浠�
- ftpService.deleteFile(path, attachmentFse.getString(CmnConst.FILE_NAME));
- //if(needOnlineViewFlag){//闇�瑕佸垹闄よ浆鎹㈠悗鐨勬枃浠�
- path += File.separator + CmnConst.TRANSFER_DIR_NAME;
- ftpService.deleteFile(path, attachmentFse.getString(CmnConst.FILE_NAME));
- //}
- } else {
- //鍒犻櫎鏈湴鏈嶅姟鍣ㄦ枃浠�
- deleteFiles(Global.getSystemConfig("temp.dir", "") + "/" + attachmentFse.getString(CmnConst.FILE_NAME));// 璺緞鍙婃枃浠跺悕锛堟垨鏂囦欢澶癸級
- deleteFiles(Global.getSystemConfig("temp.dir", "") + "/" + CmnConst.TRANSFER_DIR_NAME + "/" + attachmentFse.getString(CmnConst.FILE_NAME));// 鍦ㄧ嚎棰勮璺緞鍙婃枃浠跺悕锛堟垨鏂囦欢澶癸級
- deleteFiles(Global.getSystemConfig("local.dir", "") + "/" + attachmentFse.getString(CmnConst.FILE_NAME));// 璺緞鍙婃枃浠跺悕锛堟垨鏂囦欢澶癸級
- deleteFiles(Global.getSystemConfig("local.dir", "") + "/" + CmnConst.TRANSFER_DIR_NAME + "/" + attachmentFse.getString(CmnConst.FILE_NAME));// 鍦ㄧ嚎棰勮璺緞鍙婃枃浠跺悕锛堟垨鏂囦欢澶癸級
- }
- //鍒犻櫎鏁版嵁搴撹褰�
- return baseDao.delete(CmnConst.PRODUCT_SYS_ATTACHMENTS, new Object[]{uuid});
- }
+ File file;
+ for (Map<String, String> map : pathList) {
+ for (String key : map.keySet()) {
+ if ("1".equals(map.get(CmnConst.NEED_LOCAL_TEMP_FILE_SIGN)) && !CmnConst.SOURCE_PATH.equals(key)) {
+ continue;
+ }
+ file = new File(key);
+ file.delete();
+ }
+ }
+ logger.info("鏂囦欢娴佽幏鍙栨垚鍔�");
+ } catch (IOException e) {
+ throw e;
+ }
+ }
- /**
- * 鍒犻櫎鍗曚釜鏂囦欢
- *
- * @param pathName 鍒犻櫎鏂囦欢璺緞鍚�
- * @return
- */
- public boolean deleteFiles(String pathName) {
- boolean flag = false;
- //鏍规嵁璺緞鍒涘缓鏂囦欢瀵硅薄
- File file = new File(pathName);
- //璺緞鏄釜鏂囦欢涓斾笉涓虹┖鏃跺垹闄ゆ枃浠�
- if (file.isFile() && file.exists()) {
- flag = file.delete();
- }
- //鍒犻櫎澶辫触鏃讹紝杩斿洖false
- return flag;
- }
+ /**
+ * 鍒犻櫎鏈湴鎴栫嚎涓婃湇鍔″櫒鏂囦欢
+ *
+ * @param fse
+ * @return
+ */
+ public boolean delFiles(FieldSetEntity fse) {
+ FTPService ftpService = new FTPService();
+ boolean needUpload2FileServerFlag = FTPService.needUpload2FileServer();
+ String uuid = fse.getString(CmnConst.UUID);
+ boolean needOnlineViewFlag = "1".equals(fse.getString(CmnConst.UPLOAD_SIGN));
+ FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false);
+ String path = attachmentFse.getString(CmnConst.ATTACHMENT_URL);
+ if (needUpload2FileServerFlag) {
+ //鍒犻櫎绾夸笂鏈嶅姟鍣ㄦ枃浠�
+ ftpService.deleteFile(path, attachmentFse.getString(CmnConst.FILE_NAME));
+ //if(needOnlineViewFlag){//闇�瑕佸垹闄よ浆鎹㈠悗鐨勬枃浠�
+ path += File.separator + CmnConst.TRANSFER_DIR_NAME;
+ ftpService.deleteFile(path, attachmentFse.getString(CmnConst.FILE_NAME));
+ //}
+ } else {
+ //鍒犻櫎鏈湴鏈嶅姟鍣ㄦ枃浠�
+ deleteFiles(Global.getSystemConfig("temp.dir", "") + "/" + attachmentFse.getString(CmnConst.FILE_NAME));// 璺緞鍙婃枃浠跺悕锛堟垨鏂囦欢澶癸級
+ deleteFiles(Global.getSystemConfig("temp.dir", "") + "/" + CmnConst.TRANSFER_DIR_NAME + "/" + attachmentFse.getString(CmnConst.FILE_NAME));// 鍦ㄧ嚎棰勮璺緞鍙婃枃浠跺悕锛堟垨鏂囦欢澶癸級
+ deleteFiles(Global.getSystemConfig("local.dir", "") + "/" + attachmentFse.getString(CmnConst.FILE_NAME));// 璺緞鍙婃枃浠跺悕锛堟垨鏂囦欢澶癸級
+ deleteFiles(Global.getSystemConfig("local.dir", "") + "/" + CmnConst.TRANSFER_DIR_NAME + "/" + attachmentFse.getString(CmnConst.FILE_NAME));// 鍦ㄧ嚎棰勮璺緞鍙婃枃浠跺悕锛堟垨鏂囦欢澶癸級
+ }
+ //鍒犻櫎鏁版嵁搴撹褰�
+ return baseDao.delete(CmnConst.PRODUCT_SYS_ATTACHMENTS, new Object[]{uuid});
+ }
- /**
- * 鍒犻櫎鐩綍鏈韩浠ュ強鐩綍涓嬬殑鎵�鏈夋枃浠跺強鏂囦欢澶�
- *
- * @param pathName 鐩綍鍚�
- * @return
- */
- public boolean deleteDiretory(String pathName) {
- boolean flag = false;
- //鏍规嵁璺緞鍒涘缓鏂囦欢瀵硅薄
- File directory = new File(pathName);
- //濡傛灉璺緞鏄竴涓洰褰曚笖涓嶄负绌烘椂锛屽垹闄ょ洰褰�
- if (directory.isDirectory() && directory.exists()) {
- //鑾峰彇鐩綍涓嬬殑鎵�鏈夌殑鐩綍鍜屾枃浠讹紝鏀惧叆鏁扮粍files涓�
- File[] files = directory.listFiles();
- //閬嶅巻鐩綍涓嬬殑鎵�鏈夌殑鏂囦欢鍜岀洰褰�
- for (int i = 0; i < files.length; i++) {
- //濡傛灉鐩綍涓嬫槸鏂囦欢鏃讹紝璋冪敤deleteFiles锛堬級鏂规硶锛屽垹闄ゅ崟涓枃浠�
- if (files[i].isFile()) {
- flag = deleteFiles(files[i].getAbsolutePath());
- }//濡傛灉鐩綍涓嬫槸鐩綍鏃讹紝璋冪敤鑷韩deleteDirectory()锛屽舰鎴愰�掑綊璋冪敤
- else {
- flag = deleteDiretory(files[i].getAbsolutePath());
- }
- }
- //鍒犻櫎鐩綍鏈韩锛屽鏋滄兂瑕佷繚鐣欑洰褰曞彧鍒犻櫎鏂囦欢锛屾鍙ュ彲浠ヤ笉瑕�
- flag = directory.delete();
- }
- //鍒犻櫎鎴愬姛鏃惰繑鍥瀟rue锛屽け璐ユ椂杩斿洖false
- return flag;
- }
+ /**
+ * 鍒犻櫎鍗曚釜鏂囦欢
+ *
+ * @param pathName 鍒犻櫎鏂囦欢璺緞鍚�
+ * @return
+ */
+ public boolean deleteFiles(String pathName) {
+ boolean flag = false;
+ //鏍规嵁璺緞鍒涘缓鏂囦欢瀵硅薄
+ File file = new File(pathName);
+ //璺緞鏄釜鏂囦欢涓斾笉涓虹┖鏃跺垹闄ゆ枃浠�
+ if (file.isFile() && file.exists()) {
+ flag = file.delete();
+ }
+ //鍒犻櫎澶辫触鏃讹紝杩斿洖false
+ return flag;
+ }
- /**
- * 鍒犻櫎鏂囦欢鎴栬�呯洰褰�
- *
- * @param pathName 璺緞鍚�
- * @return
- */
- public boolean deleteDirectoryOrFile(String pathName) {
- boolean flag = false;
- File file = new File(pathName);
- //濡傛灉璺緞鏄竴涓枃浠跺垯璋冪敤deleteFiles()
- if (file.isFile() && file.exists()) {
- flag = deleteFiles(pathName);
- }//濡傛灉璺緞鏄洰褰曞垯璋冪敤deleteDirectory()
- else if (file.isDirectory() && file.exists()) {
- flag = deleteDiretory(pathName);
- }
+ /**
+ * 鍒犻櫎鐩綍鏈韩浠ュ強鐩綍涓嬬殑鎵�鏈夋枃浠跺強鏂囦欢澶�
+ *
+ * @param pathName 鐩綍鍚�
+ * @return
+ */
+ public boolean deleteDiretory(String pathName) {
+ boolean flag = false;
+ //鏍规嵁璺緞鍒涘缓鏂囦欢瀵硅薄
+ File directory = new File(pathName);
+ //濡傛灉璺緞鏄竴涓洰褰曚笖涓嶄负绌烘椂锛屽垹闄ょ洰褰�
+ if (directory.isDirectory() && directory.exists()) {
+ //鑾峰彇鐩綍涓嬬殑鎵�鏈夌殑鐩綍鍜屾枃浠讹紝鏀惧叆鏁扮粍files涓�
+ File[] files = directory.listFiles();
+ //閬嶅巻鐩綍涓嬬殑鎵�鏈夌殑鏂囦欢鍜岀洰褰�
+ for (int i = 0; i < files.length; i++) {
+ //濡傛灉鐩綍涓嬫槸鏂囦欢鏃讹紝璋冪敤deleteFiles锛堬級鏂规硶锛屽垹闄ゅ崟涓枃浠�
+ if (files[i].isFile()) {
+ flag = deleteFiles(files[i].getAbsolutePath());
+ }//濡傛灉鐩綍涓嬫槸鐩綍鏃讹紝璋冪敤鑷韩deleteDirectory()锛屽舰鎴愰�掑綊璋冪敤
+ else {
+ flag = deleteDiretory(files[i].getAbsolutePath());
+ }
+ }
+ //鍒犻櫎鐩綍鏈韩锛屽鏋滄兂瑕佷繚鐣欑洰褰曞彧鍒犻櫎鏂囦欢锛屾鍙ュ彲浠ヤ笉瑕�
+ flag = directory.delete();
+ }
+ //鍒犻櫎鎴愬姛鏃惰繑鍥瀟rue锛屽け璐ユ椂杩斿洖false
+ return flag;
+ }
- return flag;
- }
+ /**
+ * 鍒犻櫎鏂囦欢鎴栬�呯洰褰�
+ *
+ * @param pathName 璺緞鍚�
+ * @return
+ */
+ public boolean deleteDirectoryOrFile(String pathName) {
+ boolean flag = false;
+ File file = new File(pathName);
+ //濡傛灉璺緞鏄竴涓枃浠跺垯璋冪敤deleteFiles()
+ if (file.isFile() && file.exists()) {
+ flag = deleteFiles(pathName);
+ }//濡傛灉璺緞鏄洰褰曞垯璋冪敤deleteDirectory()
+ else if (file.isDirectory() && file.exists()) {
+ flag = deleteDiretory(pathName);
+ }
+
+ return flag;
+ }
}
--
Gitblit v1.9.2