2018-06-03 22:26:41 +08:00

102 lines
4.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.amarsoft.acct.accounting.web;
/**
* 2015-11-23
* ckxu
* 根据交易流水号调用交易
*/
import com.amarsoft.app.base.businessobject.BusinessObject;
import com.amarsoft.app.base.businessobject.BusinessObjectManager;
import com.amarsoft.app.base.trans.TransactionHelper;
import com.amarsoft.app.base.util.BUSINESSOBJECT_CONSTANTS;
import com.amarsoft.app.base.util.DateHelper;
import com.amarsoft.are.ARE;
import com.amarsoft.are.jbo.BizObjectClass;
import com.amarsoft.are.jbo.JBOException;
import com.amarsoft.are.jbo.JBOFactory;
import com.amarsoft.are.jbo.impl.StateBizObjectManager;
import com.amarsoft.are.lang.DataElement;
import com.amarsoft.are.lang.StringX;
import com.amarsoft.awe.util.SqlObject;
import com.amarsoft.awe.util.Transaction;
import com.amarsoft.biz.bizlet.Bizlet;
public class RunTransaction2 extends Bizlet {
public Object run(Transaction Sqlca) throws Exception{
String messageError = "";
BusinessObjectManager bom =BusinessObjectManager.createBusinessObjectManager(Sqlca);//创建对象管理器
try{
String transactionSerialNo = (String) this.getAttribute("TransactionSerialNo");//交易流水号
String userID = (String)this.getAttribute("UserID");//用户编号
String flag = (String)this.getAttribute("Flag");//是否强制执行 Y N
if(transactionSerialNo == null) transactionSerialNo = "";
if(userID == null) userID = "";
if(flag == null) flag = "";
//锁定该笔交易,防止重复点击//锁定状态将该交易的状态转变成为已执行
SqlObject sqlo = new SqlObject("update acct_transaction set TransStatus=TransStatus where TransStatus = '0' and SerialNo = :SerialNo");
sqlo.setParameter("SerialNo", transactionSerialNo);
int iupdate = Sqlca.executeSQL(sqlo);
if(iupdate == 0) messageError = "false@系统正在处理,请勿重复点击!";
//加载交易信息前,先锁定该笔交易对象信息
BusinessObject transaction = bom.loadBusinessObject(BUSINESSOBJECT_CONSTANTS.transaction, "SerialNo",transactionSerialNo);
String relativeObjectType = transaction.getString("RelativeObjectType");
String relativeObjectNo = transaction.getString("RelativeObjectNo");
//获取交易对象JBO配置信息便于拼接锁定交易对象的sql
StateBizObjectManager m = (StateBizObjectManager)JBOFactory.getFactory().getManager(relativeObjectType);
BizObjectClass clazz = JBOFactory.getBizObjectClass(relativeObjectType);
String[] keys = clazz.getKeyAttributes();
if(keys==null||keys.length == 0) {
throw new JBOException("对象"+relativeObjectType+"的主键未定义!");
}
if(keys.length>1){
throw new JBOException("对象"+relativeObjectType+"为复合主键!");
}
if(clazz.getAttribute(keys[0]).getType() != DataElement.STRING){
throw new JBOException("对象"+relativeObjectType+"的主键不是字符型!");
}
//锁定交易对象sql执行
sqlo = new SqlObject("update "+m.getTable()+" set "+keys[0]+"="+keys[0]+" where "+keys[0]+" = :"+keys[0]);
sqlo.setParameter(keys[0], relativeObjectNo);
Sqlca.executeSQL(sqlo);
//锁定该笔交易对象信息完成。
transaction = TransactionHelper.loadTransaction(transaction, bom);//加载交易
transaction.setAttributeValue("TransDate",DateHelper.getBusinessDate());//设置交易实际执行日期
if(!"0".equals(transaction.getString("TransStatus"))){
messageError = "false@错误原因:交易状态不正常,确认是否已记账!";
return messageError;
}
if(!StringX.isEmpty(transaction.getString("TransDate")) && transaction.getString("TransDate").compareTo(DateHelper.getBusinessDate())>0 && "N".equals(flag))
{
ARE.getLog().info("交易【"+transaction.getKeyString()+"】已经预约到【"+transaction.getString("TransDate")+"");
transaction.setAttributeValue("TransStatus", "3");
bom.updateBusinessObject(transaction);
bom.updateDB();
}else{
TransactionHelper.executeCheckTransaction(transaction, bom);//交易检查
TransactionHelper.executeTransaction(transaction, bom);//执行交易
bom.updateDB();
//调用接口
TransactionHelper.invokingTransaction(transaction, bom);
bom.updateDB();
}
bom.commit();
messageError = "true@交易成功";
return messageError;
}
catch(Exception e){
bom.rollback();
ARE.getLog().debug("系统出错", e);
e.printStackTrace();
messageError = "false@错误原因:"+e.getMessage();
throw e;
}
}
}