/* Ċ Ġ* ĠCopyright ĠD 3 ĠLed ger , ĠInc . ĠAll ĠRights ĠReserved . Ċ Ġ* ĠSPDX - License - Identifier : ĠApache - 2 . 0 Ċ Ġ*/ Ċ package Ġcom . d 3 . report . repository Ċ Ċ import Ġcom . d 3 . report . model . Transfer Asset Ċ import Ġorg . springframework . data . domain . Page Ċ import Ġorg . springframework . data . domain . Page able Ċ import Ġorg . springframework . data . jpa . repository . Query Ċ import Ġorg . springframework . data . repository . Crud Repository Ċ import Ġjava . math . BigDecimal ĊĊ Ċ interface ĠTransfer Asset Repo Ġ: ĠCr ud Repository < Transfer Asset , ĠLong ?> Ġ{ ĊĊĠĠĠ Ġ@ Query (" SELECT Ġt ĠFROM ĠTransfer Asset Ġt ĠWHERE Ġt . transaction . rejected Ġ= Ġfalse Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" and Ġexists Ġ( SELECT Ġta ĠFROM ĠTransfer Asset Ġta ĠWHERE Ġta . transaction . id Ġ= Ġt . transaction . id Ġand Ġta . dest AccountId Ġ= Ġ: billing AccountId ) Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" and Ġt . transaction . block . block Creation Time ĠBet ween Ġ: from Ġand Ġ: to ") ĊĠĠĠ Ġfun ĠgetData Between For Billing Account ( billing AccountId : String , Ġfrom : ĠLong , Ġto : ĠLong , Ġpage able : ĠPage able ): ĠPage < Transfer Asset > ĊĊĠĠĠ Ġ@ Query (" SELECT Ġt ĠFROM ĠTransfer Asset Ġt ĠWHERE Ġt . transaction . rejected Ġ= Ġfalse Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" and Ġ( t . src AccountId Ġ= Ġ: account ĠOR Ġ Ġt . dest AccountId Ġ= Ġ: account ) Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" ORDER ĠBY Ġt . transaction . block . block Creation Time ĠASC ") ĊĠĠĠ Ġfun ĠgetAll Trans fers For Account In And Out ( account : String , Ġpage able : ĠPage able ): ĠPage < Transfer Asset > ĊĊĠĠĠ Ġ@ Query (" SELECT Ġt ĠFROM ĠTransfer Asset Ġt ĠWHERE Ġt . transaction . rejected Ġ= Ġfalse Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" and Ġ( t . src AccountId Ġ= Ġ: account ĠOR Ġ Ġt . dest AccountId Ġ= Ġ: account )" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Ġand Ġt . transaction . block . block Creation Time Ġ< Ġ: to " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" ĠORDER ĠBY Ġt . transaction . block . block Creation Time ĠASC ") ĊĠĠĠ Ġfun ĠgetAll Trans fers For Account In And Out T ill To ( account : String , Ġto : Long , Ġpage able : ĠPage able ): ĠPage < Transfer Asset > ĊĊĠĠĠ Ġ@ Query (" SELECT Ġt ĠFROM ĠTransfer Asset Ġt ĠWHERE Ġt . transaction . rejected Ġ= Ġfalse Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" and Ġexists Ġ( SELECT Ġta ĠFROM ĠTransfer Asset Ġta ĠWHERE Ġta . transaction . id Ġ= Ġt . transaction . id Ġand Ġta . dest AccountId ĠLIKE ĠCONCAT (: billing Account Template ,' % ')) Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" and Ġt . transaction . block . block Creation Time ĠBet ween Ġ: from Ġand Ġ: to ") ĊĠĠĠ Ġfun ĠgetData Between For Billing Account Template ( billing Account Template : String , Ġfrom : ĠLong , Ġto : ĠLong , Ġpage able : ĠPage able ): ĠPage < Transfer Asset > ĊĊĠĠĠ Ġ@ Query (" SELECT Ġt ĠFROM ĠTransfer Asset Ġt ĠWHERE Ġt . transaction . rejected Ġ= Ġfalse Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" and Ġ( t . src AccountId Ġ= Ġ: account ĠOR Ġ Ġt . dest AccountId Ġ= Ġ: account )" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Ġand Ġt . transaction . block . block Creation Time Ġ< Ġ: to " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" ĠORDER ĠBY Ġt . transaction . block . block Creation Time ĠASC ") ĊĠĠĠ Ġfun ĠgetTime dB illed Trans fers For Account ( account : String , Ġto : Long , Ġpage able : ĠPage able ): ĠPage < Transfer Asset > ĊĊĠĠĠ Ġ@ Query (" SELECT Ġt ĠFROM ĠTransfer Asset Ġt ĠWHERE Ġt . transaction . rejected Ġ= Ġfalse " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Ġand Ġexists Ġ( SELECT Ġta ĠFROM ĠTransfer Asset Ġta ĠWHERE Ġta . transaction . id Ġ= Ġt . transaction . id Ġand Ġta . dest AccountId Ġ= Ġ: billing Account )" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Ġand Ġt . src AccountId Ġ= Ġ: accountId " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Ġand Ġt . transaction . block . block Creation Time ĠBet ween Ġ: from Ġand Ġ: to ") ĊĠĠĠ Ġfun ĠgetData Between For Billing Account ( accountId : String , Ġbilling Account : String , Ġfrom : ĠLong , Ġto : ĠLong , Ġpage able : ĠPage able ): ĠPage < Transfer Asset > ĊĊĠĠĠ Ġ@ Query (" SELECT Ġt ĠFROM ĠTransfer Asset Ġt ĠWHERE Ġt . transaction . rejected Ġ= Ġfalse " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Ġand Ġexists Ġ( SELECT Ġta ĠFROM ĠTransfer Asset Ġta ĠWHERE Ġta . transaction . id Ġ= Ġt . transaction . id Ġand Ġta . dest AccountId Ġ= Ġ: billing Account )" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Ġand Ġt . src AccountId Ġ= Ġ: accountId " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Ġand Ġt . asset Id Ġ= Ġ: asset Id " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Ġand Ġt . transaction . block . block Creation Time ĠBet ween Ġ: from Ġand Ġ: to ") ĊĠĠĠ Ġfun ĠgetData Between For Asset Of Account ( asset Id : String , ĠaccountId : String , Ġbilling Account : String , Ġfrom : ĠLong , Ġto : ĠLong , Ġpage able : ĠPage able ): ĠPage < Transfer Asset > ĊĊĠĠĠ Ġ@ Query (""" ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSELECT ĠSUM ( CASE ĊĠĠĠĠĠĠĠĠĠĠĠ ĠWHEN Ġt . src AccountId ĠNOT ĠLIKE Ġ% : domain Id Ġand Ġt . dest AccountId ĠLIKE Ġ% : domain Id ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTHEN Ġt . amount ĊĠĠĠĠĠĠĠĠĠĠĠ ĠWHEN Ġt . src AccountId ĠLIKE Ġ% : domain Id Ġand Ġt . dest AccountId ĠNOT ĠLIKE Ġ% : domain Id ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTHEN Ġ- t . amount ĊĠĠĠĠĠĠĠĠĠĠĠ ĠELSE Ġ 0 ĊĠĠĠĠĠĠĠĠĠĠĠ ĠEND ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġas ĠAS SET _ SUM ĠFROM ĠTransfer Asset Ġt ĠWHERE Ġt . transaction . rejected Ġ= Ġfalse Ġand Ġ Ġt . asset Id Ġ= Ġ: asset Id ĊĠĠĠĠĠĠĠĠĠĠĠĠ Ġ"" ") ĊĠĠĠ Ġfun Ġget Sum Asset ( asset Id : ĠString , Ġdomain Id : ĠString ): ĠBigDecimal Ċ } Ċ