优化网关和feign基础日志排查
This commit is contained in:
@@ -358,6 +358,12 @@ public class DataFileController implements IDataFeignClient {
|
||||
return IDataFileService.uploadScriptFile(script);
|
||||
}
|
||||
|
||||
// 根基脚本文件ID更新当前脚本文件
|
||||
@PostMapping(value = "/updateScriptFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@Operation(summary = "更新脚本文件", description = "更新脚本文件")
|
||||
public SdmResponse updateScriptFile(UpdateScriptReq req) {
|
||||
return IDataFileService.updateScriptFile(req);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,8 +7,9 @@ import lombok.Data;
|
||||
@Data
|
||||
@Schema(description = "获取文件基本信息请求参数")
|
||||
public class GetFileBaseInfoReq {
|
||||
|
||||
@NotBlank(message = "path不能为空")
|
||||
@Schema(description = "文件路径", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String path;
|
||||
|
||||
@Schema(description = "文件id")
|
||||
private Integer fileId;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.sdm.data.model.req;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.sdm.common.entity.enums.FileBizTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Schema(description = "更新脚本文件请求参数")
|
||||
public class UpdateScriptReq {
|
||||
@Schema(description = "需要更新的脚本文件ID")
|
||||
private Long scriptFileId;
|
||||
|
||||
@Schema(description = "脚本文件名称")
|
||||
private String fileName;
|
||||
|
||||
@Schema(description = "需要更新的脚本文件")
|
||||
private MultipartFile updateFile;
|
||||
}
|
||||
@@ -12,8 +12,11 @@ import com.sdm.common.entity.req.system.LaunchApproveReq;
|
||||
import com.sdm.common.entity.resp.data.FileMetadataInfoResp;
|
||||
import com.sdm.data.model.req.*;
|
||||
import com.sdm.data.model.resp.KKFileViewURLFromMinioResp;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
@@ -210,6 +213,11 @@ public interface IDataFileService {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 根基脚本文件ID更新当前脚本文件
|
||||
default SdmResponse updateScriptFile(UpdateScriptReq req) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片预览
|
||||
*
|
||||
|
||||
@@ -652,13 +652,11 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
|
||||
@Override
|
||||
public SdmResponse getFileBaseInfo(GetFileBaseInfoReq req) {
|
||||
FileMetadataInfo fileMetadataInfo = fileMetadataInfoService.lambdaQuery().eq(FileMetadataInfo::getObjectKey, req.getPath()).one();
|
||||
FileMetadataInfo fileMetadataInfo = fileMetadataInfoService.lambdaQuery().eq(FileMetadataInfo::getId, req.getFileId()).one();
|
||||
if (fileMetadataInfo == null) {
|
||||
return SdmResponse.failed("文件不存在");
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("data", fileMetadataInfo);
|
||||
return SdmResponse.success(jsonObject);
|
||||
return SdmResponse.success(fileMetadataInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1483,7 +1481,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
|
||||
// 检查文件是否为空
|
||||
if (scriptFile == null || scriptFile.isEmpty()) {
|
||||
return SdmResponse.failed("请选择要上传的仿真参数库文件");
|
||||
return SdmResponse.failed("请选择要上传的脚本文件");
|
||||
}
|
||||
|
||||
// 获取 script 目录的 id
|
||||
@@ -1516,6 +1514,55 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdmResponse updateScriptFile(UpdateScriptReq req) {
|
||||
// 先创建 script 目录
|
||||
String dirMinioObjectKey = getDirMinioObjectKey(DirTypeEnum.SCRIPT_DIR.getDirName());
|
||||
Optional<FileMetadataInfo> scriptDirInfo = getFileMetadataInfoByObjectKey(dirMinioObjectKey);
|
||||
// 检查目录是否已存在
|
||||
if (!scriptDirInfo.isPresent()) {
|
||||
return SdmResponse.failed("script 目录不存在,等待initSystemDirectory 初始化完成");
|
||||
}
|
||||
|
||||
// 检查文件是否为空
|
||||
MultipartFile updateFile = req.getUpdateFile();
|
||||
if (ObjectUtils.isEmpty(updateFile)) {
|
||||
return SdmResponse.failed("请选择要更新的脚本文件");
|
||||
}
|
||||
|
||||
// 获取 script 目录的 id
|
||||
FileMetadataInfo scriptDirMetadataInfo = scriptDirInfo.get();
|
||||
Long parScriptDirId = scriptDirMetadataInfo.getId();
|
||||
|
||||
String originalFilename = req.getFileName();
|
||||
String suffix = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
|
||||
|
||||
// 生成带时间戳的文件名以避免冲突
|
||||
String filenameWithoutSuffix = originalFilename.substring(0, originalFilename.lastIndexOf("."));
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
String newFilename = filenameWithoutSuffix + "_" + timestamp + "." + suffix;
|
||||
|
||||
// 再上传脚本文件
|
||||
String scriptFileMinioObjectKey = getFileMinioObjectKey(scriptDirMetadataInfo.getObjectKey() + newFilename);
|
||||
|
||||
try {
|
||||
minioService.uploadFile(updateFile, scriptFileMinioObjectKey, null);
|
||||
|
||||
// 创建目录元数据并保存到数据库
|
||||
fileMetadataInfoService.lambdaUpdate()
|
||||
.set(FileMetadataInfo::getObjectKey,scriptFileMinioObjectKey)
|
||||
.set(FileMetadataInfo::getOriginalName,originalFilename)
|
||||
.set(FileMetadataInfo::getFileSize,updateFile.getSize())
|
||||
.eq(FileMetadataInfo::getId,req.getScriptFileId())
|
||||
.update();
|
||||
return SdmResponse.success(req.getScriptFileId());
|
||||
} catch (Exception e) {
|
||||
minioService.deleteFile(scriptFileMinioObjectKey);
|
||||
log.error("更新传脚本文件", e);
|
||||
throw new RuntimeException("更新传脚本文件: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void previewImage(Long fileId, HttpServletResponse response) {
|
||||
try {
|
||||
|
||||
@@ -76,6 +76,12 @@
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 绑定 FeignClient → 输出到日志文件 -->
|
||||
<logger name="FeignClient" level="INFO" additivity="false">
|
||||
<appender-ref ref="INFO_FILE" />
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
<!-- 绑定 coreLogger → 输出到 core.log + 控制台 -->
|
||||
<logger name="coreLogger" level="INFO" additivity="false">
|
||||
<appender-ref ref="CORE_FILE" /> <!-- 核心日志写入 core.log -->
|
||||
|
||||
Reference in New Issue
Block a user