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

动态行为

上级 6325752a
......@@ -2,40 +2,67 @@
TARGET=PSDEACTION
</#ibiztemplate>
<#if sys.getCodeName()=='Sample' || sys.getCodeName()=='EAM'>
<#assign hasAfterLogic = false>
<#assign hasAfterLogic =false>
<#assign de=item.getPSDataEntity()>
<#if item.getAfterPSDEActionLogics?? && item.getAfterPSDEActionLogics()??>
<#list item.getAfterPSDEActionLogics() as afterlogic>
<#assign hasAfterLogic = true>
<#break>
<#if afterlogic.isValid()==true>
<#if afterlogic.isInternalLogic() && afterlogic.getPSDELogic().isEnableBackend()>
<#assign hasAfterLogic=true>
<#break>
<#elseif (afterlogic.getDstPSDE()!'')!='' && (afterlogic.getDstPSDEAction()!'')!='' && afterlogic.getDstPSDEAction().isEnableBackend()>
<#assign hasAfterLogic=true>
<#break>
</#if>
</#if>
</#list>
</#if>
<#if hasAfterLogic>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:g="http://www.jboss.org/drools/flow/gpd" xmlns:tns="http://www.jboss.org/drools" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.mvel.org/2.0" id="Definition" name="" targetNamespace="http://www.jboss.org/drools" typeLanguage="http://www.java.com/javaTypes">
<process id="${pub.getPKGCodeName()}.core.extensions.service.logic.after" isClosed="false" isExecutable="true" name="ScoreRule" processType="Private" tns:packageName="${pub.getPKGCodeName()}.core.extensions.service.logic.after">
<process id="${pub.getPKGCodeName()}.core.${de.getPSSystemModule().codeName?lower_case}.${de.codeName?lower_case}.${item.codeName?lower_case}.afterLogic" isClosed="false" isExecutable="true" name="ScoreRule" processType="Private" tns:packageName="${pub.getPKGCodeName()}.core.${de.getPSSystemModule().codeName?lower_case}.${de.codeName?lower_case}.${item.codeName?lower_case}.afterLogic">
<extensionElements>
<tns:import name="java.util.Map"/>
<tns:import name="org.springframework.util.StringUtils"/>
<tns:import name="${pub.getPKGCodeName()}.util.helper.RuleUtils"/>
<tns:import name="${pub.getPKGCodeName()}.core.${de.getPSSystemModule().getCodeName()?lower_case}.domain.${de.getCodeName()}"/>
<#comment>插入服务对象</#comment>
<#list item.getAfterPSDEActionLogics() as afterlogic>
<#if (afterlogic.getDstPSDE()!'')!='' && (afterlogic.getDstPSDEAction()!'')!='' && afterlogic.getDstPSDEAction().isEnableBackend()>
<#assign dataentity = afterlogic.getDstPSDE()>
<#assign deaction = afterlogic.getDstPSDEAction()>
<#if !P.exists("refservice",dataentity+"service")>
<tns:metaData express="T(${pub.getPKGCodeName()}.util.security.SpringContextHolder).getBean(T(${pub.getPKGCodeName()}.core.${dataentity.getPSSystemModule().codeName?lower_case}.service.I${dataentity.codeName}Service))" name="${dataentity.codeName}service" type="service"/>
</#if>
</#if>
</#list>
<#comment>插入当前实体对象</#comment>
<tns:metaData express="" name="et" type="entity"/>
</extensionElements>
<#if item.getAfterPSDEActionLogics?? && item.getAfterPSDEActionLogics()??>
<startEvent id="begin" isInterrupting="true"/>
<endEvent id="prepareparam1_end" name="end"/>
<#assign source="begin">
<#list item.getAfterPSDEActionLogics() as afterlogic>
<#comment>实体行为附加逻辑</#comment>
<#if afterlogic.getPSDELogic()?? && afterlogic.getPSDELogic().isEnableBackend()>
<#assign target =afterlogic.getId()>
<#assign delogic = afterlogic.getPSDELogic()>
<callActivity activiti:exclusive="true" calledElement="${pub.getPKGCodeName()}.core.${de.getPSSystemModule().codeName?lower_case}.service.logic.${de.codeName?lower_case}${delogic.getCodeName()?lower_case}" id="${target}" name="${delogic.codeName}"/>
<#else>
</#if>
<sequenceFlow id="${source}_${target}" sourceRef="${source}" targetRef="${target}"/>
<#assign source = target>
<#if !afterlogic_has_next>
<sequenceFlow id="${source}_${target}" sourceRef="${source}" targetRef="prepareparam1_end"/>
</#if>
</#list>
<#list item.getAfterPSDEActionLogics() as afterlogic>
<#if afterlogic.isValid()==true>
<#comment>实体行为附加逻辑</#comment>
<#if afterlogic.isInternalLogic() && afterlogic.getPSDELogic().isEnableBackend()>
<#assign delogic = afterlogic.getPSDELogic()>
<#assign target =afterlogic.getId()>
<callActivity activiti:exclusive="true" calledElement="${pub.getPKGCodeName()}.core.${de.getPSSystemModule().codeName?lower_case}.service.logic.${de.codeName?lower_case}${delogic.getCodeName()?lower_case}" id="${target}" name="${delogic.codeName}"/>
<#elseif afterlogic.getDstPSDEAction()?? && afterlogic.getDstPSDEAction().isEnableBackend()>
<#assign dataentity = afterlogic.getDstPSDE()>
<#assign deaction = afterlogic.getDstPSDEAction()>
<#assign target =afterlogic.getId()>
<businessRuleTask activiti:exclusive="true" g:ruleFlowGroup="${afterlogic.getId()}" id="${afterlogic.getId()}" implementation="http://www.jboss.org/drools/rule" name="${afterlogic.name}"/>
</#if>
<sequenceFlow id="${source}_${target}" sourceRef="${source}" targetRef="${target}"/>
<#assign source = target>
<#if !afterlogic_has_next>
<sequenceFlow id="${source}_prepareparam1_end" sourceRef="${source}" targetRef="prepareparam1_end"/>
</#if>
</#if>
</#list>
</#if>
</process>
</definitions>
......
<#ibiztemplate>
TARGET=PSDEACTION
</#ibiztemplate>
<#if sys.getCodeName()=='Sample' || sys.getCodeName()=='EAM'>
<#comment>实体行为调用实体行为</#comment>
<#assign hasAfterLogic =false>
<#assign de=item.getPSDataEntity()>
<#if item.getAfterPSDEActionLogics?? && item.getAfterPSDEActionLogics()??>
<#list item.getAfterPSDEActionLogics() as afterlogic>
<#if afterlogic.isValid()==true>
<#if (afterlogic.getDstPSDE()!'')!='' && (afterlogic.getDstPSDEAction()!'')!='' && afterlogic.getDstPSDEAction().isEnableBackend()>
<#assign hasAfterLogic=true>
<#assign dataentity = afterlogic.getDstPSDE()>
<#if !P.exists("refservice",dataentity+"service")>
global ${pub.getPKGCodeName()}.core.${dataentity.getPSSystemModule().codeName?lower_case}.service.I${dataentity.codeName}Service ${dataentity.codeName}service;
</#if>
</#if>
</#if>
</#list>
</#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
<#list item.getAfterPSDEActionLogics() as afterlogic>
<#comment>实体行为附加逻辑</#comment>
<#if afterlogic.isValid()==true && afterlogic.getDstPSDEAction()?? && afterlogic.getDstPSDEAction().isEnableBackend()>
<#assign dataentity = afterlogic.getDstPSDE()>
<#assign deaction = afterlogic.getDstPSDEAction()>
<#assign dataentityCodeName = afterlogic.getDstPSDE().codeName>
<#assign deactionCodeName = srfmethodname(afterlogic.getDstPSDEAction().codeName)>
rule "${afterlogic.getId()}"
ruleflow-group "${afterlogic.getId()}"
when
then
logger.debug("开始执行[{}]实体[{}]附加逻辑","${dataentity.codeName}", "${afterlogic.getName()}");
${pub.getPKGCodeName()}.core.${dataentity.getPSSystemModule().getCodeName()?lower_case}.domain.${dataentity.getCodeName()} entity =new ${pub.getPKGCodeName()}.core.${dataentity.getPSSystemModule().getCodeName()?lower_case}.domain.${dataentity.getCodeName()}();
et.copyTo(entity,true);
${dataentityCodeName}service.${deactionCodeName}(entity);
logger.debug("[{}]实体[{}]附加逻辑执行结束","${dataentity.codeName}", "${afterlogic.getName()}");
end
</#if>
</#list>
</#if>
</#if>
</#if>
\ No newline at end of file
......@@ -3,10 +3,18 @@ TARGET=PSDEACTION
</#ibiztemplate>
<#if sys.getCodeName()=='Sample' || sys.getCodeName()=='EAM'>
<#assign hasBeforeLogic =false>
<#assign de=item.getPSDataEntity()>
<#if item.getBeforePSDEActionLogics?? && item.getBeforePSDEActionLogics()??>
<#list item.getBeforePSDEActionLogics() as beforelogic>
<#assign hasBeforeLogic=true>
<#break>
<#if beforelogic.isValid()==true>
<#if beforelogic.isInternalLogic() && beforelogic.getPSDELogic().isEnableBackend()>
<#assign hasBeforeLogic=true>
<#break>
<#elseif (beforelogic.getDstPSDE()!'')!='' && (beforelogic.getDstPSDEAction()!'')!='' && beforelogic.getDstPSDEAction().isEnableBackend()>
<#assign hasBeforeLogic=true>
<#break>
</#if>
</#if>
</#list>
</#if>
<#if hasBeforeLogic>
......@@ -17,23 +25,42 @@ TARGET=PSDEACTION
<tns:import name="java.util.Map"/>
<tns:import name="org.springframework.util.StringUtils"/>
<tns:import name="${pub.getPKGCodeName()}.util.helper.RuleUtils"/>
<tns:import name="${pub.getPKGCodeName()}.core.${de.getPSSystemModule().getCodeName()?lower_case}.domain.${de.getCodeName()}"/>
<#comment>插入服务对象</#comment>
<#list item.getBeforePSDEActionLogics() as beforelogic>
<#if (beforelogic.getDstPSDE()!'')!='' && (beforelogic.getDstPSDEAction()!'')!='' && beforelogic.getDstPSDEAction().isEnableBackend()>
<#assign dataentity = beforelogic.getDstPSDE()>
<#assign deaction = beforelogic.getDstPSDEAction()>
<#if !P.exists("refservice",dataentity+"service")>
<tns:metaData express="T(${pub.getPKGCodeName()}.util.security.SpringContextHolder).getBean(T(${pub.getPKGCodeName()}.core.${dataentity.getPSSystemModule().codeName?lower_case}.service.I${dataentity.codeName}Service))" name="${dataentity.codeName}service" type="service"/>
</#if>
</#if>
</#list>
<#comment>插入当前实体对象</#comment>
<tns:metaData express="" name="et" type="entity"/>
</extensionElements>
<#if item.getBeforePSDEActionLogics?? && item.getBeforePSDEActionLogics()??>
<startEvent id="begin" isInterrupting="true"/>
<endEvent id="prepareparam1_end" name="end"/>
<#assign source="begin">
<#list item.getBeforePSDEActionLogics() as beforelogic>
<#comment>实体行为附加逻辑</#comment>
<#if beforelogic.getPSDELogic()??>
<#assign delogic = beforelogic.getPSDELogic()>
<#assign target =beforelogic.getId()>
<#if beforelogic.isValid()==true>
<#comment>实体行为附加逻辑</#comment>
<#if beforelogic.isInternalLogic() && beforelogic.getPSDELogic().isEnableBackend()>
<#assign delogic = beforelogic.getPSDELogic()>
<#assign target =beforelogic.getId()>
<callActivity activiti:exclusive="true" calledElement="${pub.getPKGCodeName()}.core.${de.getPSSystemModule().codeName?lower_case}.service.logic.${de.codeName?lower_case}${delogic.getCodeName()?lower_case}" id="${target}" name="${delogic.codeName}"/>
<#else>
</#if>
<#elseif beforelogic.getDstPSDEAction()?? && beforelogic.getDstPSDEAction().isEnableBackend()>
<#assign dataentity = beforelogic.getDstPSDE()>
<#assign deaction = beforelogic.getDstPSDEAction()>
<#assign target =beforelogic.getId()>
<businessRuleTask activiti:exclusive="true" g:ruleFlowGroup="${beforelogic.getId()}" id="${beforelogic.getId()}" implementation="http://www.jboss.org/drools/rule" name="${beforelogic.name}"/>
</#if>
<sequenceFlow id="${source}_${target}" sourceRef="${source}" targetRef="${target}"/>
<#assign source = target>
<#if !beforelogic_has_next>
<sequenceFlow id="${source}_${target}" sourceRef="${source}" targetRef="prepareparam1_end"/>
<#assign source = target>
<#if !beforelogic_has_next>
<sequenceFlow id="${source}_prepareparam1_end" sourceRef="${source}" targetRef="prepareparam1_end"/>
</#if>
</#if>
</#list>
</#if>
......
<#ibiztemplate>
TARGET=PSDEACTION
</#ibiztemplate>
<#if sys.getCodeName()=='Sample' || sys.getCodeName()=='EAM'>
<#comment>实体行为调用实体行为</#comment>
<#assign hasBeforeLogic =false>
<#assign de=item.getPSDataEntity()>
<#if item.getBeforePSDEActionLogics?? && item.getBeforePSDEActionLogics()??>
<#list item.getBeforePSDEActionLogics() as beforelogic>
<#if beforelogic.isValid()==true>
<#if (beforelogic.getDstPSDE()!'')!='' && (beforelogic.getDstPSDEAction()!'')!='' && beforelogic.getDstPSDEAction().isEnableBackend()>
<#assign hasBeforeLogic=true>
<#assign dataentity = beforelogic.getDstPSDE()>
<#if !P.exists("refservice",dataentity+"service")>
global ${pub.getPKGCodeName()}.core.${dataentity.getPSSystemModule().codeName?lower_case}.service.I${dataentity.codeName}Service ${dataentity.codeName}service;
</#if>
</#if>
</#if>
</#list>
</#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
<#list item.getBeforePSDEActionLogics() as beforelogic>
<#comment>实体行为附加逻辑</#comment>
<#if beforelogic.isValid()==true && beforelogic.getDstPSDEAction()?? && beforelogic.getDstPSDEAction().isEnableBackend()>
<#assign dataentity = beforelogic.getDstPSDE()>
<#assign deaction = beforelogic.getDstPSDEAction()>
<#assign dataentityCodeName = beforelogic.getDstPSDE().codeName>
<#assign deactionCodeName = srfmethodname(beforelogic.getDstPSDEAction().codeName)>
rule "${beforelogic.getId()}"
ruleflow-group "${beforelogic.getId()}"
when
then
logger.debug("开始执行[{}]实体[{}]附加逻辑","${dataentity.codeName}", "${beforelogic.getName()}");
${pub.getPKGCodeName()}.core.${dataentity.getPSSystemModule().getCodeName()?lower_case}.domain.${dataentity.getCodeName()} entity =new ${pub.getPKGCodeName()}.core.${dataentity.getPSSystemModule().getCodeName()?lower_case}.domain.${dataentity.getCodeName()}();
et.copyTo(entity,true);
${dataentityCodeName}service.${deactionCodeName}(entity);
logger.debug("[{}]实体[{}]附加逻辑执行结束","${dataentity.codeName}", "${beforelogic.getName()}");
end
</#if>
</#list>
</#if>
</#if>
</#if>
\ No newline at end of file
......@@ -2,7 +2,7 @@
TARGET=PSDEACTION
</#ibiztemplate>
<#if sys.getCodeName()=='Sample' || sys.getCodeName()=='EAM'>
<#if item.getActionType()=='DELOGIC' && item.getPSDELogic()??>
<#if item.getActionType()=='DELOGIC' && item.getPSDELogic()?? && item.getPSDELogic().isEnableBackend>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:g="http://www.jboss.org/drools/flow/gpd" xmlns:tns="http://www.jboss.org/drools" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.mvel.org/2.0" id="Definition" name="" targetNamespace="http://www.jboss.org/drools" typeLanguage="http://www.java.com/javaTypes">
<process id="${pub.getPKGCodeName()}.core.extensions.service.logic.execute" isClosed="false" isExecutable="true" name="ScoreRule" processType="Private" tns:packageName="${pub.getPKGCodeName()}.core.extensions.service.logic.execute">
......
......@@ -10,7 +10,9 @@ import ${pub.getPKGCodeName()}.util.domain.DELogic;
import ${pub.getPKGCodeName()}.util.domain.EntityBase;
import ${pub.getPKGCodeName()}.util.errors.BadRequestAlertException;
import org.apache.commons.io.IOUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.flowable.bpmn.converter.BpmnXMLConverter;
......@@ -22,6 +24,8 @@ 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;
......@@ -34,8 +38,6 @@ import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.flowable.bpmn.model.*;
import org.flowable.bpmn.model.Process;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
......@@ -63,11 +65,19 @@ public class DELogicAspect {
/**
* 本地
*/
LOCAL,
LOCAL("0","未启动"),
/**
* 远程
*/
REMOTE
REMOTE("1","未启动");
LogicMode(String value , String text) {
this.value=value;
this.text = text;
}
private String value;
private String text;
}
private static Logger logger = LoggerFactory.getLogger(DELogicAspect.class);
......@@ -82,6 +92,23 @@ public class DELogicAspect {
@Value("${r'$'}{ibiz.systemid:${sys.getCodeName()}}")
private String systemId;
@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 action = args[1];
Object entity = args[2];
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);
}
}
/**
* 执行实体行为附加逻辑、实体行为调用处理逻辑
*
......@@ -178,7 +205,7 @@ public class DELogicAspect {
* @param entity
*/
private void executeLogic(File bpmnFile, Object entity, LogicMode logicMode) {
log.debug("开始执行[{}]实体[{}]处理逻辑",entity.getClass().getSimpleName(), bpmnFile.getName());
log.debug("开始执行[{}]实体[{}]处理逻辑,模式为[{}]",entity.getClass().getSimpleName(), bpmnFile.getName(),logicMode.text);
String bpmnId = DigestUtils.md5DigestAsHex(bpmnFile.getName().getBytes());
DELogic logic = getDELogic(bpmnFile, entity, logicMode);
if (logic == null) {
......@@ -203,7 +230,7 @@ public class DELogicAspect {
}
kieSession.setGlobal("logger",logger);
kieSession.startProcess(mainProcess.getId());
log.debug("[{}]实体[{}]处理逻辑执行结束",entity.getClass().getSimpleName(), bpmnFile.getName());
log.debug("[{}]实体[{}]处理逻辑执行结束,模式为[{}]",entity.getClass().getSimpleName(), bpmnFile.getName(), bpmnFile.getName(),logicMode.text);
}
/**
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册