diff --git a/ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj b/ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj index d56ea0ac..707b4119 100644 --- a/ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj +++ b/ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj @@ -26,7 +26,6 @@ - diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/BookingSlot/BookingSlotService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/BookingSlot/BookingSlotService.cs index 8494ba87..9bd77321 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/BookingSlot/BookingSlotService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/BookingSlot/BookingSlotService.cs @@ -1423,7 +1423,7 @@ namespace DS.WMS.Core.Op.Method model = await tenantDb.Queryable().FirstAsync(x => x.SlotBookingNo == slotNO); if (model == null) { - //throw Oops.Bah($"未找到订舱编号为 {slotNO} 的数据"); + throw new Exception($"未找到订舱编号为 {slotNO} 的数据"); } id = model.Id; diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/Mapper/AddTaskPlatMapsterSetup.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/Mapper/AddTaskPlatMapsterSetup.cs index d382097d..21cbb3c9 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/Mapper/AddTaskPlatMapsterSetup.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/Mapper/AddTaskPlatMapsterSetup.cs @@ -458,7 +458,42 @@ namespace DS.WMS.Core.TaskPlat.Dtos.Mapper .Map(dest => dest.CBM, src => src.CBM) .Map(dest => dest.GoodsDescription, src => src.Description) .Map(dest => dest.KindPKGs, src => src.KindPkgs); - + } + + { + TypeAdapterConfig.NewConfig() + .Map(dest => dest.BOOKING_NO, src => src.BookingNo) + .Map(dest => dest.MBL_NO, src => src.BillNo) + .Map(dest => dest.ORIG_MBL_NO, src => src.OrigBillNo) + .Map(dest => dest.CARRIER, src => src.Carrier) + .Map(dest => dest.CHANGE_REASON, src => src.ChangeReasonNotes) + .Map(dest => dest.PORTLOAD, src => src.PortLoad) + .Map(dest => dest.PORTLOAD_COUNTRY, src => src.PortLoadCountry) + .Map(dest => dest.PORTLOAD_TERMINAL, src => src.PortLoadTerminal) + .Map(dest => dest.PORTDISCHARGE, src => src.PortDischarge) + .Map(dest => dest.PORTDISCHARGE_COUNTRY, src => src.PortDischargeCountry) + .Map(dest => dest.PORTDISCHARGE_TERMINAL, src => src.PortDischargeTerminal) + .Map(dest => dest.VESSEL, src => src.Vessel) + .Map(dest => dest.VOYNO, src => src.Voyno) + .Map(dest => dest.SHIP_FLAG, src => src.ShipFlag) + .Map(dest => dest.ETD, src => src.ETD) + .Map(dest => dest.ETA, src => src.ETA) + .Map(dest => dest.GROUP_BATCH_NO, src => src.GroupBatchNo) + .Map(dest => dest.IS_LAST, src => src.IsLast); + } + + { + TypeAdapterConfig.NewConfig() + .Map(dest => dest.BookingNo, src => src.BOOKING_NO) + .Map(dest => dest.BillNo, src => src.MBL_NO) + .Map(dest => dest.OrigBillNo, src => src.ORIG_MBL_NO) + .Map(dest => dest.Carrier, src => src.CARRIER) + .Map(dest => dest.ChangeReasonNotes, src => src.CHANGE_REASON) + .Map(dest => dest.TaskPkId, src => src.TASK_ID) + .Map(dest => dest.Id, src => src.Id) + .Map(dest => dest.BookingId, src => src.BOOKING_ID) + .Map(dest => dest.GroupBatchNo, src => src.GROUP_BATCH_NO) + .Map(dest => dest.IsLast, src => src.IS_LAST); } } } diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TransPlanHasChange/TaskTransPlanHasChangeShowDto.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TransPlanHasChange/TaskTransPlanHasChangeShowDto.cs index a2e42e81..25105fc2 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TransPlanHasChange/TaskTransPlanHasChangeShowDto.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TransPlanHasChange/TaskTransPlanHasChangeShowDto.cs @@ -19,7 +19,7 @@ namespace DS.WMS.Core.TaskPlat.Dtos /// /// 业务主键 /// - public string PKId { get; set; } + public long Id { get; set; } /// diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/TransplanHasChange/ITaskTransPlanHasChangeService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/TransplanHasChange/ITaskTransPlanHasChangeService.cs new file mode 100644 index 00000000..740ff3e6 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/TransplanHasChange/ITaskTransPlanHasChangeService.cs @@ -0,0 +1,45 @@ +using DS.Module.Core; +using DS.WMS.Core.Op.Dtos; +using DS.WMS.Core.TaskPlat.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.TaskPlat.Interface +{ + /// + /// 运输计划变更 + /// + public interface ITaskTransPlanHasChangeService + { + /// + /// 通过任务主键获取货物运输计划已变更详情 + /// + /// 货物运输计划已变更任务主键 + /// 返回回执 + Task> GetInfoByTaskId(long taskPKId); + + /// + /// 检索对应的订舱订单并保存订舱ID + /// + /// 货物运输计划已变更任务主键 + /// 返回回执 + Task> SearchAndMarkBookingOrder(long taskPKId); + + /// + /// 自动转发 + /// + /// 货物运输计划已变更任务主键 + /// 返回回执 + Task AutoTranmitToCustomer(long taskPKId); + + /// + /// 发送邮件通知给客户 + /// + /// 货物运输计划已变更主键 + /// 返回回执 + Task SendEmailToCustomer(long taskPKId); + } +} diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TransplanHasChange/TaskTransPlanHasChangeService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TransplanHasChange/TaskTransPlanHasChangeService.cs new file mode 100644 index 00000000..3c274278 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TransplanHasChange/TaskTransPlanHasChangeService.cs @@ -0,0 +1,317 @@ +using DS.Module.Core; +using DS.Module.RedisModule; +using DS.Module.SqlSugar; +using DS.Module.UserModule; +using DS.WMS.Core.Code.Interface; +using DS.WMS.Core.Code.Method; +using DS.WMS.Core.Map.Interface; +using DS.WMS.Core.Map.Method; +using DS.WMS.Core.Sys.Interface; +using DS.WMS.Core.Sys.Method; +using DS.WMS.Core.TaskPlat.Dtos; +using DS.WMS.Core.TaskPlat.Entity; +using DS.WMS.Core.TaskPlat.Interface; +using Microsoft.Extensions.DependencyInjection; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Mapster; +using DS.Module.DjyServiceStatus; +using Microsoft.AspNetCore.Identity; +using DS.WMS.Core.Op.Interface; +using Masuit.Tools; +using DS.WMS.Core.Op.Dtos; +using DS.WMS.Core.Sys.Entity; +using HtmlAgilityPack; +using Microsoft.AspNetCore.Mvc; +using Amazon.Runtime.Internal.Util; +using Newtonsoft.Json; +using NLog; +using DS.Module.Core.Helpers; +using System.Text.Json.Nodes; +using LanguageExt.Pipes; +using DS.WMS.Core.Op.Entity; +using Org.BouncyCastle.Asn1.X9; +using DS.WMS.Core.Op.EDI; +using DS.WMS.Core.Sys.Dtos; +using DS.WMS.Core.Code.Dtos; + +namespace DS.WMS.Core.TaskPlat.Method +{ + /// + /// + /// + public class TaskTransPlanHasChangeService: ITaskTransPlanHasChangeService + { + private readonly IServiceProvider _serviceProvider; + private readonly ISqlSugarClient db; + private readonly IUser user; + private readonly ISaasDbService saasService; + private readonly ISeaExportService _seaExportService; + private readonly IConfigService _configService; + private readonly IUserService _userService; + + private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger(); + + const string EMAIL_API_URL = "email_api_url"; + + public TaskTransPlanHasChangeService(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + db = _serviceProvider.GetRequiredService(); + user = _serviceProvider.GetRequiredService(); + saasService = _serviceProvider.GetRequiredService(); + _seaExportService = _serviceProvider.GetRequiredService(); + _configService = _serviceProvider.GetRequiredService(); + _userService = _serviceProvider.GetRequiredService(); + } + + #region 通过任务主键获取货物运输计划已变更详情 + /// + /// 通过任务主键获取货物运输计划已变更详情 + /// + /// 货物运输计划已变更任务主键 + /// 返回回执 + public async Task> GetInfoByTaskId(long taskPKId) + { + TaskTransPlanHasChangeShowDto dto = new TaskTransPlanHasChangeShowDto(); + + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + + var queryList = await tenantDb.Queryable() + .InnerJoin((a, b) => a.Id == b.TASK_ID) + .Where((a, b) => a.Id == taskPKId) + .Select((a, b) => new { Base = a, Plan = b }) + .ToListAsync(); + + //任务主键{taskPkId}无法获取业务信息 + if (queryList.Count == 0) + throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseInfoFromTaskIdNull)), taskPKId)); + + var parentIdList = queryList.Select(a => a.Plan.Id).ToList(); + + var detailList = await tenantDb.Queryable() + .Where(a => parentIdList.Contains(a.P_ID)).ToListAsync(); + + if (detailList.Count > 0) + { + var ctnList = detailList.Where(a => a.COLUMN_TYPE.Equals("CTN", StringComparison.OrdinalIgnoreCase)).ToList(); + + dto.ContaNoList = ctnList.Select(a => a.CONTA_NO).ToList(); + + var fromList = detailList.Where(a => !string.IsNullOrWhiteSpace(a.PLAN_TYPE) && a.PLAN_TYPE.Equals("FROM", StringComparison.OrdinalIgnoreCase)).ToList(); + + dto.From = new TaskTransportPlanHasChangeDetailShow + { + portList = new List(), + dateList = new List(), + vesselList = new List() + }; + + dto.From.portList = fromList.Where(a => !string.IsNullOrWhiteSpace(a.COLUMN_TYPE) && a.COLUMN_TYPE.Equals("PORT", StringComparison.OrdinalIgnoreCase)) + .Select(a => + { + return new TaskTransPlanHasChangePortShow + { + Indx = a.SORT_NO.HasValue ? a.SORT_NO.Value : 0, + PortName = a.PORTLOAD, + CountryCode = a.PORTLOAD_COUNTRY, + TerminalName = a.PORTLOAD_TERMINAL, + IsRemoved = a.IS_REMOVED.HasValue ? a.IS_REMOVED.Value : false + }; + }).OrderBy(a => a.Indx).ToList(); + + dto.From.dateList = fromList.Where(a => !string.IsNullOrWhiteSpace(a.COLUMN_TYPE) && a.COLUMN_TYPE.Equals("EATD", StringComparison.OrdinalIgnoreCase)) + .Select(a => + { + return new TaskTransPlanHasChangeDateShow + { + Indx = a.SORT_NO.HasValue ? a.SORT_NO.Value : 0, + DateVal = a.ETD, + IsRemoved = a.IS_REMOVED.HasValue ? a.IS_REMOVED.Value : false + }; + }).OrderBy(a => a.Indx).ToList(); + + dto.From.vesselList = fromList.Where(a => !string.IsNullOrWhiteSpace(a.COLUMN_TYPE) && a.COLUMN_TYPE.Equals("VESSEL", StringComparison.OrdinalIgnoreCase)) + .Select(a => + { + return new TaskTransPlanHasChangeVesselShow + { + Indx = a.SORT_NO.HasValue ? a.SORT_NO.Value : 0, + Vessel = a.VESSEL, + Voyno = a.VOYNO, + Flag = a.SHIP_FLAG, + IsRemoved = a.IS_REMOVED.HasValue ? a.IS_REMOVED.Value : false + }; + }).OrderBy(a => a.Indx).ToList(); + + var toList = detailList.Where(a => !string.IsNullOrWhiteSpace(a.PLAN_TYPE) && a.PLAN_TYPE.Equals("TO", StringComparison.OrdinalIgnoreCase)).ToList(); + + dto.To = new TaskTransportPlanHasChangeDetailShow + { + portList = new List(), + dateList = new List(), + vesselList = new List() + }; + + dto.To.portList = toList.Where(a => !string.IsNullOrWhiteSpace(a.COLUMN_TYPE) && a.COLUMN_TYPE.Equals("PORT", StringComparison.OrdinalIgnoreCase)) + .Select(a => + { + return new TaskTransPlanHasChangePortShow + { + Indx = a.SORT_NO.HasValue ? a.SORT_NO.Value : 0, + PortName = a.PORTDISCHARGE, + CountryCode = a.PORTDISCHARGE_COUNTRY, + TerminalName = a.PORTDISCHARGE_TERMINAL, + IsRemoved = a.IS_REMOVED.HasValue ? a.IS_REMOVED.Value : false + }; + }).OrderBy(a => a.Indx).ToList(); + + dto.To.dateList = toList.Where(a => !string.IsNullOrWhiteSpace(a.COLUMN_TYPE) && a.COLUMN_TYPE.Equals("EATD", StringComparison.OrdinalIgnoreCase)) + .Select(a => + { + return new TaskTransPlanHasChangeDateShow + { + Indx = a.SORT_NO.HasValue ? a.SORT_NO.Value : 0, + DateVal = a.ETA, + IsRemoved = a.IS_REMOVED.HasValue ? a.IS_REMOVED.Value : false + }; + }).OrderBy(a => a.Indx).ToList(); + + dto.To.vesselList = toList.Where(a => !string.IsNullOrWhiteSpace(a.COLUMN_TYPE) && a.COLUMN_TYPE.Equals("VESSEL", StringComparison.OrdinalIgnoreCase)) + .Select(a => + { + return new TaskTransPlanHasChangeVesselShow + { + Indx = a.SORT_NO.HasValue ? a.SORT_NO.Value : 0, + Vessel = a.VESSEL, + Voyno = a.VOYNO, + Flag = a.SHIP_FLAG, + IsRemoved = a.IS_REMOVED.HasValue ? a.IS_REMOVED.Value : false + }; + }).OrderBy(a => a.Indx).ToList(); + } + + return DataResult.Success(dto); + } + #endregion + + #region 检索对应的订舱订单并保存订舱ID + /// + /// 检索对应的订舱订单并保存订舱ID + /// + /// 货物运输计划已变更任务主键 + /// 返回回执 + public async Task> SearchAndMarkBookingOrder(long taskPKId) + { + SeaExportOrderExtension orderInfo = null; + try + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + + var queryList = await tenantDb.Queryable() + .InnerJoin((a, b) => a.Id == b.TASK_ID) + .Where((a, b) => a.Id == taskPKId) + .Select((a, b) => new { Base = a, Cut = b }) + .ToListAsync(); + + //任务主键{taskPkId}无法获取业务信息 + if (queryList.Count == 0) + throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseInfoFromTaskIdNull)), taskPKId)); + + string mblNo = queryList.FirstOrDefault().Base.MBL_NO; + + var orderRlt = await _seaExportService.SearchOrderInfo(mblNo); + + if (!orderRlt.Succeeded) + { + // 提单号 {0} 检索海运出口订单失败 + throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseSearchOrderFailMBLNo)), mblNo)); + + } + + orderInfo = orderRlt.Data; + + foreach (var item in queryList.Select(a => a.Cut).ToList()) + { + item.BOOKING_ID = orderInfo.currOrder.Id; + + item.UpdateTime = DateTime.Now; + item.UpdateBy = long.Parse(user.UserId); + item.UpdateUserName = user.UserName; + + tenantDb.Updateable(item).UpdateColumns(x => new + { + x.BOOKING_ID, + x.UpdateTime, + x.UpdateBy, + x.UpdateUserName + }).ExecuteCommand(); + } + + } + catch (Exception ex) + { + Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} 检索货物运输计划已变更订舱记录 处理异常,原因:{ex.Message}"); + + return DataResult.FailedData(orderInfo, $"检索失败,原因:{ex.Message}", MultiLanguageConst.Operation_Failed); + } + + return DataResult.Success(orderInfo); + } + #endregion + + #region 自动转发 + /// + /// 自动转发 + /// + /// 货物运输计划已变更任务主键 + /// 返回回执 + public async Task AutoTranmitToCustomer(long taskPKId) + { + SeaExportOrderExtension orderInfo = null; + + try + { + var queryRlt = await SearchAndMarkBookingOrder(taskPKId); + + if (!queryRlt.Succeeded) + { + throw new Exception(queryRlt.Message); + } + + orderInfo = queryRlt.Data; + + //如果没有配置批量,则按单票发送邮件 + var rlt = await SendEmailToCustomer(taskPKId); + + Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} 推送邮件完成,结果:{JsonConvert.SerializeObject(rlt)}"); + + } + catch (Exception ex) + { + Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} 自动更新订单的截单日期并转发失败异常,原因:{ex.Message}"); + + return DataResult.Failed($"自动更新订单的截单日期并转发失败,原因:{ex.Message}", MultiLanguageConst.Operation_Failed); + } + + return DataResult.Successed(string.Empty, MultiLanguageConst.OperationSuccess); + } + #endregion + + #region 发送邮件通知给客户 + /// + /// 发送邮件通知给客户 + /// + /// 货物运输计划已变更主键 + /// 返回回执 + public async Task SendEmailToCustomer(long taskPKId) + { + return null; + } + #endregion + } +} diff --git a/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskTransPlanHasChangeController.cs b/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskTransPlanHasChangeController.cs new file mode 100644 index 00000000..514f6715 --- /dev/null +++ b/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskTransPlanHasChangeController.cs @@ -0,0 +1,77 @@ +using DS.Module.Core; +using DS.WMS.Core.Op.Dtos; +using DS.WMS.Core.TaskPlat.Dtos; +using DS.WMS.Core.TaskPlat.Interface; +using Microsoft.AspNetCore.Mvc; + +namespace DS.WMS.TaskApi.Controllers +{ + /// + /// 货物运输计划已变更 + /// + public class TaskTransPlanHasChangeController : ApiController + { + private readonly ITaskTransPlanHasChangeService _taskTransPlanHasChangeService; + + /// + /// + /// + /// + public TaskTransPlanHasChangeController(ITaskTransPlanHasChangeService taskTransPlanHasChangeService) + { + _taskTransPlanHasChangeService = taskTransPlanHasChangeService; + } + + #region 通过任务主键获取货物运输计划已变更详情 + /// + /// 通过任务主键获取货物运输计划已变更详情 + /// + /// 货物运输计划已变更任务主键 + /// 返回回执 + [HttpGet("GetInfoByTaskId")] + public async Task> GetInfoByTaskId(long taskPKId) + { + return await _taskTransPlanHasChangeService.GetInfoByTaskId(taskPKId); + } + #endregion + + #region 检索对应的订舱订单并保存订舱ID + /// + /// 检索对应的订舱订单并保存订舱ID + /// + /// 货物运输计划已变更任务主键 + /// 返回回执 + [HttpGet("SearchAndMarkBookingOrder")] + public async Task> SearchAndMarkBookingOrder(long taskPKId) + { + return await _taskTransPlanHasChangeService.SearchAndMarkBookingOrder(taskPKId); + } + #endregion + + #region 自动转发 + /// + /// 自动转发 + /// + /// 货物运输计划已变更任务主键 + /// 返回回执 + [HttpGet("AutoTranmitToCustomer")] + public async Task AutoTranmitToCustomer(long taskPKId) + { + return await _taskTransPlanHasChangeService.AutoTranmitToCustomer(taskPKId); + } + #endregion + + #region 发送邮件通知给客户 + /// + /// 发送邮件通知给客户 + /// + /// 货物运输计划已变更主键 + /// 返回回执 + [HttpGet("SendEmailToCustomer")] + public async Task SendEmailToCustomer(long taskPKId) + { + return await _taskTransPlanHasChangeService.SendEmailToCustomer(taskPKId); + } + #endregion + } +}