|
|
|
@ -153,28 +153,7 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
protected async Task<string> 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|