diff --git a/Myshipping.Application/Entity/BookingTruck.cs b/Myshipping.Application/Entity/BookingTruck.cs index 0d579e52..d848dd80 100644 --- a/Myshipping.Application/Entity/BookingTruck.cs +++ b/Myshipping.Application/Entity/BookingTruck.cs @@ -115,7 +115,7 @@ namespace Myshipping.Application.Entity /// 工厂ID /// [Description("工厂ID")] - public string FactoryId { get; set; } + public Nullable FactoryId { get; set; } /// /// 工厂代码 /// @@ -200,7 +200,7 @@ namespace Myshipping.Application.Entity /// 调度ID /// [Description("调度ID")] - public string DispatcherId { get; set; } + public Nullable DispatcherId { get; set; } /// /// 调度名称 /// diff --git a/Myshipping.Application/Service/BookingTruck/BookingTruckService.cs b/Myshipping.Application/Service/BookingTruck/BookingTruckService.cs index 414594c8..18818075 100644 --- a/Myshipping.Application/Service/BookingTruck/BookingTruckService.cs +++ b/Myshipping.Application/Service/BookingTruck/BookingTruckService.cs @@ -32,16 +32,23 @@ namespace Myshipping.Application private readonly SqlSugarRepository _bookingTruckRepository; private readonly SqlSugarRepository _bookingTruckContaRepository; + private readonly SqlSugarRepository _bookingOrderRepository; + private readonly SqlSugarRepository _bookingCtnRepository; + public BookingTruckService(ISysCacheService cache, ILogger logger, SqlSugarRepository bookingTruckRepository, - SqlSugarRepository bookingTruckContaRepository) + SqlSugarRepository bookingTruckContaRepository, + SqlSugarRepository bookingOrderRepository, + SqlSugarRepository bookingCtnRepository) { _cache = cache; _logger = logger; _bookingTruckRepository = bookingTruckRepository; _bookingTruckContaRepository = bookingTruckContaRepository; + _bookingOrderRepository = bookingOrderRepository; + _bookingCtnRepository = bookingCtnRepository; } /// @@ -49,15 +56,266 @@ namespace Myshipping.Application /// /// 派车信息 /// 返回回执 + [HttpPost("/BookingTruck/Save")] public async Task Save(BookingTruckDto info) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); try { + BookingTruck entity = info.Adapt(); + + if(entity == null) + throw Oops.Oh($"派车信息不能为空"); + + List entityCtnList = info.ContaList.Adapt>(); + + if (entity.Id == 0) + { + _bookingTruckRepository.Insert(entity); + + if (entityCtnList.Count > 0) + { + entityCtnList.ForEach(async ctn => + { + ctn.TruckId = entity.Id; + + await _bookingTruckContaRepository.InsertAsync(ctn); + }); + } + } + else + { + await _bookingTruckRepository.AsUpdateable(entity).IgnoreColumns(it => new + { + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName, + it.IsDeleted, + it.BookingId, + it.TruckId, + it.TruckName, + it.TruckCode, + }).ExecuteCommandAsync(); + + if (entityCtnList.Count > 0) + { + entityCtnList.ForEach(async ctn => + { + ctn.TruckId = entity.Id; + + await _bookingTruckContaRepository.AsUpdateable(ctn).IgnoreColumns(it => new + { + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName, + it.IsDeleted, + }).ExecuteCommandAsync(); + }); + } + } + + result.succ = true; + result.msg = "保存成功"; + result.ext = entity.Id; + } + catch (Exception ex) + { + result.succ = false; + result.msg = $"保存派车异常,原因:{ex.Message}"; + } + + return result; + } + + /// + /// 获取派车详情 + /// + /// 派车主键 + /// 返回回执 + [HttpGet("/BookingTruck/GetInfo")] + public async Task GetInfo(long id) + { + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + try + { + var truckOrder = _bookingTruckRepository.AsQueryable().First(a => a.Id == id); + + if (truckOrder == null) + throw Oops.Oh($"派车主键{id}无法获取业务信息"); + var truckCtnList = _bookingTruckContaRepository.AsQueryable().Where(a => a.TruckId == id).ToList(); + + BookingTruckShowDto model = truckOrder.Adapt(); + + if (truckCtnList.Count > 0) + model.ContaList = truckCtnList.Adapt>(); + + result.succ = true; + result.ext = model; + + } + catch (Exception ex) + { + result.succ = false; + result.msg = $"获取派车详情异常,原因:{ex.Message}"; } - catch(Exception ex) + + return result; + } + + /// + /// 订舱生成派车初始信息 + /// + /// 订舱主键 + /// 返回派车初始信息 + [HttpGet("/BookingTruck/InitFromBookingOrder")] + public async Task InitFromBookingOrder(long bookingId) + { + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + try + { + var model = InnerCreateTruckFromBookingOrder(bookingId); + + result.succ = true; + result.ext = model; + } + catch (Exception ex) + { + result.succ = false; + result.msg = $"订舱生成派车初始信息异常,原因:{ex.Message}"; + } + + return result; + } + + private BookingTruckDto InnerCreateTruckFromBookingOrder(long bookingId) + { + BookingTruckDto model = null; + + //取订舱主信息 + var orderInfo = _bookingOrderRepository.AsQueryable() + .First(a => a.Id == bookingId); + + if (orderInfo == null) + throw Oops.Oh($"订舱主键{bookingId}无法获取业务信息"); + + model = new BookingTruckDto(); + + model.YARDID = orderInfo.YARDID; + model.YARD = orderInfo.YARD; + model.ClosingTime = orderInfo.CLOSINGDATE; + model.InYardID = orderInfo.YARDID; + model.InYard = orderInfo.YARD; + + model.FromName = UserManager.Name; + model.FromTel = UserManager.TEl; + model.FromMail = UserManager.Email; + + if (orderInfo.KGS.HasValue) + { + //计算总吨数 + model.KGS = Math.Round(orderInfo.KGS.Value / 1000m, 3); + } + + //取订舱箱列表 + var ctnList = _bookingCtnRepository.AsQueryable() + .Where(a => a.BILLID == bookingId).ToList(); + + if (ctnList.Count > 0) + { + model.ContaList = new List(); + + ctnList.ForEach(b => + { + if (b.CTNNUM == 1) + { + model.ContaList.Add(new BookingTruckCtnDto + { + CTNCODE = b.CTNCODE, + CTNALL = b.CTNALL, + KGS = b.KGS, + PKGS = b.PKGS, + CBM = b.CBM, + TAREWEIGHT = b.TAREWEIGHT, + CNTRNO = b.CNTRNO, + KINDPKGS = b.KINDPKGS, + SEALNO = b.SEALNO, + TEU = b.TEU, + CTNNUM = b.CTNNUM, + }); + } + else + { + for (int i = 0; i < b.CTNNUM; i++) + { + model.ContaList.Add(new BookingTruckCtnDto + { + CTNCODE = b.CTNCODE, + CTNALL = b.CTNALL, + KGS = b.KGS, + PKGS = b.PKGS, + CBM = b.CBM, + TAREWEIGHT = b.TAREWEIGHT, + CNTRNO = b.CNTRNO, + KINDPKGS = b.KINDPKGS, + SEALNO = b.SEALNO, + TEU = b.TEU, + CTNNUM = b.CTNNUM, + }); + } + } + }); + } + + return model; + } + + /// + /// 引入订舱详情生成派车信息 + /// + /// 订舱主键 + /// 返回派车初始信息 + [HttpGet("/BookingTruck/PullInBookingOrder")] + public async Task PullInBookingOrder(long bookingId) + { + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + try + { + var model = InnerCreateTruckFromBookingOrder(bookingId); + + result.succ = true; + result.ext = model; + } + catch (Exception ex) + { + result.succ = false; + result.msg = $"引入订舱详情生成派车信息异常,原因:{ex.Message}"; + } + + return result; + } + + /// + /// 引入订舱集装箱详情生成派车信息 + /// + /// 订舱主键 + /// 返回派车集装箱初始信息 + [HttpGet("/BookingTruck/PullInBookingOrderConta")] + public async Task PullInBookingOrderConta(long bookingId) + { + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + try + { + + } + catch (Exception ex) { } @@ -70,6 +328,7 @@ namespace Myshipping.Application /// /// 派车信息 /// 返回回执 + [HttpPost("/BookingTruck/Submit")] public async Task Submit(BookingTruckDto info) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); @@ -91,7 +350,8 @@ namespace Myshipping.Application /// /// 派车主键组 /// 返回回执 - public async Task SubmitBatch(long[] ids) + [HttpPost("/BookingTruck/SubmitBatch")] + public async Task SubmitBatch([FromBody] long[] ids) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); @@ -112,6 +372,7 @@ namespace Myshipping.Application /// /// 派车主键 /// 返回回执 + [HttpGet("/BookingTruck/Cancel")] public async Task Cancel(long id) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); @@ -133,7 +394,7 @@ namespace Myshipping.Application /// /// 派车主键组 /// 返回回执 - public async Task CancelBatch(long[] ids) + public async Task CancelBatch([FromBody] long[] ids) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); @@ -154,6 +415,7 @@ namespace Myshipping.Application /// /// 派车主键 /// 返回回执 + [HttpGet("/BookingTruck/Print")] public async Task Print(long id) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); @@ -175,7 +437,8 @@ namespace Myshipping.Application /// /// 派车主键组 /// 返回回执 - public async Task SendDispatchBatch(long[] ids) + [HttpPost("/BookingTruck/SendDispatchBatch")] + public async Task SendDispatchBatch([FromBody] long[] ids) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); @@ -196,6 +459,7 @@ namespace Myshipping.Application /// /// 派车主键 /// 返回回执 + [HttpGet("/BookingTruck/CancelDispatch")] public async Task CancelDispatch(long id) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); @@ -217,7 +481,8 @@ namespace Myshipping.Application /// /// 派车主键组 /// 返回回执 - public async Task CancelDispatchBatch(long[] ids) + [HttpPost("/BookingTruck/CancelDispatchBatch")] + public async Task CancelDispatchBatch([FromBody] long[] ids) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); @@ -233,20 +498,8 @@ namespace Myshipping.Application return result; } - public async Task GetInfo(long id) - { - TaskManageOrderResultDto result = new TaskManageOrderResultDto(); - - try - { - - } - catch (Exception ex) - { - - } + - return result; - } + } } diff --git a/Myshipping.Application/Service/BookingTruck/Dtos/BookingTruckDto.cs b/Myshipping.Application/Service/BookingTruck/Dtos/BookingTruckDto.cs index 536753a8..88e73acf 100644 --- a/Myshipping.Application/Service/BookingTruck/Dtos/BookingTruckDto.cs +++ b/Myshipping.Application/Service/BookingTruck/Dtos/BookingTruckDto.cs @@ -99,7 +99,7 @@ namespace Myshipping.Application /// /// 工厂ID /// - public string FactoryId { get; set; } + public Nullable FactoryId { get; set; } /// /// 工厂代码 /// @@ -167,7 +167,7 @@ namespace Myshipping.Application /// /// 调度ID /// - public string DispatcherId { get; set; } + public Nullable DispatcherId { get; set; } /// /// 调度名称 /// diff --git a/Myshipping.Application/Service/BookingTruck/Dtos/BookingTruckShowDto.cs b/Myshipping.Application/Service/BookingTruck/Dtos/BookingTruckShowDto.cs index 0d83c5d7..c4a5cc7c 100644 --- a/Myshipping.Application/Service/BookingTruck/Dtos/BookingTruckShowDto.cs +++ b/Myshipping.Application/Service/BookingTruck/Dtos/BookingTruckShowDto.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Myshipping.Application.Service.BookingTruck.Dtos +namespace Myshipping.Application { /// /// @@ -94,7 +94,7 @@ namespace Myshipping.Application.Service.BookingTruck.Dtos /// /// 工厂ID /// - public string FactoryId { get; set; } + public Nullable FactoryId { get; set; } /// /// 工厂代码 /// @@ -162,7 +162,7 @@ namespace Myshipping.Application.Service.BookingTruck.Dtos /// /// 调度ID /// - public string DispatcherId { get; set; } + public Nullable DispatcherId { get; set; } /// /// 调度名称 /// diff --git a/Myshipping.Application/Service/BookingTruck/Interface/IBookingTruckService.cs b/Myshipping.Application/Service/BookingTruck/Interface/IBookingTruckService.cs index 6a694255..fca13849 100644 --- a/Myshipping.Application/Service/BookingTruck/Interface/IBookingTruckService.cs +++ b/Myshipping.Application/Service/BookingTruck/Interface/IBookingTruckService.cs @@ -18,6 +18,28 @@ namespace Myshipping.Application /// 返回回执 Task Save(BookingTruckDto info); + /// + /// 订舱生成派车初始信息 + /// + /// 订舱主键 + /// 返回派车初始信息 + Task InitFromBookingOrder(long bookingId); + + + /// + /// 引入订舱详情生成派车信息 + /// + /// 订舱主键 + /// 返回派车初始信息 + Task PullInBookingOrder(long bookingId); + + /// + /// 引入订舱集装箱详情生成派车信息 + /// + /// 订舱主键 + /// 返回派车集装箱初始信息 + Task PullInBookingOrderConta(long bookingId); + /// /// 获取派车详情 ///