|
|
|
@ -26,15 +26,18 @@ namespace Myshipping.Core.Service
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<DjyCustomer> _rep;
|
|
|
|
|
private readonly SqlSugarRepository<DjyCustomerContact> _repContact;
|
|
|
|
|
private readonly SqlSugarRepository<DjyCustomerAddr> _repAddr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly ILogger<DjyCustomerService> _logger;
|
|
|
|
|
|
|
|
|
|
public DjyCustomerService(SqlSugarRepository<DjyCustomer> rep, SqlSugarRepository<DjyCustomerContact> repContact, ILogger<DjyCustomerService> logger)
|
|
|
|
|
public DjyCustomerService(SqlSugarRepository<DjyCustomer> rep, SqlSugarRepository<DjyCustomerContact> repContact, ILogger<DjyCustomerService> logger, SqlSugarRepository<DjyCustomerAddr> addrRepContact)
|
|
|
|
|
{
|
|
|
|
|
_rep = rep;
|
|
|
|
|
_repContact = repContact;
|
|
|
|
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_repAddr = addrRepContact;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -106,6 +109,12 @@ namespace Myshipping.Core.Service
|
|
|
|
|
var contactList = input.Contacts.Adapt<List<DjyCustomerContact>>();
|
|
|
|
|
contactList.ForEach(x => x.CustomerId = entity.Id);
|
|
|
|
|
await _repContact.InsertAsync(contactList);
|
|
|
|
|
|
|
|
|
|
//地址
|
|
|
|
|
var addrList = input.Contacts.Adapt<List<DjyCustomerAddr>>();
|
|
|
|
|
addrList.ForEach(x => x.CustomerId = entity.Id);
|
|
|
|
|
await _repAddr.InsertAsync(addrList);
|
|
|
|
|
|
|
|
|
|
return entity.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -148,6 +157,11 @@ namespace Myshipping.Core.Service
|
|
|
|
|
var contactList = input.Contacts.Adapt<List<DjyCustomerContact>>();
|
|
|
|
|
contactList.ForEach(x => x.CustomerId = entity.Id);
|
|
|
|
|
await _repContact.InsertAsync(contactList);
|
|
|
|
|
//地址
|
|
|
|
|
await _repAddr.DeleteAsync(x => x.CustomerId == input.Id);
|
|
|
|
|
var addrList = input.Contacts.Adapt<List<DjyCustomerAddr>>();
|
|
|
|
|
addrList.ForEach(x => x.CustomerId = entity.Id);
|
|
|
|
|
await _repAddr.InsertAsync(addrList);
|
|
|
|
|
return entity.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -167,6 +181,7 @@ namespace Myshipping.Core.Service
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await _repContact.DeleteAsync(x => x.CustomerId == input.Id);
|
|
|
|
|
await _repAddr.DeleteAsync(x => x.CustomerId == input.Id);
|
|
|
|
|
await _rep.DeleteAsync(entity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -188,6 +203,8 @@ namespace Myshipping.Core.Service
|
|
|
|
|
}
|
|
|
|
|
var custOut = cust.Adapt<DjyCustomerOutput>();
|
|
|
|
|
custOut.Contacts = _repContact.Where(x => x.CustomerId == input.Id).OrderBy(x => x.Sort).ToList().Adapt<List<DjyCustomerContactOutput>>();
|
|
|
|
|
custOut.Addrs = _repAddr.Where(x => x.CustomerId == input.Id).ToList().Adapt<List<DjyCustomerAddrInput>>();
|
|
|
|
|
|
|
|
|
|
return custOut;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -263,6 +280,9 @@ namespace Myshipping.Core.Service
|
|
|
|
|
var contactList = _repContact.AsQueryable()
|
|
|
|
|
.Where(a => custsArg.Contains(a.CustomerId.Value)).ToList();
|
|
|
|
|
|
|
|
|
|
var addrList = _repAddr.AsQueryable()
|
|
|
|
|
.Where(a => custsArg.Contains(a.CustomerId)).ToList();
|
|
|
|
|
|
|
|
|
|
list = list.GroupJoin(contactList, l => l.Id, r => r.CustomerId.Value, (l, r) =>
|
|
|
|
|
{
|
|
|
|
|
var curList = r.ToList();
|
|
|
|
@ -273,6 +293,21 @@ namespace Myshipping.Core.Service
|
|
|
|
|
return l;
|
|
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
if(addrList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
list = list.GroupJoin(addrList, l => l.Id, r => r.CustomerId, (l, r) =>
|
|
|
|
|
{
|
|
|
|
|
var curList = r.ToList();
|
|
|
|
|
|
|
|
|
|
if (curList.Count > 0)
|
|
|
|
|
l.Addrs = curList.Adapt<List<DjyCustomerAddrInput>>();
|
|
|
|
|
|
|
|
|
|
return l;
|
|
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|