package com.tenwa.reckon.help; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; import jbo.com.tenwa.entity.comm.holiday.BT_HOLIDAY; import com.amarsoft.app.als.prd.config.loader.ProductConfig; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.BizObjectManager; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.are.jbo.JBOTransaction; import com.tenwa.reckon.bean.CalculationCondition; import com.tenwa.reckon.bean.ConditionBean; import com.tenwa.reckon.bean.RentPlanInfo; import com.tenwa.reckon.bean.TabCalBean; import com.tenwa.reckon.util.DateUtil; import com.tenwa.reckon.util.RentCalculateUtil; /** * * @author SHIHONGFEI * @version 1.0 * @copyright (C) TENWA 2011 * @date 2011-3-3 * @desc ( 租金计划支付日期处理类) */ public class PlanDateServiceImpl { private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); public JBOTransaction tx; public PlanDateServiceImpl(){} public PlanDateServiceImpl(JBOTransaction tx){ this.tx=tx; } /** * * 租金时间计划安排 * * @param cb * @param rentListSize * @return */ public List getPlanDateList(ConditionBean cb, String rentListSize) { try { CalculationCondition condition = new CalculationConditionImpl(); condition.copyConditionBeanValues(cb); List rentPlanList = RentCalculateUtil.getEmptyPlanModel(condition); List dateList = new ArrayList(); for(RentPlanInfo rpl : rentPlanList){ dateList.add(dateFormat.format(rpl.getEndDate())); } if(cb.getLastPlanDate()!=null){ dateList.set(dateList.size()-1, cb.getLastPlanDate()); } return dateList; } catch (Exception e) { e.printStackTrace(); } return null; } /** * 计息日期列表 * @param condition * @return * @throws ParseException */ public List getInterestDateList(ConditionBean condition) throws ParseException{ String startDate = condition.getStartDate();// 起租日期,计算最后一期的还款日期 String firstInterestDate = condition.getFirstInterestDate();// 计息第1期日期 List planDateList = new ArrayList(); planDateList.add(startDate);// 必须有起始日期 if(firstInterestDate != null){ planDateList.add(firstInterestDate); } else { // 起租类型 注意: 期初 数字 1 字符串 period_type_1 #分割线# 期末 数字0 字符串 period_type_0 if("period_type_1".equals(condition.getPeriodType())){// 期初 planDateList.add(startDate);//第一期和起租日期一样 } } int incomeTimes = condition.getIncomeNumber();// 期数 int grace = condition.getGrace();// 宽限期 int issueNumber = condition.getIncomeIntervalMonth();// 每期几个月 // 计算结束租期日子 Date reference = DateUtil.getTimeByFormat(planDateList.get(planDateList.size() - 1),"yyyy/MM/dd"); for (int i = planDateList.size(); i < grace + incomeTimes + 1; i++) { reference = DateUtil.getTimeByFormat(DateUtil.addDate(reference, "MONTH", issueNumber),"yyyy/MM/dd"); planDateList.add(DateUtil.getSystemTimeByFormat(reference, "yyyy/MM/dd")); } planDateList.remove(0); if(condition.getLastInterestData()!=null){ planDateList.set(planDateList.size()-1, condition.getLastInterestData()); } return planDateList; } public List getAdjustDate(List dateList,String type) throws Exception{ List dateListNew=new ArrayList(); for(int i=0;i dateList) throws Exception { BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getRentPlan_tb(), tx); for (int i = 0; i < dateList.size(); i++) { BizObject rent=bm.createQuery("flowunid=:flowunid and plan_list=:startList").setParameter("flowunid",tcb.getDocId()).setParameter("startList", startList).getSingleResult(true); rent.setAttributeValue("plan_date", dateList.get(i).toString()); bm.saveObject(rent); startList = startList + 1; } return true; } /** * * ( 起租时的更新租金计划日期信息) * * @param tcb * @return * @throws Exception */ public boolean updateRentInterestDate(String tbName, TabCalBean tcb, int startList, List dateList) throws Exception { BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getRentPlan_tb(), tx); for (int i = 0; i < dateList.size(); i++) { BizObject rent=bm.createQuery("flowunid=:flowunid and plan_list=:startList").setParameter("flowunid",tcb.getDocId()).setParameter("startList", startList).getSingleResult(true); rent.setAttributeValue("INTEREST_DATE", dateList.get(i).toString()); bm.saveObject(rent); startList = startList + 1; } return true; } }