1.使用动态生成链路和脚本,删除多余方法

This commit is contained in:
chenweilong 2022-12-12 12:20:12 +08:00
parent 20922e68a2
commit 1088252c7c
25 changed files with 362 additions and 704 deletions

View File

@ -1,38 +0,0 @@
package com.example.liteflow.mysql.cmp;
import com.example.liteflow.mysql.bean.BusinessCategoryBean;
import com.example.liteflow.mysql.model.CostCenter;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent;
import javax.annotation.Resource;
import java.util.List;
@LiteflowComponent("businessCategory")
public class BusinessCategoryCmp extends NodeIfComponent {
@Resource
private BusinessCategoryBean businessCategoryBean;
// @Override
// public void process() {
// CostCenter requestData = this.getRequestData();
// System.out.println("sectionClassificationCmp executed! ===>>>" + JsonUtil.toJsonString(requestData));
//
// String sectionClassification = requestData.getSectionClassification();
// List<String> globalSectionClassificationList = sectionClassificationBean.getGlobalSectionClassificationList();
// if (globalSectionClassificationList.contains(sectionClassification)) {
//
// }
// }
@Override
public boolean processIf() throws Exception {
CostCenter requestData = this.getRequestData();
System.out.println("BusinessCategoryCmp executed!");
String businessCategory = requestData.getBusinessCategory();
List<String> globalBusinessCategoryList = businessCategoryBean.getGlobalBusinessCategoryList();
return globalBusinessCategoryList.contains(businessCategory);
}
}

View File

@ -1,38 +0,0 @@
package com.example.liteflow.mysql.cmp;
import com.example.liteflow.mysql.bean.BusinessTypeBean;
import com.example.liteflow.mysql.model.CostCenter;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent;
import javax.annotation.Resource;
import java.util.List;
@LiteflowComponent("businessType")
public class BusinessTypeCmp extends NodeIfComponent {
@Resource
private BusinessTypeBean businessTypeBean;
// @Override
// public void process() {
// CostCenter requestData = this.getRequestData();
// System.out.println("sectionClassificationCmp executed! ===>>>" + JsonUtil.toJsonString(requestData));
//
// String sectionClassification = requestData.getSectionClassification();
// List<String> globalSectionClassificationList = sectionClassificationBean.getGlobalSectionClassificationList();
// if (globalSectionClassificationList.contains(sectionClassification)) {
//
// }
// }
@Override
public boolean processIf() throws Exception {
CostCenter requestData = this.getRequestData();
System.out.println("BusinessTypeCmp executed!");
String businessType = requestData.getBusinessType();
List<String> globalBusinessTypeList = businessTypeBean.getGlobalBusinessTypeList();
return globalBusinessTypeList.contains(businessType);
}
}

View File

@ -1,44 +0,0 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.example.liteflow.mysql.cmp;
import com.example.liteflow.mysql.bean.SalesmanBean;
import com.example.liteflow.mysql.model.CostCenter;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent;
import javax.annotation.Resource;
import java.util.List;
@LiteflowComponent("salesman")
public class SalesmanCmp extends NodeIfComponent {
@Resource
private SalesmanBean salesmanBean;
// @Override
// public void process() {
// CostCenter requestData = this.getRequestData();
// System.out.println("sectionClassificationCmp executed! ===>>>" + JsonUtil.toJsonString(requestData));
//
// String sectionClassification = requestData.getSectionClassification();
// List<String> globalSectionClassificationList = sectionClassificationBean.getGlobalSectionClassificationList();
// if (globalSectionClassificationList.contains(sectionClassification)) {
//
// }
// }
@Override
public boolean processIf() throws Exception {
CostCenter requestData = this.getRequestData();
System.out.println("SalesmanCmp executed!");
String salesman = requestData.getSalesman();
List<String> globalSalesmanList = salesmanBean.getGlobalSalesmanList();
return globalSalesmanList.contains(salesman);
}
}

View File

@ -1,45 +0,0 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.example.liteflow.mysql.cmp;
import com.example.liteflow.mysql.bean.SectionClassificationBean;
import com.example.liteflow.mysql.model.CostCenter;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent;
import javax.annotation.Resource;
import java.util.List;
@LiteflowComponent("sectionClassification")
public class SectionClassificationCmp extends NodeIfComponent {
@Resource
private SectionClassificationBean sectionClassificationBean;
// @Override
// public void process() {
// CostCenter requestData = this.getRequestData();
// System.out.println("sectionClassificationCmp executed! ===>>>" + JsonUtil.toJsonString(requestData));
//
// String sectionClassification = requestData.getSectionClassification();
// List<String> globalSectionClassificationList = sectionClassificationBean.getGlobalSectionClassificationList();
// if (globalSectionClassificationList.contains(sectionClassification)) {
//
// }
// }
@Override
public boolean processIf() throws Exception {
CostCenter requestData = this.getRequestData();
System.out.println("sectionClassificationCmp executed!");
String sectionClassification = requestData.getSectionClassification();
List<String> globalSectionClassificationList = sectionClassificationBean.getGlobalSectionClassificationList();
return globalSectionClassificationList.contains(sectionClassification);
}
}

View File

@ -12,14 +12,6 @@ public class SoutCmp extends NodeComponent {
@Override @Override
public void process() { public void process() {
BaseCenter requestData = this.getRequestData(); BaseCenter requestData = this.getRequestData();
// LinkedHashMap<String, String> map = new LinkedHashMap<>();
// Field[] fields = ReflectUtil.getFields(CostCenter.class);
// for (Field field : fields) {
// Object fieldValue = ReflectUtil.getFieldValue(costCenter, field);
// String name = field.getName();
// map.put(name, fieldValue == null ? null : String.valueOf(fieldValue));
// }
// System.out.println(JsonUtil.toJsonString(map));
String costCenterGenerateCode = requestData.getCostCenterGenerateCode(); String costCenterGenerateCode = requestData.getCostCenterGenerateCode();
String profitCenterGenerateCode = requestData.getProfitCenterGenerateCode(); String profitCenterGenerateCode = requestData.getProfitCenterGenerateCode();

View File

@ -1,83 +0,0 @@
package com.example.liteflow.mysql.cmp.costCenter;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.model.CostCenter;
import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.service.BaseRoleService;
import com.example.liteflow.mysql.util.ConditionParser;
import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import java.lang.reflect.Field;
/**
* @author: 陈韦龙
* @date: 2022年12月05日 10:15
*/
@LiteflowComponent("costCenter01Cmp")
@Slf4j
public class CostCenter01Cmp extends NodeIfComponent {
@Resource
private BaseDataService baseDataService;
@Resource
private BaseRoleService baseRoleService;
private static final String baseRoleName = "costCenter01Cmp";
@Override
public boolean processIf() throws Exception {
BaseCenter requestData = this.getRequestData();
log.info("requestData = {}", JSONUtil.toJsonStr(requestData));
String droolStr = baseRoleService.getByName(baseRoleName);
log.info("droolStr = {}", droolStr);
if (StrUtil.isNotBlank(droolStr)) {
Field[] fields = ReflectUtil.getFields(BaseCenter.class);
for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName();
BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.costCenter.getAttribution());
if (ObjectUtil.isNotNull(baseDataEntity)) {
String content = baseDataEntity.getContent();
String contentName = baseDataEntity.getContentName();
droolStr = StrUtil.replace(droolStr, contentName, content, false);
}
String filedValueStr = "";
if (ObjectUtil.isNotNull(fieldValue)) {
filedValueStr = fieldValue.toString();
}
droolStr = StrUtil.replace(droolStr, name, filedValueStr, false);
}
log.info("after - droolStr = {}", droolStr);
JSONArray jsonArray = JSONUtil.parseArray(droolStr);
log.info("jsonArray = {}", jsonArray);
String conditionResult = ConditionParser.parseCondition(jsonArray);
log.info("condition template = {}", conditionResult);
// AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class);
// AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class);
Object executeB = AviatorEvaluator.execute(conditionResult);
log.info("CostCenter01Cmp-{} = {}", conditionResult, executeB);
boolean aBoolean = BooleanUtil.toBoolean(executeB.toString());
log.info("CostCenter01Cmp-aBoolean = {}", aBoolean);
return aBoolean;
} else {
return false;
}
}
}

View File

@ -1,41 +0,0 @@
package com.example.liteflow.mysql.cmp.costCenter;
import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.model.CostCenter;
import com.example.liteflow.mysql.service.BaseDataService;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
/**
* @author: 陈韦龙
* @date: 2022年12月05日 10:15
*/
@LiteflowComponent("CostCenter01SoutCmp")
@Slf4j
public class CostCenter01SoutCmp extends NodeComponent {
// private static final String costCenter01Code = "P350401028";
// private static final String costCenter01Name = "仓干配物流部利润中心";
@Resource
private BaseDataService baseDataService;
@Override
public void process() {
BaseDataEntity codeBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.costCenter.getAttribution(), "costCenter01Code");
BaseDataEntity nameBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.costCenter.getAttribution(), "costCenter01Name");
String costCenter01Code = codeBaseData.getContent();
String costCenter01Name = nameBaseData.getContent();
BaseCenter baseCenter = this.getRequestData();
baseCenter.setCostCenterCode(costCenter01Code);
baseCenter.setCostCenterName(costCenter01Name);
baseCenter.setCostCenterGenerateCode(costCenter01Code + costCenter01Name);
baseCenter.setGenerateCode(null);
}
}

View File

@ -1,84 +0,0 @@
package com.example.liteflow.mysql.cmp.costCenter;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.model.CostCenter;
import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.service.BaseRoleService;
import com.example.liteflow.mysql.util.ConditionParser;
import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author: 陈韦龙
* @date: 2022年12月05日 10:15
*/
@LiteflowComponent("costCenter02Cmp")
@Slf4j
public class CostCenter02Cmp extends NodeIfComponent {
@Resource
private BaseDataService baseDataService;
@Resource
private BaseRoleService baseRoleService;
private static final String baseRoleName = "costCenter02Cmp";
@Override
public boolean processIf() throws Exception {
BaseCenter requestData = this.getRequestData();
String droolStr = baseRoleService.getByName(baseRoleName);
log.info("CostCenter02Cmp-droolStr = {}", droolStr);
if (StrUtil.isNotBlank(droolStr)) {
Field[] fields = ReflectUtil.getFields(BaseCenter.class);
for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName();
BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.costCenter.getAttribution());
if (ObjectUtil.isNotNull(baseDataEntity)) {
String content = baseDataEntity.getContent();
String contentName = baseDataEntity.getContentName();
droolStr = StrUtil.replace(droolStr, contentName, content, false);
}
String filedValueStr = "";
if (ObjectUtil.isNotNull(fieldValue)) {
filedValueStr = fieldValue.toString();
}
droolStr = StrUtil.replace(droolStr, name, filedValueStr, false);
}
log.info("after - replace4 = {}", droolStr);
JSONArray jsonArray = JSONUtil.parseArray(droolStr);
log.info("jsonArray = {}", jsonArray);
String conditionResult = ConditionParser.parseCondition(jsonArray);
log.info("condition template = {}", conditionResult);
// AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class);
// AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class);
Object executeB = AviatorEvaluator.execute(conditionResult);
log.info("CostCenter02Cmp-{} = {}", conditionResult, executeB);
boolean aBoolean = BooleanUtil.toBoolean(executeB.toString());
log.info("CostCenter02Cmp-aBoolean = {}", aBoolean);
return aBoolean;
} else {
return false;
}
}
}

View File

@ -1,6 +1,6 @@
package com.example.liteflow.mysql.cmp.costCenter; package com.example.liteflow.mysql.cmp.costCenter;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
@ -9,14 +9,14 @@ import cn.hutool.json.JSONUtil;
import com.example.liteflow.mysql.entity.BaseDataEntity; import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum; import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter; import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.model.CostCenter;
import com.example.liteflow.mysql.service.BaseDataService; import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.service.BaseRoleService;
import com.example.liteflow.mysql.util.ConditionParser; import com.example.liteflow.mysql.util.ConditionParser;
import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent; import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists; import org.assertj.core.util.Lists;
import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -26,7 +26,8 @@ import java.util.List;
* @author: 陈韦龙 * @author: 陈韦龙
* @date: 2022年12月05日 10:15 * @date: 2022年12月05日 10:15
*/ */
@LiteflowComponent("costCenterCmp") //@LiteflowComponent("costCenterCmp")
@Component
@Slf4j @Slf4j
public class CostCenterCmp extends NodeIfComponent { public class CostCenterCmp extends NodeIfComponent {
@ -38,38 +39,47 @@ public class CostCenterCmp extends NodeIfComponent {
private static final List<String> businessCategoryList = Lists.newArrayList("全货船业务", "进出岛仓干配"); private static final List<String> businessCategoryList = Lists.newArrayList("全货船业务", "进出岛仓干配");
@Resource @Resource
private BaseDataService baseDataService; private BaseDataService baseDataService;
@Resource
private BaseRoleService baseRoleService;
@Override @Override
public boolean processIf() throws Exception { public boolean processIf() throws Exception {
BaseCenter requestData = this.getRequestData(); BaseCenter requestData = this.getRequestData();
String droolStr = drool; String nodeId = this.getNodeId();
Field[] fields = ReflectUtil.getFields(BaseCenter.class); String nodeName = this.getName();
for (Field field : fields) { log.info("nodeId = {}, nodeName = {}", nodeId, nodeName);
Object fieldValue = ReflectUtil.getFieldValue(requestData, field); String droolStr = baseRoleService.getByName(nodeName);
String name = field.getName(); if (StrUtil.isNotBlank(droolStr)) {
BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.costCenter.getAttribution()); Field[] fields = ReflectUtil.getFields(BaseCenter.class);
if (ObjectUtil.isNotNull(baseDataEntity)) { for (Field field : fields) {
String content = baseDataEntity.getContent(); Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String contentName = baseDataEntity.getContentName(); String name = field.getName();
droolStr = StrUtil.replace(droolStr, contentName, content, false); BaseDataEntity baseDataEntity = baseDataService.getByTypeAndName(name, BaseDataAttributionEnum.costCenter.getAttribution(), name + "List");
if (ObjectUtil.isNotNull(baseDataEntity)) {
String content = baseDataEntity.getContent();
String contentName = baseDataEntity.getContentName();
droolStr = StrUtil.replace(droolStr, contentName, content, false);
}
String filedValueStr = "";
if (ObjectUtil.isNotNull(fieldValue)) {
filedValueStr = fieldValue.toString();
}
droolStr = StrUtil.replace(droolStr, name, filedValueStr, false);
} }
String filedValueStr = "";
if (ObjectUtil.isNotNull(fieldValue)) { log.info("after - droolStr = {}", droolStr);
filedValueStr = fieldValue.toString(); JSONArray jsonArray = JSONUtil.parseArray(droolStr);
} log.info("jsonArray = {}", jsonArray);
droolStr = StrUtil.replace(droolStr, name, filedValueStr, false);
String conditionResult = ConditionParser.parseCondition(jsonArray);
log.info("condition template = {}", conditionResult);
Object executeB = AviatorEvaluator.execute(conditionResult);
log.info("CostCenterCmp-{} = {}", conditionResult, executeB);
boolean aBoolean = BooleanUtil.toBoolean(executeB.toString());
log.info("CostCenterCmp-aBoolean = {}", aBoolean);
return aBoolean;
} else {
return false;
} }
log.info("after - droolStr = {}", droolStr);
JSONArray jsonArray = JSONUtil.parseArray(droolStr);
log.info("jsonArray = {}", jsonArray);
String conditionResult = ConditionParser.parseCondition(jsonArray);
log.info("condition template = {}", conditionResult);
AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class);
AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class);
Object executeB = AviatorEvaluator.execute(conditionResult);
log.info("{} = {}", conditionResult, executeB);
return Boolean.getBoolean(executeB.toString());
} }
} }

View File

@ -3,11 +3,10 @@ package com.example.liteflow.mysql.cmp.costCenter;
import com.example.liteflow.mysql.entity.BaseDataEntity; import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum; import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter; import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.model.CostCenter;
import com.example.liteflow.mysql.service.BaseDataService; import com.example.liteflow.mysql.service.BaseDataService;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -15,9 +14,10 @@ import javax.annotation.Resource;
* @author: 陈韦龙 * @author: 陈韦龙
* @date: 2022年12月05日 10:15 * @date: 2022年12月05日 10:15
*/ */
@LiteflowComponent("CostCenter02SoutCmp") //@LiteflowComponent("CostCenter02SoutCmp")
@Component
@Slf4j @Slf4j
public class CostCenter02SoutCmp extends NodeComponent { public class CostCenterSoutCmp extends NodeComponent {
// private static final String costCenter02Code = "P350401026"; // private static final String costCenter02Code = "P350401026";
// private static final String costCenter02Name = "商品车物流部利润中心"; // private static final String costCenter02Name = "商品车物流部利润中心";
@ -27,14 +27,17 @@ public class CostCenter02SoutCmp extends NodeComponent {
@Override @Override
public void process() { public void process() {
BaseDataEntity codeBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.costCenter.getAttribution(), "costCenter02Code");
BaseDataEntity nameBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.costCenter.getAttribution(), "costCenter02Name");
BaseCenter baseCenter = this.getRequestData(); BaseCenter baseCenter = this.getRequestData();
String costCenter02Code = codeBaseData.getContent(); String nodeId = this.getNodeId();
String costCenter02Name = nameBaseData.getContent(); String nodeName = this.getName();
baseCenter.setCostCenterCode(costCenter02Code); log.info("nodeId = {}, nodeName = {}", nodeId, nodeName);
baseCenter.setCostCenterName(costCenter02Name); BaseDataEntity codeBaseData = baseDataService.getByTypeAndName("costCenterCode", BaseDataAttributionEnum.costCenter.getAttribution(), nodeName);
baseCenter.setCostCenterGenerateCode(costCenter02Code + costCenter02Name); BaseDataEntity nameBaseData = baseDataService.getByTypeAndName("costCenterName", BaseDataAttributionEnum.costCenter.getAttribution(), nodeName);
String costCenterCode = codeBaseData.getContent();
String costCenterName = nameBaseData.getContent();
baseCenter.setCostCenterCode(costCenterCode);
baseCenter.setCostCenterName(costCenterName);
baseCenter.setCostCenterGenerateCode(costCenterCode + costCenterName);
baseCenter.setGenerateCode(null); baseCenter.setGenerateCode(null);
} }

View File

@ -1,79 +0,0 @@
package com.example.liteflow.mysql.cmp.profitCenter;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.service.BaseRoleService;
import com.example.liteflow.mysql.util.ConditionParser;
import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import java.lang.reflect.Field;
/**
* @author: 陈韦龙
* @date: 2022年12月05日 10:15
*/
@LiteflowComponent("profitCenter01Cmp")
@Slf4j
public class ProfitCenter01Cmp extends NodeIfComponent {
@Resource
private BaseDataService baseDataService;
@Resource
private BaseRoleService baseRoleService;
private static final String baseRoleName = "profitCenter01Cmp";
@Override
public boolean processIf() throws Exception {
BaseCenter requestData = this.getRequestData();
String droolStr = baseRoleService.getByName(baseRoleName);
log.info("ProfitCenter01Cmp-droolStr = {}", droolStr);
if (StrUtil.isNotBlank(droolStr)) {
Field[] fields = ReflectUtil.getFields(BaseCenter.class);
for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName();
BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.profitCenter.getAttribution());
if (ObjectUtil.isNotNull(baseDataEntity)) {
String content = baseDataEntity.getContent();
String contentName = baseDataEntity.getContentName();
droolStr = StrUtil.replace(droolStr, contentName, content, false);
}
String filedValueStr = "";
if (ObjectUtil.isNotNull(fieldValue)) {
filedValueStr = fieldValue.toString();
}
droolStr = StrUtil.replace(droolStr, name, filedValueStr, false);
}
log.info("after - droolStr = {}", droolStr);
JSONArray jsonArray = JSONUtil.parseArray(droolStr);
log.info("jsonArray = {}", jsonArray);
String conditionResult = ConditionParser.parseCondition(jsonArray);
log.info("condition template = {}", conditionResult);
// AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class);
// AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class);
Object executeB = AviatorEvaluator.execute(conditionResult);
log.info("ProfitCenter01Cmp-{} = {}", conditionResult, executeB);
boolean aBoolean = BooleanUtil.toBoolean(executeB.toString());
log.info("ProfitCenter01Cmp-aBoolean = {}", aBoolean);
return aBoolean;
} else {
return false;
}
}
}

View File

@ -1,39 +0,0 @@
package com.example.liteflow.mysql.cmp.profitCenter;
import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.service.BaseDataService;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
/**
* @author: 陈韦龙
* @date: 2022年12月05日 10:15
*/
@LiteflowComponent("ProfitCenter01SoutCmp")
@Slf4j
public class ProfitCenter01SoutCmp extends NodeComponent {
// private static final String profitCenter01Code = "P350401029";
// private static final String profitCenter01Name = "仓干配物流部成本中心";
@Resource
private BaseDataService baseDataService;
@Override
public void process() {
BaseDataEntity codeBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.profitCenter.getAttribution(), "profitCenter01Code");
BaseDataEntity nameBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.profitCenter.getAttribution(), "profitCenter01Name");
BaseCenter baseCenter = this.getRequestData();
String profitCenter01Code = codeBaseData.getContent();
String profitCenter01Name = nameBaseData.getContent();
baseCenter.setProfitCenterCode(profitCenter01Code);
baseCenter.setProfitCenterName(profitCenter01Name);
baseCenter.setProfitCenterGenerateCode(profitCenter01Code + profitCenter01Name);
baseCenter.setGenerateCode(null);
}
}

View File

@ -1,79 +0,0 @@
package com.example.liteflow.mysql.cmp.profitCenter;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.service.BaseRoleService;
import com.example.liteflow.mysql.util.ConditionParser;
import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import java.lang.reflect.Field;
/**
* @author: 陈韦龙
* @date: 2022年12月05日 10:15
*/
@LiteflowComponent("profitCenter02Cmp")
@Slf4j
public class ProfitCenter02Cmp extends NodeIfComponent {
@Resource
private BaseDataService baseDataService;
@Resource
private BaseRoleService baseRoleService;
private static final String baseRoleName = "profitCenter02Cmp";
@Override
public boolean processIf() throws Exception {
BaseCenter requestData = this.getRequestData();
String droolStr = baseRoleService.getByName(baseRoleName);
log.info("ProfitCenter02Cmp-droolStr = {}", droolStr);
if (StrUtil.isNotBlank(droolStr)) {
Field[] fields = ReflectUtil.getFields(BaseCenter.class);
for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName();
BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.profitCenter.getAttribution());
if (ObjectUtil.isNotNull(baseDataEntity)) {
String content = baseDataEntity.getContent();
String contentName = baseDataEntity.getContentName();
droolStr = StrUtil.replace(droolStr, contentName, content, false);
}
String filedValueStr = "";
if (ObjectUtil.isNotNull(fieldValue)) {
filedValueStr = fieldValue.toString();
}
droolStr = StrUtil.replace(droolStr, name, filedValueStr, false);
}
log.info("after - droolStr = {}", droolStr);
JSONArray jsonArray = JSONUtil.parseArray(droolStr);
log.info("jsonArray = {}", jsonArray);
String conditionResult = ConditionParser.parseCondition(jsonArray);
log.info("condition template = {}", conditionResult);
// AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class);
// AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class);
Object executeB = AviatorEvaluator.execute(conditionResult);
log.info("CostCenter02Cmp-{} = {}", conditionResult, executeB);
boolean aBoolean = BooleanUtil.toBoolean(executeB.toString());
log.info("CostCenter02Cmp-aBoolean = {}", aBoolean);
return aBoolean;
} else {
return false;
}
}
}

View File

@ -1,42 +0,0 @@
package com.example.liteflow.mysql.cmp.profitCenter;
import cn.hutool.core.util.ObjectUtil;
import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.service.BaseDataService;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
/**
* @author: 陈韦龙
* @date: 2022年12月05日 10:15
*/
@LiteflowComponent("ProfitCenter02SoutCmp")
@Slf4j
public class ProfitCenter02SoutCmp extends NodeComponent {
// private static final String profitCenter02Code = "P350401027";
// private static final String profitCenter02Name = "商品车物流部成本中心";
@Resource
private BaseDataService baseDataService;
@Override
public void process() {
BaseDataEntity codeBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.profitCenter.getAttribution(), "profitCenter02Code");
BaseDataEntity nameBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.profitCenter.getAttribution(), "profitCenter02Name");
BaseCenter baseCenter = this.getRequestData();
if (ObjectUtil.isNotNull(codeBaseData) && ObjectUtil.isNotNull(nameBaseData)) {
String profitCenter02Code = codeBaseData.getContent();
String profitCenter02Name = nameBaseData.getContent();
baseCenter.setProfitCenterCode(profitCenter02Code);
baseCenter.setProfitCenterName(profitCenter02Name);
baseCenter.setProfitCenterGenerateCode(profitCenter02Code + profitCenter02Name);
baseCenter.setGenerateCode(null);
}
}
}

View File

@ -1,6 +1,7 @@
package com.example.liteflow.mysql.cmp.profitCenter; package com.example.liteflow.mysql.cmp.profitCenter;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
@ -10,11 +11,13 @@ import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum; import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter; import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.service.BaseDataService; import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.service.BaseRoleService;
import com.example.liteflow.mysql.util.ConditionParser; import com.example.liteflow.mysql.util.ConditionParser;
import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent; import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -23,46 +26,56 @@ import java.lang.reflect.Field;
* @author: 陈韦龙 * @author: 陈韦龙
* @date: 2022年12月05日 10:15 * @date: 2022年12月05日 10:15
*/ */
@LiteflowComponent("profitCenterCmp") //@LiteflowComponent("profitCenterCmp")
@Component
@Slf4j @Slf4j
public class ProfitCenterCmp extends NodeIfComponent { public class ProfitCenterCmp extends NodeIfComponent {
private static final String drool = "[{\"$or\": [{\"$and\": [{\"$contains\": [sectionClassification, sectionClassificationList]}, {\"$contains\": [businessType, businessTypeList]}, {\"$contains\": [salesman, salesmanList]}, {\"$contains\": [businessCategory, businessCategoryList]}]}]}, {\"$or\": [{\"$or\": [{\"$and\": [{\"$contains\": [sectionClassification, sectionClassificationList]}, {\"$contains\": [salesman, salesmanList]}]}]}, {\"$or\": [{\"$contains\": [businessType, businessTypeList]}]}]}]"; private static final String drool = "[{\"$or\": [{\"$and\": [{\"$contains\": [sectionClassification, sectionClassificationList]}, {\"$contains\": [businessType, businessTypeList]}, {\"$contains\": [salesman, salesmanList]}, {\"$contains\": [businessCategory, businessCategoryList]}]}]}, {\"$or\": [{\"$or\": [{\"$and\": [{\"$contains\": [sectionClassification, sectionClassificationList]}, {\"$contains\": [salesman, salesmanList]}]}]}, {\"$or\": [{\"$contains\": [businessType, businessTypeList]}]}]}]";
@Resource @Resource
private BaseDataService baseDataService; private BaseDataService baseDataService;
@Resource
private BaseRoleService baseRoleService;
@Override @Override
public boolean processIf() throws Exception { public boolean processIf() throws Exception {
BaseCenter requestData = this.getRequestData(); BaseCenter requestData = this.getRequestData();
String droolStr = drool; String nodeId = this.getNodeId();
Field[] fields = ReflectUtil.getFields(BaseCenter.class); String nodeName = this.getName();
for (Field field : fields) { log.info("nodeId = {}, nodeName = {}", nodeId, nodeName);
Object fieldValue = ReflectUtil.getFieldValue(requestData, field); String droolStr = baseRoleService.getByName(nodeName);
String name = field.getName(); if (StrUtil.isNotBlank(droolStr)) {
BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.profitCenter.getAttribution()); Field[] fields = ReflectUtil.getFields(BaseCenter.class);
if (ObjectUtil.isNotNull(baseDataEntity)) { for (Field field : fields) {
String content = baseDataEntity.getContent(); Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String contentName = baseDataEntity.getContentName(); String name = field.getName();
droolStr = StrUtil.replace(droolStr, contentName, content, false); BaseDataEntity baseDataEntity = baseDataService.getByTypeAndName(name, BaseDataAttributionEnum.costCenter.getAttribution(), name + "List");
if (ObjectUtil.isNotNull(baseDataEntity)) {
String content = baseDataEntity.getContent();
String contentName = baseDataEntity.getContentName();
droolStr = StrUtil.replace(droolStr, contentName, content, false);
}
String filedValueStr = "";
if (ObjectUtil.isNotNull(fieldValue)) {
filedValueStr = fieldValue.toString();
}
droolStr = StrUtil.replace(droolStr, name, filedValueStr, false);
} }
String filedValueStr = "";
if (ObjectUtil.isNotNull(fieldValue)) { log.info("after - droolStr = {}", droolStr);
filedValueStr = fieldValue.toString(); JSONArray jsonArray = JSONUtil.parseArray(droolStr);
} log.info("jsonArray = {}", jsonArray);
droolStr = StrUtil.replace(droolStr, name, filedValueStr, false);
String conditionResult = ConditionParser.parseCondition(jsonArray);
log.info("condition template = {}", conditionResult);
Object executeB = AviatorEvaluator.execute(conditionResult);
log.info("ProfitCenterCmp-{} = {}", conditionResult, executeB);
boolean aBoolean = BooleanUtil.toBoolean(executeB.toString());
log.info("ProfitCenterCmp-aBoolean = {}", aBoolean);
return aBoolean;
} else {
return false;
} }
log.info("after - droolStr = {}", droolStr);
JSONArray jsonArray = JSONUtil.parseArray(droolStr);
log.info("jsonArray = {}", jsonArray);
String conditionResult = ConditionParser.parseCondition(jsonArray);
log.info("condition template = {}", conditionResult);
AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class);
AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class);
Object executeB = AviatorEvaluator.execute(conditionResult);
log.info("{} = {}", conditionResult, executeB);
return Boolean.getBoolean(executeB.toString());
} }
} }

View File

@ -0,0 +1,43 @@
package com.example.liteflow.mysql.cmp.profitCenter;
import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.service.BaseDataService;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @author: 陈韦龙
* @date: 2022年12月05日 10:15
*/
@Component
@Slf4j
public class ProfitCenterSoutCmp extends NodeComponent {
// private static final String profitCenter02Code = "P350401026";
// private static final String profitCenter02Name = "商品车物流部利润中心";
@Resource
private BaseDataService baseDataService;
@Override
public void process() {
BaseCenter baseCenter = this.getRequestData();
String nodeId = this.getNodeId();
String nodeName = this.getName();
log.info("nodeId = {}, nodeName = {}", nodeId, nodeName);
BaseDataEntity codeBaseData = baseDataService.getByTypeAndName("profitCenterCode", BaseDataAttributionEnum.profitCenter.getAttribution(), nodeName);
BaseDataEntity nameBaseData = baseDataService.getByTypeAndName("profitCenterName", BaseDataAttributionEnum.profitCenter.getAttribution(), nodeName);
String profitCenterCode = codeBaseData.getContent();
String profitCenterName = nameBaseData.getContent();
baseCenter.setProfitCenterCode(profitCenterCode);
baseCenter.setProfitCenterName(profitCenterName);
baseCenter.setProfitCenterGenerateCode(profitCenterCode + profitCenterName);
baseCenter.setGenerateCode(null);
}
}

View File

@ -26,6 +26,11 @@ public class ChainController {
chainService.createChain(chainEntity); chainService.createChain(chainEntity);
} }
@PostMapping("/dynamicGenerateChain")
public void dynamicGenerateChain(@RequestBody ChainEntity chainEntity) {
chainService.dynamicGenerateChain(chainEntity);
}
@GetMapping("/executeChain/{chainName}") @GetMapping("/executeChain/{chainName}")
public List<BaseCenter> executeChain(@PathVariable("chainName") String chainName) { public List<BaseCenter> executeChain(@PathVariable("chainName") String chainName) {
return chainService.executeChain(chainName); return chainService.executeChain(chainName);

View File

@ -0,0 +1,61 @@
package com.example.liteflow.mysql.controller;
import com.example.liteflow.mysql.model.node.CreateNodeFrom;
import com.example.liteflow.mysql.service.NodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* @author: 陈韦龙
* @date: 2022年12月12日 09:29
*/
@Slf4j
@RestController
@RequestMapping("/node")
public class NodeController {
@Resource
private NodeService nodeService;
@PostMapping("/createCostCenterIfNode")
public void createCostCenterIfNode(@RequestBody CreateNodeFrom createNodeFrom) {
nodeService.createCostCenterIfNode(createNodeFrom);
}
@PostMapping("/batchCreateCostCenterIfNode")
public void batchCreateCostCenterIfNode(@RequestBody List<CreateNodeFrom> createNodeFroms) {
nodeService.batchCreateCostCenterIfNode(createNodeFroms);
}
@PostMapping("/createCostCenterNode")
public void createCostCenterNode(@RequestBody CreateNodeFrom createNodeFrom) {
nodeService.createCostCenterNode(createNodeFrom);
}
@PostMapping("/batchCreateCostCenterNode")
public void batchCreateCostCenterNode(@RequestBody List<CreateNodeFrom> createNodeFroms) {
nodeService.batchCreateCostCenterNode(createNodeFroms);
}
@PostMapping("/createProfitCenterIfNode")
public void createProfitCenterIfNode(@RequestBody CreateNodeFrom createNodeFrom) {
nodeService.createProfitCenterIfNode(createNodeFrom);
}
@PostMapping("/batchCreateProfitCenterIfNode")
public void batchCreateProfitCenterIfNode(@RequestBody List<CreateNodeFrom> createNodeFroms) {
nodeService.batchCreateProfitCenterIfNode(createNodeFroms);
}
@PostMapping("/createProfitCenterNode")
public void createProfitCenterNode(@RequestBody CreateNodeFrom createNodeFrom) {
nodeService.createProfitCenterNode(createNodeFrom);
}
@PostMapping("/batchCreateProfitCostCenterNode")
public void batchCreateProfitCostCenterNode(@RequestBody List<CreateNodeFrom> createNodeFroms) {
nodeService.batchCreateProfitCostCenterNode(createNodeFroms);
}
}

View File

@ -0,0 +1,13 @@
package com.example.liteflow.mysql.model.node;
import lombok.Data;
/**
* @author: 陈韦龙
* @date: 2022年12月12日 09:38
*/
@Data
public class CreateNodeFrom {
private String id;
private String name;
}

View File

@ -12,6 +12,8 @@ import java.util.List;
public interface ChainService { public interface ChainService {
void createChain(ChainEntity chainEntity); void createChain(ChainEntity chainEntity);
void dynamicGenerateChain(ChainEntity chainEntity);
List<BaseCenter> executeChain(String chainName); List<BaseCenter> executeChain(String chainName);
ChainEntity getChainName(String chainName); ChainEntity getChainName(String chainName);

View File

@ -0,0 +1,27 @@
package com.example.liteflow.mysql.service;
import com.example.liteflow.mysql.model.node.CreateNodeFrom;
import java.util.List;
/**
* @author: 陈韦龙
* @date: 2022年12月12日 09:30
*/
public interface NodeService {
void createCostCenterIfNode(CreateNodeFrom createNodeFrom);
void batchCreateCostCenterIfNode(List<CreateNodeFrom> createNodeFroms);
void createCostCenterNode(CreateNodeFrom createNodeFrom);
void batchCreateCostCenterNode(List<CreateNodeFrom> createNodeFroms);
void createProfitCenterIfNode(CreateNodeFrom createNodeFrom);
void batchCreateProfitCenterIfNode(List<CreateNodeFrom> createNodeFroms);
void createProfitCenterNode(CreateNodeFrom createNodeFrom);
void batchCreateProfitCostCenterNode(List<CreateNodeFrom> createNodeFroms);
}

View File

@ -17,7 +17,7 @@ import org.springframework.stereotype.Service;
public class BaseDataServiceImpl extends ServiceImpl<BaseDataMapper, BaseDataEntity> implements BaseDataService { public class BaseDataServiceImpl extends ServiceImpl<BaseDataMapper, BaseDataEntity> implements BaseDataService {
@Override @Override
public BaseDataEntity getByType(String type, String attribution) { public BaseDataEntity getByType(String type, String attribution) {
// log.info("type = {}, attribution = {}", type, attribution); log.info("type = {}, attribution = {}", type, attribution);
LambdaQueryWrapper<BaseDataEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<BaseDataEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(BaseDataEntity::getType, type) queryWrapper.eq(BaseDataEntity::getType, type)
.eq(BaseDataEntity::getAttribution, attribution); .eq(BaseDataEntity::getAttribution, attribution);

View File

@ -1,7 +1,5 @@
package com.example.liteflow.mysql.service.impl; package com.example.liteflow.mysql.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@ -12,6 +10,7 @@ import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.model.CostCenter; import com.example.liteflow.mysql.model.CostCenter;
import com.example.liteflow.mysql.model.ProfitCenter; import com.example.liteflow.mysql.model.ProfitCenter;
import com.example.liteflow.mysql.service.ChainService; import com.example.liteflow.mysql.service.ChainService;
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.flow.LiteflowResponse;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -27,7 +26,7 @@ import java.util.List;
*/ */
@Service @Service
@Slf4j @Slf4j
public class ChainServiceImpl extends ServiceImpl<ChainMapper, ChainEntity> implements ChainService { public class ChainServiceImpl extends ServiceImpl<ChainMapper, ChainEntity> implements ChainService {
@Resource @Resource
private FlowExecutor flowExecutor; private FlowExecutor flowExecutor;
@ -35,6 +34,13 @@ public class ChainServiceImpl extends ServiceImpl<ChainMapper, ChainEntity> imp
@Override @Override
public void createChain(ChainEntity chainEntity) { public void createChain(ChainEntity chainEntity) {
this.save(chainEntity); this.save(chainEntity);
}
@Override
public void dynamicGenerateChain(ChainEntity chainEntity) {
LiteFlowChainELBuilder.createChain()
.setChainId(chainEntity.getChainName())
.setEL(chainEntity.getElData())
.build();
flowExecutor.reloadRule(); flowExecutor.reloadRule();
} }
@ -105,6 +111,7 @@ public class ChainServiceImpl extends ServiceImpl<ChainMapper, ChainEntity> imp
return "删除失败"; return "删除失败";
} }
} }
@Override @Override
public String updateChain(ChainEntity chainEntity) { public String updateChain(ChainEntity chainEntity) {
String id = chainEntity.getId(); String id = chainEntity.getId();

View File

@ -0,0 +1,94 @@
package com.example.liteflow.mysql.service.impl;
import com.example.liteflow.mysql.model.node.CreateNodeFrom;
import com.example.liteflow.mysql.service.NodeService;
import com.yomahub.liteflow.builder.LiteFlowNodeBuilder;
import com.yomahub.liteflow.core.FlowExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* @author: 陈韦龙
* @date: 2022年12月12日 09:30
*/
@Service
@Slf4j
public class NodeServiceImpl implements NodeService {
@Resource
private FlowExecutor flowExecutor;
@Override
public void createCostCenterIfNode(CreateNodeFrom createNodeFrom) {
LiteFlowNodeBuilder.createIfNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.costCenter.CostCenterCmp")
.build();
// flowExecutor.reloadRule();
}
@Override
public void batchCreateCostCenterIfNode(List<CreateNodeFrom> createNodeFroms) {
createNodeFroms.forEach(createNodeFrom -> {
LiteFlowNodeBuilder.createIfNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.costCenter.CostCenterCmp")
.build();
});
}
@Override
public void createCostCenterNode(CreateNodeFrom createNodeFrom) {
LiteFlowNodeBuilder.createCommonNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.costCenter.CostCenterSoutCmp")
.build();
// flowExecutor.reloadRule();
}
@Override
public void batchCreateCostCenterNode(List<CreateNodeFrom> createNodeFroms) {
createNodeFroms.forEach(createNodeFrom -> {
LiteFlowNodeBuilder.createCommonNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.costCenter.CostCenterSoutCmp")
.build();
});
}
@Override
public void createProfitCenterIfNode(CreateNodeFrom createNodeFrom) {
LiteFlowNodeBuilder.createIfNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.profitCenter.ProfitCenterCmp")
.build();
// flowExecutor.reloadRule();
}
@Override
public void batchCreateProfitCenterIfNode(List<CreateNodeFrom> createNodeFroms) {
createNodeFroms.forEach(createNodeFrom -> {
LiteFlowNodeBuilder.createIfNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.profitCenter.ProfitCenterCmp")
.build();
});
}
@Override
public void createProfitCenterNode(CreateNodeFrom createNodeFrom) {
LiteFlowNodeBuilder.createCommonNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.profitCenter .ProfitCenterSoutCmp")
.build();
// flowExecutor.reloadRule();
}
@Override
public void batchCreateProfitCostCenterNode(List<CreateNodeFrom> createNodeFroms) {
createNodeFroms.forEach(createNodeFrom -> {
LiteFlowNodeBuilder.createCommonNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.profitCenter.ProfitCenterSoutCmp")
.build();
});
}
}

View File

@ -59,13 +59,13 @@ 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 ('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 `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 (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 (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 (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 (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 (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 (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'); -- 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');