202 lines
9.8 KiB
Java
202 lines
9.8 KiB
Java
package com.tenwa.makeContract.util;
|
||
|
||
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;
|
||
import jbo.app.tenwa.calc.LC_CALC_CONDITION_TEMP;
|
||
import jbo.app.tenwa.calc.LC_CALC_PERIOD;
|
||
import jbo.app.tenwa.calc.LC_CALC_RULES;
|
||
import jbo.app.tenwa.calc.LC_CALC_SUBSECTION;
|
||
import jbo.app.tenwa.calc.LC_CONTRACT_CASH_FLOW;
|
||
import jbo.app.tenwa.calc.LC_CONTRACT_CONDITION;
|
||
import jbo.app.tenwa.calc.LC_CONTRACT_FUND_PLAN;
|
||
import jbo.app.tenwa.calc.LC_CONTRACT_PERIOD;
|
||
import jbo.app.tenwa.calc.LC_CONTRACT_RENT_PLAN;
|
||
import jbo.app.tenwa.calc.LC_CONTRACT_RULES;
|
||
import jbo.app.tenwa.calc.LC_CONTRACT_SUBSECTION;
|
||
import jbo.app.tenwa.calc.LC_FUND_PLAN;
|
||
import jbo.app.tenwa.calc.LC_PAY_CASH_FLOW;
|
||
import jbo.app.tenwa.calc.LC_PAY_RENT_PLAN;
|
||
import jbo.app.tenwa.calc.LC_PROJ_CASH_FLOW;
|
||
import jbo.app.tenwa.calc.LC_PROJ_CONDITION;
|
||
import jbo.app.tenwa.calc.LC_PROJ_FUND_PLAN;
|
||
import jbo.app.tenwa.calc.LC_PROJ_PERIOD;
|
||
import jbo.app.tenwa.calc.LC_PROJ_RENT_PLAN;
|
||
import jbo.app.tenwa.calc.LC_PROJ_RULES;
|
||
import jbo.app.tenwa.calc.LC_PROJ_SUBSECTION;
|
||
import jbo.app.tenwa.calc.LC_RENT_PLAN_TEMP;
|
||
import jbo.com.tenwa.lease.comm.LC_HANDLING_APPORTION;
|
||
import jbo.com.tenwa.lease.comm.LC_PAY_CONDTION;
|
||
|
||
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.tenwa.comm.util.jboutil.DataOperatorUtil;
|
||
import com.tenwa.reckon.constant.Scale;
|
||
import com.tenwa.reckon.util.DateTools;
|
||
import com.tenwa.util.SerialNumberUtil;
|
||
|
||
public class McCalcConditionCopyService {
|
||
|
||
|
||
public void tempToContractOne(String projid,String projNo,String contractNo,String contractId,JBOTransaction tx) throws Exception{
|
||
/**
|
||
* ºÏͬ·¢ÆðʱµÄ²ÎÊý
|
||
* fromCondition£º{PROJECT_PLAN_NUMBER=A20181203000101, PROJECT_ID=1a4bed70c8f2417785f0009ef18f5eac}
|
||
otherProperty£º{CONTRACT_PLAN_NUMBER=BQAP(AZ)20181204000101, FLOWUNID=FBO2018120400000001}
|
||
¸¶¿îǰÌá
|
||
otherProperty£º{FLOWUNID=FBO2018120400000001, PLAN_NUMBER=BQAP(AZ)20181204000101}
|
||
*
|
||
* ÖÆ×÷½áÊøºóµÄ
|
||
* fromCondition£º{FLOWUNID=FBO2018120400000001}
|
||
toCondition£º{contract_id=680f113a87d74d53a6682d8ff4b4d6c0}
|
||
otherProperty£º{PAYMENT_NUMBER=BQAP(AZ)201812040001-01, contract_id=680f113a87d74d53a6682d8ff4b4d6c0}
|
||
|
||
ÌØÓеģº
|
||
paymentNumber£º680f113a87d74d53a6682d8ff4b4d6c0
|
||
contractid£ºBQAP(AZ)201812040001-01
|
||
*/
|
||
Map<String,String> fromCondition=new HashMap<String, String>();
|
||
fromCondition.put("PROJECT_ID", projid);
|
||
List<BizObject> list=DataOperatorUtil.getSetJBO(LC_PROJ_CONDITION.CLASS_NAME, fromCondition, tx);
|
||
Map<String,String> otherProperty=new HashMap<String, String>();
|
||
Map<String,String> toCondition=new HashMap<String, String>();
|
||
String paymentNumber="";
|
||
for (BizObject bo : list) {
|
||
String projPlanNumber=bo.getAttribute("PROJECT_PLAN_NUMBER").getString();
|
||
|
||
String contractPlanNumber=projPlanNumber.replace(projNo, contractNo);
|
||
fromCondition.clear();
|
||
fromCondition.put("PROJECT_ID", projid);
|
||
fromCondition.put("PROJECT_PLAN_NUMBER", projPlanNumber);
|
||
|
||
toCondition.put("contract_id", contractId);
|
||
|
||
paymentNumber=SerialNumberUtil.getPlannumber(contractNo,"pay_process", tx);
|
||
otherProperty.clear();
|
||
otherProperty.put("CONTRACT_PLAN_NUMBER", contractPlanNumber);
|
||
otherProperty.put("contract_id", contractId);
|
||
otherProperty.put("PAYMENT_NUMBER", paymentNumber);
|
||
//ÉÌÎñÌõ¼þ1
|
||
DataOperatorUtil.copyJBOSet(LC_PROJ_CONDITION.CLASS_NAME, fromCondition,LC_CONTRACT_CONDITION.CLASS_NAME, toCondition, otherProperty, null, tx);
|
||
DataOperatorUtil.copyJBOSet(LC_PROJ_CONDITION.CLASS_NAME, fromCondition,LC_CALC_CONDITION.CLASS_NAME, toCondition, otherProperty, null, tx);
|
||
//²âËã×â½ð¹æÔò2
|
||
DataOperatorUtil.copyJBOSet(LC_PROJ_RULES.CLASS_NAME, fromCondition,LC_CONTRACT_RULES.CLASS_NAME, toCondition, otherProperty, null, tx);
|
||
DataOperatorUtil.copyJBOSet(LC_PROJ_RULES.CLASS_NAME, fromCondition,LC_CALC_RULES.CLASS_NAME, toCondition, otherProperty, null, tx);
|
||
//×â½ð¼Æ»®3
|
||
DataOperatorUtil.copyJBOSet(LC_PROJ_RENT_PLAN.CLASS_NAME, fromCondition,LC_CONTRACT_RENT_PLAN.CLASS_NAME, toCondition, otherProperty, null, tx);
|
||
DataOperatorUtil.copyJBOSet(LC_PROJ_RENT_PLAN.CLASS_NAME, fromCondition,LC_PAY_RENT_PLAN.CLASS_NAME, toCondition, otherProperty, null, tx);
|
||
//×â½ð¼Æ»®4
|
||
DataOperatorUtil.copyJBOSet(LC_PROJ_FUND_PLAN.CLASS_NAME, fromCondition,LC_CONTRACT_FUND_PLAN.CLASS_NAME, toCondition, otherProperty, null, tx);
|
||
DataOperatorUtil.copyJBOSet(LC_PROJ_FUND_PLAN.CLASS_NAME, fromCondition,LC_FUND_PLAN.CLASS_NAME, toCondition, otherProperty, null, tx);
|
||
//ÏÖ½ðÁ÷5
|
||
DataOperatorUtil.copyJBOSet(LC_PROJ_CASH_FLOW.CLASS_NAME, fromCondition, LC_CONTRACT_CASH_FLOW.CLASS_NAME, toCondition, otherProperty, null, tx);
|
||
DataOperatorUtil.copyJBOSet(LC_PROJ_CASH_FLOW.CLASS_NAME, fromCondition, LC_PAY_CASH_FLOW.CLASS_NAME, toCondition, otherProperty, null, tx);
|
||
//ÒÑÖª±í6
|
||
DataOperatorUtil.copyJBOSet(LC_PROJ_PERIOD.CLASS_NAME, fromCondition, LC_CONTRACT_PERIOD.CLASS_NAME, toCondition, otherProperty, null, tx);
|
||
DataOperatorUtil.copyJBOSet(LC_PROJ_PERIOD.CLASS_NAME, fromCondition, LC_CALC_PERIOD.CLASS_NAME, toCondition, otherProperty, null, tx);
|
||
//·Ö¶Î²âËã7
|
||
DataOperatorUtil.copyJBOSet(LC_PROJ_SUBSECTION.CLASS_NAME, fromCondition, LC_CONTRACT_SUBSECTION.CLASS_NAME, toCondition, otherProperty, null, tx);
|
||
DataOperatorUtil.copyJBOSet(LC_PROJ_SUBSECTION.CLASS_NAME, fromCondition, LC_CALC_SUBSECTION.CLASS_NAME, toCondition, otherProperty, null, tx);
|
||
|
||
otherProperty.clear();
|
||
otherProperty.put("PLAN_NUMBER", contractPlanNumber);
|
||
//¸¶¿îǰÌá8
|
||
DataOperatorUtil.copyJBOSet(LC_PAY_CONDTION.CLASS_NAME,fromCondition,LC_PAY_CONDTION.CLASS_NAME, toCondition, otherProperty,null, tx);
|
||
}
|
||
//ºÏͬ½áÊøÊǶÀÓеÄ
|
||
BizObject boLCCT = JBOFactory.getBizObjectManager(LC_PROJ_CONDITION.CLASS_NAME,tx)
|
||
.createQuery("PROJECT_ID='"+projid+"'").getSingleResult(false);
|
||
//ÊÖÐø·Ñ
|
||
BigDecimal handMoney = new BigDecimal(boLCCT.getAttribute("HANDLING_CHARGE_MONEY").getString());
|
||
|
||
BizObject boLRPT = JBOFactory.getBizObjectManager(LC_PROJ_RENT_PLAN.CLASS_NAME,tx)
|
||
.createQuery("select v.sum(interest) v.allInterest from O where PROJECT_ID='"+projid+"'").getSingleResult(false);
|
||
|
||
//×ÜÀûÏ¢
|
||
BigDecimal allInterest = new BigDecimal(boLRPT.getAttribute("allInterest").getString());
|
||
|
||
List<BizObject> boLRPTs = JBOFactory.getBizObjectManager(LC_PROJ_RENT_PLAN.CLASS_NAME,tx)
|
||
.createQuery("PROJECT_ID='"+projid+"' order by plan_list").getResultList(false);
|
||
|
||
List<String> dateList = getDateList(boLRPTs);
|
||
//°´ÈÕ¼ÆËãÊÖÐø·Ñ·Ö̯
|
||
List<Map<String,BigDecimal>> 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<String> getDateList(List<BizObject> bos) throws JBOException{
|
||
List<String> dateList = new ArrayList<String>();
|
||
for(BizObject bo:bos){
|
||
dateList.add(bo.getAttribute("PLAN_DATE").getString());
|
||
}
|
||
return dateList;
|
||
}
|
||
|
||
public static List<Map<String,BigDecimal>> gethandMoneyList(String handMoney,List<String> dateList,String startDate,String period_type,String incomeNumberyear){
|
||
List<Map<String,BigDecimal>> handMoneyList=new ArrayList<Map<String,BigDecimal>>();
|
||
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<dateList.size();i++){
|
||
Map<String,BigDecimal> hand = new HashMap<String,BigDecimal>();
|
||
BigDecimal mon=BigDecimal.ZERO;
|
||
BigDecimal ratio=BigDecimal.ZERO;
|
||
long dateDiff=DateTools.getDateDiff(dateList.get(i), startDate);
|
||
if(i<dateList.size()-1){
|
||
BigDecimal cur=new BigDecimal(dateDiff);
|
||
ratio=cur.divide(all,Scale.GENERAL_RATE,BigDecimal.ROUND_HALF_UP);
|
||
mon=hmoney.multiply(cur).divide(all,Scale.CORPUS_SCALE,BigDecimal.ROUND_HALF_UP);
|
||
money=money.add(mon);
|
||
}else{
|
||
mon=hmoney.subtract(money);
|
||
if(hmoney.compareTo(BigDecimal.ZERO) != 0){
|
||
ratio=mon.divide(hmoney,Scale.GENERAL_RATE,BigDecimal.ROUND_HALF_UP);
|
||
}
|
||
}
|
||
hand.put("ratio", ratio);
|
||
hand.put("money", mon);
|
||
handMoneyList.add(hand);
|
||
startDate=dateList.get(i);
|
||
}
|
||
}catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
return handMoneyList;
|
||
}
|
||
}
|