增加公共处理
This commit is contained in:
+114
@@ -0,0 +1,114 @@
|
||||
package com.murong.ecp.netpay.mbu.web.interceptor;
|
||||
|
||||
import com.murong.ecp.bp.common.annotation.ECPInterceptorMapping;
|
||||
import com.murong.ecp.netpay.mbu.web.common.utils.CommonMessageCode;
|
||||
import com.yuangou.ecp.biz.transengine.YGAbstractBizIntercetpor;
|
||||
import com.yuangou.ecp.biz.transengine.sqlsession.YGSqlSession;
|
||||
import com.yuangou.ecp.biz.transengine.util.GDAUtil;
|
||||
import com.yuangou.ecp.bp.comp.expr.YGExpUtil;
|
||||
import com.yuangou.ecp.bp.comp.pubatc.YGPUBATCUtil;
|
||||
import com.yuangou.ecp.bp.core.common.exception.YGException;
|
||||
import com.yuangou.ecp.bp.core.common.message.YGBizMessage;
|
||||
import com.yuangou.ecp.bp.core.common.message.YGBizMessageContext;
|
||||
import com.yuangou.ecp.bp.core.common.message.YGEDB;
|
||||
import com.yuangou.ecp.bp.core.common.yglog4j.Logger;
|
||||
import com.yuangou.ecp.bp.core.common.yglog4j.YGLogger;
|
||||
import com.yuangou.ecp.bp.database.YGDatabaseUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
|
||||
/**
|
||||
* 公共处理
|
||||
*/
|
||||
@ECPInterceptorMapping({".*"})
|
||||
public class BUIInterceptor extends YGAbstractBizIntercetpor {
|
||||
|
||||
@Override
|
||||
public void onError(YGBizMessageContext bizCtx, Throwable t) throws YGException {
|
||||
|
||||
YGBizMessage msg = bizCtx.getCurrentMsg();
|
||||
|
||||
Logger logger = YGLogger.getLogger(msg);
|
||||
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("执行异常处理:[" + this.getClass().getSimpleName() + ".onError]");
|
||||
logger.info("运行时异常,回滚数据库事务");
|
||||
}
|
||||
|
||||
YGPUBATCUtil.rollbackWork(bizCtx);
|
||||
GDAUtil.setMsg_cd(msg, CommonMessageCode.FAIL.getMsgCod());
|
||||
GDAUtil.setMsg_inf(msg, CommonMessageCode.FAIL.getMsgInf());
|
||||
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error(ExceptionUtils.getFullStackTrace(t));
|
||||
}
|
||||
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("异常处理结束:[" + this.getClass().getSimpleName() + ".onError]");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onRequest(YGBizMessageContext bizCtx) throws YGException {
|
||||
|
||||
YGBizMessage msg = bizCtx.getCurrentMsg();
|
||||
Logger logger = YGLogger.getLogger(msg);
|
||||
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("执行前处理:[" + this.getClass().getSimpleName() + ".onRequest]");
|
||||
}
|
||||
|
||||
YGPUBATCUtil.initGDS(bizCtx);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("初始化GDA成功");
|
||||
logger.info("前处理结束:[" + this.getClass().getSimpleName() + ".onRequest]");
|
||||
}
|
||||
|
||||
YGDatabaseUtil dbUtlil = bizCtx.getDataBaseUtil();
|
||||
dbUtlil.insert("insert t(a,b) values(?,?)", new String[]{"a", "b"});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(YGBizMessageContext bizCtx) throws YGException {
|
||||
// 公共后处理
|
||||
|
||||
YGBizMessage msg = bizCtx.getCurrentMsg();
|
||||
YGEDB edb = msg.getEDBBody();
|
||||
|
||||
Logger logger = YGLogger.getLogger(msg);
|
||||
logger.info("执行后处理:[" + this.getClass().getSimpleName() + ".onResponse]");
|
||||
|
||||
String msg_cd = GDAUtil.getMsg_cd(msg);
|
||||
|
||||
if (StringUtils.isBlank(msg_cd)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("消息编码为空");
|
||||
}
|
||||
|
||||
GDAUtil.setMsg_cd(msg, CommonMessageCode.FAIL.getMsgCod());
|
||||
GDAUtil.setMsg_inf(msg, CommonMessageCode.FAIL.getMsgInf());
|
||||
}
|
||||
|
||||
edb.setData("msg_cd", msg_cd);
|
||||
|
||||
if (YGExpUtil.is_succ(msg_cd)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("业务处理成功,提交数据库事务");
|
||||
}
|
||||
|
||||
edb.setData("gda.msg_typ", "N");
|
||||
YGPUBATCUtil.commitWork(bizCtx);
|
||||
} else {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("业务处理失败,回滚数据库事务");
|
||||
}
|
||||
edb.setData("gda.msg_typ", "E");
|
||||
YGPUBATCUtil.rollbackWork(bizCtx);
|
||||
}
|
||||
|
||||
logger.info("后处理结束:[" + this.getClass().getSimpleName() + ".onResponse]");
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user