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

行为附加逻辑优化

上级 4c12710d
......@@ -20,7 +20,6 @@ global ${pub.getPKGCodeName()}.core.${dataentity.getPSSystemModule().codeName?lo
</#if>
<#if hasAfterLogic>
global ${pub.getPKGCodeName()}.core.${de.getPSSystemModule().getCodeName()?lower_case}.domain.${de.getCodeName()} et;
global org.slf4j.Logger logger;
<#if item.getAfterPSDEActionLogics?? && item.getAfterPSDEActionLogics()??>
no-loop
......@@ -31,13 +30,12 @@ global org.slf4j.Logger logger;
<#assign deaction = afterlogic.getDstPSDEAction()>
<#assign dataentityCodeName = afterlogic.getDstPSDE().codeName>
<#assign deactionCodeName = srfmethodname(afterlogic.getDstPSDEAction().codeName)>
rule "${afterlogic.getId()}"
ruleflow-group "${afterlogic.getId()}"
<#assign target = (dataentity.codeName + deaction.codeName)?lower_case>
rule "${target}"
ruleflow-group "${target}"
when
then
System.out.println("开始执行[${dataentity.codeName}:${deactionCodeName}]实体[${afterlogic.getName()}]附加逻辑");
<@addActionLogic deaction afterlogic/>
System.out.println("[${dataentity.codeName}:${deactionCodeName}]实体[${afterlogic.getName()}]附加逻辑执行结束");
end
</#if>
</#list>
......@@ -94,6 +92,8 @@ global org.slf4j.Logger logger;
<#comment>实体行为附加逻辑-remove</#comment>
<#macro actionLogic_remove actionlogic>
<#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>
</#macro>
\ No newline at end of file
......@@ -20,7 +20,6 @@ global ${pub.getPKGCodeName()}.core.${dataentity.getPSSystemModule().codeName?lo
</#if>
<#if hasBeforeLogic>
global ${pub.getPKGCodeName()}.core.${de.getPSSystemModule().getCodeName()?lower_case}.domain.${de.getCodeName()} et;
global org.slf4j.Logger logger;
<#if item.getBeforePSDEActionLogics?? && item.getBeforePSDEActionLogics()??>
no-loop
......@@ -36,9 +35,7 @@ global org.slf4j.Logger logger;
ruleflow-group "${target}"
when
then
System.out.println("开始执行实体附加逻辑[${dataentity.codeName}:${deactionCodeName}]");
<@addActionLogic deaction beforelogic/>
System.out.println("实体附加逻辑[${dataentity.codeName}:${deactionCodeName}]执行结束");
end
</#if>
</#list>
......@@ -94,6 +91,8 @@ global org.slf4j.Logger logger;
<#comment>实体行为附加逻辑-remove</#comment>
<#macro actionLogic_remove actionlogic>
<#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>
</#macro>
\ No newline at end of file
......@@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
import ${pub.getPKGCodeName()}.util.domain.DELogic;
import ${pub.getPKGCodeName()}.util.domain.EntityBase;
import ${pub.getPKGCodeName()}.util.errors.BadRequestAlertException;
import ${pub.getPKGCodeName()}.util.helper.DEFieldCacheMap;
import org.apache.commons.io.IOUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
......@@ -16,6 +17,8 @@ import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
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.builder.KieBuilder;
import org.kie.api.builder.KieFileSystem;
......@@ -24,8 +27,6 @@ import org.kie.api.builder.Results;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.internal.io.ResourceFactory;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
......@@ -36,14 +37,13 @@ import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
import org.springframework.util.ObjectUtils;
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.XMLStreamReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
......@@ -65,7 +65,7 @@ public class DELogicAspect {
/**
* 本地
*/
LOCAL("0","本地模"),
LOCAL("0","本地模"),
/**
* 远程
*/
......@@ -80,7 +80,6 @@ public class DELogicAspect {
private String text;
}
private static Logger logger = LoggerFactory.getLogger(DELogicAspect.class);
private static BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
private final ExpressionParser parser = new SpelExpressionParser();
private ConcurrentMap<String, DELogic> deLogicMap = new ConcurrentHashMap<>();
......@@ -98,14 +97,14 @@ public class DELogicAspect {
if (!ObjectUtils.isEmpty(args) || args.length == 3) {
Object action = args[1];
Object entity = args[2];
log.debug("开始执行[{}]实体[{}]动态行为",entity.getClass().getSimpleName(), action);
log.debug("开始执行实体[{}]动态行为[{}]",entity.getClass().getSimpleName(), action);
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("service", point.getTarget());
context.setVariable("action", action);
context.setVariable("entity", entity);
Expression oldExp = parser.parseExpression(String.format("#service.%s(#entity)",action));
oldExp.getValue(context);
log.debug("[{}]实体[{}]动态行为执行结束",entity.getClass().getSimpleName(), action);
log.debug("实体[{}]动态行为[{}]执行结束",entity.getClass().getSimpleName(), action);
}
}
......@@ -122,10 +121,19 @@ public class DELogicAspect {
if (ObjectUtils.isEmpty(args) || args.length == 0) {
return point.proceed();
}
Object service = point.getTarget();
Object arg = args[0];
if (arg instanceof EntityBase) {
String action = point.getSignature().getName();
EntityBase entity = (EntityBase) arg;
String action = point.getSignature().getName();
EntityBase entity = null;
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);
Object result = point.proceed();
executeLogic(entity, action);
......@@ -135,6 +143,28 @@ public class DELogicAspect {
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 {
if (dynamicMode) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "before");
if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity, LogicMode.REMOTE);
executeLogic(bpmnFile, entity,action, LogicMode.REMOTE);
return;
}
}
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, "before");
if (bpmnFile != null && bpmnFile.exists()) {
executeLogic(bpmnFile, entity, LogicMode.LOCAL);
executeLogic(bpmnFile, entity ,action, LogicMode.LOCAL);
}
}
......@@ -167,13 +197,13 @@ public class DELogicAspect {
if (dynamicMode) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "after");
if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity, LogicMode.REMOTE);
executeLogic(bpmnFile, entity , action, LogicMode.REMOTE);
return;
}
}
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, "after");
if (bpmnFile != null && bpmnFile.exists()) {
executeLogic(bpmnFile, entity, LogicMode.LOCAL);
executeLogic(bpmnFile, entity, action, LogicMode.LOCAL);
}
}
......@@ -188,13 +218,13 @@ public class DELogicAspect {
if (dynamicMode) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "exec");
if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity, LogicMode.REMOTE);
executeLogic(bpmnFile, entity,action, LogicMode.REMOTE);
return;
}
}
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, "exec");
if (bpmnFile != null && bpmnFile.exists()) {
executeLogic(bpmnFile, entity, LogicMode.LOCAL);
executeLogic(bpmnFile, entity , action, LogicMode.LOCAL);
}
}
......@@ -204,8 +234,8 @@ public class DELogicAspect {
* @param bpmnFile
* @param entity
*/
private void executeLogic(File bpmnFile, Object entity, LogicMode logicMode) {
log.debug("开始执行[{}]实体[{}]处理逻辑,模式为[{}]",entity.getClass().getSimpleName(), bpmnFile.getName(),logicMode.text);
private void executeLogic(File bpmnFile, Object entity, String action, LogicMode logicMode) {
log.debug("开始执行实体处理逻辑[{}:{}:{}:{}]",entity.getClass().getSimpleName(),action, bpmnFile.getName(),logicMode.text);
String bpmnId = DigestUtils.md5DigestAsHex(bpmnFile.getName().getBytes());
DELogic logic = getDELogic(bpmnFile, entity, logicMode);
if (logic == null) {
......@@ -228,9 +258,8 @@ public class DELogicAspect {
fillGlobalParam(kieSession, subLogic.getProcess(), entity);
}
}
kieSession.setGlobal("logger",logger);
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 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册