@Select({"
"SELECT t.ID,t.projectName,b.borrowUnitName as borrowUnitName,l.loanUnitName as loanUnitName,t.startData,t.endData,t.loanMoney,SUM(d.drawed) as drawed,t.repayed,t.toRepayed,t.interest_repayed as interest_repayed,t.repayWay,t.contractRepayTime,t.actualRepayTime,t.financingMode,t.contractStatus,t.examineStatus,t.contractWritter\n" +
"FROM (select c.ID,c.projectName,c.borrow_id,c.loan_id,c.startData,c.endData,c.loanMoney,sum(r.repayed) as repayed,SUM(r.repayTotal)-SUM(r.repayed) as toRepayed,SUM(r.interest_repayed) as interest_repayed,r.repayWay,r.contractRepayTime,r.actualRepayTime,c.financingMode,c.contractStatus,c.examineStatus,c.contractWritter from repay r,contract c \n" +
"WHERE c.ID = r.contract_id GROUP BY r.contract_id)as t\n" +
"\n" +
"LEFT JOIN drawmoney d on d.contract_id = t.ID\n" +
"LEFT JOIN borrower b on b.USCC = t.borrow_id\n" +
"LEFT JOIN loan l on l.ID = t.loan_id where 1=1" +
" and t.id = #{id} " +
" and t.projectName = #{projectName} " +
" and t.contractWritter = #{contractWritter} " +
" and loanName = #{loanName} " +
" and borrowName = #{borrowName} " +
" and t.examineStatus = #{examineStatus} "+
" and t.startData > STR_TO_DATE(#{startData},'%Y-%m-%d') "+
" and t.endData < STR_TO_DATE(#{endData},'%Y-%m-%d') "+
" and t.contractStatus = #{contractStatus} "+
" and t.financingMode = #{financingMode} "+
" and t.loanMoney > #{moreThan} " +
" and t.loanMoney < #{lessThan} " +
" and t.loanMoney between #{moreThan} and #{lessThan} " +
" and t.repayWay = #{repayWay} " +
" and t.contractRepayTime > STR_TO_DATE(#{after_contractRepayTime},'%Y-%m-%d') " +
" and t.contractRepayTime < STR_TO_DATE(#{before_contractRepayTime},'%Y-%m-%d') " +
"group by t.id "+
" HAVING 1=1 " +
" and SUM(t.repayed) > #{morethan_repayed} " +
" and SUM(t.repayed) < #{morethan_repayed} " +
" and drawed > #{after_drawed} " +
" and drawed < #{before_drawed} " +
" and interest_repayed > #{after_repayedInterest} " +
" and interest_repayed < #{before_repayedInterest} " +
" and toRepayed > #{after_toRepayed} " +
" and toRepayed < #{before_toRrepayed} " +
// " HAVING SUM(t.repayed) > #{morethan_repayed} " +
// " HAVING SUM(t.repayed) < #{lessthan_repayed} " +
// " HAVING SUM(t.repayed) > #{morethan_repayed} and SUM(t.repayed) < #{lessthan_repayed} " +
// " HAVING drawed > #{after_drawed} " +
// " HAVING drawed < #{before_drawed} " +
// " HAVING drawed > #{after_drawed} and drawed < #{before_drawed} " +
"ORDER BY startData" +
""})