Merge remote-tracking branch 'origin/master'

This commit is contained in:
2026-05-21 14:12:36 +08:00
18 changed files with 2566 additions and 167 deletions

5
.gitignore vendored
View File

@@ -53,6 +53,11 @@ nbdist/
!*/build/*.xml
modeler/pnpm-lock.yaml
# Application configuration files (may contain sensitive info)
**/application.yml
**/application-*.yml
!**/application-example.yml
######################################################################
# Mock bundled cache files
**/*.bundled_*.mjs

View File

@@ -97,7 +97,7 @@ public class FireRuleController extends BaseController {
/**
* 开始执行规则匹配
* @param task 敌方参数
* @return
* @return
*/
@PostMapping("/rule")
@ApiOperation("开始执行规则匹配")

View File

@@ -5,10 +5,13 @@ import com.solution.common.core.controller.BaseController;
import com.solution.common.core.domain.AjaxResult;
import com.solution.common.core.page.TableDataInfo;
import com.solution.common.enums.BusinessType;
import com.solution.common.utils.poi.ExcelUtil;
import com.solution.rule.domain.Rule;
import com.solution.rule.domain.config.RuleConfig;
import com.solution.rule.domain.config.RuleConfigExcelRow;
import com.solution.rule.domain.config.RuleConfigQuery;
import com.solution.rule.domain.config.RuleParamMeta;
import com.solution.rule.domain.config.vo.RuleDecisionTreeVO;
import com.solution.rule.domain.config.vo.RuleFourBlocksGraphVO;
import com.solution.rule.domain.config.vo.RuleGraphVO;
import com.solution.rule.service.IRuleService;
@@ -18,7 +21,9 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@Api("红蓝对抗规则管理")
@@ -89,6 +94,16 @@ import java.util.List;
return success(graph);
}
@PreAuthorize("@ss.hasPermi('system:rule:list')")
@GetMapping("/config/decision-tree")
@ApiOperation("规则决策树(围绕装备/目标/阵位/航迹四类规则,展示参数进入后的决策路径)")
public AjaxResult configDecisionTree(RuleConfigQuery query) {
startPage();
List<RuleConfig> list = ruleConfigService.selectRuleConfigList(query);
RuleDecisionTreeVO tree = ruleConfigService.buildDecisionTree(list);
return success(tree);
}
@PreAuthorize("@ss.hasPermi('system:rule:list')")
@GetMapping("/config/graph/four-blocks")
@ApiOperation("四块规则知识图谱(装备/目标/阵位/航迹;参数值与运行时 globalParams 一致)")
@@ -142,4 +157,26 @@ import java.util.List;
List<RuleParamMeta> metas = ruleConfigService.selectParamMetaList();
return success(metas);
}
}
@PreAuthorize("@ss.hasPermi('system:rule:query')")
@Log(title = "Rule Config", businessType = BusinessType.EXPORT)
@PostMapping("/config/export")
@ApiOperation("Export rule config")
public void exportConfig(HttpServletResponse response, @RequestBody(required = false) RuleConfigQuery query) {
List<RuleConfigExcelRow> rows = ruleConfigService.exportRuleConfigRows(query == null ? new RuleConfigQuery() : query);
ExcelUtil<RuleConfigExcelRow> util = new ExcelUtil<>(RuleConfigExcelRow.class);
util.exportExcel(response, rows, "rule-config");
}
@PreAuthorize("@ss.hasPermi('system:rule:edit')")
@Log(title = "Rule Config", businessType = BusinessType.IMPORT)
@PostMapping("/config/importData")
@ApiOperation("Import rule config")
public AjaxResult importConfig(MultipartFile file,
@RequestParam(value = "updateSupport", defaultValue = "true") boolean updateSupport) throws Exception {
ExcelUtil<RuleConfigExcelRow> util = new ExcelUtil<>(RuleConfigExcelRow.class);
List<RuleConfigExcelRow> rows = util.importExcel(file.getInputStream());
String result = ruleConfigService.importRuleConfigRows(rows, updateSupport);
return success(result);
}
}

View File

@@ -32,7 +32,7 @@ public class Nodeparameter extends BaseEntity
@Excel(name = "节点实例设置的具体参数值 (覆盖模板默认值)")
private String value;
private int groupIndex;
private Integer groupIndex;
public void setId(Long id)
{
@@ -48,6 +48,14 @@ public class Nodeparameter extends BaseEntity
return treeId;
}
public Integer getGroupIndex() {
return groupIndex;
}
public void setGroupIndex(Integer groupIndex) {
this.groupIndex = groupIndex;
}
public void setTreeId(Long treeId) {
this.treeId = treeId;
}
@@ -82,13 +90,6 @@ public class Nodeparameter extends BaseEntity
return value;
}
public int getGroupIndex() {
return groupIndex;
}
public void setGroupIndex(int groupIndex) {
this.groupIndex = groupIndex;
}
@Override
public String toString() {

View File

@@ -0,0 +1,65 @@
package com.solution.rule.domain.config;
import com.solution.common.annotation.Excel;
import lombok.Data;
@Data
public class RuleConfigExcelRow {
@Excel(name = "规则编码")
private String ruleCode;
@Excel(name = "规则名称")
private String ruleName;
@Excel(name = "层级编码")
private String levelCode;
@Excel(name = "类别编码")
private String kindCode;
@Excel(name = "模块编码")
private String moduleCode;
@Excel(name = "优先级", cellType = Excel.ColumnType.NUMERIC)
private Integer priorityNo;
@Excel(name = "条件表达式", width = 24)
private String conditionExpr;
@Excel(name = "动作表达式", width = 24)
private String actionExpr;
@Excel(name = "版本号", cellType = Excel.ColumnType.NUMERIC)
private Integer versionNo;
@Excel(name = "规则启用", cellType = Excel.ColumnType.NUMERIC, prompt = "1=启用,0=停用")
private Integer enabled;
@Excel(name = "备注", width = 20)
private String remark;
@Excel(name = "任务类型列表", width = 20, prompt = "多个任务类型用英文逗号分隔")
private String taskTypesCsv;
@Excel(name = "参数名称")
private String paramName;
@Excel(name = "参数键")
private String paramKey;
@Excel(name = "参数值", width = 24)
private String paramVal;
@Excel(name = "参数值类型")
private String valType;
@Excel(name = "参数排序", cellType = Excel.ColumnType.NUMERIC)
private Integer sortNo;
@Excel(name = "参数启用", cellType = Excel.ColumnType.NUMERIC, prompt = "1=启用,0=停用")
private Integer paramEnabled;
@Excel(name = "参数备注", width = 20)
private String paramRemark;
}

View File

@@ -0,0 +1,39 @@
package com.solution.rule.domain.config.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@Data
@ApiModel("单个规则决策树分块")
public class RuleDecisionBlockVO implements Serializable {
@ApiModelProperty("分块标识:equipment/target/position/track")
private String blockId;
@ApiModelProperty("模块编码")
private String moduleCode;
@ApiModelProperty("标题")
private String title;
@ApiModelProperty("Drools 规则名")
private String droolsRuleName;
@ApiModelProperty("salience")
private Integer salience;
@ApiModelProperty("树节点")
private List<RuleDecisionNodeVO> nodes;
public List<RuleDecisionNodeVO> safeNodes() {
if (nodes == null) {
nodes = new ArrayList<>();
}
return nodes;
}
}

View File

@@ -0,0 +1,39 @@
package com.solution.rule.domain.config.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@Data
@ApiModel("规则决策树节点")
public class RuleDecisionNodeVO implements Serializable {
@ApiModelProperty("节点唯一键")
private String key;
@ApiModelProperty("节点标题")
private String title;
@ApiModelProperty("节点类型")
private String nodeType;
@ApiModelProperty("补充说明")
private String description;
@ApiModelProperty("右侧值文本")
private String valueText;
@ApiModelProperty("子节点")
private List<RuleDecisionNodeVO> children;
public List<RuleDecisionNodeVO> safeChildren() {
if (children == null) {
children = new ArrayList<>();
}
return children;
}
}

View File

@@ -0,0 +1,36 @@
package com.solution.rule.domain.config.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@Data
@ApiModel("规则决策树")
public class RuleDecisionTreeVO implements Serializable {
@ApiModelProperty("与运行时 globalParams 一致的参数快照")
private Map<String, Object> globalParamsPreview;
@ApiModelProperty("四大规则分块")
private List<RuleDecisionBlockVO> blocks;
public Map<String, Object> safeGlobalParamsPreview() {
if (globalParamsPreview == null) {
globalParamsPreview = new LinkedHashMap<>();
}
return globalParamsPreview;
}
public List<RuleDecisionBlockVO> safeBlocks() {
if (blocks == null) {
blocks = new ArrayList<>();
}
return blocks;
}
}

View File

@@ -1,9 +1,11 @@
package com.solution.rule.service;
import com.solution.rule.domain.config.RuleConfig;
import com.solution.rule.domain.config.RuleConfigExcelRow;
import com.solution.rule.domain.config.RuleConfigQuery;
import com.solution.rule.domain.config.RuleDictItem;
import com.solution.rule.domain.config.RuleParamMeta;
import com.solution.rule.domain.config.vo.RuleDecisionTreeVO;
import com.solution.rule.domain.config.vo.RuleFourBlocksGraphVO;
import com.solution.rule.domain.config.vo.RuleGraphVO;
@@ -28,11 +30,17 @@ public interface IRuleConfigService {
List<RuleParamMeta> selectParamMetaList();
List<RuleConfigExcelRow> exportRuleConfigRows(RuleConfigQuery query);
String importRuleConfigRows(List<RuleConfigExcelRow> rows, boolean updateSupport);
/**
* 根据当前页规则主数据构建知识图谱(节点与边),参数与任务类型从库批量加载。
*/
RuleGraphVO buildKnowledgeGraph(List<RuleConfig> ruleConfigs);
RuleDecisionTreeVO buildDecisionTree(List<RuleConfig> ruleConfigs);
/**
* 四块规则知识图谱(装备/目标/阵位/航迹):中枢 If/Then + 环形参数,参数值与 {@link #loadEnabledGlobalParams()} 一致。
*/

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.solution.common.constant.ExceptionConstants;
import com.solution.rule.domain.config.RuleConfig;
import com.solution.rule.domain.config.RuleConfigExcelRow;
import com.solution.rule.domain.config.RuleConfigParam;
import com.solution.rule.domain.config.RuleConfigQuery;
import com.solution.rule.domain.config.RuleConfigTaskTypeRow;
@@ -13,6 +14,9 @@ import com.solution.rule.domain.config.graph.RuleFourBlockDefinition;
import com.solution.rule.domain.config.graph.RuleFourBlockRuleOutputCatalog;
import com.solution.rule.domain.config.graph.RuleParamOutputHint;
import com.solution.rule.domain.config.vo.RuleFourBlockClusterVO;
import com.solution.rule.domain.config.vo.RuleDecisionBlockVO;
import com.solution.rule.domain.config.vo.RuleDecisionNodeVO;
import com.solution.rule.domain.config.vo.RuleDecisionTreeVO;
import com.solution.rule.domain.config.vo.RuleFourBlockParamRowVO;
import com.solution.rule.domain.config.vo.RuleFourBlocksGraphVO;
import com.solution.rule.domain.config.vo.RuleGraphEdgeVO;
@@ -131,6 +135,118 @@ public class RuleConfigServiceImpl implements IRuleConfigService {
return new ArrayList<>(metaMap().values());
}
@Override
public List<RuleConfigExcelRow> exportRuleConfigRows(RuleConfigQuery query) {
List<RuleConfig> configs = selectRuleConfigList(query == null ? new RuleConfigQuery() : query);
List<RuleConfigExcelRow> rows = new ArrayList<>();
for (RuleConfig config : configs) {
if (config == null || ObjectUtil.isEmpty(config.getRuleCode())) {
continue;
}
RuleConfig detail = selectRuleConfigByCode(config.getRuleCode());
if (detail == null) {
continue;
}
List<RuleConfigParam> params = CollUtil.isNotEmpty(detail.getParams()) ? detail.getParams() : Collections.singletonList(new RuleConfigParam());
String taskTypesCsv = joinTaskTypes(detail.getTaskTypes());
for (RuleConfigParam param : params) {
RuleConfigExcelRow row = new RuleConfigExcelRow();
row.setRuleCode(detail.getRuleCode());
row.setRuleName(detail.getRuleName());
row.setLevelCode(detail.getLevelCode());
row.setKindCode(detail.getKindCode());
row.setModuleCode(detail.getModuleCode());
row.setPriorityNo(detail.getPriorityNo());
row.setConditionExpr(detail.getConditionExpr());
row.setActionExpr(detail.getActionExpr());
row.setVersionNo(detail.getVersionNo());
row.setEnabled(detail.getEnabled());
row.setRemark(detail.getRemark());
row.setTaskTypesCsv(taskTypesCsv);
if (param != null) {
row.setParamName(param.getParamName());
row.setParamKey(param.getParamKey());
row.setParamVal(param.getParamVal());
row.setValType(param.getValType());
row.setSortNo(param.getSortNo());
row.setParamEnabled(param.getEnabled());
row.setParamRemark(param.getRemark());
}
rows.add(row);
}
}
return rows;
}
@Override
@Transactional(rollbackFor = Exception.class)
public String importRuleConfigRows(List<RuleConfigExcelRow> rows, boolean updateSupport) {
if (CollUtil.isEmpty(rows)) {
throw new RuntimeException("Import data cannot be empty");
}
Map<String, RuleConfig> grouped = new LinkedHashMap<>();
for (RuleConfigExcelRow row : rows) {
if (row == null || isEmptyImportRow(row)) {
continue;
}
String ruleCode = trimmed(row.getRuleCode());
if (ObjectUtil.isEmpty(ruleCode)) {
throw new RuntimeException("Import failed: ruleCode is required");
}
RuleConfig config = grouped.computeIfAbsent(ruleCode, code -> {
RuleConfig rc = new RuleConfig();
rc.setRuleCode(code);
rc.setParams(new ArrayList<>());
rc.setTaskTypes(new ArrayList<>());
return rc;
});
mergeRuleBase(config, row);
if (ObjectUtil.isNotEmpty(trimmed(row.getParamKey()))) {
RuleConfigParam param = new RuleConfigParam();
param.setRuleCode(ruleCode);
param.setParamName(trimmed(row.getParamName()));
param.setParamKey(trimmed(row.getParamKey()));
param.setParamVal(trimmed(row.getParamVal()));
param.setValType(trimmed(row.getValType()));
param.setSortNo(row.getSortNo());
param.setEnabled(row.getParamEnabled());
param.setRemark(trimmed(row.getParamRemark()));
config.getParams().add(param);
}
}
if (grouped.isEmpty()) {
throw new RuntimeException("Import data cannot be empty");
}
int inserted = 0;
int updated = 0;
for (RuleConfig config : grouped.values()) {
fillImportDefaults(config);
validateBase(config);
if (CollUtil.isEmpty(config.getParams())) {
throw new RuntimeException("Rule " + config.getRuleCode() + " must contain at least one param row");
}
boolean exists = ruleConfigMapper.countByRuleCode(config.getRuleCode()) > 0;
if (exists) {
if (!updateSupport) {
throw new RuntimeException("Rule already exists: " + config.getRuleCode());
}
ruleConfigMapper.updateRuleConfig(fillDefault(config));
String[] ruleCodes = {config.getRuleCode()};
ruleConfigMapper.deleteParamsByRuleCodes(ruleCodes);
ruleConfigMapper.deleteTaskTypesByRuleCodes(ruleCodes);
saveChildren(config);
updated++;
} else {
ruleConfigMapper.insertRuleConfig(fillDefault(config));
saveChildren(config);
inserted++;
}
}
syncDrlAfterCrud();
return "Import completed. inserted=" + inserted + ", updated=" + updated;
}
@Override
public RuleGraphVO buildKnowledgeGraph(List<RuleConfig> ruleConfigs) {
RuleGraphVO graph = new RuleGraphVO();
@@ -276,6 +392,58 @@ public class RuleConfigServiceImpl implements IRuleConfigService {
return graph;
}
@Override
public RuleDecisionTreeVO buildDecisionTree(List<RuleConfig> ruleConfigs) {
RuleDecisionTreeVO out = new RuleDecisionTreeVO();
Map<String, Object> globalPreview = loadEnabledGlobalParams();
out.setGlobalParamsPreview(new LinkedHashMap<>(globalPreview));
List<RuleConfig> source = ruleConfigs != null ? ruleConfigs : Collections.emptyList();
List<String> ruleCodes = source.stream()
.filter(r -> r != null && ObjectUtil.isNotEmpty(r.getRuleCode()))
.map(RuleConfig::getRuleCode)
.distinct()
.collect(Collectors.toList());
Map<String, List<RuleConfigParam>> paramsByRule = ruleCodes.isEmpty()
? new LinkedHashMap<>()
: ruleConfigMapper.selectParamsByRuleCodes(ruleCodes).stream()
.filter(p -> p != null && ObjectUtil.isNotEmpty(p.getRuleCode()))
.collect(Collectors.groupingBy(RuleConfigParam::getRuleCode, LinkedHashMap::new, Collectors.toList()));
Map<String, List<String>> taskTypesByRule = new LinkedHashMap<>();
if (!ruleCodes.isEmpty()) {
List<RuleConfigTaskTypeRow> taskRows = ruleConfigMapper.selectTaskTypesByRuleCodes(ruleCodes);
for (RuleConfigTaskTypeRow row : taskRows) {
if (row == null || ObjectUtil.isEmpty(row.getRuleCode()) || ObjectUtil.isEmpty(row.getTaskTypeCode())) {
continue;
}
taskTypesByRule.computeIfAbsent(row.getRuleCode(), k -> new ArrayList<>()).add(row.getTaskTypeCode());
}
}
Map<String, List<RuleConfig>> byModule = source.stream()
.filter(r -> r != null && ObjectUtil.isNotEmpty(r.getModuleCode()))
.collect(Collectors.groupingBy(RuleConfig::getModuleCode, LinkedHashMap::new, Collectors.toList()));
List<RuleDecisionBlockVO> blocks = new ArrayList<>();
for (RuleFourBlockDefinition def : RuleFourBlockDefinition.ordered()) {
List<RuleConfig> moduleRules = new ArrayList<>(byModule.getOrDefault(def.getModuleCode(), Collections.emptyList()));
moduleRules.sort(Comparator.comparing(RuleConfig::getPriorityNo, Comparator.nullsLast(Integer::compareTo)));
RuleDecisionBlockVO block = new RuleDecisionBlockVO();
block.setBlockId(def.getBlockId());
block.setModuleCode(def.getModuleCode());
block.setTitle(def.getDroolsRuleName());
block.setDroolsRuleName(def.getDroolsRuleName());
block.setSalience(def.getSalience());
block.setNodes(buildDecisionBlockNodes(def, moduleRules, paramsByRule, taskTypesByRule, globalPreview));
blocks.add(block);
}
out.setBlocks(blocks);
return out;
}
@Override
public RuleFourBlocksGraphVO buildFourBlocksKnowledgeGraph() {
RuleFourBlocksGraphVO out = new RuleFourBlocksGraphVO();
@@ -333,6 +501,272 @@ public class RuleConfigServiceImpl implements IRuleConfigService {
return out;
}
private List<RuleDecisionNodeVO> buildDecisionBlockNodes(RuleFourBlockDefinition def,
List<RuleConfig> moduleRules,
Map<String, List<RuleConfigParam>> paramsByRule,
Map<String, List<String>> taskTypesByRule,
Map<String, Object> globalPreview) {
List<RuleDecisionNodeVO> nodes = new ArrayList<>();
nodes.add(buildDecisionInputNode(def, moduleRules, paramsByRule, globalPreview));
nodes.add(buildDecisionStepNode(def));
nodes.add(buildDecisionRulesNode(def, moduleRules, paramsByRule, taskTypesByRule, globalPreview));
nodes.add(buildDecisionOutcomeNode(def, moduleRules, paramsByRule, globalPreview));
return nodes;
}
private RuleDecisionNodeVO buildDecisionInputNode(RuleFourBlockDefinition def,
List<RuleConfig> moduleRules,
Map<String, List<RuleConfigParam>> paramsByRule,
Map<String, Object> globalPreview) {
RuleDecisionNodeVO root = decisionNode(
"decision:" + def.getBlockId() + ":input",
"输入参数",
"input_group",
"当前块启用参数会先进入 globalParams,再被规则与 Java 算子读取",
"共 " + countEnabledParams(moduleRules, paramsByRule) + " 个");
Map<String, RuleDecisionNodeVO> uniqueByKey = new LinkedHashMap<>();
for (RuleConfig rule : moduleRules) {
if (rule == null || ObjectUtil.isEmpty(rule.getRuleCode())) {
continue;
}
List<RuleConfigParam> plist = paramsByRule.getOrDefault(rule.getRuleCode(), Collections.emptyList());
for (RuleConfigParam param : plist) {
if (param == null || ObjectUtil.isEmpty(param.getParamKey())) {
continue;
}
if (param.getEnabled() != null && param.getEnabled() == 0) {
continue;
}
uniqueByKey.computeIfAbsent(param.getParamKey(), key -> {
RuleParamMeta meta = resolveMeta(key);
Object effective = globalPreview.get(key);
String description = meta != null && ObjectUtil.isNotEmpty(meta.getDescription())
? meta.getDescription()
: "由命中的规则参数写入运行时参数池";
String valueText = "生效值: " + String.valueOf(effective != null ? effective : param.getParamVal());
return decisionNode(
"decision:" + def.getBlockId() + ":input:" + key,
ObjectUtil.defaultIfBlank(param.getParamName(), key),
"input_param",
description,
valueText);
});
}
}
if (uniqueByKey.isEmpty()) {
root.safeChildren().add(decisionNode(
"decision:" + def.getBlockId() + ":input:empty",
"当前没有启用参数",
"empty",
"导入或新增参数后,这里会展示参与该块运算的参数",
null));
} else {
root.safeChildren().addAll(uniqueByKey.values());
}
return root;
}
private RuleDecisionNodeVO buildDecisionStepNode(RuleFourBlockDefinition def) {
RuleDecisionNodeVO root = decisionNode(
"decision:" + def.getBlockId() + ":steps",
"运算步骤",
"step_group",
"展示该规则块在运算中的主路径",
"salience=" + def.getSalience());
List<String> steps = def.getComputationSteps();
for (int i = 0; i < steps.size(); i++) {
String step = steps.get(i);
root.safeChildren().add(decisionNode(
"decision:" + def.getBlockId() + ":step:" + i,
"步骤 " + (i + 1),
"step",
step,
null));
}
return root;
}
private RuleDecisionNodeVO buildDecisionRulesNode(RuleFourBlockDefinition def,
List<RuleConfig> moduleRules,
Map<String, List<RuleConfigParam>> paramsByRule,
Map<String, List<String>> taskTypesByRule,
Map<String, Object> globalPreview) {
RuleDecisionNodeVO root = decisionNode(
"decision:" + def.getBlockId() + ":rules",
"规则链",
"rule_group",
"按优先级展示该块会如何判断、读取参数并产生产出",
"共 " + moduleRules.size() + " 条");
if (CollUtil.isEmpty(moduleRules)) {
root.safeChildren().add(decisionNode(
"decision:" + def.getBlockId() + ":rules:empty",
"当前没有规则项",
"empty",
"该块暂无可展示的规则配置",
null));
return root;
}
for (RuleConfig rule : moduleRules) {
if (rule == null || ObjectUtil.isEmpty(rule.getRuleCode())) {
continue;
}
String ruleCode = rule.getRuleCode();
RuleDecisionNodeVO ruleNode = decisionNode(
"decision:" + def.getBlockId() + ":rule:" + ruleCode,
ObjectUtil.defaultIfBlank(rule.getRuleName(), ruleCode),
"rule",
ObjectUtil.defaultIfBlank(rule.getRemark(), "根据条件命中后执行当前规则"),
"优先级 " + String.valueOf(rule.getPriorityNo() != null ? rule.getPriorityNo() : "-"));
ruleNode.safeChildren().add(decisionNode(
"decision:" + def.getBlockId() + ":rule:" + ruleCode + ":condition",
"命中条件",
"condition",
ObjectUtil.defaultIfBlank(rule.getConditionExpr(), def.getWhenExpr()),
null));
List<String> taskTypes = taskTypesByRule.getOrDefault(ruleCode, Collections.emptyList());
ruleNode.safeChildren().add(decisionNode(
"decision:" + def.getBlockId() + ":rule:" + ruleCode + ":task-types",
"适用任务",
"task_types",
taskTypes.isEmpty() ? "未单独限定任务类型" : joinTaskTypes(taskTypes),
taskTypes.isEmpty() ? "全部/默认" : "共 " + taskTypes.size() + " 类"));
RuleDecisionNodeVO paramGroup = decisionNode(
"decision:" + def.getBlockId() + ":rule:" + ruleCode + ":params",
"读取参数",
"param_group",
"规则命中后会读取这些参数参与计算",
null);
List<RuleConfigParam> plist = new ArrayList<>(paramsByRule.getOrDefault(ruleCode, Collections.emptyList()));
plist.sort(Comparator
.comparing((RuleConfigParam p) -> p.getSortNo() == null ? Integer.MAX_VALUE : p.getSortNo())
.thenComparing(RuleConfigParam::getParamKey, Comparator.nullsLast(String::compareTo)));
for (RuleConfigParam param : plist) {
if (param == null || ObjectUtil.isEmpty(param.getParamKey())) {
continue;
}
if (param.getEnabled() != null && param.getEnabled() == 0) {
continue;
}
String key = param.getParamKey();
RuleParamMeta meta = resolveMeta(key);
String desc = meta != null && ObjectUtil.isNotEmpty(meta.getDescription())
? meta.getDescription()
: RuleParamOutputHint.effectLine(key, def.getModuleCode());
Object effective = globalPreview.get(key);
paramGroup.safeChildren().add(decisionNode(
"decision:" + def.getBlockId() + ":rule:" + ruleCode + ":param:" + key,
ObjectUtil.defaultIfBlank(param.getParamName(), key),
"param",
desc,
"参数键=" + key + ";生效值=" + String.valueOf(effective != null ? effective : param.getParamVal())));
}
if (CollUtil.isEmpty(paramGroup.getChildren())) {
paramGroup.safeChildren().add(decisionNode(
"decision:" + def.getBlockId() + ":rule:" + ruleCode + ":params:empty",
"无参数",
"empty",
"当前规则未配置可展示参数",
null));
}
ruleNode.safeChildren().add(paramGroup);
RuleDecisionNodeVO outputGroup = decisionNode(
"decision:" + def.getBlockId() + ":rule:" + ruleCode + ":outputs",
"产出结果",
"output_group",
ObjectUtil.defaultIfBlank(rule.getActionExpr(), def.getThenAction()),
null);
List<String> outputs = RuleFourBlockRuleOutputCatalog.outputsForRule(def.getModuleCode(), ruleCode);
if (CollUtil.isEmpty(outputs)) {
outputGroup.safeChildren().add(decisionNode(
"decision:" + def.getBlockId() + ":rule:" + ruleCode + ":outputs:default",
"执行块运算",
"output",
def.getThenAction(),
"写入结果对象"));
} else {
for (int i = 0; i < outputs.size(); i++) {
outputGroup.safeChildren().add(decisionNode(
"decision:" + def.getBlockId() + ":rule:" + ruleCode + ":output:" + i,
"结果 " + (i + 1),
"output",
outputs.get(i),
null));
}
}
ruleNode.safeChildren().add(outputGroup);
root.safeChildren().add(ruleNode);
}
return root;
}
private RuleDecisionNodeVO buildDecisionOutcomeNode(RuleFourBlockDefinition def,
List<RuleConfig> moduleRules,
Map<String, List<RuleConfigParam>> paramsByRule,
Map<String, Object> globalPreview) {
RuleDecisionNodeVO root = decisionNode(
"decision:" + def.getBlockId() + ":outcome",
"最终结果",
"outcome_group",
"汇总该块在命中规则后可能产出的业务结果",
null);
LinkedHashSet<String> lines = new LinkedHashSet<>();
for (RuleConfig rule : moduleRules) {
if (rule == null || ObjectUtil.isEmpty(rule.getRuleCode())) {
continue;
}
List<String> outputs = RuleFourBlockRuleOutputCatalog.outputsForRule(def.getModuleCode(), rule.getRuleCode());
lines.addAll(outputs);
for (RuleConfigParam param : paramsByRule.getOrDefault(rule.getRuleCode(), Collections.emptyList())) {
if (param == null || ObjectUtil.isEmpty(param.getParamKey())) {
continue;
}
if (param.getEnabled() != null && param.getEnabled() == 0) {
continue;
}
Object effective = globalPreview.get(param.getParamKey());
lines.add(ObjectUtil.defaultIfBlank(param.getParamName(), param.getParamKey())
+ " -> "
+ RuleParamOutputHint.effectLine(param.getParamKey(), def.getModuleCode())
+ (effective != null ? "(当前值: " + effective + ")" : ""));
}
}
if (lines.isEmpty()) {
root.safeChildren().add(decisionNode(
"decision:" + def.getBlockId() + ":outcome:empty",
"暂无结果描述",
"empty",
"当前块暂无可汇总的产出",
null));
} else {
int index = 0;
for (String line : lines) {
root.safeChildren().add(decisionNode(
"decision:" + def.getBlockId() + ":outcome:" + index,
"结果说明 " + (index + 1),
"outcome",
line,
null));
index++;
}
}
root.safeChildren().add(decisionNode(
"decision:" + def.getBlockId() + ":outcome:end",
"输出 / 结束",
"outcome",
"当前规则块的决策链在这里收束,结果写入执行对象或作为后续环节输入",
null));
return root;
}
private List<RuleFourBlockParamRowVO> buildFourBlockParamRows(RuleFourBlockDefinition def,
Map<String, RuleConfig> ruleByCode,
List<RuleConfigParam> plist,
@@ -551,6 +985,35 @@ public class RuleConfigServiceImpl implements IRuleConfigService {
return graph;
}
private int countEnabledParams(List<RuleConfig> moduleRules, Map<String, List<RuleConfigParam>> paramsByRule) {
int count = 0;
for (RuleConfig rule : moduleRules) {
if (rule == null || ObjectUtil.isEmpty(rule.getRuleCode())) {
continue;
}
for (RuleConfigParam param : paramsByRule.getOrDefault(rule.getRuleCode(), Collections.emptyList())) {
if (param == null || ObjectUtil.isEmpty(param.getParamKey())) {
continue;
}
if (param.getEnabled() != null && param.getEnabled() == 0) {
continue;
}
count++;
}
}
return count;
}
private RuleDecisionNodeVO decisionNode(String key, String title, String nodeType, String description, String valueText) {
RuleDecisionNodeVO node = new RuleDecisionNodeVO();
node.setKey(key);
node.setTitle(title);
node.setNodeType(nodeType);
node.setDescription(description);
node.setValueText(valueText);
return node;
}
private List<RuleDictItem> safeDict(String dictType) {
List<RuleDictItem> list = ruleConfigMapper.selectDictByType(dictType);
return list != null ? list : Collections.emptyList();
@@ -595,6 +1058,107 @@ public class RuleConfigServiceImpl implements IRuleConfigService {
return fallback;
}
private boolean isEmptyImportRow(RuleConfigExcelRow row) {
return ObjectUtil.isAllEmpty(
trimmed(row.getRuleCode()),
trimmed(row.getRuleName()),
trimmed(row.getParamKey()),
trimmed(row.getParamVal()),
trimmed(row.getTaskTypesCsv()));
}
private void mergeRuleBase(RuleConfig config, RuleConfigExcelRow row) {
config.setRuleName(mergeStringField(config.getRuleCode(), "ruleName", config.getRuleName(), row.getRuleName()));
config.setLevelCode(mergeStringField(config.getRuleCode(), "levelCode", config.getLevelCode(), row.getLevelCode()));
config.setKindCode(mergeStringField(config.getRuleCode(), "kindCode", config.getKindCode(), row.getKindCode()));
config.setModuleCode(mergeStringField(config.getRuleCode(), "moduleCode", config.getModuleCode(), row.getModuleCode()));
config.setConditionExpr(mergeStringField(config.getRuleCode(), "conditionExpr", config.getConditionExpr(), row.getConditionExpr()));
config.setActionExpr(mergeStringField(config.getRuleCode(), "actionExpr", config.getActionExpr(), row.getActionExpr()));
config.setRemark(mergeStringField(config.getRuleCode(), "remark", config.getRemark(), row.getRemark()));
config.setPriorityNo(mergeIntegerField(config.getRuleCode(), "priorityNo", config.getPriorityNo(), row.getPriorityNo()));
config.setVersionNo(mergeIntegerField(config.getRuleCode(), "versionNo", config.getVersionNo(), row.getVersionNo()));
config.setEnabled(mergeIntegerField(config.getRuleCode(), "enabled", config.getEnabled(), row.getEnabled()));
String taskTypesCsv = trimmed(row.getTaskTypesCsv());
if (ObjectUtil.isNotEmpty(taskTypesCsv)) {
List<String> parsed = parseTaskTypes(taskTypesCsv);
if (CollUtil.isNotEmpty(config.getTaskTypes()) && !config.getTaskTypes().equals(parsed)) {
throw new RuntimeException("Rule " + config.getRuleCode() + " has conflicting taskTypesCsv values");
}
config.setTaskTypes(parsed);
}
}
private void fillImportDefaults(RuleConfig config) {
if (config.getParams() == null) {
config.setParams(new ArrayList<>());
}
if (config.getTaskTypes() == null) {
config.setTaskTypes(new ArrayList<>());
}
int sortNo = 0;
for (RuleConfigParam param : config.getParams()) {
if (param.getSortNo() == null) {
param.setSortNo(sortNo);
}
if (param.getEnabled() == null) {
param.setEnabled(1);
}
sortNo++;
}
}
private String mergeStringField(String ruleCode, String fieldName, String currentValue, String newValue) {
String current = trimmed(currentValue);
String incoming = trimmed(newValue);
if (ObjectUtil.isEmpty(incoming)) {
return current;
}
if (ObjectUtil.isEmpty(current)) {
return incoming;
}
if (!Objects.equals(current, incoming)) {
throw new RuntimeException("Rule " + ruleCode + " has conflicting values for field " + fieldName);
}
return current;
}
private Integer mergeIntegerField(String ruleCode, String fieldName, Integer currentValue, Integer newValue) {
if (newValue == null) {
return currentValue;
}
if (currentValue == null) {
return newValue;
}
if (!Objects.equals(currentValue, newValue)) {
throw new RuntimeException("Rule " + ruleCode + " has conflicting values for field " + fieldName);
}
return currentValue;
}
private List<String> parseTaskTypes(String taskTypesCsv) {
if (ObjectUtil.isEmpty(taskTypesCsv)) {
return new ArrayList<>();
}
return Arrays.stream(taskTypesCsv.split(","))
.map(this::trimmed)
.filter(ObjectUtil::isNotEmpty)
.distinct()
.collect(Collectors.toList());
}
private String joinTaskTypes(List<String> taskTypes) {
if (CollUtil.isEmpty(taskTypes)) {
return null;
}
return taskTypes.stream()
.filter(ObjectUtil::isNotEmpty)
.collect(Collectors.joining(","));
}
private String trimmed(String value) {
return value == null ? null : value.trim();
}
private void saveChildren(RuleConfig ruleConfig) {
if (CollUtil.isNotEmpty(ruleConfig.getParams())) {
Set<String> keys = new HashSet<>();

View File

@@ -1790,6 +1790,23 @@
border: 1px solid #475f71;
border-radius: 2px;
.ks-sidebar-list-param-head {
margin-bottom: 12px;
padding-bottom: 8px;
border-bottom: 1px solid rgba(71, 95, 113, 0.65);
}
.ks-sidebar-list-param-head-cell {
font-size: 12px;
color: #8fc7de;
line-height: 22px;
white-space: nowrap;
}
.ks-sidebar-list-param-head-cell--actions {
text-align: center;
}
.ks-sidebar-list-param-item {
margin-bottom: 15px;
@@ -1930,6 +1947,13 @@
.ks-sidebar-header {
background: url('@/assets/icons/bg-fk-title.png') center / 100% 100%;
min-height: 104px;
padding: 8px 10px 12px;
display: flex;
flex-direction: column;
justify-content: flex-start;
gap: 10px;
line-height: normal;
}
.ant-tree {
@@ -1973,6 +1997,9 @@
align-items: stretch;
overflow: hidden;
padding-right: 0;
background:
linear-gradient(180deg, rgba(1, 12, 28, 0.94) 0%, rgba(2, 16, 36, 0.92) 100%),
url('@/assets/icons/page-card-body.png') center / 100% 100%;
}
.rule-config-graph-placeholder {
@@ -2008,11 +2035,61 @@
}
}
.rule-config-sidebar .ks-sidebar-actions {
width: 100%;
display: flex;
justify-content: center;
gap: 10px;
padding: 10px 12px;
border: 1px solid rgba(71, 95, 113, 0.78);
border-radius: 2px;
background: linear-gradient(180deg, rgba(8, 29, 54, 0.88) 0%, rgba(6, 21, 40, 0.92) 100%);
box-shadow: inset 0 0 0 1px rgba(18, 70, 120, 0.18);
}
.rule-config-sidebar .ks-sidebar-add {
position: static;
right: auto;
top: auto;
font-size: 12px;
.anticon {
display: block;
float: left;
line-height: 16px;
}
}
.rule-config-sidebar-action.ant-btn {
display: inline-flex;
align-items: center;
gap: 4px;
min-width: 62px;
padding-inline: 10px;
border-color: #1c468b;
background: linear-gradient(0deg, #14223b 0, #1c468b 100%);
color: #eee;
.anticon {
margin: 0;
line-height: 1;
}
&:not(:disabled):hover,
&:hover,
&:active {
border-color: #166094;
background: linear-gradient(90deg, #3687bc 0%, #074375 100%);
color: #fff;
}
}
.rule-config-right-cluster {
display: flex;
flex: 1 1 auto;
min-width: 0;
align-items: stretch;
background: transparent;
}
.rule-config-graph-placeholder__text {
@@ -2039,6 +2116,7 @@
}
.rule-config-right-panel {
position: relative;
flex: 0 0 min(480px, 42vw);
width: min(480px, 42vw);
min-width: 320px;
@@ -2046,6 +2124,9 @@
transition: flex-basis 0.2s ease, width 0.2s ease, opacity 0.2s ease, min-width 0.2s ease;
overflow: hidden;
border-left: 1px solid rgba(71, 95, 113, 0.6);
background:
linear-gradient(180deg, rgba(4, 24, 50, 0.96) 0%, rgba(3, 17, 37, 0.94) 100%);
box-shadow: inset 0 0 0 1px rgba(18, 70, 120, 0.18);
}
.rule-config-right-panel--collapsed {
@@ -2058,8 +2139,26 @@
pointer-events: none;
}
.rule-config-right-panel-edge {
position: absolute;
left: 0;
top: 8px;
bottom: 8px;
width: 8px;
padding: 0;
border: 0;
cursor: col-resize;
background: linear-gradient(180deg, rgba(55, 126, 173, 0.15) 0%, rgba(55, 126, 173, 0.5) 50%, rgba(55, 126, 173, 0.15) 100%);
z-index: 2;
&:hover {
background: linear-gradient(180deg, rgba(55, 126, 173, 0.3) 0%, rgba(55, 126, 173, 0.72) 50%, rgba(55, 126, 173, 0.3) 100%);
}
}
.rule-config-right-panel__inner {
height: 100%;
overflow-y: auto;
padding: 10px 10px 10px 4px;
padding: 10px 10px 10px 12px;
background: transparent;
}

View File

@@ -0,0 +1,502 @@
<template>
<div class="rule-decision-binary-tree">
<div class="rule-decision-binary-tree__toolbar">
<a-popover placement="bottomLeft" trigger="click" overlay-class-name="rule-decision-binary-tree-snapshot-popover">
<template #content>
<pre class="rule-decision-binary-tree__popover-json">{{ previewJson }}</pre>
</template>
<a-button type="link" size="small" class="rule-decision-binary-tree__snapshot-btn">
全局参数快照({{ previewEntryCount }})
</a-button>
</a-popover>
</div>
<div v-if="errorMsg" class="rule-decision-binary-tree__banner rule-decision-binary-tree__banner--error">
{{ errorMsg }}
</div>
<div v-else-if="emptyHint" class="rule-decision-binary-tree__banner">
{{ emptyHint }}
</div>
<div v-else ref="hostRef" class="rule-decision-binary-tree__canvas" />
</div>
</template>
<script setup lang="ts">
import { Graph } from '@antv/g6';
import { message } from 'ant-design-vue';
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
import { findRuleDecisionTree } from './api';
import type { RuleConfigRequest, RuleDecisionBlock, RuleDecisionNode, RuleDecisionTreePayload } from './types';
const props = defineProps<{
query: RuleConfigRequest,
refreshKey: number,
}>();
type BinaryGraphNode = {
id: string,
label: string,
nodeType: string,
description?: string,
fullText?: string,
};
const hostRef = ref<HTMLDivElement | null>(null);
const errorMsg = ref<string | null>(null);
const emptyHint = ref<string | null>(null);
const payload = ref<RuleDecisionTreePayload | null>(null);
const renderVersion = ref(0);
let graph: Graph | null = null;
let resizeObserver: ResizeObserver | null = null;
const previewEntryCount = computed(() => {
const p = payload.value?.globalParamsPreview;
return p ? Object.keys(p).length : 0;
});
const previewJson = computed(() => {
const p = payload.value?.globalParamsPreview;
if (!p) {
return '';
}
try {
return JSON.stringify(p, null, 2);
} catch {
return String(p);
}
});
const NODE_COLORS: Record<string, string> = {
start: '#4fb3ff',
decision: '#ffd166',
if: '#49c59c',
else: '#ff9c4a',
output: '#9270CA',
end: '#e8684a',
};
const BLOCK_TITLE: Record<string, string> = {
equipment: '装备规则',
target: '目标规则',
position: '阵位规则',
track: '航迹规则',
};
const flatten = (nodes: RuleDecisionNode[] | null | undefined): RuleDecisionNode[] => {
const out: RuleDecisionNode[] = [];
const visit = (list: RuleDecisionNode[] | null | undefined) => {
(list ?? []).forEach((node) => {
out.push(node);
visit(node.children ?? []);
});
};
visit(nodes);
return out;
};
const pickImportantParams = (flatNodes: RuleDecisionNode[]) =>
flatNodes.filter((node) => node.nodeType === 'input_param' || node.nodeType === 'param').slice(0, 2);
const pickConditions = (flatNodes: RuleDecisionNode[]) =>
flatNodes.filter((node) => node.nodeType === 'condition').slice(0, 1);
const pickOutputs = (flatNodes: RuleDecisionNode[]) =>
flatNodes.filter((node) => node.nodeType === 'output' || node.nodeType === 'outcome').slice(0, 2);
const shortText = (text: string | null | undefined, max = 44) => {
const value = String(text ?? '').replace(/\s+/g, ' ').trim();
if (!value) {
return '';
}
return value.length > max ? `${value.slice(0, max)}...` : value;
};
const buildConditionText = (block: RuleDecisionBlock) => {
const flatNodes = flatten(block.nodes);
const condition = pickConditions(flatNodes)[0];
if (condition?.description) {
return shortText(condition.description, 52);
}
const param = pickImportantParams(flatNodes)[0];
if (param) {
return `${param.title} 是否满足当前规则条件`;
}
return `${BLOCK_TITLE[block.blockId] ?? block.title ?? block.blockId} 是否命中`;
};
const buildIfText = (block: RuleDecisionBlock) => {
const flatNodes = flatten(block.nodes);
const outputs = pickOutputs(flatNodes);
if (outputs.length > 0) {
return outputs.map((item) => shortText(item.title || item.description, 30)).join(';');
}
return `进入${BLOCK_TITLE[block.blockId] ?? block.title ?? block.blockId}处理`;
};
const buildElseText = (block: RuleDecisionBlock) =>
`不满足当前条件,跳过${BLOCK_TITLE[block.blockId] ?? block.title ?? block.blockId},继续后续判断`;
const buildBinaryGraph = (tree: RuleDecisionTreePayload) => {
const nodes: BinaryGraphNode[] = [];
const edges: Array<{ source: string; target: string; label?: string }> = [];
const startId = 'binary:start';
nodes.push({
id: startId,
label: '开始',
nodeType: 'start',
description: '载入关键参数,进入规则判断',
fullText: '开始:载入关键参数,进入规则判断',
});
const blocks = [...(tree.blocks ?? [])];
const attachSubtree = (parentId: string, branchLabel: string, branchType: 'if' | 'else', description: string, blockIndex: number) => {
const branchId = `${parentId}:${branchType}:${blockIndex}`;
nodes.push({
id: branchId,
label: branchType === 'if' ? 'If' : 'Else',
nodeType: branchType,
description,
fullText: `${branchType === 'if' ? 'If' : 'Else'}:${description}`,
});
edges.push({ source: parentId, target: branchId, label: branchLabel });
if (blockIndex >= blocks.length) {
const endId = `${branchId}:end`;
nodes.push({
id: endId,
label: '输出 / 结束',
nodeType: 'end',
description: '输出最终规则结果',
});
edges.push({ source: branchId, target: endId });
return;
}
const block = blocks[blockIndex];
if (!block) {
const endId = `${branchId}:end:fallback`;
nodes.push({
id: endId,
label: '输出 / 结束',
nodeType: 'end',
description: '输出最终规则结果',
});
edges.push({ source: branchId, target: endId });
return;
}
const decisionId = `${branchId}:decision:${block.blockId}:${blockIndex}`;
nodes.push({
id: decisionId,
label: `${BLOCK_TITLE[block.blockId] ?? block.title ?? block.blockId}判断`,
nodeType: 'decision',
description: buildConditionText(block),
fullText: `${BLOCK_TITLE[block.blockId] ?? block.title ?? block.blockId}判断:${buildConditionText(block)}`,
});
edges.push({ source: branchId, target: decisionId });
attachSubtree(decisionId, '满足', 'if', buildIfText(block), blockIndex + 1);
attachSubtree(decisionId, '不满足', 'else', buildElseText(block), blockIndex + 1);
};
if (!blocks.length) {
const endId = 'binary:end:empty';
nodes.push({
id: endId,
label: '输出 / 结束',
nodeType: 'end',
description: '当前没有可用规则',
fullText: '输出 / 结束:当前没有可用规则',
});
edges.push({ source: startId, target: endId });
return { nodes, edges };
}
const first = blocks[0];
if (!first) {
const endId = 'binary:end:fallback';
nodes.push({
id: endId,
label: '输出 / 结束',
nodeType: 'end',
description: '当前没有可用规则',
});
edges.push({ source: startId, target: endId });
return { nodes, edges };
}
const firstDecisionId = `binary:decision:${first.blockId}:0`;
nodes.push({
id: firstDecisionId,
label: `${BLOCK_TITLE[first.blockId] ?? first.title ?? first.blockId}判断`,
nodeType: 'decision',
description: buildConditionText(first),
fullText: `${BLOCK_TITLE[first.blockId] ?? first.title ?? first.blockId}判断:${buildConditionText(first)}`,
});
edges.push({ source: startId, target: firstDecisionId });
attachSubtree(firstDecisionId, '满足', 'if', buildIfText(first), 1);
attachSubtree(firstDecisionId, '不满足', 'else', buildElseText(first), 1);
return { nodes, edges };
};
const disposeGraph = () => {
resizeObserver?.disconnect();
resizeObserver = null;
if (graph) {
try {
graph.destroy();
} catch {
/* ignore */
}
graph = null;
}
hostRef.value?.replaceChildren();
};
const renderGraph = async (tree: RuleDecisionTreePayload, version: number) => {
const host = hostRef.value;
if (!host) {
return;
}
disposeGraph();
if (version !== renderVersion.value) {
return;
}
const data = buildBinaryGraph(tree);
graph = new Graph({
container: host,
width: Math.max(host.clientWidth, 320),
height: Math.max(host.clientHeight, 260),
data: {
nodes: data.nodes.map((node) => ({
id: node.id,
data: node,
})),
edges: data.edges.map((edge, index) => ({
id: `edge:${index}:${edge.source}:${edge.target}`,
source: edge.source,
target: edge.target,
data: { label: edge.label ?? '' },
})),
},
layout: {
type: 'antv-dagre',
rankdir: 'TB',
nodesep: 28,
ranksep: 42,
},
node: {
type: (model: { data?: { nodeType?: string } }) => {
const t = model.data?.nodeType;
if (t === 'start') return 'rect';
if (t === 'end' || t === 'decision') return 'diamond';
return 'circle';
},
style: {
size: (model: { data?: { nodeType?: string } }) => {
const t = model.data?.nodeType;
if (t === 'start') return 24;
if (t === 'end') return 22;
if (t === 'decision') return 26;
return 18;
},
fill: (model: { data?: { nodeType?: string } }) => NODE_COLORS[model.data?.nodeType ?? 'decision'] ?? '#5B8FF9',
stroke: '#0d1f2c',
lineWidth: 1.5,
labelText: (model: { data?: { label?: string; description?: string; fullText?: string; nodeType?: string } }) => {
const fullText = model.data?.fullText;
if (fullText) {
return fullText;
}
const label = model.data?.label ?? '';
const description = model.data?.description;
return description ? `${label}\n${description}` : label;
},
labelFill: '#e8f4f8',
labelFontSize: 11,
labelLineHeight: 15,
labelWordWrap: true,
labelMaxWidth: 320,
labelPlacement: (model: { data?: { nodeType?: string } }) => {
const t = model.data?.nodeType;
if (t === 'decision' || t === 'if' || t === 'else' || t === 'output' || t === 'end') {
return 'right';
}
return 'bottom';
},
labelOffsetX: (model: { data?: { nodeType?: string } }) => {
const t = model.data?.nodeType;
if (t === 'decision' || t === 'if' || t === 'else' || t === 'output' || t === 'end') {
return 14;
}
return 0;
},
labelTextAlign: (model: { data?: { nodeType?: string } }) => {
const t = model.data?.nodeType;
if (t === 'decision' || t === 'if' || t === 'else' || t === 'output' || t === 'end') {
return 'left';
}
return 'center';
},
labelBackground: true,
labelBackgroundFill: 'rgba(6, 21, 40, 0.88)',
labelBackgroundRadius: 4,
labelPadding: [6, 8],
},
},
edge: {
style: {
stroke: 'rgba(120, 170, 200, 0.52)',
lineWidth: 1.2,
endArrow: true,
labelText: (edge: { data?: { label?: string } }) => edge.data?.label ?? '',
labelFill: '#9ad0f5',
labelFontSize: 11,
labelBackground: true,
labelBackgroundFill: 'rgba(6, 21, 40, 0.85)',
labelBackgroundRadius: 3,
labelPadding: [2, 6],
},
},
behaviors: ['drag-canvas', 'zoom-canvas'],
});
await graph.render();
if (version !== renderVersion.value) {
disposeGraph();
return;
}
await graph.fitView({ when: 'always' });
resizeObserver = new ResizeObserver(() => {
if (!graph || !hostRef.value) {
return;
}
graph.setSize(Math.max(hostRef.value.clientWidth, 320), Math.max(hostRef.value.clientHeight, 260));
void graph.fitView({ when: 'overflow' });
});
resizeObserver.observe(host);
};
const load = async () => {
errorMsg.value = null;
emptyHint.value = null;
payload.value = null;
renderVersion.value += 1;
disposeGraph();
try {
const r = await findRuleDecisionTree({
pageNum: props.query.pageNum,
pageSize: props.query.pageSize,
ruleCode: props.query.ruleCode ?? undefined,
ruleName: props.query.ruleName ?? undefined,
levelCode: props.query.levelCode ?? undefined,
kindCode: props.query.kindCode ?? undefined,
moduleCode: props.query.moduleCode ?? undefined,
enabled: props.query.enabled ?? undefined,
});
if (r.code !== 200 || !r.data) {
errorMsg.value = r.msg ?? '加载二叉决策树失败';
return;
}
if (!r.data.blocks?.length) {
emptyHint.value = '当前没有可展示的二叉决策树数据';
return;
}
payload.value = r.data;
await nextTick();
await renderGraph(r.data, renderVersion.value);
} catch (e: unknown) {
const msg = e instanceof Error ? e.message : String(e);
errorMsg.value = `二叉决策树请求失败:${msg}`;
message.error(errorMsg.value);
}
};
watch(
() => [props.query.pageNum, props.query.pageSize, props.refreshKey],
() => {
void load();
},
{ immediate: true },
);
onBeforeUnmount(() => {
renderVersion.value += 1;
disposeGraph();
});
</script>
<style scoped lang="less">
.rule-decision-binary-tree {
flex: 1;
min-height: 0;
width: 100%;
display: flex;
flex-direction: column;
gap: 6px;
background: transparent;
}
.rule-decision-binary-tree__toolbar {
flex: 0 0 auto;
padding: 0 2px;
}
.rule-decision-binary-tree__snapshot-btn {
padding-left: 0;
font-size: 11px;
color: #8fafbd;
}
.rule-decision-binary-tree__banner {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 12px;
font-size: 13px;
color: #a2b1ba;
text-align: center;
}
.rule-decision-binary-tree__banner--error {
color: #ff9c9c;
}
.rule-decision-binary-tree__canvas {
flex: 1;
min-height: 0;
width: 100%;
border: 1px solid rgba(80, 120, 150, 0.22);
border-radius: 4px;
background: rgba(4, 18, 28, 0.35);
}
</style>
<style lang="less">
.rule-decision-binary-tree-snapshot-popover {
.ant-popover-inner-content {
max-width: min(520px, 90vw);
max-height: 70vh;
overflow: auto;
background: #081e3b;
}
.ant-popover-inner {
background: #081e3b;
}
}
.rule-decision-binary-tree__popover-json {
margin: 0;
font-size: 10px;
line-height: 1.35;
color: #c9dfe8;
white-space: pre-wrap;
}
</style>

View File

@@ -0,0 +1,415 @@
<template>
<div class="rule-decision-tree">
<div class="rule-decision-tree__toolbar">
<a-popover placement="bottomLeft" trigger="click" overlay-class-name="rule-decision-tree-snapshot-popover">
<template #content>
<pre class="rule-decision-tree__popover-json">{{ previewJson }}</pre>
</template>
<a-button type="link" size="small" class="rule-decision-tree__snapshot-btn">
全局参数快照({{ previewEntryCount }})
</a-button>
</a-popover>
</div>
<div v-if="errorMsg" class="rule-decision-tree__banner rule-decision-tree__banner--error">
{{ errorMsg }}
</div>
<div v-else-if="emptyHint" class="rule-decision-tree__banner">
{{ emptyHint }}
</div>
<div v-else-if="payload" class="rule-decision-tree__grid">
<section
v-for="block in payload.blocks"
:key="block.blockId"
class="rule-decision-tree__pane"
>
<header class="rule-decision-tree__pane-header">
<div class="rule-decision-tree__pane-title">{{ block.title || block.blockId }}</div>
<div class="rule-decision-tree__pane-meta">
模块:{{ block.moduleCode || '-' }} / salience:{{ block.salience ?? '-' }}
</div>
</header>
<div
:ref="(el) => registerHost(block.blockId, el)"
class="rule-decision-tree__canvas"
/>
</section>
</div>
</div>
</template>
<script setup lang="ts">
import { Graph } from '@antv/g6';
import { message } from 'ant-design-vue';
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
import { findRuleDecisionTree } from './api';
import type { RuleConfigRequest, RuleDecisionBlock, RuleDecisionNode, RuleDecisionTreePayload } from './types';
const props = defineProps<{
query: RuleConfigRequest,
refreshKey: number,
}>();
const payload = ref<RuleDecisionTreePayload | null>(null);
const errorMsg = ref<string | null>(null);
const emptyHint = ref<string | null>(null);
const hostMap = new Map<string, HTMLDivElement>();
const graphMap = new Map<string, Graph>();
const resizeMap = new Map<string, ResizeObserver>();
const renderVersion = ref(0);
const previewEntryCount = computed(() => {
const p = payload.value?.globalParamsPreview;
return p ? Object.keys(p).length : 0;
});
const previewJson = computed(() => {
const p = payload.value?.globalParamsPreview;
if (!p) {
return '';
}
try {
return JSON.stringify(p, null, 2);
} catch {
return String(p);
}
});
const BLOCK_COLORS: Record<string, string> = {
equipment: '#5B8FF9',
target: '#F6903D',
position: '#61DDAA',
track: '#9270CA',
};
const NODE_COLORS: Record<string, string> = {
root: '#5B8FF9',
input_group: '#5B8FF9',
input_param: '#4fb3ff',
step_group: '#61DDAA',
step: '#49c59c',
rule_group: '#F6903D',
rule: '#ff9c4a',
condition: '#ffd166',
task_types: '#9ad0f5',
param_group: '#3db2ff',
param: '#5ab9ff',
output_group: '#f08c6c',
output: '#ffb366',
outcome_group: '#9270CA',
outcome: '#a98cf0',
end: '#e8684a',
empty: '#6f8194',
};
const registerHost = (blockId: string, el: unknown) => {
if (!(el instanceof HTMLDivElement)) {
disposeBlock(blockId);
hostMap.delete(blockId);
return;
}
hostMap.set(blockId, el);
};
const flattenTree = (block: RuleDecisionBlock) => {
const nodes: Array<{ id: string; label: string; nodeType: string; valueText?: string | null; description?: string | null }> = [];
const edges: Array<{ source: string; target: string }> = [];
const rootId = `block:${block.blockId}:root`;
nodes.push({
id: rootId,
label: block.title || block.blockId,
nodeType: 'root',
valueText: block.salience != null ? `salience=${block.salience}` : undefined,
description: block.droolsRuleName || undefined,
});
const visit = (node: RuleDecisionNode, parentId: string) => {
const desc = node.description ? (node.valueText ? `${node.description} | ${node.valueText}` : node.description) : (node.valueText ?? '');
nodes.push({
id: node.key,
label: node.title,
nodeType: node.nodeType,
description: desc || undefined,
});
edges.push({ source: parentId, target: node.key });
(node.children ?? []).forEach((child) => visit(child, node.key));
};
(block.nodes ?? []).forEach((node) => visit(node, rootId));
return { nodes, edges };
};
const disposeBlock = (blockId: string) => {
resizeMap.get(blockId)?.disconnect();
resizeMap.delete(blockId);
const graph = graphMap.get(blockId);
if (graph) {
try {
graph.destroy();
} catch {
/* ignore */
}
graphMap.delete(blockId);
}
const host = hostMap.get(blockId);
if (host) {
host.replaceChildren();
}
};
const renderBlock = async (block: RuleDecisionBlock, version: number) => {
const host = hostMap.get(block.blockId);
if (!host) {
return;
}
disposeBlock(block.blockId);
if (version !== renderVersion.value) {
return;
}
const width = Math.max(host.clientWidth, 320);
const height = Math.max(host.clientHeight, 240);
const accent = BLOCK_COLORS[block.blockId] ?? '#5B8FF9';
const data = flattenTree(block);
const graph = new Graph({
container: host,
width,
height,
data: {
nodes: data.nodes.map((node) => ({
id: node.id,
data: node,
})),
edges: data.edges,
},
layout: {
type: 'antv-dagre',
rankdir: 'TB',
nodesep: 20,
ranksep: 42,
},
node: {
type: (model: { data?: { nodeType?: string } }) => {
const t = model.data?.nodeType;
if (t === 'input_group') return 'rect';
if (t === 'end') return 'diamond';
return 'circle';
},
style: {
size: (model: { data?: { nodeType?: string } }) => {
const t = model.data?.nodeType;
if (t === 'root') return 18;
if (t === 'input_group' || t === 'end') return 20;
return 14;
},
fill: (model: { data?: { nodeType?: string } }) => NODE_COLORS[model.data?.nodeType ?? ''] ?? accent,
stroke: '#0d1f2c',
lineWidth: 1.5,
labelText: (model: { data?: { label?: string; description?: string } }) => {
const label = model.data?.label ?? '';
const description = model.data?.description;
return description ? `${label}\n${description}` : label;
},
labelFill: '#e8f4f8',
labelFontSize: 11,
labelLineHeight: 15,
labelWordWrap: true,
labelMaxWidth: 160,
},
},
edge: {
style: {
stroke: 'rgba(120, 170, 200, 0.52)',
lineWidth: 1.2,
endArrow: true,
},
},
behaviors: ['drag-canvas', 'zoom-canvas'],
});
await graph.render();
if (version !== renderVersion.value) {
try {
graph.destroy();
} catch {
/* ignore */
}
return;
}
await graph.fitView({ when: 'always' });
graphMap.set(block.blockId, graph);
const observer = new ResizeObserver(() => {
const nextWidth = Math.max(host.clientWidth, 320);
const nextHeight = Math.max(host.clientHeight, 240);
graph.setSize(nextWidth, nextHeight);
void graph.fitView({ when: 'overflow' });
});
observer.observe(host);
resizeMap.set(block.blockId, observer);
};
const renderAll = async () => {
if (!payload.value?.blocks?.length) {
return;
}
await nextTick();
const version = renderVersion.value;
for (const block of payload.value.blocks) {
await renderBlock(block, version);
}
};
const load = async () => {
errorMsg.value = null;
emptyHint.value = null;
payload.value = null;
renderVersion.value += 1;
Array.from(graphMap.keys()).forEach(disposeBlock);
try {
const r = await findRuleDecisionTree({
pageNum: props.query.pageNum,
pageSize: props.query.pageSize,
ruleCode: props.query.ruleCode ?? undefined,
ruleName: props.query.ruleName ?? undefined,
levelCode: props.query.levelCode ?? undefined,
kindCode: props.query.kindCode ?? undefined,
moduleCode: props.query.moduleCode ?? undefined,
enabled: props.query.enabled ?? undefined,
});
if (r.code !== 200 || !r.data) {
errorMsg.value = r.msg ?? '加载决策树失败';
return;
}
if (!r.data.blocks?.length) {
emptyHint.value = '当前没有可展示的规则决策树数据';
return;
}
payload.value = r.data;
await renderAll();
} catch (e: unknown) {
const msg = e instanceof Error ? e.message : String(e);
errorMsg.value = `决策树请求失败:${msg}`;
message.error(errorMsg.value);
}
};
watch(
() => [props.query.pageNum, props.query.pageSize, props.refreshKey],
() => {
void load();
},
{ immediate: true },
);
onBeforeUnmount(() => {
renderVersion.value += 1;
Array.from(graphMap.keys()).forEach(disposeBlock);
});
</script>
<style scoped lang="less">
.rule-decision-tree {
flex: 1;
min-height: 0;
width: 100%;
display: flex;
flex-direction: column;
gap: 6px;
background: transparent;
}
.rule-decision-tree__toolbar {
flex: 0 0 auto;
padding: 0 2px;
}
.rule-decision-tree__snapshot-btn {
padding-left: 0;
font-size: 11px;
color: #8fafbd;
}
.rule-decision-tree__banner {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 12px;
font-size: 13px;
color: #a2b1ba;
text-align: center;
}
.rule-decision-tree__banner--error {
color: #ff9c9c;
}
.rule-decision-tree__grid {
flex: 1;
min-height: 0;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
grid-template-rows: repeat(2, minmax(0, 1fr));
gap: 8px;
}
.rule-decision-tree__pane {
display: flex;
flex-direction: column;
min-height: 0;
border: 1px solid rgba(80, 120, 150, 0.25);
background: linear-gradient(180deg, rgba(8, 20, 30, 0.78) 0%, rgba(5, 16, 29, 0.9) 100%);
overflow: hidden;
}
.rule-decision-tree__pane-header {
flex: 0 0 auto;
padding: 8px 10px 6px;
border-bottom: 1px solid rgba(80, 120, 150, 0.2);
background: rgba(10, 28, 40, 0.78);
}
.rule-decision-tree__pane-title {
font-size: 14px;
color: #d8edf6;
}
.rule-decision-tree__pane-meta {
margin-top: 2px;
font-size: 11px;
color: #7f9aaa;
}
.rule-decision-tree__canvas {
flex: 1;
min-height: 0;
width: 100%;
background: transparent;
}
</style>
<style lang="less">
.rule-decision-tree-snapshot-popover {
.ant-popover-inner-content {
max-width: min(520px, 90vw);
max-height: 70vh;
overflow: auto;
background: #081e3b;
}
.ant-popover-inner {
background: #081e3b;
}
}
.rule-decision-tree__popover-json {
margin: 0;
font-size: 10px;
line-height: 1.35;
color: #c9dfe8;
white-space: pre-wrap;
}
</style>

View File

@@ -0,0 +1,466 @@
<template>
<div class="rule-decision-tree-simple">
<div class="rule-decision-tree-simple__toolbar">
<a-popover placement="bottomLeft" trigger="click" overlay-class-name="rule-decision-tree-simple-snapshot-popover">
<template #content>
<pre class="rule-decision-tree-simple__popover-json">{{ previewJson }}</pre>
</template>
<a-button type="link" size="small" class="rule-decision-tree-simple__snapshot-btn">
全局参数快照({{ previewEntryCount }})
</a-button>
</a-popover>
</div>
<div v-if="errorMsg" class="rule-decision-tree-simple__banner rule-decision-tree-simple__banner--error">
{{ errorMsg }}
</div>
<div v-else-if="emptyHint" class="rule-decision-tree-simple__banner">
{{ emptyHint }}
</div>
<div v-else ref="hostRef" class="rule-decision-tree-simple__canvas" />
</div>
</template>
<script setup lang="ts">
import { Graph } from '@antv/g6';
import { message } from 'ant-design-vue';
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
import { findRuleDecisionTree } from './api';
import type { RuleConfigRequest, RuleDecisionBlock, RuleDecisionNode, RuleDecisionTreePayload } from './types';
const props = defineProps<{
query: RuleConfigRequest,
refreshKey: number,
}>();
type GraphNode = {
id: string,
label: string,
nodeType: string,
description?: string,
fullText?: string,
};
const hostRef = ref<HTMLDivElement | null>(null);
const errorMsg = ref<string | null>(null);
const emptyHint = ref<string | null>(null);
const payload = ref<RuleDecisionTreePayload | null>(null);
const renderVersion = ref(0);
let graph: Graph | null = null;
let resizeObserver: ResizeObserver | null = null;
const previewEntryCount = computed(() => {
const p = payload.value?.globalParamsPreview;
return p ? Object.keys(p).length : 0;
});
const previewJson = computed(() => {
const p = payload.value?.globalParamsPreview;
if (!p) {
return '';
}
try {
return JSON.stringify(p, null, 2);
} catch {
return String(p);
}
});
const NODE_COLORS: Record<string, string> = {
start: '#4fb3ff',
block: '#5B8FF9',
params: '#49c59c',
rules: '#ff9c4a',
outputs: '#a98cf0',
end: '#e8684a',
};
const BLOCK_TITLE: Record<string, string> = {
equipment: '装备规则',
target: '目标规则',
position: '阵位规则',
track: '航迹规则',
};
const flatten = (nodes: RuleDecisionNode[] | null | undefined): RuleDecisionNode[] => {
const out: RuleDecisionNode[] = [];
const visit = (items: RuleDecisionNode[] | null | undefined) => {
(items ?? []).forEach((item) => {
out.push(item);
visit(item.children ?? []);
});
};
visit(nodes);
return out;
};
const scoreParamNode = (node: RuleDecisionNode) => {
const text = `${node.title ?? ''} ${node.description ?? ''} ${node.valueText ?? ''}`.toLowerCase();
let score = 0;
const keywords = [
'模式', '类型', '目标', '装备', '阵位', '航迹', '选择', '分配', '距离', '阈值', '权重',
'比例', '数量', '规则', 'mode', 'type', 'target', 'equipment', 'position', 'track',
'select', 'assign', 'distance', 'threshold', 'weight', 'ratio', 'count', 'limit', 'min', 'max',
];
keywords.forEach((keyword) => {
if (text.includes(keyword)) {
score += 2;
}
});
if (text.includes('生效值')) {
score += 1;
}
return score;
};
const pickImportantParams = (flatNodes: RuleDecisionNode[]) => {
return flatNodes
.filter((node) => node.nodeType === 'input_param' || node.nodeType === 'param')
.sort((a, b) => scoreParamNode(b) - scoreParamNode(a))
.slice(0, 4);
};
const pickCoreRules = (flatNodes: RuleDecisionNode[]) => {
return flatNodes
.filter((node) => node.nodeType === 'rule')
.slice(0, 2);
};
const pickOutputs = (flatNodes: RuleDecisionNode[]) => {
const list = flatNodes.filter((node) => node.nodeType === 'output' || node.nodeType === 'outcome');
return list.slice(0, 3);
};
const buildMergedTree = (tree: RuleDecisionTreePayload) => {
const nodes: GraphNode[] = [];
const edges: Array<{ source: string; target: string }> = [];
const startId = 'simple:start';
nodes.push({
id: startId,
label: '输入参数',
nodeType: 'start',
description: `汇总四类规则块共享的运行时参数(${Object.keys(tree.globalParamsPreview ?? {}).length}项)`,
});
let previousMainId = startId;
const blocks = [...(tree.blocks ?? [])];
for (const block of blocks) {
const mainId = `simple:block:${block.blockId}`;
nodes.push({
id: mainId,
label: BLOCK_TITLE[block.blockId] ?? (block.title || block.blockId),
nodeType: 'block',
description: `salience=${block.salience ?? '-'};保留核心规则与关键参数`,
});
edges.push({ source: previousMainId, target: mainId });
const flatNodes = flatten(block.nodes);
const importantParams = pickImportantParams(flatNodes);
const coreRules = pickCoreRules(flatNodes);
const outputs = pickOutputs(flatNodes);
const paramId = `simple:block:${block.blockId}:params`;
nodes.push({
id: paramId,
label: '关键参数',
nodeType: 'params',
description: importantParams.length > 0
? importantParams.map((item) => `${item.title}${item.valueText ? `:${item.valueText}` : ''}`).join(';')
: '无关键参数',
fullText: importantParams.length > 0
? `关键参数:${importantParams.map((item) => `${item.title}${item.valueText ? `=${item.valueText}` : ''}`).join(';')}`
: '关键参数:无',
});
edges.push({ source: mainId, target: paramId });
const ruleId = `simple:block:${block.blockId}:rules`;
nodes.push({
id: ruleId,
label: '核心规则',
nodeType: 'rules',
description: coreRules.length > 0
? coreRules.map((item) => item.title).join(';')
: '无核心规则',
fullText: coreRules.length > 0
? `核心规则:${coreRules.map((item) => item.title).join(';')}`
: '核心规则:无',
});
edges.push({ source: mainId, target: ruleId });
const outputId = `simple:block:${block.blockId}:outputs`;
nodes.push({
id: outputId,
label: '阶段输出',
nodeType: 'outputs',
description: outputs.length > 0
? outputs.map((item) => String(item.title || item.description || '')).join(';')
: '无阶段输出',
fullText: outputs.length > 0
? `阶段输出:${outputs.map((item) => String(item.title || item.description || '')).join(';')}`
: '阶段输出:无',
});
edges.push({ source: mainId, target: outputId });
previousMainId = mainId;
}
nodes.push({
id: 'simple:end',
label: '输出 / 结束',
nodeType: 'end',
description: '四类规则块汇总后输出最终结果',
fullText: '输出 / 结束:四类规则块汇总后输出最终结果',
});
edges.push({ source: previousMainId, target: 'simple:end' });
return { nodes, edges };
};
const disposeGraph = () => {
resizeObserver?.disconnect();
resizeObserver = null;
if (graph) {
try {
graph.destroy();
} catch {
/* ignore */
}
graph = null;
}
hostRef.value?.replaceChildren();
};
const renderGraph = async (tree: RuleDecisionTreePayload, version: number) => {
const host = hostRef.value;
if (!host) {
return;
}
disposeGraph();
if (version !== renderVersion.value) {
return;
}
const data = buildMergedTree(tree);
graph = new Graph({
container: host,
width: Math.max(host.clientWidth, 320),
height: Math.max(host.clientHeight, 240),
data: {
nodes: data.nodes.map((node) => ({
id: node.id,
data: node,
})),
edges: data.edges,
},
layout: {
type: 'antv-dagre',
rankdir: 'LR',
nodesep: 28,
ranksep: 56,
},
node: {
type: (model: { data?: { nodeType?: string } }) => {
const t = model.data?.nodeType;
if (t === 'start') return 'rect';
if (t === 'end') return 'diamond';
return 'circle';
},
style: {
size: (model: { data?: { nodeType?: string } }) => {
const t = model.data?.nodeType;
if (t === 'start' || t === 'end') return 26;
if (t === 'block') return 20;
if (t === 'params' || t === 'rules' || t === 'outputs') return 16;
return 16;
},
fill: (model: { data?: { nodeType?: string } }) => NODE_COLORS[model.data?.nodeType ?? 'block'] ?? '#5B8FF9',
stroke: '#0d1f2c',
lineWidth: 1.5,
labelText: (model: { data?: { label?: string; description?: string; fullText?: string; nodeType?: string } }) => {
const text = model.data?.fullText;
if (text) {
return text;
}
const label = model.data?.label ?? '';
const description = model.data?.description;
return description ? `${label}:${description}` : label;
},
labelFill: '#e8f4f8',
labelFontSize: 11,
labelLineHeight: 15,
labelWordWrap: true,
labelMaxWidth: 360,
labelPlacement: (model: { data?: { nodeType?: string } }) => {
const t = model.data?.nodeType;
if (t === 'params' || t === 'rules' || t === 'outputs') {
return 'right';
}
return 'bottom';
},
labelOffsetX: (model: { data?: { nodeType?: string } }) => {
const t = model.data?.nodeType;
if (t === 'params' || t === 'rules' || t === 'outputs') {
return 14;
}
return 0;
},
labelTextAlign: (model: { data?: { nodeType?: string } }) => {
const t = model.data?.nodeType;
if (t === 'params' || t === 'rules' || t === 'outputs') {
return 'left';
}
return 'center';
},
labelBackground: true,
labelBackgroundFill: 'rgba(6, 21, 40, 0.88)',
labelBackgroundRadius: 4,
labelPadding: [6, 8],
},
},
edge: {
style: {
stroke: 'rgba(120, 170, 200, 0.52)',
lineWidth: 1.2,
endArrow: true,
},
},
behaviors: ['drag-canvas', 'zoom-canvas'],
});
await graph.render();
if (version !== renderVersion.value) {
disposeGraph();
return;
}
await graph.fitView({ when: 'always' });
resizeObserver = new ResizeObserver(() => {
if (!graph || !hostRef.value) {
return;
}
graph.setSize(Math.max(hostRef.value.clientWidth, 320), Math.max(hostRef.value.clientHeight, 240));
void graph.fitView({ when: 'overflow' });
});
resizeObserver.observe(host);
};
const load = async () => {
errorMsg.value = null;
emptyHint.value = null;
payload.value = null;
renderVersion.value += 1;
disposeGraph();
try {
const r = await findRuleDecisionTree({
pageNum: props.query.pageNum,
pageSize: props.query.pageSize,
ruleCode: props.query.ruleCode ?? undefined,
ruleName: props.query.ruleName ?? undefined,
levelCode: props.query.levelCode ?? undefined,
kindCode: props.query.kindCode ?? undefined,
moduleCode: props.query.moduleCode ?? undefined,
enabled: props.query.enabled ?? undefined,
});
if (r.code !== 200 || !r.data) {
errorMsg.value = r.msg ?? '加载简化决策树失败';
return;
}
if (!r.data.blocks?.length) {
emptyHint.value = '当前没有可展示的简化决策树数据';
return;
}
payload.value = r.data;
await nextTick();
await renderGraph(r.data, renderVersion.value);
} catch (e: unknown) {
const msg = e instanceof Error ? e.message : String(e);
errorMsg.value = `简化决策树请求失败:${msg}`;
message.error(errorMsg.value);
}
};
watch(
() => [props.query.pageNum, props.query.pageSize, props.refreshKey],
() => {
void load();
},
{ immediate: true },
);
onBeforeUnmount(() => {
renderVersion.value += 1;
disposeGraph();
});
</script>
<style scoped lang="less">
.rule-decision-tree-simple {
flex: 1;
min-height: 0;
width: 100%;
display: flex;
flex-direction: column;
gap: 6px;
background: transparent;
}
.rule-decision-tree-simple__toolbar {
flex: 0 0 auto;
padding: 0 2px;
}
.rule-decision-tree-simple__snapshot-btn {
padding-left: 0;
font-size: 11px;
color: #8fafbd;
}
.rule-decision-tree-simple__banner {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 12px;
font-size: 13px;
color: #a2b1ba;
text-align: center;
}
.rule-decision-tree-simple__banner--error {
color: #ff9c9c;
}
.rule-decision-tree-simple__canvas {
flex: 1;
min-height: 0;
width: 100%;
border: 1px solid rgba(80, 120, 150, 0.22);
border-radius: 4px;
background: rgba(4, 18, 28, 0.35);
}
</style>
<style lang="less">
.rule-decision-tree-simple-snapshot-popover {
.ant-popover-inner-content {
max-width: min(520px, 90vw);
max-height: 70vh;
overflow: auto;
background: #081e3b;
}
.ant-popover-inner {
background: #081e3b;
}
}
.rule-decision-tree-simple__popover-json {
margin: 0;
font-size: 10px;
line-height: 1.35;
color: #c9dfe8;
white-space: pre-wrap;
}
</style>

View File

@@ -12,20 +12,32 @@
class="rule-knowledge-graph"
:class="{
'rule-knowledge-graph--four-blocks': density === 'four-blocks',
'rule-knowledge-graph--decision-tree': density === 'decision-tree',
'rule-knowledge-graph--fullscreen': isFullscreen,
}"
>
<div class="rule-knowledge-graph__toolbar">
<a-radio-group v-model:value="density" size="small" button-style="solid">
<a-radio-button value="overview">简要结构</a-radio-button>
<a-radio-button value="full">完整</a-radio-button>
<a-radio-button value="decision-tree-simple">决策树(简化)</a-radio-button>
<a-radio-button value="decision-tree-binary">决策树(二叉树)</a-radio-button>
<a-radio-button value="decision-tree">决策树</a-radio-button>
<a-radio-button value="full">完整图谱</a-radio-button>
<a-radio-button value="four-blocks">四块分区</a-radio-button>
</a-radio-group>
<span v-if="density !== 'four-blocks'" class="rule-knowledge-graph__hint">
简要:仅层级→种类→模块→规则;完整:含参数、任务类型与执行顺序边;四块:业务运算步骤 + 规则项 + 参数(与 globalParams 一致)
<span v-if="density === 'decision-tree-simple'" class="rule-knowledge-graph__hint">
决策树(简化):把装备、目标、阵位、航迹四个规则块合并成一棵总树,只保留关键参数、核心规则和阶段输出
</span>
<span v-else-if="density === 'decision-tree-binary'" class="rule-knowledge-graph__hint">
决策树(二叉树):按 if / else 方式展示关键参数条件判断、分支去向与最终输出
</span>
<span v-else-if="density === 'decision-tree'" class="rule-knowledge-graph__hint">
决策树:按装备、目标、阵位、航迹四个规则块展示输入参数、运算步骤、命中规则与结果产出
</span>
<span v-else-if="density === 'full'" class="rule-knowledge-graph__hint">
完整图谱包含参数、任务类型与执行顺序
</span>
<span v-else class="rule-knowledge-graph__hint rule-knowledge-graph__hint--compact">
四宫格 · 拖拽画布 / 滚轮缩放
四块分区:可拖动画布,滚轮缩放
</span>
<a-button type="default" size="small" class="rule-knowledge-graph__fullscreen-btn" @click="toggleFullscreen">
<template #icon>
@@ -35,7 +47,10 @@
{{ isFullscreen ? '退出全屏' : '全屏' }}
</a-button>
</div>
<RuleFourBlocksPanel v-if="density === 'four-blocks'" :refresh-key="refreshKey" />
<RuleDecisionTreeSimplePanel v-if="density === 'decision-tree-simple'" :query="query" :refresh-key="refreshKey" />
<RuleDecisionBinaryTreePanel v-else-if="density === 'decision-tree-binary'" :query="query" :refresh-key="refreshKey" />
<RuleDecisionTreePanel v-else-if="density === 'decision-tree'" :query="query" :refresh-key="refreshKey" />
<RuleFourBlocksPanel v-else-if="density === 'four-blocks'" :refresh-key="refreshKey" />
<template v-else>
<div v-if="errorMsg" class="rule-knowledge-graph__banner rule-knowledge-graph__banner--error">
{{ errorMsg }}
@@ -54,10 +69,13 @@ import { Graph } from '@antv/g6';
import { message } from 'ant-design-vue';
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { findRuleConfigGraph } from './api';
import RuleDecisionBinaryTreePanel from './RuleDecisionBinaryTreePanel.vue';
import RuleDecisionTreeSimplePanel from './RuleDecisionTreeSimplePanel.vue';
import RuleDecisionTreePanel from './RuleDecisionTreePanel.vue';
import RuleFourBlocksPanel from './RuleFourBlocksPanel.vue';
import type { RuleConfigRequest, RuleGraphEdge, RuleGraphNode, RuleGraphPayload } from './types';
import type { RuleConfigRequest, RuleGraphPayload } from './types';
type RuleGraphDensityMode = 'overview' | 'full' | 'four-blocks';
type RuleGraphDensityMode = 'decision-tree-simple' | 'decision-tree-binary' | 'decision-tree' | 'full' | 'four-blocks';
const emit = defineEmits<{
densityChange: [RuleGraphDensityMode],
@@ -73,7 +91,7 @@ const hostRef = ref<HTMLDivElement | null>(null);
const isFullscreen = ref(false);
const errorMsg = ref<string | null>(null);
const emptyHint = ref<string | null>(null);
const density = ref<RuleGraphDensityMode>('overview');
const density = ref<RuleGraphDensityMode>('decision-tree-simple');
const lastPayload = ref<RuleGraphPayload | null>(null);
let graph: Graph | null = null;
@@ -88,56 +106,6 @@ const NODE_COLORS: Record<string, string> = {
taskType: '#269A99',
};
const str = (v: unknown): string => (v === null || v === undefined ? '' : String(v));
/** 简要:只保留结构主干,边改为 level → kind → module → rule 便于分层布局 */
const buildOverviewPayload = (payload: RuleGraphPayload): RuleGraphPayload => {
const keepTypes = new Set(['level', 'kind', 'module', 'rule']);
const nodes = payload.nodes.filter((n) => keepTypes.has(n.nodeType));
const nodeIds = new Set(nodes.map((n) => n.id));
const edgeSeen = new Set<string>();
const edges: RuleGraphEdge[] = [];
const addEdge = (source: string, target: string, suffix: string) => {
if (!nodeIds.has(source) || !nodeIds.has(target)) {
return;
}
const key = `${source}|${target}`;
if (edgeSeen.has(key)) {
return;
}
edgeSeen.add(key);
edges.push({
id: `ov:${suffix}:${key}`,
source,
target,
edgeType: 'overview_hierarchy',
label: null,
});
};
for (const r of nodes) {
if (r.nodeType !== 'rule' || !r.payload) {
continue;
}
const levelCode = str(r.payload.levelCode);
const kindCode = str(r.payload.kindCode);
const moduleCode = str(r.payload.moduleCode);
if (!levelCode || !kindCode || !moduleCode) {
continue;
}
const lid = `level:${levelCode}`;
const kid = `kind:${levelCode}:${kindCode}`;
const mid = `module:${moduleCode}`;
addEdge(lid, kid, 'lk');
addEdge(kid, mid, 'km');
addEdge(mid, r.id, 'mr');
}
return { nodes, edges };
};
const toGraphData = (payload: RuleGraphPayload) => ({
nodes: payload.nodes.map((n) => ({
id: n.id,
@@ -213,56 +181,36 @@ const disposeGraph = async () => {
}
};
const buildGraph = async (payload: RuleGraphPayload, mode: 'overview' | 'full') => {
const buildGraph = async (payload: RuleGraphPayload) => {
await disposeGraph();
const el = hostRef.value;
if (!el) {
return;
}
const raw = mode === 'overview' ? buildOverviewPayload(payload) : payload;
const data = toGraphData(raw);
if (raw.nodes.length === 0) {
const data = toGraphData(payload);
if (!payload.nodes.length) {
return;
}
const width = Math.max(el.clientWidth, 280);
const height = Math.max(el.clientHeight, 240);
const layout =
mode === 'overview'
? {
type: 'antv-dagre' as const,
rankdir: 'TB',
ranksep: 56,
nodesep: 36,
}
: {
type: 'd3-force' as const,
};
graph = new Graph({
container: el,
width,
height,
data,
layout,
layout: {
type: 'd3-force' as const,
},
node: {
style: {
size: (d: { data?: { nodeType?: string } }) => {
const t = d.data?.nodeType;
if (mode === 'overview') {
if (t === 'rule') return 20;
if (t === 'module') return 18;
return 16;
}
return t === 'param' ? 5 : 11;
},
size: (d: { data?: { nodeType?: string } }) => (d.data?.nodeType === 'param' ? 5 : 11),
fill: (d: { data?: { nodeType?: string } }) => NODE_COLORS[d.data?.nodeType ?? ''] ?? '#8B8B8B',
labelText: (d: { data?: { label?: string }; id: string }) => d.data?.label ?? String(d.id),
labelFill: '#e8f4f8',
labelFontSize: (d: { data?: { nodeType?: string } }) =>
(mode === 'overview' ? (d.data?.nodeType === 'rule' ? 11 : 12) : 9),
labelMaxWidth: mode === 'overview' ? 200 : 100,
labelFontSize: 9,
labelMaxWidth: 100,
labelWordWrap: true,
lineWidth: 1.5,
stroke: '#0d1f2c',
@@ -270,19 +218,11 @@ const buildGraph = async (payload: RuleGraphPayload, mode: 'overview' | 'full')
},
edge: {
style: {
stroke: (d: { data?: { edgeType?: string } }) => {
const t = d.data?.edgeType;
if (t === 'overview_hierarchy') {
return 'rgba(120, 170, 200, 0.55)';
}
if (t === 'rule_exec_before') {
return '#faad14';
}
return 'rgba(150, 175, 190, 0.35)';
},
stroke: (d: { data?: { edgeType?: string } }) =>
(d.data?.edgeType === 'rule_exec_before' ? '#faad14' : 'rgba(150, 175, 190, 0.35)'),
lineWidth: (d: { data?: { edgeType?: string } }) =>
(d.data?.edgeType === 'rule_exec_before' ? 2 : 1),
endArrow: mode !== 'overview',
endArrow: true,
},
},
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-element'],
@@ -302,18 +242,11 @@ const buildGraph = async (payload: RuleGraphPayload, mode: 'overview' | 'full')
};
const renderFromCache = async () => {
if (density.value === 'four-blocks') {
return;
}
if (!lastPayload.value) {
return;
}
if (!lastPayload.value.nodes?.length) {
if (density.value !== 'full' || !lastPayload.value || !lastPayload.value.nodes?.length) {
return;
}
await nextTick();
const mode: 'overview' | 'full' = density.value === 'full' ? 'full' : 'overview';
await buildGraph(lastPayload.value, mode);
await buildGraph(lastPayload.value);
};
const load = async () => {
@@ -336,13 +269,12 @@ const load = async () => {
lastPayload.value = null;
return;
}
const payload = r.data;
if (!payload.nodes?.length) {
if (!r.data.nodes?.length) {
emptyHint.value = '当前页无规则数据,图谱为空';
lastPayload.value = null;
return;
}
lastPayload.value = payload;
lastPayload.value = r.data;
await renderFromCache();
} catch (e: unknown) {
const msg = e instanceof Error ? e.message : String(e);
@@ -355,7 +287,7 @@ const load = async () => {
watch(
() => [props.query.pageNum, props.query.pageSize, props.refreshKey],
() => {
if (density.value === 'four-blocks') {
if (density.value !== 'full') {
return;
}
void load();
@@ -365,11 +297,11 @@ watch(
watch(density, async (mode, prev) => {
emit('densityChange', mode);
if (mode === 'four-blocks') {
if (mode !== 'full') {
await disposeGraph();
return;
}
if (prev === 'four-blocks') {
if (prev !== 'full') {
await load();
return;
}
@@ -418,42 +350,10 @@ onBeforeUnmount(() => {
font-size: 11px;
color: #7a8d96;
line-height: 1.35;
max-width: 100%;
}
.rule-knowledge-graph__hint--compact {
font-size: 10px;
color: #6d8290;
}
.rule-knowledge-graph--four-blocks {
min-height: 0;
}
.rule-knowledge-graph--fullscreen {
box-sizing: border-box;
width: 100vw;
height: 100vh;
max-height: 100vh;
padding: 10px 12px;
gap: 10px;
background: #0d1f2c;
}
.rule-knowledge-graph--fullscreen .rule-knowledge-graph__host {
min-height: 0;
flex: 1;
}
.rule-knowledge-graph--fullscreen :deep(.rule-four-blocks) {
flex: 1;
min-height: 0;
}
.rule-knowledge-graph__host {
flex: 1;
min-height: 200px;
position: relative;
letter-spacing: 0.2px;
}
.rule-knowledge-graph__banner {
@@ -470,4 +370,18 @@ onBeforeUnmount(() => {
.rule-knowledge-graph__banner--error {
color: #ff9c9c;
}
.rule-knowledge-graph__host {
flex: 1;
min-height: 0;
width: 100%;
border: 1px solid rgba(80, 120, 150, 0.18);
border-radius: 4px;
background: rgba(4, 18, 28, 0.35);
}
.rule-knowledge-graph--fullscreen {
background: #061522;
padding: 12px;
}
</style>

View File

@@ -7,9 +7,10 @@
* that was distributed with this source code.
*/
import { HttpRequestClient } from '@/utils/request';
import { HttpRequestClient, originalAxios } from '@/utils/request';
import type { ApiDataResponse, BasicResponse } from '@/types';
import type { RuleConfig, RuleConfigPageableResponse, RuleConfigRequest, RuleDictItem, RuleFourBlocksPayload, RuleGraphPayload, RuleParamMeta } from './types';
import type { AxiosResponse } from 'axios';
import type { RuleConfig, RuleConfigPageableResponse, RuleConfigRequest, RuleDecisionTreePayload, RuleDictItem, RuleFourBlocksPayload, RuleGraphPayload, RuleParamMeta } from './types';
const req = HttpRequestClient.create<BasicResponse>({
baseURL: '/api',
@@ -50,3 +51,28 @@ export const findRuleConfigGraph = (query: Partial<RuleConfigRequest> = {}): Pro
export const findRuleFourBlocksGraph = (): Promise<ApiDataResponse<RuleFourBlocksPayload>> => {
return req.get('/system/rule/config/graph/four-blocks');
};
export const findRuleDecisionTree = (query: Partial<RuleConfigRequest> = {}): Promise<ApiDataResponse<RuleDecisionTreePayload>> => {
return req.get('/system/rule/config/decision-tree', query);
};
export const exportRuleConfig = (query: Partial<RuleConfigRequest> = {}): Promise<AxiosResponse<Blob>> => {
return originalAxios.post('/api/system/rule/config/export', query, {
responseType: 'blob',
headers: {
'Content-Type': 'application/json;charset=utf-8',
'Accept': 'application/octet-stream',
},
});
};
export const importRuleConfig = (file: File, updateSupport: boolean = true): Promise<BasicResponse> => {
const formData = new FormData();
formData.append('file', file);
formData.append('updateSupport', String(updateSupport));
return originalAxios.post('/api/system/rule/config/importData', formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
}).then((response) => response.data as BasicResponse);
};

View File

@@ -6,10 +6,31 @@
<span class="icon"></span>
<span class="text">规则聚合测试</span>
</a-flex>
<a-button class="ks-sidebar-add" size="small" @click="handleCreate">
<PlusOutlined />
新增
</a-button>
<a-space class="ks-sidebar-actions">
<a-button class="ks-sidebar-add" size="small" @click="handleCreate">
<PlusOutlined />
&#26032;&#22686;
</a-button>
<a-tooltip title="导入 Excel">
<a-button class="rule-config-sidebar-action" size="small" :loading="importLoading" @click="handleImportTrigger">
<UploadOutlined />
导入
</a-button>
</a-tooltip>
<a-tooltip title="导出 Excel">
<a-button class="rule-config-sidebar-action" size="small" :loading="exportLoading" @click="handleExport">
<DownloadOutlined />
导出
</a-button>
</a-tooltip>
</a-space>
<input
ref="importInputRef"
type="file"
accept=".xls,.xlsx"
style="display: none;"
@change="handleImportChange"
/>
</div>
<a-tree
@@ -72,7 +93,15 @@
<div
class="rule-config-right-panel"
:class="{ 'rule-config-right-panel--collapsed': !rightPanelExpanded }"
:style="rightPanelExpanded ? { flexBasis: `${rightPanelWidth}px`, width: `${rightPanelWidth}px` } : undefined"
>
<button
v-if="rightPanelExpanded"
type="button"
class="rule-config-right-panel-edge"
title="左右拖动调整参数配置区域宽度"
@mousedown="onRightPanelResizeMouseDown"
/>
<div class="rule-config-right-panel__inner">
<a-form
ref="formRef"
@@ -96,6 +125,22 @@
>
<a-form-item-rest>
<div class="ks-sidebar-list-param-list">
<div class="ks-sidebar-list-param-head">
<a-row :gutter="10">
<a-col :span="6">
<div class="ks-sidebar-list-param-head-cell">参数作用</div>
</a-col>
<a-col :span="6">
<div class="ks-sidebar-list-param-head-cell">参数键</div>
</a-col>
<a-col :span="9">
<div class="ks-sidebar-list-param-head-cell">参数值</div>
</a-col>
<a-col :span="3">
<div class="ks-sidebar-list-param-head-cell ks-sidebar-list-param-head-cell--actions">操作</div>
</a-col>
</a-row>
</div>
<div class="ks-sidebar-list-param-item" v-for="(item,index) in selectedRuleConfig.params" :key="`param-${index}`">
<a-row :gutter="10">
<a-col :span="6">
@@ -182,10 +227,10 @@
<script setup lang="ts">
import { nextTick, onMounted, ref } from 'vue';
import { type FormInstance, message } from 'ant-design-vue';
import { LeftOutlined, MinusCircleOutlined, PlusCircleOutlined, PlusOutlined, RightOutlined } from '@ant-design/icons-vue';
import { DownloadOutlined, LeftOutlined, MinusCircleOutlined, PlusCircleOutlined, PlusOutlined, RightOutlined, UploadOutlined } from '@ant-design/icons-vue';
import Layout from '../layout.vue';
import RuleKnowledgeGraph from './RuleKnowledgeGraph.vue';
import { createRuleConfig, deleteRuleConfig, findRuleConfigByCode, findRuleConfigByQuery, findRuleParamMeta, updateRuleConfig } from './api';
import { createRuleConfig, deleteRuleConfig, exportRuleConfig, findRuleConfigByCode, findRuleConfigByQuery, findRuleParamMeta, importRuleConfig, updateRuleConfig } from './api';
import type { RuleConfig, RuleConfigParam, RuleConfigRequest, RuleParamMeta } from './types';
const query = ref<RuleConfigRequest>({
@@ -225,6 +270,9 @@ const datasource = ref<RuleConfig[]>([]);
const datasourceTotal = ref<number>(0);
const selectedRuleConfig = ref<RuleConfig>(JSON.parse(JSON.stringify(defaultRuleConfig)));
const formRef = ref<FormInstance | null>(null);
const importInputRef = ref<HTMLInputElement | null>(null);
const importLoading = ref(false);
const exportLoading = ref(false);
const treeData = ref<any[]>([]);
const selectedTreeKeys = ref<string[]>([]);
const expandedTreeKeys = ref<string[]>([]);
@@ -250,15 +298,25 @@ const rightPanelExpanded = ref(true);
const GRAPH_PANE_STORAGE_KEY = 'rule-config-graph-pane-percent';
const GRAPH_PANE_MIN = 18;
const GRAPH_PANE_MAX = 70;
const RIGHT_PANEL_WIDTH_STORAGE_KEY = 'rule-config-right-panel-width';
const RIGHT_PANEL_MIN = 360;
const RIGHT_PANEL_MAX = 960;
const graphPanePercent = ref(32);
const graphPanePercentBeforeFourBlocks = ref<number | null>(null);
const splitRootRef = ref<HTMLElement | null>(null);
const graphRevision = ref(0);
const rightPanelWidth = ref(480);
const clampGraphPercent = (n: number) =>
Math.min(GRAPH_PANE_MAX, Math.max(GRAPH_PANE_MIN, Math.round(n)));
const onRuleGraphDensityChange = (mode: 'overview' | 'full' | 'four-blocks') => {
const clampRightPanelWidth = (n: number) => {
const rootWidth = splitRootRef.value?.getBoundingClientRect().width ?? window.innerWidth;
const dynamicMax = Math.min(RIGHT_PANEL_MAX, Math.max(420, Math.floor(rootWidth * 0.72)));
return Math.min(dynamicMax, Math.max(RIGHT_PANEL_MIN, Math.round(n)));
};
const onRuleGraphDensityChange = (mode: 'decision-tree-simple' | 'decision-tree-binary' | 'decision-tree' | 'full' | 'four-blocks') => {
if (mode === 'four-blocks') {
if (graphPanePercentBeforeFourBlocks.value === null) {
graphPanePercentBeforeFourBlocks.value = graphPanePercent.value;
@@ -295,6 +353,28 @@ const onGraphSplitMouseDown = (e: MouseEvent) => {
window.addEventListener('mouseup', onUp);
};
const onRightPanelResizeMouseDown = (e: MouseEvent) => {
e.preventDefault();
const root = splitRootRef.value;
if (!root) return;
const rect = root.getBoundingClientRect();
const onMove = (ev: MouseEvent) => {
const width = rect.right - ev.clientX;
rightPanelWidth.value = clampRightPanelWidth(width);
};
const onUp = () => {
window.removeEventListener('mousemove', onMove);
window.removeEventListener('mouseup', onUp);
document.body.style.removeProperty('cursor');
document.body.style.removeProperty('user-select');
sessionStorage.setItem(RIGHT_PANEL_WIDTH_STORAGE_KEY, String(rightPanelWidth.value));
};
document.body.style.cursor = 'col-resize';
document.body.style.userSelect = 'none';
window.addEventListener('mousemove', onMove);
window.addEventListener('mouseup', onUp);
};
const kindOptions = [
{ code: 'select', name: '选择' },
{ code: 'assign', name: '分配' },
@@ -581,6 +661,79 @@ const handleMinusParam = (index: number) => {
selectedRuleConfig.value.params = params;
};
const extractFilename = (contentDisposition?: string) => {
if (!contentDisposition) {
return 'rule-config.xlsx';
}
const match = /filename\*=UTF-8''([^;]+)|filename="?([^";]+)"?/i.exec(contentDisposition);
const raw = match?.[1] ?? match?.[2] ?? 'rule-config.xlsx';
try {
return decodeURIComponent(raw.replace(/\+/g, '%20'));
} catch {
return raw;
}
};
const downloadBlob = (blob: Blob, filename: string) => {
const url = window.URL.createObjectURL(blob);
const anchor = document.createElement('a');
anchor.href = url;
anchor.download = filename;
document.body.appendChild(anchor);
anchor.click();
anchor.remove();
window.URL.revokeObjectURL(url);
};
const handleExport = async () => {
exportLoading.value = true;
try {
const response = await exportRuleConfig(query.value as Partial<RuleConfigRequest>);
const filename = extractFilename(response.headers['content-disposition']);
downloadBlob(response.data, filename);
message.success('导出成功');
} catch (err: any) {
message.error(err?.message ?? '导出失败');
} finally {
exportLoading.value = false;
}
};
const handleImportTrigger = () => {
if (importInputRef.value) {
importInputRef.value.value = '';
importInputRef.value.click();
}
};
const handleImportChange = async (event: Event) => {
const input = event.target as HTMLInputElement | null;
const file = input?.files?.[0];
if (!file) {
return;
}
if (!/\.(xls|xlsx)$/i.test(file.name)) {
message.error('请选择 Excel 文件');
if (input) {
input.value = '';
}
return;
}
importLoading.value = true;
try {
const response = await importRuleConfig(file, true);
await load();
message.success(response.msg ?? '导入成功');
} catch (err: any) {
message.error(err?.message ?? '导入失败');
} finally {
importLoading.value = false;
if (input) {
input.value = '';
}
}
};
onMounted(() => {
const raw = sessionStorage.getItem(GRAPH_PANE_STORAGE_KEY);
if (raw) {
@@ -589,6 +742,13 @@ onMounted(() => {
graphPanePercent.value = clampGraphPercent(v);
}
}
const rightPanelRaw = sessionStorage.getItem(RIGHT_PANEL_WIDTH_STORAGE_KEY);
if (rightPanelRaw) {
const width = Number(rightPanelRaw);
if (!Number.isNaN(width)) {
rightPanelWidth.value = clampRightPanelWidth(width);
}
}
loadParamMeta().then(() => load());
});

View File

@@ -135,3 +135,26 @@ export interface RuleFourBlocksPayload {
globalParamsPreview: Record<string, unknown>,
blocks: RuleFourBlockCluster[],
}
export interface RuleDecisionNode {
key: string,
title: string,
nodeType: string,
description?: string | null,
valueText?: string | null,
children?: RuleDecisionNode[] | null,
}
export interface RuleDecisionBlock {
blockId: string,
moduleCode: NullableString,
title: NullableString,
droolsRuleName: NullableString,
salience: number | null,
nodes: RuleDecisionNode[],
}
export interface RuleDecisionTreePayload {
globalParamsPreview: Record<string, unknown>,
blocks: RuleDecisionBlock[],
}