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

逻辑支持动态系统业务标记,将File改为Resource直接读取classpath中的处理逻辑

上级 4276652a
...@@ -500,14 +500,15 @@ public class DELogicAspect { ...@@ -500,14 +500,15 @@ public class DELogicAspect {
<#comment>加载远程逻辑(动态系统)</#comment> <#comment>加载远程逻辑(动态系统)</#comment>
package ${pub.getPKGCodeName()}.util.aspect; package ${pub.getPKGCodeName()}.util.aspect;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import ${pub.getPKGCodeName()}.util.annotation.DEField;
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 ${pub.getPKGCodeName()}.util.helper.DEFieldCacheMap;
import org.apache.commons.io.FileUtils;
import java.io.IOException;
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;
...@@ -526,6 +527,9 @@ import org.kie.api.runtime.KieContainer; ...@@ -526,6 +527,9 @@ 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.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression; import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser; import org.springframework.expression.ExpressionParser;
...@@ -539,9 +543,10 @@ import org.springframework.util.StringUtils; ...@@ -539,9 +543,10 @@ import org.springframework.util.StringUtils;
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.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -628,10 +633,10 @@ public class DELogicAspect { ...@@ -628,10 +633,10 @@ public class DELogicAspect {
EntityBase entity = null; EntityBase entity = null;
if ("remove".equalsIgnoreCase(action) || "get".equalsIgnoreCase(action)) { if ("remove".equalsIgnoreCase(action) || "get".equalsIgnoreCase(action)) {
entity = getEntity(service.getClass()); entity = getEntity(service.getClass());
if(!ObjectUtils.isEmpty(entity)) { if (!ObjectUtils.isEmpty(entity)) {
String id = DEFieldCacheMap.getDEKeyField(entity.getClass()); String id = DEFieldCacheMap.getDEKeyField(entity.getClass());
if(StringUtils.isEmpty(id)) { if (StringUtils.isEmpty(id)) {
log.debug("无法获取实体主键属性[{}]",entity.getClass().getSimpleName()); log.debug("无法获取实体主键属性[{}]", entity.getClass().getSimpleName());
return point.proceed(); return point.proceed();
} }
entity.set(id, arg); entity.set(id, arg);
...@@ -639,11 +644,16 @@ public class DELogicAspect { ...@@ -639,11 +644,16 @@ public class DELogicAspect {
} else if (arg instanceof EntityBase) { } else if (arg instanceof EntityBase) {
entity = (EntityBase) arg; entity = (EntityBase) arg;
} }
String dynaInstId = null;
if (isDyna) {
dynaInstId = getDynaInstId(entity);
dynaInstId = ObjectUtils.isEmpty(dynaInstId) ? defaultDynaInstId : dynaInstId;
}
if (entity != null) { if (entity != null) {
executeBeforeLogic(entity, action, isDyna); executeBeforeLogic(entity, action, isDyna, dynaInstId);
Object result = point.proceed(); Object result = point.proceed();
executeLogic(entity, action, isDyna); executeLogic(entity, action, isDyna, dynaInstId);
executeAfterLogic(entity, action, isDyna); executeAfterLogic(entity, action, isDyna, dynaInstId);
return result; return result;
} }
return point.proceed(); return point.proceed();
...@@ -655,18 +665,18 @@ public class DELogicAspect { ...@@ -655,18 +665,18 @@ public class DELogicAspect {
* @param entity * @param entity
* @param action * @param action
*/ */
private void executeBeforeLogic(EntityBase entity, String action, boolean isDyna) { private void executeBeforeLogic(EntityBase entity, String action, boolean isDyna, String instanceId) {
File bpmnFile; Resource bpmnFile;
if (isDyna) { if (isDyna) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, LogicExecMode.BEFORE); bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, LogicExecMode.BEFORE, instanceId);
if (bpmnFile != null && bpmnFile.exists()) { if (bpmnFile != null && bpmnFile.exists()) {
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE); executeLogic(bpmnFile, entity, action, instanceId);
return; return;
} }
} }
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, LogicExecMode.BEFORE); bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, LogicExecMode.BEFORE);
if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) { if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic(bpmnFile, entity, action, LogicMode.LOCAL); executeLogic(bpmnFile, entity, action, instanceId);
} }
} }
...@@ -676,18 +686,18 @@ public class DELogicAspect { ...@@ -676,18 +686,18 @@ public class DELogicAspect {
* @param entity * @param entity
* @param action * @param action
*/ */
private void executeAfterLogic(EntityBase entity, String action, boolean isDyna) { private void executeAfterLogic(EntityBase entity, String action, boolean isDyna, String instanceId) {
File bpmnFile; Resource bpmnFile;
if (isDyna) { if (isDyna) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, LogicExecMode.AFTER); bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, LogicExecMode.AFTER, instanceId);
if (bpmnFile != null && bpmnFile.exists()) { if (bpmnFile != null && bpmnFile.exists()) {
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE); executeLogic(bpmnFile, entity, action, instanceId);
return; return;
} }
} }
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, LogicExecMode.AFTER); bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, LogicExecMode.AFTER);
if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) { if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic(bpmnFile, entity, action, LogicMode.LOCAL); executeLogic(bpmnFile, entity, action, instanceId);
} }
} }
...@@ -697,18 +707,18 @@ public class DELogicAspect { ...@@ -697,18 +707,18 @@ public class DELogicAspect {
* @param entity * @param entity
* @param action * @param action
*/ */
private void executeLogic(EntityBase entity, String action, boolean isDyna) { private void executeLogic(EntityBase entity, String action, boolean isDyna, String instanceId) {
File bpmnFile; Resource bpmnFile;
if (isDyna) { if (isDyna) {
bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, LogicExecMode.EXEC); bpmnFile = getRemoteModel(getDEModule(entity), entity.getClass().getSimpleName(), action, LogicExecMode.EXEC, instanceId);
if (bpmnFile != null && bpmnFile.exists()) { if (bpmnFile != null && bpmnFile.exists()) {
executeLogic(bpmnFile, entity, action, LogicMode.REMOTE); executeLogic(bpmnFile, entity, action, instanceId);
return; return;
} }
} }
bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, LogicExecMode.EXEC); bpmnFile = getLocalModel(entity.getClass().getSimpleName(), action, LogicExecMode.EXEC);
if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) { if (bpmnFile != null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic(bpmnFile, entity, action, LogicMode.LOCAL); executeLogic(bpmnFile, entity, action, instanceId);
} }
} }
...@@ -718,32 +728,38 @@ public class DELogicAspect { ...@@ -718,32 +728,38 @@ public class DELogicAspect {
* @param bpmnFile * @param bpmnFile
* @param entity * @param entity
*/ */
private void executeLogic(File bpmnFile, Object entity, String action, LogicMode logicMode) { private void executeLogic(Resource bpmnFile, Object entity, String action, String instanceId) {
log.debug("开始执行实体处理逻辑[{}:{}:{}:{}]", entity.getClass().getSimpleName(), action, bpmnFile.getName(), logicMode.text); String logicMode = bpmnFile instanceof FileSystemResource ? String.format("远程模式:%s", instanceId) : "本地模式";
String bpmnId = DigestUtils.md5DigestAsHex(bpmnFile.getPath().getBytes()); try {
DELogic logic = getDELogic(bpmnFile, entity, logicMode); log.debug("开始执行实体处理逻辑[{}:{}:{}:{}]", entity.getClass().getSimpleName(), action, bpmnFile.getFilename(), logicMode);
if (logic == null) { String bpmnId = DigestUtils.md5DigestAsHex(bpmnFile.getURL().getPath().getBytes());
return; DELogic logic = getDELogic(bpmnFile, entity, instanceId);
} if (logic == null) {
if (deLogicMap.containsKey(bpmnId) && logic.getMd5().equals(deLogicMap.get(bpmnId).getMd5())) { return;
logic = deLogicMap.get(bpmnId); }
} else { if (deLogicMap.containsKey(bpmnId) && logic.getMd5().equals(deLogicMap.get(bpmnId).getMd5())) {
reloadLogic(logic); logic = deLogicMap.get(bpmnId);
deLogicMap.put(bpmnId, logic); } else {
} reloadLogic(logic);
KieContainer container = logic.getContainer(); deLogicMap.put(bpmnId, logic);
KieSession kieSession = container.getKieBase().newKieSession();
Process mainProcess = logic.getProcess();
//主流程参数
fillGlobalParam(kieSession, mainProcess, entity);
//子流程参数
if (!ObjectUtils.isEmpty(logic.getRefLogic())) {
for (DELogic subLogic : logic.getRefLogic()) {
fillGlobalParam(kieSession, subLogic.getProcess(), entity);
} }
KieContainer container = logic.getContainer();
KieSession kieSession = container.getKieBase().newKieSession();
Process mainProcess = logic.getProcess();
//主流程参数
fillGlobalParam(kieSession, mainProcess, entity);
//子流程参数
if (!ObjectUtils.isEmpty(logic.getRefLogic())) {
for (DELogic subLogic : logic.getRefLogic()) {
fillGlobalParam(kieSession, subLogic.getProcess(), entity);
}
}
kieSession.startProcess(mainProcess.getId());
log.debug("实体处理逻辑[{}:{}:{}:{}]执行结束", entity.getClass().getSimpleName(), action, bpmnFile.getFilename(), logicMode);
} catch (IOException e) {
log.error("执行实体处理逻辑[{}:{}:{}:{}]发生异常" + e.getMessage(), entity.getClass().getSimpleName(), action, bpmnFile.getFilename(), logicMode);
throw new BadRequestAlertException("执行实体处理逻辑发生异常"+ e.getMessage(), "DELogicAspect", "executeLogic");
} }
kieSession.startProcess(mainProcess.getId());
log.debug("实体处理逻辑[{}:{}:{}:{}]执行结束", entity.getClass().getSimpleName(), action, bpmnFile.getName(), logicMode.text);
} }
/** /**
...@@ -751,11 +767,11 @@ public class DELogicAspect { ...@@ -751,11 +767,11 @@ public class DELogicAspect {
* *
* @param logic * @param logic
*/ */
private void reloadLogic(DELogic logic) { private void reloadLogic(DELogic logic) throws IOException {
KieServices kieServices = KieServices.get(); KieServices kieServices = KieServices.get();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem(); KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
for (File bpmn : logic.getRefRuleFiles()) { for (Resource bpmn : logic.getRefRuleFiles()) {
kieFileSystem.write(ResourceFactory.newFileResource(bpmn)); kieFileSystem.write(ResourceFactory.newUrlResource(bpmn.getURL()));
} }
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem).buildAll(); KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem).buildAll();
Results results = kieBuilder.getResults(); Results results = kieBuilder.getResults();
...@@ -811,28 +827,29 @@ public class DELogicAspect { ...@@ -811,28 +827,29 @@ public class DELogicAspect {
* @param entity * @param entity
* @return * @return
*/ */
@SneakyThrows private DELogic getDELogic(Resource bpmnFile, Object entity, String instanceId) {
private DELogic getDELogic(File bpmnFile, Object entity, LogicMode logicMode) {
DELogic logic = null; DELogic logic = null;
XMLStreamReader reader = null; XMLStreamReader reader = null;
InputStream bpmn = null; InputStream bpmn = null;
try { try {
if (bpmnFile.exists()) { if (bpmnFile.exists()) {
XMLInputFactory factory = XMLInputFactory.newInstance(); XMLInputFactory factory = XMLInputFactory.newInstance();
bpmn = new FileInputStream(bpmnFile); bpmn = bpmnFile.getInputStream();
reader = factory.createXMLStreamReader(bpmn); reader = factory.createXMLStreamReader(bpmn);
BpmnModel model = bpmnXMLConverter.convertToBpmnModel(reader); BpmnModel model = bpmnXMLConverter.convertToBpmnModel(reader);
Process mainProcess = model.getMainProcess(); Process mainProcess = model.getMainProcess();
if (mainProcess == null) { if (mainProcess == null) {
return null; return null;
} }
log.debug("正在加载 BPMN:{}", bpmnFile.getURL().getPath());
List<DELogic> refLogics = new ArrayList<>(); List<DELogic> refLogics = new ArrayList<>();
List<File> refFiles = new ArrayList<>(); List<Resource> refFiles = new ArrayList<>();
//自己 bpmn drl //自己 bpmn drl
refFiles.add(bpmnFile); refFiles.add(bpmnFile);
File drlFile = getDrl(bpmnFile); Resource drlFile = getDrl(bpmnFile);
if (drlFile != null && drlFile.exists()) { if (drlFile != null && drlFile.exists()) {
refFiles.add(drlFile); refFiles.add(drlFile);
log.debug("正在加载 DRL:{}", drlFile.getURL().getPath());
} }
// bpmn drl // bpmn drl
if (!ObjectUtils.isEmpty(model.getMainProcess()) && !ObjectUtils.isEmpty(model.getMainProcess().getFlowElementMap())) { if (!ObjectUtils.isEmpty(model.getMainProcess()) && !ObjectUtils.isEmpty(model.getMainProcess().getFlowElementMap())) {
...@@ -840,12 +857,8 @@ public class DELogicAspect { ...@@ -840,12 +857,8 @@ public class DELogicAspect {
if (item instanceof CallActivity) { if (item instanceof CallActivity) {
CallActivity subBpmn = (CallActivity) item; CallActivity subBpmn = (CallActivity) item;
String bpmnFileName = subBpmn.getName(); String bpmnFileName = subBpmn.getName();
log.debug("正在加载 BPMN:{}", bpmnFileName); Resource subBpmnFile = getSubBpmn(getDEModule(entity), entity.getClass().getSimpleName(), bpmnFileName, bpmnFile, instanceId);
File subBpmnFile = getSubBpmn(getDEModule(entity), entity.getClass().getSimpleName(), bpmnFileName, logicMode); DELogic refLogic = getDELogic(subBpmnFile, entity, instanceId);
if (ObjectUtils.isEmpty(subBpmnFile)) {
log.debug("BPMN:{},缺少文件:{} ", bpmnFileName, subBpmnFile);
}
DELogic refLogic = getDELogic(subBpmnFile, entity, logicMode);
if (refLogic != null) { if (refLogic != null) {
refLogics.add(refLogic); refLogics.add(refLogic);
if (!ObjectUtils.isEmpty(refLogic.getRefRuleFiles())) { if (!ObjectUtils.isEmpty(refLogic.getRefRuleFiles())) {
...@@ -864,7 +877,7 @@ public class DELogicAspect { ...@@ -864,7 +877,7 @@ public class DELogicAspect {
logic.setMd5(getMd5(refFiles)); logic.setMd5(getMd5(refFiles));
} }
} catch (Exception e) { } catch (Exception e) {
log.error("执行处理逻辑失败"+e); log.error("执行处理逻辑失败" + e);
} finally { } finally {
try { try {
if (reader != null) { if (reader != null) {
...@@ -874,7 +887,7 @@ public class DELogicAspect { ...@@ -874,7 +887,7 @@ public class DELogicAspect {
bpmn.close(); bpmn.close();
} }
} catch (Exception e) { } catch (Exception e) {
log.error("执行处理逻辑失败"+e); log.error("执行处理逻辑失败" + e);
} }
} }
return logic; return logic;
...@@ -899,10 +912,10 @@ public class DELogicAspect { ...@@ -899,10 +912,10 @@ public class DELogicAspect {
} }
} }
} }
if(!ObjectUtils.isEmpty(service.getSuperclass()) && !service.getSuperclass().getName().equals(Object.class.getName())) { if (!ObjectUtils.isEmpty(service.getSuperclass()) && !service.getSuperclass().getName().equals(Object.class.getName())) {
return getEntity(service.getSuperclass()); return getEntity(service.getSuperclass());
} }
log.error("获取实体信息失败,未能在[{}]中找到参数为实体类对象的行为,如create.update等",service.getSimpleName()); log.error("获取实体信息失败,未能在[{}]中找到参数为实体类对象的行为,如create.update等", service.getSimpleName());
return null; return null;
} }
...@@ -912,19 +925,19 @@ public class DELogicAspect { ...@@ -912,19 +925,19 @@ public class DELogicAspect {
* @param subFiles * @param subFiles
* @return * @return
*/ */
private String getMd5(List<File> subFiles) { private String getMd5(List<Resource> subFiles) {
try { try {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
for (File file : subFiles) { for (Resource file : subFiles) {
InputStream bpmnFile = null; InputStream bpmnFile = null;
try { try {
bpmnFile = new FileInputStream(file); bpmnFile = file.getInputStream();
if (!ObjectUtils.isEmpty(bpmnFile)) { if (!ObjectUtils.isEmpty(bpmnFile)) {
String strBpmn = IOUtils.toString(bpmnFile, "UTF-8"); String strBpmn = IOUtils.toString(bpmnFile, "UTF-8");
buffer.append(strBpmn); buffer.append(strBpmn);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("处理逻辑版本检查失败"+e); log.error("处理逻辑版本检查失败" + e);
} finally { } finally {
if (bpmnFile != null) { if (bpmnFile != null) {
bpmnFile.close(); bpmnFile.close();
...@@ -937,7 +950,7 @@ public class DELogicAspect { ...@@ -937,7 +950,7 @@ public class DELogicAspect {
return null; return null;
} }
} catch (Exception e) { } catch (Exception e) {
log.error("处理逻辑版本检查失败"+e); log.error("处理逻辑版本检查失败" + e);
return null; return null;
} }
} }
...@@ -950,10 +963,8 @@ public class DELogicAspect { ...@@ -950,10 +963,8 @@ public class DELogicAspect {
* @param logicExecMode * @param logicExecMode
* @return * @return
*/ */
private File getLocalModel(String entity, String action, LogicExecMode logicExecMode) { private Resource getLocalModel(String entity, String action, LogicExecMode logicExecMode) {
String logicName = String.format("%s.bpmn", logicExecMode.text); return new ClassPathResource("rules" + File.separator + entity + File.separator + action.toLowerCase() + File.separator + logicExecMode.text + ".bpmn");
String filePath = File.separator + "rules" + File.separator + entity + File.separator + action.toLowerCase() + File.separator + logicName;
return getBpmnFile(filePath);
} }
/** /**
...@@ -965,9 +976,9 @@ public class DELogicAspect { ...@@ -965,9 +976,9 @@ public class DELogicAspect {
* @param logicExecMode * @param logicExecMode
* @return * @return
*/ */
private File getRemoteModel(String module, String entity, String action, LogicExecMode logicExecMode) { private Resource getRemoteModel(String module, String entity, String action, LogicExecMode logicExecMode, String instanceId) {
String logicName = String.format("psdeaction.json.%s.bpmn", logicExecMode.text); return new FileSystemResource(dynamicPath + File.separator + (systemId + File.separator + instanceId + File.separator + "psmodules" + File.separator + module +
return getBpmnFile(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()); File.separator + "psdataentities" + File.separator + entity + File.separator + "psdeactions" + File.separator + action + ".json." + logicExecMode.text + ".bpmn").toLowerCase());
} }
/** /**
...@@ -978,14 +989,13 @@ public class DELogicAspect { ...@@ -978,14 +989,13 @@ public class DELogicAspect {
* @param logicName * @param logicName
* @return * @return
*/ */
private File getSubBpmn(String module, String entity, String logicName, LogicMode logicMode) { private Resource getSubBpmn(String module, String entity, String logicName, Resource parentBpmn, String instanceId) {
if (LogicMode.REMOTE.equals(logicMode)) { if (parentBpmn instanceof FileSystemResource) {
return getBpmnFile(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()); return new FileSystemResource(dynamicPath + File.separator + (systemId + File.separator + instanceId + File.separator + "psmodules" + File.separator + module
+ File.separator + "psdataentities" + File.separator + entity + File.separator + "psdelogics" + File.separator + logicName).toLowerCase());
} else { } else {
String filePath = String.format("/rules/%s", logicName); return new ClassPathResource(String.format("rules/%s", logicName));
return getBpmnFile(filePath);
} }
} }
/** /**
...@@ -994,41 +1004,11 @@ public class DELogicAspect { ...@@ -994,41 +1004,11 @@ public class DELogicAspect {
* @param bpmn * @param bpmn
* @return * @return
*/ */
private File getDrl(File bpmn) { @SneakyThrows
if (bpmn.getPath().endsWith("RuleFlow.bpmn")) { private Resource getDrl(Resource bpmn) {
return getBpmnFile(bpmn.getPath().replace("RuleFlow.bpmn", "Rule.drl")); String filePath = bpmn instanceof FileSystemResource ? bpmn.getURL().getPath() : ((ClassPathResource) bpmn).getPath();
} else { filePath = filePath.endsWith("RuleFlow.bpmn") ? filePath.replace("RuleFlow.bpmn", "Rule.drl") : filePath.replace(".bpmn", ".drl");
return getBpmnFile(bpmn.getPath().replace(".bpmn", ".drl")); return bpmn instanceof FileSystemResource ? new FileSystemResource(filePath) : new ClassPathResource(filePath);
}
}
/**
* 获取 bpmn
*
* @param filePath
* @return
*/
private File getBpmnFile(String filePath) {
InputStream in = null;
File bpmn = null;
try {
in = this.getClass().getResourceAsStream(filePath.replace("\\", "/"));
if (in != null) {
bpmn = new File(filePath);
FileUtils.copyToFile(in, bpmn);
}
} catch (IOException e) {
log.error("执行处理逻辑失败,无法获取逻辑文件"+e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return bpmn;
} }
/** /**
...@@ -1051,6 +1031,79 @@ public class DELogicAspect { ...@@ -1051,6 +1031,79 @@ public class DELogicAspect {
return strModule; return strModule;
} }
/**
* 获取动态实例标识
*
* @param entity
* @return
*/
private String getDynaInstId(EntityBase entity) {
String instId = null;
Object instTag = null;
Map<String, DEField> deFields = DEFieldCacheMap.getDEFields(entity.getClass());
for (Map.Entry<String, DEField> deField : deFields.entrySet()) {
if (deField.getValue().dynaInstTagField()) {
instTag = entity.get(deField.getKey());
}
}
if (ObjectUtils.isEmpty(instTag)) {
return null;
}
JSONObject defaultDynaInst = getDefaultDynaInst();
if (!ObjectUtils.isEmpty(defaultDynaInst)) {
JSONArray instances = defaultDynaInst.getJSONArray("getPSDynaInsts");
if (!ObjectUtils.isEmpty(instances)) {
for (Object item : instances) {
JSONObject dynaInst = (JSONObject) item;
if (dynaInst != null) {
if (!ObjectUtils.isEmpty(dynaInst.get("instTag"))) {
return String.valueOf(dynaInst.get("instTag"));
}
}
}
}
}
return instId;
}
/**
* 获取系统标识
*
* @return 返回一组SystemJSON数据
*/
private JSONObject getDefaultDynaInst() {
JSONObject dynaInst = null;
InputStream in = null;
byte[] bytes = null;
try {
Resource file = new FileSystemResource(dynamicPath + File.separator + systemId + File.separator + defaultDynaInstId + File.separator + "PSSYSTEM.json");
if (!file.exists()) {
throw new BadRequestAlertException(String.format("无法获取动态实例[%s]", file.getURL().getPath()), "DELogicAspect", "getDefaultDynaInst");
}
in = file.getInputStream();
bytes = new byte[in.available()];
in.read(bytes);
} catch (Exception e) {
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
}
}
if (bytes != null) {
String strSystem = new String(bytes, StandardCharsets.UTF_8);
if (!StringUtils.isEmpty(strSystem)) {
dynaInst = JSONObject.parseObject(strSystem);
}
}
if (ObjectUtils.isEmpty(dynaInst)) {
throw new BadRequestAlertException("无法获取动态实例", "DELogicAspect", "getDefaultDynaInst");
}
return dynaInst;
}
/** /**
* 执行动态行为 * 执行动态行为
* *
...@@ -1141,25 +1194,6 @@ public class DELogicAspect { ...@@ -1141,25 +1194,6 @@ public class DELogicAspect {
<#comment>输出枚举类</#comment> <#comment>输出枚举类</#comment>
<#macro enum> <#macro enum>
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 { public enum LogicExecMode {
/** /**
* 前附加逻辑 * 前附加逻辑
......
<#ibiztemplate> <#ibiztemplate>
TARGET=PSSYSTEM TARGET=PSSYSTEM
</#ibiztemplate> </#ibiztemplate>
<#assign isDynaSys =false>
<#if sys.getAllPSSystemModules()??>
<#list sys.getAllPSSystemModules() as module>
<#if module.getDynaInstMode()?? && (module.getDynaInstMode()?c=='1' || module.getDynaInstMode()?c=='2' )>
<#assign isDynaSys =true>
<#break>
</#if>
</#list>
</#if>
package ${pub.getPKGCodeName()}.util.domain; package ${pub.getPKGCodeName()}.util.domain;
import lombok.Data; import lombok.Data;
import org.flowable.bpmn.model.Process; import org.flowable.bpmn.model.Process;
import org.springframework.core.io.Resource;
import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieContainer;
import java.io.File; import java.io.File;
import java.io.Serializable; import java.io.Serializable;
...@@ -17,6 +27,11 @@ public class DELogic implements Serializable { ...@@ -17,6 +27,11 @@ public class DELogic implements Serializable {
Process process; Process process;
KieContainer container; KieContainer container;
List<DELogic> refLogic; List<DELogic> refLogic;
<#comment>非动态系统</#comment>
<#if !isDynaSys>
List<File> refRuleFiles; List<File> refRuleFiles;
<#else>
List<Resource> refRuleFiles;
</#if>
String md5; String md5;
} }
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册