资方租金计划拷贝定时任务及功能优化
This commit is contained in:
parent
33d6fbb58e
commit
d4f06b5729
@ -0,0 +1,352 @@
|
||||
package com.tenwa.lease.app.quartzmession;
|
||||
|
||||
import com.amarsoft.are.ARE;
|
||||
import com.amarsoft.are.jbo.*;
|
||||
import com.amarsoft.are.util.StringFunction;
|
||||
import com.amarsoft.awe.util.Transaction;
|
||||
import com.base.util.QuartzUtil;
|
||||
import com.tenwa.comm.util.jboutil.DataOperatorUtil;
|
||||
import com.tenwa.reckon.executor.CreateTransactionExecutor;
|
||||
import jbo.app.tenwa.calc.LC_CALC_CONDITION;
|
||||
import jbo.app.tenwa.calc.LC_RENT_PLAN;
|
||||
import jbo.app.tenwa.calc.LC_RENT_PLAN_HIS;
|
||||
import jbo.oti.FC_FILE_PUSH;
|
||||
import jbo.oti.FC_YC_FILE_REPAY_PLAN;
|
||||
import jbo.oti.LC_PROFIT_PLAN;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.math.BigDecimal.ROUND_HALF_UP;
|
||||
|
||||
/**
|
||||
* 资方租金计划拷贝
|
||||
*/
|
||||
public class CorpusSourceFileCopy {
|
||||
|
||||
private String contractId;
|
||||
private String fileType;
|
||||
|
||||
public void doCopy(JBOTransaction tx) throws JobExecutionException {
|
||||
BizObjectManager ffpBom = null;
|
||||
Transaction Sqlca = null;
|
||||
try {
|
||||
Sqlca = Transaction.createTransaction(tx);
|
||||
ffpBom = JBOFactory.getBizObjectManager(FC_FILE_PUSH.CLASS_NAME,tx);
|
||||
//todo 添加渠道商的选择,哪些需要拷表哪些不需要
|
||||
String fileSql = "select ID,FILE_STS from O where FILE_TYPE='"+fileType+"' and FILE_STS='2'";
|
||||
List<BizObject> ffpBoList = ffpBom.createQuery(fileSql).getResultList(true);
|
||||
if(ffpBoList.size()==0){
|
||||
ARE.getLog().info("暂时没有需要拷表的资方文件");
|
||||
return;
|
||||
}
|
||||
//遍历解析每个文件
|
||||
for(BizObject ffpBo : ffpBoList){
|
||||
analyticalFile(ffpBo,tx);
|
||||
ffpBo.setAttributeValue("FILE_STS","3");
|
||||
ffpBo.setAttributeValue("FILE_STS_DESC","拷贝成功");
|
||||
ffpBom.saveObject(ffpBo);
|
||||
}
|
||||
Sqlca.commit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
if (Sqlca != null) {
|
||||
Sqlca.rollback();
|
||||
}
|
||||
} catch (JBOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
throw new JobExecutionException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析文件
|
||||
* @param ffpBo
|
||||
* @param tx
|
||||
* @throws Exception
|
||||
*/
|
||||
public void analyticalFile(BizObject ffpBo,JBOTransaction tx) throws Exception {
|
||||
String fcFileId = ffpBo.getAttribute("ID").toString();
|
||||
List<BizObject> fyfrpBoList = getFileInfoByFileId(fcFileId);
|
||||
|
||||
respectiveDo(fyfrpBoList,tx);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行自己类所需的操作
|
||||
* @param fyfrpBoList
|
||||
* @param tx
|
||||
* @throws Exception
|
||||
*/
|
||||
public void respectiveDo(List<BizObject> fyfrpBoList , JBOTransaction tx) throws Exception {
|
||||
//获取对应的合同
|
||||
Map<String,String> contractMap = this.getContractIdMap(fyfrpBoList);
|
||||
if(contractMap.size()==0){
|
||||
String fcFileId = fyfrpBoList.get(0).getAttribute("FC_REQUEST_ID").toString();
|
||||
ARE.getLog().error("未找到FC_REQUEST_ID: "+fcFileId+" 对应的合同ID");
|
||||
throw new Exception("未找到FC_REQUEST_ID: "+fcFileId+" 对应的合同ID");
|
||||
}
|
||||
Transaction Sqlca = Transaction.createTransaction(tx);
|
||||
//===顺序不能错===
|
||||
//0.将租金计划拷贝到历史表
|
||||
copyRentPlanFormatToHis(contractMap,tx);
|
||||
//1.更新租金计划表(直接文件每条信息更新,不需要遍历)
|
||||
updateRentPlan(fyfrpBoList,tx);
|
||||
for(Map.Entry<String,String> entry : contractMap.entrySet()){
|
||||
String contractId = entry.getKey();
|
||||
Map<String ,String > param = getParamByContractId(contractId,tx);
|
||||
//2.更新剩余本金
|
||||
updateAllRemainCorpus(contractId,Sqlca);
|
||||
//3.更新SP分润计划
|
||||
updateSplitSP(param,Sqlca);
|
||||
//4.插入分润计划
|
||||
insertProfitPlan(param,tx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取每个文件的文件信息
|
||||
* @param fcFileId
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public List<BizObject> getFileInfoByFileId(String fcFileId) throws Exception {
|
||||
String sql = "select fr.CONTRACT_ID,O.FC_REQUEST_ID,O.LEND_TERM,O.ANS_REPAYMENT_DATE,O.ANS_PRINCIPAL,O.ANS_INTEREST,ANS_REPAYMENT_MONEY from O left join jbo.oti.FC_REQUEST fr on O.FC_REQUEST_ID=fr.ID where fr.DEL_FLAG='0' and O.FC_FILE_ID=:fcFileId";
|
||||
BizObjectManager fyfrpBom = JBOFactory.getBizObjectManager(FC_YC_FILE_REPAY_PLAN.CLASS_NAME);
|
||||
List<BizObject> fyfrpBoList = fyfrpBom.createQuery(sql).setParameter("fcFileId",fcFileId).getResultList(false);
|
||||
if(fyfrpBoList.size()==0){
|
||||
ARE.getLog().error("未找到FC_REQUEST_ID: "+fcFileId+" 对应的资方还款计划");
|
||||
throw new Exception("未找到FC_REQUEST_ID: "+fcFileId+" 对应的资方还款计划");
|
||||
}
|
||||
return fyfrpBoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* copy租金计划到历史表
|
||||
* @param contractMap
|
||||
* @param tx
|
||||
* @throws Exception
|
||||
*/
|
||||
public void copyRentPlanFormatToHis(Map<String,String> contractMap ,JBOTransaction tx) throws Exception {
|
||||
for(Map.Entry<String,String> entry: contractMap.entrySet()){
|
||||
Map<String,String> fromCondtion=new HashMap<String,String>();
|
||||
fromCondtion.put("CONTRACT_ID",entry.getKey());
|
||||
|
||||
Map<String,String> otherProperty=new HashMap<String,String>();
|
||||
otherProperty.put("MEMO", "安鹏原正式租金计划");
|
||||
otherProperty.put("FLOWUNID", entry.getValue());
|
||||
|
||||
DataOperatorUtil.copyJBOSet(LC_RENT_PLAN.CLASS_NAME, fromCondtion, LC_RENT_PLAN_HIS.CLASS_NAME,null, otherProperty, null, tx);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取对应的合同ID
|
||||
* @param fyfrpBoList
|
||||
* @return
|
||||
* @throws JBOException
|
||||
*/
|
||||
public Map<String,String> getContractIdMap(List<BizObject> fyfrpBoList) throws JBOException {
|
||||
Map<String,String> contractMap = new HashMap<>();
|
||||
for(BizObject bo : fyfrpBoList){
|
||||
String contractId = bo.getAttribute("CONTRACT_ID").toString();
|
||||
String fcRequestId = bo.getAttribute("FC_REQUEST_ID").toString();
|
||||
contractMap.put(contractId,fcRequestId);
|
||||
}
|
||||
return contractMap;
|
||||
}
|
||||
/**
|
||||
* 租金计划拷贝
|
||||
* @param fyfrpBoList 每个回执文件包含的租金计划信息
|
||||
* @return 每个回执文件包含的contract_id
|
||||
* @throws JBOException
|
||||
* @throws ParseException
|
||||
*/
|
||||
public void updateRentPlan(List<BizObject> fyfrpBoList,JBOTransaction tx) throws JBOException, ParseException {
|
||||
BizObjectManager lrpBom = null;
|
||||
lrpBom = JBOFactory.getBizObjectManager(LC_RENT_PLAN.CLASS_NAME,tx);
|
||||
//更新租金计划表
|
||||
for(BizObject bo : fyfrpBoList){
|
||||
//获取参数
|
||||
String contractId = bo.getAttribute("CONTRACT_ID").toString();
|
||||
String lendTerm = bo.getAttribute("LEND_TERM").toString();
|
||||
String principal = bo.getAttribute("ANS_PRINCIPAL").toString();
|
||||
String interest = bo.getAttribute("ANS_INTEREST").toString();
|
||||
String rent = new BigDecimal(principal).add(new BigDecimal(interest)).toString();
|
||||
String repaymentMoney = bo.getAttribute("ANS_REPAYMENT_MONEY").toString();
|
||||
String repaymentDate = bo.getAttribute("ANS_REPAYMENT_DATE").toString();
|
||||
//转换日期格式
|
||||
Date date = new SimpleDateFormat("yyyyMMdd").parse(repaymentDate);
|
||||
repaymentDate = new SimpleDateFormat("yyyy/MM/dd").format(date);
|
||||
//更新租金计划表
|
||||
BizObject lrpBo = lrpBom.createQuery("CONTRACT_ID=:contractId and PLAN_LIST=:lendTerm").setParameter("contractId",contractId).setParameter("lendTerm",lendTerm).getSingleResult(true);
|
||||
lrpBo.setAttributeValue("RENT",rent);
|
||||
lrpBo.setAttributeValue("CORPUS",principal);
|
||||
lrpBo.setAttributeValue("INTEREST",interest);
|
||||
lrpBo.setAttributeValue("CORPUS_BUSINESS",principal);
|
||||
lrpBo.setAttributeValue("INTEREST_BUSINESS",interest);
|
||||
lrpBo.setAttributeValue("PLAN_DATE",repaymentDate);
|
||||
lrpBo.setAttributeValue("RENT",repaymentMoney);
|
||||
lrpBom.saveObject(lrpBo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新剩余本金信息
|
||||
* @throws JBOException
|
||||
*/
|
||||
public void updateAllRemainCorpus(String contractId,JBOTransaction tx) throws JBOException {
|
||||
BizObjectManager lrpBom = null;
|
||||
lrpBom = JBOFactory.getBizObjectManager(LC_RENT_PLAN.CLASS_NAME,tx);
|
||||
BizObjectManager lccBom = null;
|
||||
lccBom = JBOFactory.getBizObjectManager(LC_CALC_CONDITION.CLASS_NAME,tx);
|
||||
|
||||
BizObject lccBo = lccBom.createQuery("select CLEAN_LEASE_MONEY from O where contract_id=:contractId").setParameter("contractId",contractId).getSingleResult(false);
|
||||
String clean_lease_money = lccBo.getAttribute("CLEAN_LEASE_MONEY").toString();
|
||||
BigDecimal cleanLeaseMoneyBd = new BigDecimal(clean_lease_money);
|
||||
List<BizObject> lrpBos= lrpBom.createQuery("contract_id=:contractId order by plan_list").setParameter("contractId",contractId).getResultList(true);
|
||||
for(BizObject bo :lrpBos){
|
||||
String corpus = bo.getAttribute("corpus").toString();
|
||||
BigDecimal corpusBd = new BigDecimal(corpus);
|
||||
cleanLeaseMoneyBd = cleanLeaseMoneyBd.subtract(corpusBd).setScale(2,ROUND_HALF_UP);
|
||||
bo.setAttributeValue("ALL_REMAIN_CORPUS",cleanLeaseMoneyBd.toString());
|
||||
lrpBom.saveObject(bo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新剩余本金信息
|
||||
* @throws JBOException
|
||||
*/
|
||||
public void updateAllRemainCorpus(JBOTransaction tx) throws JBOException {
|
||||
updateAllRemainCorpus(contractId,tx);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新分润信息
|
||||
* @throws Exception
|
||||
*/
|
||||
public void updateSplitSP(Map<String,String> param,Transaction Sqlca) throws Exception {
|
||||
|
||||
String splittingRatio = param.get("splittingRatio");
|
||||
//必须的判断条件(配置了灵活分润的产品可能没有配置分润)
|
||||
// 判断顺序,是否分润--》是否灵活分润
|
||||
//是否灵活分润在insertRentPlan_SP()方法中判断
|
||||
if (!"".equals(splittingRatio) && splittingRatio != null) {
|
||||
String paymentNumber = param.get("paymentNumber");
|
||||
String splitType = param.get("splitType");
|
||||
CreateTransactionExecutor cre = new CreateTransactionExecutor();
|
||||
cre.setPlannumber(paymentNumber);
|
||||
cre.insertRentPlan_SP(splittingRatio, Sqlca, splitType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新分润信息
|
||||
* @throws Exception
|
||||
*/
|
||||
public void updateSplitSP(JBOTransaction tx) {
|
||||
Transaction Sqlca = null;
|
||||
try {
|
||||
Sqlca = Transaction.createTransaction(tx);
|
||||
Map<String,String> param = getParamByContractId(contractId,tx);
|
||||
updateSplitSP(param,Sqlca);
|
||||
} catch (JBOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
if (Sqlca != null) {
|
||||
Sqlca.rollback();
|
||||
}
|
||||
} catch (JBOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取每个合同的参数
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Map<String,String> getParamByContractId(String contractId,JBOTransaction tx) throws Exception {
|
||||
String sql = "select * from vi_corpus_source_param where contractId='" + contractId + "'";
|
||||
List<Map<String,String>> data = DataOperatorUtil.getDataBySql(sql,tx);
|
||||
return data.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取每个合同的参数
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Map<String,String> getParamByContractId(JBOTransaction tx) throws Exception {
|
||||
return getParamByContractId(contractId,tx);
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入分润计划
|
||||
* @param param
|
||||
* @throws JBOException
|
||||
*/
|
||||
public void insertProfitPlan(Map<String,String> param,JBOTransaction tx) throws JBOException {
|
||||
BizObjectManager lppBom = null;
|
||||
lppBom = JBOFactory.getBizObjectManager(LC_PROFIT_PLAN.CLASS_NAME,tx);
|
||||
BizObjectManager lrpBom = null;
|
||||
lrpBom = JBOFactory.getBizObjectManager(LC_RENT_PLAN.CLASS_NAME,tx);
|
||||
BizObject lppBo = null;
|
||||
String paymentNumber = param.get("paymentNumber");
|
||||
String corpusSourceRate = param.get("corpusSourceRate");
|
||||
List<BizObject> lrpBos = lrpBom.createQuery("PAYMENT_NUMBER=:paymentNumber order by plan_list").setParameter("paymentNumber",paymentNumber).getResultList(false);
|
||||
for(BizObject bo :lrpBos){
|
||||
String rentPlanId = bo.getAttribute("ID").toString();
|
||||
String interest = bo.getAttribute("INTEREST").toString();
|
||||
String yearRate = bo.getAttribute("YEAR_RATE").toString();
|
||||
String profit = new BigDecimal(yearRate).subtract(new BigDecimal(corpusSourceRate)).divide(new BigDecimal(yearRate),6,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(interest)).setScale(2,BigDecimal.ROUND_HALF_UP).toString();
|
||||
lppBo = lppBom.newObject();
|
||||
lppBo.setAttributeValue("rent_plan_id",rentPlanId);
|
||||
lppBo.setAttributeValue("CORPUS_RATE",corpusSourceRate);
|
||||
lppBo.setAttributeValue("profit",profit);
|
||||
lppBo.setAttributeValue("inputtime",StringFunction.getTodayNow());
|
||||
lppBom.saveObject(lppBo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入分润计划
|
||||
* @param tx
|
||||
* @throws JBOException
|
||||
*/
|
||||
public void insertProfitPlan(JBOTransaction tx) throws Exception {
|
||||
Map<String,String> param = getParamByContractId(contractId,tx);
|
||||
insertProfitPlan(param,tx);
|
||||
}
|
||||
|
||||
public String getContractId() {
|
||||
return contractId;
|
||||
}
|
||||
|
||||
public void setContractId(String contractId) {
|
||||
this.contractId = contractId;
|
||||
}
|
||||
|
||||
public String getFileType() { return fileType; }
|
||||
|
||||
public void setFileType(String fileType) { this.fileType = fileType; }
|
||||
|
||||
}
|
||||
@ -27,86 +27,29 @@ import static java.math.BigDecimal.ROUND_HALF_UP;
|
||||
/**
|
||||
* 资方租金计划拷贝
|
||||
*/
|
||||
public class CorpusSourceRentPlanCopy implements Job {
|
||||
public class CorpusSourceRentPlanCopy extends CorpusSourceFileCopy implements Job {
|
||||
|
||||
private String contractId;
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
|
||||
String startime = StringFunction.getTodayNow();
|
||||
Object userId = jobExecutionContext.getTrigger().getJobDataMap().get("CurUserId");
|
||||
String curUserId = userId == null? "system" : userId.toString();
|
||||
|
||||
BizObjectManager ffpBom = null;
|
||||
BizObjectManager fyfrpBom = null;
|
||||
|
||||
JBOTransaction tx = null;
|
||||
Transaction Sqlca = null;
|
||||
|
||||
try {
|
||||
tx = JBOFactory.createJBOTransaction();
|
||||
Sqlca = Transaction.createTransaction(tx);
|
||||
ffpBom = JBOFactory.getBizObjectManager(FC_FILE_PUSH.CLASS_NAME,tx);
|
||||
fyfrpBom = JBOFactory.getBizObjectManager(FC_YC_FILE_REPAY_PLAN.CLASS_NAME,tx);
|
||||
//todo 添加渠道商的选择,哪些需要拷表哪些不需要
|
||||
List<BizObject> ffpBoList = ffpBom.createQuery("select ID,FILE_STS from O where FILE_STS='2'").getResultList(true);
|
||||
if(ffpBoList.size()==0){
|
||||
ARE.getLog().info("暂时没有需要拷表的资方文件");
|
||||
return;
|
||||
}
|
||||
//遍历每个文件
|
||||
for(BizObject ffpBo : ffpBoList){
|
||||
String fcFileId = ffpBo.getAttribute("ID").toString();
|
||||
String sql = "select fr.CONTRACT_ID,O.FC_REQUEST_ID,O.LEND_TERM,O.ANS_REPAYMENT_DATE,O.ANS_PRINCIPAL,O.ANS_INTEREST,ANS_REPAYMENT_MONEY from O left join jbo.oti.FC_REQUEST fr on O.FC_REQUEST_ID=fr.ID where fr.DEL_FLAG='0' and O.FC_FILE_ID=:fcFileId";
|
||||
List<BizObject> fyfrpBoList = fyfrpBom.createQuery(sql).setParameter("fcFileId",fcFileId).getResultList(false);
|
||||
if(fyfrpBoList.size()==0){
|
||||
ARE.getLog().error("未找到FC_REQUEST_ID: "+fcFileId+" 对应的资方还款计划");
|
||||
throw new Exception("未找到FC_REQUEST_ID: "+fcFileId+" 对应的资方还款计划");
|
||||
}
|
||||
//获取对应的合同
|
||||
Map<String,String> contractMap = this.getContractIdMap(fyfrpBoList);
|
||||
if(contractMap.size()==0){
|
||||
ARE.getLog().error("未找到FC_REQUEST_ID: "+fcFileId+" 对应的合同ID");
|
||||
throw new Exception("未找到FC_REQUEST_ID: "+fcFileId+" 对应的合同ID");
|
||||
}
|
||||
//0.租金计划正式表考入历史表
|
||||
for(Map.Entry<String,String> entry: contractMap.entrySet()){
|
||||
Map<String,String> fromCondtion=new HashMap<String,String>();
|
||||
fromCondtion.put("CONTRACT_ID",entry.getKey());
|
||||
|
||||
Map<String,String> otherProperty=new HashMap<String,String>();
|
||||
otherProperty.put("MEMO", "安鹏原正式租金计划");
|
||||
otherProperty.put("FLOWUNID", entry.getValue());
|
||||
|
||||
DataOperatorUtil.copyJBOSet(LC_RENT_PLAN.CLASS_NAME, fromCondtion, LC_RENT_PLAN_HIS.CLASS_NAME,null, otherProperty, null, Sqlca);
|
||||
}
|
||||
//1.更新租金计划(直接文件每条信息更新,不需要遍历)
|
||||
this.updateRentPlan(fyfrpBoList,tx);
|
||||
|
||||
for(Map.Entry<String,String> entry: contractMap.entrySet()){
|
||||
String contractId = entry.getKey();
|
||||
Map<String,String> param= this.getParamByContractId(contractId,tx);
|
||||
//2.更新租金计划剩余本金
|
||||
this.updateAllRemainCorpus(contractId,tx);
|
||||
//3.更新租金计划分润信息
|
||||
this.updateSplitSP(param,Sqlca);
|
||||
//4.插入分润计划
|
||||
this.insertProfitPlan(param,tx);
|
||||
}
|
||||
ffpBo.setAttributeValue("FILE_STS","3");
|
||||
ffpBo.setAttributeValue("FILE_STS_DESC","拷贝成功");
|
||||
ffpBom.saveObject(ffpBo);
|
||||
}
|
||||
|
||||
Sqlca.commit();
|
||||
setFileType("RepayPlan");
|
||||
doCopy(tx);
|
||||
tx.commit();
|
||||
QuartzUtil.insertLog(startime,"com.tenwa.lease.app.quartzmession.CorpusSourceRentPlanCopy", "success", "成功", curUserId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
QuartzUtil.insertLog(startime,"com.tenwa.lease.app.quartzmession.CorpusSourceRentPlanCopy", "error", "失败", curUserId);
|
||||
try {
|
||||
if (Sqlca != null) {
|
||||
Sqlca.rollback();
|
||||
if (tx != null) {
|
||||
tx.rollback();
|
||||
}
|
||||
} catch (JBOException e1) {
|
||||
e1.printStackTrace();
|
||||
@ -116,196 +59,54 @@ public class CorpusSourceRentPlanCopy implements Job {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对应的合同ID
|
||||
* 执行自己类所需的操作
|
||||
* @param fyfrpBoList
|
||||
* @return
|
||||
* @throws JBOException
|
||||
*/
|
||||
public Map<String,String> getContractIdMap(List<BizObject> fyfrpBoList) throws JBOException {
|
||||
Map<String,String> contractMap = new HashMap<>();
|
||||
for(BizObject bo : fyfrpBoList){
|
||||
String contractId = bo.getAttribute("CONTRACT_ID").toString();
|
||||
String fcRequestId = bo.getAttribute("FC_REQUEST_ID").toString();
|
||||
contractMap.put(contractId,fcRequestId);
|
||||
}
|
||||
return contractMap;
|
||||
}
|
||||
/**
|
||||
* 租金计划拷贝
|
||||
* @param fyfrpBoList 每个回执文件包含的租金计划信息
|
||||
* @return 每个回执文件包含的contract_id
|
||||
* @throws JBOException
|
||||
* @throws ParseException
|
||||
*/
|
||||
public void updateRentPlan(List<BizObject> fyfrpBoList,JBOTransaction tx) throws JBOException, ParseException {
|
||||
BizObjectManager lrpBom = null;
|
||||
lrpBom = JBOFactory.getBizObjectManager(LC_RENT_PLAN.CLASS_NAME,tx);
|
||||
//更新租金计划表
|
||||
for(BizObject bo : fyfrpBoList){
|
||||
//获取参数
|
||||
String contractId = bo.getAttribute("CONTRACT_ID").toString();
|
||||
String lendTerm = bo.getAttribute("LEND_TERM").toString();
|
||||
String principal = bo.getAttribute("ANS_PRINCIPAL").toString();
|
||||
String interest = bo.getAttribute("ANS_INTEREST").toString();
|
||||
String repaymentMoney = bo.getAttribute("ANS_REPAYMENT_MONEY").toString();
|
||||
String repaymentDate = bo.getAttribute("ANS_REPAYMENT_DATE").toString();
|
||||
//转换日期格式
|
||||
Date date = new SimpleDateFormat("yyyyMMdd").parse(repaymentDate);
|
||||
repaymentDate = new SimpleDateFormat("yyyy/MM/dd").format(date);
|
||||
//更新租金计划表
|
||||
BizObject lrpBo = lrpBom.createQuery("CONTRACT_ID=:contractId and PLAN_LIST=:lendTerm").setParameter("contractId",contractId).setParameter("lendTerm",lendTerm).getSingleResult(true);
|
||||
lrpBo.setAttributeValue("RENT",repaymentMoney);
|
||||
lrpBo.setAttributeValue("CORPUS",principal);
|
||||
lrpBo.setAttributeValue("INTEREST",interest);
|
||||
lrpBo.setAttributeValue("CORPUS_BUSINESS",principal);
|
||||
lrpBo.setAttributeValue("INTEREST_BUSINESS",interest);
|
||||
lrpBo.setAttributeValue("PLAN_DATE",repaymentDate);
|
||||
lrpBo.setAttributeValue("RENT",repaymentMoney);
|
||||
lrpBom.saveObject(lrpBo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新剩余本金信息
|
||||
* @throws JBOException
|
||||
*/
|
||||
public void updateAllRemainCorpus(String contractId,JBOTransaction tx) throws JBOException {
|
||||
BizObjectManager lrpBom = null;
|
||||
lrpBom = JBOFactory.getBizObjectManager(LC_RENT_PLAN.CLASS_NAME,tx);
|
||||
BizObjectManager lccBom = null;
|
||||
lccBom = JBOFactory.getBizObjectManager(LC_CALC_CONDITION.CLASS_NAME,tx);
|
||||
|
||||
BizObject lccBo = lccBom.createQuery("select CLEAN_LEASE_MONEY from O where contract_id=:contractId").setParameter("contractId",contractId).getSingleResult(false);
|
||||
String clean_lease_money = lccBo.getAttribute("CLEAN_LEASE_MONEY").toString();
|
||||
BigDecimal cleanLeaseMoneyBd = new BigDecimal(clean_lease_money);
|
||||
List<BizObject> lrpBos= lrpBom.createQuery("contract_id=:contractId order by plan_list").setParameter("contractId",contractId).getResultList(true);
|
||||
for(BizObject bo :lrpBos){
|
||||
String corpus = bo.getAttribute("corpus").toString();
|
||||
BigDecimal corpusBd = new BigDecimal(corpus);
|
||||
cleanLeaseMoneyBd = cleanLeaseMoneyBd.subtract(corpusBd).setScale(2,ROUND_HALF_UP);
|
||||
bo.setAttributeValue("ALL_REMAIN_CORPUS",cleanLeaseMoneyBd.toString());
|
||||
lrpBom.saveObject(bo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新剩余本金信息
|
||||
* @throws JBOException
|
||||
*/
|
||||
public void updateAllRemainCorpus(JBOTransaction tx) throws JBOException {
|
||||
this.updateAllRemainCorpus(contractId,tx);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新分润信息
|
||||
* @throws Exception
|
||||
*/
|
||||
public void updateSplitSP(Map<String,String> param,Transaction Sqlca) throws Exception {
|
||||
|
||||
String splittingRatio = param.get("splittingRatio");
|
||||
//必须的判断条件(配置了灵活分润的产品可能没有配置分润)
|
||||
// 判断顺序,是否分润--》是否灵活分润
|
||||
//是否灵活分润在insertRentPlan_SP()方法中判断
|
||||
if (!"".equals(splittingRatio) && splittingRatio != null) {
|
||||
String paymentNumber = param.get("paymentNumber");
|
||||
String splitType = param.get("splitType");
|
||||
CreateTransactionExecutor cre = new CreateTransactionExecutor();
|
||||
cre.setPlannumber(paymentNumber);
|
||||
cre.insertRentPlan_SP(splittingRatio, Sqlca, splitType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新分润信息
|
||||
* @throws Exception
|
||||
*/
|
||||
public void updateSplitSP(JBOTransaction tx) {
|
||||
Transaction Sqlca = null;
|
||||
try {
|
||||
Sqlca = Transaction.createTransaction(tx);
|
||||
Map<String,String> param = this.getParamByContractId(contractId,tx);
|
||||
this.updateSplitSP(param,Sqlca);
|
||||
} catch (JBOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
if (Sqlca != null) {
|
||||
Sqlca.rollback();
|
||||
}
|
||||
} catch (JBOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取每个合同的参数
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Map<String,String> getParamByContractId(String contractId,JBOTransaction tx) throws Exception {
|
||||
String sql = "select * from vi_corpus_source_param where contractId='" + contractId + "'";
|
||||
List<Map<String,String>> data = DataOperatorUtil.getDataBySql(sql,tx);
|
||||
return data.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取每个合同的参数
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Map<String,String> getParamByContractId(JBOTransaction tx) throws Exception {
|
||||
return this.getParamByContractId(contractId,tx);
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入分润计划
|
||||
* @param param
|
||||
* @throws JBOException
|
||||
*/
|
||||
public void insertProfitPlan(Map<String,String> param,JBOTransaction tx) throws JBOException {
|
||||
BizObjectManager lppBom = null;
|
||||
lppBom = JBOFactory.getBizObjectManager(LC_PROFIT_PLAN.CLASS_NAME,tx);
|
||||
BizObjectManager lrpBom = null;
|
||||
lrpBom = JBOFactory.getBizObjectManager(LC_RENT_PLAN.CLASS_NAME,tx);
|
||||
BizObject lppBo = null;
|
||||
String paymentNumber = param.get("paymentNumber");
|
||||
String corpusSourceRate = param.get("corpusSourceRate");
|
||||
List<BizObject> lrpBos = lrpBom.createQuery("PAYMENT_NUMBER=:paymentNumber order by plan_list").setParameter("paymentNumber",paymentNumber).getResultList(false);
|
||||
for(BizObject bo :lrpBos){
|
||||
String rentPlanId = bo.getAttribute("ID").toString();
|
||||
String interest = bo.getAttribute("INTEREST").toString();
|
||||
String yearRate = bo.getAttribute("YEAR_RATE").toString();
|
||||
String profit = new BigDecimal(yearRate).subtract(new BigDecimal(corpusSourceRate)).divide(new BigDecimal(yearRate),6,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(interest)).setScale(2,BigDecimal.ROUND_HALF_UP).toString();
|
||||
lppBo = lppBom.newObject();
|
||||
lppBo.setAttributeValue("rent_plan_id",rentPlanId);
|
||||
lppBo.setAttributeValue("CORPUS_RATE",corpusSourceRate);
|
||||
lppBo.setAttributeValue("profit",profit);
|
||||
lppBo.setAttributeValue("inputtime",StringFunction.getTodayNow());
|
||||
lppBom.saveObject(lppBo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入分润计划
|
||||
* @param tx
|
||||
* @throws JBOException
|
||||
* @throws Exception
|
||||
*/
|
||||
public void insertProfitPlan(JBOTransaction tx) throws Exception {
|
||||
Map<String,String> param = this.getParamByContractId(contractId,tx);
|
||||
this.insertProfitPlan(param,tx);
|
||||
public void respectiveDo(List<BizObject> fyfrpBoList , JBOTransaction tx) throws Exception {
|
||||
//获取对应的合同
|
||||
Map<String,String> contractMap = getContractIdMap(fyfrpBoList);
|
||||
if(contractMap.size()==0){
|
||||
String fcFileId = fyfrpBoList.get(0).getAttribute("FC_REQUEST_ID").toString();
|
||||
ARE.getLog().error("未找到FC_REQUEST_ID: "+fcFileId+" 对应的合同ID");
|
||||
throw new Exception("未找到FC_REQUEST_ID: "+fcFileId+" 对应的合同ID");
|
||||
}
|
||||
Transaction Sqlca = Transaction.createTransaction(tx);
|
||||
//===顺序不能错===
|
||||
//0.将租金计划拷贝到历史表
|
||||
copyRentPlanFormatToHis(contractMap,tx);
|
||||
//1.更新租金计划表(直接文件每条信息更新,不需要遍历)
|
||||
updateRentPlan(fyfrpBoList,tx);
|
||||
for(Map.Entry<String,String> entry : contractMap.entrySet()){
|
||||
String contractId = entry.getKey();
|
||||
Map<String ,String > param = getParamByContractId(contractId,tx);
|
||||
//2.更新剩余本金
|
||||
updateAllRemainCorpus(contractId,Sqlca);
|
||||
//3.更新SP分润计划
|
||||
updateSplitSP(param,Sqlca);
|
||||
//4.插入分润计划
|
||||
insertProfitPlan(param,tx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getContractId() {
|
||||
return contractId;
|
||||
/**
|
||||
* 根据文件ID获取《租金计划》信息
|
||||
* @param fcFileId
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public List<BizObject> getFileInfoByFileId(String fcFileId) throws Exception {
|
||||
String sql = "select fr.CONTRACT_ID,O.FC_REQUEST_ID,O.LEND_TERM,O.ANS_REPAYMENT_DATE,O.ANS_PRINCIPAL,O.ANS_INTEREST,ANS_REPAYMENT_MONEY from O left join jbo.oti.FC_REQUEST fr on O.FC_REQUEST_ID=fr.ID where fr.DEL_FLAG='0' and O.FC_FILE_ID=:fcFileId";
|
||||
BizObjectManager fyfrpBom = JBOFactory.getBizObjectManager(FC_YC_FILE_REPAY_PLAN.CLASS_NAME);
|
||||
List<BizObject> fyfrpBoList = fyfrpBom.createQuery(sql).setParameter("fcFileId",fcFileId).getResultList(false);
|
||||
if(fyfrpBoList.size()==0){
|
||||
ARE.getLog().error("未找到FC_REQUEST_ID: "+fcFileId+" 对应的资方还款计划");
|
||||
throw new Exception("未找到FC_REQUEST_ID: "+fcFileId+" 对应的资方还款计划");
|
||||
}
|
||||
return fyfrpBoList;
|
||||
}
|
||||
|
||||
public void setContractId(String contractId) {
|
||||
this.contractId = contractId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user