diff --git a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageBCService.cs b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageBCService.cs
index 521e1951..7625771a 100644
--- a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageBCService.cs
+++ b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageBCService.cs
@@ -1,4 +1,5 @@
-using System;
+using Microsoft.AspNetCore.Mvc;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -24,5 +25,18 @@ namespace Myshipping.Application
/// BC任务主键
/// 返回回执
Task GetInfoByTaskId(string taskPkId);
+
+ ///
+ /// 获取待处理的BC任务(来自邮件解析需要对应订舱,系统会根据用户的订舱台账预配)
+ ///
+ /// 返回回执
+ Task GetToDoBCList();
+
+ ///
+ /// 任务ID下载附件
+ ///
+ /// BC任务主键
+ /// 返回数据流
+ Task DownloadFile(string taskPKId);
}
}
diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs
index 4099e2bf..5c90768b 100644
--- a/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs
+++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs
@@ -1,16 +1,22 @@
-using Furion.DynamicApiController;
+using Furion;
+using Furion.DynamicApiController;
using Furion.FriendlyException;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
+using Myshipping.Application.ConfigOption;
using Myshipping.Application.Entity;
+using Myshipping.Application.Enum;
using Myshipping.Core;
using Myshipping.Core.Service;
+using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Web;
namespace Myshipping.Application
{
@@ -27,16 +33,22 @@ namespace Myshipping.Application
private readonly SqlSugarRepository _taskBCCTNInfoRepository;
private readonly SqlSugarRepository _taskBaseRepository;
private readonly SqlSugarRepository _taskFileRepository;
+ private readonly SqlSugarRepository _bookingOrderRepository;
+ private readonly SqlSugarRepository _bookingCtnRepository;
public TaskManageBCService(SqlSugarRepository taskBCInfoRepository,
SqlSugarRepository taskBaseRepository,
SqlSugarRepository taskBCCTNInfoRepository,
- SqlSugarRepository taskFileRepository)
+ SqlSugarRepository taskFileRepository,
+ SqlSugarRepository bookingOrderRepository,
+ SqlSugarRepository bookingCtnRepository)
{
_taskBaseRepository = taskBaseRepository;
_taskBCInfoRepository = taskBCInfoRepository;
_taskBCCTNInfoRepository = taskBCCTNInfoRepository;
_taskFileRepository = taskFileRepository;
+ _bookingOrderRepository = bookingOrderRepository;
+ _bookingCtnRepository = bookingCtnRepository;
}
#region 获取BC详情
@@ -73,11 +85,31 @@ namespace Myshipping.Application
result.succ = true;
result.ext = model;
+ //如果当前BC有对应记录,则读取订舱详情
+ if (bcOrder.BOOKING_ORDER_ID.HasValue)
+ {
+ var bkOrder = await _bookingOrderRepository.AsQueryable().
+ FirstAsync(a => a.Id == bcOrder.BOOKING_ORDER_ID.Value);
+
+ if (bkOrder != null)
+ {
+ var showBKOrder = bkOrder.Adapt();
+
+ var ctnList = await _bookingCtnRepository.AsQueryable().
+ Where(a => a.BILLID == bkOrder.Id).ToListAsync();
+
+ if (ctnList.Count > 0)
+ showBKOrder.ctnInputs = ctnList.Adapt>();
+
+ result.ext2 = showBKOrder;
+ }
+ }
+
}
catch (Exception ex)
{
result.succ = false;
- result.msg = $"获取派车详情异常,原因:{ex.Message}";
+ result.msg = $"获取BC详情异常,原因:{ex.Message}";
}
return result;
@@ -119,18 +151,113 @@ namespace Myshipping.Application
if (fileList.Count > 0)
model.FileList = fileList.Adapt>();
+
result.succ = true;
result.ext = model;
+ //如果当前BC有对应记录,则读取订舱详情
+ if (bcOrder.BOOKING_ORDER_ID.HasValue)
+ {
+ var bkOrder = await _bookingOrderRepository.AsQueryable().
+ FirstAsync(a => a.Id == bcOrder.BOOKING_ORDER_ID.Value);
+
+ if(bkOrder != null)
+ {
+ var showBKOrder = bkOrder.Adapt();
+
+ var ctnList = await _bookingCtnRepository.AsQueryable().
+ Where(a => a.BILLID == bkOrder.Id).ToListAsync();
+
+ if (ctnList.Count > 0)
+ showBKOrder.ctnInputs = ctnList.Adapt>();
+
+ result.ext2 = showBKOrder;
+ }
+ }
}
catch (Exception ex)
{
result.succ = false;
- result.msg = $"获取派车详情异常,原因:{ex.Message}";
+ result.msg = $"获取BC详情异常,原因:{ex.Message}";
}
return result;
}
#endregion
+
+ ///
+ /// 获取待处理的BC任务(来自邮件解析需要对应订舱,系统会根据用户的订舱台账预配)
+ ///
+ /// 返回回执
+ public async Task GetToDoBCList()
+ {
+ TaskManageOrderResultDto result = new TaskManageOrderResultDto();
+
+ /*
+ 1、优先匹配提单号一致的
+ 2、判断船名航次一致的
+ 3、
+ */
+ try
+ {
+ //获取所有待处理的BC任务
+ var taskList = await _taskBCInfoRepository.AsQueryable().InnerJoin((a,b)=>a.TASK_ID == b.PK_ID)
+ .Where((a, b)=> !a.BOOKING_ORDER_ID.HasValue && b.STATUS == TaskStatusEnum.Create.ToString())
+ .Select((a,b)=>new { BC = a,TSK = b }).ToListAsync();
+
+ if (taskList.Count > 0)
+ {
+
+ }
+
+ result.succ = true;
+ }
+ catch (Exception ex)
+ {
+ result.succ = false;
+ result.msg = $"获取派车详情异常,原因:{ex.Message}";
+ }
+
+ return result;
+ }
+
+ ///
+ /// 任务ID下载附件
+ ///
+ /// BC任务主键
+ /// 返回数据流
+ [HttpGet("/TaskManageBC/DownloadFile")]
+ public async Task DownloadFile(string taskPKId)
+ {
+ var bcTaskInfo = await _taskBaseRepository.AsQueryable().FirstAsync(u => u.PK_ID == taskPKId);
+ if (bcTaskInfo == null)
+ {
+ throw Oops.Oh($"任务主键{taskPKId}无法获取业务信息");
+ }
+
+ var fileInfo = await _taskFileRepository.AsQueryable().FirstAsync(u => u.TASK_PKID == taskPKId);
+
+ if (fileInfo == null)
+ {
+ throw Oops.Oh($"任务主键{taskPKId}没有可下载的附件");
+ }
+
+ var opt = App.GetOptions();
+ var dirAbs = opt.basePath;
+ if (string.IsNullOrEmpty(dirAbs))
+ {
+ dirAbs = App.WebHostEnvironment.WebRootPath;
+ }
+
+ var fileFullPath = Path.Combine(dirAbs, fileInfo.FILE_PATH);
+ if (!File.Exists(fileFullPath))
+ {
+ throw Oops.Oh($"任务主键{taskPKId} 附件下载请求失败,请确认文件是否存在");
+ }
+
+ var fileName = HttpUtility.UrlEncode(fileInfo.FILE_NAME, Encoding.GetEncoding("UTF-8"));
+ var result = new FileStreamResult(new FileStream(fileFullPath, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName };
+ return result;
+ }
}
}