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

区分本地与远程逻辑

上级 9ecc8dca
......@@ -2,6 +2,10 @@
TARGET=PSSYSTEM
</#ibiztemplate>
<#if sys.getCodeName()=='Sample' || sys.getCodeName()=='EAM'>
<#assign isDynaSys =false>
<#if pub.isEnableDynaModel()?? && pub.isEnableDynaModel()== true>
<#assign isDynaSys =true>
</#if>
package ${pub.getPKGCodeName()}.util.aspect;
import lombok.SneakyThrows;
......@@ -62,66 +66,19 @@ import java.util.regex.Pattern;
@Slf4j
public class DELogicAspect {
public enum LogicMode {
/**
* 本地
*/
LOCAL("0", "本地模式"),
/**
* 远程
*/
REMOTE("1", "远程模式");
LogicMode(String value, String text) {
this.value = value;
this.text = text;
}
private String value;
private String text;
}
private static BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
private final ExpressionParser parser = new SpelExpressionParser();
private ConcurrentMap<String, DELogic> deLogicMap = new ConcurrentHashMap<>();
private final String DEFAULT_MODULE_PACKAGE = "[\\w+\\.]\\.core.(\\w+)\\.domain";
@Value("${r'${ibiz.dynamicMode:true}'}")
private boolean dynamicMode;
private static Map<String, Object> validLogic = new HashMap<>();
<#if isDynaSys>
@Value("${r'${ibiz.dynamic.path:/app/file/dynamicmodel/}'}")
private String dynamicPath;
@Value("${r'$'}{ibiz.systemid:${sys.getCodeName()}}")
private String systemId;
@Value("${r'$'}{ibiz.dynainstid:${sys.getCodeName()?lower_case}}")
private String dynamicId;
private static Map<String, Object> validLogic = new HashMap<>();
/**
* 执行动态行为
* @param point
*/
@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 id = args[0];
String action = String.valueOf(args[1]);
Object entity = args[2];
if (entity instanceof EntityBase) {
log.debug("开始执行实体动态行为[{}:{}]", entity.getClass().getSimpleName(), action);
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("service", point.getTarget());
context.setVariable("action", action);
if ("remove".equalsIgnoreCase(action) || "get".equalsIgnoreCase(action)) {
context.setVariable("args", id);
} else {
context.setVariable("args", entity);
}
Expression oldExp = parser.parseExpression(String.format("#service.%s(#args)", action));
oldExp.getValue(context);
log.debug("实体动态行为[{}:{}]执行结束", entity.getClass().getSimpleName(), action);
}
}
}
</#if>
/**
* 执行实体行为附加逻辑、实体行为调用处理逻辑
......@@ -157,29 +114,6 @@ 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");
}
/**
* 前附加逻辑
*
......@@ -188,14 +122,14 @@ public class DELogicAspect {
*/
private void executeBeforeLogic(EntityBase entity, String action) {
File bpmnFile;
if (dynamicMode) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "before");
if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE);
return;
}
<#if isDynaSys>
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, LogicExecMode.BEFORE);
if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE);
return;
}
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, "before");
</#if>
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, LogicExecMode.BEFORE);
if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic(bpmnFile, entity, action, LogicMode.LOCAL);
}
......@@ -209,14 +143,14 @@ public class DELogicAspect {
*/
private void executeAfterLogic(EntityBase entity, String action) {
File bpmnFile;
if (dynamicMode) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "after");
if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE);
return;
}
<#if isDynaSys>
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, LogicExecMode.AFTER);
if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE);
return;
}
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, "after");
</#if>
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, LogicExecMode.AFTER);
if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic(bpmnFile, entity, action, LogicMode.LOCAL);
}
......@@ -230,14 +164,14 @@ public class DELogicAspect {
*/
private void executeLogic(EntityBase entity, String action) {
File bpmnFile;
if (dynamicMode) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, "exec");
if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE);
return;
}
<#if isDynaSys>
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, LogicExecMode.EXEC);
if (bpmnFile.exists()) {
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE);
return;
}
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, "exec");
</#if>
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, LogicExecMode.EXEC);
if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic(bpmnFile, entity, action, LogicMode.LOCAL);
}
......@@ -369,10 +303,10 @@ public class DELogicAspect {
if (item instanceof CallActivity) {
CallActivity subBpmn = (CallActivity) item;
String bpmnFileName = subBpmn.getName();
log.debug("正在加载 ********************BPMN:{}********************",bpmnFileName);
log.debug("正在加载 BPMN{}", bpmnFileName);
File subBpmnFile = getSubBpmn(getDEModule(entity), entity.getClass().getSimpleName(), bpmnFileName, logicMode);
if(!subBpmnFile.exists()){
log.debug("BPMN:{},缺少文件:{} ",bpmnFileName,subBpmnFile);
if (ObjectUtils.isEmpty(subBpmnFile)) {
log.debug("BPMN:{},缺少文件:{} ", bpmnFileName, subBpmnFile);
}
DELogic refLogic = getDELogic(subBpmnFile, entity, logicMode);
if (refLogic != null) {
......@@ -407,6 +341,29 @@ public class DELogicAspect {
return logic;
}
/**
* 获取实体
*
* @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");
}
/**
* 获取bpmn md5
*
......@@ -446,29 +403,31 @@ public class DELogicAspect {
*
* @param entity
* @param action
* @param actionLogic
* @param logicExecMode
* @return
*/
private File getLocalModel(String entity, String action, String actionLogic) {
String logicName = String.format("%s.bpmn", actionLogic);
private File getLocalModel(String entity, String action, LogicExecMode logicExecMode) {
String logicName = String.format("%s.bpmn", logicExecMode.value);
String filePath = File.separator + "rules" + File.separator + entity.toLowerCase() + File.separator + action + File.separator + logicName;
URL url = this.getClass().getResource(filePath.replace("\\", "/"));
return ObjectUtils.isEmpty(url) ? null : new File(url.getPath());
}
<#if isDynaSys>
/**
* 远程逻辑
*
* @param module
* @param entity
* @param action
* @param actionLogic
* @param logicExecMode
* @return
*/
private File getRemoteModel(String module, String entity, String action, String actionLogic) {
String logicName = String.format("psdeaction.json.%s.bpmn", actionLogic);
private File getRemoteModel(String module, String entity, String action, LogicExecMode logicExecMode) {
String logicName = String.format("psdeaction.json.%s.bpmn", logicExecMode.value);
return new File(dynamicPath + File.separator + (systemId + File.separator + dynamicId + File.separator + "psmodules" + File.separator + module + File.separator + "psdataentities" + File.separator + entity + File.separator + "psdeactions" + File.separator + action + File.separator + logicName).toLowerCase());
}
</#if>
/**
* 处理逻辑 bpmn
......@@ -479,12 +438,18 @@ public class DELogicAspect {
* @return
*/
private File getSubBpmn(String module, String entity, String logicName, LogicMode logicMode) {
<#if isDynaSys>
if (LogicMode.REMOTE.equals(logicMode)) {
return new File(dynamicPath + File.separator + (systemId + File.separator + dynamicId + File.separator + "psmodules" + File.separator + module + File.separator + "psdataentities" + File.separator + entity + File.separator + "psdelogics" + File.separator + logicName + File.separator + "psdelogic.json.bpmn").toLowerCase());
} else {
String filePath = String.format("/rules/%s", logicName);
return ObjectUtils.isEmpty(this.getClass().getResource(filePath)) ? null : new File(this.getClass().getResource(filePath).getPath());
}
<#else>
String filePath = String.format("/rules/%s", logicName);
return ObjectUtils.isEmpty(this.getClass().getResource(filePath)) ? null : new File(this.getClass().getResource(filePath).getPath());
</#if>
}
/**
......@@ -494,11 +459,15 @@ public class DELogicAspect {
* @return
*/
private File getDrl(File bpmn) {
<#if isDynaSys>
if (bpmn.getPath().endsWith("RuleFlow.bpmn")) {
return new File(bpmn.getPath().replace("RuleFlow.bpmn", "Rule.drl"));
} else {
return new File(bpmn.getPath().replace(".bpmn", ".drl"));
}
<#else>
return new File(bpmn.getPath().replace("RuleFlow.bpmn", "Rule.drl"));
</#if>
}
/**
......@@ -521,6 +490,37 @@ public class DELogicAspect {
return strModule;
}
<#if isDynaSys>
/**
* 执行动态行为
*
* @param point
*/
@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 id = args[0];
String action = String.valueOf(args[1]);
Object entity = args[2];
if (entity instanceof EntityBase) {
log.debug("开始执行实体动态行为[{}:{}]", entity.getClass().getSimpleName(), action);
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("service", point.getTarget());
context.setVariable("action", action);
if ("remove".equalsIgnoreCase(action) || "get".equalsIgnoreCase(action)) {
context.setVariable("args", id);
} else {
context.setVariable("args", entity);
}
Expression oldExp = parser.parseExpression(String.format("#service.%s(#args)", action));
oldExp.getValue(context);
log.debug("实体动态行为[{}:{}]执行结束", entity.getClass().getSimpleName(), action);
}
}
}
</#if>
/**
* 逻辑是否有效
*
......@@ -539,36 +539,63 @@ public class DELogicAspect {
}
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("${(dataEntity.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("${(dataEntity.codeName+deaction.codeName)?lower_case}after.bpmn", 1);
</#if>
</#list>
</#if>
<#comment>行为调用逻辑</#comment>
<#if deaction.getActionType() =='DELOGIC' && deaction.getPSDELogic().isEnableBackend()>
validLogic.put("${(dataEntity.codeName+deaction.codeName)?lower_case}exec.bpmn", 1);
</#if>
</#list>
</#if>
</#list>
</#if>
validLogic.put("bsentity2checkkeybefore.bpmn", 1);
validLogic.put("bsentity2checkkeyafter.bpmn", 1);
validLogic.put("citysyncmqdatabefore.bpmn", 1);
validLogic.put("citysyncmqdataafter.bpmn", 1);
validLogic.put("citysyncmqdataexec.bpmn", 1);
validLogic.put("humancreatebefore.bpmn", 1);
validLogic.put("humancustom3before.bpmn", 1);
validLogic.put("humancustom3after.bpmn", 1);
validLogic.put("humancustom3exec.bpmn", 1);
validLogic.put("humancustomdeleteexec.bpmn", 1);
validLogic.put("humangettaxamountexec.bpmn", 1);
validLogic.put("humanlogicexec.bpmn", 1);
validLogic.put("humansmileexec.bpmn", 1);
validLogic.put("humantaxamountexec.bpmn", 1);
validLogic.put("loginaccountsyncsysadminexec.bpmn", 1);
}
public enum LogicMode {
/**
* 本地
*/
LOCAL("0", "本地模式"),
/**
* 远程
*/
REMOTE("1", "远程模式");
LogicMode(String value, String text) {
this.value = value;
this.text = text;
}
private String value;
private String text;
}
public enum LogicExecMode {
/**
* 前附加逻辑
*/
BEFORE("0", "before"),
/**
* 后附加逻辑
*/
AFTER("1", "after"),
/**
*
*/
EXEC("2", "exec");
LogicExecMode(String value, String text) {
this.value = value;
this.text = text;
}
private String value;
private String text;
}
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册