|
|
|
@ -9,6 +9,8 @@ using Microsoft.Extensions.Logging;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
{
|
|
|
|
@ -102,12 +104,14 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存文件并返回文件完整路径
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="fileDictKey">追加文件夹</param>
|
|
|
|
|
/// <param name="fileBytes">文件二进制流</param>
|
|
|
|
|
/// <param name="batchNo">批次号</param>
|
|
|
|
|
/// <param name="fileNameNoSuffix">无拓展名的文件名</param>
|
|
|
|
|
/// <param name="printFileType">文件类型</param>
|
|
|
|
|
/// <param name="attachFileType">附件类型 bcfiles-BC文件 sofile-订舱附件</param>
|
|
|
|
|
/// <returns>返回文件完整路径</returns>
|
|
|
|
|
protected async Task<string> SaveFile(byte[] fileBytes, string batchNo,
|
|
|
|
|
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" });
|
|
|
|
@ -116,6 +120,9 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(attachFileType))
|
|
|
|
|
relativePath += $"\\{attachFileType}";
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(fileDictKey))
|
|
|
|
|
relativePath += $"\\{fileDictKey}";
|
|
|
|
|
|
|
|
|
|
string? dirAbs;
|
|
|
|
|
if (string.IsNullOrEmpty(basePath))
|
|
|
|
|
{
|
|
|
|
@ -151,11 +158,13 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
fileType = ".doc";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var id = SnowFlakeSingle.Instance.NextId();
|
|
|
|
|
var fileSaveName = $"{id}{fileType}".ToLower();
|
|
|
|
|
string curFileName = fileNameNoSuffix;
|
|
|
|
|
|
|
|
|
|
//var id = SnowFlakeSingle.Instance.NextId();
|
|
|
|
|
var fileSaveName = $"{curFileName}{fileType}";
|
|
|
|
|
|
|
|
|
|
string fileRelaPath = Path.Combine(relativePath, fileSaveName).ToLower();
|
|
|
|
|
string fileAbsPath = Path.Combine(dirAbs, fileSaveName).ToLower();
|
|
|
|
|
string fileRelaPath = Path.Combine(relativePath, fileSaveName);
|
|
|
|
|
string fileAbsPath = Path.Combine(dirAbs, fileSaveName);
|
|
|
|
|
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
|
{
|
|
|
|
@ -214,6 +223,65 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据任务ID获取附件信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="taskId">任务Id</param>
|
|
|
|
|
/// <param name="fileCategory">附件分类代码</param>
|
|
|
|
|
public async Task<(string fileFullPath, string fileName)> GetTaskFileInfo(long taskId, string fileCategory)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
var bcTaskInfo = await tenantDb.Queryable<TaskBaseInfo>().Where(u => u.Id == taskId).FirstAsync();
|
|
|
|
|
if (bcTaskInfo == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataQueryNoData)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskFileCategoryEnum fileCategoryEnum = TaskFileCategoryEnum.NONE;
|
|
|
|
|
|
|
|
|
|
System.Enum.TryParse(fileCategory, out fileCategoryEnum);
|
|
|
|
|
|
|
|
|
|
if (fileCategoryEnum == TaskFileCategoryEnum.NONE)
|
|
|
|
|
{
|
|
|
|
|
// 附件分类代码错误,请提供正确的分类代码
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskFileCategoryError)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string name = fileCategoryEnum.ToString();
|
|
|
|
|
|
|
|
|
|
var fileInfo = await tenantDb.Queryable<TaskFileInfo>().Where(u => u.TASK_PKID == taskId && u.FILE_CATEGORY == name).OrderByDescending(x => x.Id).FirstAsync();
|
|
|
|
|
|
|
|
|
|
if (fileInfo == null)
|
|
|
|
|
{
|
|
|
|
|
// 附件分类代码错误,请提供正确的分类代码
|
|
|
|
|
throw new Exception(
|
|
|
|
|
string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskFileCategoryError)), taskId)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
var basePath = AppSetting.app(new string[] { "FileSettings", "BasePath" });
|
|
|
|
|
|
|
|
|
|
string fileFullPath;
|
|
|
|
|
if (string.IsNullOrEmpty(basePath))
|
|
|
|
|
{
|
|
|
|
|
fileFullPath = Path.Combine(environment.WebRootPath ?? "", fileInfo.FILE_PATH);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fileFullPath = Path.Combine(basePath, fileInfo.FILE_PATH);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (!File.Exists(fileFullPath))
|
|
|
|
|
{
|
|
|
|
|
//任务主键{0} 附件下载请求失败,请确认文件是否存在
|
|
|
|
|
throw new Exception(
|
|
|
|
|
string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskFileNotExists)), taskId)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var fileName = HttpUtility.UrlEncode(fileInfo.FILE_NAME, Encoding.GetEncoding("UTF-8"))!;
|
|
|
|
|
return (fileFullPath, fileName);
|
|
|
|
|
//return (new FileStream(fileFullPath, FileMode.Open), fileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|