feat():增加规则策略与代码生成接口
parent
3763f0b9ad
commit
e4bbcea391
|
@ -31,7 +31,7 @@ public class RuleDataAddReq {
|
|||
/**
|
||||
* 规则名称
|
||||
*/
|
||||
@NotEmpty(message = "规则名称不可为空 ")
|
||||
@NotEmpty(message = "规则名称不可为空")
|
||||
@Schema(title = "规则名称" , type = "String",defaultValue = "XX规则"
|
||||
,description = "规则名称一般为类型名称,方便使用者进行区分" ,requiredProperties = {"ruleName"})
|
||||
private String ruleName;
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-rule</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-rule-engine</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>cloud-rule-engine</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-rabbit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataSource -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datascope</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common Log -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 接口模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-api-doc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-rule-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,75 @@
|
|||
package com.muyu.constant;
|
||||
|
||||
import com.muyu.common.domain.RuleData;
|
||||
import com.muyu.common.domain.RuleVersion;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.constant
|
||||
* @Project:cloud-rule
|
||||
* @name:GenerateConstant
|
||||
* @Date:2024/8/30 上午12:49
|
||||
* @Description: 规则引擎版本生成
|
||||
*/
|
||||
@Component
|
||||
public class GenerateConstant {
|
||||
|
||||
public static final String DATA_FIELD = "DataEngineValueActuator";
|
||||
public static final String DATA_RECORD = "DataEngineRecordActuator";
|
||||
public static final String DATA_SET = "DataEngineSetActuator";
|
||||
public static final String ACTION_IMPORT = "import com.muyu.rule.engine.action.ActionDiscard;\n";
|
||||
public static final String SCOPE_IMPORT = "import com.muyu.rule.engine.scope.DataModelEngine";
|
||||
public static final String PACKAGE_PATH = "package com.muyu.generate;";
|
||||
|
||||
public static String getClassName(String versionCode){
|
||||
String[] splits = versionCode.split("_");
|
||||
String className="";
|
||||
for (String split : splits) {
|
||||
className += split.substring(0,1).toUpperCase()+split.substring(1);
|
||||
}
|
||||
return className;
|
||||
}
|
||||
|
||||
public static String generateConstant(RuleData ruleData, RuleVersion ruleVersion){
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
String format = simpleDateFormat.format(new Date());
|
||||
String level = selectType(ruleData.getRuleRegion());
|
||||
return PACKAGE_PATH + "\n" +
|
||||
ACTION_IMPORT + "\n" +
|
||||
SCOPE_IMPORT+level+";\n" +
|
||||
"\n" +
|
||||
"/**\n" +
|
||||
" * @Author: "+ SecurityUtils.getUsername() +"\n" +
|
||||
" * @date: "+format+"\n" +
|
||||
" * @Description: "+ruleVersion.getRuleVersionName()+ruleVersion.getRuleVersionCode()+"\n" +
|
||||
" * @Version: 1.0\n" +
|
||||
" */\n" +
|
||||
"public class "+getClassName(ruleVersion.getRuleVersionType()) + " extends "+level+" {\n" +
|
||||
" @Override\n" +
|
||||
" public void run () {\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
}
|
||||
|
||||
public static String selectType(String level){
|
||||
String type = "";
|
||||
switch (level) {
|
||||
case "F":
|
||||
type = DATA_FIELD;
|
||||
break;
|
||||
case "R":
|
||||
type = DATA_RECORD;
|
||||
break;
|
||||
case "C":
|
||||
type = DATA_SET;
|
||||
break;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,7 +2,6 @@ package com.muyu.engine;
|
|||
|
||||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.engine.basic.BasicEngine;
|
||||
import com.muyu.servier.ENGINE_VALUE_JDIES732842_V1;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -20,7 +19,7 @@ public class Main {
|
|||
|
||||
static {
|
||||
try {
|
||||
Class<?> aClass = Class.forName("com.muyu.servier.ENGINE_VALUE_JDIES732842_V1");
|
||||
Class<?> aClass = Class.forName("com.muyu.server.ENGINE_VALUE_JDIES732842_V1");
|
||||
try {
|
||||
engineMap.put("ENGINE_VALUE_JDIES732842_V1",(BasicEngine<DataValue>) aClass.newInstance());
|
||||
} catch (InstantiationException e) {
|
|
@ -9,6 +9,7 @@ import com.muyu.engine.basic.handler.DataEngineValueHandler;
|
|||
* @Project:cloud-rule
|
||||
* @name:BasicEngin
|
||||
* @Date:2024/8/29 下午3:13
|
||||
* @Description: 规则引擎基准
|
||||
*/
|
||||
public interface BasicEngine<V> {
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.engine.basic.abstracts;
|
||||
|
||||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.engine.basic.BasicEngine;
|
||||
import com.muyu.engine.basic.handler.DataEngineRecordHandler;
|
||||
import com.muyu.engine.basic.handler.DataEngineSetHandler;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.engine.basic.abstracts
|
||||
* @Project:cloud-rule
|
||||
* @name:DataEngineSetActuator
|
||||
* @Date:2024/8/30 上午11:13
|
||||
* @Description: 记录
|
||||
*/
|
||||
public abstract class DataEngineRecordActuator implements BasicEngine<DataValue> {
|
||||
|
||||
public void set(DataValue dataValue){
|
||||
DataEngineRecordHandler.set(dataValue);
|
||||
}
|
||||
|
||||
//获取原始值
|
||||
public DataValue get(){
|
||||
return DataEngineRecordHandler.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execution() {
|
||||
this.run();
|
||||
this.remove();
|
||||
}
|
||||
|
||||
public abstract void run();
|
||||
|
||||
}
|
|
@ -3,7 +3,6 @@ package com.muyu.engine.basic.abstracts;
|
|||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.engine.basic.BasicEngine;
|
||||
import com.muyu.engine.basic.handler.DataEngineRowHandler;
|
||||
import com.muyu.engine.basic.handler.DataEngineValueHandler;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.engine.basic.abstracts;
|
||||
|
||||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.engine.basic.BasicEngine;
|
||||
import com.muyu.engine.basic.handler.DataEngineSetHandler;
|
||||
import com.muyu.engine.basic.handler.DataEngineValueHandler;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.engine.basic.abstracts
|
||||
* @Project:cloud-rule
|
||||
* @name:DataEngineSetActuator
|
||||
* @Date:2024/8/30 上午11:13
|
||||
* @Description: 数据集
|
||||
*/
|
||||
public abstract class DataEngineSetActuator implements BasicEngine<DataValue> {
|
||||
|
||||
public void set(DataValue dataValue){
|
||||
DataEngineSetHandler.set(dataValue);
|
||||
}
|
||||
|
||||
//获取原始值
|
||||
public DataValue get(){
|
||||
return DataEngineSetHandler.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execution() {
|
||||
this.run();
|
||||
this.remove();
|
||||
}
|
||||
|
||||
public abstract void run();
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.engine.basic.handler;
|
||||
|
||||
import com.muyu.common.core.text.Convert;
|
||||
import com.muyu.common.domain.DataValue;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.engine.basic.handler
|
||||
* @Project:cloud-rule
|
||||
* @name:DataEngineValueHandler
|
||||
* @Date:2024/8/29 下午3:21
|
||||
* @Description: 数据值作用域
|
||||
*/
|
||||
public class DataEngineRecordHandler {
|
||||
|
||||
public static void set(DataValue dataValue){
|
||||
DataEngineHandler.set(dataValue);
|
||||
}
|
||||
|
||||
public static DataValue get(){
|
||||
return DataEngineHandler.get();
|
||||
}
|
||||
|
||||
public static void remove(){
|
||||
DataEngineHandler.remove();
|
||||
}
|
||||
|
||||
public static Object getValue(){
|
||||
return get().getValue();
|
||||
}
|
||||
|
||||
public static Integer getIntegerValue(){
|
||||
return Convert.toInt(getValue(),null);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package com.muyu.engine.basic.handler;
|
||||
|
||||
import com.muyu.common.core.text.Convert;
|
||||
import com.muyu.common.domain.DataValue;
|
||||
|
||||
/**
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.engine.basic.handler;
|
||||
|
||||
import com.muyu.common.core.text.Convert;
|
||||
import com.muyu.common.domain.DataValue;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.engine.basic.handler
|
||||
* @Project:cloud-rule
|
||||
* @name:DataEngineValueHandler
|
||||
* @Date:2024/8/29 下午3:21
|
||||
* @Description: 数据值作用域
|
||||
*/
|
||||
public class DataEngineSetHandler {
|
||||
|
||||
public static void set(DataValue dataValue){
|
||||
DataEngineHandler.set(dataValue);
|
||||
}
|
||||
|
||||
public static DataValue get(){
|
||||
return DataEngineHandler.get();
|
||||
}
|
||||
|
||||
public static void remove(){
|
||||
DataEngineHandler.remove();
|
||||
}
|
||||
|
||||
public static Object getValue(){
|
||||
return get().getValue();
|
||||
}
|
||||
|
||||
public static Integer getIntegerValue(){
|
||||
return Convert.toInt(getValue(),null);
|
||||
}
|
||||
|
||||
}
|
|
@ -9,7 +9,7 @@ import com.muyu.common.domain.DataValue;
|
|||
* @Project:cloud-rule
|
||||
* @name:DataEngineValueHandler
|
||||
* @Date:2024/8/29 下午3:21
|
||||
* @Description: 数据自作用域
|
||||
* @Description: 数据值作用域
|
||||
*/
|
||||
public class DataEngineValueHandler {
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
package com.muyu.servier;
|
||||
package com.muyu.server;
|
||||
|
||||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.engine.basic.abstracts.DataEngineValueActuator;
|
||||
import com.muyu.engine.basic.handler.DataEngineValueHandler;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
|
@ -0,0 +1,38 @@
|
|||
package com.muyu;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
|
@ -81,6 +81,11 @@
|
|||
<artifactId>cloud-rule-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-rule-engine</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.muyu.servier.RuleVersionService;
|
|||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -25,6 +26,7 @@ import java.util.List;
|
|||
* @name:RuleVersionController
|
||||
* @Date:2024/8/27 上午11:42
|
||||
*/
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/ruleVersion")
|
||||
@Tag(name = "规则版本控制层",description = "进行版本制定,查看等操作")
|
||||
|
@ -110,4 +112,19 @@ public class RuleVersionController {
|
|||
return Result.success(null,"操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成规则版本代码
|
||||
* @param ruleVersion
|
||||
* @return 生成结果
|
||||
*/
|
||||
@PostMapping("/generatedCode")
|
||||
@Operation(summary = "生成规则版本代码",description = "通过名称和编码生成版本类")
|
||||
public Result<RuleVersion> generatedCode(
|
||||
@Validated @RequestBody RuleVersion ruleVersion
|
||||
){
|
||||
return Result.success(ruleVersionService.generatedCode(ruleVersion));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -28,4 +28,6 @@ public interface RuleVersionService extends IService<RuleVersion> {
|
|||
* @param activate 状态 SysIsYesNo
|
||||
*/
|
||||
public void settingVersionActivate(Long ruleVersionId, String activate);
|
||||
|
||||
RuleVersion generatedCode(RuleVersion ruleVersion);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,9 @@ import com.muyu.common.domain.RuleData;
|
|||
import com.muyu.common.domain.RuleVersion;
|
||||
import com.muyu.common.domain.req.RuleVersionUpdReq;
|
||||
import com.muyu.common.domain.resp.RuleVersionResp;
|
||||
import com.muyu.constant.GenerateConstant;
|
||||
import com.muyu.mapper.RuleVersionMapper;
|
||||
import com.muyu.servier.RuleDataService;
|
||||
import com.muyu.servier.RuleVersionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -29,6 +31,7 @@ public class RuleVersionServiceImpl
|
|||
implements RuleVersionService {
|
||||
|
||||
@Autowired private RuleVersionMapper ruleVersionMapper;
|
||||
@Autowired private RuleDataService ruleDataService;
|
||||
|
||||
@Override
|
||||
public List<RuleVersionResp> selectList(Long ruleId) {
|
||||
|
@ -68,4 +71,12 @@ public class RuleVersionServiceImpl
|
|||
this.update(updateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuleVersion generatedCode(RuleVersion ruleVersion) {
|
||||
RuleData ruleData = ruleDataService.getById(ruleVersion.getRuleId());
|
||||
ruleVersion.setRuleVersionType("generate"+"_"+ruleData.getRuleCoding()+"_"+ruleVersion.getRuleVersionCode());
|
||||
ruleVersion.setRuleVersionText(GenerateConstant.generateConstant(ruleData,ruleVersion));
|
||||
return ruleVersion;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue