@ -15,6 +15,7 @@ using DS.WMS.Core.Op.Dtos.TaskInteraction;
using DS.WMS.Core.Op.Entity ;
using DS.WMS.Core.Op.Interface.TaskInteraction ;
using DS.WMS.Core.Sys.Entity ;
using Fasterflect ;
using Mapster ;
using Masuit.Tools.Systems ;
using Microsoft.Extensions.DependencyInjection ;
@ -42,6 +43,8 @@ public class ClientInfoService : ServiceBase, IClientInfoService
taskService = new Lazy < ITaskService > ( serviceProvider . GetRequiredService < ITaskService > ( ) ) ;
}
#region 审核
/// <summary>
/// 提交审核
/// </summary>
@ -246,26 +249,73 @@ public class ClientInfoService : ServiceBase, IClientInfoService
return rows > 0 ? DataResult . Success : DataResult . FailedWithDesc ( nameof ( MultiLanguageConst . Operation_Failed ) ) ;
}
# endregion
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public DataResult < List < ClientInfoRes > > GetListByPage ( PageRequest request )
public async Task < DataResult < List < ClientInfoRes > > > GetListAsync ( PageRequest < ClientQuery > request )
{
//序列化查询条件
var whereList = request . GetConditionalModels ( Db ) ;
var result = TenantDb . Queryable < InfoClient > ( )
. Where ( whereList )
. Select < ClientInfoRes > ( ) . ToQueryPage ( request . PageCondition ) ;
foreach ( var item in whereList )
{
var condition = ( ConditionalModel ) item ;
condition . FieldName = "c." + condition . FieldName . ToUpperCamelCase ( ) ;
}
var query = TenantDb . Queryable < InfoClient > ( )
. LeftJoin < InfoClientContact > ( ( c , c1 ) = > c . Id = = c1 . ClientId )
. LeftJoin < InfoClientContract > ( ( c , c1 , c2 ) = > c . Id = = c2 . ClientId )
. InnerJoinIF < InfoClientTag > ( request . OtherQueryCondition ? . ClientTag ! = null , ( c , c1 , c2 , ct ) = > c . Id = = ct . ClientId ) ;
if ( ! string . IsNullOrEmpty ( request . OtherQueryCondition ? . ContactInfo ) )
query = query . Where ( ( c , c1 , c2 ) = > c1 . Tel . Contains ( request . OtherQueryCondition . ContactInfo ) | |
c1 . Mobile . Contains ( request . OtherQueryCondition . ContactInfo ) | | c1 . Email . Contains ( request . OtherQueryCondition . ContactInfo ) ) ;
if ( request . OtherQueryCondition ! = null & & request . OtherQueryCondition . IsContractExpired . GetValueOrDefault ( ) )
query = query . Where ( ( c , c1 , c2 ) = > SqlFunc . GetDate ( ) > c2 . EndDate ) ;
if ( request . OtherQueryCondition ? . ClientTag ! = null )
{
var props = Array . FindAll ( request . OtherQueryCondition . ClientTag . GetType ( ) . GetProperties ( ) , x = > x . Name . StartsWith ( "Is" ) & & x . PropertyType = = typeof ( bool ) ) ;
foreach ( var prop in props )
{
object val = PropertyInfoExtensions . Get ( prop , request . OtherQueryCondition . ClientTag ) ;
if ( val ! = null & & val is bool value & & value )
{
whereList . Add ( new ConditionalModel
{
ConditionalType = ConditionalType . Equal ,
FieldName = "ct." + prop . Name ,
FieldValue = "1"
} ) ;
}
}
}
var result = await query . Where ( whereList ) . Select < ClientInfoRes > ( ) . ToQueryPageAsync ( request . PageCondition ) ;
if ( result . Data ? . Count > 0 )
{
var ids = result . Data . SelectMany ( x = > x . SaleOrgIdList ) . Distinct ( ) ;
var orgs = Db . Queryable < SysOrg > ( ) . Where ( x = > ids . Contains ( x . Id ) ) . Select ( x = > new { x . Id , x . OrgName } ) . ToList ( ) ;
var ids = result . Data . Select ( x = > x . Id ) ;
var contacts = TenantDb . Queryable < InfoClientContact > ( ) . Where ( x = > ids . Contains ( x . ClientId ) & & x . IsDefault )
. Select < ClientContactRes > ( ) . ToList ( ) ;
var accountDates = TenantDb . Queryable < InfoClientAccountDate > ( ) . Where ( x = > ids . Contains ( x . ClientId ) & & x . Id = =
SqlFunc . Subqueryable < InfoClientAccountDate > ( ) . Where ( y = > y . Id = = x . Id ) . Select ( y = > SqlFunc . AggregateMax ( y . Id ) )
) . Select < ClientAccountDateRes > ( ) . ToList ( ) ;
var ids2 = result . Data . SelectMany ( x = > x . SaleOrgIdList ) . Distinct ( ) ;
var orgs = Db . Queryable < SysOrg > ( ) . Where ( x = > ids2 . Contains ( x . Id ) ) . Select ( x = > new { x . Id , x . OrgName } ) . ToList ( ) ;
foreach ( var item in result . Data )
{
item . DefaultContact = contacts . Find ( x = > x . ClientId = = item . Id ) ;
item . LastAccountDate = accountDates . Find ( x = > x . ClientId = = item . Id ) ;
var list = orgs . FindAll ( x = > item . SaleOrgIdList . Contains ( x . Id ) ) ;
item . SaleOrgNames = string . Join ( "," , list . Select ( x = > x . OrgName ) ) ;
}
@ -274,6 +324,26 @@ public class ClientInfoService : ServiceBase, IClientInfoService
return result ;
}
/// <summary>
/// 确定往来单位是否已使用
/// </summary>
/// <param name="ids">往来单位ID</param>
/// <returns></returns>
public async Task < DataResult < List < ClientUsage > > > GetUsageAsync ( params long [ ] ids )
{
var list = await TenantDb . Queryable < InfoClient > ( )
. Select ( c = > new ClientUsage
{
Id = c . Id ,
Name = c . ShortName ,
IsUsed = SqlFunc . Subqueryable < SeaExport > ( ) . Where ( s = > c . Id = = s . CustomerId | | c . Id = = s . ForwarderId | | c . Id = = s . YardId ) . Any ( )
} ) . ToListAsync ( ) ;
var result = DataResult < List < ClientUsage > > . Success ( list ) ;
result . Count = list . Count ;
return result ;
}
/// <summary>
/// 编辑
/// </summary>
@ -292,9 +362,7 @@ public class ClientInfoService : ServiceBase, IClientInfoService
if ( req . Id = = 0 )
{
if ( TenantDb . Queryable < InfoClient > ( ) . Where ( x = > ( x . ShortName = = req . ShortName . Trim ( ) | | x . Description = = req . Description . Trim ( ) | | x . TaxNo = = req . TaxNo . Trim ( ) ) ) . Any ( ) )
{
return DataResult . Failed ( "客户信息已存在,请检查客户全称、简称或社会信用代码是否重复!" , MultiLanguageConst . ClientInfoExist ) ;
}
var tag = req . ClientTag . Adapt < InfoClientTag > ( ) ;
//助记码