From a82adc164398a0f7a6d71d2bbdb3b1e7c18d98fc Mon Sep 17 00:00:00 2001 From: wanghaomei Date: Tue, 20 Dec 2022 13:51:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B7=BB=E5=8A=A0=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E8=81=94=E7=B3=BB=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BookingOrderContactService.cs | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrderContact/BookingOrderContactService.cs b/Myshipping.Application/Service/BookingOrderContact/BookingOrderContactService.cs index 931b618e..46079a97 100644 --- a/Myshipping.Application/Service/BookingOrderContact/BookingOrderContactService.cs +++ b/Myshipping.Application/Service/BookingOrderContact/BookingOrderContactService.cs @@ -10,6 +10,7 @@ using Myshipping.Application.Entity; using Microsoft.Extensions.Logging; using System.Collections.Generic; using Furion.FriendlyException; +using Myshipping.Core.Entity; namespace Myshipping.Application { @@ -20,11 +21,18 @@ namespace Myshipping.Application public class BookingOrderContactService : IBookingOrderContactService, IDynamicApiController, ITransient { private readonly SqlSugarRepository _rep; + private readonly SqlSugarRepository _repOrder; + private readonly SqlSugarRepository _repContact; private readonly ILogger _logger; - public BookingOrderContactService(SqlSugarRepository rep, ILogger logger) + public BookingOrderContactService(SqlSugarRepository rep, + SqlSugarRepository repOrder, + SqlSugarRepository repContact, + ILogger logger) { _rep = rep; + _repOrder = repOrder; + _repContact = repContact; _logger = logger; } @@ -41,7 +49,7 @@ namespace Myshipping.Application .WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name.Trim())) .WhereIF(!string.IsNullOrWhiteSpace(input.Tel), u => u.Tel.Contains(input.Tel.Trim())) .WhereIF(!string.IsNullOrWhiteSpace(input.Email), u => u.Email.Contains(input.Email.Trim())) - .WhereIF(input.BookingId!=0,u=>u.BookingId==input.BookingId) + .WhereIF(input.BookingId != 0, u => u.BookingId == input.BookingId) .ToPagedListAsync(input.PageNo, input.PageSize); return entities.XnPagedResult(); } @@ -111,16 +119,32 @@ namespace Myshipping.Application /// /// [HttpPost("/BookingOrderContact/savebatch"), SqlSugarUnitOfWork] - public async Task SaveBatch(List input,long bookingId) + public async Task SaveBatch(List input, long bookingId) { _rep.Delete(x => x.BookingId == bookingId); - if (input!=null&&input.Count>0) { + if (input != null && input.Count > 0) + { foreach (var item in input) { await _rep.InsertAsync(item.Adapt()); } } - + + //自动增加到该客户的联系人 + var bookObj = _repOrder.FirstOrDefault(x => x.Id == bookingId); + if (bookObj.CUSTOMERID.HasValue && bookObj.CUSTOMERID.Value > 0) + { + var dbContacts = _repContact.Where(x => x.CustomerId == bookObj.CUSTOMERID.Value).ToList(); + + //不存在的,增加 + foreach (var item in input.Where(x => dbContacts.Count(cc => cc.Name == x.Name) == 0)) + { + var ct = item.Adapt(); + ct.CustomerId = bookObj.CUSTOMERID.Value; + await _repContact.InsertAsync(ct); + } + + } } /////