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

适配动态系统

上级 aaf4fcd1
......@@ -9,6 +9,37 @@ TARGET=PSDELOGIC
<tns:import name="java.util.Map" />
<tns:import name="org.springframework.util.StringUtils"/>
<tns:import name="${pub.getPKGCodeName()}.util.helper.RuleUtils"/>
<#if pub.isEnableDynaModel()?? && pub.isEnableDynaModel()== true>
<#comment>插入逻辑参数</#comment>
<#if item.getPSDELogicParams?? && item.getPSDELogicParams()??>
<#assign logicName=(de.codeName+item.codeName)?lower_case>
<#list item.getPSDELogicParams() as logicParam>
<#assign paramObj=(logicName+logicParam.codeName)?lower_case>
<#if logicParam.isDefault()==true><#comment>默认变量</#comment>
<tns:metaData express="" name="${paramObj}" type="entity"/>
<#elseif logicParam.getParamPSDataEntity?? && logicParam.getParamPSDataEntity()??>
<#assign ParamPSDataEntity=logicParam.getParamPSDataEntity()>
<tns:metaData express="new ${pub.getPKGCodeName()}.core.${ParamPSDataEntity.getPSSystemModule().codeName?lower_case}.domain.${ParamPSDataEntity.codeName}()" name="${(logicName+logicParam.codeName)?lower_case}" type="ref"/>
<#else>
<tns:metaData express="new HashMap()" name="${(logicName+logicParam.codeName)?lower_case}" type="ref"/>
</#if>
</#list>
</#if>
<#comment>插入处理逻辑中所用到的service对象</#comment>
<#if item.getPSDELogicNodes?? && item.getPSDELogicNodes()??>
<#list item.getPSDELogicNodes() as deLogicNode>
<#if deLogicNode.getDstPSDataEntity?? && deLogicNode.getDstPSDataEntity()??>
<#assign nodePSDataEntity=deLogicNode.getDstPSDataEntity()>
<#if !P.exists(item.codeName,"kieSessionGlobalServiceBpmn",deLogicNode.getDstPSDataEntity().getCodeName()?lower_case)>
<tns:metaData express="T(${pub.getPKGCodeName()}.util.security.SpringContextHolder).getBean(T(${pub.getPKGCodeName()}.core.${nodePSDataEntity.getPSSystemModule().codeName?lower_case}.service.I${nodePSDataEntity.codeName}Service))" name="${deLogicNode.getDstPSDataEntity().getCodeName()?lower_case}service" type="service"/>
</#if>
</#if>
</#list>
</#if>
<#comment>插入当前实体的defaultService对象,供自定义查询使用</#comment>
<tns:metaData express="T(${pub.getPKGCodeName()}.util.security.SpringContextHolder).getBean(T(${pub.getPKGCodeName()}.core.${de.getPSSystemModule().codeName?lower_case}.service.I${de.codeName}Service))" name="iBzSys${de.codeName?lower_case?cap_first}DefaultService" type="service"/>
<tns:metaData express="T(${pub.getPKGCodeName()}.util.security.AuthenticationUser).getAuthenticationUser()" name="curuser" type="session"/>
</#if>
<#assign logicName=(de.codeName+item.codeName)?lower_case>
<#comment>插入逻辑参数</#comment>
<#if item.getPSDELogicParams?? && item.getPSDELogicParams()??>
......
<#ibiztemplate>
TARGET=PSDEACTION
</#ibiztemplate>
<#if sys.getCodeName()=='Sample'>
<#assign hasAfterLogic = false>
<#if item.getAfterPSDEActionLogics?? && item.getAfterPSDEActionLogics()??>
<#list item.getAfterPSDEActionLogics() as afterlogic>
<#assign hasAfterLogic = true>
<#break>
</#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">
<extensionElements>
<tns:import name="java.util.Map"/>
<tns:import name="org.springframework.util.StringUtils"/>
<tns:import name="${pub.getPKGCodeName()}.util.helper.RuleUtils"/>
</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>
</#if>
</process>
</definitions>
</#if>
</#if>
\ No newline at end of file
<#ibiztemplate>
TARGET=PSDEACTION
</#ibiztemplate>
<#if sys.getCodeName()=='Sample'>
<#assign hasBeforeLogic =false>
<#if item.getBeforePSDEActionLogics?? && item.getBeforePSDEActionLogics()??>
<#list item.getBeforePSDEActionLogics() as beforelogic>
<#assign hasBeforeLogic=true>
<#break>
</#list>
</#if>
<#if hasBeforeLogic>
<?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.before" isClosed="false" isExecutable="true" name="ScoreRule" processType="Private" tns:packageName="${pub.getPKGCodeName()}.core.extensions.service.logic.before">
<extensionElements>
<tns:import name="java.util.Map"/>
<tns:import name="org.springframework.util.StringUtils"/>
<tns:import name="${pub.getPKGCodeName()}.util.helper.RuleUtils"/>
</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()>
<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 !beforelogic_has_next>
<sequenceFlow id="${source}_${target}" sourceRef="${source}" targetRef="prepareparam1_end"/>
</#if>
</#list>
</#if>
</process>
</definitions>
</#if>
</#if>
\ No newline at end of file
<#ibiztemplate>
TARGET=PSDEACTION
</#ibiztemplate>
<#if sys.getCodeName()=='Sample'>
<#if item.getActionType()=='DELOGIC' && item.getPSDELogic()??>
<?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">
<extensionElements>
<tns:import name="java.util.Map"/>
<tns:import name="org.springframework.util.StringUtils"/>
<tns:import name="${pub.getPKGCodeName()}.util.helper.RuleUtils"/>
</extensionElements>
<#comment>实体行为附加逻辑</#comment>
<#assign delogic = item.getPSDELogic()>
<#assign source="begin">
<#assign action=item.getPSDELogic()>
<startEvent id="begin" isInterrupting="true"/>
<endEvent id="prepareparam1_end" name="end"/>
<#assign target = action.getCodeName()>
<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}"/>
<sequenceFlow id="${source}_${target}" sourceRef="${source}" targetRef="${target}"/>
<#assign source = target>
<sequenceFlow id="${source}_${target}" sourceRef="${source}" targetRef="prepareparam1_end"/>
</process>
</definitions>
</#if>
</#if>
\ No newline at end of file
......@@ -123,7 +123,9 @@ TARGET=PSSYSTEM
<#if hasMQEntity>
<rocketmq.version>4.7.0</rocketmq.version>
</#if>
<#if pub.isEnableDynaModel()?? && pub.isEnableDynaModel()== true>
<flowable-modeler.version>6.4.2</flowable-modeler.version>
</#if>
</properties>
<#-- dependencies,just for statement, manage the version of jars -->
......@@ -327,7 +329,7 @@ TARGET=PSSYSTEM
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<version> ${r'${spring-cloud-alibaba.version}'}</version>
<version>${r'${spring-cloud-alibaba.version}'}</version>
<exclusions>
<exclusion>
<groupId>io.seata</groupId>
......@@ -337,6 +339,18 @@ TARGET=PSSYSTEM
</dependency>
</#if>
<#if pub.isEnableDynaModel()?? && pub.isEnableDynaModel()== true>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-json-converter</artifactId>
<version>${r'${flowable-modeler.version}'}</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-modeler-conf</artifactId>
<version>${r'${flowable-modeler.version}'}</version>
</dependency>
</#if>
</dependencies>
</dependencyManagement>
......
......@@ -93,5 +93,33 @@ TARGET=PSSYSTEM
<artifactId>feign-httpclient</artifactId>
</dependency>
<#if pub.isEnableDynaModel()?? && pub.isEnableDynaModel()== true>
<!-- drools -->
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-spring</artifactId>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-json-converter</artifactId>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-modeler-conf</artifactId>
</dependency>
</#if>
</dependencies>
</project>
......@@ -127,6 +127,9 @@ public class RedisCacheConfig {
container.setConnectionFactory(redisConnectionFactory);
container.addMessageListener(messageListener, RedisChannelTopic.REDIS_CACHE_DELETE_TOPIC.getChannelTopic());
container.addMessageListener(messageListener, RedisChannelTopic.REDIS_CACHE_CLEAR_TOPIC.getChannelTopic());
<#if pub.isEnableDynaModel()?? && pub.isEnableDynaModel()== true>
container.addMessageListener(messageListener, RedisChannelTopic.REDIS_CACHE_DYNAMICMODEL_TOPIC.getChannelTopic());
</#if>
return container;
}
}
\ No newline at end of file
......@@ -15,6 +15,10 @@ import org.springframework.util.ObjectUtils;
import java.util.Map;
import ${pub.getPKGCodeName()}.util.cache.cache.LayeringCache;
import ${pub.getPKGCodeName()}.util.enums.RedisChannelTopic;
<#if pub.isEnableDynaModel()?? && pub.isEnableDynaModel()== true>
import ${pub.getPKGCodeName()}.util.security.SpringContextHolder;
import ${pub.getPKGCodeName()}.util.service.DynamicModelService;
</#if>
/**
* redis消息的订阅者
......@@ -45,6 +49,13 @@ public class RedisMessageListener extends MessageListenerAdapter {
log.debug("redis消息订阅者接收到频道【{}】发布的消息。消息内容:{}", channelTopic.getChannelTopicStr(), result.toString());
String cacheName = (String) map.get("cacheName");
Cache cache = cacheManager.getCache(cacheName);// 根据缓存名称获取多级缓存
<#if pub.isEnableDynaModel()?? && pub.isEnableDynaModel()== true>
if (channelTopic.equals(RedisChannelTopic.REDIS_CACHE_DYNAMICMODEL_TOPIC)) {
DynamicModelService dynamicModelService = SpringContextHolder.getBean(DynamicModelService.class);
dynamicModelService.syncModel();
return;
}
</#if>
if (cache != null && cache instanceof LayeringCache) { // 判断缓存是否是多级缓存
switch (channelTopic) {
case REDIS_CACHE_DELETE_TOPIC: // 获取一级缓存,并删除一级缓存数据
......
<#ibiztemplate>
TARGET=PSSYSTEM
</#ibiztemplate>
<#if sys.getCodeName()=='Sample'>
package ${pub.getPKGCodeName()}.util.domain;
import lombok.Data;
import org.flowable.bpmn.model.Process;
import org.kie.api.runtime.KieContainer;
import java.io.File;
import java.io.Serializable;
import java.util.List;
@Data
public class DELogic implements Serializable {
String id;
String name;
Process process;
KieContainer container;
List<DELogic> refLogic;
List<File> refRuleFiles;
String md5;
}
</#if>
\ No newline at end of file
......@@ -9,6 +9,9 @@ import org.springframework.data.redis.listener.ChannelTopic;
*/
public enum RedisChannelTopic {
REDIS_CACHE_DELETE_TOPIC("redis:cache:delete:topic1", "删除redis缓存消息频道"),
<#if pub.isEnableDynaModel()?? && pub.isEnableDynaModel()== true>
REDIS_CACHE_DYNAMICMODEL_TOPIC("redis:cache:dynamicmodel:topic3", "动态模型频道"),
</#if>
REDIS_CACHE_CLEAR_TOPIC("redis:cache:clear:topic2", "清空redis缓存消息频道");
String channelTopic;
......
<#ibiztemplate>
TARGET=PSSYSTEM
</#ibiztemplate>
<#if sys.getCodeName()=='Sample'>
package ${pub.getPKGCodeName()}.util.service;
import lombok.extern.slf4j.Slf4j;
import ${pub.getPKGCodeName()}.util.client.IBZLiteFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.io.*;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class DynamicModelService {
@Value("${r'$'}{ibiz.systemid:${sys.getCodeName()}}")
private String systemId;
@Value("${r'${ibiz.dynamic.path:/app/file/dynamicmodel/}'}")
private String dynamicPath;
@Autowired
IBZLiteFeignClient liteClient;
/**
* 同步动态模型
* @return
*/
public boolean syncModel() {
log.debug("开始同步动态模型");
long start = System.currentTimeMillis();
List<Map<String, Object>> dynamicModels = liteClient.getDynamicModel(systemId);
if (!ObjectUtils.isEmpty(dynamicModels)) {
File dynamicFolder = new File(dynamicPath + File.separator + systemId);
if (dynamicFolder.exists()) {
deleteDir(dynamicFolder.getPath());
}
for (Map<String, Object> dynamicModel : dynamicModels) {
InputStream inputStream = null;
BufferedInputStream bufferedInputStream = null;
FileOutputStream outputStream = null;
BufferedOutputStream bufferedOutputStream = null;
try {
String strFileName = String.valueOf(dynamicModel.get("filename"));
String strFilePath = String.valueOf(dynamicModel.get("filepath"));
Object strFileContent = dynamicModel.get("filecontent");
String fullPath = dynamicPath + strFilePath;
File parent = new File(fullPath.replace(strFileName, ""));
if (!parent.exists()) {
parent.mkdirs();
}
File file = new File(fullPath);
file.createNewFile();
// 文件输入流并进行缓冲
inputStream = new ByteArrayInputStream(String.valueOf(strFileContent).getBytes());
bufferedInputStream = new BufferedInputStream(inputStream);
// 文件输出流并进行缓冲
outputStream = new FileOutputStream(file);
bufferedOutputStream = new BufferedOutputStream(outputStream);
// 缓冲数组,大文件 可将 1024 * 2 改大一些,但是 并不是越大就越快
byte[] bytes = new byte[1024 * 2];
int len = 0;
while ((len = inputStream.read(bytes)) != -1) {
bufferedOutputStream.write(bytes, 0, len);
}
// 刷新输出缓冲流
bufferedOutputStream.flush();
log.debug(fullPath);
} catch (IOException e) {
} finally {
try {
if (bufferedInputStream != null) {
bufferedInputStream.close();
}
if (bufferedOutputStream != null) {
bufferedOutputStream.close();
}
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
} catch (IOException e) {
}
}
}
}
long end = System.currentTimeMillis();
log.debug("动态模型同步完成,共耗时"+ (end - start) / 1000 + " 秒");
return true;
}
/**
* 删除历史动态模型
* @param dirPath
*/
public void deleteDir(String dirPath) {
File file = new File(dirPath);
if (file.isFile()) {
file.delete();
} else {
File[] files = file.listFiles();
if (files == null) {
file.delete();
} else {
for (int i = 0; i < files.length; i++) {
deleteDir(files[i].getAbsolutePath());
}
file.delete();
}
}
}
}
</#if>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册