提交 5bd82f6a 编写于 作者: zhouweidong's avatar zhouweidong

区分本地与远程逻辑

上级 9ecc8dca
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
TARGET=PSSYSTEM TARGET=PSSYSTEM
</#ibiztemplate> </#ibiztemplate>
<#if sys.getCodeName()=='Sample' || sys.getCodeName()=='EAM'> <#if sys.getCodeName()=='Sample' || sys.getCodeName()=='EAM'>
<#assign isDynaSys =false>
<#if pub.isEnableDynaModel()?? && pub.isEnableDynaModel()== true>
<#assign isDynaSys =true>
</#if>
package ${pub.getPKGCodeName()}.util.aspect; package ${pub.getPKGCodeName()}.util.aspect;
import lombok.SneakyThrows; import lombok.SneakyThrows;
...@@ -62,66 +66,19 @@ import java.util.regex.Pattern; ...@@ -62,66 +66,19 @@ import java.util.regex.Pattern;
@Slf4j @Slf4j
public class DELogicAspect { public class DELogicAspect {
public enum LogicMode {
/**
* 本地
*/
LOCAL("0", "本地模式"),
/**
* 远程
*/
REMOTE("1", "远程模式");
LogicMode(String value, String text) {
this.value = value;
this.text = text;
}
private String value;
private String text;
}
private static BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter(); private static BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
private final ExpressionParser parser = new SpelExpressionParser(); private final ExpressionParser parser = new SpelExpressionParser();
private ConcurrentMap<String, DELogic> deLogicMap = new ConcurrentHashMap<>(); private ConcurrentMap<String, DELogic> deLogicMap = new ConcurrentHashMap<>();
private final String DEFAULT_MODULE_PACKAGE = "[\\w+\\.]\\.core.(\\w+)\\.domain"; private final String DEFAULT_MODULE_PACKAGE = "[\\w+\\.]\\.core.(\\w+)\\.domain";
@Value("${r'${ibiz.dynamicMode:true}'}") private static Map<String, Object> validLogic = new HashMap<>();
private boolean dynamicMode; <#if isDynaSys>
@Value("${r'${ibiz.dynamic.path:/app/file/dynamicmodel/}'}") @Value("${r'${ibiz.dynamic.path:/app/file/dynamicmodel/}'}")
private String dynamicPath; private String dynamicPath;
@Value("${r'$'}{ibiz.systemid:${sys.getCodeName()}}") @Value("${r'$'}{ibiz.systemid:${sys.getCodeName()}}")
private String systemId; private String systemId;
@Value("${r'$'}{ibiz.dynainstid:${sys.getCodeName()?lower_case}}") @Value("${r'$'}{ibiz.dynainstid:${sys.getCodeName()?lower_case}}")
private String dynamicId; private String dynamicId;
private static Map<String, Object> validLogic = new HashMap<>(); </#if>
/**
* 执行动态行为
* @param point
*/
@AfterReturning(value = "execution(* ${pub.getPKGCodeName()}.core.*.service.*.dynamicCall(..))")
public void dynamicCall(JoinPoint point) {
Object args[] = point.getArgs();
if (!ObjectUtils.isEmpty(args) || args.length == 3) {
Object id = args[0];
String action = String.valueOf(args[1]);
Object entity = args[2];
if (entity instanceof EntityBase) {
log.debug("开始执行实体动态行为[{}:{}]", entity.getClass().getSimpleName(), action);
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("service", point.getTarget());
context.setVariable("action", action);
if ("remove".equalsIgnoreCase(action) || "get".equalsIgnoreCase(action)) {
context.setVariable("args", id);
} else {
context.setVariable("args", entity);
}
Expression oldExp = parser.parseExpression(String.format("#service.%s(#args)", action));
oldExp.getValue(context);
log.debug("实体动态行为[{}:{}]执行结束", entity.getClass().getSimpleName(), action);
}
}
}
/** /**
* 执行实体行为附加逻辑、实体行为调用处理逻辑 * 执行实体行为附加逻辑、实体行为调用处理逻辑
...@@ -157,29 +114,6 @@ public class DELogicAspect { ...@@ -157,29 +114,6 @@ public class DELogicAspect {
return point.proceed(); return point.proceed();
} }
/**
* 获取实体
*
* @param service
* @return
* @throws Exception
*/
private EntityBase getEntity(Object service) throws Exception {
Method[] methods = service.getClass().getDeclaredMethods();
for (Method method : methods) {
for (Class cls : method.getParameterTypes()) {
try {
Object arg = cls.newInstance();
if (arg instanceof EntityBase) {
return (EntityBase) arg;
}
} catch (InstantiationException e) {
}
}
}
throw new BadRequestAlertException("获取实体信息失败", "DELogicAspect", "getEntity");
}
/** /**
* 前附加逻辑 * 前附加逻辑
* *
...@@ -188,14 +122,14 @@ public class DELogicAspect { ...@@ -188,14 +122,14 @@ public class DELogicAspect {
*/ */
private void executeBeforeLogic(EntityBase entity, String action) { private void executeBeforeLogic(EntityBase entity, String action) {
File bpmnFile; File bpmnFile;
if (dynamicMode) { <#if isDynaSys>
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "before"); bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, LogicExecMode.BEFORE);
if (bpmnFile.exists()) { if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE); executeLogic(bpmnFile, entity, action, LogicMode.REMOTE);
return; return;
}
} }
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, "before"); </#if>
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, LogicExecMode.BEFORE);
if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) { if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic(bpmnFile, entity, action, LogicMode.LOCAL); executeLogic(bpmnFile, entity, action, LogicMode.LOCAL);
} }
...@@ -209,14 +143,14 @@ public class DELogicAspect { ...@@ -209,14 +143,14 @@ public class DELogicAspect {
*/ */
private void executeAfterLogic(EntityBase entity, String action) { private void executeAfterLogic(EntityBase entity, String action) {
File bpmnFile; File bpmnFile;
if (dynamicMode) { <#if isDynaSys>
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "after"); bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, LogicExecMode.AFTER);
if (bpmnFile.exists()) { if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE); executeLogic(bpmnFile, entity, action, LogicMode.REMOTE);
return; return;
}
} }
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, "after"); </#if>
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, LogicExecMode.AFTER);
if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) { if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic(bpmnFile, entity, action, LogicMode.LOCAL); executeLogic(bpmnFile, entity, action, LogicMode.LOCAL);
} }
...@@ -230,14 +164,14 @@ public class DELogicAspect { ...@@ -230,14 +164,14 @@ public class DELogicAspect {
*/ */
private void executeLogic(EntityBase entity, String action) { private void executeLogic(EntityBase entity, String action) {
File bpmnFile; File bpmnFile;
if (dynamicMode) { <#if isDynaSys>
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "exec"); bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, LogicExecMode.EXEC);
if (bpmnFile.exists()) { if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE); executeLogic(bpmnFile, entity, action, LogicMode.REMOTE);
return; return;
}
} }
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, "exec"); </#if>
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, LogicExecMode.EXEC);
if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) { if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic(bpmnFile, entity, action, LogicMode.LOCAL); executeLogic(bpmnFile, entity, action, LogicMode.LOCAL);
} }
...@@ -369,10 +303,10 @@ public class DELogicAspect { ...@@ -369,10 +303,10 @@ public class DELogicAspect {
if (item instanceof CallActivity) { if (item instanceof CallActivity) {
CallActivity subBpmn = (CallActivity) item; CallActivity subBpmn = (CallActivity) item;
String bpmnFileName = subBpmn.getName(); String bpmnFileName = subBpmn.getName();
log.debug("正在加载 ********************BPMN:{}********************",bpmnFileName); log.debug("正在加载 BPMN{}", bpmnFileName);
File subBpmnFile = getSubBpmn(getDEModule(entity), entity.getClass().getSimpleName(), bpmnFileName, logicMode); File subBpmnFile = getSubBpmn(getDEModule(entity), entity.getClass().getSimpleName(), bpmnFileName, logicMode);
if(!subBpmnFile.exists()){ if (ObjectUtils.isEmpty(subBpmnFile)) {
log.debug("BPMN:{},缺少文件:{} ",bpmnFileName,subBpmnFile); log.debug("BPMN:{},缺少文件:{} ", bpmnFileName, subBpmnFile);
} }
DELogic refLogic = getDELogic(subBpmnFile, entity, logicMode); DELogic refLogic = getDELogic(subBpmnFile, entity, logicMode);
if (refLogic != null) { if (refLogic != null) {
...@@ -407,6 +341,29 @@ public class DELogicAspect { ...@@ -407,6 +341,29 @@ public class DELogicAspect {
return logic; return logic;
} }
/**
* 获取实体
*
* @param service
* @return
* @throws Exception
*/
private EntityBase getEntity(Object service) throws Exception {
Method[] methods = service.getClass().getDeclaredMethods();
for (Method method : methods) {
for (Class cls : method.getParameterTypes()) {
try {
Object arg = cls.newInstance();
if (arg instanceof EntityBase) {
return (EntityBase) arg;
}
} catch (InstantiationException e) {
}
}
}
throw new BadRequestAlertException("获取实体信息失败", "DELogicAspect", "getEntity");
}
/** /**
* 获取bpmn md5 * 获取bpmn md5
* *
...@@ -446,29 +403,31 @@ public class DELogicAspect { ...@@ -446,29 +403,31 @@ public class DELogicAspect {
* *
* @param entity * @param entity
* @param action * @param action
* @param actionLogic * @param logicExecMode
* @return * @return
*/ */
private File getLocalModel(String entity, String action, String actionLogic) { private File getLocalModel(String entity, String action, LogicExecMode logicExecMode) {
String logicName = String.format("%s.bpmn", actionLogic); String logicName = String.format("%s.bpmn", logicExecMode.value);
String filePath = File.separator + "rules" + File.separator + entity.toLowerCase() + File.separator + action + File.separator + logicName; String filePath = File.separator + "rules" + File.separator + entity.toLowerCase() + File.separator + action + File.separator + logicName;
URL url = this.getClass().getResource(filePath.replace("\\", "/")); URL url = this.getClass().getResource(filePath.replace("\\", "/"));
return ObjectUtils.isEmpty(url) ? null : new File(url.getPath()); return ObjectUtils.isEmpty(url) ? null : new File(url.getPath());
} }
<#if isDynaSys>
/** /**
* 远程逻辑 * 远程逻辑
* *
* @param module * @param module
* @param entity * @param entity
* @param action * @param action
* @param actionLogic * @param logicExecMode
* @return * @return
*/ */
private File getRemoteModel(String module, String entity, String action, String actionLogic) { private File getRemoteModel(String module, String entity, String action, LogicExecMode logicExecMode) {
String logicName = String.format("psdeaction.json.%s.bpmn", actionLogic); String logicName = String.format("psdeaction.json.%s.bpmn", logicExecMode.value);
return new File(dynamicPath + File.separator + (systemId + File.separator + dynamicId + File.separator + "psmodules" + File.separator + module + File.separator + "psdataentities" + File.separator + entity + File.separator + "psdeactions" + File.separator + action + File.separator + logicName).toLowerCase()); return new File(dynamicPath + File.separator + (systemId + File.separator + dynamicId + File.separator + "psmodules" + File.separator + module + File.separator + "psdataentities" + File.separator + entity + File.separator + "psdeactions" + File.separator + action + File.separator + logicName).toLowerCase());
} }
</#if>
/** /**
* 处理逻辑 bpmn * 处理逻辑 bpmn
...@@ -479,12 +438,18 @@ public class DELogicAspect { ...@@ -479,12 +438,18 @@ public class DELogicAspect {
* @return * @return
*/ */
private File getSubBpmn(String module, String entity, String logicName, LogicMode logicMode) { private File getSubBpmn(String module, String entity, String logicName, LogicMode logicMode) {
<#if isDynaSys>
if (LogicMode.REMOTE.equals(logicMode)) { if (LogicMode.REMOTE.equals(logicMode)) {
return new File(dynamicPath + File.separator + (systemId + File.separator + dynamicId + File.separator + "psmodules" + File.separator + module + File.separator + "psdataentities" + File.separator + entity + File.separator + "psdelogics" + File.separator + logicName + File.separator + "psdelogic.json.bpmn").toLowerCase()); return new File(dynamicPath + File.separator + (systemId + File.separator + dynamicId + File.separator + "psmodules" + File.separator + module + File.separator + "psdataentities" + File.separator + entity + File.separator + "psdelogics" + File.separator + logicName + File.separator + "psdelogic.json.bpmn").toLowerCase());
} else { } else {
String filePath = String.format("/rules/%s", logicName); String filePath = String.format("/rules/%s", logicName);
return ObjectUtils.isEmpty(this.getClass().getResource(filePath)) ? null : new File(this.getClass().getResource(filePath).getPath()); return ObjectUtils.isEmpty(this.getClass().getResource(filePath)) ? null : new File(this.getClass().getResource(filePath).getPath());
} }
<#else>
String filePath = String.format("/rules/%s", logicName);
return ObjectUtils.isEmpty(this.getClass().getResource(filePath)) ? null : new File(this.getClass().getResource(filePath).getPath());
</#if>
} }
/** /**
...@@ -494,11 +459,15 @@ public class DELogicAspect { ...@@ -494,11 +459,15 @@ public class DELogicAspect {
* @return * @return
*/ */
private File getDrl(File bpmn) { private File getDrl(File bpmn) {
<#if isDynaSys>
if (bpmn.getPath().endsWith("RuleFlow.bpmn")) { if (bpmn.getPath().endsWith("RuleFlow.bpmn")) {
return new File(bpmn.getPath().replace("RuleFlow.bpmn", "Rule.drl")); return new File(bpmn.getPath().replace("RuleFlow.bpmn", "Rule.drl"));
} else { } else {
return new File(bpmn.getPath().replace(".bpmn", ".drl")); return new File(bpmn.getPath().replace(".bpmn", ".drl"));
} }
<#else>
return new File(bpmn.getPath().replace("RuleFlow.bpmn", "Rule.drl"));
</#if>
} }
/** /**
...@@ -521,6 +490,37 @@ public class DELogicAspect { ...@@ -521,6 +490,37 @@ public class DELogicAspect {
return strModule; return strModule;
} }
<#if isDynaSys>
/**
* 执行动态行为
*
* @param point
*/
@AfterReturning(value = "execution(* ${pub.getPKGCodeName()}.core.*.service.*.dynamicCall(..))")
public void dynamicCall(JoinPoint point) {
Object args[] = point.getArgs();
if (!ObjectUtils.isEmpty(args) || args.length == 3) {
Object id = args[0];
String action = String.valueOf(args[1]);
Object entity = args[2];
if (entity instanceof EntityBase) {
log.debug("开始执行实体动态行为[{}:{}]", entity.getClass().getSimpleName(), action);
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("service", point.getTarget());
context.setVariable("action", action);
if ("remove".equalsIgnoreCase(action) || "get".equalsIgnoreCase(action)) {
context.setVariable("args", id);
} else {
context.setVariable("args", entity);
}
Expression oldExp = parser.parseExpression(String.format("#service.%s(#args)", action));
oldExp.getValue(context);
log.debug("实体动态行为[{}:{}]执行结束", entity.getClass().getSimpleName(), action);
}
}
}
</#if>
/** /**
* 逻辑是否有效 * 逻辑是否有效
* *
...@@ -539,36 +539,63 @@ public class DELogicAspect { ...@@ -539,36 +539,63 @@ public class DELogicAspect {
} }
static { static {
<#if sys.getAllPSDataEntities()??> validLogic.put("bsentity2checkkeybefore.bpmn", 1);
<#list sys.getAllPSDataEntities() as dataEntity> validLogic.put("bsentity2checkkeyafter.bpmn", 1);
<#if dataEntity.getAllPSDEActions()??> validLogic.put("citysyncmqdatabefore.bpmn", 1);
<#list dataEntity.getAllPSDEActions() as deaction> validLogic.put("citysyncmqdataafter.bpmn", 1);
<#comment>前附加逻辑</#comment> validLogic.put("citysyncmqdataexec.bpmn", 1);
<#if deaction.getBeforePSDEActionLogics()??> validLogic.put("humancreatebefore.bpmn", 1);
<#list deaction.getBeforePSDEActionLogics() as beforeLogic> validLogic.put("humancustom3before.bpmn", 1);
<#if (beforeLogic.isValid()==true && beforeLogic.isInternalLogic() && beforeLogic.getPSDELogic().isEnableBackend()) || validLogic.put("humancustom3after.bpmn", 1);
(beforeLogic.getDstPSDE()!'')!='' && (beforeLogic.getDstPSDEAction()!'')!='' && beforeLogic.getDstPSDEAction().isEnableBackend() > validLogic.put("humancustom3exec.bpmn", 1);
validLogic.put("${(dataEntity.codeName+deaction.codeName)?lower_case}before.bpmn", 1); validLogic.put("humancustomdeleteexec.bpmn", 1);
</#if> validLogic.put("humangettaxamountexec.bpmn", 1);
</#list> validLogic.put("humanlogicexec.bpmn", 1);
</#if> validLogic.put("humansmileexec.bpmn", 1);
<#comment>后附加逻辑</#comment> validLogic.put("humantaxamountexec.bpmn", 1);
<#if deaction.getAfterPSDEActionLogics()??> validLogic.put("loginaccountsyncsysadminexec.bpmn", 1);
<#list deaction.getAfterPSDEActionLogics() as afterLogic> }
<#if (afterLogic.isValid()==true && afterLogic.isInternalLogic() && afterLogic.getPSDELogic().isEnableBackend()) ||
(afterLogic.getDstPSDE()!'')!='' && (afterLogic.getDstPSDEAction()!'')!='' && afterLogic.getDstPSDEAction().isEnableBackend() > public enum LogicMode {
validLogic.put("${(dataEntity.codeName+deaction.codeName)?lower_case}after.bpmn", 1); /**
</#if> * 本地
</#list> */
</#if> LOCAL("0", "本地模式"),
<#comment>行为调用逻辑</#comment> /**
<#if deaction.getActionType() =='DELOGIC' && deaction.getPSDELogic().isEnableBackend()> * 远程
validLogic.put("${(dataEntity.codeName+deaction.codeName)?lower_case}exec.bpmn", 1); */
</#if> REMOTE("1", "远程模式");
</#list>
</#if> LogicMode(String value, String text) {
</#list> this.value = value;
</#if> this.text = text;
}
private String value;
private String text;
}
public enum LogicExecMode {
/**
* 前附加逻辑
*/
BEFORE("0", "before"),
/**
* 后附加逻辑
*/
AFTER("1", "after"),
/**
*
*/
EXEC("2", "exec");
LogicExecMode(String value, String text) {
this.value = value;
this.text = text;
}
private String value;
private String text;
} }
} }
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册