@ -260,6 +260,20 @@ public class ClientInfoService : ServiceBase, IClientInfoService
{
long userId = long . Parse ( User . UserId ) ;
DateTime dtNow = DateTime . Now ;
TenantDb . QueryFilter . Clear < IOrgId > ( ) ;
TenantDb . QueryFilter . Clear < ISharedOrgId > ( ) ;
var clientNames1 = list . Select ( x = > x . ShortName ) . Distinct ( ) ;
var clientNames2 = list . Select ( x = > x . CNName ) . Distinct ( ) ;
var clients = await TenantDb . Queryable < InfoClient > ( ) . Where ( x = > clientNames1 . Contains ( x . ShortName ) | | clientNames2 . Contains ( x . Description ) )
. Select ( x = > new InfoClient
{
Id = x . Id ,
ShortName = x . ShortName ,
Description = x . Description ,
IsCustomer = x . IsCustomer ,
IsSupplier = x . IsSupplier
} ) . ToListAsync ( ) ;
var attrbutes = list . SelectMany ( x = > x . AttributeNames ) . Where ( x = > ! string . IsNullOrEmpty ( x ) ) . Distinct ( ) ;
var dicList = await Db . Queryable < SysDictData > ( ) . InnerJoin < SysDictType > ( ( d , t ) = > d . TypeId = = t . Id )
@ -284,10 +298,21 @@ public class ClientInfoService : ServiceBase, IClientInfoService
x . DefaultOrgId
} ) . ToListAsync ( ) ;
List < InfoClient > clients = new List < InfoClient > ( list . Count ) ;
List < InfoClient > newClients = new ( list . Count ) ;
List < InfoClient > existClients = [ ] ;
foreach ( var model in list )
{
InfoClient client = new ( )
InfoClient ? client = clients . Find ( x = > x . ShortName = = model . ShortName & & x . Description = = model . CNName ) ;
if ( client ! = null )
{
client . IsCustomer = model . IsCustomer ;
client . IsSupplier = model . IsSupplier ;
//client.Note = "系统导入";
existClients . Add ( client ) ;
continue ;
}
client = new ( )
{
Address = model . Address ,
AuditStatus = model . StatusText = = "认证" ? AuditStatusEnum . Approve : AuditStatusEnum . NoAudit ,
@ -324,7 +349,7 @@ public class ClientInfoService : ServiceBase, IClientInfoService
var dicValue = item . Value . ToUpperCamelCase ( ) ;
PropertyExtensions . SetPropertyValue ( client . ClientTag , dicValue , true ) ;
}
client . AccountDates . Add ( new InfoClientAccountDate
{
AccountType = model . StlType ,
@ -336,15 +361,18 @@ public class ClientInfoService : ServiceBase, IClientInfoService
CreateTime = dtNow ,
} ) ;
c lients. Add ( client ) ;
newC lients. Add ( client ) ;
}
await TenantDb . Ado . BeginTranAsync ( ) ;
try
{
await TenantDb . Fastest < InfoClient > ( ) . RemoveDataCache ( $"{SqlSugarCacheConst.InfoClient}{User.TenantId}" ) . BulkMergeAsync ( clients ) ;
foreach ( var client in clients )
if ( existClients . Count > 0 )
await TenantDb . Updateable ( existClients ) . UpdateColumns ( x = > new { x . IsCustomer , x . IsSupplier } ) . ExecuteCommandAsync ( ) ;
await TenantDb . Fastest < InfoClient > ( ) . RemoveDataCache ( $"{SqlSugarCacheConst.InfoClient}{User.TenantId}" ) . BulkMergeAsync ( newClients ) ;
foreach ( var client in newClients )
{
client . ClientTag . ClientId = client . Id ;
@ -352,14 +380,16 @@ public class ClientInfoService : ServiceBase, IClientInfoService
item . ClientId = client . Id ;
}
var tags = c lients. Select ( x = > x . ClientTag ) . ToList ( ) ;
var tags = newC lients. Select ( x = > x . ClientTag ) . ToList ( ) ;
await TenantDb . Fastest < InfoClientTag > ( ) . BulkMergeAsync ( tags ) ;
var accountDates = c lients. SelectMany ( x = > x . AccountDates ) . ToList ( ) ;
var accountDates = newC lients. SelectMany ( x = > x . AccountDates ) . ToList ( ) ;
await TenantDb . Fastest < InfoClientAccountDate > ( ) . BulkMergeAsync ( accountDates ) ;
await TenantDb . Ado . CommitTranAsync ( ) ;
return DataResult . Success ;
var result = DataResult . Success ;
result . Message = $"新增往来单位:{newClients.Count}项,更新往来单位:{existClients}项" ;
return result ;
}
catch ( Exception ex )
{