fix(file): 优化文件上传及预览逻辑,完善当前用户信息设置
This commit is contained in:
@ -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;
|
||||
@ -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 用于文件表绑定<EFBFBD><EFBFBD>料节点用字段 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);
|
||||
|
||||
@ -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');
|
||||
};
|
||||
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
<%@ page language="java" pageEncoding="UTF-8" %>
|
||||
<script type="text/javascript">
|
||||
|
||||
var previews = new Array();
|
||||
var previewConfigs = new Array();
|
||||
var filelist = new Array();
|
||||
// 不重新定义这些变量,直接使用主页面的全局变量
|
||||
// var previews = new Array();
|
||||
// var previewConfigs = new Array();
|
||||
// var filelist = new Array();
|
||||
|
||||
//初始化fileinput控件(第一次初始化)
|
||||
function initFileInput(ctrlName, uploadUrl) {
|
||||
@ -55,9 +56,10 @@
|
||||
//导入文件上传完成之后的事件
|
||||
control.on("fileuploaded", function (event, data, previewId, index) {
|
||||
if (data.response.suc) {
|
||||
<%--getFileListMinioPic('${param.divId}','edit');--%>
|
||||
// getFileListMinioPic('abnormityFileId', 'edit', '', previews, previewConfigs);
|
||||
// 直接使用主页面的全局变量重新加载文件列表
|
||||
getFileListMinioPic('${param.divId}', 'edit', '', previews, previewConfigs);
|
||||
// 关闭上传弹窗,返回主页面
|
||||
closeModal('fileInputModal');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -354,7 +354,7 @@
|
||||
</div>--%>
|
||||
|
||||
<div class="form-group" style="margin:8px">
|
||||
<button type="button" class="btn btn-default btn-file" onclick="fileinputPic('maintenanceDetailFile')"
|
||||
<button type="button" class="btn btn-default btn-file" onclick="fileinputPic('abnormityFileId')"
|
||||
id="btn_save"><i
|
||||
class="fa fa-paperclip"></i>上传图片
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user