diff --git a/src/main/java/com/sipai/service/base/CommonFileServiceImpl.java b/src/main/java/com/sipai/service/base/CommonFileServiceImpl.java index ea93f202..8918e7b6 100644 --- a/src/main/java/com/sipai/service/base/CommonFileServiceImpl.java +++ b/src/main/java/com/sipai/service/base/CommonFileServiceImpl.java @@ -20,9 +20,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -377,12 +380,12 @@ public class CommonFileServiceImpl implements CommonFileService { try { // 安全获取文件名(自动检测编码) fileName = getSafeFileName(item); - + // 生成MinIO安全的对象名称 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); String timestamp = dateFormat.format(new Date()); filePath = generateMinioObjectName(fileName, timestamp); - + InputStream in = item.getInputStream(); String contentType = item.getContentType(); minioTemplate.makeBucket(nameSpace); @@ -391,7 +394,7 @@ public class CommonFileServiceImpl implements CommonFileService { CommonFile commonFile = new CommonFile(); commonFile.setId(CommUtil.getUUID()); commonFile.setMasterid(masterId); - // 20210105 YYJ 用于文件表绑定资料节点用字段 tb_doc_file内和masterId一样 + // 20210105 YYJ 用于文件表绑定��料节点用字段 tb_doc_file内和masterId一样 // commonFile.setPid(masterId); commonFile.setFilename(fileName); // 保存原始文件名用于显示 commonFile.setType(contentType); @@ -400,6 +403,19 @@ public class CommonFileServiceImpl implements CommonFileService { commonFile.setAbspath(filePath); // 保存MinIO对象名称 commonFile.setInsdt(CommUtil.nowDate()); commonFile.setSize((int) item.getSize()); + // 获取当前用户ID并设置 + try { + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if (attributes != null) { + HttpServletRequest request = attributes.getRequest(); + User cu = (User) request.getSession().getAttribute("cu"); + if (cu != null) { + commonFile.setInsuser(cu.getId()); + } + } + } catch (Exception e) { + logger.warn("无法获取当前用户信息: {}", e.getMessage()); + } res = this.insertByTable(tableName, commonFile); } catch (Exception e) { logger.error("Failed to update file to MinIO for masterId: {}", masterId, e); diff --git a/src/main/webapp/JS/commonFile.js b/src/main/webapp/JS/commonFile.js index 9cfb6cb7..96fee3c9 100644 --- a/src/main/webapp/JS/commonFile.js +++ b/src/main/webapp/JS/commonFile.js @@ -116,8 +116,11 @@ var getFileListMinioPic = function (divId, status, entityId, previews, previewCo tbName: tbName, bucketName: bucketName }, function (data) { + // 清空数组而不是重新赋值,这样可以保持引用不变 + previews.length = 0; + previewConfigs.length = 0; + if (data.length > 0) { - previews = new Array(); $('#maintenancefile').show(); for (var i = 0; i < data.length; i++) { var previewConfig = new Object(); @@ -133,10 +136,9 @@ var getFileListMinioPic = function (divId, status, entityId, previews, previewCo } previewConfigs.push(previewConfig); } - showFileInput_new(divId, previews, previewConfigs); - } else { - $('#' + divId).hide(); } + // 无论是否有数据都重新初始化控件 + showFileInput_new(divId, previews, previewConfigs); }, 'json'); }; diff --git a/src/main/webapp/jsp/base/fileinputMinioPic.jsp b/src/main/webapp/jsp/base/fileinputMinioPic.jsp index c762b5f7..92f58551 100644 --- a/src/main/webapp/jsp/base/fileinputMinioPic.jsp +++ b/src/main/webapp/jsp/base/fileinputMinioPic.jsp @@ -1,9 +1,10 @@ <%@ page language="java" pageEncoding="UTF-8" %>