diff --git a/.gitignore b/.gitignore index eaac9be..45ad185 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/auto-solution-admin/src/main/java/com/solution/web/controller/rule/FireRuleController.java b/auto-solution-admin/src/main/java/com/solution/web/controller/rule/FireRuleController.java index 56ba729..159e06c 100644 --- a/auto-solution-admin/src/main/java/com/solution/web/controller/rule/FireRuleController.java +++ b/auto-solution-admin/src/main/java/com/solution/web/controller/rule/FireRuleController.java @@ -97,7 +97,7 @@ public class FireRuleController extends BaseController { /** * 开始执行规则匹配 * @param task 敌方参数 - * @return + * @return */ @PostMapping("/rule") @ApiOperation("开始执行规则匹配") diff --git a/auto-solution-admin/src/main/java/com/solution/web/controller/rule/RuleController.java b/auto-solution-admin/src/main/java/com/solution/web/controller/rule/RuleController.java index b073c30..fc9bfd1 100644 --- a/auto-solution-admin/src/main/java/com/solution/web/controller/rule/RuleController.java +++ b/auto-solution-admin/src/main/java/com/solution/web/controller/rule/RuleController.java @@ -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 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 metas = ruleConfigService.selectParamMetaList(); return success(metas); } -} \ No newline at end of file + + @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 rows = ruleConfigService.exportRuleConfigRows(query == null ? new RuleConfigQuery() : query); + ExcelUtil 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 util = new ExcelUtil<>(RuleConfigExcelRow.class); + List rows = util.importExcel(file.getInputStream()); + String result = ruleConfigService.importRuleConfigRows(rows, updateSupport); + return success(result); + } +} diff --git a/auto-solution-behaviour/src/main/java/com/solution/system/domain/Nodeparameter.java b/auto-solution-behaviour/src/main/java/com/solution/system/domain/Nodeparameter.java index 9c637d8..2373f5a 100644 --- a/auto-solution-behaviour/src/main/java/com/solution/system/domain/Nodeparameter.java +++ b/auto-solution-behaviour/src/main/java/com/solution/system/domain/Nodeparameter.java @@ -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() { diff --git a/auto-solution-rule/src/main/java/com/solution/rule/domain/config/RuleConfigExcelRow.java b/auto-solution-rule/src/main/java/com/solution/rule/domain/config/RuleConfigExcelRow.java new file mode 100644 index 0000000..4830b38 --- /dev/null +++ b/auto-solution-rule/src/main/java/com/solution/rule/domain/config/RuleConfigExcelRow.java @@ -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; +} diff --git a/auto-solution-rule/src/main/java/com/solution/rule/domain/config/vo/RuleDecisionBlockVO.java b/auto-solution-rule/src/main/java/com/solution/rule/domain/config/vo/RuleDecisionBlockVO.java new file mode 100644 index 0000000..3ab8b6a --- /dev/null +++ b/auto-solution-rule/src/main/java/com/solution/rule/domain/config/vo/RuleDecisionBlockVO.java @@ -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 nodes; + + public List safeNodes() { + if (nodes == null) { + nodes = new ArrayList<>(); + } + return nodes; + } +} diff --git a/auto-solution-rule/src/main/java/com/solution/rule/domain/config/vo/RuleDecisionNodeVO.java b/auto-solution-rule/src/main/java/com/solution/rule/domain/config/vo/RuleDecisionNodeVO.java new file mode 100644 index 0000000..80bc1a6 --- /dev/null +++ b/auto-solution-rule/src/main/java/com/solution/rule/domain/config/vo/RuleDecisionNodeVO.java @@ -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 children; + + public List safeChildren() { + if (children == null) { + children = new ArrayList<>(); + } + return children; + } +} diff --git a/auto-solution-rule/src/main/java/com/solution/rule/domain/config/vo/RuleDecisionTreeVO.java b/auto-solution-rule/src/main/java/com/solution/rule/domain/config/vo/RuleDecisionTreeVO.java new file mode 100644 index 0000000..c70d3ad --- /dev/null +++ b/auto-solution-rule/src/main/java/com/solution/rule/domain/config/vo/RuleDecisionTreeVO.java @@ -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 globalParamsPreview; + + @ApiModelProperty("四大规则分块") + private List blocks; + + public Map safeGlobalParamsPreview() { + if (globalParamsPreview == null) { + globalParamsPreview = new LinkedHashMap<>(); + } + return globalParamsPreview; + } + + public List safeBlocks() { + if (blocks == null) { + blocks = new ArrayList<>(); + } + return blocks; + } +} diff --git a/auto-solution-rule/src/main/java/com/solution/rule/service/IRuleConfigService.java b/auto-solution-rule/src/main/java/com/solution/rule/service/IRuleConfigService.java index 9e88dc0..4a6db39 100644 --- a/auto-solution-rule/src/main/java/com/solution/rule/service/IRuleConfigService.java +++ b/auto-solution-rule/src/main/java/com/solution/rule/service/IRuleConfigService.java @@ -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 selectParamMetaList(); + List exportRuleConfigRows(RuleConfigQuery query); + + String importRuleConfigRows(List rows, boolean updateSupport); + /** * 根据当前页规则主数据构建知识图谱(节点与边),参数与任务类型从库批量加载。 */ RuleGraphVO buildKnowledgeGraph(List ruleConfigs); + RuleDecisionTreeVO buildDecisionTree(List ruleConfigs); + /** * 四块规则知识图谱(装备/目标/阵位/航迹):中枢 If/Then + 环形参数,参数值与 {@link #loadEnabledGlobalParams()} 一致。 */ diff --git a/auto-solution-rule/src/main/java/com/solution/rule/service/impl/RuleConfigServiceImpl.java b/auto-solution-rule/src/main/java/com/solution/rule/service/impl/RuleConfigServiceImpl.java index 9d09408..9b63833 100644 --- a/auto-solution-rule/src/main/java/com/solution/rule/service/impl/RuleConfigServiceImpl.java +++ b/auto-solution-rule/src/main/java/com/solution/rule/service/impl/RuleConfigServiceImpl.java @@ -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 exportRuleConfigRows(RuleConfigQuery query) { + List configs = selectRuleConfigList(query == null ? new RuleConfigQuery() : query); + List 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 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 rows, boolean updateSupport) { + if (CollUtil.isEmpty(rows)) { + throw new RuntimeException("Import data cannot be empty"); + } + Map 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 ruleConfigs) { RuleGraphVO graph = new RuleGraphVO(); @@ -276,6 +392,58 @@ public class RuleConfigServiceImpl implements IRuleConfigService { return graph; } + @Override + public RuleDecisionTreeVO buildDecisionTree(List ruleConfigs) { + RuleDecisionTreeVO out = new RuleDecisionTreeVO(); + Map globalPreview = loadEnabledGlobalParams(); + out.setGlobalParamsPreview(new LinkedHashMap<>(globalPreview)); + + List source = ruleConfigs != null ? ruleConfigs : Collections.emptyList(); + List ruleCodes = source.stream() + .filter(r -> r != null && ObjectUtil.isNotEmpty(r.getRuleCode())) + .map(RuleConfig::getRuleCode) + .distinct() + .collect(Collectors.toList()); + + Map> 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> taskTypesByRule = new LinkedHashMap<>(); + if (!ruleCodes.isEmpty()) { + List 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> byModule = source.stream() + .filter(r -> r != null && ObjectUtil.isNotEmpty(r.getModuleCode())) + .collect(Collectors.groupingBy(RuleConfig::getModuleCode, LinkedHashMap::new, Collectors.toList())); + + List blocks = new ArrayList<>(); + for (RuleFourBlockDefinition def : RuleFourBlockDefinition.ordered()) { + List 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 buildDecisionBlockNodes(RuleFourBlockDefinition def, + List moduleRules, + Map> paramsByRule, + Map> taskTypesByRule, + Map globalPreview) { + List 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 moduleRules, + Map> paramsByRule, + Map globalPreview) { + RuleDecisionNodeVO root = decisionNode( + "decision:" + def.getBlockId() + ":input", + "输入参数", + "input_group", + "当前块启用参数会先进入 globalParams,再被规则与 Java 算子读取", + "共 " + countEnabledParams(moduleRules, paramsByRule) + " 个"); + + Map uniqueByKey = new LinkedHashMap<>(); + for (RuleConfig rule : moduleRules) { + if (rule == null || ObjectUtil.isEmpty(rule.getRuleCode())) { + continue; + } + List 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 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 moduleRules, + Map> paramsByRule, + Map> taskTypesByRule, + Map 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 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 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 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 moduleRules, + Map> paramsByRule, + Map globalPreview) { + RuleDecisionNodeVO root = decisionNode( + "decision:" + def.getBlockId() + ":outcome", + "最终结果", + "outcome_group", + "汇总该块在命中规则后可能产出的业务结果", + null); + + LinkedHashSet lines = new LinkedHashSet<>(); + for (RuleConfig rule : moduleRules) { + if (rule == null || ObjectUtil.isEmpty(rule.getRuleCode())) { + continue; + } + List 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 buildFourBlockParamRows(RuleFourBlockDefinition def, Map ruleByCode, List plist, @@ -551,6 +985,35 @@ public class RuleConfigServiceImpl implements IRuleConfigService { return graph; } + private int countEnabledParams(List moduleRules, Map> 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 safeDict(String dictType) { List 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 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 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 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 keys = new HashSet<>(); diff --git a/modeler/src/style.less b/modeler/src/style.less index 8ba69bf..2112a14 100644 --- a/modeler/src/style.less +++ b/modeler/src/style.less @@ -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; } diff --git a/modeler/src/views/decision/rule-config/RuleDecisionBinaryTreePanel.vue b/modeler/src/views/decision/rule-config/RuleDecisionBinaryTreePanel.vue new file mode 100644 index 0000000..06b97d6 --- /dev/null +++ b/modeler/src/views/decision/rule-config/RuleDecisionBinaryTreePanel.vue @@ -0,0 +1,502 @@ + + + + + + + diff --git a/modeler/src/views/decision/rule-config/RuleDecisionTreePanel.vue b/modeler/src/views/decision/rule-config/RuleDecisionTreePanel.vue new file mode 100644 index 0000000..d464a70 --- /dev/null +++ b/modeler/src/views/decision/rule-config/RuleDecisionTreePanel.vue @@ -0,0 +1,415 @@ + + + + + + + diff --git a/modeler/src/views/decision/rule-config/RuleDecisionTreeSimplePanel.vue b/modeler/src/views/decision/rule-config/RuleDecisionTreeSimplePanel.vue new file mode 100644 index 0000000..34b448f --- /dev/null +++ b/modeler/src/views/decision/rule-config/RuleDecisionTreeSimplePanel.vue @@ -0,0 +1,466 @@ + + + + + + + diff --git a/modeler/src/views/decision/rule-config/RuleKnowledgeGraph.vue b/modeler/src/views/decision/rule-config/RuleKnowledgeGraph.vue index 7d5c8d6..fefe06d 100644 --- a/modeler/src/views/decision/rule-config/RuleKnowledgeGraph.vue +++ b/modeler/src/views/decision/rule-config/RuleKnowledgeGraph.vue @@ -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, }" >
- 简要结构 - 完整 + 决策树(简化) + 决策树(二叉树) + 决策树 + 完整图谱 四块分区 - - 简要:仅层级→种类→模块→规则;完整:含参数、任务类型与执行顺序边;四块:业务运算步骤 + 规则项 + 参数(与 globalParams 一致) + + 决策树(简化):把装备、目标、阵位、航迹四个规则块合并成一棵总树,只保留关键参数、核心规则和阶段输出 + + + 决策树(二叉树):按 if / else 方式展示关键参数条件判断、分支去向与最终输出 + + + 决策树:按装备、目标、阵位、航迹四个规则块展示输入参数、运算步骤、命中规则与结果产出 + + + 完整图谱包含参数、任务类型与执行顺序 - 四宫格 · 拖拽画布 / 滚轮缩放 + 四块分区:可拖动画布,滚轮缩放