package com.tenwa.flow.fund.fundcollection; import java.math.BigDecimal; import java.util.HashMap; import java.util.List; import java.util.Map; 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.VI_LC_FUND_PLAN; import jbo.com.tenwa.entity.comm.own.OWN_ACCOUNT; 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.ASResultSet; import com.amarsoft.awe.util.SqlObject; import com.amarsoft.awe.util.Transaction; import com.tenwa.comm.util.jboutil.DataOperatorUtil; import com.tenwa.flow.bussinessapprove.BussinessStatusAndDetailAction; public class FundIncomeMethod { private String planIDs; private String flowunid; private String overMoneys; private String balance; private String portionCollectionID; private String portionMoney; private String oldFactMoney; private String newFactMoney; private String isChanged; private String CONTRACT_ID; private String contractIds; private String userId; private String orgId; private String status; public String getIsChanged() { return isChanged; } public void setIsChanged(String isChanged) { this.isChanged = isChanged; } 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 getOverMoneys() { return overMoneys; } public void setOverMoneys(String overMoneys) { this.overMoneys = overMoneys; } 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 getCONTRACT_ID() { return CONTRACT_ID; } public void setCONTRACT_ID(String cONTRACT_ID) { CONTRACT_ID = cONTRACT_ID; } public String getContractIds() { return contractIds; } public void setContractIds(String contractIds) { this.contractIds = contractIds; } 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 getStatus() { return status; } public void setStatus(String status) { this.status = status; } public String setFundDataToFundIncome(JBOTransaction tx) throws JBOException{ try{ boolean flag = false; if("Y".equals(isChanged)){ flag = true; } BigDecimal bel = new BigDecimal(balance); BigDecimal allFactMoney = bel; BigDecimal zero = new BigDecimal(0); 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[] moneys = overMoneys.split("@"); String[] ids = planIDs.split("@"); for(int i=0;i boLCFI = JBOFactory.createBizObjectQuery(LC_FUND_INCOME.CLASS_NAME, "PLAN_ID=:PLAN_ID and ROLL_BACK='0'").setParameter("PLAN_ID", ids[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", ids[i]) .getResultList(false); boLFIT.setAttributeValue("CHARGE_LIST", boLCFI.size()+boLCFIT.size()+1); boLFIT.setAttributeValue("FACT_DATE", boEb.getAttribute("FACT_DATE").getString()); if(!flag){ if(!ids[i].equals(portionCollectionID) && bel.subtract(new BigDecimal(moneys[i])).compareTo(new BigDecimal(0)) >= 0){ bel = bel.subtract(new BigDecimal(moneys[i])); boLFIT.setAttributeValue("FACT_MONEY", new BigDecimal(moneys[i])); }else{ boLFIT.setAttributeValue("FACT_MONEY", new BigDecimal(portionMoney)); bel = bel.subtract(new BigDecimal(portionMoney)); } }else{ moneys[i] = boVLFP.getAttribute("OVERMONEY").getString(); if(bel.subtract(new BigDecimal(moneys[i])).compareTo(new BigDecimal(0)) >= 0){ bel = bel.subtract(new BigDecimal(moneys[i])); boLFIT.setAttributeValue("FACT_MONEY", new BigDecimal(moneys[i])); }else{ boLFIT.setAttributeValue("FACT_MONEY",bel); bel = zero; } } boLFIT.setAttributeValue("FEE_ADJUST", 0); boLFIT.setAttributeValue("FACT_OBJECT", boVLF.getAttribute("PAY_OBJ").getString()); boLFIT.setAttributeValue("EBANK_NUMBER", boEb.getAttribute("ID").getString()); boLFIT.setAttributeValue("BANK", boEb.getAttribute("OWN_BANK").getString()); boLFIT.setAttributeValue("ACCOUNT", boEb.getAttribute("OWN_ACCOUNT").getString()); boLFIT.setAttributeValue("ACC_NUMBER", boEb.getAttribute("OWNACC_NUMBER").getString()); boLFIT.setAttributeValue("CLIENT_BANK", boEb.getAttribute("CLIENT_BANK").getString()); boLFIT.setAttributeValue("CLIENT_ACCOUNT", boEb.getAttribute("CLIENT_ACCOUNT").getString()); boLFIT.setAttributeValue("CLIENT_ACCNUMBER", boEb.getAttribute("CLIENT_ACC_NUMBER").getString()); boLFIT.setAttributeValue("ACCOUNTING_DATE", boEb.getAttribute("FACT_DATE").getString()); boLFIT.setAttributeValue("ROLL_BACK", 0); boLFIT.setAttributeValue("COIN", boVLF.getAttribute("COIN").getString()); boLFIT.setAttributeValue("IS_FLOWING", 0); boLFIT.setAttributeValue("FLOWUNID", flowunid); boLFI.saveObject(boLFIT); } 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 hadMoney = new BigDecimal(boEb.getAttribute("HAD_MONEY").getDouble()).add(allFactMoney); BigDecimal factMoney = new BigDecimal(boEb.getAttribute("FACT_MONEY").getDouble()); boEb.setAttributeValue("HAD_MONEY", hadMoney); boEb.setAttributeValue("MAYOPE_MONEY", factMoney.subtract(hadMoney)); bomEb.saveObject(boEb); }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 createActualPayment(JBOTransaction tx) throws JBOException{ try{ //获取本方账户 BizObject boOA = JBOFactory.getBizObjectManager(OWN_ACCOUNT.CLASS_NAME,tx) .createQuery("account_purpose='default' and state_='0010'").getSingleResult(false); for(String contractId : contractIds.split("@")){ @SuppressWarnings("unchecked") List bos = JBOFactory.getBizObjectManager(LC_FUND_INCOME.CLASS_NAME) .createQuery("contract_id='"+contractId+"' and pay_type='pay_type_out' and pay_status='apply_pass'") .getResultList(false); BigDecimal totalMoney = new BigDecimal("0"); int contractCount = 0; if(bos.size() > 0){ Map fromCondition = new HashMap(); Map otherProperty = new HashMap(); for(BizObject bo:bos){ fromCondition.clear(); fromCondition.put("ID", bo.getAttribute("ID").getString()); fromCondition.put(LC_FUND_INCOME.SETTLE_METHOD, "settlemethod6"); otherProperty.clear(); otherProperty.put("FlowUnid", flowunid); otherProperty.put("IS_FLOWING", "0"); otherProperty.put("ACCOUNTING_DATE", StringFunction.getTodayNow().split(" ")[0]); otherProperty.put("BANK", boOA.getAttribute("ACC_BANK").getString()); otherProperty.put("ACCOUNT", boOA.getAttribute("ACC_NAME").getString()); otherProperty.put("ACC_NUMBER", boOA.getAttribute("ACC_NUMBER").getString()); otherProperty.put("INCOME_ID", bo.getAttribute("ID").getString()); otherProperty.put(LC_FUND_INCOME.EBANK_STATUS, "01"); DataOperatorUtil.copySingleJBO(LC_FUND_INCOME.CLASS_NAME, fromCondition,LC_FUND_INCOME_TEMP.CLASS_NAME, null, otherProperty,tx); BussinessStatusAndDetailAction.stageRun( tx, userId, contractId, "30"); } } Transaction sqlTran = Transaction.createTransaction(tx); ASResultSet rs = sqlTran.getResultSet(new SqlObject("select count(1) contract_count,sum(fact_money) total_money from lc_fund_income_temp where flowunid='"+flowunid+"' and pay_status<>'apply_return' group by flowunid")); if(rs.next()){ totalMoney = new BigDecimal(rs.getString("total_money")); contractCount = Integer.parseInt(rs.getString("contract_count")); SqlObject so = new SqlObject("update lb_actual_payment_info_temp set contract_count='"+contractCount+"',total_money='"+totalMoney+"',updateuserid='"+userId+"',updateorgid='"+orgId+"',updatetime='"+StringFunction.getTodayNow().replaceAll(":", "@")+"' where flowunid='"+flowunid+"'"); so.setDebugSql(so.getDebugSql().replaceAll("@", ":")); so.setOriginalSql(so.getOriginalSql().replaceAll("@", ":")); so.setRunSql(so.getRunSql().replaceAll("@", ":")); sqlTran.executeSQL(so); so = new SqlObject("update flow_bussiness_object set proj_name=(substr(proj_name,1,instr(proj_name,'实际付款')-1)||'实际付款,金额为:"+totalMoney+"') where flow_unid='"+flowunid+"'"); sqlTran.executeSQL(so); } } }catch(Exception e){ e.printStackTrace(); tx.rollback(); return "ERROR"; } return "SUCCESS"; } }