BC附件保存调整

usertest
zhangxiaofeng 3 months ago
parent a613784c5e
commit 0568abd6b4

@ -2903,7 +2903,7 @@ namespace DS.WMS.Core.TaskPlat.Method
string bcFileName = file.FileName; string bcFileName = file.FileName;
var bcFileBytes = file.ToByteArray(); var bcFileBytes = file.ToByteArray();
var bcNoExtensionFileName = Path.GetFileNameWithoutExtension(file.FileName); var bcNoExtensionFileName = Path.GetFileNameWithoutExtension(file.FileName);
var bcFileFullName = await SaveFile(taskInfo.Id.ToString()!, var bcFileRelativePath = await SaveFile(taskInfo.Id.ToString()!,
bcFileBytes, bcFileBytes,
batchNo, batchNo,
bcNoExtensionFileName, bcNoExtensionFileName,
@ -2916,7 +2916,7 @@ namespace DS.WMS.Core.TaskPlat.Method
TASK_PKID = taskInfo.Id, TASK_PKID = taskInfo.Id,
CreateBy = taskInfo.CreateBy, CreateBy = taskInfo.CreateBy,
CreateTime = taskInfo.CreateTime, CreateTime = taskInfo.CreateTime,
FILE_PATH = bcFileFullName, FILE_PATH = bcFileRelativePath,
FILE_NAME = bcFileName, FILE_NAME = bcFileName,
FILE_TYPE = Path.GetExtension(bcFileName).ToLower(), FILE_TYPE = Path.GetExtension(bcFileName).ToLower(),
FILE_CATEGORY = TaskFileCategoryEnum.BC.ToString(), FILE_CATEGORY = TaskFileCategoryEnum.BC.ToString(),
@ -2931,7 +2931,7 @@ namespace DS.WMS.Core.TaskPlat.Method
return DataResult.Failed(bcNotifyFileBytes.Message); return DataResult.Failed(bcNotifyFileBytes.Message);
} }
var bcNotifyNoExtensionFileName = Path.GetFileNameWithoutExtension(bcNotifyFileName); var bcNotifyNoExtensionFileName = Path.GetFileNameWithoutExtension(bcNotifyFileName);
var bcNotifyFileFullName = await SaveFile(taskInfo.Id.ToString()!, var bcNotifyFileRelativePath = await SaveFile(taskInfo.Id.ToString()!,
bcNotifyFileBytes.Data, bcNotifyFileBytes.Data,
batchNo, batchNo,
bcNotifyNoExtensionFileName, bcNotifyNoExtensionFileName,
@ -2944,11 +2944,11 @@ namespace DS.WMS.Core.TaskPlat.Method
TASK_PKID = taskInfo.Id, TASK_PKID = taskInfo.Id,
CreateBy = taskInfo.CreateBy, CreateBy = taskInfo.CreateBy,
CreateTime = taskInfo.CreateTime, CreateTime = taskInfo.CreateTime,
FILE_PATH = bcNotifyFileFullName, FILE_PATH = bcNotifyFileRelativePath,
FILE_NAME = bcNotifyFileName, FILE_NAME = bcNotifyFileName,
FILE_TYPE = Path.GetExtension(bcNotifyFileName).ToLower(), FILE_TYPE = Path.GetExtension(bcNotifyFileName).ToLower(),
FILE_CATEGORY = TaskFileCategoryEnum.BC.ToString(), FILE_CATEGORY = TaskFileCategoryEnum.BC_NOTICE.ToString(),
FILE_CATEGORY_NAME = TaskFileCategoryEnum.BC.EnumDescription() FILE_CATEGORY_NAME = TaskFileCategoryEnum.BC_NOTICE.EnumDescription()
}; };
// 用于挂载到订单的文件信息 // 用于挂载到订单的文件信息

@ -153,28 +153,7 @@ namespace DS.WMS.Core.TaskPlat.Method
protected async Task<string> SaveFile(string fileDictKey, byte[] fileBytes, string batchNo, string fileNameNoSuffix, protected async Task<string> SaveFile(string fileDictKey, byte[] fileBytes, string batchNo, string fileNameNoSuffix,
PrintFileTypeEnum printFileType, string attachFileType = "sofiles") PrintFileTypeEnum printFileType, string attachFileType = "sofiles")
{ {
var basePath = AppSetting.app(new string[] { "FileSettings", "BasePath" }); // 获取文件存盘时保存的物理文件名fileName
var relativePath = AppSetting.app(new string[] { "FileSettings", "RelativePath" });
if (!string.IsNullOrWhiteSpace(attachFileType))
relativePath += $"\\{attachFileType}";
if (!string.IsNullOrWhiteSpace(fileDictKey))
relativePath += $"\\{fileDictKey}";
string? dirAbs;
if (string.IsNullOrEmpty(basePath))
{
dirAbs = Path.Combine(environment.WebRootPath ?? "", relativePath);
}
else
{
dirAbs = Path.Combine(basePath, relativePath);
}
if (!Directory.Exists(dirAbs))
Directory.CreateDirectory(dirAbs);
var fileType = string.Empty; var fileType = string.Empty;
if (printFileType == PrintFileTypeEnum.PDF) if (printFileType == PrintFileTypeEnum.PDF)
{ {
@ -196,38 +175,50 @@ namespace DS.WMS.Core.TaskPlat.Method
{ {
fileType = ".doc"; fileType = ".doc";
} }
var fileName = $"{fileNameNoSuffix}{fileType}"; // 文件存盘时保存的物理文件名
string curFileName = fileNameNoSuffix;
//var id = SnowFlakeSingle.Instance.NextId(); // 获取文件存库时保存的文件名fileInfoRelativePathWithName
var fileSaveName = $"{curFileName}{fileType}"; var fileInfoRelativeDic = string.Empty;
string fileRelaPath = Path.Combine(relativePath, fileSaveName); if (!string.IsNullOrWhiteSpace(attachFileType))
string fileAbsPath = Path.Combine(dirAbs, fileSaveName); fileInfoRelativeDic = Path.Combine(fileInfoRelativeDic, attachFileType);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) if (!string.IsNullOrWhiteSpace(fileDictKey))
fileInfoRelativeDic = Path.Combine(fileInfoRelativeDic, fileDictKey);
// 文件存库时保存的文件名
var fileInfoRelativePathWithName = Path.Combine(fileInfoRelativeDic, fileName); // 文件存库时保存的文件名
// 获取文件存盘所需的绝对路径absFilePath
var absFilePath = string.Empty;
var baseDicConfig = AppSetting.app(new string[] { "FileSettings", "BasePath" });
var relativeDicConfig = AppSetting.app(new string[] { "FileSettings", "RelativePath" });
if (string.IsNullOrEmpty(baseDicConfig))
{ {
relativePath = relativePath.Replace("\\", "/"); absFilePath = Path.Combine(environment.WebRootPath ?? "", relativeDicConfig, fileInfoRelativeDic);
fileRelaPath = fileRelaPath.Replace("\\", "/"); }
fileAbsPath = fileAbsPath.Replace("\\", "/"); else
{
absFilePath = Path.Combine(baseDicConfig, relativeDicConfig, fileInfoRelativeDic);
} }
//logger.LogInformation("批次={no} 生成文件保存路径完成 路由={filePath} 服务器系统={system}", batchNo, fileRelaPath, RuntimeInformation.OSDescription); if (!Directory.Exists(absFilePath))
Directory.CreateDirectory(absFilePath);
await File.WriteAllBytesAsync(fileAbsPath, fileBytes); absFilePath = Path.Combine(absFilePath, fileName);
//string bookFilePath; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
//if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
//{ fileInfoRelativePathWithName = fileInfoRelativePathWithName.Replace("\\", "/");
// bookFilePath = System.Text.RegularExpressions.Regex.Match(fileAbsPath, relativePath.Replace("/", "\\/") + ".*").Value; absFilePath = absFilePath.Replace("\\", "/");
//} }
//else await File.WriteAllBytesAsync(absFilePath, fileBytes);
//{
// bookFilePath = System.Text.RegularExpressions.Regex.Match(fileAbsPath, relativePath.Replace("\\", "\\\\") + ".*").Value;
//}
return fileAbsPath; return fileInfoRelativePathWithName;
//return bookFilePath;
} }
/// <summary> /// <summary>
@ -300,21 +291,21 @@ namespace DS.WMS.Core.TaskPlat.Method
string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskFileEmpty)), taskId) string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskFileEmpty)), taskId)
); );
} }
var basePath = AppSetting.app(new string[] { "FileSettings", "BasePath" }); var baseDicConfig = AppSetting.app(new string[] { "FileSettings", "BasePath" });
var relativeDicConfig = AppSetting.app(new string[] { "FileSettings", "RelativePath" });
string fileFullPath; string absFilePath;
if (string.IsNullOrEmpty(basePath)) if (string.IsNullOrEmpty(baseDicConfig))
{ {
fileFullPath = Path.Combine(environment.WebRootPath ?? "", fileInfo.FILE_PATH); absFilePath = Path.Combine(environment.WebRootPath ?? "", relativeDicConfig, fileInfo.FILE_PATH);
} }
else else
{ {
fileFullPath = Path.Combine(basePath, fileInfo.FILE_PATH); absFilePath = Path.Combine(baseDicConfig, relativeDicConfig, fileInfo.FILE_PATH);
} }
if (!File.Exists(fileFullPath)) if (!File.Exists(absFilePath))
{ {
logger.LogError("根据任务主键获取文件信息失败文件不存在fileFullPath={fileFullPath}", fileFullPath); logger.LogError("根据任务主键获取文件信息失败文件不存在fileFullPath={fileFullPath}", absFilePath);
//任务主键{0} 附件下载请求失败,请确认文件是否存在 //任务主键{0} 附件下载请求失败,请确认文件是否存在
throw new Exception( throw new Exception(
string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskFileNotExists)), taskId) string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskFileNotExists)), taskId)
@ -322,7 +313,7 @@ namespace DS.WMS.Core.TaskPlat.Method
} }
var fileName = HttpUtility.UrlEncode(fileInfo.FILE_NAME, Encoding.GetEncoding("UTF-8"))!; var fileName = HttpUtility.UrlEncode(fileInfo.FILE_NAME, Encoding.GetEncoding("UTF-8"))!;
return (fileFullPath, fileName); return (absFilePath, fileName);
//return (new FileStream(fileFullPath, FileMode.Open), fileName); //return (new FileStream(fileFullPath, FileMode.Open), fileName);
} }

@ -61,7 +61,7 @@
} }
}, },
"FileSettings": { "FileSettings": {
"BasePath": "", //使 "BasePath": "D:\\ds8\\main-api\\wwwroot", //使
"RelativePath": "LinkAttach", "RelativePath": "LinkAttach",
"FileType": [ ".xls", ".xlsx", ".pdf", ".txt", ".pms" ] "FileType": [ ".xls", ".xlsx", ".pdf", ".txt", ".pms" ]
}, },

Loading…
Cancel
Save