package com.tenwa.loan.action; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import com.amarsoft.are.jbo.JBOTransaction; import com.amarsoft.awe.util.ASResultSet; import com.amarsoft.awe.util.SqlObject; import com.amarsoft.awe.util.Transaction; public class LoanCashPoolManagerAction { /** * 展示三个月的资金池 * @param tx * @return * @throws Exception */ public List> showCashPoolForThreeMonth(JBOTransaction tx) throws Exception{ Date curDate = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); String showCurDate = sdf.format(curDate); String showDate=""; Map showDates = new HashMap(); showDates.put("0week",showCurDate); for(int i=1;i<=13;i++){ Date date = new Date(); date.setTime(curDate.getTime()+(7L*i*24*3600000)); showDate = sdf.format(date); showDates.put(i+"week",showDate); } List> showWeeks = new ArrayList>(); Map showWeek = new HashMap(); showWeek.put("fundtype", "资金类型"); for(int i=0;i> fundtypes = new HashMap>(); for(int i=0;i<11;i++){ fundtypes.put("fund"+i, new HashMap()); } fundtypes.get("fund0").put("fundtype", "期初资金余额"); fundtypes.get("fund1").put("fundtype", "回笼租金"); fundtypes.get("fund2").put("fundtype", "业务收款"); fundtypes.get("fund3").put("fundtype", "理财产品到期"); fundtypes.get("fund4").put("fundtype", "新增融资"); fundtypes.get("fund5").put("fundtype", "流入合计"); fundtypes.get("fund6").put("fundtype", "业务放款"); fundtypes.get("fund7").put("fundtype", "偿还贷款"); fundtypes.get("fund8").put("fundtype", "购买理财"); fundtypes.get("fund9").put("fundtype", "流出合计"); fundtypes.get("fund10").put("fundtype", "期末银行余额"); Transaction Sqlca =null; Sqlca = Transaction.createTransaction(tx); ASResultSet rs = null; String sql = "select MAX(INPUTDATE) as calcdate from loan_fund_balance where inputdate<='"+showCurDate+"'"; SqlObject asql = new SqlObject(sql); rs = Sqlca.getASResultSet(asql); String calcDate = ""; if (rs.next()){ calcDate=rs.getString("calcdate"); } if(calcDate==null||calcDate.length()<=0){ return null; } fundtypes = calcWeek0 (fundtypes,calcDate,showCurDate,Sqlca); fundtypes=calcWeekOther(fundtypes,showDates,Sqlca); Sqlca.disConnect(); Sqlca=null; for(int i=0;i> calcWeek0 (Map> fundtypes,String calcDate,String showCurDate,Transaction Sqlca) throws Exception{ ASResultSet rs = null; String sql = ""; SqlObject asql = null; String fundbalancein = calcFundBalance (calcDate,showCurDate,Sqlca); fundbalancein = new BigDecimal(String.valueOf(fundbalancein)).setScale(2, BigDecimal.ROUND_HALF_UP).toString(); fundtypes.get("fund0").put("week0", fundbalancein); sql = "select SUM(rent) as rentbalance from lc_rent_plan where plan_date='"+showCurDate+"'"; asql = new SqlObject(sql); rs = Sqlca.getASResultSet(asql); String rent0=""; if (rs.next()){ rent0=rs.getString("rentbalance"); } if(rent0==null||rent0.length()<=0){ rent0="0.00"; } fundtypes.get("fund1").put("week0", rent0); rs = null; sql = "select SUM(plan_money) as fundbalance from lc_fund_plan where pay_type='pay_type_in' and plan_date='"+showCurDate+"'"; asql = new SqlObject(sql); rs = Sqlca.getASResultSet(asql); String fundin0=""; if (rs.next()){ fundin0=rs.getString("fundbalance"); } if(fundin0==null||fundin0.length()<=0){ fundin0="0.00"; } fundtypes.get("fund2").put("week0", fundin0); rs = null; sql = "SELECT SUM(PRODUCT_AMOUNT+DUE_INTEREST) AS finproduct FROM LOAN_FIN_PRODUCT WHERE REDEMPTION_DATE='"+showCurDate+"'"; asql = new SqlObject(sql); rs = Sqlca.getASResultSet(asql); String finproductin0=""; if (rs.next()){ finproductin0=rs.getString("finproduct"); } if(finproductin0==null||finproductin0.length()<=0){ finproductin0="0.00"; } fundtypes.get("fund3").put("week0", finproductin0); rs = null; sql = "SELECT SUM(LOAN_AMOUNT) AS loanmoney FROM LOAN_BILL_INFO WHERE LOAN_START_DATE='"+showCurDate+"'"; asql = new SqlObject(sql); rs = Sqlca.getASResultSet(asql); String loanmoneyin0=""; if (rs.next()){ loanmoneyin0=rs.getString("loanmoney"); } if(loanmoneyin0==null||loanmoneyin0.length()<=0){ loanmoneyin0="0.00"; } fundtypes.get("fund4").put("week0", loanmoneyin0); String intotal = String.valueOf(Double.parseDouble(rent0)+Double.parseDouble(fundin0)+Double.parseDouble(finproductin0)+Double.parseDouble(loanmoneyin0)); intotal = new BigDecimal(String.valueOf(intotal)).setScale(2, BigDecimal.ROUND_HALF_UP).toString(); fundtypes.get("fund5").put("week0", intotal); rs = null; sql = "select SUM(plan_money) as fundbalance from lc_fund_plan where pay_type='pay_type_out' and plan_date='"+showCurDate+"'"; asql = new SqlObject(sql); rs = Sqlca.getASResultSet(asql); String fundout0=""; if (rs.next()){ fundout0=rs.getString("fundbalance"); } if(fundout0==null||fundout0.length()<=0){ fundout0="0.00"; } fundtypes.get("fund6").put("week0", fundout0); rs = null; sql = "SELECT SUM(rent) AS loanmoney FROM LOAN_FUND_PLAN WHERE plan_date='"+showCurDate+"'"; asql = new SqlObject(sql); rs = Sqlca.getASResultSet(asql); String loanmoneyout0=""; if (rs.next()){ loanmoneyout0=rs.getString("loanmoney"); } if(loanmoneyout0==null||loanmoneyout0.length()<=0){ loanmoneyout0="0.00"; } fundtypes.get("fund7").put("week0", loanmoneyout0); rs = null; sql = "SELECT SUM(PRODUCT_AMOUNT) AS finproduct FROM LOAN_FIN_PRODUCT WHERE BUY_DATE='"+showCurDate+"'"; asql = new SqlObject(sql); rs = Sqlca.getASResultSet(asql); String finproductout0=""; if (rs.next()){ finproductout0=rs.getString("finproduct"); } if(finproductout0==null||finproductout0.length()<=0){ finproductout0="0.00"; } fundtypes.get("fund8").put("week0", finproductout0); String outtotal = String.valueOf(Double.parseDouble(fundout0)+Double.parseDouble(finproductout0)+Double.parseDouble(loanmoneyout0)); outtotal = new BigDecimal(String.valueOf(outtotal)).setScale(2, BigDecimal.ROUND_HALF_UP).toString(); fundtypes.get("fund9").put("week0", outtotal); String inouttotal = String.valueOf(Double.parseDouble(fundtypes.get("fund0").get("week0"))+Double.parseDouble(intotal)-Double.parseDouble(outtotal)); inouttotal = new BigDecimal(String.valueOf(inouttotal)).setScale(2, BigDecimal.ROUND_HALF_UP).toString(); fundtypes.get("fund10").put("week0", inouttotal); return fundtypes; } /** * 计算除了当天之外的资金流入和流出状况 * @param weekResult * @param showDates * @param Sqlca * @return * @throws Exception */ public Map> calcWeekOther(Map> fundtypes,Map showDates,Transaction Sqlca) throws Exception{ ASResultSet rs = null; String sql=""; SqlObject asql=null; for(int i=1;i