提交 8290978f 编写于 作者: zhouweidong's avatar zhouweidong

补充有效逻辑

上级 7835622f
...@@ -46,6 +46,7 @@ import java.io.InputStream; ...@@ -46,6 +46,7 @@ import java.io.InputStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
...@@ -65,14 +66,14 @@ public class DELogicAspect { ...@@ -65,14 +66,14 @@ public class DELogicAspect {
/** /**
* 本地 * 本地
*/ */
LOCAL("0","本地模式"), LOCAL("0", "本地模式"),
/** /**
* 远程 * 远程
*/ */
REMOTE("1","远程模式"); REMOTE("1", "远程模式");
LogicMode(String value , String text) { LogicMode(String value, String text) {
this.value=value; this.value = value;
this.text = text; this.text = text;
} }
...@@ -90,21 +91,22 @@ public class DELogicAspect { ...@@ -90,21 +91,22 @@ public class DELogicAspect {
private String dynamicPath; private String dynamicPath;
@Value("${r'$'}{ibiz.systemid:${sys.getCodeName()}}") @Value("${r'$'}{ibiz.systemid:${sys.getCodeName()}}")
private String systemId; private String systemId;
private static Map<String, Object> validLogic = new HashMap<>();
@AfterReturning(value = "execution(* ${pub.getPKGCodeName()}.core.*.service.*.dynamicCall(..))") @AfterReturning(value = "execution(* ${pub.getPKGCodeName()}.core.*.service.*.dynamicCall(..))")
public void dynamicCall(JoinPoint point){ public void dynamicCall(JoinPoint point) {
Object args[] = point.getArgs(); Object args[] = point.getArgs();
if (!ObjectUtils.isEmpty(args) || args.length == 3) { if (!ObjectUtils.isEmpty(args) || args.length == 3) {
Object action = args[1]; Object action = args[1];
Object entity = args[2]; Object entity = args[2];
log.debug("开始执行实体[{}]动态行为[{}]",entity.getClass().getSimpleName(), action); log.debug("开始执行实体动态行为[{}:{}]", entity.getClass().getSimpleName(), action);
EvaluationContext context = new StandardEvaluationContext(); EvaluationContext context = new StandardEvaluationContext();
context.setVariable("service", point.getTarget()); context.setVariable("service", point.getTarget());
context.setVariable("action", action); context.setVariable("action", action);
context.setVariable("entity", entity); context.setVariable("entity", entity);
Expression oldExp = parser.parseExpression(String.format("#service.%s(#entity)",action)); Expression oldExp = parser.parseExpression(String.format("#service.%s(#entity)", action));
oldExp.getValue(context); oldExp.getValue(context);
log.debug("实体[{}]动态行为[{}]执行结束",entity.getClass().getSimpleName(), action); log.debug("实体动态行为[{}:{}]执行结束", entity.getClass().getSimpleName(), action);
} }
} }
...@@ -125,15 +127,14 @@ public class DELogicAspect { ...@@ -125,15 +127,14 @@ public class DELogicAspect {
Object arg = args[0]; Object arg = args[0];
String action = point.getSignature().getName(); String action = point.getSignature().getName();
EntityBase entity = null; EntityBase entity = null;
if("remove".equalsIgnoreCase(action) || "get".equalsIgnoreCase(action)) { if ("remove".equalsIgnoreCase(action) || "get".equalsIgnoreCase(action)) {
entity = getEntity(service); entity = getEntity(service);
String id = DEFieldCacheMap.getDEKeyField(entity.getClass()); String id = DEFieldCacheMap.getDEKeyField(entity.getClass());
entity.set(id,arg); entity.set(id, arg);
} } else if (arg instanceof EntityBase) {
else if (arg instanceof EntityBase){
entity = (EntityBase) arg; entity = (EntityBase) arg;
} }
if(entity != null){ if (entity != null) {
executeBeforeLogic(entity, action); executeBeforeLogic(entity, action);
Object result = point.proceed(); Object result = point.proceed();
executeLogic(entity, action); executeLogic(entity, action);
...@@ -145,24 +146,25 @@ public class DELogicAspect { ...@@ -145,24 +146,25 @@ public class DELogicAspect {
/** /**
* 获取实体 * 获取实体
*
* @param service * @param service
* @return * @return
* @throws Exception * @throws Exception
*/ */
private EntityBase getEntity(Object service) throws Exception{ private EntityBase getEntity(Object service) throws Exception {
Method[] methods = service.getClass().getDeclaredMethods(); Method[] methods = service.getClass().getDeclaredMethods();
for(Method method : methods){ for (Method method : methods) {
for(Class cls : method.getParameterTypes()){ for (Class cls : method.getParameterTypes()) {
try { try {
Object arg = cls.newInstance(); Object arg = cls.newInstance();
if(arg instanceof EntityBase){ if (arg instanceof EntityBase) {
return (EntityBase) arg; return (EntityBase) arg;
} }
} catch (InstantiationException e) { } catch (InstantiationException e) {
} }
} }
} }
throw new BadRequestAlertException("获取实体信息失败","DELogicAspect","getEntity"); throw new BadRequestAlertException("获取实体信息失败", "DELogicAspect", "getEntity");
} }
/** /**
...@@ -176,13 +178,13 @@ public class DELogicAspect { ...@@ -176,13 +178,13 @@ public class DELogicAspect {
if (dynamicMode) { if (dynamicMode) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "before"); bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "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"); bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, "before");
if (bpmnFile != null && bpmnFile.exists()) { if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic(bpmnFile, entity ,action, LogicMode.LOCAL); executeLogic(bpmnFile, entity, action, LogicMode.LOCAL);
} }
} }
...@@ -197,12 +199,12 @@ public class DELogicAspect { ...@@ -197,12 +199,12 @@ public class DELogicAspect {
if (dynamicMode) { if (dynamicMode) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "after"); bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "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"); bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, "after");
if (bpmnFile != null && bpmnFile.exists()) { if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic(bpmnFile, entity, action, LogicMode.LOCAL); executeLogic(bpmnFile, entity, action, LogicMode.LOCAL);
} }
} }
...@@ -218,13 +220,13 @@ public class DELogicAspect { ...@@ -218,13 +220,13 @@ public class DELogicAspect {
if (dynamicMode) { if (dynamicMode) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "exec"); bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "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"); bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, "exec");
if (bpmnFile != null && bpmnFile.exists()) { if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic(bpmnFile, entity , action, LogicMode.LOCAL); executeLogic(bpmnFile, entity, action, LogicMode.LOCAL);
} }
} }
...@@ -235,7 +237,7 @@ public class DELogicAspect { ...@@ -235,7 +237,7 @@ public class DELogicAspect {
* @param entity * @param entity
*/ */
private void executeLogic(File bpmnFile, Object entity, String action, LogicMode logicMode) { private void executeLogic(File bpmnFile, Object entity, String action, LogicMode logicMode) {
log.debug("开始执行实体处理逻辑[{}:{}:{}:{}]",entity.getClass().getSimpleName(),action, bpmnFile.getName(),logicMode.text); log.debug("开始执行实体处理逻辑[{}:{}:{}:{}]", entity.getClass().getSimpleName(), action, bpmnFile.getName(), logicMode.text);
String bpmnId = DigestUtils.md5DigestAsHex(bpmnFile.getName().getBytes()); String bpmnId = DigestUtils.md5DigestAsHex(bpmnFile.getName().getBytes());
DELogic logic = getDELogic(bpmnFile, entity, logicMode); DELogic logic = getDELogic(bpmnFile, entity, logicMode);
if (logic == null) { if (logic == null) {
...@@ -259,7 +261,7 @@ public class DELogicAspect { ...@@ -259,7 +261,7 @@ public class DELogicAspect {
} }
} }
kieSession.startProcess(mainProcess.getId()); kieSession.startProcess(mainProcess.getId());
log.debug("实体处理逻辑[{}:{}:{}:{}]执行结束",entity.getClass().getSimpleName(),action, bpmnFile.getName(), logicMode.text); log.debug("实体处理逻辑[{}:{}:{}:{}]执行结束", entity.getClass().getSimpleName(), action, bpmnFile.getName(), logicMode.text);
} }
/** /**
...@@ -309,7 +311,7 @@ public class DELogicAspect { ...@@ -309,7 +311,7 @@ public class DELogicAspect {
Expression oldExp = parser.parseExpression(express_value); Expression oldExp = parser.parseExpression(express_value);
value = oldExp.getValue(oldContext); value = oldExp.getValue(oldContext);
} }
if("entity".equalsIgnoreCase(type.getValue()) || "refentity".equalsIgnoreCase(type.getValue())){ if ("entity".equalsIgnoreCase(type.getValue()) || "refentity".equalsIgnoreCase(type.getValue())) {
kieSession.insert(value); kieSession.insert(value);
} }
kieSession.setGlobal(name.getValue(), value); kieSession.setGlobal(name.getValue(), value);
...@@ -501,5 +503,56 @@ public class DELogicAspect { ...@@ -501,5 +503,56 @@ public class DELogicAspect {
} }
return strModule; return strModule;
} }
/**
* 逻辑是否有效
*
* @param bpmn
* @param entity
* @param action
* @return
*/
private boolean isValid(File bpmn, Object entity, Object action) {
String logicId = String.format("%s%s%s", entity.getClass().getSimpleName(), action, bpmn.getName()).toLowerCase();
if (validLogic.containsKey(logicId)) {
return true;
} else {
return false;
}
}
static {
<#if sys.getAllPSDataEntities()??>
<#list sys.getAllPSDataEntities() as dataEntity>
<#if dataEntity.getAllPSDEActions()??>
<#list dataEntity.getAllPSDEActions() as deaction>
<#comment>前附加逻辑</#comment>
<#if deaction.getBeforePSDEActionLogics()??>
<#list deaction.getBeforePSDEActionLogics() as beforeLogic>
<#if (beforeLogic.isValid()==true && beforeLogic.isInternalLogic() && beforeLogic.getPSDELogic().isEnableBackend()) ||
(beforeLogic.getDstPSDE()!'')!='' && (beforeLogic.getDstPSDEAction()!'')!='' && beforeLogic.getDstPSDEAction().isEnableBackend() >
validLogic.put("${(de.codeName+deaction.codeName)?lower_case}before.bpmn", 1);
</#if>
</#list>
</#if>
<#comment>后附加逻辑</#comment>
<#if deaction.getAfterPSDEActionLogics()??>
<#list deaction.getAfterPSDEActionLogics() as afterLogic>
<#if (afterLogic.isValid()==true && afterLogic.isInternalLogic() && afterLogic.getPSDELogic().isEnableBackend()) ||
(afterLogic.getDstPSDE()!'')!='' && (afterLogic.getDstPSDEAction()!'')!='' && afterLogic.getDstPSDEAction().isEnableBackend() >
validLogic.put("${(de.codeName+deaction.codeName)?lower_case}after.bpmn", 1);
</#if>
</#list>
</#if>
<#comment>行为调用逻辑</#comment>
<#if deaction.getActionType() =='DELOGIC' && deaction.getPSDELogic().isEnableBackend()>
validLogic.put("${(de.codeName+deaction.codeName)?lower_case}exec.bpmn", 1);
</#if>
</#list>
</#if>
</#list>
</#if>
}
} }
</#if> </#if>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册