package com.tenwa.flow.rent.rentincome; import java.math.BigDecimal; import java.sql.*; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.Date; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; import java.util.stream.Collectors; import cn.hutool.db.Entity; import cn.hutool.db.handler.EntityHandler; import cn.hutool.db.handler.EntityListHandler; import cn.hutool.db.handler.NumberHandler; import com.amarsoft.are.ARE; import com.amarsoft.are.log.Log; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; import com.tenwa.lease.service.LCOccupyRentListService; import com.tenwa.util.JsonUtil; import com.tenwa.util.SqlRunnerUtil; import org.apache.commons.lang3.tuple.Pair; import org.springframework.web.context.ContextLoader; import org.springframework.web.context.WebApplicationContext; import jbo.app.tenwa.calc.LC_CARD_DEDUCT_DOC_TEMP; import jbo.app.tenwa.calc.LC_EBANK_PROCESS; import jbo.app.tenwa.calc.LC_EBANK_TEMP; import jbo.app.tenwa.calc.LC_FUND_INCOME; import jbo.app.tenwa.calc.LC_FUND_INCOME_TEMP; import jbo.app.tenwa.calc.LC_FUND_PLAN; import jbo.app.tenwa.calc.LC_RENT_INCOME; import jbo.app.tenwa.calc.LC_RENT_INCOME_TEMP; import jbo.app.tenwa.calc.LC_RENT_PLAN; import jbo.app.tenwa.calc.VI_CARD_DEDUCT_DATA; import jbo.app.tenwa.calc.VI_LC_RENT_PLAN; import jbo.com.tenwa.lease.comm.LB_CONTRACT_INFO; import jbo.com.tenwa.lease.comm.LC_OCCUPY_RENT_LIST; import com.amarsoft.app.awe.config.InitDBType; import com.amarsoft.app.util.ProductParamUtil; 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.are.util.StringFunction; import com.amarsoft.awe.util.Transaction; import com.mchange.v2.c3p0.ComboPooledDataSource; import com.tenwa.reckon.constant.Scale; import com.tenwa.reckon.util.UUIDUtil; public class RentIncomeMethod { protected static Log logger = ARE.getLog(); private String planIDs; private String flowunid; private String overCorpuss; private String overInterests; private String overPenaltys; private String balance; private String portionCollectionID; private String portionMoney; private String oldFactMoney; private String newFactMoney; private String cautionDeductionIDs; private String ids;//实际回笼临时表标识 private String isChanged;//操作时后台数据库产生变化开关 private String sql; private String userid; private String orgid; private String deductDocId; private String params; public String getDeductDocId() { return deductDocId; } public void setDeductDocId(String deductDocId) { this.deductDocId = deductDocId; } public String getUserid() { return userid; } public void setUserid(String userid) { this.userid = userid; } public String getOrgid() { return orgid; } public void setOrgid(String orgid) { this.orgid = orgid; } public String getSql() { return sql; } public void setSql(String sql) { this.sql = sql; } public String getIsChanged() { return isChanged; } public void setIsChanged(String isChanged) { this.isChanged = isChanged; } public String getIds() { return ids; } public void setIds(String ids) { this.ids = ids; } public String getCautionDeductionIDs() { return cautionDeductionIDs; } public void setCautionDeductionIDs(String cautionDeductionIDs) { this.cautionDeductionIDs = cautionDeductionIDs; } public String getFlowunid() { return flowunid; } public void setFlowunid(String flowunid) { this.flowunid = flowunid; } public String getPlanIDs() { return planIDs; } public void setPlanIDs(String planIDs) { this.planIDs = planIDs; } public String getOverCorpuss() { return overCorpuss; } public void setOverCorpuss(String overCorpuss) { this.overCorpuss = overCorpuss; } public String getOverInterests() { return overInterests; } public void setOverInterests(String overInterests) { this.overInterests = overInterests; } public String getOverPenaltys() { return overPenaltys; } public void setOverPenaltys(String overPenaltys) { this.overPenaltys = overPenaltys; } public String getBalance() { return balance; } public void setBalance(String balance) { this.balance = balance; } public String getPortionCollectionID() { return portionCollectionID; } public void setPortionCollectionID(String portionCollectionID) { this.portionCollectionID = portionCollectionID; } public String getPortionMoney() { return portionMoney; } public void setPortionMoney(String portionMoney) { this.portionMoney = portionMoney; } public String getOldFactMoney() { return oldFactMoney; } public void setOldFactMoney(String oldFactMoney) { this.oldFactMoney = oldFactMoney; } public String getNewFactMoney() { return newFactMoney; } public void setNewFactMoney(String newFactMoney) { this.newFactMoney = newFactMoney; } public String getParams() { return params; } public void setParams(String params) { this.params = params; } /** * 租金核销 */ public String setRentDataToRentIncome(JBOTransaction tx) throws JBOException { try { boolean flag = false; if ("Y".equals(isChanged)) { flag = true; } BigDecimal bel = new BigDecimal(balance == null ? "0" : balance); //可核销金额 BigDecimal allFactMoney = bel; BizObjectManager bomEb = JBOFactory.getBizObjectManager(LC_EBANK_TEMP.CLASS_NAME); tx.join(bomEb); BizObject boEb = bomEb.createQuery("FLOWUNID=:FLOWUNID") .setParameter("FLOWUNID", flowunid).getSingleResult(true); if (flag) { bel = new BigDecimal(boEb.getAttribute("MAYOPE_MONEY").getString()); allFactMoney = bel; } String[] ids = planIDs.split("@"); String[] corpuss = new String[ids.length]; String[] interests = new String[ids.length]; String[] Penaltys = new String[ids.length]; if (overCorpuss != null) { corpuss = overCorpuss.split("@"); interests = overInterests.split("@"); Penaltys = overPenaltys.split("@"); } String factDate = boEb.getAttribute("FACT_DATE").getString(); Date f = new SimpleDateFormat("yyyy/MM/dd").parse(factDate); for (int i = 0; i < ids.length; i++) { BizObject boVLRP = JBOFactory.createBizObjectQuery(LC_RENT_PLAN.CLASS_NAME, "ID=:ID").setParameter("ID", ids[i]) .getSingleResult(false); BizObject boLCI = JBOFactory.createBizObjectQuery(LB_CONTRACT_INFO.CLASS_NAME, "ID=:ID") .setParameter("ID", boVLRP.getAttribute("CONTRACT_ID").getString()) .getSingleResult(false); Map>> paymentOrders = ProductParamUtil .getProductComponentDecisionTable(boLCI.getAttribute("PRODUCT_ID").getString(), "PRD0307", "rmoname", "rmosortno"); String penaltyRule = ProductParamUtil .getProductParameterValue(boLCI.getAttribute("PRODUCT_ID").getString(), "PRD0307", "PenaltyRule", "PenaltyRule"); String[] paymentOrder = new String[3]; String planDate = boVLRP.getAttribute("PLAN_DATE").getString(); if (f.compareTo(new SimpleDateFormat("yyyy/MM/dd").parse(planDate)) > 0) { for (int j = 0; j < paymentOrders.get("RMO-02").size(); j++) { paymentOrder[Integer.parseInt(paymentOrders.get("RMO-02").get(j).get("rmosortno")) - 1] = paymentOrders.get("RMO-02").get(j).get("rmoname"); } } else { for (int j = 0; j < paymentOrders.get("RMO-01").size(); j++) { paymentOrder[Integer.parseInt(paymentOrders.get("RMO-01").get(j).get("rmosortno")) - 1] = paymentOrders.get("RMO-01").get(j).get("rmoname"); } } if ("penalty_income".equals(penaltyRule)) { Penaltys[i] = "0.00"; } BizObjectManager boLRI = JBOFactory.getBizObjectManager(LC_RENT_INCOME_TEMP.CLASS_NAME); BizObjectManager bomLORL = JBOFactory.getBizObjectManager(LC_OCCUPY_RENT_LIST.CLASS_NAME, tx); BizObject boLORL = bomLORL.newObject(); boLORL.setAttributeValue("ID", UUIDUtil.getUUID()); boLORL.setAttributeValue("PAYMENT_NUMBER", boVLRP.getAttribute("PAYMENT_NUMBER").getString()); boLORL.setAttributeValue("PLAN_LIST", boVLRP.getAttribute("PLAN_LIST").getString()); boLORL.setAttributeValue("PLAN_ID", boVLRP.getAttribute("ID").getString()); boLORL.setAttributeValue("FLOW_NAME", "网银收款"); boLORL.setAttributeValue("FLOWUNID", flowunid); boLORL.setAttributeValue(LC_OCCUPY_RENT_LIST.INPUTTIME, StringFunction.getTodayNow()); bomLORL.saveObject(boLORL); tx.join(boLRI); BizObject boLRIT = boLRI.newObject(); boLRIT.setAttributeValue("QUOT_ID", boVLRP.getAttribute("QUOT_ID").getString()); boLRIT.setAttributeValue("CUST_ID", boVLRP.getAttribute("CUST_ID").getString()); boLRIT.setAttributeValue("PROJECT_ID", boVLRP.getAttribute("PROJECT_ID").getString()); boLRIT.setAttributeValue("PROJECT_PLAN_NUMBER", boVLRP.getAttribute("PROJECT_PLAN_NUMBER").getString()); boLRIT.setAttributeValue("CONTRACT_ID", boVLRP.getAttribute("CONTRACT_ID").getString()); boLRIT.setAttributeValue("CONTRACT_PLAN_NUMBER", boVLRP.getAttribute("CONTRACT_PLAN_NUMBER").getString()); boLRIT.setAttributeValue("PAYMENT_NUMBER", boVLRP.getAttribute("PAYMENT_NUMBER").getString()); boLRIT.setAttributeValue("EBANK_NUMBER", boEb.getAttribute("EBANK_NUMBER").getString()); boLRIT.setAttributeValue("PLAN_ID", ids[i]); boLRIT.setAttributeValue("PLAN_LIST", boVLRP.getAttribute("PLAN_LIST").getString()); boLRIT.setAttributeValue("INTEREST_ADJUST", 0); boLRIT.setAttributeValue("SETTLE_METHOD", "settlemethod6"); List boLCRI = JBOFactory.createBizObjectQuery(LC_RENT_INCOME.CLASS_NAME, "PLAN_ID=:PLAN_ID").setParameter("PLAN_ID", ids[i]) .getResultList(false); List boLCRIT = JBOFactory.createBizObjectQuery(LC_RENT_INCOME_TEMP.CLASS_NAME, "PLAN_ID=:PLAN_ID and IS_FLOWING = 0").setParameter("PLAN_ID", ids[i]) .getResultList(false); boLRIT.setAttributeValue("HIRE_LIST", boLCRI.size() + boLCRIT.size() + 1); //安鹏要求改为网银到账日期 boLRIT.setAttributeValue("HIRE_DATE", factDate); boLRIT.setAttributeValue("CHARGE_WAY", "Collection"); boLRIT.setAttributeValue("HIRE_OBJECT", boEb.getAttribute("CLIENT_NAME").getString()); BigDecimal money; if (!flag) { money = new BigDecimal(corpuss[i]).add(new BigDecimal(interests[i])).add(new BigDecimal(Penaltys[i])); if (!ids[i].equals(portionCollectionID)) { bel = bel.subtract(money); boLRIT.setAttributeValue("RENT", new BigDecimal(corpuss[i]).add(new BigDecimal(interests[i]))); boLRIT.setAttributeValue("CORPUS", new BigDecimal(corpuss[i])); boLRIT.setAttributeValue("INTEREST", new BigDecimal(interests[i])); boLRIT.setAttributeValue("PENALTY", new BigDecimal(Penaltys[i])); } else { BigDecimal portionMoneys = new BigDecimal(portionMoney); BigDecimal rentMoney = new BigDecimal(0); for (int j = 0; j < paymentOrder.length; j++) { //获取产品还款次序 BigDecimal subtractMoney = new BigDecimal(0); String subtractMoneyName = ""; if ("本金".equals(paymentOrder[j])) { subtractMoneyName = "CORPUS"; subtractMoney = new BigDecimal(corpuss[i]); } else if ("利息".equals(paymentOrder[j])) { subtractMoneyName = "INTEREST"; subtractMoney = new BigDecimal(interests[i]); } else if ("罚息".equals(paymentOrder[j])) { subtractMoneyName = "PENALTY"; subtractMoney = new BigDecimal(Penaltys[i]); } if (portionMoneys.compareTo(new BigDecimal(0)) == 0) { //如果已经为0,则为对应的回笼对象赋值0 if ("CORPUS".equals(subtractMoneyName) || "INTEREST".equals(subtractMoneyName)) { rentMoney = rentMoney.add(new BigDecimal(0)); } //暂时解决报错问题 if ("".equals(subtractMoneyName) || subtractMoneyName == null) { subtractMoneyName = "PENALTY"; } boLRIT.setAttributeValue(subtractMoneyName, 0); } else { if (portionMoneys.compareTo(subtractMoney) >= 0) { //如果能正常减去,则为对应的回笼对象赋值对应值 if ("CORPUS".equals(subtractMoneyName) || "INTEREST".equals(subtractMoneyName)) { rentMoney = rentMoney.add(subtractMoney); } portionMoneys = portionMoneys.subtract(subtractMoney); boLRIT.setAttributeValue(subtractMoneyName, subtractMoney); } else { //如果不够减,则把剩余的值赋值给对应的回笼对象 if ("CORPUS".equals(subtractMoneyName) || "INTEREST".equals(subtractMoneyName)) { rentMoney = rentMoney.add(portionMoneys); } boLRIT.setAttributeValue(subtractMoneyName, portionMoneys); portionMoneys = new BigDecimal(0); } } } boLRIT.setAttributeValue("RENT", rentMoney); bel = bel.subtract(new BigDecimal(portionMoney)); } } else { // BizObject bo = JBOFactory.getBizObjectManager(VI_LC_RENT_PLAN.CLASS_NAME).createQuery("id=:planID").setParameter("planID", ids[i]).getSingleResult(false); Map sqlParamMap = new HashMap<>(); sqlParamMap.put("planId", ids[i]); Entity entity = SqlRunnerUtil.query("flow.FundCollectionFlow.queryRentPlanList", sqlParamMap, new EntityHandler()); String paymentNumber = entity.getStr("payment_number"); String planList = entity.getStr("plan_list"); BigDecimal corpusOver = entity.getBigDecimal("corpus_over"); BigDecimal interestOver = entity.getBigDecimal("interest_over"); BigDecimal penaltySum = entity.getBigDecimal("penalty_sum");// 包含罚息实收和罚息调整 String penalty = JBOFactory.getBizObjectManager(LB_CONTRACT_INFO.CLASS_NAME) .createQuery("select v.round(v.getRentPenalty('" + paymentNumber + "','" + planList + "','" + factDate + "'),2) as v.penalty from O").getSingleResult(false).getAttribute("penalty").getString(); BigDecimal penaltyOver = new BigDecimal(penalty).subtract(penaltySum); if ("penalty_income".equals(penaltyRule)) { penaltyOver = BigDecimal.ZERO; } else { // penaltyOver = JBOFactory.getBizObjectManager(VI_LC_RENT_PLAN.CLASS_NAME).createQuery("select v.getRentPenalty('"+boVLRP.getAttribute("PAYMENT_NUMBER").getString()+"','"+boVLRP.getAttribute("PLAN_LIST").getString()+"','"+factDate+"') v.penalty from O").getSingleResult(false).getAttribute("penalty").getString(); } money = corpusOver.add(interestOver).add(penaltyOver); if (money.compareTo(bel) <= 0) { bel = bel.subtract(money); boLRIT.setAttributeValue("RENT", corpusOver.add(interestOver)); boLRIT.setAttributeValue("CORPUS", corpusOver); boLRIT.setAttributeValue("INTEREST", interestOver); boLRIT.setAttributeValue("PENALTY", penaltyOver); } else { BigDecimal portionMoneys = bel; BigDecimal rentMoney = new BigDecimal(0); for (int j = 0; j < paymentOrder.length; j++) { //获取产品还款次序 BigDecimal subtractMoney = new BigDecimal(0); String subtractMoneyName = ""; if ("本金".equals(paymentOrder[j])) { subtractMoneyName = "CORPUS"; subtractMoney = corpusOver; } else if ("利息".equals(paymentOrder[j])) { subtractMoneyName = "INTEREST"; subtractMoney = interestOver; } else if ("罚息".equals(paymentOrder[j])) { subtractMoneyName = "PENALTY"; subtractMoney = penaltyOver; } if (portionMoneys.compareTo(new BigDecimal(0)) == 0) { //如果已经为0,则为对应的回笼对象赋值0 if ("CORPUS".equals(subtractMoneyName) || "INTEREST".equals(subtractMoneyName)) { rentMoney = rentMoney.add(new BigDecimal(0)); } boLRIT.setAttributeValue(subtractMoneyName, 0); } else { if (portionMoneys.compareTo(subtractMoney) >= 0) { //如果能正常减去,则为对应的回笼对象赋值对应值 if ("CORPUS".equals(subtractMoneyName) || "INTEREST".equals(subtractMoneyName)) { rentMoney = rentMoney.add(subtractMoney); } portionMoneys = portionMoneys.subtract(subtractMoney); boLRIT.setAttributeValue(subtractMoneyName, subtractMoney); } else { //如果不够减,则把剩余的值赋值给对应的回笼对象 if ("CORPUS".equals(subtractMoneyName) || "INTEREST".equals(subtractMoneyName)) { rentMoney = rentMoney.add(portionMoneys); } boLRIT.setAttributeValue(subtractMoneyName, portionMoneys); portionMoneys = new BigDecimal(0); } } } boLRIT.setAttributeValue("RENT", rentMoney); bel = bel.subtract(bel); } } boLRIT.setAttributeValue("CORPUS_ADJUST", 0); boLRIT.setAttributeValue("PENALTY_ADJUST", 0); boLRIT.setAttributeValue("OWN_BANK", boEb.getAttribute("OWN_BANK").getString()); boLRIT.setAttributeValue("OWN_ACCOUNT", boEb.getAttribute("OWN_ACCOUNT").getString()); boLRIT.setAttributeValue("OWN_NUMBER", boEb.getAttribute("OWNACC_NUMBER").getString()); boLRIT.setAttributeValue("HIRE_BANK", boEb.getAttribute("CLIENT_BANK").getString()); boLRIT.setAttributeValue("HIRE_ACCOUNT", boEb.getAttribute("CLIENT_ACCOUNT").getString()); boLRIT.setAttributeValue("HIRE_NUMBER", boEb.getAttribute("CLIENT_ACC_NUMBER").getString()); //安鹏要求改为当前日期 //boLRIT.setAttributeValue("ACCOUNTING_DATE", boEb.getAttribute("FACT_DATE").getString()); boLRIT.setAttributeValue("ACCOUNTING_DATE", StringFunction.getToday()); boLRIT.setAttributeValue("ROLL_BACK", 0); boLRIT.setAttributeValue("COIN", boVLRP.getAttribute("COIN").getString()); boLRIT.setAttributeValue("IS_FLOWING", 0); boLRIT.setAttributeValue("FLOWUNID", flowunid); boLRI.saveObject(boLRIT); } if (bel.compareTo(new BigDecimal(0)) > 0) { allFactMoney = allFactMoney.subtract(bel); } BizObjectManager bomLEP = JBOFactory.getBizObjectManager(LC_EBANK_PROCESS.CLASS_NAME); tx.join(bomLEP); BizObject boLEP = bomLEP.createQuery("FLOWUNID=:FLOWUNID").setParameter("FLOWUNID", flowunid).getSingleResult(true); BigDecimal processMoney = new BigDecimal(boLEP.getAttribute("PROCESS_MONEY").getDouble()); boLEP.setAttributeValue("PROCESS_MONEY", processMoney.add(allFactMoney)); bomLEP.saveObject(boLEP); //剩余可核销金额=上次的剩余可核销金额-本次核销金额 //已核销金额 = 到账总金额 - 剩余可核销金额 BigDecimal mayMoney = new BigDecimal(boEb.getAttribute("MAYOPE_MONEY").getDouble()); BigDecimal factMoney = new BigDecimal(boEb.getAttribute("FACT_MONEY").getDouble()); BigDecimal mayMoneyNew = mayMoney.subtract(allFactMoney); boEb.setAttributeValue("MAYOPE_MONEY", mayMoneyNew.toString()); boEb.setAttributeValue("HAD_MONEY", factMoney.subtract(mayMoneyNew).toString()); bomEb.saveObject(boEb); } catch (Exception e) { e.printStackTrace(); return "ERROR"; } return "SUCCESS"; } public String generateRentIncomeData(JBOTransaction tx) throws Exception { // 获取请求参数 ObjectMapper objectMapper = JsonUtil.getObjectMapper(); JsonNode jsonNode = objectMapper.readTree(params); String contractId = jsonNode.get("contractId").textValue(); String planIDsParam = jsonNode.get("planIDs").textValue(); String flowunidParam = jsonNode.get("flowunid").textValue(); String hireTypesParam = jsonNode.get("hireTypes").textValue(); String currUserId = jsonNode.get("currUserId").textValue(); String currOrgId = jsonNode.get("currOrgId").textValue(); List planIDList = Arrays.asList(planIDsParam.split(",")); List hireTypeList = Arrays.asList(hireTypesParam.split(",")); Transaction transaction = Transaction.createTransaction(tx); LCOccupyRentListService lcOccupyRentListService = LCOccupyRentListService.getInstance(); // 查询核销使用的网银 BizObjectManager ebankTempBOM = JBOFactory.getBizObjectManager(LC_EBANK_TEMP.CLASS_NAME, tx); BizObject ebankTempBizObj = ebankTempBOM.createQuery("FLOWUNID=:FLOWUNID").setParameter("FLOWUNID", flowunidParam).getSingleResult(true); String factDateStr = ebankTempBizObj.getAttribute("FACT_DATE").getString(); Date factDate = new SimpleDateFormat("yyyy/MM/dd").parse(factDateStr); // 可核销金额 BigDecimal mayopeMoney = new BigDecimal(ebankTempBizObj.getAttribute("MAYOPE_MONEY").getString()); // AtomicReference moneyAmtRef = new AtomicReference<>(mayopeMoney); // 查询核销的租金计划及计划剩余金额等信息 Map sqlParamMap = new HashMap<>(); // sqlParamMap.put("planIds", planIDList); sqlParamMap.put("contractId", contractId); sqlParamMap.put("factDate", factDateStr); List entityList = SqlRunnerUtil.query(transaction, "flow.FundCollectionFlow.queryRentPlanList", sqlParamMap, new EntityListHandler()); entityList.sort(Comparator.comparingInt(o -> o.getInt("plan_list"))); // 查询核销顺序 BizObjectManager lbContractInfoBOM = JBOFactory.getBizObjectManager(LB_CONTRACT_INFO.CLASS_NAME, tx); BizObject lbContractInfoBizObj = lbContractInfoBOM.createQuery("ID=:contractId").setParameter("contractId", contractId).getSingleResult(false); Map>> paymentOrders = ProductParamUtil .getProductComponentDecisionTable(lbContractInfoBizObj.getAttribute("PRODUCT_ID").getString(), "PRD0307", "rmoname", "rmosortno"); // 罚息核销规则 String penaltyRule = ProductParamUtil .getProductParameterValue(lbContractInfoBizObj.getAttribute("PRODUCT_ID").getString(), "PRD0307", "PenaltyRule", "PenaltyRule"); Pair, List> paymentOrderPair = getHirePaymentOrder(paymentOrders, hireTypeList); int hirePlanCount = planIDList.size(); int hireTimes = 0; List paymentOrder = null; for (Entity entity : entityList) { String planId = entity.getStr("id"); String paymentNumber = entity.getStr("payment_number"); Integer planList = entity.getInt("plan_list"); String planDate = entity.getStr("plan_date"); BigDecimal corpusOver = entity.getBigDecimal("corpus_over"); BigDecimal interestOver = entity.getBigDecimal("interest_over"); BigDecimal penaltyOver = entity.getBigDecimal("penalty_over"); if ((hireTypeList.contains("CORPUS") && corpusOver.compareTo(BigDecimal.ZERO) == 1) || (hireTypeList.contains("INTEREST") && interestOver.compareTo(BigDecimal.ZERO) == 1) || (hireTypeList.contains("PENALTY") && penaltyOver.compareTo(BigDecimal.ZERO) == 1) ) { hireTimes++; if (hireTimes <= hirePlanCount) { if (!planIDList.contains(planId)) { throw new RuntimeException("ERROR@期次【" + planList + "】尚未核销,不可以跨期核销"); } if (moneyAmtRef.get().compareTo(BigDecimal.ZERO) < 1) { throw new RuntimeException("ERROR@网银可核销金额不足"); } // 保存租金占用 lcOccupyRentListService.save(tx, paymentNumber, planList, planId, "网银收款", flowunidParam); // 获取核销顺序 if (factDate.compareTo(new SimpleDateFormat("yyyy/MM/dd").parse(planDate)) > 0) { paymentOrder = paymentOrderPair.getLeft(); } else { paymentOrder = paymentOrderPair.getRight(); } // 判断罚息是否核销 if("penalty_income".equals(penaltyRule)) { penaltyOver = BigDecimal.ZERO; } Map moneyOverMap = ImmutableMap.of("CORPUS", corpusOver, "INTEREST", interestOver, "PENALTY", penaltyOver); Map hireResMap = hireMoney(paymentOrder, moneyAmtRef, moneyOverMap); BigDecimal incomeCorpus = hireResMap.containsKey("CORPUS") ? hireResMap.get("CORPUS") : BigDecimal.ZERO; BigDecimal incomeInterest = hireResMap.containsKey("INTEREST") ? hireResMap.get("INTEREST") : BigDecimal.ZERO; BigDecimal incomePenalty = hireResMap.containsKey("PENALTY") ? hireResMap.get("PENALTY") : BigDecimal.ZERO; // 保存租金实收临时表 BizObjectManager rentIncomeTempBOM = JBOFactory.getBizObjectManager(LC_RENT_INCOME_TEMP.CLASS_NAME, tx); BizObject rentIncomeTempBizObj = rentIncomeTempBOM.newObject(); rentIncomeTempBizObj.setAttributeValue("QUOT_ID", entity.getStr("quot_id")); rentIncomeTempBizObj.setAttributeValue("CUST_ID", entity.getStr("cust_id")); rentIncomeTempBizObj.setAttributeValue("PROJECT_ID", entity.getStr("project_id")); rentIncomeTempBizObj.setAttributeValue("PROJECT_PLAN_NUMBER", entity.getStr("project_plan_number")); rentIncomeTempBizObj.setAttributeValue("CONTRACT_ID", entity.getStr("contract_id")); rentIncomeTempBizObj.setAttributeValue("CONTRACT_PLAN_NUMBER", entity.getStr("contract_plan_number")); rentIncomeTempBizObj.setAttributeValue("PAYMENT_NUMBER", paymentNumber); rentIncomeTempBizObj.setAttributeValue("EBANK_NUMBER", ebankTempBizObj.getAttribute("EBANK_NUMBER").getString()); rentIncomeTempBizObj.setAttributeValue("PLAN_ID", planId); rentIncomeTempBizObj.setAttributeValue("PLAN_LIST", planList); rentIncomeTempBizObj.setAttributeValue("INTEREST_ADJUST", 0); rentIncomeTempBizObj.setAttributeValue("SETTLE_METHOD", "settlemethod6"); rentIncomeTempBizObj.setAttributeValue("HIRE_LIST", getPlanHireList(planId)); rentIncomeTempBizObj.setAttributeValue("HIRE_DATE", factDateStr); rentIncomeTempBizObj.setAttributeValue("CHARGE_WAY", "Collection"); rentIncomeTempBizObj.setAttributeValue("HIRE_OBJECT", ebankTempBizObj.getAttribute("CLIENT_NAME").getString()); rentIncomeTempBizObj.setAttributeValue("RENT", incomeCorpus.add(incomeInterest)); rentIncomeTempBizObj.setAttributeValue("CORPUS", incomeCorpus); rentIncomeTempBizObj.setAttributeValue("INTEREST", incomeInterest); rentIncomeTempBizObj.setAttributeValue("PENALTY", incomePenalty); rentIncomeTempBizObj.setAttributeValue("CORPUS_ADJUST", 0); rentIncomeTempBizObj.setAttributeValue("PENALTY_ADJUST", 0); rentIncomeTempBizObj.setAttributeValue("OWN_BANK", ebankTempBizObj.getAttribute("OWN_BANK").getString()); rentIncomeTempBizObj.setAttributeValue("OWN_ACCOUNT", ebankTempBizObj.getAttribute("OWN_ACCOUNT").getString()); rentIncomeTempBizObj.setAttributeValue("OWN_NUMBER", ebankTempBizObj.getAttribute("OWNACC_NUMBER").getString()); rentIncomeTempBizObj.setAttributeValue("HIRE_BANK", ebankTempBizObj.getAttribute("CLIENT_BANK").getString()); rentIncomeTempBizObj.setAttributeValue("HIRE_ACCOUNT", ebankTempBizObj.getAttribute("CLIENT_ACCOUNT").getString()); rentIncomeTempBizObj.setAttributeValue("HIRE_NUMBER", ebankTempBizObj.getAttribute("CLIENT_ACC_NUMBER").getString()); //安鹏要求改为当前日期 //boLRIT.setAttributeValue("ACCOUNTING_DATE", boEb.getAttribute("FACT_DATE").getString()); rentIncomeTempBizObj.setAttributeValue("ACCOUNTING_DATE", StringFunction.getToday()); rentIncomeTempBizObj.setAttributeValue("ROLL_BACK", 0); rentIncomeTempBizObj.setAttributeValue("COIN", entity.getStr("COIN")); rentIncomeTempBizObj.setAttributeValue("IS_FLOWING", 0); rentIncomeTempBizObj.setAttributeValue("FLOWUNID", flowunidParam); rentIncomeTempBizObj.setAttributeValue("INPUTUSERID", currUserId); rentIncomeTempBizObj.setAttributeValue("INPUTORGID", currOrgId); rentIncomeTempBizObj.setAttributeValue("INPUTTIME", StringFunction.getTodayNow()); rentIncomeTempBizObj.setAttributeValue("UPDATEUSERID", currUserId); rentIncomeTempBizObj.setAttributeValue("UPDATEORGID", currOrgId); rentIncomeTempBizObj.setAttributeValue("UPDATETIME", StringFunction.getTodayNow()); rentIncomeTempBOM.saveObject(rentIncomeTempBizObj); } } } // 核销总共使用金额 BigDecimal allFactMoney = mayopeMoney.subtract(moneyAmtRef.get()); // 保存网银过程表 BizObjectManager lcEbankProcessBOM = JBOFactory.getBizObjectManager(LC_EBANK_PROCESS.CLASS_NAME, tx); BizObject lcEbankProcessBizObj = lcEbankProcessBOM.createQuery("FLOWUNID=:FLOWUNID").setParameter("FLOWUNID", flowunidParam).getSingleResult(true); BigDecimal processMoney = new BigDecimal(lcEbankProcessBizObj.getAttribute("PROCESS_MONEY").getString()); lcEbankProcessBizObj.setAttributeValue("PROCESS_MONEY", processMoney.add(allFactMoney)); lcEbankProcessBOM.saveObject(lcEbankProcessBizObj); // 保存网银 MAYOPE_MONEY【可核销金额】 和 HAD_MONEY【已核销金额】 //剩余可核销金额=上次的剩余可核销金额-本次核销金额 //已核销金额 = 到账总金额 - 剩余可核销金额 // BigDecimal mayMoney = new BigDecimal(ebankTempBizObj.getAttribute("MAYOPE_MONEY").getDouble()); BigDecimal factMoney = new BigDecimal(ebankTempBizObj.getAttribute("FACT_MONEY").getString()); // BigDecimal mayMoneyNew = mayopeMoney.subtract(allFactMoney); ebankTempBizObj.setAttributeValue("MAYOPE_MONEY", moneyAmtRef.get()); ebankTempBizObj.setAttributeValue("HAD_MONEY", factMoney.subtract(moneyAmtRef.get()).toString()); ebankTempBOM.saveObject(ebankTempBizObj); return "SUCCESS"; } /** * 获取核销次数 * @param planID * @return * @throws JBOException */ private Integer getPlanHireList(String planID) throws JBOException { List boLCRI = JBOFactory.createBizObjectQuery(LC_RENT_INCOME.CLASS_NAME, "PLAN_ID=:PLAN_ID").setParameter("PLAN_ID", planID) .getResultList(false); List boLCRIT = JBOFactory.createBizObjectQuery(LC_RENT_INCOME_TEMP.CLASS_NAME, "PLAN_ID=:PLAN_ID and IS_FLOWING = 0").setParameter("PLAN_ID", planID) .getResultList(false); return boLCRI.size() + boLCRIT.size() + 1; } /** * 获取核销类型和核销顺序列表 * @param paymentOrders * @param hireTypeList * @return */ private Pair, List> getHirePaymentOrder(Map>> paymentOrders, List hireTypeList) { Function>, List> hireTypeConvertFunc = tempList -> tempList.stream() .map(tempMap -> { String rmoname = tempMap.get("rmoname"); if("本金".equals(rmoname)) { tempMap.put("hireType", "CORPUS"); } else if("利息".equals(rmoname)) { tempMap.put("hireType", "INTEREST"); } else if("罚息".equals(rmoname)) { tempMap.put("hireType", "PENALTY"); } return tempMap; }) .filter(o -> o.containsKey("hireType") && hireTypeList.contains(o.get("hireType"))) .sorted(Comparator.comparing(o -> Integer.valueOf(o.get("rmosortno")))) .map(tempMap -> tempMap.get("hireType")) .collect(Collectors.toList()); return Pair.of(hireTypeConvertFunc.apply(paymentOrders.get("RMO-02")), hireTypeConvertFunc.apply(paymentOrders.get("RMO-01"))); // for (int j = 0; j < paymentOrders.get("RMO-02").size(); j++) { // String hireType = hireTypeConvertFunc.apply(paymentOrders.get("RMO-02").get(j).get("rmoname")); // if(hireTypeList.contains(hireType)) { // paymentOrderLeft.add(hireType); // } // } // List paymentOrderRight = new ArrayList<>(); // for (int j = 0; j < paymentOrders.get("RMO-01").size(); j++) { // String hireType = hireTypeConvertFunc.apply(paymentOrders.get("RMO-01").get(j).get("rmoname")); // if(hireTypeList.contains(hireType)) { //// paymentOrderRight[Integer.parseInt(paymentOrders.get("RMO-01").get(j).get("rmosortno")) - 1] = hireType; // paymentOrderRight.add(hireType); // } // } // return Pair.of(paymentOrderLeft, paymentOrderRight); } private Map hireMoney(List paymentOrder, AtomicReference moneyAmtRef, Map hireMap) { Map resMap = new HashMap<>(); System.out.println("paymentOrder:" + paymentOrder); System.out.println("moneyAmt:" + moneyAmtRef.get()); System.out.println("hireMap:" + hireMap); for (String hireType : paymentOrder) { BigDecimal overMoney = hireMap.get(hireType); BigDecimal incomeMoney; if (moneyAmtRef.get().compareTo(overMoney) >= 0) { incomeMoney = overMoney; moneyAmtRef.set(moneyAmtRef.get().subtract(overMoney)); } else { incomeMoney = moneyAmtRef.get(); moneyAmtRef.set(BigDecimal.ZERO); } logger.info(hireType + ": overMoney:" + overMoney + ", incomeMoney:" + incomeMoney + ", moneyAmt:" + moneyAmtRef.get()); resMap.put(hireType, incomeMoney); } return resMap; } /** * 保证金抵扣 */ public String setCautionDeduction(JBOTransaction tx) throws Exception{ try{ boolean flag = false; if("Y".equals(isChanged)){ flag = true; } String[] ids = planIDs.split("@");//计划id String[] corpuss = new String[ids.length]; String[] interests = new String[ids.length]; String[] Penaltys = new String[ids.length]; if(overCorpuss != null){ corpuss = overCorpuss.split("@");//本金余额 interests = overInterests.split("@");//利息余额 Penaltys = overPenaltys.split("@");//罚息余额 } String[] datas = cautionDeductionIDs.split("@~");//保证金抵扣id+保证金余额 String[] cIDs = new String[datas.length]; BigDecimal[] overmoneys = new BigDecimal[datas.length];//保证金余额 BigDecimal zero = new BigDecimal(0); BizObjectManager boLRI = JBOFactory.getBizObjectManager(LC_RENT_INCOME_TEMP.CLASS_NAME); tx.join(boLRI); BizObjectManager boLFI = JBOFactory.getBizObjectManager(LC_FUND_INCOME_TEMP.CLASS_NAME); tx.join(boLFI); for(int i=0;i boLCRI = JBOFactory.createBizObjectQuery(LC_RENT_INCOME.CLASS_NAME, "PLAN_ID=:PLAN_ID and ROLL_BACK=0 ").setParameter("PLAN_ID", ids[j]) .getResultList(false); List boLCRIT = JBOFactory.createBizObjectQuery(LC_RENT_INCOME_TEMP.CLASS_NAME, "PLAN_ID=:PLAN_ID and IS_FLOWING = 0 and ROLL_BACK=0 ").setParameter("PLAN_ID", ids[j]) .getResultList(false); int charge_list = boLCRI.size()+boLCRIT.size()+1; BizObject boVLRP = JBOFactory.createBizObjectQuery(LC_RENT_PLAN.CLASS_NAME, "ID=:ID").setParameter("ID", ids[j]) .getSingleResult(false); BizObject boLCI = JBOFactory.createBizObjectQuery(LB_CONTRACT_INFO.CLASS_NAME, "ID=:ID").setParameter("ID", boVLRP.getAttribute("CONTRACT_ID").getString()) .getSingleResult(false); Map>> paymentOrders = ProductParamUtil.getProductComponentDecisionTable(boLCI.getAttribute("PRODUCT_ID").getString(), "PRD0307", "rmoname", "rmosortno"); String penaltyRule = ProductParamUtil.getProductParameterValue(boLCI.getAttribute("PRODUCT_ID").getString(), "PRD0307","PenaltyRule", "PenaltyRule"); if("penalty_income".equals(penaltyRule)){ Penaltys[j] = "0.00"; } BigDecimal money = new BigDecimal(corpuss[j]).add(new BigDecimal(interests[j])).add(new BigDecimal(Penaltys[j])); String corpusOver = ""; String interestOver = ""; String penaltyOver = ""; if(flag){ BizObject bo = JBOFactory.getBizObjectManager(VI_LC_RENT_PLAN.CLASS_NAME).createQuery("id=:planID").setParameter("planID", ids[i]).getSingleResult(false); corpusOver = bo.getAttribute("corpus_over").getString(); interestOver = bo.getAttribute("interest_over").getString(); penaltyOver = bo.getAttribute("penalty_over").getString(); if("penalty_income".equals(penaltyRule)){ penaltyOver = "0.00"; } money = new BigDecimal(corpusOver).add(new BigDecimal(interestOver)).add(new BigDecimal(penaltyOver)); } if(deductionOverMoney.compareTo(zero)>0 && money.compareTo(zero)>0){//保证金抵扣大于零和活动租金大于零 BizObjectManager bomLORL = JBOFactory.getBizObjectManager(LC_OCCUPY_RENT_LIST.CLASS_NAME,tx); BizObject boLORL = bomLORL.createQuery("PAYMENT_NUMBER=:paymentnumber and PLAN_LIST=:planlist and FLOW_NAME='保证金抵扣流程' and FLOWUNID=:flowunid ").setParameter("paymentnumber", boVLRP.getAttribute("PAYMENT_NUMBER").getString()) .setParameter("planlist",boVLRP.getAttribute("PLAN_LIST").getString()).setParameter("flowunid",flowunid).getSingleResult(); if(boLORL==null){ boLORL = bomLORL.newObject(); boLORL.setAttributeValue("ID", UUIDUtil.getUUID()); boLORL.setAttributeValue("PAYMENT_NUMBER", boVLRP.getAttribute("PAYMENT_NUMBER").getString()); boLORL.setAttributeValue("PLAN_LIST", boVLRP.getAttribute("PLAN_LIST").getString()); boLORL.setAttributeValue("FLOW_NAME", "保证金抵扣流程"); boLORL.setAttributeValue("FLOWUNID", flowunid); bomLORL.saveObject(boLORL); } String[] paymentOrder = new String[3]; if(new BigDecimal(Penaltys[j]).compareTo(zero)==0){//正常还款次序 for(int k=0;k=0){//此笔保证金抵扣余额大于等于回笼租金加回笼罚息之和 if(flag){ boLRIT.setAttributeValue("RENT", new BigDecimal(corpusOver).add(new BigDecimal(interestOver))); boLRIT.setAttributeValue("CORPUS", new BigDecimal(corpusOver)); boLRIT.setAttributeValue("INTEREST", new BigDecimal(interestOver)); boLRIT.setAttributeValue("PENALTY", new BigDecimal(penaltyOver)); }else{ boLRIT.setAttributeValue("RENT", new BigDecimal(corpuss[j]).add(new BigDecimal(interests[j]))); boLRIT.setAttributeValue("CORPUS", new BigDecimal(corpuss[j])); boLRIT.setAttributeValue("INTEREST", new BigDecimal(interests[j])); boLRIT.setAttributeValue("PENALTY", new BigDecimal(Penaltys[j])); corpuss[j]="0.00"; interests[j]="0.00"; Penaltys[j]="0.00"; } deductionOverMoney=deductionOverMoney.subtract(money); }else{//此笔保证金抵扣余额小于回笼租金加回笼罚息之和 if(flag){ BigDecimal thisRent = zero; for(int k=0;k=0){ boLRIT.setAttributeValue("CORPUS", new BigDecimal(corpusOver)); deductionOverMoney=deductionOverMoney.subtract(new BigDecimal(corpusOver)); thisRent=thisRent.add(new BigDecimal(corpusOver)); }else{ boLRIT.setAttributeValue("CORPUS", deductionOverMoney); deductionOverMoney=zero; thisRent=thisRent.add(deductionOverMoney); } }else if("利息".equals(paymentOrder[k])){ if(deductionOverMoney.compareTo(new BigDecimal(interestOver))>=0){ boLRIT.setAttributeValue("INTEREST", new BigDecimal(interestOver)); deductionOverMoney=deductionOverMoney.subtract(new BigDecimal(interestOver)); thisRent=thisRent.add(new BigDecimal(interestOver)); }else{ boLRIT.setAttributeValue("INTEREST", deductionOverMoney); deductionOverMoney=zero; thisRent=thisRent.add(deductionOverMoney); } }else if("罚息".equals(paymentOrder[k])){ if(deductionOverMoney.compareTo(new BigDecimal(penaltyOver))>=0){ boLRIT.setAttributeValue("PENALTY", new BigDecimal(penaltyOver)); deductionOverMoney=deductionOverMoney.subtract(new BigDecimal(penaltyOver)); }else{ boLRIT.setAttributeValue("PENALTY", deductionOverMoney); deductionOverMoney=zero; } } } boLRIT.setAttributeValue("RENT", thisRent); }else{ BigDecimal thisRent = zero; for(int k=0;k=0){ boLRIT.setAttributeValue("CORPUS", new BigDecimal(corpuss[j])); deductionOverMoney=deductionOverMoney.subtract(new BigDecimal(corpuss[j])); thisRent=thisRent.add(new BigDecimal(corpuss[j])); corpuss[j]="0.00"; }else{ boLRIT.setAttributeValue("CORPUS", deductionOverMoney); thisRent=thisRent.add(deductionOverMoney); deductionOverMoney=zero; corpuss[j]=new BigDecimal(corpuss[j]).subtract(deductionOverMoney).setScale(Scale.CORPUS_SCALE).toString(); } }else if("利息".equals(paymentOrder[k])){ if(deductionOverMoney.compareTo(new BigDecimal(interests[j]))>=0){ boLRIT.setAttributeValue("INTEREST", new BigDecimal(interests[j])); deductionOverMoney=deductionOverMoney.subtract(new BigDecimal(interests[j])); thisRent=thisRent.add(new BigDecimal(interests[j])); interests[j]="0.00"; }else{ boLRIT.setAttributeValue("INTEREST", deductionOverMoney); thisRent=thisRent.add(deductionOverMoney); deductionOverMoney=zero; interests[j]=new BigDecimal(interests[j]).subtract(deductionOverMoney).setScale(Scale.INTEREST_SCALE).toString(); } }else if("罚息".equals(paymentOrder[k])){ if(deductionOverMoney.compareTo(new BigDecimal(Penaltys[j]))>=0){ boLRIT.setAttributeValue("PENALTY", new BigDecimal(Penaltys[j])); deductionOverMoney=deductionOverMoney.subtract(new BigDecimal(Penaltys[j])); Penaltys[j]="0.00"; }else{ boLRIT.setAttributeValue("PENALTY", deductionOverMoney); deductionOverMoney=zero; Penaltys[j]=new BigDecimal(Penaltys[j]).subtract(deductionOverMoney).setScale(Scale.RENT_SCALE).toString(); } } } boLRIT.setAttributeValue("RENT", thisRent); } } boLRIT.setAttributeValue("CORPUS_ADJUST", 0); boLRIT.setAttributeValue("PENALTY_ADJUST", 0); boLRIT.setAttributeValue("ROLL_BACK", 0); boLRIT.setAttributeValue("DEDUCTION_ID", deductionID); boLRIT.setAttributeValue("COIN", boVLRP.getAttribute("COIN").getString()); boLRIT.setAttributeValue("IS_FLOWING", 0); boLRIT.setAttributeValue("FLOWUNID", flowunid); boLRI.saveObject(boLRIT); } } if(overmoneys[i].compareTo(deductionOverMoney)>0){ List boLCFI = JBOFactory.createBizObjectQuery(LC_FUND_INCOME.CLASS_NAME, "PLAN_ID=:PLAN_ID and ROLL_BACK=0 ").setParameter("PLAN_ID", cIDs[i]) .getResultList(false); List boLCFIT = JBOFactory.createBizObjectQuery(LC_FUND_INCOME_TEMP.CLASS_NAME, "PLAN_ID=:PLAN_ID and IS_FLOWING = 0 and ROLL_BACK=0 ").setParameter("PLAN_ID", cIDs[i]) .getResultList(false); int charge_listFund = boLCFI.size()+boLCFIT.size()+1; BizObject boLFP = JBOFactory.createBizObjectQuery(LC_FUND_PLAN.CLASS_NAME, "id=:id").setParameter("id", cIDs[i]).getSingleResult(false); BizObject boLFIT = boLFI.newObject(); boLFIT.setAttributeValue("ID", deductionID); boLFIT.setAttributeValue("QUOT_ID", boLFP.getAttribute("QUOT_ID").getString()); boLFIT.setAttributeValue("CUST_ID", boLFP.getAttribute("CUST_ID").getString()); boLFIT.setAttributeValue("PROJECT_ID", boLFP.getAttribute("PROJECT_ID").getString()); boLFIT.setAttributeValue("PROJECT_PLAN_NUMBER", boLFP.getAttribute("PROJECT_PLAN_NUMBER").getString()); boLFIT.setAttributeValue("CONTRACT_ID", boLFP.getAttribute("CONTRACT_ID").getString()); boLFIT.setAttributeValue("CONTRACT_PLAN_NUMBER", boLFP.getAttribute("CONTRACT_PLAN_NUMBER").getString()); boLFIT.setAttributeValue("PAYMENT_NUMBER", boLFP.getAttribute("PAYMENT_NUMBER").getString()); boLFIT.setAttributeValue("PLAN_ID", boLFP.getAttribute("ID").getString()); boLFIT.setAttributeValue("PLAN_LIST", boLFP.getAttribute("PLAN_LIST").getString()); boLFIT.setAttributeValue("PAY_TYPE", boLFP.getAttribute("PAY_TYPE").getString()); boLFIT.setAttributeValue("FEE_TYPE", boLFP.getAttribute("FEE_TYPE").getString()); boLFIT.setAttributeValue("SETTLE_METHOD", "settlemethod7"); boLFIT.setAttributeValue("CHARGE_LIST", charge_listFund); boLFIT.setAttributeValue("FACT_DATE", StringFunction.getToday()); boLFIT.setAttributeValue("ACCOUNTING_DATE", StringFunction.getToday()); boLFIT.setAttributeValue("FACT_MONEY", overmoneys[i].subtract(deductionOverMoney)); boLFIT.setAttributeValue("FEE_ADJUST", 0); boLFIT.setAttributeValue("FACT_OBJECT", boLFP.getAttribute("PAY_OBJ").getString()); boLFIT.setAttributeValue("ROLL_BACK", 0); boLFIT.setAttributeValue("FLOWUNID", flowunid); boLFIT.setAttributeValue("IS_FLOWING", 0); boLFIT.setAttributeValue("COIN", boLFP.getAttribute("COIN").getString()); boLFIT.setAttributeValue("MEMO", boLFP.getAttribute("FPNOTE").getString()); boLFI.saveObject(boLFIT); } } }catch(Exception e){ e.printStackTrace(); return "ERROR"; } return "SUCCESS"; } public String updateEbankAndEbankProcess(JBOTransaction tx){ try{ BizObjectManager bomEb = JBOFactory.getBizObjectManager(LC_EBANK_TEMP.CLASS_NAME); tx.join(bomEb); BizObject boEb = bomEb.createQuery("FLOWUNID=:FLOWUNID") .setParameter("FLOWUNID", flowunid).getSingleResult(true); BigDecimal hadMoney = new BigDecimal(boEb.getAttribute("HAD_MONEY").getDouble()) .subtract(new BigDecimal(oldFactMoney)).add(new BigDecimal(newFactMoney)); BigDecimal factMoney = new BigDecimal(boEb.getAttribute("FACT_MONEY").getDouble()); boEb.setAttributeValue("HAD_MONEY", hadMoney); boEb.setAttributeValue("MAYOPE_MONEY", factMoney.subtract(hadMoney)); BizObjectManager bomLEP = JBOFactory.getBizObjectManager(LC_EBANK_PROCESS.CLASS_NAME); tx.join(bomLEP); bomLEP.createQuery("update O set process_money=:allFactMoney where flowunid=:flowUnid") .setParameter("allFactMoney", newFactMoney).setParameter("flowUnid", flowunid).executeUpdate(); bomEb.saveObject(boEb); }catch(Exception e){ e.printStackTrace(); return "ERROR"; } return "SUCCESS"; } public String updateRelativeFundIncome(JBOTransaction tx){ try{ if(ids != null){ BizObjectManager bomLFIT = JBOFactory.getBizObjectManager(LC_FUND_INCOME_TEMP.CLASS_NAME); tx.join(bomLFIT); String[] incomeIds = ids.split("@"); for(int i=0;i boLCRI = JBOFactory.createBizObjectQuery(LC_RENT_INCOME.CLASS_NAME, "PAYMENT_NUMBER=:paymentNumber AND PLAN_LIST = :planList and ROLL_BACK='0'") .setParameter("paymentNumber", boVLR.getAttribute(LC_RENT_PLAN.PAYMENT_NUMBER).getString()) .setParameter("planList", boVLR.getAttribute(LC_RENT_PLAN.PLAN_LIST).getString()) .getResultList(false); List boLCRIT = JBOFactory.createBizObjectQuery(LC_RENT_INCOME_TEMP.CLASS_NAME, "PAYMENT_NUMBER=:paymentNumber AND PLAN_LIST = :planList and IS_FLOWING = 0 and ROLL_BACK='0'") .setParameter("paymentNumber", boVLR.getAttribute(LC_RENT_PLAN.PAYMENT_NUMBER).getString()) .setParameter("planList", boVLR.getAttribute(LC_RENT_PLAN.PLAN_LIST).getString()) .getResultList(false); boLRIT.setAttributeValue("HIRE_LIST", boLCRI.size() + boLCRIT.size() + 1); boLRIT.setAttributeValue("HIRE_DATE", StringFunction.getToday()); boLRIT.setAttributeValue("ACCOUNTING_DATE", StringFunction.getToday()); boLRIT.setAttributeValue("RENT", 0); boLRIT.setAttributeValue("CORPUS", 0); boLRIT.setAttributeValue("INTEREST", 0); boLRIT.setAttributeValue("INTEREST_ADJUST", 0); boLRIT.setAttributeValue("PENALTY", 0); boLRIT.setAttributeValue("CORPUS_ADJUST", 0); boLRIT.setAttributeValue("PENALTY_ADJUST", penaltyOver); boLRIT.setAttributeValue("ROLL_BACK", 0); boLRIT.setAttributeValue("COIN", boVLR.getAttribute("COIN").getString()); boLRIT.setAttributeValue("IS_FLOWING", 0); boLRIT.setAttributeValue("FLOWUNID", flowunid); boLRI.saveObject(boLRIT); } } catch (Exception e) { e.printStackTrace(); return "ERROR"; } return "SUCCESS"; } public String createRentIncomeWithCard(JBOTransaction tx) throws Exception{ String sReturn = "SUCCESS"; Transaction tran = Transaction.createTransaction(tx); Connection con = null; try{ con = tran.getConnection(tran); /* ResultSet rs = stat.executeQuery("select count(1) cou from lc_card_deduct_data where deduct_docid='"+deductDocId+"' and income_status='0'"); if(rs.next()){ String cou = rs.getString("cou"); if("0".equals(cou)){ return "false"; } }*/ CallableStatement call = con.prepareCall("call proc_card_income('"+deductDocId+"','"+userid+"','"+orgid+"')"); call.execute(); }catch(Exception e){ e.printStackTrace(); if(con !=null){ con.rollback(); con.close(); con = null; } return "ERROR"; }finally{ if(con !=null){ con.commit(); con.close(); con = null; } } return sReturn; } /*public String createRentIncomeWithCard(JBOTransaction tx) throws Exception{ String sReturn = "SUCCESS"; sql = sql.replaceAll("△", ","); sql = sql.replaceAll("&", "="); Connection con = null; try{ List boVCDD = JBOFactory.getBizObjectManager(VI_CARD_DEDUCT_DATA.CLASS_NAME).createQuery(sql).getResultList(false); int count = 0;//循环次数 int n = 0;//匹配失败次数 long start = System.currentTimeMillis(); WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); ComboPooledDataSource datasource = wac.getBean("dataSourceJDBC",ComboPooledDataSource.class); BigDecimal money = new BigDecimal(0); con = datasource.getConnection(); con.setAutoCommit(false); String executeSql = "insert into lc_rent_income_temp (id," + "quot_id," + "cust_id," + "project_id," + "project_plan_number," + "contract_id," + "contract_plan_number," + "payment_number," + "plan_id," + "plan_list," + "hire_list," + "hire_date," + "rent," + "corpus," + "interest," + "penalty," + "corpus_adjust," + "interest_adjust," + "penalty_adjust," + "settle_method," + "carddeduct_id," + "carddeduct_status," + "hire_object," + "hire_bank," + "hire_account," + "hire_number," + "own_bank," + "own_account," + "own_number," + "roll_back," + "flowunid," + "inputuserid," + "inputorgid," + "inputtime," + "is_flowing) " + "SELECT replace(uuid(),'-','')," + "lrp.quot_id," + "lrp.cust_id," + "lrp.project_id," + "lrp.project_plan_number," + "lrp.contract_id," + "lrp.contract_plan_number," + "lrp.payment_number," + "lrp.id," + "lrp.plan_list," + "ifnull(li.hire_list,0)+1+?," + "?," + "CASE WHEN '租金'=? THEN vlrp.rent_over ELSE 0 END," + "CASE WHEN '租金'=? THEN vlrp.corpus_over ELSE 0 END," + "CASE WHEN '租金'=? THEN vlrp.interest_over ELSE 0 END," + "CASE WHEN '租金'=? THEN 0 ELSE vlrp.penalty_over END," + "0," + "0," + "0," + "'settlemethod6'," + "?," + "'have_income'," + "?," + "?," + "?," + "?," + "?," + "?," + "?," + "'0'," + "?," + "?," + "?," + "?," + "'0' FROM lc_rent_plan AS lrp LEFT JOIN(SELECT lr.payment_number,lr.plan_list,COUNT(lr.plan_list)AS hire_list FROM (SELECT lri.payment_number,lri.plan_list,COUNT(lri.plan_list)AS hire_list FROM lc_rent_income AS lri WHERE lri.ROLL_BACK='0' and lri.payment_number=? and lri.plan_list=? GROUP BY lri.payment_number,lri.plan_list UNION SELECT lrit.payment_number,lrit.plan_list,COUNT(lrit.plan_list)AS hire_list FROM lc_rent_income_temp AS lrit WHERE lrit.roll_back='0' AND lrit.is_flowing='0' and lrit.payment_number=? and lrit.plan_list=? GROUP BY lrit.payment_number,lrit.plan_list)AS lr GROUP BY lr.payment_number,lr.plan_list) AS li ON li.payment_number=lrp.PAYMENT_NUMBER AND li.plan_list=lrp.PLAN_LIST LEFT JOIN vi_lc_rent_plan AS vlrp ON vlrp.payment_number=lrp.PAYMENT_NUMBER AND vlrp.plan_list=lrp.plan_list where lrp.plan_list=? and lrp.PAYMENT_NUMBER=?"; if("ORACLE".equals(InitDBType.DBTYPE)){ executeSql = "insert into lc_rent_income_temp (id," + "quot_id," + "cust_id," + "project_id," + "project_plan_number," + "contract_id," + "contract_plan_number," + "payment_number," + "plan_id," + "plan_list," + "hire_list," + "hire_date," + "rent," + "corpus," + "interest," + "penalty," + "corpus_adjust," + "interest_adjust," + "penalty_adjust," + "settle_method," + "carddeduct_id," + "carddeduct_status," + "hire_object," + "hire_bank," + "hire_account," + "hire_number," + "own_bank," + "own_account," + "own_number," + "roll_back," + "flowunid," + "inputuserid," + "inputorgid," + "inputtime," + "is_flowing) " + "SELECT sys_guid()," + "lrp.quot_id," + "lrp.cust_id," + "lrp.project_id," + "lrp.project_plan_number," + "lrp.contract_id," + "lrp.contract_plan_number," + "lrp.payment_number," + "lrp.id," + "lrp.plan_list," + "nvl(li.hire_list,0)+1+?," + "?," + "CASE WHEN '租金'=? THEN vlrp.rent_over ELSE 0 END," + "CASE WHEN '租金'=? THEN vlrp.corpus_over ELSE 0 END," + "CASE WHEN '租金'=? THEN vlrp.interest_over ELSE 0 END," + "CASE WHEN '租金'=? THEN 0 ELSE vlrp.penalty_over END," + "0," + "0," + "0," + "'settlemethod6'," + "?," + "'have_income'," + "?," + "?," + "?," + "?," + "?," + "?," + "?," + "'0'," + "?," + "?," + "?," + "?," + "'0' FROM lc_rent_plan lrp LEFT JOIN(SELECT lr.payment_number,lr.plan_list,COUNT(lr.plan_list)AS hire_list FROM (SELECT lri.payment_number,lri.plan_list,COUNT(lri.plan_list)AS hire_list FROM lc_rent_income lri WHERE lri.ROLL_BACK='0' and lri.payment_number=? and lri.plan_list=? GROUP BY lri.payment_number,lri.plan_list UNION SELECT lrit.payment_number,lrit.plan_list,COUNT(lrit.plan_list)AS hire_list FROM lc_rent_income_temp lrit WHERE lrit.roll_back='0' AND lrit.is_flowing='0' and lrit.payment_number=? and lrit.plan_list=? GROUP BY lrit.payment_number,lrit.plan_list) lr GROUP BY lr.payment_number,lr.plan_list) li ON li.payment_number=lrp.PAYMENT_NUMBER AND li.plan_list=lrp.PLAN_LIST LEFT JOIN vi_lc_rent_plan vlrp ON vlrp.payment_number=lrp.PAYMENT_NUMBER AND vlrp.plan_list=lrp.plan_list where lrp.plan_list=? and lrp.PAYMENT_NUMBER=?"; } String failedSql = "insert into lc_card_deduct_matchfail_temp(id,deduct_docid,carddeduct_id,inputuserid,inputorgid,inputtime,flowunid) values(replace(uuid(),'-',''),?,?,?,?,?,?)"; if("ORACLE".equals(InitDBType.DBTYPE)){ failedSql = "insert into lc_card_deduct_matchfail_temp(id,deduct_docid,carddeduct_id,inputuserid,inputorgid,inputtime,flowunid) values(sys_guid(),?,?,?,?,?,?)"; } PreparedStatement executeStat = con.prepareStatement(executeSql); PreparedStatement executeFailedStat = con.prepareStatement(failedSql); String planList = ""; String paymentNumber = ""; for(BizObject b:boVCDD){ if(!b.getAttribute("actual_debit_amt").getString().equals(b.getAttribute("over_money").getString())){ n++; executeFailedStat.setString(1, b.getAttribute("deduct_docid").getString()); executeFailedStat.setString(2, b.getAttribute("carddeduct_id").getString()); executeFailedStat.setString(3, userid); executeFailedStat.setString(4, orgid); executeFailedStat.setString(5, StringFunction.getToday()); executeFailedStat.setString(6, flowunid); executeFailedStat.addBatch(); continue; } count++; if(planList.equals(b.getAttribute("plan_list").getString()) && paymentNumber.equals(b.getAttribute("payment_number").getString())){ executeStat.setInt(1, 0); }else{ executeStat.setInt(1, 0); } executeStat.setString(2, b.getAttribute("enddate").getString()); executeStat.setString(3, b.getAttribute("fee_type").getString()); executeStat.setString(4, b.getAttribute("fee_type").getString()); executeStat.setString(5, b.getAttribute("fee_type").getString()); executeStat.setString(6, b.getAttribute("fee_type").getString()); executeStat.setString(7, b.getAttribute("carddeduct_id").getString()); executeStat.setString(8, b.getAttribute("client_account").getString()); executeStat.setString(9, b.getAttribute("client_bank").getString()); executeStat.setString(10, b.getAttribute("client_account").getString()); executeStat.setString(11, b.getAttribute("client_acc_number").getString()); executeStat.setString(12, b.getAttribute("lease_acc_bank").getString()); executeStat.setString(13, b.getAttribute("own_account").getString()); executeStat.setString(14, b.getAttribute("ownacc_number").getString()); executeStat.setString(15, flowunid); executeStat.setString(16, userid); executeStat.setString(17, orgid); executeStat.setString(18, StringFunction.getToday()); executeStat.setString(19, b.getAttribute("payment_number").getString()); executeStat.setString(20, b.getAttribute("plan_list").getString()); executeStat.setString(21, b.getAttribute("payment_number").getString()); executeStat.setString(22, b.getAttribute("plan_list").getString()); executeStat.setString(23, b.getAttribute("plan_list").getString()); executeStat.setString(24, b.getAttribute("payment_number").getString()); planList = b.getAttribute("plan_list").getString(); paymentNumber = b.getAttribute("payment_number").getString(); money = money.add(new BigDecimal(b.getAttribute("actual_debit_amt").getString())); executeStat.addBatch(); if(count == 1000){ executeStat.executeBatch(); executeStat.clearBatch(); count = 0; } } executeFailedStat.executeBatch(); executeStat.executeBatch(); BizObjectManager bomLCDD = JBOFactory.getBizObjectManager(LC_CARD_DEDUCT_DOC_TEMP.CLASS_NAME); tx.join(bomLCDD); bomLCDD.createQuery("update O set allmayope_money=allfact_money-(allhad_money+"+money+"),allhad_money=allhad_money+"+money+" where flowunid='"+flowunid+"'").executeUpdate(); con.commit(); if(n > 0){ sReturn = "PORTION@"+n; } }catch(Exception e){ e.printStackTrace(); con.rollback(); tx.rollback(); return "ERROR"; } return sReturn; }*/ }