package com.tenwa.reckon.help; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; import jbo.app.tenwa.calc.LC_CALC_CONDITION_TEMP; import jbo.app.tenwa.calc.LC_RENT_PLAN_TEMP; import jbo.com.tenwa.lease.comm.LC_HANDLING_APPORTION; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.BizObjectManager; import com.amarsoft.are.jbo.JBOException; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.are.jbo.JBOTransaction; import com.amarsoft.awe.util.Transaction; import com.tenwa.lease.app.quartzmession.SplitInts; import com.tenwa.reckon.constant.Scale; import com.tenwa.reckon.util.DateTools; public class HandlingApportionManager { public static void setHandlingApportion(String flowunid,String contractid,String paymentNumber,JBOTransaction tx) throws JBOException{ BizObject boLCCT = JBOFactory.getBizObjectManager(LC_CALC_CONDITION_TEMP.CLASS_NAME,tx) .createQuery("flowunid='"+flowunid+"' and payment_number='"+paymentNumber+"'").getSingleResult(false); //手续费 BigDecimal handMoney = new BigDecimal(boLCCT.getAttribute("HANDLING_CHARGE_MONEY").getString()); BizObject boLRPT = JBOFactory.getBizObjectManager(LC_RENT_PLAN_TEMP.CLASS_NAME,tx) .createQuery("select v.sum(interest) v.Interest from O where flowunid='"+flowunid+"' and payment_number='"+paymentNumber+"'").getSingleResult(false); //总利息 BigDecimal allInterest = new BigDecimal(boLRPT.getAttribute("Interest").getString()); List boLRPTs = JBOFactory.getBizObjectManager(LC_RENT_PLAN_TEMP.CLASS_NAME,tx) .createQuery("flowunid='"+flowunid+"' and payment_number='"+paymentNumber+"' order by plan_list").getResultList(false); List dateList = getDateList(boLRPTs); //按日计算手续费分摊 List> handMoneyList = gethandMoneyList(handMoney.toString(), dateList, boLCCT.getAttribute("START_DATE").getString(), boLCCT.getAttribute("PERIOD_TYPE").getString(), boLCCT.getAttribute("INCOME_INTERVAL_MONTH").getInt()+""); BizObjectManager bomLHA = JBOFactory.getBizObjectManager(LC_HANDLING_APPORTION.CLASS_NAME,tx); bomLHA.createQuery("delete from O where payment_number='"+paymentNumber+"'").executeUpdate(); //入库 int n = 0; for(BizObject bo:boLRPTs){ BizObject boLHA = bomLHA.newObject(); boLHA.setAttributeValue("CONTRACT_ID",contractid); boLHA.setAttributeValue("PLAN_LIST",bo.getAttribute("PLAN_LIST").getString()); boLHA.setAttributeValue("PAYMENT_NUMBER",paymentNumber); boLHA.setAttributeValue("HANDLING_APPORTION_MONEY",handMoneyList.get(n).get("money")); boLHA.setAttributeValue("HANDLING_APPORTION_RATIO",handMoneyList.get(n).get("ratio")); bomLHA.saveObject(boLHA); n++; } } public static void setSingleHandlingApportion(String flowunid,String paymentNumber,String contractid,JBOTransaction tx) throws JBOException{ BizObject boLCCT = JBOFactory.getBizObjectManager(LC_CALC_CONDITION_TEMP.CLASS_NAME,tx) .createQuery("flowunid='"+flowunid+"'").getSingleResult(false); //手续费 BigDecimal handMoney = new BigDecimal(boLCCT.getAttribute("HANDLING_CHARGE_MONEY").getString()); BizObject boLRPT = JBOFactory.getBizObjectManager(LC_RENT_PLAN_TEMP.CLASS_NAME,tx) .createQuery("select v.sum(interest) v.allInterest from O where flowunid='"+flowunid+"'").getSingleResult(false); //总利息 BigDecimal allInterest = new BigDecimal(boLRPT.getAttribute("allInterest").getString()); List boLRPTs = JBOFactory.getBizObjectManager(LC_RENT_PLAN_TEMP.CLASS_NAME,tx) .createQuery("flowunid='"+flowunid+"' order by plan_list").getResultList(false); List dateList = getDateList(boLRPTs); //按日计算手续费分摊 List> handMoneyList = gethandMoneyList(handMoney.toString(), dateList, boLCCT.getAttribute("START_DATE").getString(), boLCCT.getAttribute("PERIOD_TYPE").getString(), boLCCT.getAttribute("INCOME_INTERVAL_MONTH").getInt()+""); BizObjectManager bomLHA = JBOFactory.getBizObjectManager(LC_HANDLING_APPORTION.CLASS_NAME,tx); bomLHA.createQuery("delete from O where payment_number='"+paymentNumber+"'").executeUpdate(); //入库 int n = 0; for(BizObject bo:boLRPTs){ BizObject boLHA = bomLHA.newObject(); boLHA.setAttributeValue("CONTRACT_ID",contractid); boLHA.setAttributeValue("PLAN_LIST",bo.getAttribute("PLAN_LIST").getString()); boLHA.setAttributeValue("PAYMENT_NUMBER",paymentNumber); boLHA.setAttributeValue("HANDLING_APPORTION_MONEY",handMoneyList.get(n).get("money")); boLHA.setAttributeValue("HANDLING_APPORTION_RATIO",handMoneyList.get(n).get("ratio")); bomLHA.saveObject(boLHA); n++; } } public static List getDateList(List bos) throws JBOException{ List dateList = new ArrayList(); for(BizObject bo:bos){ dateList.add(bo.getAttribute("PLAN_DATE").getString()); } return dateList; } public static List> gethandMoneyList(String handMoney,List dateList,String startDate,String period_type,String incomeNumberyear){ List> handMoneyList=new ArrayList>(); try { BigDecimal hmoney=new BigDecimal(handMoney); int number=Integer.parseInt(incomeNumberyear); if("period_type_1".equals(period_type)){ SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd"); dateList.remove(0); Calendar enddate=Calendar.getInstance(); enddate.setTime(sdf.parse(dateList.get(dateList.size()-1))); enddate.add(Calendar.MONTH, number); dateList.add(sdf.format(enddate.getTime())); } BigDecimal money=BigDecimal.ZERO; BigDecimal all=BigDecimal.ZERO; all=new BigDecimal(DateTools.getDateDiff(dateList.get(dateList.size()-1), startDate)); for(int i=0;i hand = new HashMap(); BigDecimal mon=BigDecimal.ZERO; BigDecimal ratio=BigDecimal.ZERO; long dateDiff=DateTools.getDateDiff(dateList.get(i), startDate); if(i