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

补充有效逻辑

上级 7835622f
......@@ -46,6 +46,7 @@ import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
......@@ -65,14 +66,14 @@ public class DELogicAspect {
/**
* 本地
*/
LOCAL("0","本地模式"),
LOCAL("0", "本地模式"),
/**
* 远程
*/
REMOTE("1","远程模式");
REMOTE("1", "远程模式");
LogicMode(String value , String text) {
this.value=value;
LogicMode(String value, String text) {
this.value = value;
this.text = text;
}
......@@ -90,21 +91,22 @@ public class DELogicAspect {
private String dynamicPath;
@Value("${r'$'}{ibiz.systemid:${sys.getCodeName()}}")
private String systemId;
private static Map<String, Object> validLogic = new HashMap<>();
@AfterReturning(value = "execution(* ${pub.getPKGCodeName()}.core.*.service.*.dynamicCall(..))")
public void dynamicCall(JoinPoint point){
public void dynamicCall(JoinPoint point) {
Object args[] = point.getArgs();
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));
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);
}
}
......@@ -125,15 +127,14 @@ public class DELogicAspect {
Object arg = args[0];
String action = point.getSignature().getName();
EntityBase entity = null;
if("remove".equalsIgnoreCase(action) || "get".equalsIgnoreCase(action)) {
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.set(id, arg);
} else if (arg instanceof EntityBase) {
entity = (EntityBase) arg;
}
if(entity != null){
if (entity != null) {
executeBeforeLogic(entity, action);
Object result = point.proceed();
executeLogic(entity, action);
......@@ -145,24 +146,25 @@ public class DELogicAspect {
/**
* 获取实体
*
* @param service
* @return
* @throws Exception
*/
private EntityBase getEntity(Object service) throws Exception{
private EntityBase getEntity(Object service) throws Exception {
Method[] methods = service.getClass().getDeclaredMethods();
for(Method method : methods){
for(Class cls : method.getParameterTypes()){
for (Method method : methods) {
for (Class cls : method.getParameterTypes()) {
try {
Object arg = cls.newInstance();
if(arg instanceof EntityBase){
if (arg instanceof EntityBase) {
return (EntityBase) arg;
}
} catch (InstantiationException e) {
}
}
}
throw new BadRequestAlertException("获取实体信息失败","DELogicAspect","getEntity");
throw new BadRequestAlertException("获取实体信息失败", "DELogicAspect", "getEntity");
}
/**
......@@ -176,13 +178,13 @@ public class DELogicAspect {
if (dynamicMode) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "before");
if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity,action, LogicMode.REMOTE);
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE);
return;
}
}
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, "before");
if (bpmnFile != null && bpmnFile.exists()) {
executeLogic(bpmnFile, entity ,action, LogicMode.LOCAL);
if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic(bpmnFile, entity, action, LogicMode.LOCAL);
}
}
......@@ -197,12 +199,12 @@ public class DELogicAspect {
if (dynamicMode) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "after");
if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity , action, LogicMode.REMOTE);
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE);
return;
}
}
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);
}
}
......@@ -218,13 +220,13 @@ public class DELogicAspect {
if (dynamicMode) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "exec");
if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity,action, LogicMode.REMOTE);
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE);
return;
}
}
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, "exec");
if (bpmnFile != null && bpmnFile.exists()) {
executeLogic(bpmnFile, entity , action, LogicMode.LOCAL);
if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic(bpmnFile, entity, action, LogicMode.LOCAL);
}
}
......@@ -235,7 +237,7 @@ public class DELogicAspect {
* @param entity
*/
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());
DELogic logic = getDELogic(bpmnFile, entity, logicMode);
if (logic == null) {
......@@ -259,7 +261,7 @@ public class DELogicAspect {
}
}
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 {
Expression oldExp = parser.parseExpression(express_value);
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.setGlobal(name.getValue(), value);
......@@ -501,5 +503,56 @@ public class DELogicAspect {
}
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>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册