From 10b525a1148b4f28ad9e2c394daeb5c11073bd50 Mon Sep 17 00:00:00 2001 From: wet <1034391973@qq.com> Date: Wed, 11 Jan 2023 15:47:30 +0800 Subject: [PATCH 1/7] excel --- .../BookingOrder/BookingOrderService.cs | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 2c912c4e..25e820a6 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -1786,7 +1786,9 @@ namespace Myshipping.Application - fileName = $"{dicCate.Value}_{order.MBLNO}_{DateTime.Now.Ticks}{fileType}";//名称 + //fileName = $"{dicCate.Value}_{order.MBLNO}_{DateTime.Now.Ticks}{fileType}";//名称 + + fileName = $"{order.MBLNO}_{DateTime.Now.Ticks}{fileType}";//名称 var opt = App.GetOptions().Path; var serverpath = Path.Combine(App.WebHostEnvironment.WebRootPath, opt);//服务器路径 if (!Directory.Exists(serverpath)) @@ -1825,31 +1827,30 @@ namespace Myshipping.Application if (entity.Where(x => x.Row == _row).Count() > 0) { - - - - //获取行 - var row = sheet.GetRow(_row); + ////获取行 + var row = sheet.GetRow(_row-1); if (row != null) { - for (int _cellNum = 0; _cellNum < entity.Max(x => x.Column); _cellNum++) + for (int _cellNum = 1; _cellNum <= entity.Max(x => x.Column); _cellNum++) { - if (entity.Where(x => x.Row == _row && x.Column == _cellNum + 1).Count() > 0) + if (entity.Where(x => x.Row == _row && x.Column == _cellNum).Count() > 0) { foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(order)) { - var name = entity.Where(x => x.Row == _row && x.Column == _cellNum + 1).Select(x => x.Field).FirstOrDefault(); + var name = entity.Where(x => x.Row == _row && x.Column == _cellNum).Select(x => x.Field).FirstOrDefault(); var _name = descriptor.Name.ToLower(); if (name == _name) { var value = descriptor.GetValue(order).ToString(); - if (_cellNum < row.Cells.Count()) + ICell cell= row.GetCell(_cellNum - 1); + + if (cell != null) { - row.Cells[_cellNum].SetCellValue(value); + row.Cells[_cellNum-1].SetCellValue(value); } else { - row.CreateCell(_cellNum).SetCellValue(value); + row.CreateCell(_cellNum-1).SetCellValue(value); } } } @@ -1860,20 +1861,20 @@ namespace Myshipping.Application { ////创建行 - var srow = NpoiExcelExportHelper._.CreateRow(sheet, _row); + var srow = NpoiExcelExportHelper._.CreateRow(sheet, _row-1); - for (int _cellNum = 0; _cellNum < entity.Max(x => x.Column); _cellNum++) + for (int _cellNum = 1; _cellNum <= entity.Max(x => x.Column); _cellNum++) { - if (entity.Where(x => x.Row == _row && x.Column == _cellNum + 1).Count() > 0) + if (entity.Where(x => x.Row == _row && x.Column == _cellNum).Count() > 0) { foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(order)) { - var name = entity.Where(x => x.Row == _row && x.Column == _cellNum + 1).Select(x => x.Field).FirstOrDefault(); + var name = entity.Where(x => x.Row == _row && x.Column == _cellNum).Select(x => x.Field).FirstOrDefault(); var _name = descriptor.Name.ToLower(); if (name == _name) { var value = descriptor.GetValue(order).ToString(); - srow.CreateCell(_cellNum).SetCellValue(value); + srow.CreateCell(_cellNum-1).SetCellValue(value); } } } From 8ea6c558d6c0152a0f19a7ed285785e00e4aeb3d Mon Sep 17 00:00:00 2001 From: wet <1034391973@qq.com> Date: Wed, 11 Jan 2023 16:04:07 +0800 Subject: [PATCH 2/7] displayName --- .../BookingPrintTemplate/BookingPrintTemplateService.cs | 4 ++-- Myshipping.Application/Service/DataSync/DataSyncService.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs b/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs index b7f967d0..66532a5f 100644 --- a/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs +++ b/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs @@ -395,7 +395,7 @@ namespace Myshipping.Application /// /// [HttpGet("/BookingPrintTemplate/GetPrinttemplateRightList")] - public async Task GetPrinttemplateRightList(long userId, string cateCode, string type,string name) + public async Task GetPrinttemplateRightList(long userId, string cateCode, string type,string displayName) { var userlist = await _repUser.AsQueryable().Filter(null, true).ToListAsync(); var list = await _repRight.AsQueryable().InnerJoin((d, t) => d.PrintTemplateId == t.Id && t.TenantId == UserManager.TENANT_ID). @@ -417,7 +417,7 @@ namespace Myshipping.Application UserName = "", }).ToListAsync(); - list = list.WhereIF(!string.IsNullOrWhiteSpace(cateCode), x => x.CateCode == cateCode).WhereIF(!string.IsNullOrWhiteSpace(name), x => x.DisplayName.StartsWith(name)). + list = list.WhereIF(!string.IsNullOrWhiteSpace(cateCode), x => x.CateCode == cateCode).WhereIF(!string.IsNullOrWhiteSpace(displayName), x => x.DisplayName.StartsWith(displayName)). WhereIF(!string.IsNullOrWhiteSpace(type), x => x.Type == type).ToList(); foreach (var item in list) { diff --git a/Myshipping.Application/Service/DataSync/DataSyncService.cs b/Myshipping.Application/Service/DataSync/DataSyncService.cs index a8da5995..3f04186b 100644 --- a/Myshipping.Application/Service/DataSync/DataSyncService.cs +++ b/Myshipping.Application/Service/DataSync/DataSyncService.cs @@ -149,7 +149,7 @@ namespace Myshipping.Application throw Oops.Bah("未录入创建人"); } - var user= _repUser.AsQueryable().Where(x => x.CreatedUserName == model.CreatedUserName).FirstAsync(); + var user= _repUser.AsQueryable().Where(x => x.CreatedUserName.Trim() == model.CreatedUserName.Trim()).FirstAsync(); From 7ac511ecb53ee17ae179006ce899cb1539f136b2 Mon Sep 17 00:00:00 2001 From: wet <1034391973@qq.com> Date: Wed, 11 Jan 2023 16:11:36 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E6=A8=A1=E7=B3=8A=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Myshipping.Application.xml | 19 ++++++++++++++++++- .../BookingPrintTemplateService.cs | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Myshipping.Application/Myshipping.Application.xml b/Myshipping.Application/Myshipping.Application.xml index 46bc84df..624560dc 100644 --- a/Myshipping.Application/Myshipping.Application.xml +++ b/Myshipping.Application/Myshipping.Application.xml @@ -11247,7 +11247,7 @@ - + 获取打印模板权限 @@ -15889,6 +15889,23 @@ 文件功能 (9原始) 返回结果 + + + 更新订舱的状态 + + 订舱主键 + 状态代码 + 状态名称 + + + + + 扣费 + + 任务信息 + 是否执行扣费 true-执行扣费 false-不执行扣费(主要是符合扣费条件但是由于超时没有得到准确回执) + 返回回执 + 获取订舱详情 diff --git a/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs b/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs index 66532a5f..94d22068 100644 --- a/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs +++ b/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs @@ -417,7 +417,7 @@ namespace Myshipping.Application UserName = "", }).ToListAsync(); - list = list.WhereIF(!string.IsNullOrWhiteSpace(cateCode), x => x.CateCode == cateCode).WhereIF(!string.IsNullOrWhiteSpace(displayName), x => x.DisplayName.StartsWith(displayName)). + list = list.WhereIF(!string.IsNullOrWhiteSpace(cateCode), x => x.CateCode == cateCode).WhereIF(!string.IsNullOrWhiteSpace(displayName), x => x.DisplayName.ToUpper().StartsWith(displayName.ToUpper())). WhereIF(!string.IsNullOrWhiteSpace(type), x => x.Type == type).ToList(); foreach (var item in list) { From 7b6de7c4a9078e034c4ceeea1f669fc3babd4585 Mon Sep 17 00:00:00 2001 From: wet <1034391973@qq.com> Date: Wed, 11 Jan 2023 17:45:25 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BookingOrder/BookingOrderService.cs | 20 ++++++++++-- .../Service/DataSync/DataSyncService.cs | 31 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index d81461c8..4629c439 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -494,7 +494,7 @@ namespace Myshipping.Application 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().Where(x => x.Id == input.Id).FirstAsync(); + var main = await _rep.AsQueryable().Filter(null,true).Where(x => x.Id == input.Id).FirstAsync(); 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) @@ -506,7 +506,14 @@ namespace Myshipping.Application var entity = input.Adapt(); //entity.TOTALNO = NumberToUpper.ToUpper(entity.PKGS == null ? 0 : entity.PKGS); - await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); + await _rep.AsUpdateable(entity).IgnoreColumns(it => new + { + it.ParentId, + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName + }).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)); @@ -762,7 +769,14 @@ namespace Myshipping.Application { var entity = _bookingremark.FirstOrDefault(x => x.Id == dto.Id); entity.Remark = dto.Remark; - await _bookingremark.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); + await _bookingremark.AsUpdateable(entity).IgnoreColumns(it => new + { + + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName + }).ExecuteCommandAsync(); } } diff --git a/Myshipping.Application/Service/DataSync/DataSyncService.cs b/Myshipping.Application/Service/DataSync/DataSyncService.cs index 3f04186b..2d6936ad 100644 --- a/Myshipping.Application/Service/DataSync/DataSyncService.cs +++ b/Myshipping.Application/Service/DataSync/DataSyncService.cs @@ -150,6 +150,37 @@ namespace Myshipping.Application } var user= _repUser.AsQueryable().Where(x => x.CreatedUserName.Trim() == model.CreatedUserName.Trim()).FirstAsync(); + if (user==null) { + throw Oops.Bah("未匹配到创建人"); + } + var order = await _rep.AsQueryable().Where(x => x.BSNO == model.BSNO).FirstAsync(); + if (order == null) + { + + JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME"); + JsonUtil.TrimFields(model); + if (model.ctnInputs != null) + { + var groupList = model.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}"); + model.CNTRTOTAL = string.Join(" / ", groupList); + } + var et = await _rep.Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.ParentId == 0).FirstAsync(); + if (et != null) + { + + throw Oops.Bah("当前提单号已存在,请勿重复录入!"); + + } + var entity = model.Adapt(); + + } + else { + + + + + + } From feb1c8c011e4a25dfa54d06f6fe3f741067c9579 Mon Sep 17 00:00:00 2001 From: wet <1034391973@qq.com> Date: Thu, 12 Jan 2023 09:27:54 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/DataSync/DataSyncService.cs | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/Myshipping.Application/Service/DataSync/DataSyncService.cs b/Myshipping.Application/Service/DataSync/DataSyncService.cs index 2d6936ad..9b6e7a7c 100644 --- a/Myshipping.Application/Service/DataSync/DataSyncService.cs +++ b/Myshipping.Application/Service/DataSync/DataSyncService.cs @@ -44,6 +44,7 @@ namespace Myshipping.Application private readonly ISysCacheService _cache; private readonly SqlSugarRepository _rep; private readonly SqlSugarRepository _repCtn; + private readonly SqlSugarRepository _ctndetailrep; private readonly SqlSugarRepository _repUser; private readonly SqlSugarRepository _repTenant; private readonly SqlSugarRepository _djycustomer; @@ -52,7 +53,7 @@ namespace Myshipping.Application public DataSyncService(ILogger logger, ISysCacheService cache, SqlSugarRepository rep, SqlSugarRepository repCtn, SqlSugarRepository repUser, SqlSugarRepository repTenant, SqlSugarRepository djycustomer, - SqlSugarRepository djycustomercontact, SqlSugarRepository vesselinfo) + SqlSugarRepository djycustomercontact, SqlSugarRepository vesselinfo, SqlSugarRepository ctndetailrep) { this._logger = logger; this._rep = rep; @@ -63,6 +64,7 @@ namespace Myshipping.Application this._djycustomer = djycustomer; this._djycustomercontact = djycustomercontact; this._vesselinfo = vesselinfo; + this._ctndetailrep = ctndetailrep; } @@ -149,7 +151,7 @@ namespace Myshipping.Application throw Oops.Bah("未录入创建人"); } - var user= _repUser.AsQueryable().Where(x => x.CreatedUserName.Trim() == model.CreatedUserName.Trim()).FirstAsync(); + var user= _repUser.AsQueryable().Where(x => x.CreatedUserName.Trim() == model.CreatedUserName.Trim()).FirstAsync(); if (user==null) { throw Oops.Bah("未匹配到创建人"); } @@ -172,6 +174,31 @@ namespace Myshipping.Application } var entity = model.Adapt(); + entity.CreatedUserId = user.Result.Id; + entity.CreatedUserName = user.Result.Name; + entity.CreatedTime = DateTime.Now; + await _rep.InsertAsync(entity); + if (model.ctnInputs != null) + { + foreach (var item in model.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); + } + } + } + } + } else { @@ -181,13 +208,6 @@ namespace Myshipping.Application } - - - - - - - return 0; } From d27ab7092efb48e77e119b9d33fd50164df8fa63 Mon Sep 17 00:00:00 2001 From: wet <1034391973@qq.com> Date: Thu, 12 Jan 2023 14:07:25 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E8=AE=A2=E8=88=B1=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/DataSync/DataSyncService.cs | 449 +++++++++++++++++- 1 file changed, 429 insertions(+), 20 deletions(-) diff --git a/Myshipping.Application/Service/DataSync/DataSyncService.cs b/Myshipping.Application/Service/DataSync/DataSyncService.cs index 9b6e7a7c..69246369 100644 --- a/Myshipping.Application/Service/DataSync/DataSyncService.cs +++ b/Myshipping.Application/Service/DataSync/DataSyncService.cs @@ -50,10 +50,14 @@ namespace Myshipping.Application private readonly SqlSugarRepository _djycustomer; private readonly SqlSugarRepository _djycustomercontact; private readonly SqlSugarRepository _vesselinfo; + private readonly SqlSugarRepository _bookingEDIExt; + private readonly SqlSugarRepository _bookinglog; + private readonly SqlSugarRepository _bookinglogdetail; public DataSyncService(ILogger logger, ISysCacheService cache, SqlSugarRepository rep, SqlSugarRepository repCtn, SqlSugarRepository repUser, SqlSugarRepository repTenant, SqlSugarRepository djycustomer, - SqlSugarRepository djycustomercontact, SqlSugarRepository vesselinfo, SqlSugarRepository ctndetailrep) + SqlSugarRepository djycustomercontact, SqlSugarRepository vesselinfo, SqlSugarRepository ctndetailrep + , SqlSugarRepository bookingEDIExt, SqlSugarRepository bookinglog, SqlSugarRepository bookinglogdetail) { this._logger = logger; this._rep = rep; @@ -65,6 +69,9 @@ namespace Myshipping.Application this._djycustomercontact = djycustomercontact; this._vesselinfo = vesselinfo; this._ctndetailrep = ctndetailrep; + this._bookingEDIExt = bookingEDIExt; + this._bookinglog = bookinglog; + this._bookinglogdetail = bookinglogdetail; } @@ -74,11 +81,12 @@ namespace Myshipping.Application /// /// /// - [HttpPost("/DataSync/SyncCustomer"),ApiUser(ApiCode= "SyncCustomer")] + [HttpPost("/DataSync/SyncCustomer"), ApiUser(ApiCode = "SyncCustomer")] public async Task SyncCustomer(DjyCustomerSyncDto model) { - - if (string.IsNullOrWhiteSpace(model.BSNO)) { + + if (string.IsNullOrWhiteSpace(model.BSNO)) + { throw Oops.Bah("BSNO未录入"); } var m = await _djycustomer.Where(x => x.BSNO == model.BSNO).FirstAsync(); @@ -91,10 +99,11 @@ namespace Myshipping.Application var contact = item.Adapt(); contact.CustomerId = entity.Id; await _djycustomercontact.InsertAsync(contact); - } + } } - else { - entity.Id=m.Id; + else + { + entity.Id = m.Id; await _djycustomer.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); await _djycustomercontact.DeleteAsync(x => x.CustomerId == entity.Id); foreach (var item in model.ContactList) @@ -121,7 +130,7 @@ namespace Myshipping.Application { throw Oops.Bah("BSNO未录入"); } - var m = await _vesselinfo.Where(x => x.BSNO==model.BSNO).FirstAsync(); + var m = await _vesselinfo.Where(x => x.BSNO == model.BSNO).FirstAsync(); var entity = model.Adapt(); entity.Vessel = model.Vessel.ToUpper().Trim(); if (m == null) @@ -141,24 +150,34 @@ namespace Myshipping.Application /// /// /// + [SqlSugarUnitOfWork] [HttpPost("/DataSync/SyncBooking"), ApiUser(ApiCode = "SyncBooking")] - public async Task SyncBooking(SyncBookingOrderDto model) + public async Task SyncBooking(SyncBookingOrderDto model) { - if (string.IsNullOrWhiteSpace(model.BSNO)) { + if (string.IsNullOrWhiteSpace(model.BSNO)) + { throw Oops.Bah("主单BSNO未录入"); } - if (string.IsNullOrWhiteSpace(model.CreatedUserName)) { + if (string.IsNullOrWhiteSpace(model.CreatedUserName)) + { throw Oops.Bah("未录入创建人"); } - var user= _repUser.AsQueryable().Where(x => x.CreatedUserName.Trim() == model.CreatedUserName.Trim()).FirstAsync(); - if (user==null) { + var user = _repUser.AsQueryable().Where(x => x.CreatedUserName.Trim() == model.CreatedUserName.Trim()).FirstAsync(); + if (user == null) + { throw Oops.Bah("未匹配到创建人"); } var order = await _rep.AsQueryable().Where(x => x.BSNO == model.BSNO).FirstAsync(); if (order == null) { + #region 新增 + if (string.IsNullOrWhiteSpace(model.MBLNO)) + { + throw Oops.Bah("请填写提单号!"); + } + JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME"); JsonUtil.TrimFields(model); if (model.ctnInputs != null) @@ -199,18 +218,408 @@ namespace Myshipping.Application } } + if (model.BookingEDIExt != null) + { + //写入EDI扩展 + var ediExtEntity = model.BookingEDIExt.Adapt(); + + ediExtEntity.BookingId = entity.Id; + + ediExtEntity.CreatedUserId = user.Result.Id; + ediExtEntity.CreatedUserName = user.Result.Name; + ediExtEntity.CreatedTime = DateTime.Now; + 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 = user.Result.Id, + CreatedUserName = "系统" + }); + + + //分单 + if (model.childrens != null) + { + foreach (var item in model.childrens) + { + if (string.IsNullOrWhiteSpace(item.MBLNO)) + { + throw Oops.Bah("请填写提单号!"); + } + if (string.IsNullOrWhiteSpace(item.HBLNO)) + { + throw Oops.Bah("请填写分提单号!"); + } + JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME"); + JsonUtil.TrimFields(item); + if (model.ctnInputs != null) + { + var groupList = item.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}"); + item.CNTRTOTAL = string.Join(" / ", groupList); + } + var fdet = await _rep.Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.ParentId == entity.Id).FirstAsync(); + if (fdet != null) + { + + throw Oops.Bah($"当前分单中提单号({item.MBLNO}_{item.HBLNO})已存在,请勿重复录入!"); + + } + var fdentity = item.Adapt(); + fdentity.CreatedUserId = user.Result.Id; + fdentity.CreatedUserName = user.Result.Name; + fdentity.CreatedTime = DateTime.Now; + fdentity.ParentId = entity.Id; + await _rep.InsertAsync(fdentity); + + if (item.ctnInputs != null) + { + foreach (var it in item.ctnInputs) + { + var ctnentity = item.Adapt(); + ctnentity.BILLID = fdentity.Id; + await _repCtn.InsertAsync(ctnentity); + + //这里保存有可能没有添加多品名,所有箱下没有货物信息 + if (it.ctnDetailInputs != null) + { + foreach (var dit in it.ctnDetailInputs) + { + var ctndetail = dit.Adapt(); + ctndetail.CTNID = ctnentity.Id; + await _ctndetailrep.InsertAsync(ctndetail); + } + } + } + + } + + + if (item.BookingEDIExt != null) + { + //写入EDI扩展 + var ediExtEntity = model.BookingEDIExt.Adapt(); + + ediExtEntity.BookingId = fdentity.Id; + ediExtEntity.CreatedUserId = user.Result.Id; + ediExtEntity.CreatedUserName = user.Result.Name; + ediExtEntity.CreatedTime = DateTime.Now; + await _bookingEDIExt.InsertAsync(ediExtEntity); + } + ////添加booking日志 + await _bookinglog.InsertAsync(new BookingLog + { + Type = "Add", + BookingId = fdentity.Id, + TenantId = Convert.ToInt64(UserManager.TENANT_ID), + CreatedTime = DateTime.Now, + CreatedUserId = user.Result.Id, + CreatedUserName = "系统" + }); + + } + } + return entity.Id; + #endregion } - else { - - - - - + else + { + + #region 编辑 + if (string.IsNullOrWhiteSpace(model.MBLNO)) + { + throw Oops.Bah("请填写提单号!"); + } + + JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME"); + JsonUtil.TrimFields(model); + + if (model.ctnInputs != null) + { + var groupList = model.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}"); + model.CNTRTOTAL = string.Join(" / ", groupList); + } + + var main = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == model.BSNO).FirstAsync(); + + + var et = await _rep.Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.BSNO != model.BSNO).FirstAsync(); + if (et != null) + { + throw Oops.Bah("当前提单号已存在,请勿重复录入!"); + } + var entity = model.Adapt(); + entity.Id = main.Id; + entity.UpdatedUserName = user.Result.Name; + entity.UpdatedUserId = user.Result.Id; + entity.UpdatedTime = DateTime.Now; + await _rep.AsUpdateable(entity).IgnoreColumns(it => new + { + it.ParentId, + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName + }).ExecuteCommandAsync(); + var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == main.Id).Select(x => x.Id).ToListAsync(); + await _repCtn.DeleteAsync(x => x.BILLID == main.Id); + await _ctndetailrep.DeleteAsync(x => ctnlist.Contains((long)x.CTNID)); + if (model.ctnInputs != null) + { + foreach (var item in model.ctnInputs) + { + var ctnentity = item.Adapt(); + ctnentity.BILLID = main.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 (model.BookingEDIExt != null) + { + //检索EDI扩展 + var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == main.Id); + + if (ediExtEntity == null) + { + //写入EDI扩展 + ediExtEntity = model.BookingEDIExt.Adapt(); + ediExtEntity.BookingId = main.Id; + ediExtEntity.CreatedUserId = user.Result.Id; + ediExtEntity.CreatedUserName = user.Result.Name; + ediExtEntity.CreatedTime = DateTime.Now; + await _bookingEDIExt.InsertAsync(ediExtEntity); + } + else + { + //更新EDI扩展 + var currEdiExtEntity = model.BookingEDIExt.Adapt(); + + currEdiExtEntity.Id = ediExtEntity.Id; + + 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 = user.Result.Id, + CreatedUserName = user.Result.Name + }); + flag = false; + } + await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail + { + PId = bid, + Field = descriptor.Description, + OldValue = _oldvalue, + NewValue = _value, + }); + + } + } + //分单 + if (model.childrens != null) + { + foreach (var item in model.childrens) + { + if (string.IsNullOrWhiteSpace(item.MBLNO)) + { + throw Oops.Bah("请填写提单号!"); + } + JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME"); + JsonUtil.TrimFields(item); + + if (item.ctnInputs != null) + { + var groupList = item.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}"); + item.CNTRTOTAL = string.Join(" / ", groupList); + } + + var fdmain = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == item.BSNO).FirstAsync(); + var fdet = await _rep.Where(x => x.MBLNO == item.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == item.HBLNO && x.BSNO != fdmain.BSNO).FirstAsync(); + if (fdet != null) + { + throw Oops.Bah($"当前提单号{fdet.MBLNO}_{fdet.HBLNO}已存在,请勿重复录入!"); + } + var fdentity = model.Adapt(); + fdentity.Id = fdmain.Id; + fdentity.UpdatedUserName = user.Result.Name; + fdentity.UpdatedUserId = user.Result.Id; + fdentity.UpdatedTime = DateTime.Now; + await _rep.AsUpdateable(fdentity).IgnoreColumns(it => new + { + it.ParentId, + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName + }).ExecuteCommandAsync(); + var fdctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == fdmain.Id).Select(x => x.Id).ToListAsync(); + await _repCtn.DeleteAsync(x => x.BILLID == fdmain.Id); + await _ctndetailrep.DeleteAsync(x => fdctnlist.Contains((long)x.CTNID)); + if (item.ctnInputs != null) + { + foreach (var it in model.ctnInputs) + { + var ctnentity = item.Adapt(); + ctnentity.BILLID = fdmain.Id; + await _repCtn.InsertAsync(ctnentity); + if (it.ctnDetailInputs != null) + { + foreach (var it_ in it.ctnDetailInputs) + { + var ctndetail = it_.Adapt(); + ctndetail.CTNID = ctnentity.Id; + await _ctndetailrep.InsertAsync(ctndetail); + } + } + } + } + + if (item.BookingEDIExt != null) + { + //检索EDI扩展 + var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == fdmain.Id); + + if (ediExtEntity == null) + { + //写入EDI扩展 + ediExtEntity = item.BookingEDIExt.Adapt(); + ediExtEntity.BookingId = fdmain.Id; + ediExtEntity.CreatedUserId = user.Result.Id; + ediExtEntity.CreatedUserName = user.Result.Name; + ediExtEntity.CreatedTime = DateTime.Now; + await _bookingEDIExt.InsertAsync(ediExtEntity); + } + else + { + //更新EDI扩展 + var currEdiExtEntity = model.BookingEDIExt.Adapt(); + + currEdiExtEntity.Id = ediExtEntity.Id; + + await _bookingEDIExt.AsUpdateable(currEdiExtEntity).IgnoreColumns(it => new + { + it.BookingId, + it.TenantId, + it.CreatedTime, + it.CreatedUserId, + it.CreatedUserName + }).ExecuteCommandAsync(); + } + } + + bool fdflag = true; + long fdbid = 0; + foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(fdentity)) + { + string name = descriptor.Name; + if (name == "TenantId" || name == "CreatedTime" || name == "UpdatedTime" || name == "CreatedUserId" || name == "CreatedUserName") + { + continue; + } + object value = descriptor.GetValue(fdentity); + var oldvalue = fdmain.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 (fdflag) + { + ////添加booking日志 + fdbid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog + { + Type = "Edit", + BookingId = fdentity.Id, + TenantId = Convert.ToInt64(UserManager.TENANT_ID), + CreatedTime = DateTime.Now, + CreatedUserId = user.Result.Id, + CreatedUserName = user.Result.Name, + }); + fdflag = false; + } + await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail + { + PId = fdbid, + Field = descriptor.Description, + OldValue = _oldvalue, + NewValue = _value, + }); + + } + } + + + + } + } + + + + #endregion } return 0; } - + From 14ff66310249833b1a29a9cad99580bd5ff1df42 Mon Sep 17 00:00:00 2001 From: wet <1034391973@qq.com> Date: Thu, 12 Jan 2023 14:09:50 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E8=AE=A2=E8=88=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Myshipping.Application/Service/DataSync/DataSyncService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Myshipping.Application/Service/DataSync/DataSyncService.cs b/Myshipping.Application/Service/DataSync/DataSyncService.cs index 69246369..1ad2cc87 100644 --- a/Myshipping.Application/Service/DataSync/DataSyncService.cs +++ b/Myshipping.Application/Service/DataSync/DataSyncService.cs @@ -614,10 +614,10 @@ namespace Myshipping.Application } - + return main.Id; #endregion } - return 0; + }