stringwhere=string.Format(" where A."+nameof(RB_AccountType_Extend.Status)+"={0}",(int)Common.Enum.DateStateEnum.Normal);
if(model.RB_Group_Id>0)
{
where+=string.Format(" AND A."+nameof(RB_AccountType_Extend.RB_Group_Id)+"={0}",model.RB_Group_Id);
}
//if (model.RB_Branch_Id >= 0)
//{
// where += string.Format(" AND A." + nameof(RB_AccountType_Extend.RB_Branch_Id) + "={0}", model.RB_Branch_Id);
//}
stringsql=string.Format(" SELECT *,((SELECT COUNT(1) FROM rb_backaccount where TypeId=A.ID AND `Status`=0)+(SELECT COUNT(1) FROM rb_cashaccount where TypeId=A.ID AND `Status`=0)+(SELECT COUNT(1) FROM rb_cashpoolaccount where TypeId=A.ID AND `Status`=0)+(SELECT COUNT(1) FROM rb_platformaccount where TypeId=A.ID AND `Status`=0)) as PeopleNum FROM {0} as A {1}",TableName,where);
where+=string.Format(" AND t."+nameof(RB_BackAccount_Extend.BankType)+" ={0}",(int)model.BankType);
}
if(model.TypeId>0)
{
where+=string.Format(" AND t."+nameof(RB_BackAccount_Extend.TypeId)+" ={0}",model.TypeId);
}
if(!string.IsNullOrEmpty(model.Alias))
{
where+=string.Format(" AND t."+nameof(RB_BackAccount_Extend.Alias)+" like '%{0}%' ",model.Alias);
}
if(model.BranchId>=0)
{
where+=string.Format(" AND t."+nameof(RB_BackAccount_Extend.BranchId)+" ={0}",model.BranchId);
}
stringsql=string.Format(@"select t.ID,t.BranchId,t.Alias,t.AccountType as AccountTypeName,BackNo,t.backId,t.TypeId,t.BankType,t.CreateBy,t.CreateDate,t.CurrencyName,t.Rate,t.Initialbalance from (
SELECT ID,BranchId,Alias,'银行' as AccountType,backNo AS BackNo,backId,TypeId,1 as BankType,CreateBy,CreateDate,(SELECT `Name` from rb_currency where ID=currencyId ) as CurrencyName,IFNULL((SELECT CurrentRate from rb_currency where ID=currencyId) ,0)as Rate,Initialbalance FROM rb_backaccount as A where `Status`=0
UNION ALL
SELECT ID,BranchId,Alias,'平台' as AccountType,PlatformNo AS BackNo,BackId as backId,TypeId,2 as BankType,CreateBy,CreateDate,(SELECT `Name` from rb_currency where ID=currencyId ) as CurrencyName,IFNULL((SELECT CurrentRate from rb_currency where ID=currencyId) ,0)as Rate,Initialbalance FROM rb_platformaccount as A where `Status`=0
UNION ALL
SELECT ID,BranchId,Alias,'现金' as AccountType,'' AS BackNo,0 as backId,TypeId,3 as BankType,CreateBy,CreateDate,(SELECT `Name` from rb_currency where ID=currencyId ) as CurrencyName,IFNULL((SELECT CurrentRate from rb_currency where ID=currencyId) ,0)as Rate,Initialbalance FROM rb_cashaccount as A where `Status`=0
UNION ALL
SELECT ID,BranchId,Alias,'资金池' as AccountType,'' AS BackNo,0 as backId,TypeId,4 as BankType,CreateBy,CreateDate,(SELECT `Name` from rb_currency where ID=currencyId ) as CurrencyName,IFNULL((SELECT CurrentRate from rb_currency where ID=currencyId) ,0)as Rate,Initialbalance FROM rb_cashpoolaccount as A where `Status`=0
stringwhere=" where 1=1 and a.`Status`=0 and a.Type=2 ";
if(model.BankType>0)
{
where+=string.Format(" AND t."+nameof(RB_BackAccount_Extend.BankType)+" ={0}",(int)model.BankType);
}
if(model.RB_Branch_Id>=0)
{
where+=string.Format(" AND a."+nameof(RB_BackAccount_Extend.RB_Branch_Id)+" ={0}",model.RB_Branch_Id);
}
if(model.ID>0)
{
where+=string.Format(" AND t."+nameof(RB_BackAccount_Extend.ID)+" ={0}",model.ID);
}
if(model.TypeId>0)
{
where+=string.Format(" AND t."+nameof(RB_BackAccount_Extend.TypeId)+" ={0}",model.TypeId);
}
if(!string.IsNullOrEmpty(model.Alias))
{
where+=string.Format(" AND t."+nameof(RB_BackAccount_Extend.Alias)+" like '%{0}%' ",model.Alias);
}
stringsql=string.Format(@"select t.ID,t.Alias,t.AccountType as AccountTypeName,BackNo,t.backId,t.TypeId,t.BankType,t.CreateBy,t.CreateDate,t.CurrencyName,t.Rate,t.Initialbalance,IFNULL(a.RB_Branch_Id,-1) as RB_Branch_Id from (
SELECT ID,Alias,'银行' as AccountType,BackNo AS BackNo,backId,TypeId,1 as BankType,CreateBy,CreateDate,(SELECT `Name` from rb_currency where ID=currencyId ) as CurrencyName,IFNULL((SELECT CurrentRate from rb_currency where ID=currencyId) ,0)as Rate,Initialbalance FROM rb_backaccount as A where `Status`=0
UNION ALL
SELECT ID,Alias,'平台' as AccountType,PlatformNo AS BackNo,BackId as backId,TypeId,2 as BankType,CreateBy,CreateDate,(SELECT `Name` from rb_currency where ID=currencyId ) as CurrencyName,IFNULL((SELECT CurrentRate from rb_currency where ID=currencyId) ,0)as Rate,Initialbalance FROM rb_platformaccount as A where `Status`=0
UNION ALL
SELECT ID,Alias,'现金' as AccountType,'' AS BackNo,0 as backId,TypeId,3 as BankType,CreateBy,CreateDate,(SELECT `Name` from rb_currency where ID=currencyId ) as CurrencyName,IFNULL((SELECT CurrentRate from rb_currency where ID=currencyId) ,0)as Rate,Initialbalance FROM rb_cashaccount as A where `Status`=0
UNION ALL
SELECT ID,Alias,'资金池' as AccountType,'' AS BackNo,0 as backId,TypeId,4 as BankType,CreateBy,CreateDate,(SELECT `Name` from rb_currency where ID=currencyId ) as CurrencyName,IFNULL((SELECT CurrentRate from rb_currency where ID=currencyId) ,0)as Rate,Initialbalance FROM rb_cashpoolaccount as A where `Status`=0
)as t LEFT JOIN rb_accountrelation as a on t.ID=a.AccountID AND t.BankType=a.AccountType {0}",where);
where+=string.Format(" AND t."+nameof(RB_BackAccount_Extend.ID)+" ={0}",model.ID);
}
if(model.BackId>0)
{
where+=string.Format(" AND t."+nameof(RB_BackAccount_Extend.BackId)+" ={0}",model.BackId);
}
if(model.TypeId>0)
{
where+=string.Format(" AND t."+nameof(RB_BackAccount_Extend.TypeId)+" ={0}",model.TypeId);
}
if(!string.IsNullOrEmpty(model.Alias))
{
where+=string.Format(" AND t."+nameof(RB_BackAccount_Extend.Alias)+" like '%{0}%' ",model.Alias);
}
if(model.BranchId.HasValue&&model.BranchId>=0){
where+=$@" and al.RB_Branch_Id={model.BranchId}";
}
stringsql=string.Format(@"select distinct t.ID,t.Alias,t.BackNo,t.CurrencyId,t.AccountType as AccountTypeName,t.backId,t.TypeId,t.BankType,t.CreateBy,t.CreateDate,t.CurrencyName,t.Rate,t.Initialbalance from (
SELECT ID,Alias,backNo AS BackNo,CurrencyId,'银行' as AccountType,backId,TypeId,1 as BankType,CreateBy,CreateDate,(SELECT `Name` from rb_currency where ID=currencyId ) as CurrencyName,IFNULL((SELECT (IFNULL(CurrentRate,0)+IFNULL(ExchangeRates,0)) as CurrentRate from rb_currency where ID=currencyId) ,0)as Rate,Initialbalance FROM rb_backaccount as A where `Status`=0 and RB_Group_Id={0}
UNION ALL
SELECT ID,Alias,PlatformNo AS BackNo,CurrencyId,'平台' as AccountType,BackId as backId,TypeId,2 as BankType,CreateBy,CreateDate,(SELECT `Name` from rb_currency where ID=currencyId ) as CurrencyName,IFNULL((SELECT (IFNULL(CurrentRate,0)+IFNULL(ExchangeRates,0)) as CurrentRate from rb_currency where ID=currencyId) ,0)as Rate,Initialbalance FROM rb_platformaccount as A where `Status`=0 and RB_Group_Id={0}
UNION ALL
SELECT ID,Alias,'' AS BackNo,CurrencyId,'现金' as AccountType,0 as backId,TypeId,3 as BankType,CreateBy,CreateDate,(SELECT `Name` from rb_currency where ID=currencyId ) as CurrencyName,IFNULL((SELECT (IFNULL(CurrentRate,0)+IFNULL(ExchangeRates,0)) as CurrentRate from rb_currency where ID=currencyId) ,0)as Rate,Initialbalance FROM rb_cashaccount as A where `Status`=0 and RB_Group_Id={0}
UNION ALL
SELECT ID,Alias,'' AS BackNo,CurrencyId,'资金池' as AccountType,0 as backId,TypeId,4 as BankType,CreateBy,CreateDate,(SELECT `Name` from rb_currency where ID=currencyId ) as CurrencyName,IFNULL((SELECT (IFNULL(CurrentRate,0)+IFNULL(ExchangeRates,0)) as CurrentRate from rb_currency where ID=currencyId) ,0)as Rate,Initialbalance FROM rb_cashpoolaccount as A where `Status`=0 and RB_Group_Id={0}
)as t
left join rb_accountrelation al on t.BankType=al.AccountType and t.ID=al.AccountID and al.Type=2 and al.Status=0
{1} {2}",model.RB_Group_Id,where," order by t.ID asc ");