Commit b370961e by s_guodong

流程控制和日志打印

parent 14788401
......@@ -61,20 +61,24 @@ public abstract class AbstractAutoCompileEmitter extends AbstractRuleEmitter {
continue;
}
try {
boolean b = true;
switch (ruleItem.getRuleType()) {
case RuleItem.INIT:
execInitItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot()));
b = execInitItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot()));
break;
case RuleItem.CHECK:
execCheckItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot()));
b = execCheckItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot()));
break;
case RuleItem.DEFAULT:
execDefaultItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot()));
b = execDefaultItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot()));
break;
case RuleItem.RULE:
execRuleItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot()));
b = execRuleItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot()));
break;
}
if (!b) {
return false;
}
} catch (Exception e) {
log.error("execute Rule Exception", e);
throw e;
......@@ -164,6 +168,7 @@ public abstract class AbstractAutoCompileEmitter extends AbstractRuleEmitter {
boolean result = invokeRuleList(RuleItem.CHECK, entry.getKey(), order);
if (!result) {
log.warn(String.format("execute @Check[%s,%d] return false", entry.getKey(), order));
return false;
}
}
return true;
......
......@@ -109,7 +109,7 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
protected boolean checkPathMatch(String path, String target) {
if(target.startsWith("\\")){
if (target.startsWith("\\")) {
target = target.substring(1).toLowerCase();
}
int targetLen = target.length();
......@@ -322,7 +322,7 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
Boolean result = executeInit(-1);
return result;
} catch (RuleExitException e) {
throw new RuleExecuteException("Init执行返回false", e);
throw new RuleExecuteException("Init执行异常", e);
// return false;
} catch (Exception ex) {
DCR.emptyDefaultQueue();
......@@ -346,7 +346,7 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
}
}
public void execInitItem(int order, String path, Ruleable<Boolean> ruleHolder) {
public boolean execInitItem(int order, String path, Ruleable<Boolean> ruleHolder) {
boolean ignore = false;
if (ruleHolder instanceof RuleItemExecutor) {
RuleItemExecutor executor = (RuleItemExecutor) ruleHolder;
......@@ -365,14 +365,16 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
if (!ruleHolder.exec()) {
stopWatch.stop();
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execInitItem", path, order);
throw new RuleExitException(String.format("%s init %d %s exit", MdaEnv.getContext().getTransName(), order, path));
// throw new RuleExitException(String.format("%s init %d %s exit", MdaEnv.getContext().getTransName(), order, path));
return false;
}
stopWatch.stop();
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execInitItem", path, order);
}
return true;
}
public void execRuleItem(int order, String path, Ruleable<Boolean> ruleHolder) {
public boolean execRuleItem(int order, String path, Ruleable<Boolean> ruleHolder) {
boolean ignore = false;
String eventPath = MdaEnv.getContext().getEventPath();
if (ruleHolder instanceof RuleItemExecutor) {
......@@ -394,7 +396,8 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
if (!b) {
stopWatch.stop();
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execRuleItem", path, order);
throw new RuleExitException(String.format("%s rule %d %s exit", MdaEnv.getContext().getTransName(), order, eventPath));
return false;
// throw new RuleExitException(String.format("%s rule %d %s exit", MdaEnv.getContext().getTransName(), order, eventPath));
}
if (MdaEnv.getContext().getFieldErrors().size() > oldLength) {
log.warn("{} rule [{}] [{}] set fieldError", MdaEnv.getContext().getTransName(), order, eventPath);
......@@ -402,10 +405,11 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
stopWatch.stop();
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execRuleItem", path, order);
}
return true;
//log.debug("rule [{}] [{}] finished",order,eventPath);
}
public void execCheckItem(int order, String path, Ruleable<Boolean> ruleHolder) {
public boolean execCheckItem(int order, String path, Ruleable<Boolean> ruleHolder) {
boolean ignore = false;
String eventPath = MdaEnv.getContext().getEventPath();
if (ruleHolder instanceof RuleItemExecutor) {
......@@ -426,7 +430,8 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
if (!ruleHolder.exec()) {
stopWatch.stop();
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execCheckItem", path, order);
throw new RuleExitException(String.format("check [%d] [%s] exit", order, eventPath));
// throw new RuleExitException(String.format("check [%d] [%s] exit", order, eventPath));
return false;
}
if (MdaEnv.getContext().getFieldErrors().size() > oldLength) {
log.warn(String.format("%s check [%d] [%s] set fieldError", MdaEnv.getContext().getTransName(), order, eventPath));
......@@ -435,9 +440,10 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execCheckItem", path, order);
//log.debug("check [{}] [{}] finished",order,eventPath);
}
return true;
}
public void execDefaultItem(int order, String path, Ruleable<Boolean> ruleHolder) {
public boolean execDefaultItem(int order, String path, Ruleable<Boolean> ruleHolder) {
boolean ignore = false;
String eventPath = MdaEnv.getContext().getEventPath();
if (ruleHolder instanceof RuleItemExecutor) {
......@@ -457,12 +463,14 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
if (!ruleHolder.exec()) {
stopWatch.stop();
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execDefaultItem", path, order);
throw new RuleExitException(String.format("%s default [%d] [%s] exit", MdaEnv.getContext().getTransName(), order, eventPath));
// throw new RuleExitException(String.format("%s default [%d] [%s] exit", MdaEnv.getContext().getTransName(), order, eventPath));
return false;
}
stopWatch.stop();
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execDefaultItem", path, order);
//log.debug("default [{}] [{}] finished",order,eventPath);
}
return true;
}
public List<IModuleList> getAllModuleList() {
......
......@@ -157,19 +157,26 @@ public abstract class AbstractRouteService<V extends BaseVO> {
try {
StopWatch stopWatch = new StopWatch("executeCheck:" + StringUtils.join(rulePathArr, ','));
stopWatch.start("enterTransaction");
enterTransaction(req);
boolean b = enterTransaction(req);
stopWatch.stop();
IContext ctx = MdaEnv.getContext();
if (!b) {
return new ResponseSet<V>(ctx, req);
}
synchronized (ctx) {
stopWatch.start("setValueFromVO");
setValueFromVO(req);
stopWatch.stop();
stopWatch.start("executeStepWithCheckList");
executeStepWithCheckList(rulePathArr);
boolean[] step = executeStepWithCheckList(rulePathArr);
stopWatch.stop();
boolean continueFlag = summarizeResult(step);
if (!continueFlag) {
return new ResponseSet<V>(ctx.getErrorNo(), ctx.getErrorMessage(), req);
}
stopWatch.start("afterExecute");
boolean result = ctx.getFieldErrors().size() <= 0;
afterExecute(rulePathArr);
......@@ -199,10 +206,13 @@ public abstract class AbstractRouteService<V extends BaseVO> {
try {
StopWatch stopWatch = new StopWatch("executeRule:" + StringUtils.join(rulePathArr, ','));
stopWatch.start("enterTransaction");
enterTransaction(req);
boolean b = enterTransaction(req);
stopWatch.stop();
IContext ctx = MdaEnv.getContext();
if (!b) {
return new ResponseSet<V>(ctx.getErrorNo(), ctx.getErrorMessage(), req);
}
synchronized (ctx) {
stopWatch.start("setValueFromVO");
setValueFromVO(req);
......@@ -212,6 +222,11 @@ public abstract class AbstractRouteService<V extends BaseVO> {
boolean[] step = executeStepWithRuleList(rulePathArr);
stopWatch.stop();
boolean continueFlag = summarizeResult(step);
if (!continueFlag) {
return new ResponseSet<V>(ctx.getErrorNo(), ctx.getErrorMessage(), req);
}
// checkAll时对ModuleList进行check
if (rulePathArr.length == 1 && CHEK_PATH.equals(rulePathArr[0])) {
stopWatch.start("executeCheckAll");
......@@ -240,14 +255,13 @@ public abstract class AbstractRouteService<V extends BaseVO> {
//return new ResponseSet<V>(ctx.getErrorNo(), ctx.getErrorMessage(), ctx.getFieldErrors());
}
} catch (Exception e) {
// throw new RuleExecuteException(e.getMessage(), e);
IContext ctx = MdaEnv.getContext();
return new ResponseSet<V>(ctx.getErrorNo(), ctx.getErrorMessage());
return ResponseSet.fail(e.getMessage());
} finally {
DCR.emptyDefaultQueue();
}
}
/**
* 执行defaultRule
*/
......@@ -328,16 +342,11 @@ public abstract class AbstractRouteService<V extends BaseVO> {
/**
* 初始化步骤
*/
public void initTrans(V req) {
public boolean initTrans(V req) {
IContext ctx = MdaEnv.getContext();
if (req != null) {
ctx.setVo(req);
}
// if (!req.isNeedInit()) {
// logger.info("不需要初始化");
// return;
// }
// logger.info("开始初始化...");
StopWatch watch = new StopWatch("initTrans");
IRuleEmitter emitter = getEmitter();
//将认证信息(usr、usg、ety)放入sysStream
......@@ -349,8 +358,12 @@ public abstract class AbstractRouteService<V extends BaseVO> {
//一阶段,构造与初始化
// DCR.emptyDefaultQueue();
watch.start("executeInit");
emitter.executeInit(); // 执行初始
boolean b = emitter.executeInit();// 执行初始
watch.stop();
// 初始化返回false就不往下执行了
if (!b) {
return false;
}
DCR.enNotify(true);
watch.start("executeDefaultAfterInit");
emitter.executeDefaultAfterInit();
......@@ -362,6 +375,7 @@ public abstract class AbstractRouteService<V extends BaseVO> {
logger.info(watch.prettyPrint());
//执行Default
DCR.executeQueue();
return true;
}
/**
......@@ -393,6 +407,9 @@ public abstract class AbstractRouteService<V extends BaseVO> {
String path = ruleList[i];
Argument<String> pathBox = Argument.box(path);
result[i] = getEmitterByPath(pathBox).executeRule(pathBox.value);
if (!result[i]) {
return result;
}
//todo 判断是否列表数据,例如机构选择,如果是则不执行后续的default,
Map<String, Object> gridData = MdaEnv.getGridData();
if (gridData != null && ruleList.length == 1) {
......@@ -417,6 +434,9 @@ public abstract class AbstractRouteService<V extends BaseVO> {
String path = ruleList[i];
Argument<String> pathBox = Argument.box(path);
result[i] = getEmitterByPath(pathBox).executeCheck(pathBox.value);
if (!result[i]) {
return result;
}
//执行Default
DCR.executeQueue();
executeAndClearPostQueue();
......@@ -476,7 +496,7 @@ public abstract class AbstractRouteService<V extends BaseVO> {
}
ctx.storeData(IContext.DISPLAY_KEY, req);
initTrans(req);
return initTrans(req);
}
return true;
}
......@@ -490,4 +510,13 @@ public abstract class AbstractRouteService<V extends BaseVO> {
// DCR.executeQueue(false);
beforeExecute();
}
private boolean summarizeResult(boolean[] step) {
for (boolean b : step) {
if (!b) {
return b;
}
}
return true;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment