232 lines
8.6 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.amarsoft.awe.util.SqlObject;
import com.amarsoft.awe.util.Transaction;
import com.base.util.QuartzUtil;
import com.tenwa.collectaudit.cache.CollectAuditInfoCache;
import com.tenwa.collectaudit.cache.CollectAuditInfoCacheTj;
import com.tenwa.comm.util.date.DateAssistant;
import com.tenwa.lease.app.allinpay.service.impl.AllinpayPaymentDo;
import com.tenwa.reckon.util.DateUtil;
import com.tenwa.reckon.util.UUIDUtil;
public class AutoBuckle implements Job {
private JobInitUserName jboName;
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
//插入一条数据定时任务开始时间
Transaction startTx =null;
String uuid = UUIDUtil.getUUID();
try {
startTx = Transaction.createTransaction("als");
String insertSql="insert into lb_card_buckle_status(id,status,starttime) values('"+uuid+"','Y',:starttime)";
SqlObject asql = new SqlObject(insertSql);
asql.setParameter("starttime", DateUtil.getSystemTimeByFormat("yyyy/MM/dd HH:mm:ss"));
startTx.executeSQL(asql);
} catch (Exception e) {
if (startTx != null) {
try {
startTx.rollback();
startTx=null;
} catch (JBOException e1) {
e1.printStackTrace();
}
}
}finally{
try {
if(startTx !=null){
startTx.commit();
startTx.disConnect();
}
} catch (JBOException e) {
e.printStackTrace();
}
}
System.out.println("自动卡扣定时任务开始");
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();
String sql = "O.plan_list=(select min(t.plan_list) from jbo.loan.VI_RENT_COLLECT t where t.contract_id=O.contract_id and t.COLLECT_STATUS IN ('未收款', '部分收款','代偿') and t.SUBJECTID=:subjectId and t.collect_type=:collectType 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','BQAP(AH)201907290017','BQAP(AH)201909060001')) 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";
// 获取传递过来的参数
try {
tx = JBOFactory.createJBOTransaction();
String subjectId = "aa740e4111c111eaaa0000163e0e11e6";
String collectType = "YLcollect";
List<BizObject> bosSz = JBOFactory.getBizObjectManager("jbo.loan.VI_RENT_COLLECT", tx).createQuery(sql).setParameter("subjectId", subjectId).setParameter("collectType", collectType).getResultList(false);
StringBuffer ids = new StringBuffer();
if(bosSz!=null&&bosSz.size()>0){
for(BizObject bo : bosSz){
String pid = bo.getAttribute("id").getString();
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();
String subjectId = "d989246c11c111eaaa0000163e0e11e6";
String collectType = "YLcollect";
List<BizObject> bosTj = JBOFactory.getBizObjectManager("jbo.loan.VI_RENT_COLLECT", txTj).createQuery(sql).setParameter("subjectId", subjectId).setParameter("collectType", collectType).getResultList(false);
StringBuffer idsTj = new StringBuffer();
if(bosTj!=null && bosTj.size()>0){
for(BizObject bo : bosTj){
String pid = bo.getAttribute("id").getString();
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();
}
}
//通联扣款(主体区分在内部)
JBOTransaction txTL = null;
try {
txTL = JBOFactory.createJBOTransaction();
String collectType = "TLcollect";
String TLsql = "O.plan_list=(select min(t.plan_list) from jbo.loan.VI_RENT_COLLECT t where t.contract_id=O.contract_id and t.COLLECT_STATUS IN ('未收款', '部分收款','代偿') and t.collect_type=:collectType 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";
List<BizObject> bos = JBOFactory.getBizObjectManager("jbo.loan.VI_RENT_COLLECT", txTL).createQuery(TLsql).setParameter("collectType", collectType).getResultList(false);
StringBuffer ids = new StringBuffer();
if(bos!=null && bos.size()>0){
for(BizObject bo : bos){
String pid = bo.getAttribute("id").getString();
ids.append(pid+"@");
}
AllinpayPaymentDo apd = new AllinpayPaymentDo();
apd.setId(ids.toString());
apd.batchCollectManage(txTL);
}
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 (txTL != null) {
try {
txTL.rollback();
txTL=null;
} catch (JBOException e1) {
e1.printStackTrace();
}
}
} finally{
try {
if(txTL !=null){
txTL.commit();
}
} catch (JBOException e) {
e.printStackTrace();
}
}
System.out.println("自动卡扣定时任务结束");
//更新定时任务计划表
Transaction endTx =null;
try {
endTx = Transaction.createTransaction("als");
String updateSql="update lb_card_buckle_status set status='N',endtime=:endtime where id='"+uuid+"' ";
SqlObject asql = new SqlObject(updateSql);
asql.setParameter("endtime", DateUtil.getSystemTimeByFormat("yyyy/MM/dd HH:mm:ss"));
endTx.executeSQL(asql);
} catch (Exception e) {
if (endTx != null) {
try {
endTx.rollback();
endTx=null;
} catch (JBOException e1) {
e1.printStackTrace();
}
}
}finally{
try {
if(endTx !=null){
endTx.commit();
endTx.disConnect();
}
} catch (JBOException e) {
e.printStackTrace();
}
}
}
}