169 lines
6.9 KiB
Java

package com.tenwa.lease.app.quartzmession;
import java.util.ArrayList;
import java.util.List;
import jbo.app.tenwa.calc.LC_RENT_INCOME_TEMP;
import jbo.app.tenwa.calc.LC_RENT_PLAN;
import jbo.com.tenwa.lease.comm.LC_OCCUPY_RENT_LIST;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.JBOException;
import com.amarsoft.are.jbo.JBOFactory;
import com.amarsoft.are.jbo.JBOTransaction;
import com.amarsoft.awe.Configure;
import com.base.util.QuartzUtil;
import com.tenwa.collectaudit.cache.CollectAuditInfoCache;
import com.tenwa.collectaudit.cache.CollectAuditInfoCacheTj;
import com.tenwa.comm.util.date.DateAssistant;
public class AutoBuckle implements Job {
private JobInitUserName jboName;
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
CollectAuditInfoCache ca = new CollectAuditInfoCache();
JBOTransaction tx = null;
String plan_date = DateAssistant.getToday();
Object userId = arg0.getTrigger().getJobDataMap().get("CurUserId");
String curUserId = userId == null? "system" : userId.toString();
//获取租金占用表里的数据有哪些是网银收款占用的
List<String> planIDs = new ArrayList<String>();
// 获取传递过来的参数
try {
//
tx = JBOFactory.createJBOTransaction();
//and (O.rent<>'' or O.rent<>'0' or O.rent<>'0.0')
List<BizObject> bosSz = JBOFactory.getBizObjectManager("jbo.com.tenwa.lease.comm.VI_LC_AUDIT_RENT_PLAN", tx).createQuery("O.plan_list=(select min(plan_list) from jbo.com.tenwa.lease.comm.VI_LC_AUDIT_RENT_PLAN t where t.contract_id=O.contract_id and t.COLLECT_STATUS IN ('未收款', '部分收款','代偿') and t.SUBJECTID='aa740e4111c111eaaa0000163e0e11e6' and t.PLAN_DATE <= '" + plan_date + "' and ( t.BATCH_STATUS<>'process' or t.BATCH_STATUS IS NULL ) and (t.contract_number NOT IN ('BQAP(AH)201908060003','BQAP(AH)201908070002','BQAP(AH)201908070003')) and (t.distributor_id not in (select dw.distributor_id from jbo.app.tenwa.customer.DEDUCTIONS_WAY dw where dw.Whether_to_enable='Y'))) GROUP BY contract_id").getResultList(true);
List<BizObject> bol = JBOFactory.createBizObjectQuery(LC_OCCUPY_RENT_LIST.CLASS_NAME,"FLOW_NAME in ('网银收款','微信银联收款','微信支付收款','合同中途终止')").getResultList(false);
if(bol.size()>0){
for(int i=0;i<bol.size();i++){
String flowName = bol.get(i).getAttribute("FLOW_NAME").toString();
if("网银收款".equals(flowName)){
//暂时没有让更新
String flowunid = bol.get(i).getAttribute("FLOWUNID").toString();
List<BizObject> bof = JBOFactory.createBizObjectQuery(LC_RENT_INCOME_TEMP.CLASS_NAME,"FLOWUNID=:flowunid").setParameter("flowunid", flowunid).getResultList(false);
if(bof.size()>0){
for(int j=0;j<bof.size();j++){
String planID = bof.get(j).getAttribute("PLAN_ID").toString();
planIDs.add(planID);
}
}
}else if ("微信银联收款".equals(flowName) || "微信支付收款".equals(flowName)){
planIDs.add(bol.get(i).getAttribute("PLAN_ID").toString());
}else if("合同中途终止".equals(flowName)){
String PAYMENT_NUMBER = bol.get(i).getAttribute("PAYMENT_NUMBER").toString();
List<BizObject> bop = JBOFactory.createBizObjectQuery(LC_RENT_PLAN.CLASS_NAME,"PAYMENT_NUMBER=:PAYMENT_NUMBER").setParameter("PAYMENT_NUMBER", PAYMENT_NUMBER).getResultList(false);
if(bop.size()>0){
for(int k=0;k<bop.size();k++){
String planID = bop.get(k).getAttribute("ID").toString();
planIDs.add(planID);
}
}
}
}
}
StringBuffer ids = new StringBuffer();
if(bosSz!=null&&bosSz.size()>0){
a:for(BizObject bo : bosSz){
String pid = bo.getAttribute("id").getString();
if(planIDs.size()>0){
for(int i=0;i<planIDs.size();i++){
if(pid.equals(planIDs.get(i))){
continue a;
}
}
}
ids.append(pid+"@");
}
System.out.println("本次扣款的plan_id:"+ids.toString());
ca.setId(ids.toString().substring(0, ids.toString().length()-1));
Configure CurConfig = Configure.getInstance();
ca.setFileSavePath(CurConfig.getConfigure("InterfaceFileSavePath"));
ca.setInputuserid(jboName.getUserId(arg0, tx));
ca.setInputorgid("system");
ca.batchCollectManage(tx);
// ca.queryBatchCollectStatus(tx);
}
QuartzUtil.insertLog(plan_date,"com.tenwa.lease.app.quartzmession.AutoBuckle", "success", "深圳成功", curUserId);
} catch (Exception e) {
e.printStackTrace();
QuartzUtil.insertLog(plan_date,"com.tenwa.lease.app.quartzmession.AutoBuckle", "error", "深圳失败", curUserId);
if (tx != null) {
try {
tx.rollback();
tx=null;
} catch (JBOException e1) {
e1.printStackTrace();
}
}
}finally{
try {
if(tx !=null){
tx.commit();
}
} catch (JBOException e) {
e.printStackTrace();
}
}
//天津扣款
JBOTransaction txTj = null;
try {
txTj = JBOFactory.createJBOTransaction();
CollectAuditInfoCacheTj caTj = new CollectAuditInfoCacheTj();
List<BizObject> bosTj = JBOFactory.getBizObjectManager("jbo.com.tenwa.lease.comm.VI_LC_AUDIT_RENT_PLAN", txTj).createQuery(" O.COLLECT_STATUS IN ('未收款', '部分收款','代偿') and O.SUBJECTID='d989246c11c111eaaa0000163e0e11e6' and O.PLAN_DATE <= '" + plan_date + "' and ( O.BATCH_STATUS<>'process' or O.BATCH_STATUS IS NULL ) and (O.distributor_id not in (select dw.distributor_id from jbo.app.tenwa.customer.DEDUCTIONS_WAY dw where dw.Whether_to_enable='Y')) ").getResultList(true);
StringBuffer idsTj = new StringBuffer();
if(bosTj!=null && bosTj.size()>0){
a:for(BizObject bo : bosTj){
String pid = bo.getAttribute("id").getString();
if(planIDs.size()>0){
for(int i=0;i<planIDs.size();i++){
if(pid.equals(planIDs.get(i))){
continue a;
}
}
}
idsTj.append(pid+"@");
}
System.out.println("本次扣款的plan_id:"+idsTj.toString());
caTj.setId(idsTj.toString().substring(0, idsTj.toString().length()-1));
Configure CurConfig = Configure.getInstance();
caTj.setFileSavePath(CurConfig.getConfigure("InterfaceFileSavePath"));
caTj.setInputuserid(jboName.getUserId(arg0, txTj));
caTj.setInputorgid("system");
caTj.batchCollectManage(txTj);
// caTj.queryBatchCollectStatus(txTj);
}
QuartzUtil.insertLog(plan_date,"com.tenwa.lease.app.quartzmession.AutoBuckle", "success", "天津成功", curUserId);
} catch (Exception e) {
e.printStackTrace();
QuartzUtil.insertLog(plan_date,"com.tenwa.lease.app.quartzmession.AutoBuckle", "error", "天津失败", curUserId);
if (txTj != null) {
try {
txTj.rollback();
txTj=null;
} catch (JBOException e1) {
e1.printStackTrace();
}
}
} finally{
try {
if(txTj !=null){
txTj.commit();
}
} catch (JBOException e) {
e.printStackTrace();
}
}
}
}