1.增加链路初始化

2.删除无效sql
3.更新测试参数
This commit is contained in:
chenweilong 2022-12-13 11:00:43 +08:00
parent 6ebf3b8c30
commit a37e5df823
8 changed files with 122 additions and 51 deletions

View File

@ -1,10 +1,13 @@
package com.example.liteflow.mysql.bean;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.liteflow.mysql.entity.ChainEntity;
import com.example.liteflow.mysql.entity.DynamicScriptEntity;
import com.example.liteflow.mysql.enums.NodeEnum;
import com.example.liteflow.mysql.service.ChainService;
import com.example.liteflow.mysql.service.DynamicScriptService;
import com.yomahub.liteflow.builder.LiteFlowNodeBuilder;
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.FlowBus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
@ -22,17 +25,22 @@ import java.util.List;
public class AviatorEvaluatorRunner implements CommandLineRunner {
@Resource
private DynamicScriptService dynamicScriptService;
@Resource
private ChainService chainService;
@Resource
private FlowExecutor flowExecutor;
@Override
public void run(String... args) throws Exception {
List<DynamicScriptEntity> list = dynamicScriptService.list();
log.info("AviatorEvaluatorRunner-list = {}", list.size());
list.forEach(item -> {
String scriptId = item.getScriptId();
List<DynamicScriptEntity> dynamicScriptEntityList = dynamicScriptService.list();
log.info("AviatorEvaluatorRunner-dynamicScriptEntityList = {}", dynamicScriptEntityList.size());
dynamicScriptEntityList.forEach(dynamicScript -> {
String scriptId = dynamicScript.getScriptId();
boolean containNode = FlowBus.containNode(scriptId);
if (!containNode) {
String scriptName = item.getScriptName();
String scriptClass = item.getScriptClass();
String nodeType = item.getNodeType();
String scriptName = dynamicScript.getScriptName();
String scriptClass = dynamicScript.getScriptClass();
String nodeType = dynamicScript.getNodeType();
if (NodeEnum.CommonNode.getName().equals(nodeType)) {
LiteFlowNodeBuilder.createCommonNode().setId(scriptId)
.setName(scriptName)
@ -46,5 +54,15 @@ public class AviatorEvaluatorRunner implements CommandLineRunner {
}
}
});
List<ChainEntity> chainEntityList = chainService.list();
log.info("AviatorEvaluatorRunner-chainEntityList = {}", chainEntityList.size());
chainEntityList.forEach(chainEntity -> {
LiteFlowChainELBuilder.createChain()
.setChainId(chainEntity.getChainName())
.setEL(chainEntity.getElData())
.build();
flowExecutor.reloadRule();
});
}
}

View File

@ -61,7 +61,7 @@ public class CostCenterCmp extends NodeIfComponent {
for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName();
BaseDataEntity baseDataEntity = baseDataService.getByTypeAndName(name, BaseDataAttributionEnum.costCenter.getAttribution(), name + "List");
BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.costCenter.getAttribution());
if (ObjectUtil.isNotNull(baseDataEntity)) {
String content = baseDataEntity.getContent();
String contentName = baseDataEntity.getContentName();

View File

@ -54,7 +54,7 @@ public class ProfitCenterCmp extends NodeIfComponent {
for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName();
BaseDataEntity baseDataEntity = baseDataService.getByTypeAndName(name, BaseDataAttributionEnum.costCenter.getAttribution(), name + "List");
BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.costCenter.getAttribution());
if (ObjectUtil.isNotNull(baseDataEntity)) {
String content = baseDataEntity.getContent();
String contentName = baseDataEntity.getContentName();

View File

@ -1,5 +1,6 @@
package com.example.liteflow.mysql.controller;
import cn.hutool.json.JSONObject;
import com.example.liteflow.mysql.entity.ChainEntity;
import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.service.ChainService;
@ -80,4 +81,9 @@ public class ChainController {
public String updateChain(@RequestBody ChainEntity chainEntity) {
return chainService.updateChain(chainEntity);
}
@GetMapping("/getChain")
public List<JSONObject> getChain() {
return chainService.getChain();
}
}

View File

@ -1,5 +1,7 @@
package com.example.liteflow.mysql.service;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.liteflow.mysql.entity.ChainEntity;
import com.example.liteflow.mysql.model.BaseCenter;
@ -9,7 +11,7 @@ import java.util.List;
* @author: 陈韦龙
* @date: 2022年12月08日 18:23
*/
public interface ChainService {
public interface ChainService extends IService<ChainEntity> {
void createChain(ChainEntity chainEntity);
void dynamicGenerateChain(ChainEntity chainEntity);
@ -21,4 +23,6 @@ public interface ChainService {
String deleteChain(String id);
String updateChain(ChainEntity chainEntity);
List<JSONObject> getChain();
}

View File

@ -1,5 +1,6 @@
package com.example.liteflow.mysql.service.impl;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@ -12,13 +13,17 @@ import com.example.liteflow.mysql.model.ProfitCenter;
import com.example.liteflow.mysql.service.ChainService;
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.flow.element.Chain;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author: 陈韦龙
@ -42,6 +47,7 @@ public class ChainServiceImpl extends ServiceImpl<ChainMapper, ChainEntity> impl
.setEL(chainEntity.getElData())
.build();
flowExecutor.reloadRule();
this.save(chainEntity);
}
@Override
@ -125,4 +131,16 @@ public class ChainServiceImpl extends ServiceImpl<ChainMapper, ChainEntity> impl
return "更新失败";
}
}
@Override
public List<JSONObject> getChain() {
List<ChainEntity> list = this.list();
return list.stream().filter(item -> FlowBus.containChain(item.getChainName())).map(item -> {
String chainName = item.getChainName();
String elData = item.getElData();
JSONObject jsonObject = new JSONObject();
jsonObject.putOpt("chainName", chainName).putOpt("elData", elData);
return jsonObject;
}).collect(Collectors.toList());
}
}

View File

@ -9,31 +9,6 @@ create table chain
create_time datetime null
);
create table script
(
id bigint auto_increment
primary key,
application_name varchar(32) null,
script_id varchar(32) null,
script_name varchar(64) null,
script_data text null,
script_type varchar(16) null
);
INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (1, 'demo', 'chain1', '测试流程', 'THEN(s3, s4, s5, s6);', '2022-09-19 19:31:00');
INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (2, 'demo', 'costCenter', '测试流程', 'THEN(s3, s4, s5, s6, IF(sectionClassification, IF(businessType, IF(salesman, IF(businessCategory, s7, s9), s9), s9), IF(businessType, IF(salesman, s8, s9), IF(businessType, s8, s9))));', '2022-11-29 14:58:00');
INSERT INTO `script`(`id`, `application_name`, `script_id`, `script_name`, `script_data`, `script_type`) VALUES (1, 'demo', 's1', '脚本s1', 'import cn.hutool.core.date.DateUtil\r\n\r\ndef date = DateUtil.parse(\"2022-10-17 13:31:43\")\r\nprintln(date)\r\ndefaultContext.setData(\"demoDate\", date)\r\n\r\nclass Student {\r\n int studentID\r\n String studentName\r\n}\r\n\r\nStudent student = new Student()\r\nstudent.studentID = 100301\r\nstudent.studentName = \"张三\"\r\ndefaultContext.setData(\"student\",student)\r\n\r\ndef a=3\r\ndef b=2\r\ndefaultContext.setData(\"s1\",a*b)', 'script');
INSERT INTO `script`(`id`, `application_name`, `script_id`, `script_name`, `script_data`, `script_type`) VALUES (2, 'demo', 's2', '脚本s2', 'defaultContext.setData(\"s2\",\"hello\")', 'script');
INSERT INTO `script`(`id`, `application_name`, `script_id`, `script_name`, `script_data`, `script_type`) VALUES (3, 'demo', 's3', 'sectionClassification', 'def globalSectionClassificationList = [\"汇差\",\"手续费\",\"成本科目\"]\r\nglobalSectionClassification.setGlobalSectionClassificationList(globalSectionClassificationList)\r\n', 'script');
INSERT INTO `script`(`id`, `application_name`, `script_id`, `script_name`, `script_data`, `script_type`) VALUES (4, 'demo', 's4', 'globalBusinessType', 'def globalBusinessTypeList = [\"货代\",\"报关\",\"船代\",\"散杂货\"]\r\nglobalBusinessType.setGlobalBusinessTypeList(globalBusinessTypeList)', 'script');
INSERT INTO `script`(`id`, `application_name`, `script_id`, `script_name`, `script_data`, `script_type`) VALUES (5, 'demo', 's5', 'salesman', 'def globalSalesmanList = [\"仓干配物流部(物流)\"]\r\nsalesman.setGlobalSalesmanList(globalSalesmanList)', 'script');
INSERT INTO `script`(`id`, `application_name`, `script_id`, `script_name`, `script_data`, `script_type`) VALUES (6, 'demo', 's6', 'businessCategory', 'def globalBusinessCategoryList = [\"全货船业务\",\"进出岛仓干配\"]\r\nbusinessCategory.setGlobalBusinessCategoryList(globalBusinessCategoryList)', 'script');
INSERT INTO `script`(`id`, `application_name`, `script_id`, `script_name`, `script_data`, `script_type`) VALUES (7, 'demo', 's7', 'costCenter01', 'def costCenter01Code = \"P350401028\"\r\ncostCenterContext.setCode(costCenter01Code)\r\n\r\ndef costCenter01Name = \"仓干配物流部利润中心\"\r\ncostCenterContext.setName(costCenter01Name)\r\n\r\ncostCenterContext.setGenerateCode(costCenter01Code + costCenter01Name)', 'script');
INSERT INTO `script`(`id`, `application_name`, `script_id`, `script_name`, `script_data`, `script_type`) VALUES (8, 'demo', 's8', 'costCenter02', 'def costCenter02Code = \"P350401026\"\r\ncostCenterContext.setCode(costCenter02Code)\r\n\r\ndef costCenter02Name = \"商品车物流部利润中心\"\r\ncostCenterContext.setName(costCenter02Name)\r\n\r\ncostCenterContext.setGenerateCode(costCenter02Code + costCenter02Name)', 'script');
INSERT INTO `script`(`id`, `application_name`, `script_id`, `script_name`, `script_data`, `script_type`) VALUES (9, 'demo', 's9', 'sout', 'def defaultName = \"无匹配项\"\r\ncostCenterContext.setGenerateCode(defaultName)', 'script');
CREATE TABLE `base_data` (
`id` varchar(255) NOT NULL,
`type` varchar(30) NULL,
@ -43,12 +18,6 @@ CREATE TABLE `base_data` (
`content_name` varchar(30) NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `base_role` (
`id` varchar(255) NOT NULL,
`role_str` text NULL,
`role_name` varchar(30) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
);
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('0927941726325838', 'sectionClassification', 'costCenter', '[银行科目, 预付科目, 预收科目]', 'List', 'sectionClassificationList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('3927088550655742', 'businessCategory', 'costCenter', '[运输业务, 全货船业务, 进出岛仓干配]', 'List', 'businessCategoryList');
@ -59,14 +28,6 @@ INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`,
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('9047450688035130', 'businessType', 'costCenter', '[货代, 报关, 船代, 散杂货]', 'List', 'businessTypeList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('2790513253702116', 'salesman', 'costCenter', '[仓干配物流部(物流)]', 'List', 'salesmanList');
-- INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (3, 'demo', 'cost01AndCost02', '测试流程', 'IF(costCenter01Cmp, CostCenter01SoutCmp, IF(costCenter02Cmp, CostCenter02SoutCmp, sout));', '2022-12-06 16:03:34');
-- INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (4, 'demo', 'cost01', '测试流程', 'IF(costCenter01Cmp, CostCenter01SoutCmp, sout);', '2022-12-06 16:03:34');
-- INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (5, 'demo', 'cost02', '测试流程', 'IF(costCenter02Cmp, CostCenter02SoutCmp, sout);', '2022-12-06 16:03:34');
-- INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (6, 'demo', 'profit01AndProfit02', '测试流程', 'IF(profitCenter01Cmp, ProfitCenter01SoutCmp, IF(profitCenter02Cmp, ProfitCenter02SoutCmp, sout));', '2022-12-06 16:03:34');
-- INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (7, 'demo', 'profit01', '测试流程', 'IF(profitCenter01Cmp, ProfitCenter01SoutCmp, sout);', '2022-12-06 16:03:34');
-- INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (8, 'demo', 'profit02', '测试流程', 'IF(profitCenter02Cmp, ProfitCenter02SoutCmp, sout);', '2022-12-06 16:03:34');
-- INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (9, 'demo', 'costAndProfit', '测试流程', 'THEN(cost01AndCost02, profit01AndProfit02);', '2022-12-06 16:03:34');
CREATE TABLE `dynamic_script` (
`id` varchar(255) NOT NULL COMMENT '主键',
`script_id` varchar(32) NULL DEFAULT NULL COMMENT '脚本Id',

View File

@ -36,7 +36,7 @@
]
}
/dynamicScript/createCostCenterNode
/dynamicScript/createCostCenterIfNode
{
"scriptId": "a4",
"scriptName": "costCenter02Cmp",
@ -178,4 +178,68 @@
]
}
]
}
/dynamicScript/createProfitCenterNode
{
"scriptId": "a5",
"scriptName": "profitCenter01Sout",
"content": {
"code": "P350401029",
"name": "仓干配物流部成本中心"
}
}
/dynamicScript/createProfitCenterNode
{
"scriptId": "a6",
"scriptName": "profitCenter02Sout",
"content": {
"code": "P350401027",
"name": "商品车物流部成本中心"
}
}
/dynamicScript/createCostCenterNode
{
"scriptId": "a7",
"scriptName": "costCenter01Sout",
"content": {
"code": "P350401028",
"name": "仓干配物流部利润中心"
}
}
/dynamicScript/createCostCenterNode
{
"scriptId": "a8",
"scriptName": "costCenter02Sout",
"content": {
"code": "P350401026",
"name": "商品车物流部利润中心"
}
}
/chain/dynamicGenerateChain
{
"applicationName": "demo",
"chainName": "cost01AndCost02",
"chainDesc": "测试流程",
"elData": "IF(a3, a7, IF(a4, a8, sout));"
}
/chain/dynamicGenerateChain
{
"applicationName": "demo",
"chainName": "profit01AndProfit02",
"chainDesc": "测试流程",
"elData": "IF(a1, a5, IF(a2, a6, sout));"
}
/chain/dynamicGenerateChain
{
"applicationName": "demo",
"chainName": "costAndProfit",
"chainDesc": "测试流程",
"elData": "THEN(cost01AndCost02, profit01AndProfit02);"
}