199 lines
6.0 KiB
Java
199 lines
6.0 KiB
Java
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<String> getPlanDateList(ConditionBean cb, String rentListSize) {
|
|
try {
|
|
CalculationCondition condition = new CalculationConditionImpl();
|
|
condition.copyConditionBeanValues(cb);
|
|
List<RentPlanInfo> rentPlanList = RentCalculateUtil.getEmptyPlanModel(condition);
|
|
List<String> dateList = new ArrayList<String>();
|
|
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<String> getInterestDateList(ConditionBean condition) throws ParseException{
|
|
|
|
String startDate = condition.getStartDate();// 起租日期,计算最后一期的还款日期
|
|
String firstInterestDate = condition.getFirstInterestDate();// 计息第1期日期
|
|
List<String> planDateList = new ArrayList<String>();
|
|
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<String> getAdjustDate(List<String> dateList,String type) throws Exception{
|
|
List<String> dateListNew=new ArrayList<String>();
|
|
for(int i=0;i<dateList.size();i++){
|
|
dateListNew.add(adjustDate(dateList.get(i),type));
|
|
}
|
|
return dateListNew;
|
|
}
|
|
|
|
public String adjustDate(String date,String type) throws Exception{
|
|
|
|
/*BizObject bo2=JBOFactory.createBizObjectQuery(BT_HOLIDAY.CLASS_NAME, "c_date='"+date+"'").getSingleResult(false);
|
|
|
|
if(bo2==null){
|
|
Calendar cal = Calendar.getInstance();
|
|
cal.setTime(dateFormat.parse(date));
|
|
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY||cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY)
|
|
{
|
|
|
|
}else{
|
|
return date;
|
|
}
|
|
}else if("班".equals(bo2.getAttribute("otype").getString())){
|
|
return date;
|
|
}*/
|
|
String otype = ProductConfig.getHoliday(date);
|
|
if(otype==null){
|
|
Calendar cal = Calendar.getInstance();
|
|
cal.setTime(dateFormat.parse(date));
|
|
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY||cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY)
|
|
{
|
|
|
|
}else{
|
|
return date;
|
|
}
|
|
}else if("班".equals(otype)){
|
|
return date;
|
|
}
|
|
|
|
|
|
int day=1;
|
|
if("unchanged".equals(type)){
|
|
return date;
|
|
}else if("advance".equals(type)){
|
|
day=-1;
|
|
}
|
|
String dateNew=DateUtil.addDate(dateFormat.parse(date), DateUtil.TIME_DAY, day);
|
|
return adjustDate(dateNew,type);
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
* ( 起租时的更新租金计划日期信息)
|
|
*
|
|
* @param tcb
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public boolean updateRentPlanDate(String tbName, TabCalBean tcb, int startList, List<String> 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<String> 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;
|
|
}
|
|
|
|
|
|
}
|