修改BC任务

optimize
jianghaiqing 10 months ago
parent c1f09f7d04
commit 5ffc741903

@ -31,9 +31,10 @@ namespace Myshipping.Application
/// <param name="batchNo">批次号</param> /// <param name="batchNo">批次号</param>
/// <param name="isLocalTempFile">是否生成本地文件</param> /// <param name="isLocalTempFile">是否生成本地文件</param>
/// <param name="attachFileType">附件类型 bcfiles-BC文件</param> /// <param name="attachFileType">附件类型 bcfiles-BC文件</param>
/// <param name="isKeepSource">是否保留原文件</param>
/// <returns>返回新的文件路径</returns> /// <returns>返回新的文件路径</returns>
public static async Task<string> MoveFile(string fileDictKey,string sourceFilePath,string batchNo, public static async Task<string> MoveFile(string fileDictKey,string sourceFilePath,string batchNo,
bool isLocalTempFile = false,string attachFileType = "bcfiles") bool isLocalTempFile = false,string attachFileType = "bcfiles",bool isKeepSource = false)
{ {
var logger = Log.CreateLogger(nameof(FileAttachHelper)); var logger = Log.CreateLogger(nameof(FileAttachHelper));
@ -115,10 +116,14 @@ namespace Myshipping.Application
file.Close(); file.Close();
try try
{ {
//删除原文件 if (!isKeepSource)
System.IO.File.Delete(sourceFilePath); {
//删除原文件
System.IO.File.Delete(sourceFilePath);
}
} }
catch(Exception delEx) catch(Exception delEx)
{ {

@ -249,7 +249,7 @@ namespace Myshipping.Application
} }
//如果确认文件读取成功 //如果确认文件读取成功
var bookFilePath = await FileAttachHelper.MoveFile(bookingOrder.Id.ToString(), fileFullName, batchNo); var bookFilePath = await FileAttachHelper.MoveFile(bookingOrder.Id.ToString(), fileFullName, batchNo, false, "draftfiles");
//将格式单附件写入订舱的附件 //将格式单附件写入订舱的附件
await SaveEDIFile(bookingOrder.Id, bookFilePath, new System.IO.FileInfo(fileFullName).Name, entity.TenantId.Value, await SaveEDIFile(bookingOrder.Id, bookFilePath, new System.IO.FileInfo(fileFullName).Name, entity.TenantId.Value,

@ -52,6 +52,11 @@ namespace Myshipping.Application
private readonly IBookingSlotService _bookingSlotService; private readonly IBookingSlotService _bookingSlotService;
private readonly IBookingValueAddedService _bookingValueAddedService; private readonly IBookingValueAddedService _bookingValueAddedService;
const string CONST_BC_FILE_CODE = "bc";
const string CONST_BC_FILE_NAME = "Booking Confirmation";
const string CONST_BC_NOTICE_FILE_CODE = "bc_notice";
const string CONST_BC_NOTICE_FILE_NAME = "Booking Confirmation Notice";
public TaskManageBCService(SqlSugarRepository<TaskBCInfo> taskBCInfoRepository, public TaskManageBCService(SqlSugarRepository<TaskBCInfo> taskBCInfoRepository,
SqlSugarRepository<TaskBaseInfo> taskBaseRepository, SqlSugarRepository<TaskBaseInfo> taskBaseRepository,
@ -661,14 +666,179 @@ namespace Myshipping.Application
throw Oops.Oh($"当前BC任务已生成订舱或舱位不能重复生成"); throw Oops.Oh($"当前BC任务已生成订舱或舱位不能重复生成");
} }
if (model.GenerateMethod == "GEN_BOOKING_SLOT") if (model.GenerateMethod == "GEN_BOOKING_SLOT")
{ {
#region 推送舱位、推送订舱
//推送舱位 //推送舱位
GenerateBookingSlot(bcOrder, bcCtnList, fileList).GetAwaiter().GetResult(); var bookingSlotId = GenerateBookingSlot(bcOrder, bcCtnList, fileList).GetAwaiter().GetResult();
//推送订舱 //推送订舱
var bookingOrderId = GenerateBookingOrder(bcOrder, bcCtnList, fileList, model).GetAwaiter().GetResult(); var bookingOrderId = GenerateBookingOrder(bcOrder, bcCtnList, fileList, model).GetAwaiter().GetResult();
if (bookingSlotId > 0 || bookingOrderId > 0)
{
var bcEntity = _taskBCInfoRepository.AsQueryable().First(a => a.PK_ID == bcTaskInfo.PK_ID);
if (bcEntity != null)
{
if (bookingOrderId > 0)
bcEntity.BOOKING_ORDER_ID = bookingOrderId;
if (bookingSlotId > 0)
bcEntity.BOOKING_SLOT_ID = bookingSlotId;
bcEntity.UpdatedTime = DateTime.Now;
bcEntity.UpdatedUserId = UserManager.UserId;
bcEntity.UpdatedUserName = UserManager.Name;
_taskBCInfoRepository.AsUpdateable(bcEntity).UpdateColumns(it => new
{
it.BOOKING_ORDER_ID,
it.BOOKING_SLOT_ID,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommand();
var taskEntity = _taskBaseRepository.AsQueryable().First(u => u.PK_ID == bcEntity.TASK_ID);
if(taskEntity != null && taskEntity.IS_PUBLIC == 1)
{
taskEntity.IS_PUBLIC = 0;
taskEntity.CreatedUserId = UserManager.UserId;
taskEntity.CreatedUserName = UserManager.Name;
taskEntity.UpdatedTime = DateTime.Now;
taskEntity.UpdatedUserId = UserManager.UserId;
taskEntity.UpdatedUserName = UserManager.Name;
_taskBaseRepository.AsUpdateable(taskEntity).UpdateColumns(it => new
{
it.IS_PUBLIC,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName,
it.CreatedUserId,
it.CreatedUserName
}).ExecuteCommand();
}
}
}
#endregion
}
else if (model.GenerateMethod == "GEN_BOOKING")
{
#region 推送订舱
//推送订舱
var bookingOrderId = GenerateBookingOrder(bcOrder, bcCtnList, fileList, model).GetAwaiter().GetResult();
if (bookingOrderId > 0)
{
var bcEntity = _taskBCInfoRepository.AsQueryable().First(a => a.PK_ID == bcTaskInfo.PK_ID);
if (bcEntity != null)
{
if (bookingOrderId > 0)
bcEntity.BOOKING_ORDER_ID = bookingOrderId;
bcEntity.UpdatedTime = DateTime.Now;
bcEntity.UpdatedUserId = UserManager.UserId;
bcEntity.UpdatedUserName = UserManager.Name;
_taskBCInfoRepository.AsUpdateable(bcEntity).UpdateColumns(it => new
{
it.BOOKING_ORDER_ID,
it.BOOKING_SLOT_ID,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommand();
var taskEntity = _taskBaseRepository.AsQueryable().First(u => u.PK_ID == bcEntity.TASK_ID);
if (taskEntity != null && taskEntity.IS_PUBLIC == 1)
{
taskEntity.IS_PUBLIC = 0;
taskEntity.CreatedUserId = UserManager.UserId;
taskEntity.CreatedUserName = UserManager.Name;
taskEntity.UpdatedTime = DateTime.Now;
taskEntity.UpdatedUserId = UserManager.UserId;
taskEntity.UpdatedUserName = UserManager.Name;
_taskBaseRepository.AsUpdateable(taskEntity).UpdateColumns(it => new
{
it.IS_PUBLIC,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName,
it.CreatedUserId,
it.CreatedUserName
}).ExecuteCommand();
}
}
}
#endregion
}
else if (model.GenerateMethod == "GEN_BOOKING_SLOT")
{
#region 推送舱位
//推送舱位
var bookingSlotId = GenerateBookingSlot(bcOrder, bcCtnList, fileList).GetAwaiter().GetResult();
if (bookingSlotId > 0)
{
var bcEntity = _taskBCInfoRepository.AsQueryable().First(a => a.PK_ID == bcTaskInfo.PK_ID);
if (bcEntity != null)
{
if (bookingSlotId > 0)
bcEntity.BOOKING_SLOT_ID = bookingSlotId;
bcEntity.UpdatedTime = DateTime.Now;
bcEntity.UpdatedUserId = UserManager.UserId;
bcEntity.UpdatedUserName = UserManager.Name;
_taskBCInfoRepository.AsUpdateable(bcEntity).UpdateColumns(it => new
{
it.BOOKING_ORDER_ID,
it.BOOKING_SLOT_ID,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommand();
var taskEntity = _taskBaseRepository.AsQueryable().First(u => u.PK_ID == bcEntity.TASK_ID);
if (taskEntity != null && taskEntity.IS_PUBLIC == 1)
{
taskEntity.IS_PUBLIC = 0;
taskEntity.CreatedUserId = UserManager.UserId;
taskEntity.CreatedUserName = UserManager.Name;
taskEntity.UpdatedTime = DateTime.Now;
taskEntity.UpdatedUserId = UserManager.UserId;
taskEntity.UpdatedUserName = UserManager.Name;
_taskBaseRepository.AsUpdateable(taskEntity).UpdateColumns(it => new
{
it.IS_PUBLIC,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName,
it.CreatedUserId,
it.CreatedUserName
}).ExecuteCommand();
}
}
}
#endregion
} }
result.succ = true; result.succ = true;
@ -710,6 +880,7 @@ namespace Myshipping.Application
{ {
CARRIERID = taskBCInfo.CARRIERID, CARRIERID = taskBCInfo.CARRIERID,
CARRIER = carrierInfo.CnName?.Trim(), CARRIER = carrierInfo.CnName?.Trim(),
SLOT_BOOKING_NO = taskBCInfo.MBL_NO,
BOOKING_PARTY = taskBCInfo.BOOKING_PARTY, BOOKING_PARTY = taskBCInfo.BOOKING_PARTY,
BOOKING_SLOT_TYPE = taskBCInfo.BOOKING_SLOT_TYPE, BOOKING_SLOT_TYPE = taskBCInfo.BOOKING_SLOT_TYPE,
BOOKING_SLOT_TYPE_NAME = taskBCInfo.BOOKING_SLOT_TYPE_NAME, BOOKING_SLOT_TYPE_NAME = taskBCInfo.BOOKING_SLOT_TYPE_NAME,
@ -768,15 +939,44 @@ namespace Myshipping.Application
//成功后写入附件 //成功后写入附件
if (id > 0) if (id > 0)
{ {
taskFileList.ForEach(async file => var opt = App.GetOptions<BookingAttachOptions>();
var dirAbs = opt.basePath;
if (string.IsNullOrEmpty(dirAbs))
{
dirAbs = App.WebHostEnvironment.WebRootPath;
}
taskFileList.ForEach(file =>
{ {
//System.IO.FileStream file = new System.IO.FileStream(file, FileMode.Open, FileAccess.Read); if (file.FILE_CATEGORY == TaskFileCategoryEnum.BC.ToString())
//附件暂存 {
//var fileFullName = await FileAttachHelper.SaveFile(id, file, batchNo, "bc"); var fileFullPath = Path.Combine(dirAbs, file.FILE_PATH);
if (File.Exists(fileFullPath))
{
//如果确认文件读取成功
var bookFilePath = FileAttachHelper.MoveFile(id.ToString(), fileFullPath, batchNo, false, "bcfiles", true).GetAwaiter().GetResult();
}); //将格式单附件写入订舱的附件
SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, taskBCInfo.TenantId.Value,
CONST_BC_FILE_CODE, CONST_BC_FILE_NAME).GetAwaiter();
}
}
else if (file.FILE_CATEGORY == TaskFileCategoryEnum.BC_NOTICE.ToString())
{
var fileFullPath = Path.Combine(dirAbs, file.FILE_PATH);
if (File.Exists(fileFullPath))
{
//如果确认文件读取成功
var bookFilePath = FileAttachHelper.MoveFile(id.ToString(), fileFullPath, batchNo,false,"bcnoticefile",true).GetAwaiter().GetResult();
//将格式单附件写入订舱的附件
SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, taskBCInfo.TenantId.Value,
CONST_BC_NOTICE_FILE_CODE, CONST_BC_NOTICE_FILE_NAME).GetAwaiter();
}
}
});
} }
} }
catch (Exception ex) catch (Exception ex)
@ -871,29 +1071,62 @@ namespace Myshipping.Application
id = bkRlt.Id; id = bkRlt.Id;
//附件暂存 string batchNo = IDGen.NextID().ToString();
//var fileFullName = await FileAttachHelper.SaveFile(id, file, batchNo, CONST_DRAFT_FILE_CODE);
//如果确认文件读取成功 if (id > 0)
//var bookFilePath = await FileAttachHelper.MoveFile(bookingOrder.Id.ToString(), fileFullName, batchNo); {
if (generateModel.ProjectList != null && generateModel.ProjectList.Count > 0)
{
ModifyServiceProjectDto projectDto = new ModifyServiceProjectDto
{
BookingId = id,
ProjectCodes = generateModel.ProjectList.Distinct().ToArray(),
};
//写入服务项目
var prjRlt = await _bookingValueAddedService.SaveServiceProject(projectDto);
//写入附件 _logger.LogInformation($"推送订舱的服务项目完成 id={id} rlt={JSON.Serialize(prjRlt)}");
//await SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(fileFullName).Name, entity.TenantId.Value, }
// CONST_DRAFT_FILE_CODE, CONST_DRAFT_FILE_NAME);
if (generateModel.ProjectList != null && generateModel.ProjectList.Count > 0) var opt = App.GetOptions<BookingAttachOptions>();
{ var dirAbs = opt.basePath;
ModifyServiceProjectDto projectDto = new ModifyServiceProjectDto if (string.IsNullOrEmpty(dirAbs))
{ {
BookingId = id, dirAbs = App.WebHostEnvironment.WebRootPath;
ProjectCodes = generateModel.ProjectList.Distinct().ToArray(), }
};
//写入服务项目
var prjRlt = await _bookingValueAddedService.SaveServiceProject(projectDto);
_logger.LogInformation($"推送订舱的服务项目完成 id={id} rlt={JSON.Serialize(prjRlt)}"); taskFileList.ForEach(file =>
} {
if (file.FILE_CATEGORY == TaskFileCategoryEnum.BC.ToString())
{
var fileFullPath = Path.Combine(dirAbs, file.FILE_PATH);
if (File.Exists(fileFullPath))
{
//如果确认文件读取成功
var bookFilePath = FileAttachHelper.MoveFile(id.ToString(), fileFullPath, batchNo).GetAwaiter().GetResult();
//将格式单附件写入订舱的附件
SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, taskBCInfo.TenantId.Value,
CONST_BC_FILE_CODE, CONST_BC_FILE_NAME).GetAwaiter();
}
}
else if (file.FILE_CATEGORY == TaskFileCategoryEnum.BC_NOTICE.ToString())
{
var fileFullPath = Path.Combine(dirAbs, file.FILE_PATH);
if (File.Exists(fileFullPath))
{
//如果确认文件读取成功
var bookFilePath = FileAttachHelper.MoveFile(id.ToString(), fileFullPath, batchNo, false, "bcnoticefile").GetAwaiter().GetResult();
//将格式单附件写入订舱的附件
SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, taskBCInfo.TenantId.Value,
CONST_BC_NOTICE_FILE_CODE, CONST_BC_NOTICE_FILE_NAME).GetAwaiter();
}
}
});
}
_logger.LogInformation($"任务BC MBLNO:{taskBCInfo.MBL_NO} 生成订舱成功 id={id}"); _logger.LogInformation($"任务BC MBLNO:{taskBCInfo.MBL_NO} 生成订舱成功 id={id}");

Loading…
Cancel
Save