diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs index 9dd22ac1..85b029a0 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBCService.cs @@ -2903,7 +2903,7 @@ namespace DS.WMS.Core.TaskPlat.Method string bcFileName = file.FileName; var bcFileBytes = file.ToByteArray(); var bcNoExtensionFileName = Path.GetFileNameWithoutExtension(file.FileName); - var bcFileFullName = await SaveFile(taskInfo.Id.ToString()!, + var bcFileRelativePath = await SaveFile(taskInfo.Id.ToString()!, bcFileBytes, batchNo, bcNoExtensionFileName, @@ -2916,7 +2916,7 @@ namespace DS.WMS.Core.TaskPlat.Method TASK_PKID = taskInfo.Id, CreateBy = taskInfo.CreateBy, CreateTime = taskInfo.CreateTime, - FILE_PATH = bcFileFullName, + FILE_PATH = bcFileRelativePath, FILE_NAME = bcFileName, FILE_TYPE = Path.GetExtension(bcFileName).ToLower(), FILE_CATEGORY = TaskFileCategoryEnum.BC.ToString(), @@ -2931,7 +2931,7 @@ namespace DS.WMS.Core.TaskPlat.Method return DataResult.Failed(bcNotifyFileBytes.Message); } var bcNotifyNoExtensionFileName = Path.GetFileNameWithoutExtension(bcNotifyFileName); - var bcNotifyFileFullName = await SaveFile(taskInfo.Id.ToString()!, + var bcNotifyFileRelativePath = await SaveFile(taskInfo.Id.ToString()!, bcNotifyFileBytes.Data, batchNo, bcNotifyNoExtensionFileName, @@ -2944,11 +2944,11 @@ namespace DS.WMS.Core.TaskPlat.Method TASK_PKID = taskInfo.Id, CreateBy = taskInfo.CreateBy, CreateTime = taskInfo.CreateTime, - FILE_PATH = bcNotifyFileFullName, + FILE_PATH = bcNotifyFileRelativePath, FILE_NAME = bcNotifyFileName, FILE_TYPE = Path.GetExtension(bcNotifyFileName).ToLower(), - FILE_CATEGORY = TaskFileCategoryEnum.BC.ToString(), - FILE_CATEGORY_NAME = TaskFileCategoryEnum.BC.EnumDescription() + FILE_CATEGORY = TaskFileCategoryEnum.BC_NOTICE.ToString(), + FILE_CATEGORY_NAME = TaskFileCategoryEnum.BC_NOTICE.EnumDescription() }; // 用于挂载到订单的文件信息 diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs index c499f919..5c80acee 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs @@ -153,28 +153,7 @@ namespace DS.WMS.Core.TaskPlat.Method protected async Task SaveFile(string fileDictKey, byte[] fileBytes, string batchNo, string fileNameNoSuffix, PrintFileTypeEnum printFileType, string attachFileType = "sofiles") { - var basePath = AppSetting.app(new string[] { "FileSettings", "BasePath" }); - 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); - + // 获取文件存盘时保存的物理文件名:fileName var fileType = string.Empty; if (printFileType == PrintFileTypeEnum.PDF) { @@ -196,38 +175,50 @@ namespace DS.WMS.Core.TaskPlat.Method { fileType = ".doc"; } + var fileName = $"{fileNameNoSuffix}{fileType}"; // 文件存盘时保存的物理文件名 - string curFileName = fileNameNoSuffix; - //var id = SnowFlakeSingle.Instance.NextId(); - var fileSaveName = $"{curFileName}{fileType}"; + // 获取文件存库时保存的文件名:fileInfoRelativePathWithName + var fileInfoRelativeDic = string.Empty; - string fileRelaPath = Path.Combine(relativePath, fileSaveName); - string fileAbsPath = Path.Combine(dirAbs, fileSaveName); + if (!string.IsNullOrWhiteSpace(attachFileType)) + 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("\\", "/"); - fileRelaPath = fileRelaPath.Replace("\\", "/"); - fileAbsPath = fileAbsPath.Replace("\\", "/"); + absFilePath = Path.Combine(environment.WebRootPath ?? "", relativeDicConfig, fileInfoRelativeDic); + } + 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)) - //{ - // bookFilePath = System.Text.RegularExpressions.Regex.Match(fileAbsPath, relativePath.Replace("/", "\\/") + ".*").Value; - //} - //else - //{ - // bookFilePath = System.Text.RegularExpressions.Regex.Match(fileAbsPath, relativePath.Replace("\\", "\\\\") + ".*").Value; - //} + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + fileInfoRelativePathWithName = fileInfoRelativePathWithName.Replace("\\", "/"); + absFilePath = absFilePath.Replace("\\", "/"); + } + await File.WriteAllBytesAsync(absFilePath, fileBytes); - return fileAbsPath; - //return bookFilePath; + return fileInfoRelativePathWithName; } /// @@ -300,21 +291,21 @@ namespace DS.WMS.Core.TaskPlat.Method 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; - if (string.IsNullOrEmpty(basePath)) + string absFilePath; + if (string.IsNullOrEmpty(baseDicConfig)) { - fileFullPath = Path.Combine(environment.WebRootPath ?? "", fileInfo.FILE_PATH); + absFilePath = Path.Combine(environment.WebRootPath ?? "", relativeDicConfig, fileInfo.FILE_PATH); } 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} 附件下载请求失败,请确认文件是否存在 throw new Exception( 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"))!; - return (fileFullPath, fileName); + return (absFilePath, fileName); //return (new FileStream(fileFullPath, FileMode.Open), fileName); } diff --git a/ds-wms-service/DS.WMS.TaskApi/appsettings.json b/ds-wms-service/DS.WMS.TaskApi/appsettings.json index 963b3c82..00104877 100644 --- a/ds-wms-service/DS.WMS.TaskApi/appsettings.json +++ b/ds-wms-service/DS.WMS.TaskApi/appsettings.json @@ -61,7 +61,7 @@ } }, "FileSettings": { - "BasePath": "", //基础路径,不配置则使用当前系统目录 + "BasePath": "D:\\ds8\\main-api\\wwwroot", //基础路径,不配置则使用当前系统目录 "RelativePath": "LinkAttach", "FileType": [ ".xls", ".xlsx", ".pdf", ".txt", ".pms" ] },