提交 60cef721 编写于 作者: zhouweidong's avatar zhouweidong

行为附加逻辑优化

上级 4c12710d
...@@ -20,7 +20,6 @@ global ${pub.getPKGCodeName()}.core.${dataentity.getPSSystemModule().codeName?lo ...@@ -20,7 +20,6 @@ global ${pub.getPKGCodeName()}.core.${dataentity.getPSSystemModule().codeName?lo
</#if> </#if>
<#if hasAfterLogic> <#if hasAfterLogic>
global ${pub.getPKGCodeName()}.core.${de.getPSSystemModule().getCodeName()?lower_case}.domain.${de.getCodeName()} et; global ${pub.getPKGCodeName()}.core.${de.getPSSystemModule().getCodeName()?lower_case}.domain.${de.getCodeName()} et;
global org.slf4j.Logger logger;
<#if item.getAfterPSDEActionLogics?? && item.getAfterPSDEActionLogics()??> <#if item.getAfterPSDEActionLogics?? && item.getAfterPSDEActionLogics()??>
no-loop no-loop
...@@ -31,13 +30,12 @@ global org.slf4j.Logger logger; ...@@ -31,13 +30,12 @@ global org.slf4j.Logger logger;
<#assign deaction = afterlogic.getDstPSDEAction()> <#assign deaction = afterlogic.getDstPSDEAction()>
<#assign dataentityCodeName = afterlogic.getDstPSDE().codeName> <#assign dataentityCodeName = afterlogic.getDstPSDE().codeName>
<#assign deactionCodeName = srfmethodname(afterlogic.getDstPSDEAction().codeName)> <#assign deactionCodeName = srfmethodname(afterlogic.getDstPSDEAction().codeName)>
rule "${afterlogic.getId()}" <#assign target = (dataentity.codeName + deaction.codeName)?lower_case>
ruleflow-group "${afterlogic.getId()}" rule "${target}"
ruleflow-group "${target}"
when when
then then
System.out.println("开始执行[${dataentity.codeName}:${deactionCodeName}]实体[${afterlogic.getName()}]附加逻辑");
<@addActionLogic deaction afterlogic/> <@addActionLogic deaction afterlogic/>
System.out.println("[${dataentity.codeName}:${deactionCodeName}]实体[${afterlogic.getName()}]附加逻辑执行结束");
end end
</#if> </#if>
</#list> </#list>
...@@ -94,6 +92,8 @@ global org.slf4j.Logger logger; ...@@ -94,6 +92,8 @@ global org.slf4j.Logger logger;
<#comment>实体行为附加逻辑-remove</#comment> <#comment>实体行为附加逻辑-remove</#comment>
<#macro actionLogic_remove actionlogic> <#macro actionLogic_remove actionlogic>
<#if de.getKeyPSDEField().getStdDataType()==actionLogicDE.getKeyPSDEField().getStdDataType()> <#if de.getKeyPSDEField().getStdDataType()==actionLogicDE.getKeyPSDEField().getStdDataType()>
${srfcaseformat(actionLogicDE.getCodeName(),'l_u2lC')}Service.remove(key); <#assign privateCodeName = srfcaseformat(actionLogicDE.getKeyPSDEField().getCodeName(),'l_u2lC') >
<#assign publicCodeName = privateCodeName?cap_first >
${srfcaseformat(actionLogicDE.getCodeName(),'l_u2lC')}Service.remove(et.get${publicCodeName}());
</#if> </#if>
</#macro> </#macro>
\ No newline at end of file
...@@ -20,7 +20,6 @@ global ${pub.getPKGCodeName()}.core.${dataentity.getPSSystemModule().codeName?lo ...@@ -20,7 +20,6 @@ global ${pub.getPKGCodeName()}.core.${dataentity.getPSSystemModule().codeName?lo
</#if> </#if>
<#if hasBeforeLogic> <#if hasBeforeLogic>
global ${pub.getPKGCodeName()}.core.${de.getPSSystemModule().getCodeName()?lower_case}.domain.${de.getCodeName()} et; global ${pub.getPKGCodeName()}.core.${de.getPSSystemModule().getCodeName()?lower_case}.domain.${de.getCodeName()} et;
global org.slf4j.Logger logger;
<#if item.getBeforePSDEActionLogics?? && item.getBeforePSDEActionLogics()??> <#if item.getBeforePSDEActionLogics?? && item.getBeforePSDEActionLogics()??>
no-loop no-loop
...@@ -36,9 +35,7 @@ global org.slf4j.Logger logger; ...@@ -36,9 +35,7 @@ global org.slf4j.Logger logger;
ruleflow-group "${target}" ruleflow-group "${target}"
when when
then then
System.out.println("开始执行实体附加逻辑[${dataentity.codeName}:${deactionCodeName}]");
<@addActionLogic deaction beforelogic/> <@addActionLogic deaction beforelogic/>
System.out.println("实体附加逻辑[${dataentity.codeName}:${deactionCodeName}]执行结束");
end end
</#if> </#if>
</#list> </#list>
...@@ -94,6 +91,8 @@ global org.slf4j.Logger logger; ...@@ -94,6 +91,8 @@ global org.slf4j.Logger logger;
<#comment>实体行为附加逻辑-remove</#comment> <#comment>实体行为附加逻辑-remove</#comment>
<#macro actionLogic_remove actionlogic> <#macro actionLogic_remove actionlogic>
<#if de.getKeyPSDEField().getStdDataType()==actionLogicDE.getKeyPSDEField().getStdDataType()> <#if de.getKeyPSDEField().getStdDataType()==actionLogicDE.getKeyPSDEField().getStdDataType()>
${srfcaseformat(actionLogicDE.getCodeName(),'l_u2lC')}Service.remove(key); <#assign privateCodeName = srfcaseformat(actionLogicDE.getKeyPSDEField().getCodeName(),'l_u2lC') >
<#assign publicCodeName = privateCodeName?cap_first >
${srfcaseformat(actionLogicDE.getCodeName(),'l_u2lC')}Service.remove(et.get${publicCodeName}());
</#if> </#if>
</#macro> </#macro>
\ No newline at end of file
...@@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
import ${pub.getPKGCodeName()}.util.domain.DELogic; import ${pub.getPKGCodeName()}.util.domain.DELogic;
import ${pub.getPKGCodeName()}.util.domain.EntityBase; import ${pub.getPKGCodeName()}.util.domain.EntityBase;
import ${pub.getPKGCodeName()}.util.errors.BadRequestAlertException; import ${pub.getPKGCodeName()}.util.errors.BadRequestAlertException;
import ${pub.getPKGCodeName()}.util.helper.DEFieldCacheMap;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
...@@ -16,6 +17,8 @@ import org.aspectj.lang.annotation.AfterReturning; ...@@ -16,6 +17,8 @@ import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.flowable.bpmn.converter.BpmnXMLConverter; import org.flowable.bpmn.converter.BpmnXMLConverter;
import org.flowable.bpmn.model.*;
import org.flowable.bpmn.model.Process;
import org.kie.api.KieServices; import org.kie.api.KieServices;
import org.kie.api.builder.KieBuilder; import org.kie.api.builder.KieBuilder;
import org.kie.api.builder.KieFileSystem; import org.kie.api.builder.KieFileSystem;
...@@ -24,8 +27,6 @@ import org.kie.api.builder.Results; ...@@ -24,8 +27,6 @@ import org.kie.api.builder.Results;
import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession; import org.kie.api.runtime.KieSession;
import org.kie.internal.io.ResourceFactory; import org.kie.internal.io.ResourceFactory;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression; import org.springframework.expression.Expression;
...@@ -36,14 +37,13 @@ import org.springframework.stereotype.Component; ...@@ -36,14 +37,13 @@ import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils; import org.springframework.util.DigestUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.flowable.bpmn.model.*;
import org.flowable.bpmn.model.Process;
import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -65,7 +65,7 @@ public class DELogicAspect { ...@@ -65,7 +65,7 @@ public class DELogicAspect {
/** /**
* 本地 * 本地
*/ */
LOCAL("0","本地模"), LOCAL("0","本地模"),
/** /**
* 远程 * 远程
*/ */
...@@ -80,7 +80,6 @@ public class DELogicAspect { ...@@ -80,7 +80,6 @@ public class DELogicAspect {
private String text; private String text;
} }
private static Logger logger = LoggerFactory.getLogger(DELogicAspect.class);
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<>();
...@@ -98,14 +97,14 @@ public class DELogicAspect { ...@@ -98,14 +97,14 @@ public class DELogicAspect {
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);
} }
} }
...@@ -122,10 +121,19 @@ public class DELogicAspect { ...@@ -122,10 +121,19 @@ public class DELogicAspect {
if (ObjectUtils.isEmpty(args) || args.length == 0) { if (ObjectUtils.isEmpty(args) || args.length == 0) {
return point.proceed(); return point.proceed();
} }
Object service = point.getTarget();
Object arg = args[0]; Object arg = args[0];
if (arg instanceof EntityBase) { String action = point.getSignature().getName();
String action = point.getSignature().getName(); EntityBase entity = null;
EntityBase entity = (EntityBase) arg; if("remove".equalsIgnoreCase(action) || "get".equalsIgnoreCase(action)) {
entity = getEntity(service);
String id = DEFieldCacheMap.getDEKeyField(entity.getClass());
entity.set(id,arg);
}
else if (arg instanceof EntityBase){
entity = (EntityBase) arg;
}
if(entity != null){
executeBeforeLogic(entity, action); executeBeforeLogic(entity, action);
Object result = point.proceed(); Object result = point.proceed();
executeLogic(entity, action); executeLogic(entity, action);
...@@ -135,6 +143,28 @@ public class DELogicAspect { ...@@ -135,6 +143,28 @@ 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");
}
/** /**
* 前附加逻辑 * 前附加逻辑
* *
...@@ -146,13 +176,13 @@ public class DELogicAspect { ...@@ -146,13 +176,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, 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()) {
executeLogic(bpmnFile, entity, LogicMode.LOCAL); executeLogic(bpmnFile, entity ,action, LogicMode.LOCAL);
} }
} }
...@@ -167,13 +197,13 @@ public class DELogicAspect { ...@@ -167,13 +197,13 @@ 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, 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()) {
executeLogic(bpmnFile, entity, LogicMode.LOCAL); executeLogic(bpmnFile, entity, action, LogicMode.LOCAL);
} }
} }
...@@ -188,13 +218,13 @@ public class DELogicAspect { ...@@ -188,13 +218,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, 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()) {
executeLogic(bpmnFile, entity, LogicMode.LOCAL); executeLogic(bpmnFile, entity , action, LogicMode.LOCAL);
} }
} }
...@@ -204,8 +234,8 @@ public class DELogicAspect { ...@@ -204,8 +234,8 @@ public class DELogicAspect {
* @param bpmnFile * @param bpmnFile
* @param entity * @param entity
*/ */
private void executeLogic(File bpmnFile, Object entity, LogicMode logicMode) { private void executeLogic(File bpmnFile, Object entity, String action, LogicMode logicMode) {
log.debug("开始执行[{}]实体[{}]处理逻辑,模式为[{}]",entity.getClass().getSimpleName(), 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) {
...@@ -228,9 +258,8 @@ public class DELogicAspect { ...@@ -228,9 +258,8 @@ public class DELogicAspect {
fillGlobalParam(kieSession, subLogic.getProcess(), entity); fillGlobalParam(kieSession, subLogic.getProcess(), entity);
} }
} }
kieSession.setGlobal("logger",logger);
kieSession.startProcess(mainProcess.getId()); kieSession.startProcess(mainProcess.getId());
log.debug("[{}]实体[{}]处理逻辑执行结束,模式为[{}]",entity.getClass().getSimpleName(), bpmnFile.getName(), bpmnFile.getName(),logicMode.text); log.debug("实体处理逻辑[{}:{}:{}:{}]执行结束",entity.getClass().getSimpleName(),action, bpmnFile.getName(), logicMode.text);
} }
/** /**
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册