From 3cc75d1d8bc7dd1cab35d1b57766e65d90e57931 Mon Sep 17 00:00:00 2001 From: wet <1034391973@qq.com> Date: Mon, 26 Jun 2023 13:37:07 +0800 Subject: [PATCH] 1 --- .../BookingOrder/BookingOrderService.cs | 432 +++++++----------- 1 file changed, 155 insertions(+), 277 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index eff8f144..fa397385 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -999,14 +999,6 @@ namespace Myshipping.Application } - - - - - - - - if (input.Id == 0) { if (string.IsNullOrEmpty(entity.VOYNO)) @@ -1199,7 +1191,7 @@ namespace Myshipping.Application var Id = entity.Id; BookingOrderOutput ordOut = new BookingOrderOutput(); var main = await _rep.FirstOrDefaultAsync(u => u.Id == Id); - if (!string.IsNullOrEmpty(entity.MBLNO) || string.IsNullOrEmpty(entity.CUSTNO)) + if (!string.IsNullOrEmpty(entity.MBLNO) || !string.IsNullOrEmpty(entity.CUSTNO)) { #region 插入货运动态 @@ -1276,10 +1268,10 @@ namespace Myshipping.Application it.BOOKINGNO }).ExecuteCommandAsync(); } - + } } - + } else { @@ -1352,10 +1344,154 @@ namespace Myshipping.Application it.BOOKINGNO }).ExecuteCommandAsync(); } - + + } + } + + } + + + + #endregion + } + + if (string.IsNullOrEmpty(entity.MBLNO) || string.IsNullOrEmpty(entity.CUSTNO)) + { + + #region 取消货运动态 + //配置中所有的货物状态 + var config = _goodsStatusConfig.AsQueryable().Filter(null, true).Where(config => config.CreatedUserId == main.CreatedUserId).ToList().DistinctBy(x => x.StatusName).ToList(); + + if (config.Count() == 0) + { + _GoodsConfig.InitGoodsStatusConfig((long)main.CreatedUserId, main.CreatedUserName); + config = _goodsStatusConfig.AsQueryable().Filter(null, true).Where(config => config.CreatedUserId == main.CreatedUserId).ToList().DistinctBy(x => x.StatusName).ToList(); + if (string.IsNullOrEmpty(entity.CUSTNO)) + { + var Config = config.Where(x => x.SystemCode == "YDC").FirstOrDefault(); + if (Config != null) + { + _goodsStatus.Delete(x => x.bookingId == Id && x.ConfigId == Config.Id); + var ConfigId = _goodsStatus.Where(x => x.FinishTime.HasValue && x.bookingId == Id).OrderByDescending(x => x.FinishTime).Select(x => x.ConfigId).First(); + string BSSTATUSNAME = String.Empty; + if (ConfigId == null) + { + main.BSSTATUSNAME = ""; + } + else + { + BSSTATUSNAME = config.Where(x => x.Id == ConfigId).Select(x => x.StatusName).FirstOrDefault(); + main.BSSTATUSNAME = BSSTATUSNAME == null ? "" : BSSTATUSNAME; + } + await _rep.AsUpdateable(main).IgnoreColumns(it => new + { + it.ParentId, + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName, + it.TenantName, + it.IsDeleted, + it.BOOKINGNO + }).ExecuteCommandAsync(); + } + } + + if (string.IsNullOrEmpty(entity.MBLNO)) + { + var Config = config.Where(x => x.SystemCode == "YSDBC").FirstOrDefault(); + if (Config != null) + { + _goodsStatus.Delete(x => x.bookingId == Id && x.ConfigId == Config.Id); + var ConfigId = _goodsStatus.Where(x => x.FinishTime.HasValue && x.bookingId == Id).OrderByDescending(x => x.FinishTime).Select(x => x.ConfigId).First(); + string BSSTATUSNAME = String.Empty; + if (ConfigId == null) + { + main.BSSTATUSNAME = ""; + } + else + { + BSSTATUSNAME = config.Where(x => x.Id == ConfigId).Select(x => x.StatusName).FirstOrDefault(); + main.BSSTATUSNAME = BSSTATUSNAME == null ? "" : BSSTATUSNAME; + } + await _rep.AsUpdateable(main).IgnoreColumns(it => new + { + it.ParentId, + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName, + it.TenantName, + it.IsDeleted, + it.BOOKINGNO + }).ExecuteCommandAsync(); + } + } + + } + else + { + if (string.IsNullOrEmpty(entity.CUSTNO)) + { + var Config = config.Where(x => x.SystemCode == "YDC").FirstOrDefault(); + if (Config != null) + { + _goodsStatus.Delete(x => x.bookingId == Id && x.ConfigId == Config.Id); + var ConfigId = _goodsStatus.Where(x => x.FinishTime.HasValue && x.bookingId == Id).OrderByDescending(x => x.FinishTime).Select(x => x.ConfigId).First(); + string BSSTATUSNAME = String.Empty; + if (ConfigId == null) + { + main.BSSTATUSNAME = ""; + } + else + { + BSSTATUSNAME = config.Where(x => x.Id == ConfigId).Select(x => x.StatusName).FirstOrDefault(); + main.BSSTATUSNAME = BSSTATUSNAME == null ? "" : BSSTATUSNAME; + } + await _rep.AsUpdateable(main).IgnoreColumns(it => new + { + it.ParentId, + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName, + it.TenantName, + it.IsDeleted, + it.BOOKINGNO + }).ExecuteCommandAsync(); + } + } + if (string.IsNullOrEmpty(entity.MBLNO)) + { + var Config = config.Where(x => x.SystemCode == "YSDBC").FirstOrDefault(); + if (Config != null) + { + _goodsStatus.Delete(x => x.bookingId == Id && x.ConfigId == Config.Id); + var ConfigId = _goodsStatus.Where(x => x.FinishTime.HasValue && x.bookingId == Id).OrderByDescending(x => x.FinishTime).Select(x => x.ConfigId).First(); + string BSSTATUSNAME = String.Empty; + if (ConfigId == null) + { + main.BSSTATUSNAME = ""; + } + else + { + BSSTATUSNAME = config.Where(x => x.Id == ConfigId).Select(x => x.StatusName).FirstOrDefault(); + main.BSSTATUSNAME = BSSTATUSNAME == null ? "" : BSSTATUSNAME; + } + await _rep.AsUpdateable(main).IgnoreColumns(it => new + { + it.ParentId, + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName, + it.TenantName, + it.IsDeleted, + it.BOOKINGNO + }).ExecuteCommandAsync(); } } - + } @@ -1363,6 +1499,8 @@ namespace Myshipping.Application #endregion } + + if (main != null) { ordOut = main.Adapt(); @@ -1447,113 +1585,7 @@ namespace Myshipping.Application } - #region 废弃代码 - - //[HttpPost("/BookingOrder/AddOrUpdate")] - //public async Task AddOrUpdate(BookingOrderDto Dto) - //{ - // if (Dto == null) - // { - // throw Oops.Bah("请传入正常数据!"); - // } - - // if (Dto.Id == 0) - // { - // return await Add(Dto); - // } - // else - // { - // await Update(Dto); - // return Dto.Id; - // } - //} - - ///// - ///// 增加订舱 - ///// - ///// - ///// - //[SqlSugarUnitOfWork] - //[HttpPost("/BookingOrder/Add")] - //public async Task Add(BookingOrderDto input) - //{ - // JsonUtil.PropToUpper(input, "ORDNO", "BSSTATUS", "YARDID", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME"); - // var ms = JsonUtil.TrimFields(input); - // if (!string.IsNullOrEmpty(ms)) - // { - // throw Oops.Bah(ms); - // } - // if (input.ctnInputs != null) - // { - // var groupList = input.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}"); - // input.CNTRTOTAL = string.Join(" / ", groupList); - // } - // if (!string.IsNullOrWhiteSpace(input.MBLNO)) - // { - // var et = await _rep.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == input.HBLNO && x.ParentId == input.ParentId).FirstAsync(); - // if (et != null) - // { - - // throw Oops.Bah("当前提单号已存在,请勿重复录入!"); - - // } - // } - - - // var entity = input.Adapt(); - // entity.BOOKINGNO = Yitter.IdGenerator.YitIdHelper.NextId().ToString(); - // //entity.TOTALNO = NumberToUpper.ToUpper(entity.PKGS == null ? 0 : entity.PKGS); - // await _rep.InsertAsync(entity); - // if (input.ctnInputs != null) - // { - // foreach (var item in input.ctnInputs) - // { - // var ctnentity = item.Adapt(); - // ctnentity.BILLID = entity.Id; - // await _repCtn.InsertAsync(ctnentity); - - // //这里保存有可能没有添加多品名,所有箱下没有货物信息 - // if (item.ctnDetailInputs != null) - // { - // foreach (var it in item.ctnDetailInputs) - // { - // var ctndetail = it.Adapt(); - // ctndetail.CTNID = ctnentity.Id; - // await _ctndetailrep.InsertAsync(ctndetail); - // } - // } - // } - // } - - // if (input.BookingEDIExt != null) - // { - // //写入EDI扩展 - // var ediExtEntity = input.BookingEDIExt.Adapt(); - - // ediExtEntity.BookingId = entity.Id; - - // await _bookingEDIExt.InsertAsync(ediExtEntity); - // } - - // ////添加booking日志 - // await _bookinglog.InsertAsync(new BookingLog - // { - // Type = "Add", - // BookingId = entity.Id, - // TenantId = Convert.ToInt64(UserManager.TENANT_ID), - // CreatedTime = DateTime.Now, - // CreatedUserId = UserManager.UserId, - // CreatedUserName = UserManager.Name - // }); - - // //////分单不调用 - // //if (!string.IsNullOrWhiteSpace(input.YARDID) && !string.IsNullOrWhiteSpace(input.YARD) && !string.IsNullOrWhiteSpace(input.MBLNO)) - // //{ - // // await SendTrace(entity.Id.ToString(), entity.YARDID, entity.YARD, entity.MBLNO); - // //} - // return entity.Id; - //} - #endregion + /// /// 删除订舱 /// @@ -1598,7 +1630,7 @@ namespace Myshipping.Application await _repCtn.UpdateAsync(x => x.BILLID == Id, x => new BookingCtn { IsDeleted = true }); await _ctndetailrep.UpdateAsync(x => ctnlist.Contains((long)x.CTNID), x => new BookingCtnDetail { IsDeleted = true }); await _rep.UpdateAsync(x => x.Id == Id, x => new BookingOrder { IsDeleted = true }); - await _bookingEDIExt.UpdateAsync(x => x.BookingId == Id&&x.IsDeleted==false, x => new BookingEDIExt { IsDeleted = true }); + await _bookingEDIExt.UpdateAsync(x => x.BookingId == Id && x.IsDeleted == false, x => new BookingEDIExt { IsDeleted = true }); _logger.LogInformation(Id + "删除成功!"); } @@ -1684,7 +1716,7 @@ namespace Myshipping.Application await _repCtn.UpdateAsync(x => x.BILLID == Id, x => new BookingCtn { IsDeleted = false }); await _ctndetailrep.UpdateAsync(x => ctnlist.Contains((long)x.CTNID), x => new BookingCtnDetail { IsDeleted = false }); await _rep.UpdateAsync(x => x.Id == Id, x => new BookingOrder { IsDeleted = false }); - await _bookingEDIExt.UpdateAsync(x => x.BookingId == Id&&x.IsDeleted==true, x => new BookingEDIExt { IsDeleted = false }); + await _bookingEDIExt.UpdateAsync(x => x.BookingId == Id && x.IsDeleted == true, x => new BookingEDIExt { IsDeleted = false }); List list = new List(); list.Add(Id); var itemcode = _cache.GetAllTenantParam().Result.Where(x => x.ParaCode == "BOOKING_DATA_PUSH" && x.TenantId == UserManager.TENANT_ID).Select(x => x.ItemCode).FirstOrDefault(); @@ -1743,161 +1775,7 @@ namespace Myshipping.Application } - #region 废弃代码 - ///// - ///// 更新订舱 - ///// - ///// - ///// - //[SqlSugarUnitOfWork] - //[HttpPost("/BookingOrder/Update")] - //public async Task Update(BookingOrderDto input) - //{ - - // JsonUtil.PropToUpper(input, "ORDNO", "BSSTATUS", "YARDID", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME"); - // JsonUtil.TrimFields(input); - // if (input.ctnInputs != null) - // { - // var groupList = input.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}"); - // input.CNTRTOTAL = string.Join(" / ", groupList); - // } - // var main = await _rep.AsQueryable().Filter(null, true).Where(x => x.Id == input.Id).FirstAsync(); - - // if (!string.IsNullOrWhiteSpace(input.MBLNO)) - // { - // var et = await _rep.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == input.HBLNO && x.ParentId == input.ParentId && x.Id != input.Id).FirstAsync(); - // if (et != null) - // { - - // throw Oops.Bah("当前提单号已存在,请勿重复录入!"); - - // } - // } - - - // var entity = input.Adapt(); - // //entity.TOTALNO = NumberToUpper.ToUpper(entity.PKGS == null ? 0 : entity.PKGS); - // await _rep.AsUpdateable(entity).IgnoreColumns(it => new - // { - // it.ParentId, - // it.TenantId, - // it.CreatedTime, - // it.CreatedUserId, - // it.CreatedUserName, - // it.TenantName, - // it.IsDeleted, - // it.BOOKINGNO - // }).ExecuteCommandAsync(); - // var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == input.Id).Select(x => x.Id).ToListAsync(); - // await _repCtn.DeleteAsync(x => x.BILLID == input.Id); - // await _ctndetailrep.DeleteAsync(x => ctnlist.Contains((long)x.CTNID)); - // if (input.ctnInputs != null) - // { - // foreach (var item in input.ctnInputs) - // { - // var ctnentity = item.Adapt(); - // ctnentity.BILLID = entity.Id; - // await _repCtn.InsertAsync(ctnentity); - // if (item.ctnDetailInputs != null) - // { - // foreach (var it in item.ctnDetailInputs) - // { - // var ctndetail = it.Adapt(); - // ctndetail.CTNID = ctnentity.Id; - // await _ctndetailrep.InsertAsync(ctndetail); - // } - // } - // } - // } - - // if (input.BookingEDIExt != null) - // { - // //检索EDI扩展 - // var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == input.Id); - - // if (ediExtEntity == null) - // { - // //写入EDI扩展 - // ediExtEntity = input.BookingEDIExt.Adapt(); - // ediExtEntity.BookingId = entity.Id; - - // await _bookingEDIExt.InsertAsync(ediExtEntity); - // } - // else - // { - // //更新EDI扩展 - // var currEdiExtEntity = input.BookingEDIExt.Adapt(); - - // currEdiExtEntity.Id = ediExtEntity.Id; - // currEdiExtEntity.BookingId = ediExtEntity.BookingId; - - // await _bookingEDIExt.AsUpdateable(currEdiExtEntity).IgnoreColumns(it => new - // { - // it.BookingId, - // it.TenantId, - // it.CreatedTime, - // it.CreatedUserId, - // it.CreatedUserName - // }).ExecuteCommandAsync(); - // } - // } - - - // bool flag = true; - // long bid = 0; - // foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(entity)) - // { - // string name = descriptor.Name; - // if (name == "TenantId" || name == "CreatedTime" || name == "UpdatedTime" || name == "CreatedUserId" || name == "CreatedUserName") - // { - // continue; - // } - // object value = descriptor.GetValue(entity); - // var oldvalue = main.GetType().GetProperty(name).GetValue(main, null); - - // if (name == "KGS" || name == "CBM") - // { - // if (Convert.ToDecimal(value) == Convert.ToDecimal(oldvalue)) - // { - // continue; - // } - // } - // string _oldvalue = oldvalue != null ? oldvalue.ToString() : ""; - // string _value = value != null ? value.ToString() : ""; - // if (_oldvalue != _value && !string.IsNullOrWhiteSpace(descriptor.Description)) - // { - // if (flag) - // { - // ////添加booking日志 - // bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog - // { - // Type = "Edit", - // BookingId = entity.Id, - // TenantId = Convert.ToInt64(UserManager.TENANT_ID), - // CreatedTime = DateTime.Now, - // CreatedUserId = UserManager.UserId, - // CreatedUserName = UserManager.Name - // }); - // flag = false; - // } - // await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail - // { - // PId = bid, - // Field = descriptor.Description, - // OldValue = _oldvalue, - // NewValue = _value, - // }); - // //if (descriptor.Name == "YARDID" || descriptor.Name == "YARD" || descriptor.Name == "MBLNO") - // //{ - // // if (!string.IsNullOrWhiteSpace(input.YARDID) && !string.IsNullOrWhiteSpace(input.YARD) && !string.IsNullOrWhiteSpace(input.MBLNO)) - // // { - // // await SendTrace(entity.Id.ToString(), entity.YARDID, entity.YARD, entity.MBLNO); - // // } - // //} - // } - // } - //} - #endregion + /// /// 获取订舱明细 ///