客户相关导入优化

dev
嵇文龙 1 month ago
parent 123b85fbce
commit 5c5df78378

@ -123,13 +123,15 @@ public class ClientBankService : ServiceBase, IClientBankService
{ {
long userId = long.Parse(User.UserId); long userId = long.Parse(User.UserId);
DateTime dtNow = DateTime.Now; DateTime dtNow = DateTime.Now;
TenantDb.QueryFilter.Clear<IOrgId>();
TenantDb.QueryFilter.Clear<ISharedOrgId>();
var clientNames = list.Select(x => x.CompanyName).Distinct(); var clientNames = list.Select(x => x.CompanyName).Distinct();
var clients = await TenantDb.Queryable<InfoClient>().Where(x => clientNames.Contains(x.ShortName)) var clients = await TenantDb.Queryable<InfoClient>().Where(x => clientNames.Contains(x.ShortName) || clientNames.Contains(x.Description))
.Select(x => new .Select(x => new
{ {
x.Id, x.Id,
x.ShortName, x.ShortName,
x.Description,
x.OrgId x.OrgId
}).ToListAsync(); }).ToListAsync();
@ -137,40 +139,43 @@ public class ClientBankService : ServiceBase, IClientBankService
List<InfoClientBank> banks = new List<InfoClientBank>(list.Count); List<InfoClientBank> banks = new List<InfoClientBank>(list.Count);
foreach (var model in list) foreach (var model in list)
{ {
var client = clients.Find(x => x.ShortName == model.CompanyName); var clientList = clients.FindAll(x => x.ShortName == model.CompanyName || x.Description == model.CompanyName);
if (client == null) if (clientList.Count == 0)
{ {
sb.Append("," + model.CompanyName); sb.Append("," + model.CompanyName);
continue; continue;
} }
InfoClientBank bank = new() foreach (var item in clientList)
{
ClientId = client.Id,
OrgId = client.OrgId,
BankName = model.BankName,
Account = model.BankAccount,
BankAddress = model.BankAddress,
BankAccountNo = model.BankAccount,
IsInvoiceDefault = model.IsDefault,
CreateBy = userId,
CreateUserName = User.UserName,
CreateTime = dtNow,
InvoiceHeaders = []
};
if (model.Currency == "人民币")
bank.Currency = FeeCurrency.RMB_CODE;
else if (model.Currency == "美元")
bank.Currency = FeeCurrency.USD_CODE;
bank.InvoiceHeaders.Add(new InvoiceHeader
{ {
Header = model.InvoiceHeader, InfoClientBank bank = new()
AddressTel = model.InvoiceAddress + " " + model.InvoiceTel {
}); ClientId = item.Id,
OrgId = item.OrgId,
banks.Add(bank); BankName = model.BankName,
Account = model.BankAccount,
BankAddress = model.BankAddress,
BankAccountNo = model.BankAccount,
IsInvoiceDefault = model.IsDefault,
CreateBy = userId,
CreateUserName = User.UserName,
CreateTime = dtNow,
InvoiceHeaders = []
};
if (model.Currency == "人民币")
bank.Currency = FeeCurrency.RMB_CODE;
else if (model.Currency == "美元")
bank.Currency = FeeCurrency.USD_CODE;
bank.InvoiceHeaders.Add(new InvoiceHeader
{
Header = model.InvoiceHeader,
AddressTel = model.InvoiceAddress + " " + model.InvoiceTel
});
banks.Add(bank);
}
} }
if (sb.Length > 0) if (sb.Length > 0)

@ -100,45 +100,50 @@ public class ClientContactService : ServiceBase, IClientContactService
{ {
long userId = long.Parse(User.UserId); long userId = long.Parse(User.UserId);
DateTime dtNow = DateTime.Now; DateTime dtNow = DateTime.Now;
TenantDb.QueryFilter.Clear<IOrgId>();
TenantDb.QueryFilter.Clear<ISharedOrgId>();
var clientNames = list.Select(x => x.CompanyName).Distinct(); var clientNames = list.Select(x => x.CompanyName).Distinct();
var clients = await TenantDb.Queryable<InfoClient>().Where(x => clientNames.Contains(x.ShortName)) var clients = await TenantDb.Queryable<InfoClient>().Where(x => clientNames.Contains(x.ShortName) || clientNames.Contains(x.Description))
.Select(x => new .Select(x => new
{ {
x.Id, x.Id,
x.ShortName, x.ShortName,
x.Description,
x.OrgId x.OrgId
}).ToListAsync(); }).ToListAsync();
StringBuilder sb = new(); StringBuilder sb = new();
List<InfoClientContact> contacts = new List<InfoClientContact>(list.Count); List<InfoClientContact> contacts = new(list.Count * 2);
foreach (var model in list) foreach (var model in list)
{ {
var client = clients.Find(x => x.ShortName == model.CompanyName); var clientList = clients.FindAll(x => x.ShortName == model.CompanyName || x.Description == model.CompanyName);
if (client == null) if (clientList.Count == 0)
{ {
sb.Append("," + model.CompanyName); sb.Append("," + model.CompanyName);
continue; continue;
} }
InfoClientContact contact = new() foreach (var item in clientList)
{ {
ClientId = client.Id, InfoClientContact contact = new()
OrgId = client.OrgId, {
CreateBy = userId, ClientId = item.Id,
CreateUserName = User.UserName, OrgId = item.OrgId,
CreateTime = dtNow, CreateBy = userId,
Name = model.ContactName, CreateUserName = User.UserName,
EnName = model.ContactEnName, CreateTime = dtNow,
Job = model.Job, Name = model.ContactName,
Email = model.Email, EnName = model.ContactEnName,
Mobile = model.Mobile, Job = model.Job,
Tel = model.Tel, Email = model.Email,
QQ = model.QQ, Mobile = model.Mobile,
IsDefault = model.IsDefault Tel = model.Tel,
}; QQ = model.QQ,
IsDefault = model.IsDefault
contacts.Add(contact); };
contacts.Add(contact);
}
} }
if (sb.Length > 0) if (sb.Length > 0)

@ -318,10 +318,10 @@ public class ClientInfoService : ServiceBase, IClientInfoService
AccountDates = [] AccountDates = []
}; };
var dicValue = dicList.Find(x => x.Name == model.Attribute)?.Value; var dicValues = dicList.FindAll(x => model.AttributeNames.Contains(x.Name));
if (!string.IsNullOrEmpty(dicValue)) foreach (var item in dicValues)
{ {
dicValue = dicValue.ToUpperCamelCase(); var dicValue = item.Value.ToUpperCamelCase();
PropertyExtensions.SetPropertyValue(client.ClientTag, dicValue, true); PropertyExtensions.SetPropertyValue(client.ClientTag, dicValue, true);
} }

@ -357,7 +357,7 @@ public class ClientInfoController : ApiController
{ {
var model = new InfoClientBankModel var model = new InfoClientBankModel
{ {
CompanyName = item["A"]?.ToString(), CompanyName = item["A"]?.ToString()?.Trim(),
Currency = item["B"]?.ToString(), Currency = item["B"]?.ToString(),
BankName = item["C"]?.ToString(), BankName = item["C"]?.ToString(),
BankAccount = item["E"]?.ToString(), BankAccount = item["E"]?.ToString(),
@ -415,7 +415,7 @@ public class ClientInfoController : ApiController
{ {
var model = new InfoClientContactModel var model = new InfoClientContactModel
{ {
CompanyName = item["A"]?.ToString(), CompanyName = item["A"]?.ToString()?.Trim(),
ContactName = item["B"]?.ToString(), ContactName = item["B"]?.ToString(),
ContactEnName = item["C"]?.ToString(), ContactEnName = item["C"]?.ToString(),
Tel = item["D"]?.ToString(), Tel = item["D"]?.ToString(),

Loading…
Cancel
Save