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