Compare commits
44 Commits
25e6ac1cbe
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 11e25fd0de | |||
| eb57d2d228 | |||
| bcb0ca03b1 | |||
| 7610076760 | |||
| e52aaa1680 | |||
|
|
fecfb8d39c | ||
|
|
150966824e | ||
|
|
a4d9e8d8eb | ||
|
|
a0d8f555f9 | ||
|
|
705021b391 | ||
|
|
889cc02631 | ||
|
|
cc1e003bc4 | ||
| eeed692ba6 | |||
| b3563a05d6 | |||
| a7c19fb7e7 | |||
| 36809d4033 | |||
| 1dba7584cd | |||
| 35d2766442 | |||
| ce832fb16d | |||
| e9503358d3 | |||
| 3b3370c440 | |||
| d8719c30c6 | |||
| 9ff0e50bba | |||
|
|
2838938cfa | ||
| c4cc3cc30b | |||
|
|
d1f720f691 | ||
|
|
cb1019b7d7 | ||
| 18827cfbe7 | |||
| 3fe32e4ac3 | |||
|
|
168ced6b27 | ||
|
|
499734efe8 | ||
|
|
27c8fc13c6 | ||
|
|
505092bcf4 | ||
|
|
41ba11dc9b | ||
|
|
158512cd12 | ||
|
|
3a3ab0c9c6 | ||
|
|
b08c74260d | ||
|
|
02e9ca26a1 | ||
|
|
8958ecd6dc | ||
|
|
6656479327 | ||
|
|
18ccf490e4 | ||
| 4a0602ce4e | |||
| 8844830afc | |||
| bcc450141e |
@@ -42,6 +42,12 @@ public class BehaviortreeController extends BaseController
|
||||
@Autowired
|
||||
private BehaviortreeProcessor behaviortreeProcessor;
|
||||
|
||||
@GetMapping(value = "/platform/{id}")
|
||||
public AjaxResult fromPlatform(@PathVariable("id") Integer id)
|
||||
{
|
||||
return success(behaviortreeService.findOneByPlatformId(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询行为树主列表
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.solution.web.controller.behaviour;
|
||||
|
||||
import com.solution.common.core.controller.BaseController;
|
||||
import com.solution.common.core.domain.AjaxResult;
|
||||
import com.solution.system.service.HbNodeCommandService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/node/command")
|
||||
public class HbNodeCommandController extends BaseController {
|
||||
|
||||
private final HbNodeCommandService nodeCommandService;
|
||||
|
||||
public HbNodeCommandController(HbNodeCommandService nodeCommandService) {
|
||||
this.nodeCommandService = nodeCommandService;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/all")
|
||||
public AjaxResult all() {
|
||||
return success(nodeCommandService.findAll());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.solution.web.controller.rule;
|
||||
import com.solution.common.core.controller.BaseController;
|
||||
import com.solution.common.core.domain.AjaxResult;
|
||||
import com.solution.rule.domain.FireRuleExecuteDTO;
|
||||
import com.solution.rule.domain.simplerulepojo.Task;
|
||||
import com.solution.rule.service.FireRuleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -68,6 +69,11 @@ public class FireRuleController extends BaseController {
|
||||
return success(ruleService.findAllPlatformComponents());
|
||||
}
|
||||
|
||||
@GetMapping("/platforms/basic")
|
||||
public AjaxResult platformsBasic(){
|
||||
return success(ruleService.findAllBasicPlatformComponents());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据平台id获取平台下所有组件
|
||||
* @param platformId
|
||||
@@ -78,4 +84,15 @@ public class FireRuleController extends BaseController {
|
||||
public AjaxResult getComponents(@PathVariable Integer platformId){
|
||||
return success(ruleService.getComponents(platformId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始执行规则匹配
|
||||
* @param task 敌方参数
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/rule")
|
||||
@ApiOperation("开始执行规则匹配")
|
||||
public AjaxResult execute(@RequestBody Task task){
|
||||
return success(ruleService.executeTask(task));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,4 +49,10 @@ public class SceneController extends BaseController {
|
||||
List<AfsimScenario> list = sceneService.selectSceneList();
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(sceneService.findOneById(id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,11 @@ import com.solution.web.core.graph.GraphEdge;
|
||||
import com.solution.web.core.graph.GraphNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@@ -98,10 +101,17 @@ public class BehaviortreeProcessor {
|
||||
instanceKeyMap.put(node.getKey(), instance);
|
||||
|
||||
if (node.hasParameters()) {
|
||||
// 插入parameter nodeparameter
|
||||
for (Templateparameterdef parameter : node.getParameters()) {
|
||||
Nodeparameter nodeparameter = createNodeParameter(behaviortree, parameter, instance);
|
||||
nodeparameterService.insertNodeparameter(nodeparameter);
|
||||
if (node.isMultiable()) {
|
||||
List<Nodeparameter> nodeparameters = createMultiableNodeparameter(behaviortree, node, instance);
|
||||
for (Nodeparameter nodeparameter : nodeparameters) {
|
||||
nodeparameterService.insertNodeparameter(nodeparameter);
|
||||
}
|
||||
} else {
|
||||
// 插入parameter nodeparameter
|
||||
for (Templateparameterdef parameter : node.getParameters()) {
|
||||
Nodeparameter nodeparameter = createNodeParameter(behaviortree, parameter, instance);
|
||||
nodeparameterService.insertNodeparameter(nodeparameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
nodeKeyIndexMap.put(node.getKey(), index);
|
||||
@@ -148,6 +158,47 @@ public class BehaviortreeProcessor {
|
||||
return connection;
|
||||
}
|
||||
|
||||
private List<Nodeparameter> createMultiableNodeparameter(Behaviortree behaviortree, GraphNode node,
|
||||
Treenodeinstance instance) {
|
||||
|
||||
List<Nodeparameter> nodeparameters = new ArrayList<>();
|
||||
|
||||
Map<Long, List<String>> idValues = new HashMap<>();
|
||||
List<String> tmpValues = null;
|
||||
Map<Long, List<Templateparameterdef>> mappedValues = new HashMap<>();
|
||||
List<Templateparameterdef> tmpDefs = null;
|
||||
|
||||
for (Templateparameterdef parameter : node.getParameters()) {
|
||||
tmpDefs = mappedValues.get(parameter.getId() );
|
||||
if (null == tmpDefs) {
|
||||
tmpDefs = new ArrayList<>();
|
||||
}
|
||||
tmpDefs.add(parameter);
|
||||
mappedValues.put(parameter.getId(), tmpDefs);
|
||||
|
||||
tmpValues = idValues.get(parameter.getId() );
|
||||
if (null == tmpValues) {
|
||||
tmpValues = new ArrayList<>();
|
||||
}
|
||||
tmpValues.add(parameter.getDefaultValue());
|
||||
idValues.put(parameter.getId(), tmpValues);
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (Long id : idValues.keySet()) {
|
||||
tmpValues = idValues.get(id);
|
||||
Nodeparameter nodeparameter = new Nodeparameter();
|
||||
nodeparameter.setTreeId(behaviortree.getId());
|
||||
nodeparameter.setNodeInstanceId(instance.getId());
|
||||
nodeparameter.setParamDefId(id);
|
||||
nodeparameter.setValue(StringUtils.collectionToCommaDelimitedString(tmpValues));
|
||||
nodeparameter.setGroupIndex(index);
|
||||
nodeparameters.add(nodeparameter);
|
||||
index++;
|
||||
}
|
||||
return nodeparameters;
|
||||
}
|
||||
|
||||
private Nodeparameter createNodeParameter(Behaviortree behaviortree, Templateparameterdef parameter,
|
||||
Treenodeinstance instance) {
|
||||
Nodeparameter nodeparameter = new Nodeparameter();
|
||||
@@ -155,6 +206,7 @@ public class BehaviortreeProcessor {
|
||||
nodeparameter.setNodeInstanceId(instance.getId());
|
||||
nodeparameter.setParamDefId(parameter.getId());
|
||||
nodeparameter.setValue(parameter.getDefaultValue());
|
||||
nodeparameter.setGroupIndex(parameter.getGroupIndex());
|
||||
return nodeparameter;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ public class GraphNode implements Serializable {
|
||||
|
||||
private String category;
|
||||
|
||||
private boolean multiable;
|
||||
|
||||
private List<Templateparameterdef> parameters;
|
||||
|
||||
private List<GraphVariable> variables;
|
||||
@@ -61,6 +63,14 @@ public class GraphNode implements Serializable {
|
||||
'}';
|
||||
}
|
||||
|
||||
public boolean isMultiable() {
|
||||
return multiable;
|
||||
}
|
||||
|
||||
public void setMultiable(boolean multiable) {
|
||||
this.multiable = multiable;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,18 @@ public class Behaviortree extends BaseEntity
|
||||
@Excel(name = "储存行为树的节点关系图")
|
||||
private String xmlContent;
|
||||
|
||||
public void setId(Long id)
|
||||
@Excel(name = "平台ID")
|
||||
private Integer platformId;
|
||||
|
||||
public Integer getPlatformId() {
|
||||
return platformId;
|
||||
}
|
||||
|
||||
public void setPlatformId(Integer platformId) {
|
||||
this.platformId = platformId;
|
||||
}
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
@@ -118,14 +129,15 @@ public class Behaviortree extends BaseEntity
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("name", getName())
|
||||
.append("description", getDescription())
|
||||
.append("createdAt", getCreatedAt())
|
||||
.append("updatedAt", getUpdatedAt())
|
||||
.append("englishName", getEnglishName())
|
||||
.append("xmlContent", getXmlContent())
|
||||
.toString();
|
||||
return "Behaviortree{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", createdAt=" + createdAt +
|
||||
", updatedAt=" + updatedAt +
|
||||
", englishName='" + englishName + '\'' +
|
||||
", xmlContent='" + xmlContent + '\'' +
|
||||
", platformId=" + platformId +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.solution.system.domain;
|
||||
/*
|
||||
* This file is part of the kernelstudio package.
|
||||
*
|
||||
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class HbNodeCommand implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String command;
|
||||
|
||||
private String chineseName;
|
||||
|
||||
private String description;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public void setCommand(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public String getChineseName() {
|
||||
return chineseName;
|
||||
}
|
||||
|
||||
public void setChineseName(String chineseName) {
|
||||
this.chineseName = chineseName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,6 +32,8 @@ public class Nodeparameter extends BaseEntity
|
||||
@Excel(name = "节点实例设置的具体参数值 (覆盖模板默认值)")
|
||||
private String value;
|
||||
|
||||
private int groupIndex;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
@@ -80,6 +82,14 @@ public class Nodeparameter extends BaseEntity
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getGroupIndex() {
|
||||
return groupIndex;
|
||||
}
|
||||
|
||||
public void setGroupIndex(int groupIndex) {
|
||||
this.groupIndex = groupIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
|
||||
@@ -42,6 +42,8 @@ public class Nodetemplate extends BaseEntity
|
||||
@Excel(name = "模版类型,节点模版或者条件判断,例如“node”,precondition“")
|
||||
private String templateType;
|
||||
|
||||
private boolean multiable;
|
||||
|
||||
public Nodetemplate() {
|
||||
}
|
||||
|
||||
@@ -53,6 +55,7 @@ public class Nodetemplate extends BaseEntity
|
||||
this.description = template.description;
|
||||
this.englishName = template.englishName;
|
||||
this.templateType = template.templateType;
|
||||
this.multiable = template.multiable;
|
||||
}
|
||||
|
||||
public void setId(Long id)
|
||||
@@ -125,6 +128,14 @@ public class Nodetemplate extends BaseEntity
|
||||
return templateType;
|
||||
}
|
||||
|
||||
public boolean isMultiable() {
|
||||
return multiable;
|
||||
}
|
||||
|
||||
public void setMultiable(boolean multiable) {
|
||||
this.multiable = multiable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
|
||||
@@ -42,6 +42,8 @@ public class Templateparameterdef extends BaseEntity
|
||||
@Excel(name = "判断参数模版是节点的参数模版还是条件的参数模版")
|
||||
private String templateType;
|
||||
|
||||
private int groupIndex;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
@@ -112,6 +114,14 @@ public class Templateparameterdef extends BaseEntity
|
||||
return templateType;
|
||||
}
|
||||
|
||||
public int getGroupIndex() {
|
||||
return groupIndex;
|
||||
}
|
||||
|
||||
public void setGroupIndex(int groupIndex) {
|
||||
this.groupIndex = groupIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
|
||||
@@ -12,6 +12,9 @@ import com.solution.system.domain.Behaviortree;
|
||||
*/
|
||||
public interface BehaviortreeMapper
|
||||
{
|
||||
|
||||
Behaviortree findOneByPlatformId(Integer platformId);
|
||||
|
||||
/**
|
||||
* 查询行为树主
|
||||
*
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.solution.system.mapper;
|
||||
/*
|
||||
* This file is part of the kernelstudio package.
|
||||
*
|
||||
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import com.solution.system.domain.HbNodeCommand;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface HbNodeCommandMapper {
|
||||
|
||||
List<HbNodeCommand> findAll();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.solution.system.service;
|
||||
/*
|
||||
* This file is part of the kernelstudio package.
|
||||
*
|
||||
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import com.solution.system.domain.HbNodeCommand;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface HbNodeCommandService {
|
||||
|
||||
List<HbNodeCommand> findAll();
|
||||
}
|
||||
@@ -12,6 +12,9 @@ import com.solution.system.domain.Behaviortree;
|
||||
*/
|
||||
public interface IBehaviortreeService
|
||||
{
|
||||
|
||||
Behaviortree findOneByPlatformId(Integer platformId);
|
||||
|
||||
/**
|
||||
* 查询行为树主
|
||||
*
|
||||
|
||||
@@ -22,6 +22,12 @@ public class BehaviortreeServiceImpl implements IBehaviortreeService
|
||||
@Autowired
|
||||
private BehaviortreeMapper behaviortreeMapper;
|
||||
|
||||
@Override
|
||||
public Behaviortree findOneByPlatformId(Integer platformId)
|
||||
{
|
||||
return behaviortreeMapper.findOneByPlatformId(platformId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询行为树主
|
||||
*
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.solution.system.service.impl;
|
||||
/*
|
||||
* This file is part of the kernelstudio package.
|
||||
*
|
||||
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import com.solution.system.domain.HbNodeCommand;
|
||||
import com.solution.system.mapper.HbNodeCommandMapper;
|
||||
import com.solution.system.service.HbNodeCommandService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class HbNodeCommandServiceImpl implements HbNodeCommandService {
|
||||
|
||||
private final HbNodeCommandMapper hbNodeCommandMapper;
|
||||
|
||||
public HbNodeCommandServiceImpl(HbNodeCommandMapper hbNodeCommandMapper) {
|
||||
this.hbNodeCommandMapper = hbNodeCommandMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HbNodeCommand> findAll() {
|
||||
return hbNodeCommandMapper.findAll();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="xmlContent" column="xml_content" />
|
||||
</resultMap>
|
||||
|
||||
<select id="findOneByPlatformId" resultMap="BehaviortreeResult">
|
||||
select * from behaviortree
|
||||
where platform_id=#{platformId}
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<sql id="selectBehaviortreeVo">
|
||||
select id, name, description, created_at, updated_at, english_name, xml_content from behaviortree
|
||||
</sql>
|
||||
@@ -44,6 +50,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="updatedAt != null">updated_at,</if>
|
||||
<if test="englishName != null and englishName != ''">english_name,</if>
|
||||
<if test="xmlContent != null">xml_content,</if>
|
||||
<if test="platformId != null">platform_id,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="name != null and name != ''">#{name},</if>
|
||||
@@ -52,6 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="updatedAt != null">#{updatedAt},</if>
|
||||
<if test="englishName != null and englishName != ''">#{englishName},</if>
|
||||
<if test="xmlContent != null">#{xmlContent},</if>
|
||||
<if test="platformId != null">#{platformId},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.solution.system.mapper.HbNodeCommandMapper">
|
||||
|
||||
<resultMap type="com.solution.system.domain.HbNodeCommand" id="HbNodeCommandMapperMap">
|
||||
<result property="id" column="id"/>
|
||||
<result property="command" column="command"/>
|
||||
<result property="description" column="description"/>
|
||||
<result property="chineseName" column="chinese_name"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="findAll" resultMap="HbNodeCommandMapperMap">
|
||||
select *
|
||||
from bh_node_command
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -10,6 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="nodeInstanceId" column="node_instance_id" />
|
||||
<result property="paramDefId" column="param_def_id" />
|
||||
<result property="value" column="value" />
|
||||
<result property="groupIndex" column="group_index" />
|
||||
</resultMap>
|
||||
|
||||
<delete id="deleteByTreeId">
|
||||
@@ -17,7 +18,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</delete>
|
||||
|
||||
<sql id="selectNodeparameterVo">
|
||||
select id, treeId, node_instance_id, param_def_id, value from nodeparameter
|
||||
select id, treeId, node_instance_id, param_def_id,`value`, group_index from nodeparameter
|
||||
</sql>
|
||||
|
||||
<select id="selectNodeparameterList" parameterType="Nodeparameter" resultMap="NodeparameterResult">
|
||||
@@ -41,12 +42,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="nodeInstanceId != null">node_instance_id,</if>
|
||||
<if test="paramDefId != null">param_def_id,</if>
|
||||
<if test="value != null">value,</if>
|
||||
group_index
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="treeId != null">#{treeId},</if>
|
||||
<if test="nodeInstanceId != null">#{nodeInstanceId},</if>
|
||||
<if test="paramDefId != null">#{paramDefId},</if>
|
||||
<if test="value != null">#{value},</if>
|
||||
#{groupIndex}
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
@@ -57,6 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="nodeInstanceId != null">node_instance_id = #{nodeInstanceId},</if>
|
||||
<if test="paramDefId != null">param_def_id = #{paramDefId},</if>
|
||||
<if test="value != null">value = #{value},</if>
|
||||
group_index=#{groupIndex}
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
@@ -12,10 +12,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="description" column="description" />
|
||||
<result property="englishName" column="english_name" />
|
||||
<result property="templateType" column="templete_type" />
|
||||
<result property="multiable" column="is_multiable" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectNodetemplateVo">
|
||||
select id, type, name, logic_handler, description, english_name, templete_type from nodetemplate
|
||||
select id, type, name, logic_handler, description, english_name, templete_type, is_multiable from nodetemplate
|
||||
</sql>
|
||||
|
||||
<select id="selectNodetemplateList" parameterType="Nodetemplate" resultMap="NodetemplateResult">
|
||||
|
||||
@@ -113,6 +113,12 @@
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.34</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
|
||||
@@ -16,18 +16,61 @@
|
||||
rule模块
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<!-- Drools 版本,建议使用稳定版,如 7.74.1.Final 或 8.x 系列 -->
|
||||
<drools.version>7.74.1.Final</drools.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- 1. Drools 核心引擎 -->
|
||||
<dependency>
|
||||
<groupId>org.drools</groupId>
|
||||
<artifactId>drools-core</artifactId>
|
||||
<version>${drools.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.drools</groupId>
|
||||
<artifactId>drools-templates</artifactId>
|
||||
<version>${drools.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 2. KIE API(Drools 属于 KIE 项目的一部分,此依赖提供核心 API) -->
|
||||
<dependency>
|
||||
<groupId>org.kie</groupId>
|
||||
<artifactId>kie-api</artifactId>
|
||||
<version>${drools.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 3. 规则编译器(用于编译 .drl 等规则文件) -->
|
||||
<dependency>
|
||||
<groupId>org.drools</groupId>
|
||||
<artifactId>drools-compiler</artifactId>
|
||||
<version>${drools.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 4. Spring 整合(如果需要和 Spring/Spring Boot 深度整合) -->
|
||||
<dependency>
|
||||
<groupId>org.kie</groupId>
|
||||
<artifactId>kie-spring</artifactId>
|
||||
<version>${drools.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 流式解析工具-->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.15.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 通用工具-->
|
||||
<dependency>
|
||||
<groupId>com.solution</groupId>
|
||||
<artifactId>solution-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.solution.rule.config;
|
||||
|
||||
import org.kie.api.KieBase;
|
||||
import org.kie.api.KieServices;
|
||||
import org.kie.api.builder.KieBuilder;
|
||||
import org.kie.api.builder.KieFileSystem;
|
||||
import org.kie.api.builder.KieRepository;
|
||||
import org.kie.api.builder.Message;
|
||||
import org.kie.api.runtime.KieContainer;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import org.kie.internal.io.ResourceFactory;
|
||||
import org.kie.spring.KModuleBeanFactoryPostProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Configuration
|
||||
public class DroolsConfig {
|
||||
|
||||
private static final String RULE_PATH = "classpath*:rules/**/*.drl";
|
||||
|
||||
private final KieServices kieServices = KieServices.Factory.get();
|
||||
|
||||
/**
|
||||
* 加载规则文件
|
||||
*/
|
||||
@Bean
|
||||
public KieFileSystem kieFileSystem() throws IOException {
|
||||
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
|
||||
|
||||
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
Resource[] resources = resolver.getResources(RULE_PATH);
|
||||
|
||||
for (Resource resource : resources) {
|
||||
kieFileSystem.write(
|
||||
ResourceFactory.newInputStreamResource(resource.getInputStream())
|
||||
.setSourcePath("rules/" + resource.getFilename())
|
||||
);
|
||||
}
|
||||
|
||||
return kieFileSystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建 KieContainer
|
||||
*/
|
||||
@Bean
|
||||
public KieContainer kieContainer(KieFileSystem kieFileSystem) {
|
||||
|
||||
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
|
||||
kieBuilder.buildAll();
|
||||
|
||||
// 检查错误
|
||||
if (kieBuilder.getResults().hasMessages(Message.Level.ERROR)) {
|
||||
throw new RuntimeException("Drools规则编译错误:\n" +
|
||||
kieBuilder.getResults().toString());
|
||||
}
|
||||
|
||||
KieRepository repository = kieServices.getRepository();
|
||||
|
||||
return kieServices.newKieContainer(repository.getDefaultReleaseId());
|
||||
}
|
||||
|
||||
/**
|
||||
* KieBase
|
||||
*/
|
||||
@Bean
|
||||
public KieBase kieBase(KieContainer kieContainer) {
|
||||
return kieContainer.getKieBase();
|
||||
}
|
||||
|
||||
/**
|
||||
* KieSession(推荐加)
|
||||
*/
|
||||
@Bean
|
||||
public KieSession kieSession(KieContainer kieContainer) {
|
||||
return kieContainer.newKieSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* 必须是 static
|
||||
*/
|
||||
@Bean
|
||||
public static KModuleBeanFactoryPostProcessor kiePostProcessor() {
|
||||
return new KModuleBeanFactoryPostProcessor();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.solution.rule.domain;
|
||||
/*
|
||||
* This file is part of the kernelstudio package.
|
||||
*
|
||||
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class BasicPlatform implements Serializable {
|
||||
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,43 +8,12 @@ package com.solution.rule.domain;
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class Platform implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
public class Platform extends BasicPlatform {
|
||||
|
||||
private List<PlatformComponent> components;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public List<PlatformComponent> getComponents() {
|
||||
return components;
|
||||
}
|
||||
@@ -52,5 +21,4 @@ public class Platform implements Serializable {
|
||||
public void setComponents(List<PlatformComponent> components) {
|
||||
this.components = components;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 平台挂载的组件实体类
|
||||
* 对应表 platform_component
|
||||
@@ -29,4 +31,7 @@ public class PlatformComponent {
|
||||
|
||||
@ApiModelProperty(value = "组件数量")
|
||||
private Long num;
|
||||
|
||||
@ApiModelProperty(value = "平台参数(List<String>)")
|
||||
private List<String> platformParams;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.solution.rule.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ComponentJsonDTO {
|
||||
|
||||
//组件类型
|
||||
private String type;
|
||||
//组件名称
|
||||
private String name;
|
||||
|
||||
//组件参数列表
|
||||
private List<PlatformJsonDTO> parameters;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.solution.rule.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ComponentParamJsonDTO {
|
||||
|
||||
// 参数名称
|
||||
private String name;
|
||||
|
||||
private String def;
|
||||
|
||||
// 参数值
|
||||
private String value;
|
||||
|
||||
// 参数单位
|
||||
private String unit;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.solution.rule.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PlatformJsonDTO {
|
||||
// 装备ID
|
||||
private String id;
|
||||
|
||||
// 装备名称
|
||||
private String name;
|
||||
|
||||
// 平台类型 (Platform_type)
|
||||
private String type;
|
||||
|
||||
// 子组件列表(武器、传感器、通信等)
|
||||
private List<ComponentJsonDTO> components;
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.solution.rule.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 规则请求参数
|
||||
*/
|
||||
@Data
|
||||
public class RequestDTO {
|
||||
|
||||
//编队数量
|
||||
private Long formationNum;
|
||||
|
||||
//武装直升机数量
|
||||
private Long gunshipNum;
|
||||
|
||||
//无人机数量
|
||||
private Long droneNum;
|
||||
|
||||
//单兵武器数量
|
||||
private Long singleWeaponNum;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.solution.rule.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.sound.midi.Track;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TaskJsonDTO {
|
||||
|
||||
//任务id
|
||||
private Long attackId;
|
||||
|
||||
//任务名称
|
||||
private String name;
|
||||
|
||||
//任务类型
|
||||
private String dataType;
|
||||
|
||||
//任务下的平台
|
||||
private List<PlatformJsonDTO> platforms;
|
||||
|
||||
//任务轨迹
|
||||
private List<Track> tracks;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.solution.rule.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TrackJsonDTO {
|
||||
|
||||
// 轨迹ID
|
||||
private String id;
|
||||
|
||||
// 轨迹名称
|
||||
private String name;
|
||||
|
||||
// 轨迹点列表
|
||||
private List<TrackPointJsonDTO> points;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.solution.rule.domain.dto;
|
||||
|
||||
public class TrackPointJsonDTO {
|
||||
|
||||
// 轨迹点索引
|
||||
private int index;
|
||||
|
||||
// 经度
|
||||
private double longitude;
|
||||
|
||||
// 纬度
|
||||
private double latitude;
|
||||
|
||||
// 高度(米)
|
||||
private double height;
|
||||
|
||||
// 速度(米/秒)
|
||||
private double speed;
|
||||
|
||||
// 航向角(度)
|
||||
private double heading;
|
||||
|
||||
// 时间点(秒)
|
||||
private double time;
|
||||
}
|
||||
@@ -20,4 +20,7 @@ public class WeaponModelDTO {
|
||||
|
||||
@ApiModelProperty("平台组件")
|
||||
private List<PlatformComponent> components;
|
||||
|
||||
@ApiModelProperty("平台参数(List<String>)")
|
||||
private List<String> platformParams;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.solution.rule.domain.request;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.solution.common.utils.sign.Md5Utils;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 单个属性的定义
|
||||
*/
|
||||
@Data
|
||||
public class Attribute {
|
||||
|
||||
//uuid
|
||||
@JsonProperty("_uuid")
|
||||
private String uuid;
|
||||
/** 属性数据类型(如:float、int、string、bool、enum) */
|
||||
private String attDataType;
|
||||
/** 属性定义(英文标识) */
|
||||
private String attDef;
|
||||
/** 属性默认值 */
|
||||
private String attDefaultValue;
|
||||
/** 属性详细信息 */
|
||||
private Object attDetail;
|
||||
/** 属性说明(中文描述) */
|
||||
private String attExplain;
|
||||
/** 属性ID */
|
||||
private String attId;
|
||||
/** 属性名称(中文) */
|
||||
private String attName;
|
||||
/** 属性取值范围(格式:最小值|最大值) */
|
||||
private String attRange;
|
||||
/** 属性单位 */
|
||||
private String attUnit;
|
||||
/** 是否为内置属性 */
|
||||
private boolean builtIn;
|
||||
/** 枚举信息 */
|
||||
private String enumInfo;
|
||||
/** 是否为关键属性 */
|
||||
private boolean isKey;
|
||||
/** 是否为公共属性 */
|
||||
private boolean isPublic;
|
||||
/** 是否可搜索 */
|
||||
private boolean isSearch;
|
||||
/** 是否为文本域 */
|
||||
private boolean isTextarea;
|
||||
/** 模型信息(可以是对象或数组,此处定义为具体对象) */
|
||||
private List<ModelInfo> mdlInfo;
|
||||
/** 是否只读(0-可编辑,1-只读) */
|
||||
private int readOnly;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.solution.rule.domain.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 字典项实体
|
||||
*/
|
||||
@Data
|
||||
public class DictItem {
|
||||
/** 编码 */
|
||||
private String code;
|
||||
/** 说明 */
|
||||
private String explain;
|
||||
/** 名称 */
|
||||
private String name;
|
||||
/** 唯一标识符 */
|
||||
private String uuid;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.solution.rule.domain.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Equipments {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.solution.rule.domain.request;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Force {
|
||||
|
||||
//对象句柄
|
||||
private String ObjectHandle;
|
||||
|
||||
//类型
|
||||
private Integer type;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.solution.rule.domain.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 阵营实体
|
||||
*/
|
||||
@Data
|
||||
public class ForceSides {
|
||||
|
||||
//分组类型
|
||||
private String groupType;
|
||||
|
||||
private List<Force> postures;
|
||||
|
||||
//对象句柄
|
||||
private String ObjectHandle;
|
||||
|
||||
//阵营名称
|
||||
private String ForceSideName;
|
||||
|
||||
//作战目标
|
||||
private String warGoal;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.solution.rule.domain.request;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 模型信息实体
|
||||
*/
|
||||
@Data
|
||||
public class ModelInfo {
|
||||
/** 模型ID */
|
||||
@JsonProperty("_id")
|
||||
private String id;
|
||||
/** 类别 */
|
||||
private String category;
|
||||
/** 分类ID */
|
||||
private String classifyId;
|
||||
/** 分类名称 */
|
||||
private String classifyName;
|
||||
/** 创建时间(时间戳) */
|
||||
private long createTime;
|
||||
/** 字典项列表 */
|
||||
private List<DictItem> dict;
|
||||
/** 模型系统ID */
|
||||
private int mxSysId;
|
||||
/** 名称 */
|
||||
private String name;
|
||||
/** 角色ID */
|
||||
private int roleId;
|
||||
/** 空间ID */
|
||||
private int spaceId;
|
||||
/** 更新时间(时间戳) */
|
||||
private long updateTime;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.solution.rule.domain.request;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 引用属性对象
|
||||
*/
|
||||
@Data
|
||||
public class RefAttributeObject {
|
||||
|
||||
//属性列表
|
||||
private Map<String, List<Attribute>> attributes;
|
||||
|
||||
private TrackParam trackParam;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.solution.rule.domain.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 接收智唐接口实体
|
||||
*/
|
||||
@Data
|
||||
public class RequestDTO {
|
||||
|
||||
//引用属性对象(设备属性定义)
|
||||
private RefAttributeObject refAttributeObject;
|
||||
|
||||
//阵营列表
|
||||
private List<ForceSides> forceSides;
|
||||
|
||||
//装备列表
|
||||
private List<Equipments> equipments;
|
||||
|
||||
//private List<Tasks> tasks;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.solution.rule.domain.request;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Track {
|
||||
//航迹名称
|
||||
private String name;
|
||||
//航迹开始时间
|
||||
private int StartTime;
|
||||
//航迹结束时间
|
||||
private int EndTime;
|
||||
//航迹类型
|
||||
private String TrackType;
|
||||
//航迹高度类型
|
||||
private String HeightType;
|
||||
//航迹海面类型
|
||||
private String seaType;
|
||||
//航迹点集合
|
||||
private List<TrackPoint> TrackPoints;
|
||||
//航迹所属阵营
|
||||
private String Color;
|
||||
//航迹总点数
|
||||
private int PointCount;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.solution.rule.domain.request;
|
||||
|
||||
import javax.sound.midi.Track;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 航迹参数
|
||||
*/
|
||||
public class TrackParam {
|
||||
|
||||
private Map<String, List<Track>> tracks;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.solution.rule.domain.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 航迹节点实体
|
||||
*/
|
||||
@Data
|
||||
public class TrackPoint {
|
||||
//航迹索引
|
||||
private String index;
|
||||
//经度
|
||||
private String longitude;
|
||||
//纬度
|
||||
private String latitude;
|
||||
//高度
|
||||
private String height;
|
||||
//航速
|
||||
private String speed;
|
||||
//航向角
|
||||
private String psia;
|
||||
//时间
|
||||
private String time;
|
||||
//活动
|
||||
private String active;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.solution.rule.domain.simplerulepojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ComponentParam {
|
||||
|
||||
//唯一标识符
|
||||
private String uuid;
|
||||
|
||||
//组件默认参数
|
||||
private String attDefaultValue;
|
||||
|
||||
//参数单位
|
||||
private String attExplain;
|
||||
|
||||
//组件数量
|
||||
private Integer number;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.solution.rule.domain.simplerulepojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class Coordinate {
|
||||
|
||||
//经度
|
||||
private BigDecimal longitude;
|
||||
|
||||
//纬度
|
||||
private BigDecimal latitude;
|
||||
|
||||
//高度
|
||||
private Integer height;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.solution.rule.domain.simplerulepojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SubComponents {
|
||||
|
||||
//设备id
|
||||
private String deviceId;
|
||||
|
||||
//设备名称
|
||||
private String deviceName;
|
||||
|
||||
//设备组件参数
|
||||
private List<ComponentParam> componentParams;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.solution.rule.domain.simplerulepojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 简单任务实体
|
||||
*/
|
||||
@Data
|
||||
public class Task {
|
||||
|
||||
//任务id
|
||||
private String id;
|
||||
|
||||
//任务名称
|
||||
private String drawName;
|
||||
|
||||
//任务类型
|
||||
private String dataType;
|
||||
|
||||
//任务所属阵营
|
||||
private String side;
|
||||
|
||||
//任务威胁等级(1-3)
|
||||
private String threatLevel;
|
||||
|
||||
//任务航迹
|
||||
private List<TrackPoints> trackPoints;
|
||||
|
||||
//任务武器
|
||||
private List<Weapon> taskWeapons;
|
||||
|
||||
//任务目标id
|
||||
private String targetId;
|
||||
|
||||
//作战区经纬高
|
||||
private List<Coordinate> warZoneLocation;
|
||||
|
||||
//防区经纬高
|
||||
private List<Coordinate> defZoneLocation;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.solution.rule.domain.simplerulepojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class TrackPoints extends Coordinate{
|
||||
|
||||
// 轨迹索引
|
||||
private Integer index;
|
||||
|
||||
// // 轨迹点经度
|
||||
// private BigDecimal longitude;
|
||||
//
|
||||
// // 轨迹点纬度
|
||||
// private BigDecimal latitude;
|
||||
//
|
||||
// // 轨迹点高度
|
||||
// private Integer height;
|
||||
|
||||
//速度
|
||||
private Integer speed;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.solution.rule.domain.simplerulepojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Weapon {
|
||||
|
||||
//装备id
|
||||
private String equipmentId;
|
||||
|
||||
//装备名称
|
||||
private String name;
|
||||
|
||||
//装备类型
|
||||
private String supportType;
|
||||
|
||||
//装备组件
|
||||
private List<SubComponents> components;
|
||||
|
||||
//装备部署位置(经纬高)
|
||||
private Coordinate coordinate;
|
||||
|
||||
//武器数量
|
||||
private Integer number;
|
||||
|
||||
//武器命中率
|
||||
private Double hitRate;
|
||||
|
||||
//目标id
|
||||
private String targetId;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.solution.rule.domain.simplerulepojo.fact;
|
||||
|
||||
import com.solution.rule.domain.simplerulepojo.Task;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FactTask {
|
||||
|
||||
private Task blueTask;
|
||||
|
||||
private Task redTask;
|
||||
}
|
||||
@@ -7,10 +7,12 @@ import com.solution.common.constant.PlatformAndModuleConstants;
|
||||
import com.solution.rule.domain.PlatformComponent;
|
||||
import com.solution.rule.domain.RuleParam;
|
||||
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||
import com.solution.rule.handler.opponent.OpponentParamChain;
|
||||
import com.solution.rule.domain.vo.ComponentCountVO;
|
||||
import com.solution.rule.domain.vo.PlatformWeaponAggregateVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -26,6 +28,9 @@ public class WarplaneHandler extends AbstractRuleChainHandler {
|
||||
// 组件数量增量常量
|
||||
private static final long COMPONENT_COUNT_INCREMENT = 1;
|
||||
|
||||
@Resource
|
||||
private OpponentParamChain opponentParamChain;
|
||||
|
||||
@Override
|
||||
public RuleParam doHandler(RuleParam ruleParam) {
|
||||
// 1. 参数校验
|
||||
@@ -52,12 +57,16 @@ public class WarplaneHandler extends AbstractRuleChainHandler {
|
||||
if(component.getName().equals(databaseWeapon.getComponentName())){
|
||||
PlatformComponent component1 = new PlatformComponent();
|
||||
component1.setName(databaseWeapon.getComponentName());
|
||||
// TODO
|
||||
component1.setPlatformParams(CollUtil.isNotEmpty(component.getPlatformParams())
|
||||
? component.getPlatformParams()
|
||||
: dto.getPlatformParams());
|
||||
opponentParamChain.apply(ruleParam, dto, componentList);
|
||||
if(databaseWeapon.getCount() > component.getNum()){
|
||||
component1.setNum(component.getNum() + COMPONENT_COUNT_INCREMENT);
|
||||
}else {
|
||||
component1.setNum(databaseWeapon.getCount());
|
||||
}
|
||||
//TODO 补充基本信息 暂未完成
|
||||
componentList.add(component1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.solution.rule.handler.opponent;
|
||||
|
||||
public abstract class AbstractOpponentParamHandler {
|
||||
|
||||
private AbstractOpponentParamHandler next;
|
||||
|
||||
public abstract void handle(OpponentParamContext context);
|
||||
|
||||
protected void doNext(OpponentParamContext context) {
|
||||
if (next == null) return;
|
||||
next.handle(context);
|
||||
}
|
||||
|
||||
public void setNext(AbstractOpponentParamHandler next) {
|
||||
this.next = next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.solution.rule.handler.opponent;
|
||||
|
||||
import com.solution.rule.domain.PlatformComponent;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Order(2)
|
||||
public class Ammo20Handler extends AbstractOpponentParamHandler {
|
||||
|
||||
@Override
|
||||
public void handle(OpponentParamContext context) {
|
||||
Long ammo = context.getParamLong("ammo");
|
||||
if (ammo != null && ammo <= 20) {
|
||||
PlatformComponent reaction = new PlatformComponent();
|
||||
reaction.setType("weapon");
|
||||
reaction.setName("reaction_ammo_le_20");
|
||||
reaction.setNum(1L);
|
||||
context.addReactionComponent(reaction);
|
||||
}
|
||||
doNext(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.solution.rule.handler.opponent;
|
||||
|
||||
import com.solution.rule.domain.PlatformComponent;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Order(3)
|
||||
public class Distance50Handler extends AbstractOpponentParamHandler {
|
||||
|
||||
@Override
|
||||
public void handle(OpponentParamContext context) {
|
||||
Long distance = context.getParamLong("distance");
|
||||
if (distance != null && distance <= 50) {
|
||||
PlatformComponent reaction = new PlatformComponent();
|
||||
reaction.setType("weapon");
|
||||
reaction.setName("reaction_distance_le_50");
|
||||
reaction.setNum(1L);
|
||||
context.addReactionComponent(reaction);
|
||||
}
|
||||
doNext(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.solution.rule.handler.opponent;
|
||||
|
||||
import com.solution.rule.domain.PlatformComponent;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Order(4)
|
||||
public class FallbackHandler extends AbstractOpponentParamHandler {
|
||||
|
||||
@Override
|
||||
public void handle(OpponentParamContext context) {
|
||||
PlatformComponent reaction = new PlatformComponent();
|
||||
reaction.setType("weapon");
|
||||
reaction.setName("reaction_default");
|
||||
reaction.setNum(0L);
|
||||
context.addReactionComponent(reaction);
|
||||
doNext(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.solution.rule.handler.opponent;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.solution.rule.domain.PlatformComponent;
|
||||
import com.solution.rule.domain.RuleParam;
|
||||
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class OpponentParamChain {
|
||||
|
||||
@Resource
|
||||
private List<AbstractOpponentParamHandler> handlers;
|
||||
|
||||
private AbstractOpponentParamHandler first;
|
||||
|
||||
@PostConstruct
|
||||
private void construct() {
|
||||
if (CollUtil.isEmpty(handlers)) {
|
||||
return;
|
||||
}
|
||||
this.first = handlers.get(0);
|
||||
for (int i = 0; i < handlers.size(); i++) {
|
||||
AbstractOpponentParamHandler current = handlers.get(i);
|
||||
AbstractOpponentParamHandler next = (i == handlers.size() - 1) ? null : handlers.get(i + 1);
|
||||
current.setNext(next);
|
||||
}
|
||||
}
|
||||
|
||||
public void apply(RuleParam ruleParam, WeaponModelDTO dto, List<PlatformComponent> resultComponents) {
|
||||
if (first == null) return;
|
||||
OpponentParamContext context = new OpponentParamContext(ruleParam, dto, resultComponents);
|
||||
first.handle(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.solution.rule.handler.opponent;
|
||||
|
||||
import com.solution.rule.domain.PlatformComponent;
|
||||
import com.solution.rule.domain.RuleParam;
|
||||
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Getter
|
||||
public class OpponentParamContext {
|
||||
|
||||
private static final Pattern NUMBER_PATTERN = Pattern.compile("(\\d+(?:\\.\\d+)?)");
|
||||
|
||||
private final RuleParam ruleParam;
|
||||
private final WeaponModelDTO weaponModelDTO;
|
||||
private final List<PlatformComponent> resultComponents;
|
||||
private final Map<String, String> paramMap;
|
||||
|
||||
public OpponentParamContext(RuleParam ruleParam, WeaponModelDTO weaponModelDTO, List<PlatformComponent> resultComponents) {
|
||||
this.ruleParam = ruleParam;
|
||||
this.weaponModelDTO = weaponModelDTO;
|
||||
this.resultComponents = resultComponents;
|
||||
this.paramMap = parseParams(weaponModelDTO);
|
||||
}
|
||||
|
||||
public String getParamRaw(String key) {
|
||||
if (key == null) return null;
|
||||
return paramMap.get(key.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public Long getParamLong(String key) {
|
||||
String raw = getParamRaw(key);
|
||||
if (raw == null) return null;
|
||||
Matcher m = NUMBER_PATTERN.matcher(raw);
|
||||
if (!m.find()) return null;
|
||||
try {
|
||||
return (long) Double.parseDouble(m.group(1));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addReactionComponent(PlatformComponent component) {
|
||||
if (component == null || component.getName() == null) return;
|
||||
for (PlatformComponent existing : resultComponents) {
|
||||
if (component.getName().equals(existing.getName())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
resultComponents.add(component);
|
||||
}
|
||||
|
||||
private static Map<String, String> parseParams(WeaponModelDTO dto) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (dto == null || dto.getPlatformParams() == null) return map;
|
||||
for (String item : dto.getPlatformParams()) {
|
||||
if (item == null) continue;
|
||||
String s = item.trim();
|
||||
if (s.isEmpty()) continue;
|
||||
|
||||
String[] parts;
|
||||
if (s.contains("=")) {
|
||||
parts = s.split("=", 2);
|
||||
} else if (s.contains(":")) {
|
||||
parts = s.split(":", 2);
|
||||
} else if (s.contains(":")) {
|
||||
parts = s.split(":", 2);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
if (parts.length != 2) continue;
|
||||
|
||||
String key = parts[0].trim().toLowerCase(Locale.ROOT);
|
||||
String val = parts[1].trim();
|
||||
if (!key.isEmpty() && !val.isEmpty()) {
|
||||
map.put(key, val);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
## opponent(对方参数嵌套责任链)说明
|
||||
|
||||
本目录新增了一套**“嵌套责任链”**,用于在已有规则链(`AbstractRuleChainHandler` / `RuleChainHandler`)执行过程中,再额外对“对方传入的平台参数”做二次判断,并把**我方的反应**写入到 `RuleParam.resultWeapons` 对应平台的 `components` 中。
|
||||
|
||||
> 你原本已经在用“规则链”处理 `RuleParam`;这里是在 `WarplaneHandler` 内部再次调用一条新的链,因此属于 **责任链嵌套责任链**。
|
||||
|
||||
---
|
||||
|
||||
### 1. 改动点概览(这个目录配套的改动)
|
||||
|
||||
- **`WeaponModelDTO` 增加字段**
|
||||
- `platformParams: List<String>`
|
||||
- 用于接收平台维度的参数列表(例如对方速度、弹量、距离等)。
|
||||
|
||||
- **`PlatformComponent` 增加字段**
|
||||
- `platformParams: List<String>`
|
||||
- 用于在“组件维度”也能承载同样的参数(如果你希望参数挂在组件上)。
|
||||
|
||||
- **`WarplaneHandler`(第55行 `// TODO` 下方)接入嵌套链**
|
||||
- 将平台参数透传到结果组件 `component1.platformParams`
|
||||
- 优先取 `component.platformParams`
|
||||
- 若组件没传,则取 `dto.platformParams`
|
||||
- 调用 `OpponentParamChain.apply(ruleParam, dto, componentList)`:
|
||||
- 读取 `dto.platformParams` 中的对方参数
|
||||
- 按责任链规则生成“反应组件”
|
||||
- 把反应组件加入当前平台的 `componentList`(最终进入 `RuleParam.resultWeapons`)
|
||||
|
||||
---
|
||||
|
||||
### 2. 对方参数的传参格式约定
|
||||
|
||||
目前解析逻辑位于 `OpponentParamContext`,支持以下分隔符:
|
||||
|
||||
- `key=value`
|
||||
- `key:value`
|
||||
- `key:value`(中文冒号)
|
||||
|
||||
并会从 `value` 中提取**第一个数字**作为判断依据(例如 `200km` 会提取为 `200`)。
|
||||
|
||||
建议前端/调用方传参示例:
|
||||
|
||||
```text
|
||||
["speed=200km", "ammo=20", "distance=50km"]
|
||||
```
|
||||
|
||||
目前内置识别的 key:
|
||||
|
||||
- `speed`:速度
|
||||
- `ammo`:弹量
|
||||
- `distance`:距离
|
||||
|
||||
---
|
||||
|
||||
### 3. 目录结构与职责(类说明)
|
||||
|
||||
- **`OpponentParamChain`**
|
||||
- 责任链的“组装与入口”。
|
||||
- Spring `@Component` + `@PostConstruct`:自动获取容器中的 `AbstractOpponentParamHandler` 实现列表并按顺序串起来。
|
||||
- `apply(ruleParam, dto, resultComponents)`:对外入口,创建上下文并触发链路执行。
|
||||
|
||||
- **`AbstractOpponentParamHandler`**
|
||||
- 对方参数链的抽象 Handler。
|
||||
- 只负责:
|
||||
- `handle(context)`:当前节点处理
|
||||
- `doNext(context)`:传递到下一个节点
|
||||
|
||||
- **`OpponentParamContext`**
|
||||
- 链路执行上下文(把链执行需要的对象集中起来):
|
||||
- `RuleParam ruleParam`:当前规则执行参数
|
||||
- `WeaponModelDTO weaponModelDTO`:当前处理的平台 DTO(承载 `platformParams`)
|
||||
- `List<PlatformComponent> resultComponents`:本平台最终要返回的组件列表(也就是要写入 `resultWeapons` 的列表)
|
||||
- 关键能力:
|
||||
- `getParamLong(key)`:从 `platformParams` 中按 key 取值并解析出数字
|
||||
- `addReactionComponent(component)`:把“反应组件”加入 `resultComponents`(按 name 做简单去重,避免循环里重复加入)
|
||||
|
||||
---
|
||||
|
||||
### 4. 当前内置的 4 个链节点(最少四个)
|
||||
|
||||
这 4 个节点都实现了 `AbstractOpponentParamHandler`,并通过 `@Order` 控制执行顺序:
|
||||
|
||||
- **`Speed200Handler`(@Order(1))**
|
||||
- 条件:`speed >= 200`
|
||||
- 反应:加入组件
|
||||
- `name = reaction_speed_ge_200`
|
||||
- `type = weapon`
|
||||
- `num = 1`
|
||||
|
||||
- **`Ammo20Handler`(@Order(2))**
|
||||
- 条件:`ammo <= 20`
|
||||
- 反应:加入组件
|
||||
- `name = reaction_ammo_le_20`
|
||||
- `type = weapon`
|
||||
- `num = 1`
|
||||
|
||||
- **`Distance50Handler`(@Order(3))**
|
||||
- 条件:`distance <= 50`
|
||||
- 反应:加入组件
|
||||
- `name = reaction_distance_le_50`
|
||||
- `type = weapon`
|
||||
- `num = 1`
|
||||
|
||||
- **`FallbackHandler`(@Order(4))**
|
||||
- 兜底:无论是否命中其它规则,都加入一个默认反应(便于你观察链是否运行)
|
||||
- 反应:加入组件
|
||||
- `name = reaction_default`
|
||||
- `type = weapon`
|
||||
- `num = 0`
|
||||
|
||||
> 注意:这些“反应组件”目前只是用 `PlatformComponent` 承载并加入到返回的 `components` 列表中,保证**一定能落到 `RuleParam.resultWeapons`**。
|
||||
|
||||
---
|
||||
|
||||
### 5. 如何扩展新规则(你后续要加更多链节点时)
|
||||
|
||||
按照下面步骤即可:
|
||||
|
||||
1. 在本目录新增一个类,继承 `AbstractOpponentParamHandler`
|
||||
2. 加上 `@Component` 与 `@Order(n)`(n 决定执行顺序)
|
||||
3. 在 `handle` 中从 `context.getParamLong("xxx")` 取值判断
|
||||
4. 组装一个 `PlatformComponent` 作为“反应”,调用 `context.addReactionComponent(...)`
|
||||
5. 最后 `doNext(context)` 传递到下一节点
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.solution.rule.handler.opponent;
|
||||
|
||||
import com.solution.rule.domain.PlatformComponent;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Order(1)
|
||||
public class Speed200Handler extends AbstractOpponentParamHandler {
|
||||
|
||||
@Override
|
||||
public void handle(OpponentParamContext context) {
|
||||
Long speed = context.getParamLong("speed");
|
||||
if (speed != null && speed >= 200) {
|
||||
PlatformComponent reaction = new PlatformComponent();
|
||||
reaction.setType("weapon");
|
||||
reaction.setName("reaction_speed_ge_200");
|
||||
reaction.setNum(1L);
|
||||
context.addReactionComponent(reaction);
|
||||
}
|
||||
doNext(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.solution.rule.mapper;
|
||||
|
||||
import com.solution.rule.domain.BasicPlatform;
|
||||
import com.solution.rule.domain.Platform;
|
||||
import com.solution.rule.domain.PlatformComponent;
|
||||
import com.solution.rule.domain.vo.ComponentCountVO;
|
||||
@@ -44,4 +45,6 @@ public interface FireRuleMapper {
|
||||
List<Platform> findPlatformComponents(Integer scenarioId);
|
||||
|
||||
List<Platform> findAllPlatformComponents();
|
||||
|
||||
List<BasicPlatform> findAllBasicPlatformComponents();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
//package com.solution.rule.parser;
|
||||
//
|
||||
//import com.fasterxml.jackson.core.JsonParser;
|
||||
//import com.fasterxml.jackson.core.JsonToken;
|
||||
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import java.io.IOException;
|
||||
//import java.util.*;
|
||||
//
|
||||
//public class JsonStreamParser {
|
||||
//
|
||||
// // 核心:解析所有集合 → 内存关联ID → 组装完整数据
|
||||
// public List<AssembledWeapon> parseAndAssemble(HttpServletRequest request) throws IOException {
|
||||
// ObjectMapper mapper = new ObjectMapper();
|
||||
// try (JsonParser parser = mapper.getFactory().createParser(request.getInputStream())) {
|
||||
//
|
||||
// // ========== 步骤1:流式解析,把所有关联集合存到内存 ==========
|
||||
// String version = null;
|
||||
// // 存储所有集合:key=集合名(weaponList/weaponParams),value=数据列表
|
||||
// Map<String, List<Map<String, Object>>> allCollections = new HashMap<>();
|
||||
//
|
||||
// // 解析状态
|
||||
// String currentCollection = null;
|
||||
// Map<String, Object> currentItem = null;
|
||||
//
|
||||
// JsonToken token;
|
||||
// while ((token = parser.nextToken()) != null) {
|
||||
// switch (token) {
|
||||
// case START_OBJECT:
|
||||
// if (currentCollection != null) currentItem = new HashMap<>();
|
||||
// break;
|
||||
// case END_OBJECT:
|
||||
// if (currentCollection != null && currentItem != null) {
|
||||
// allCollections.get(currentCollection).add(currentItem);
|
||||
// currentItem = null;
|
||||
// }
|
||||
// break;
|
||||
// case START_ARRAY:
|
||||
// currentCollection = parser.getCurrentName();
|
||||
// allCollections.putIfAbsent(currentCollection, new ArrayList<>());
|
||||
// break;
|
||||
// case END_ARRAY:
|
||||
// currentCollection = null;
|
||||
// break;
|
||||
// case FIELD_NAME:
|
||||
// String field = parser.getCurrentName();
|
||||
// // 解析版本号
|
||||
// if ("version".equals(field) && isInMeta(parser)) {
|
||||
// version = parser.nextTextValue();
|
||||
// break;
|
||||
// }
|
||||
// // 解析普通字段
|
||||
// if (currentItem != null) {
|
||||
// parser.nextToken();
|
||||
// currentItem.put(field, getValue(parser));
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // ========== 步骤2:核心!通过ID关联匹配,组装完整数据 ==========
|
||||
// return assembleFullWeaponData(allCollections);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 【核心逻辑】ID关联匹配:武器列表 + 参数列表 → 完整武器
|
||||
// */
|
||||
// private List<AssembledWeapon> assembleFullWeaponData(Map<String, List<Map<String, Object>>> allCollections) {
|
||||
// List<AssembledWeapon> result = new ArrayList<>();
|
||||
//
|
||||
// // 1. 获取武器主列表
|
||||
// List<Map<String, Object>> weaponList = allCollections.getOrDefault("weaponList", Collections.emptyList());
|
||||
// // 2. 获取武器参数列表
|
||||
// List<Map<String, Object>> paramList = allCollections.getOrDefault("weaponParams", Collections.emptyList());
|
||||
//
|
||||
// // 3. 构建【ID -> 参数】索引Map(O(1)快速匹配,效率最高)
|
||||
// Map<Long, Map<String, Object>> paramIndex = new HashMap<>();
|
||||
// for (Map<String, Object> param : paramList) {
|
||||
// Long weaponId = Long.valueOf(param.get("weaponId").toString());
|
||||
// paramIndex.put(weaponId, param);
|
||||
// }
|
||||
//
|
||||
// // 4. 遍历武器,通过ID匹配参数,组装完整对象
|
||||
// for (Map<String, Object> weapon : weaponList) {
|
||||
// AssembledWeapon fullWeapon = new AssembledWeapon();
|
||||
// Long weaponId = Long.valueOf(weapon.get("id").toString());
|
||||
//
|
||||
// // 填充基础信息
|
||||
// fullWeapon.setId(weaponId);
|
||||
// fullWeapon.setName((String) weapon.get("name"));
|
||||
//
|
||||
// // 匹配参数(通过ID)
|
||||
// Map<String, Object> param = paramIndex.get(weaponId);
|
||||
// if (param != null) {
|
||||
// fullWeapon.setDamage(Integer.valueOf(param.get("damage").toString()));
|
||||
// fullWeapon.setMagazine(Integer.valueOf(param.get("magazine").toString()));
|
||||
// fullWeapon.setType((String) param.get("type"));
|
||||
// }
|
||||
//
|
||||
// result.add(fullWeapon);
|
||||
// }
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// // ---------------- 工具方法 ----------------
|
||||
// private boolean isInMeta(JsonParser parser) {
|
||||
// return parser.getParsingContext().getParent() != null
|
||||
// && "meta".equals(parser.getParsingContext().getParent().getCurrentName());
|
||||
// }
|
||||
//
|
||||
// private Object getValue(JsonParser parser) throws IOException {
|
||||
// if (parser.getCurrentToken().isNumeric()) return parser.getLongValue();
|
||||
// if (parser.getCurrentToken() == JsonToken.VALUE_STRING) return parser.getText();
|
||||
// if (parser.getCurrentToken() == JsonToken.VALUE_TRUE) return true;
|
||||
// if (parser.getCurrentToken() == JsonToken.VALUE_FALSE) return false;
|
||||
// return null;
|
||||
// }
|
||||
//}
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.solution.rule.service;
|
||||
|
||||
import com.solution.rule.domain.BasicPlatform;
|
||||
import com.solution.rule.domain.FireRuleExecuteDTO;
|
||||
import com.solution.rule.domain.Platform;
|
||||
import com.solution.rule.domain.PlatformComponent;
|
||||
import com.solution.rule.domain.simplerulepojo.Task;
|
||||
import com.solution.rule.domain.vo.PlatformComponentNamesVO;
|
||||
import com.solution.rule.domain.vo.PlatformWeaponAggregateVO;
|
||||
|
||||
@@ -47,4 +49,13 @@ public interface FireRuleService {
|
||||
List<Platform> findPlatformComponents(Integer scenarioId);
|
||||
|
||||
List<Platform> findAllPlatformComponents();
|
||||
|
||||
List<BasicPlatform> findAllBasicPlatformComponents();
|
||||
|
||||
/**
|
||||
* 开始执行规则匹配
|
||||
* @param task
|
||||
* @return
|
||||
*/
|
||||
Task executeTask(Task task);
|
||||
}
|
||||
|
||||
@@ -3,19 +3,22 @@ package com.solution.rule.service.impl;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.solution.common.constant.ExceptionConstants;
|
||||
import com.solution.rule.domain.FireRuleExecuteDTO;
|
||||
import com.solution.rule.domain.Platform;
|
||||
import com.solution.rule.domain.PlatformComponent;
|
||||
import com.solution.rule.domain.RuleParam;
|
||||
import com.solution.rule.domain.*;
|
||||
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||
import com.solution.rule.domain.simplerulepojo.Task;
|
||||
import com.solution.rule.domain.simplerulepojo.Weapon;
|
||||
import com.solution.rule.domain.vo.ComponentCountVO;
|
||||
import com.solution.rule.domain.vo.PlatformComponentNamesVO;
|
||||
import com.solution.rule.domain.vo.PlatformWeaponAggregateVO;
|
||||
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||
import com.solution.rule.mapper.FireRuleMapper;
|
||||
import com.solution.rule.service.FireRuleService;
|
||||
import com.solution.rule.simpstrategy.FireRUleType;
|
||||
import com.solution.rule.simpstrategy.FireRuleStrategy;
|
||||
import com.solution.rule.simpstrategy.FireRuleStrategyFactory;
|
||||
import com.solution.rule.strategy.SceneStrategy;
|
||||
import com.solution.rule.strategy.SceneStrategyFactory;
|
||||
import org.kie.api.KieBase;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -33,9 +36,15 @@ public class FireRuleServiceImpl implements FireRuleService {
|
||||
@Autowired
|
||||
private SceneStrategyFactory strategyFactory;
|
||||
|
||||
@Autowired
|
||||
private FireRuleStrategyFactory fireStrategyFactory;
|
||||
|
||||
@Autowired
|
||||
private FireRuleMapper ruleMapper;
|
||||
|
||||
@Autowired
|
||||
private KieBase kieBase;
|
||||
|
||||
/* @Override
|
||||
public WeaponModelVO execute(Integer sceneType, WeaponModelDTO weaponModelDTO) {
|
||||
if(ObjectUtil.isNull(sceneType) || ObjectUtil.isEmpty(weaponModelDTO)){
|
||||
@@ -155,6 +164,28 @@ public class FireRuleServiceImpl implements FireRuleService {
|
||||
return ruleMapper.getComponents(platformId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行任务
|
||||
* @param task
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Task executeTask(Task task) {
|
||||
if(ObjectUtil.isEmpty(task)){
|
||||
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
|
||||
}
|
||||
String dataType = task.getDataType();
|
||||
if("打击".contains(dataType)){
|
||||
FireRuleStrategy strategy = fireStrategyFactory.getStrategy(0);
|
||||
task = strategy.mappingTask(task);
|
||||
} else {
|
||||
FireRuleStrategy strategy = fireStrategyFactory.getStrategy(1);
|
||||
task = strategy.mappingTask(task);
|
||||
}
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有组件以及数量
|
||||
* @return
|
||||
@@ -181,4 +212,9 @@ public class FireRuleServiceImpl implements FireRuleService {
|
||||
return ruleMapper.findAllPlatformComponents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BasicPlatform> findAllBasicPlatformComponents() {
|
||||
return ruleMapper.findAllBasicPlatformComponents();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.solution.rule.simpstrategy;
|
||||
|
||||
import com.solution.rule.enums.SceneType;
|
||||
|
||||
public enum FireRUleType {
|
||||
HIT(0, "打击"),
|
||||
DISTURB(2, "干扰");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
FireRUleType(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据数字编码获取对应的枚举
|
||||
* @param code 前端传递的数字
|
||||
* @return 枚举实例
|
||||
* @throws IllegalArgumentException 如果找不到对应枚举
|
||||
*/
|
||||
public static FireRUleType fromCode(int code) {
|
||||
for (FireRUleType type : values()) {
|
||||
if (type.code == code) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("未知的任务类型编码: " + code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.solution.rule.simpstrategy;
|
||||
|
||||
|
||||
import com.solution.rule.domain.FireRuleExecuteDTO;
|
||||
import com.solution.rule.domain.simplerulepojo.Task;
|
||||
import com.solution.rule.enums.SceneType;
|
||||
|
||||
public interface FireRuleStrategy {
|
||||
|
||||
Task mappingTask(Task task);
|
||||
|
||||
FireRUleType getFireRuleType();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.solution.rule.simpstrategy;
|
||||
|
||||
import com.solution.rule.enums.SceneType;
|
||||
import com.solution.rule.strategy.SceneStrategy;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class FireRuleStrategyFactory {
|
||||
|
||||
@Autowired
|
||||
private List<FireRuleStrategy> strategyList;
|
||||
|
||||
private final Map<FireRUleType, FireRuleStrategy> strategyMap = new EnumMap<>(FireRUleType.class);
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
for (FireRuleStrategy strategy : strategyList) {
|
||||
FireRUleType type = strategy.getFireRuleType();
|
||||
if (strategyMap.containsKey(type)) {
|
||||
throw new IllegalStateException("重复的场景类型: " + type);
|
||||
}
|
||||
strategyMap.put(type, strategy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据前端传递的数字编码获取对应的策略
|
||||
* @param code 前端传递的数字
|
||||
* @return 策略实现
|
||||
* @throws IllegalArgumentException 如果编码无效或策略未注册
|
||||
*/
|
||||
public FireRuleStrategy getStrategy(int code) {
|
||||
FireRUleType type = FireRUleType.fromCode(code);
|
||||
FireRuleStrategy strategy = strategyMap.get(type);
|
||||
if (strategy == null) {
|
||||
throw new IllegalArgumentException("未找到任务 " + code + " 对应的策略实现");
|
||||
}
|
||||
return strategy;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.solution.rule.simpstrategy.impl;
|
||||
|
||||
import com.solution.rule.domain.simplerulepojo.Task;
|
||||
import com.solution.rule.domain.simplerulepojo.fact.FactTask;
|
||||
import com.solution.rule.simpstrategy.FireRUleType;
|
||||
import com.solution.rule.simpstrategy.FireRuleStrategy;
|
||||
import org.kie.api.KieBase;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class BlowStrategy implements FireRuleStrategy {
|
||||
|
||||
private static final String TASK_TYPE = "打击任务";
|
||||
|
||||
@Autowired
|
||||
private KieBase kieBase;
|
||||
@Override
|
||||
public Task mappingTask(Task task) {
|
||||
KieSession kieSession = kieBase.newKieSession();
|
||||
FactTask factTask = new FactTask();
|
||||
Task redTask = new Task();
|
||||
redTask.setTargetId(task.getId());
|
||||
redTask.setSide("红方");
|
||||
|
||||
Map<String, Object> globalParams = new HashMap<>();
|
||||
kieSession.setGlobal("globalParams", globalParams);
|
||||
|
||||
factTask.setRedTask(redTask);
|
||||
factTask.setBlueTask(task);
|
||||
kieSession.insert(factTask);
|
||||
|
||||
// 👇 核心:根据策略选择规则组
|
||||
kieSession.getAgenda()
|
||||
.getAgendaGroup(TASK_TYPE)
|
||||
.setFocus();
|
||||
|
||||
kieSession.fireAllRules();
|
||||
return redTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FireRUleType getFireRuleType() {
|
||||
return FireRUleType.HIT;
|
||||
}
|
||||
}
|
||||
15
auto-solution-rule/src/main/resources/META-INF/kmoudle.xml
Normal file
15
auto-solution-rule/src/main/resources/META-INF/kmoudle.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<kmodule xmlns="http://www.drools.org/xsd/kmodule">
|
||||
<!--
|
||||
name:指定kbase的名称,可以任意,但是需要唯一
|
||||
packages:指定规则文件的目录,需要根据实际情况填写,否则无法加载到规则文件
|
||||
default:指定当前kbase是否为默认
|
||||
-->
|
||||
<kbase name="myKbase1" packages="rules" default="true">
|
||||
<!--
|
||||
name:指定ksession名称,可以任意,但是需要唯一
|
||||
default:指定当前session是否为默认
|
||||
-->
|
||||
<ksession name="ksession-rule" default="true"/>
|
||||
</kbase>
|
||||
</kmodule>
|
||||
@@ -85,6 +85,16 @@
|
||||
WHERE platform_id=#{platformId}
|
||||
</select>
|
||||
|
||||
<resultMap id="VPBasicPlatformMap" type="com.solution.rule.domain.BasicPlatform">
|
||||
<result property="id" column="id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="description" column="description"/>
|
||||
</resultMap>
|
||||
<select id="findAllBasicPlatformComponents" resultMap="VPBasicPlatformMap">
|
||||
SELECT *
|
||||
FROM platform
|
||||
</select>
|
||||
|
||||
<resultMap id="VPlatformMap" type="com.solution.rule.domain.Platform">
|
||||
<result property="id" column="id"/>
|
||||
<result property="name" column="name"/>
|
||||
|
||||
338
auto-solution-rule/src/main/resources/rules/README.md
Normal file
338
auto-solution-rule/src/main/resources/rules/README.md
Normal file
@@ -0,0 +1,338 @@
|
||||
# fire-rule.drl 维护说明(业务+开发)
|
||||
|
||||
本文档对应 `auto-solution-rule/src/main/resources/rules/fire-rule.drl` 当前版本,重点说明:
|
||||
- 业务人员改哪里
|
||||
- 每个参数改了会产生什么效果
|
||||
- 如何快速判断规则是否“命中/不命中”
|
||||
|
||||
## 1. 先看这一个入口:业务可改区
|
||||
|
||||
|
||||
|
||||
只改 `//TODO` 下的 `buildBusinessConfig()`,其他函数不要改。
|
||||
|
||||
`buildBusinessConfig()` 里每个参数的效果如下。
|
||||
|
||||
## 2. 参数-效果对照(给业务人员)
|
||||
|
||||
### 2.1 武器名称映射(改名字,不改逻辑)
|
||||
- `redStrikeDroneName`:空中反制组中的无人机名称。
|
||||
- `redArmedHelicopterName`:空中反制组中的武装直升机名称。
|
||||
- `redHowitzerName`:地面反制组中的迫榴炮名称。
|
||||
- `redVehicleMortarName`:地面反制组中的车载迫击炮名称。
|
||||
- `redAaWeaponName`:空中反制组中的防空导弹武器名称。
|
||||
- `redAtRocketName`:装甲反制组中的反坦克火箭名称。
|
||||
- `redAtMissileSystemName`:装甲反制组中的反坦克导弹系统名称。
|
||||
- `redMissileVehicleName`:导弹补充组中的导弹发射车名称。
|
||||
|
||||
### 2.2 白名单开关(决定“是否匹配”)
|
||||
- `enableAirRule`:`true` 时,蓝方空中目标会触发红方空中反制组;`false` 时该组永不触发。
|
||||
- `enableGroundRule`:`true` 时,蓝方地面目标会触发红方炮类反制组;`false` 时不触发。
|
||||
- `enableArmorRule`:`true` 时,蓝方装甲目标会触发红方反坦克组;`false` 时不触发。
|
||||
- `enableMissileVehicleRule`:`true` 时,蓝方有导弹能力可追加导弹发射车;`false` 时不追加。
|
||||
- `enableMissileLinkage`:`true` 时开启导弹数量/范围联动;`false` 时不做导弹联动增强。
|
||||
- `allowMultiGroup`:
|
||||
- `true`:同一批输入可命中多组策略并叠加武器;
|
||||
- `false`:只命中第一组,后续组不再生效(更“死规则”)。
|
||||
- `enableArmedHelicopterOnAir`:空中组中是否包含武装直升机。
|
||||
|
||||
### 2.3 蓝方类型到红方方案映射(核心,可多选)
|
||||
|
||||
先解释你提到的 “k”:
|
||||
- 这里的 `k` 就是 **key(键名)**,例如 `map_armor_targets`。
|
||||
- `v` 是 **value(值)**,例如 `反坦克火箭,反坦克导弹系统`。
|
||||
- 规则实际含义就是:`key` 决定“哪类蓝方目标”,`value` 决定“红方上哪些武器”。
|
||||
|
||||
映射键名中文对照:
|
||||
- `map_air_targets`:蓝方是空中目标时,红方使用哪些武器。
|
||||
- `map_ground_targets`:蓝方是地面目标时,红方使用哪些武器。
|
||||
- `map_armor_targets`:蓝方是装甲目标(坦克/装甲车)时,红方使用哪些武器。
|
||||
- `map_artillery_targets`:蓝方是炮类目标时,红方使用哪些武器。
|
||||
- `map_missile_targets`:蓝方有导弹能力时,红方使用哪些武器。
|
||||
|
||||
映射规则说明:
|
||||
- 值必须是红方武器库内合法名称,否则该项会被忽略。
|
||||
- 为空时视为该组不配置,允许不命中。
|
||||
- 示例:`map_armor_targets=反坦克火箭,反坦克导弹系统` 表示坦克可同时触发两种红方反制武器。
|
||||
|
||||
### 2.4 数量和阈值(决定“匹配后给多少”)
|
||||
- `defaultAirNum`:空中组默认数量。
|
||||
- `defaultGroundNum`:地面/装甲组默认数量。
|
||||
- `defaultMissileVehicleNum`:导弹发射车默认数量。
|
||||
- `shellRangeDefault`:炮类组件参数值,单位固定 `范围米`。
|
||||
- `missileCountOffset`:红方导弹数量 = 蓝方导弹数量 + 偏移量。
|
||||
- `missileRangeOffset`:红方导弹范围 = 蓝方导弹范围 + 偏移量(单位 `破坏范围米`)。
|
||||
- `blueMissileRangeDefault`:蓝方导弹范围缺失时采用的默认值。
|
||||
- `minBlueMissileCountForLinkage`:蓝方导弹数量达到该值才触发联动增强。
|
||||
|
||||
### 2.5 全组件数量匹配参数(新增)
|
||||
- `enableComponentQuantityMatch`:是否启用全组件数量覆盖(非导弹组件)。
|
||||
- `componentDeviceNameMappingCsv`:组件名映射表(逗号分隔),格式 `蓝组件deviceName->红组件deviceName`;为空则默认 `deviceName` 直匹配。
|
||||
- `skipMissileComponentsByNameContains`:跳过覆盖关键词:蓝方组件 `deviceName` 包含该关键词则不覆盖;默认 `导弹`(用于保留导弹联动偏移)。
|
||||
|
||||
### 2.6 targetId 自动绑定参数(新增)
|
||||
- `enableTargetAutoBind`:是否自动给红方武器写入 `targetId`。
|
||||
- `minTargetBindRatio`:最低绑定比例(例如 `0.7` 表示至少 70% 红方武器有目标)。
|
||||
- `allowReserveWithoutTarget`:
|
||||
- `true`:允许少量红方武器 `targetId` 为空(火力冗余)。
|
||||
- `false`:尽量给每个红方武器分配目标。
|
||||
|
||||
绑定规则说明(固定,不需要业务改代码):
|
||||
- 绑定来源是蓝方武器 `equipmentId`。
|
||||
- 匹配优先级按武器类型:
|
||||
- 防空类红方武器优先绑定蓝方空中目标
|
||||
- 反装甲类红方武器优先绑定蓝方装甲目标
|
||||
- 炮类红方武器优先绑定蓝方炮类/地面目标
|
||||
- 导弹发射车优先绑定蓝方导弹能力目标
|
||||
- 当优先池不足时自动回退到地面池/全目标池,保证大部分武器有目标。
|
||||
|
||||
### 2.7 命中率与动态火力参数(新增)
|
||||
- `hitRateCsv`:业务可配置红方武器命中率,格式 `武器名=0.72,武器名2=0.55`。
|
||||
- `defaultHitRateFallback`:未命中 `hitRateCsv` 且武器未携带 `hitRate` 时的兜底命中率。
|
||||
- `desiredKillProbability`:目标毁伤置信度(例如 `0.9`)。
|
||||
- `offsetCsvByWeapon`:显式 offset(最高优先级),格式 `武器名=1,武器名2=2`。
|
||||
- `enableDynamicMultiRedPerBlue`:是否按命中率动态决定“一个蓝方目标需要几把红方武器”。
|
||||
- `minRedWeaponsPerBlueTarget` / `maxRedWeaponsPerBlueTargetCap`:每个蓝方目标的最小/最大红方分配数。
|
||||
|
||||
优先级说明(重要):
|
||||
- 若 `offsetCsvByWeapon` 命中某武器,则直接使用显式 offset,不再使用命中率推导 offset。
|
||||
- 未配置显式 offset 时,规则按命中率与 `desiredKillProbability` 自动推导所需火力数量。
|
||||
- 同一蓝方 `equipmentId` 可能被多个红方武器绑定(不是固定 2 把),数量由命中率动态计算并受 cap 限制。
|
||||
|
||||
### 2.8 阵位规则参数(新增)
|
||||
- `enablePositionRules`:阵位规则总开关。
|
||||
- 阵位输入来源:`blueTask.warZoneLocation` 与 `blueTask.defZoneLocation`(各 4 个经纬点)。
|
||||
- `fireUnitSpacingMeters`:防区/作战区点位间距(米),例如 `100` 代表约每 100 米一个火力单元。
|
||||
- `airDeployZonePreference`:飞机优先部署区域(`combat` 或 `defense`)。
|
||||
- `defensePriorityWeapons`:优先部署在防区的武器名单(逗号分隔)。
|
||||
- `groundDeployHeight` / `airDeployHeight`:地面/空中武器部署高度。
|
||||
|
||||
阵位规则效果:
|
||||
- 新增两条规则:
|
||||
- `阵位规则-区域解析与点位生成`
|
||||
- `阵位规则-武器部署赋位`
|
||||
- 飞机可在任意区(按偏好区优先);反坦克等重火力优先防区。
|
||||
- 在多边形区域内按间距生成候选点,并给红方武器写入 `weapon.coordinate`。
|
||||
|
||||
阵位输入示例(仅经纬度,4点):
|
||||
|
||||
```json
|
||||
{
|
||||
"warZoneLocation": [
|
||||
{ "longitude": 116.3801, "latitude": 39.9001 },
|
||||
{ "longitude": 116.3901, "latitude": 39.9001 },
|
||||
{ "longitude": 116.3901, "latitude": 39.9101 },
|
||||
{ "longitude": 116.3801, "latitude": 39.9101 }
|
||||
],
|
||||
"defZoneLocation": [
|
||||
{ "longitude": 116.3825, "latitude": 39.9025 },
|
||||
{ "longitude": 116.3875, "latitude": 39.9025 },
|
||||
{ "longitude": 116.3875, "latitude": 39.9075 },
|
||||
{ "longitude": 116.3825, "latitude": 39.9075 }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 2.9 航迹规则参数(新增)
|
||||
- `enableTrajectoryRules`:航迹规则总开关。
|
||||
- `strategyMode`:`auto/shortest/flank/interfere`。
|
||||
- `auto`:智能选择策略。
|
||||
- 其他值:强制使用指定策略(若该策略被禁用会自动回退)。
|
||||
- `enableShortest` / `enableFlank` / `enableInterfere`:各策略开关。
|
||||
- `nearDefDistanceMeters`:蓝方末端点到防区的“近距离阈值”。
|
||||
- `farDefDistanceMeters`:蓝方末端点到防区的“远距离阈值”。
|
||||
- `fastSpeedThreshold`:蓝方平均速度达到该值视为“高速”。
|
||||
- `flankOffsetMeters`:绕后追击偏移幅度(越大绕后越明显)。
|
||||
- `interfereOffsetMeters`:干扰轨迹基础偏移。
|
||||
- `interfereZigzagAmplitude`:干扰轨迹锯齿振幅(越大摆动越明显)。
|
||||
- `keepBlueHeight`:是否沿用蓝方高度。
|
||||
- `redTrackHeightOverride`:不沿用时红方统一高度。
|
||||
|
||||
航迹智能选择逻辑:
|
||||
- `near + fast` -> `shortest`(最短距离追击)
|
||||
- `far + fast` -> `interfere`(干扰/诱偏)
|
||||
- 其他 -> `flank`(绕后追击)
|
||||
|
||||
不生成保护:
|
||||
- 蓝方 `trackPoints` 为空,或 `defZoneLocation` 点数不足(<3),则不生成红方航迹。
|
||||
|
||||
## 3. 当前规则行为(简版)
|
||||
|
||||
- `装备组件匹配`、`组件参数匹配`:已作为 `legacy` 占位,不承担当前业务决策。
|
||||
- 主决策在 `红方武器自适应装配规则`:调用 `configureRedWeaponsByBlue(...)`,按“映射配置”添加武器。
|
||||
- 导弹增强在 `导弹联动增强规则`:调用 `applyMissileLinkage(...)`,受开关和阈值控制。
|
||||
- 全组件数量匹配在 `全组件数量匹配规则`:按红方 `targetId` 绑定蓝方装备,覆盖非导弹组件 `componentParams[0].number`;找不到组件/targetId 允许跳过。
|
||||
- 命中率驱动数量在 `命中率规则-动态数量与offset`:按 `hitRate` 与目标毁伤概率推导火力数量;显式 offset 配置优先。
|
||||
- 任务命名在 `任务自动匹配规则`:调用 `assignTaskNameByRedWeapons(...)`,按红方最终武器自动生成任务名和 `dataType`。
|
||||
- 炮类约束:命中炮类条件时,炮类武器只保留 `炮弹` 组件,单位 `范围米`。
|
||||
- `targetId` 绑定:在装配后自动执行,按命中率动态给蓝目标分配多个红方武器(受上下限约束),允许少量空值冗余。
|
||||
- 阵位部署:按多边形区域和武器类型自动赋位,保证防区火力覆盖。
|
||||
- 射程合理性在 `射程合理性校验规则`:基于蓝/红武器坐标计算距离,自动避免“射程不足却打击”的不合理情况(可自动调参)。
|
||||
- 航迹生成:根据蓝方 `trackPoints` 生成红方 `trackPoints`,点数与蓝方一致,支持三套策略和智能选择。
|
||||
|
||||
## 3.1 任务名称自动匹配(新增)
|
||||
|
||||
任务命名依据:**红方最终武器**(不是蓝方任务名关键字)。
|
||||
|
||||
当前分类优先级:
|
||||
- 导弹突击(导弹发射车)
|
||||
- 防空压制(防空导弹武器/火力打击无人机/武装直升机)
|
||||
- 反装甲打击(反坦克火箭/反坦克导弹系统)
|
||||
- 炮火压制(迫榴炮/车载迫击炮)
|
||||
- 通用打击(兜底)
|
||||
|
||||
业务可调模板(在 `buildBusinessConfig()`):
|
||||
- `taskName_missile_strike` / `taskDataType_missile_strike`
|
||||
- `taskName_air_defence` / `taskDataType_air_defence`
|
||||
- `taskName_anti_armor` / `taskDataType_anti_armor`
|
||||
- `taskName_artillery` / `taskDataType_artillery`
|
||||
- `taskName_general` / `taskDataType_general`
|
||||
|
||||
效果说明:
|
||||
- 只改这些模板文字,不改函数,也能改变最终任务展示名。
|
||||
- 若分类与武器不一致,会自动回落到 `通用打击任务`,避免“任务名和武器不符”。
|
||||
|
||||
## 4. 快速修改示例(业务常用)
|
||||
|
||||
- 想让规则更“死”:
|
||||
- 把 `allowMultiGroup` 改成 `false`。
|
||||
- 想让“坦克只上反坦克火箭,不上导弹系统”:
|
||||
- 把 `map_armor_targets` 改成 `反坦克火箭`。
|
||||
- 想让“坦克同时上火箭和导弹系统”:
|
||||
- 把 `map_armor_targets` 改成 `反坦克火箭,反坦克导弹系统`。
|
||||
- 想允许更多不命中:
|
||||
- 关闭部分开关,例如 `enableGroundRule=false`、`enableArmorRule=false`。
|
||||
- 想让导弹联动更难触发:
|
||||
- 提高 `minBlueMissileCountForLinkage`,例如从 `1` 调到 `3`。
|
||||
- 想提升炮类打击范围:
|
||||
- 调大 `shellRangeDefault`,例如 `1500 -> 1800`。
|
||||
|
||||
## 5. 测试 JSON(按你项目常用的 Task 入参格式)
|
||||
|
||||
说明:下面 JSON 是 **单个 Task** 格式,不是 `FactTask` 包装格式。
|
||||
如果你的执行入口最终需要 `FactTask`,则由开发在服务层把“蓝方 Task + 红方 Task”组装后再 `insert` 规则引擎。
|
||||
|
||||
### 5.1 不命中样例(蓝方 Task)
|
||||
说明:该样例仅用于蓝方任务输入结构校验;若业务把对应映射留空或关闭开关,则允许不命中。
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "blue-miss-001",
|
||||
"side": "蓝方",
|
||||
"dataType": "打击",
|
||||
"threatLevel": "2",
|
||||
"taskWeapons": [
|
||||
{
|
||||
"name": "攻击直升机",
|
||||
"supportType": "overhead",
|
||||
"number": 1,
|
||||
"components": []
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 5.2 命中样例(蓝方 Task)
|
||||
说明:该蓝方输入同时包含空中和装甲特征,且有导弹组件,满足命中与联动测试条件。
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "blue-hit-001",
|
||||
"side": "蓝方",
|
||||
"dataType": "打击",
|
||||
"threatLevel": "3",
|
||||
"taskWeapons": [
|
||||
{
|
||||
"name": "攻击直升机",
|
||||
"supportType": "overhead",
|
||||
"number": 2,
|
||||
"components": [
|
||||
{
|
||||
"deviceName": "机载导弹",
|
||||
"componentParams": [
|
||||
{
|
||||
"attDefaultValue": "260",
|
||||
"attExplain": "破坏范围米",
|
||||
"number": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "主战坦克",
|
||||
"supportType": "ground",
|
||||
"number": 2,
|
||||
"components": []
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 5.3 红方初始 Task 样例(通常为空列表)
|
||||
说明:用于和蓝方 Task 组装成规则输入对象。
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "red-init-001",
|
||||
"side": "红方",
|
||||
"dataType": "打击",
|
||||
"threatLevel": "1",
|
||||
"taskWeapons": []
|
||||
}
|
||||
```
|
||||
|
||||
### 5.4 航迹规则不生成样例(缺防区)
|
||||
```json
|
||||
{
|
||||
"id": "blue-track-miss-001",
|
||||
"side": "蓝方",
|
||||
"dataType": "打击",
|
||||
"threatLevel": "2",
|
||||
"defZoneLocation": [],
|
||||
"trackPoints": [
|
||||
{ "index": 0, "longitude": 116.3801, "latitude": 39.9001, "height": 100, "speed": 210 },
|
||||
{ "index": 1, "longitude": 116.3810, "latitude": 39.9010, "height": 100, "speed": 220 }
|
||||
],
|
||||
"taskWeapons": []
|
||||
}
|
||||
```
|
||||
|
||||
### 5.5 航迹规则命中样例(可生成)
|
||||
```json
|
||||
{
|
||||
"id": "blue-track-hit-001",
|
||||
"side": "蓝方",
|
||||
"dataType": "打击",
|
||||
"threatLevel": "3",
|
||||
"defZoneLocation": [
|
||||
{ "longitude": 116.4001, "latitude": 39.9201 },
|
||||
{ "longitude": 116.4051, "latitude": 39.9201 },
|
||||
{ "longitude": 116.4051, "latitude": 39.9251 },
|
||||
{ "longitude": 116.4001, "latitude": 39.9251 }
|
||||
],
|
||||
"trackPoints": [
|
||||
{ "index": 0, "longitude": 116.3801, "latitude": 39.9001, "height": 120, "speed": 240 },
|
||||
{ "index": 1, "longitude": 116.3840, "latitude": 39.9040, "height": 120, "speed": 245 },
|
||||
{ "index": 2, "longitude": 116.3880, "latitude": 39.9080, "height": 120, "speed": 250 },
|
||||
{ "index": 3, "longitude": 116.3920, "latitude": 39.9120, "height": 120, "speed": 248 }
|
||||
],
|
||||
"taskWeapons": []
|
||||
}
|
||||
```
|
||||
|
||||
## 6. 开发人员说明(放在末尾)
|
||||
|
||||
- **入口约定**:业务仅改 `buildBusinessConfig()`,开发改函数实现时不要破坏该入口。
|
||||
- **类型约定**:配置读取统一走 `readIntCfg(...)` / `readBooleanCfg(...)`,避免 `Map` 强转异常。
|
||||
- **策略收敛**:`configureRedWeaponsByBlue(...)` 使用 `matchedAny + allowMultiGroup` 控制“单组命中/多组叠加”。
|
||||
- **映射解析**:通过 `parseMappedWeaponNames(...)` 将逗号分隔配置解析为武器列表,非法名称会被 `isValidRedWeaponNameByConfig(...)` 过滤。
|
||||
- **联动门控**:`applyMissileLinkage(...)` 必须同时满足:
|
||||
- `enableMissileLinkage=true`
|
||||
- 蓝方导弹数量 `>= minBlueMissileCountForLinkage`
|
||||
- **目标绑定**:`bindTargetIdsForRedWeapons(...)` 基于蓝方 `equipmentId` 分配 `targetId`,支持“优先匹配 + 绑定率阈值 + 冗余空目标”。
|
||||
- **阵位部署**:`prepareDeploymentPools(...)` + `applyWeaponDeployment(...)` 负责区域解析、点位生成与部署赋位。
|
||||
- **航迹生成**:`applyTrajectoryGeneration(...)` + `chooseTrajectoryStrategy(...)` + `generateRedTrackPoints(...)` 负责红方航迹策略生成。
|
||||
- **任务命名**:`assignTaskNameByRedWeapons(...)` 仅基于红方最终武器,避免旧版按蓝方 `drawName` 关键字造成误判。
|
||||
- **legacy 区域**:`装备组件匹配`、`组件参数匹配` 及 legacy 函数区只保留回滚,不建议继续扩展。
|
||||
- **新增武器建议**:优先补 `isAirWeapon/isGroundWeapon/isArmorWeapon/isArtilleryWeapon` 分类,再补 `ensureBasicRedComponents(...)` 模板。
|
||||
2409
auto-solution-rule/src/main/resources/rules/fire-rule.drl
Normal file
2409
auto-solution-rule/src/main/resources/rules/fire-rule.drl
Normal file
File diff suppressed because it is too large
Load Diff
@@ -30,10 +30,6 @@
|
||||
<artifactId>solution-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
|
||||
@@ -24,4 +24,6 @@ public interface SceneMapper {
|
||||
* @return
|
||||
*/
|
||||
List<AfsimScenario> selectSceneList();
|
||||
|
||||
AfsimScenario findOneById(Long id);
|
||||
}
|
||||
|
||||
@@ -23,4 +23,6 @@ public interface SceneService {
|
||||
* @return
|
||||
*/
|
||||
List<AfsimScenario> selectSceneList();
|
||||
|
||||
AfsimScenario findOneById(Long id);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ public class SceneServiceImpl implements SceneService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public int saveOrUpdate(AfsimScenario afsimScenario) {
|
||||
//TODO 报错待修改
|
||||
if (null != afsimScenario.getId() && afsimScenario.getId() > 0) {
|
||||
// 更新场景
|
||||
int updated = sceneMapper.update(afsimScenario);
|
||||
@@ -65,4 +64,10 @@ public class SceneServiceImpl implements SceneService {
|
||||
public List<AfsimScenario> selectSceneList() {
|
||||
return sceneMapper.selectSceneList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AfsimScenario findOneById(Long id) {
|
||||
return sceneMapper.findOneById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="communicationGraph" column="communication_graph" />
|
||||
</resultMap>
|
||||
|
||||
<select id="findOneById" resultMap="SceneMap">
|
||||
SELECT * FROM afsim_scenario
|
||||
WHERE id=#{id}
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.solution.scene.domain.AfsimScenario" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO afsim_scenario (name, description, scenario_path, communication_graph)
|
||||
VALUES (#{name}, #{description}, #{scenarioPath}, #{communicationGraph})
|
||||
|
||||
@@ -1829,4 +1829,51 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
.ant-select .ant-select-clear {
|
||||
color: rgb(153 168 180);
|
||||
background: #475f71;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.ks-add-parameter-action{
|
||||
color: #eee;
|
||||
position: absolute;
|
||||
right: 14px;
|
||||
top: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ks-parameter-setting-tabs{
|
||||
.ant-tabs-nav{
|
||||
background: none;
|
||||
}
|
||||
.ant-tabs-nav-list{
|
||||
margin-left: 0;
|
||||
}
|
||||
&.ant-tabs-left >.ant-tabs-content-holder,
|
||||
&.ant-tabs-left >div>.ant-tabs-content-holder{
|
||||
border-left-color: #09264b;
|
||||
}
|
||||
.ant-tabs-tab-remove{
|
||||
//position: absolute;
|
||||
//right: 10px;
|
||||
//top: 7px;
|
||||
.anticon{
|
||||
color: rgb(173 206 224);
|
||||
}
|
||||
}
|
||||
&.ant-tabs-left >.ant-tabs-nav .ant-tabs-tab{
|
||||
border-radius: 0!important;
|
||||
}
|
||||
&.ant-tabs-card >.ant-tabs-nav .ant-tabs-tab-active,
|
||||
&.ant-tabs-card >div>.ant-tabs-nav .ant-tabs-tab-active {
|
||||
background: #09264c;
|
||||
}
|
||||
|
||||
&.ant-tabs-left >.ant-tabs-content-holder >.ant-tabs-content>.ant-tabs-tabpane,
|
||||
&.ant-tabs-left >div>.ant-tabs-content-holder >.ant-tabs-content>.ant-tabs-tabpane{
|
||||
padding-left: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is part of the kernelstudio package.
|
||||
*
|
||||
* (c) 2014-2025 zlin <admin@kernelstudio.com>
|
||||
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* that was distributed with this source code.
|
||||
@@ -23,14 +23,14 @@ export class EventError {
|
||||
|
||||
export class EventListener {
|
||||
|
||||
private readonly _listeners: Record<string, Function[]>;
|
||||
private _listeners: Record<string, Function[]>;
|
||||
|
||||
constructor(listeners: Record<string, Function[]> = {}) {
|
||||
this._listeners = listeners;
|
||||
}
|
||||
|
||||
all(): Record<string, Function[]> {
|
||||
return {...this._listeners}; // 返回副本,避免外部直接修改
|
||||
return { ...this._listeners }; // 返回副本,避免外部直接修改
|
||||
}
|
||||
|
||||
has(name: string): boolean {
|
||||
@@ -55,16 +55,24 @@ export class EventListener {
|
||||
[...listeners].forEach(f => f(options));
|
||||
}
|
||||
}
|
||||
|
||||
clear(){
|
||||
for (const key in this._listeners) {
|
||||
if (this._listeners.hasOwnProperty(key)) {
|
||||
delete this._listeners[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const safePreventDefault = (event: any) => {
|
||||
if (event && typeof event.preventDefault === 'function') {
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const safeStopPropagation = (event: any) => {
|
||||
if (event && typeof event.stopPropagation === 'function') {
|
||||
event.stopPropagation();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
25
modeler/src/views/decision/api.ts
Normal file
25
modeler/src/views/decision/api.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of the kernelstudio package.
|
||||
*
|
||||
* (c) 2014-2025 zlin <admin@kernelstudio.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import { HttpRequestClient } from '@/utils/request';
|
||||
import type { BasicResponse } from '@/types';
|
||||
import type { NodeCommandListResponse, PlatformListableResponse } from './types';
|
||||
|
||||
const req = HttpRequestClient.create<BasicResponse>({
|
||||
baseURL: '/api',
|
||||
});
|
||||
|
||||
|
||||
export const findAllBasicPlatforms = (): Promise<PlatformListableResponse> => {
|
||||
return req.get<PlatformListableResponse>('/system/firerule/platforms/basic');
|
||||
};
|
||||
|
||||
export const findAllNodeCommands = (): Promise<NodeCommandListResponse> => {
|
||||
return req.get<NodeCommandListResponse>('/node/command/all')
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
import { HttpRequestClient } from '@/utils/request';
|
||||
import type { Scenario, ScenarioPageableResponse, ScenarioRequest } from './types';
|
||||
import type { Scenario, ScenarioDetailsResponse, ScenarioPageableResponse, ScenarioRequest } from './types';
|
||||
import type { PlatformWithComponentsResponse } from '../types';
|
||||
import type { BasicResponse } from '@/types';
|
||||
|
||||
@@ -17,17 +17,21 @@ const req = HttpRequestClient.create<BasicResponse>({
|
||||
});
|
||||
|
||||
export const findScenarioByQuery = (_query: Partial<ScenarioRequest> = {}): Promise<ScenarioPageableResponse> => {
|
||||
return req.get('/system/scene/list', _query);
|
||||
return req.get<ScenarioPageableResponse>('/system/scene/list', _query);
|
||||
};
|
||||
|
||||
export const findOneScenarioById = (id: number): Promise<ScenarioDetailsResponse> => {
|
||||
return req.get<ScenarioDetailsResponse>(`/system/scene/${id}`);
|
||||
};
|
||||
|
||||
export const deleteOneScenarioById = (id: number): Promise<BasicResponse> => {
|
||||
return req.delete(`/system/behaviortree/${id}`);
|
||||
return req.delete<BasicResponse>(`/system/behaviortree/${id}`);
|
||||
};
|
||||
|
||||
export const findPlatformWithComponents = (id: number): Promise<PlatformWithComponentsResponse> => {
|
||||
return req.get(`/system/firerule/platforms/${id}`);
|
||||
return req.get<PlatformWithComponentsResponse>(`/system/firerule/platforms/${id}`);
|
||||
};
|
||||
|
||||
export const saveScenario = (scenario: Scenario): Promise<BasicResponse> => {
|
||||
return req.postJson(`/system/scene/saveSceneConfig`,scenario);
|
||||
return req.postJson<BasicResponse>(`/system/scene/saveSceneConfig`,scenario);
|
||||
};
|
||||
@@ -46,6 +46,7 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { message } from 'ant-design-vue';
|
||||
import { getTeleport } from '@antv/x6-vue-shape';
|
||||
import { Graph, Node, type NodeProperties } from '@antv/x6';
|
||||
@@ -54,16 +55,17 @@ import { Wrapper } from '@/components/wrapper';
|
||||
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
||||
import Header from '../header.vue';
|
||||
|
||||
import type { PlatformWithComponents, Scenario } from './types';
|
||||
import { createGraphTaskElement, createLineOptions, type GraphContainer, type GraphTaskElement, resolveGraph, useGraphCanvas } from '../graph';
|
||||
import type { Scenario } from './types';
|
||||
import type { PlatformWithComponents } from '../types';
|
||||
import { createLineOptions, type GraphContainer, type GraphTaskElement, resolveGraph, useGraphCanvas } from '../graph';
|
||||
|
||||
import { registerScenarioElement } from './register';
|
||||
import { createGraphScenarioElement, createGraphTaskElementFromScenario } from './utils';
|
||||
|
||||
import PlatformCard from './platform-card.vue';
|
||||
import NodesCard from './nodes-card.vue';
|
||||
import { saveScenario } from './api';
|
||||
import {resolveConnectionRelation} from './relation'
|
||||
import { findOneScenarioById, saveScenario } from './api';
|
||||
import { resolveConnectionRelation } from './relation';
|
||||
|
||||
const TeleportContainer = defineComponent(getTeleport());
|
||||
|
||||
@@ -82,6 +84,7 @@ export default defineComponent({
|
||||
TeleportContainer,
|
||||
},
|
||||
setup() {
|
||||
const currentRoute = useRoute();
|
||||
const canvas = ref<HTMLDivElement | null>(null);
|
||||
const graph = ref<Graph | null>(null);
|
||||
const currentZoom = ref<number>(1);
|
||||
@@ -94,6 +97,7 @@ export default defineComponent({
|
||||
const selectedNodeTaskElement = ref<GraphTaskElement | null>(null);
|
||||
const changed = ref<boolean>(false);
|
||||
const scenariosCardRef = ref<InstanceType<typeof PlatformCard> | null>(null);
|
||||
const currentScenarioId = ref<number | null>(null);
|
||||
|
||||
const {
|
||||
handleGraphEvent,
|
||||
@@ -105,6 +109,19 @@ export default defineComponent({
|
||||
resizeCanvas,
|
||||
} = useGraphCanvas();
|
||||
|
||||
const destroy = ()=> {
|
||||
window.removeEventListener('resize', handleResize);
|
||||
if (graph.value) {
|
||||
try {
|
||||
graph.value.clearCells();
|
||||
} catch (error) {
|
||||
console.warn('销毁画布时出错:', error);
|
||||
}
|
||||
graph.value = null;
|
||||
console.log('画布已销毁');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理拖动开始
|
||||
const handleDragStart = (nm: PlatformWithComponents) => {
|
||||
draggedNodeData.value = nm;
|
||||
@@ -293,6 +310,19 @@ export default defineComponent({
|
||||
currentScenarioEditing.value = null !== currentScenario.value;
|
||||
});
|
||||
|
||||
handleGraphEvent('node:dblclick', (args: any) => {
|
||||
const node = args.node as Node<NodeProperties>;
|
||||
const element = node.getData() as GraphTaskElement;
|
||||
console.error('element',element)
|
||||
window.location.href = `/app/decision/designer?scenario=${currentScenario.value?.id}&platform=${element?.platformId?? ''}`
|
||||
|
||||
// destroy()
|
||||
// window.location.href = '/app/decision/designer'
|
||||
// router.push({
|
||||
// path: '/app/decision/designer'
|
||||
// })
|
||||
});
|
||||
|
||||
handleGraphEvent('node:click', (args: any) => {
|
||||
const node = args.node as Node<NodeProperties>;
|
||||
const newElement = node.getData() as GraphTaskElement;
|
||||
@@ -325,6 +355,15 @@ export default defineComponent({
|
||||
initGraph();
|
||||
window.addEventListener('resize', handleResize);
|
||||
console.log('节点挂载完成');
|
||||
|
||||
let scenarioId = Number(currentRoute.query.scenario);
|
||||
if (!isNaN(scenarioId)) {
|
||||
findOneScenarioById(scenarioId).then(r=> {
|
||||
if(r.data){
|
||||
handleSelect(r.data)
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -382,18 +421,7 @@ export default defineComponent({
|
||||
});
|
||||
|
||||
// 清理
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('resize', handleResize);
|
||||
if (graph.value) {
|
||||
try {
|
||||
graph.value.clearCells();
|
||||
} catch (error) {
|
||||
console.warn('销毁画布时出错:', error);
|
||||
}
|
||||
graph.value = null;
|
||||
console.log('画布已销毁');
|
||||
}
|
||||
});
|
||||
onBeforeUnmount(() => destroy());
|
||||
|
||||
return {
|
||||
scenariosCardRef,
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
</div>
|
||||
<a-list :data-source="scenario || []" size="small" style="min-height: 25vh">
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item>
|
||||
<a-list-item @click="()=> handleSelect(item)">
|
||||
<a-flex>
|
||||
<a-tooltip placement="bottom">
|
||||
<template #title>
|
||||
@@ -28,7 +28,7 @@
|
||||
<span>{{ substring(item.name, 15) }}</span>
|
||||
</a-tooltip>
|
||||
<a-flex class="ks-tree-actions">
|
||||
<span style="margin-right: 10px" @click="()=> handleSelect(item)"><EditFilled /></span>
|
||||
<!-- <span style="margin-right: 10px" @click="()=> handleSelect(item)"><EditFilled /></span>-->
|
||||
<!-- <a-popconfirm-->
|
||||
<!-- title="确定删除?"-->
|
||||
<!-- @confirm="()=> handleDelete(item)"-->
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import { Graph, Node,Edge } from '@antv/x6';
|
||||
import type { Platform, PlatformComponent, PlatformRelation } from './types';
|
||||
import { Edge, Graph, Node } from '@antv/x6';
|
||||
import type { PlatformRelation } from './types';
|
||||
import type { Platform, PlatformComponent } from '../types';
|
||||
import type { GraphTaskElement } from '../graph';
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,3 +44,7 @@ export interface ScenarioPageableResponse extends PageableResponse<Scenario> {
|
||||
|
||||
}
|
||||
|
||||
export interface ScenarioDetailsResponse extends ApiDataResponse<Scenario> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
import type { GraphRect, GraphTaskElement } from '../graph';
|
||||
import { generateKey } from '@/utils/strings';
|
||||
import type { PlatformWithComponents } from './types';
|
||||
import type { PlatformWithComponents } from '../types';
|
||||
|
||||
export const createGraphTaskElementFromScenario = (
|
||||
platform: PlatformWithComponents,
|
||||
@@ -28,6 +28,7 @@ export const createGraphTaskElementFromScenario = (
|
||||
template: 0,
|
||||
templateType: null,
|
||||
category: null,
|
||||
multiable: false,
|
||||
group: null,
|
||||
description: platform.description,
|
||||
order: 0,
|
||||
|
||||
@@ -24,6 +24,10 @@ export const findTreesByQuery = (query: Partial<BehaviorTreeRequest> = {}): Prom
|
||||
return req.get<BehaviorTreePageResponse>('/system/behaviortree/list', query);
|
||||
};
|
||||
|
||||
export const findOneTreeByPlatformId = (platformId: number): Promise<BehaviorTreeDetailsResponse> => {
|
||||
return req.get(`/system/behaviortree/platform/${platformId}`);
|
||||
};
|
||||
|
||||
export const findOneTreeById = (id: number): Promise<BehaviorTreeDetailsResponse> => {
|
||||
return req.get(`/system/behaviortree/${id}`);
|
||||
};
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
<CheckOutlined />
|
||||
<span>保存</span>
|
||||
</a-button>
|
||||
|
||||
<a-button v-if="currentScenarioId" class="ks-model-builder-save" size="small" @click="handleGoback">
|
||||
<BackwardFilled />
|
||||
<span>返回</span>
|
||||
</a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
<div
|
||||
@@ -37,6 +42,8 @@
|
||||
</div>
|
||||
<Properties
|
||||
v-if="graph"
|
||||
:platforms="platforms"
|
||||
:nodeCommands="nodeCommands"
|
||||
:element="selectedNodeTaskElement"
|
||||
:graph="graph as any"
|
||||
:node="selectedModelNode as any"
|
||||
@@ -51,10 +58,11 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { message } from 'ant-design-vue';
|
||||
import { getTeleport } from '@antv/x6-vue-shape';
|
||||
import { Graph, Node, type NodeProperties } from '@antv/x6';
|
||||
import { CheckCircleOutlined, CheckOutlined, RollbackOutlined, SaveOutlined } from '@ant-design/icons-vue';
|
||||
import { CheckCircleOutlined, CheckOutlined, RollbackOutlined, SaveOutlined, BackwardFilled } from '@ant-design/icons-vue';
|
||||
import { Wrapper } from '@/components/wrapper';
|
||||
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
||||
import Header from '../header.vue';
|
||||
@@ -65,8 +73,9 @@ import { createGraphTaskElementFromTemplate } from './utils';
|
||||
|
||||
import { createGraphTaskElement, createLineOptions, type GraphContainer, type GraphTaskElement, hasElements, hasRootElementNode, resolveGraph, useGraphCanvas } from '../graph';
|
||||
import { registerNodeElement } from './register';
|
||||
|
||||
import { createTree, findOneTreeById, updateTree } from './api';
|
||||
import { findAllBasicPlatforms, findAllNodeCommands } from '../api';
|
||||
import type { Platform } from '../types';
|
||||
import { createTree, findOneTreeById, findOneTreeByPlatformId, updateTree } from './api';
|
||||
import TressCard from './trees-card.vue';
|
||||
import NodesCard from './nodes-card.vue';
|
||||
|
||||
@@ -85,9 +94,11 @@ export default defineComponent({
|
||||
CheckCircleOutlined,
|
||||
CheckOutlined,
|
||||
RollbackOutlined,
|
||||
BackwardFilled,
|
||||
TeleportContainer,
|
||||
},
|
||||
setup() {
|
||||
const currentRoute = useRoute();
|
||||
const canvas = ref<HTMLDivElement | null>(null);
|
||||
const graph = ref<Graph | null>(null);
|
||||
const currentZoom = ref<number>(1);
|
||||
@@ -100,6 +111,9 @@ export default defineComponent({
|
||||
const selectedNodeTaskElement = ref<GraphTaskElement | null>(null);
|
||||
const changed = ref<boolean>(false);
|
||||
const treesCardRef = ref<InstanceType<typeof TressCard> | null>(null);
|
||||
const platforms = ref<Platform[]>([]);
|
||||
const nodeCommands = ref<NodeCommand[]>([])
|
||||
const currentScenarioId = ref<number | null>(null);
|
||||
|
||||
const {
|
||||
handleGraphEvent,
|
||||
@@ -109,8 +123,35 @@ export default defineComponent({
|
||||
fitToScreen,
|
||||
centerContent,
|
||||
resizeCanvas,
|
||||
destroyGraph,
|
||||
clearGraph,
|
||||
} = useGraphCanvas();
|
||||
|
||||
const destroy = ()=> {
|
||||
window.removeEventListener('resize', handleResize);
|
||||
destroyGraph();
|
||||
graph.value = null;
|
||||
}
|
||||
|
||||
const loadPlatforms = () => {
|
||||
platforms.value = [];
|
||||
findAllBasicPlatforms().then(r => {
|
||||
platforms.value = r.data ?? [];
|
||||
});
|
||||
};
|
||||
|
||||
const loadNodeCommands = ()=> {
|
||||
nodeCommands.value = []
|
||||
findAllNodeCommands().then(r=> {
|
||||
nodeCommands.value = r.data ?? []
|
||||
})
|
||||
}
|
||||
|
||||
const loadDatasource = ()=> {
|
||||
loadPlatforms();
|
||||
loadNodeCommands();
|
||||
}
|
||||
|
||||
// 处理拖动开始
|
||||
const handleDragStart = (nm: NodeDragTemplate) => {
|
||||
draggedNodeData.value = nm;
|
||||
@@ -201,6 +242,8 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const handleSelectTree = (tree: BehaviorTree) => {
|
||||
destroyGraph();
|
||||
|
||||
console.info('handleSelectTree', tree);
|
||||
findOneTreeById(tree.id).then(r => {
|
||||
if (r.data) {
|
||||
@@ -221,7 +264,9 @@ export default defineComponent({
|
||||
graph: nodeGraph,
|
||||
};
|
||||
currentTreeEditing.value = true;
|
||||
createElements();
|
||||
nextTick(() => {
|
||||
initGraph();
|
||||
});
|
||||
} else {
|
||||
message.error(r.msg ?? '行为树不存在.');
|
||||
}
|
||||
@@ -229,12 +274,8 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const createElements = () => {
|
||||
clearGraph();
|
||||
nextTick(() => {
|
||||
try {
|
||||
graph.value?.clearCells();
|
||||
} catch (e: any) {
|
||||
console.error('clear cells error, cause:', e);
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (currentBehaviorTree.value?.graph && graph.value) {
|
||||
if (currentBehaviorTree.value?.graph.nodes) {
|
||||
@@ -262,6 +303,8 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const handleCreateTree = () => {
|
||||
destroyGraph();
|
||||
|
||||
currentBehaviorTree.value = {
|
||||
id: 0,
|
||||
name: '行为树',
|
||||
@@ -282,7 +325,9 @@ export default defineComponent({
|
||||
selectedModelNode.value = null;
|
||||
selectedNodeTaskElement.value = null;
|
||||
|
||||
createElements();
|
||||
nextTick(() => {
|
||||
initGraph();
|
||||
});
|
||||
};
|
||||
|
||||
// 初始化X6画布
|
||||
@@ -311,6 +356,7 @@ export default defineComponent({
|
||||
handleGraphEvent('node:click', (args: any) => {
|
||||
const node = args.node as Node<NodeProperties>;
|
||||
const newElement = node.getData() as GraphTaskElement;
|
||||
console.error('ddd', args);
|
||||
|
||||
selectedModelNode.value = node;
|
||||
selectedNodeTaskElement.value = JSON.parse(JSON.stringify(newElement || {})) as GraphTaskElement;
|
||||
@@ -340,6 +386,26 @@ export default defineComponent({
|
||||
initGraph();
|
||||
window.addEventListener('resize', handleResize);
|
||||
console.log('节点挂载完成');
|
||||
|
||||
let scenarioId = Number(currentRoute.query.scenario);
|
||||
if (!isNaN(scenarioId)) {
|
||||
currentScenarioId.value = scenarioId;
|
||||
} else {
|
||||
currentScenarioId.value = null;
|
||||
}
|
||||
|
||||
let platformId = Number(currentRoute.query.platform);
|
||||
if (!isNaN(platformId)) {
|
||||
findOneTreeByPlatformId(platformId).then(r => {
|
||||
if (r.data) {
|
||||
handleSelectTree(r.data);
|
||||
} else {
|
||||
handleCreateTree();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
handleCreateTree();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -354,6 +420,10 @@ export default defineComponent({
|
||||
changed.value = true;
|
||||
};
|
||||
|
||||
const handleGoback = ()=> {
|
||||
window.location.href = `/app/decision/communication?scenario=${currentScenarioId.value}`
|
||||
}
|
||||
|
||||
const handleSave = () => {
|
||||
const graphData: GraphContainer = resolveGraph(graph.value as Graph);
|
||||
console.info('handleSave', graphData);
|
||||
@@ -393,23 +463,16 @@ export default defineComponent({
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
init();
|
||||
loadDatasource();
|
||||
});
|
||||
|
||||
// 清理
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('resize', handleResize);
|
||||
if (graph.value) {
|
||||
try {
|
||||
graph.value.clearCells();
|
||||
} catch (error) {
|
||||
console.warn('销毁画布时出错:', error);
|
||||
}
|
||||
graph.value = null;
|
||||
console.log('画布已销毁');
|
||||
}
|
||||
});
|
||||
onBeforeUnmount(() => destroy());
|
||||
|
||||
return {
|
||||
nodeCommands,
|
||||
currentScenarioId,
|
||||
platforms,
|
||||
treesCardRef,
|
||||
handleCreateTree,
|
||||
currentTreeEditing,
|
||||
@@ -432,6 +495,7 @@ export default defineComponent({
|
||||
handleSave,
|
||||
handleUpdateElement,
|
||||
handleSelectTree,
|
||||
handleGoback,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -69,61 +69,86 @@
|
||||
|
||||
</a-tabs>
|
||||
|
||||
<a-tabs v-if="currentElement" v-model:activeKey="activeBottomTabsKey" class="ks-model-builder-tabs parameters-tabs">
|
||||
<a-tabs v-if="currentElement?.parameters && currentElement?.parameters.length > 0" v-model:activeKey="activeBottomTabsKey" class="ks-model-builder-tabs parameters-tabs">
|
||||
<template #leftExtra>
|
||||
<span class="ks-model-builder-title-icon icon-input"></span>
|
||||
</template>
|
||||
<a-tab-pane key="1" tab="节点变量">
|
||||
<a-form
|
||||
v-if="currentElement.parameters && currentElement.parameters.length > 0"
|
||||
autocomplete="off"
|
||||
layout="vertical"
|
||||
name="basic"
|
||||
style="padding-bottom:15px;"
|
||||
>
|
||||
<a-form-item v-for="setting in currentElement.parameters" :label="setting.description">
|
||||
<a-input-number v-if="setting.dataType === 'double'" v-model:value="setting.defaultValue" :placeholder="setting.description" size="small" style="width:100%;" />
|
||||
<a-input v-else v-model:value="setting.defaultValue" :placeholder="setting.description" size="small" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
<a-empty v-else>
|
||||
|
||||
<template #rightExtra v-if="multiableParameters">
|
||||
<a-tooltip title="添加平台" placement="left">
|
||||
<div class="ks-add-parameter-action" @click="()=> addParameterTab()">
|
||||
<a-space>
|
||||
<PlusCircleOutlined/>
|
||||
<span>添加</span>
|
||||
</a-space>
|
||||
</div>
|
||||
</a-tooltip>
|
||||
</template>
|
||||
<a-tab-pane key="1" tab="节点变量">
|
||||
<template v-if="currentElement.parameters && currentElement.parameters.length > 0">
|
||||
<a-form
|
||||
autocomplete="off"
|
||||
layout="vertical"
|
||||
name="basic"
|
||||
style="padding-bottom:15px;"
|
||||
>
|
||||
|
||||
<template v-if="multiableParameters">
|
||||
<a-tabs class="ks-parameter-setting-tabs"
|
||||
v-model:activeKey="groupedParametersActiveTab"
|
||||
tab-position="left"
|
||||
hide-add
|
||||
size="small"
|
||||
type="editable-card"
|
||||
@edit="onEditParameterTab">
|
||||
<a-tab-pane v-for="(grouped,index) in groupedParameters" :key="index" :tab="`平台 ${index + 1}`" :closable="true">
|
||||
<a-form-item v-for="setting in grouped" :label="setting.description">
|
||||
<a-input-number v-if="setting.dataType === 'double'"
|
||||
v-model:value="setting.defaultValue"
|
||||
:placeholder="setting.description" size="small" style="width:100%;" />
|
||||
<a-select :placeholder="`请选择${setting.description}`"
|
||||
allow-clear
|
||||
v-else-if="setting.paramKey === 'platforms'" v-model:value="setting.defaultValue">
|
||||
<a-select-option v-for="pl in platforms" :value="pl.name">{{pl.description}}</a-select-option>
|
||||
</a-select>
|
||||
<a-select :placeholder="`请选择${setting.description}`"
|
||||
allow-clear
|
||||
v-else-if="setting.paramKey === 'command'" v-model:value="setting.defaultValue">
|
||||
<a-select-option v-for="pl in nodeCommands" :value="pl.command">{{pl.chineseName}}</a-select-option>
|
||||
</a-select>
|
||||
<a-input v-else v-model:value="setting.defaultValue"
|
||||
:placeholder="setting.description" size="small" />
|
||||
</a-form-item>
|
||||
</a-tab-pane>
|
||||
<!-- <template #leftExtra>-->
|
||||
<!-- <a-button class="ks-btn" size="small" style="margin-bottom: 15px; width: 100%" block @click="()=> addParameterTab()">-->
|
||||
<!-- <PlusOutlined />-->
|
||||
<!--<!– <span>添加</span>–>-->
|
||||
<!-- </a-button>-->
|
||||
<!-- </template>-->
|
||||
</a-tabs>
|
||||
</template>
|
||||
<template v-else>
|
||||
<a-form-item v-for="setting in currentElement.parameters" :label="setting.description">
|
||||
<a-input-number v-if="setting.dataType === 'double'" v-model:value="setting.defaultValue"
|
||||
:placeholder="setting.description" size="small" style="width:100%;" />
|
||||
<a-select :placeholder="`请选择${setting.description}`"
|
||||
allow-clear
|
||||
v-else-if="setting.paramKey === 'platforms'" v-model:value="setting.defaultValue">
|
||||
<a-select-option v-for="pl in platforms" :value="pl.name">{{ pl.description }}</a-select-option>
|
||||
</a-select>
|
||||
<a-select :placeholder="`请选择${setting.description}`"
|
||||
allow-clear
|
||||
v-else-if="setting.paramKey === 'command'" v-model:value="setting.defaultValue">
|
||||
<a-select-option v-for="pl in nodeCommands" :value="pl.command">{{pl.chineseName}}</a-select-option>
|
||||
</a-select>
|
||||
<a-input v-else v-model:value="setting.defaultValue" :placeholder="setting.description" size="small" />
|
||||
</a-form-item>
|
||||
</template>
|
||||
</a-form>
|
||||
</template>
|
||||
<a-empty v-else>
|
||||
</a-empty>
|
||||
<!-- <div class="w-full">-->
|
||||
<!-- <a-space>-->
|
||||
<!-- <a-button size="small" type="primary" @click="addVariable">添加</a-button>-->
|
||||
<!-- </a-space>-->
|
||||
<!-- <a-table-->
|
||||
<!-- :columns="actionSpaceColumns"-->
|
||||
<!-- :dataSource="currentElement.variables"-->
|
||||
<!-- :pagination="false"-->
|
||||
<!-- :scroll="{ x: 500 }"-->
|
||||
<!-- class="mt-1"-->
|
||||
<!-- row-key="key"-->
|
||||
<!-- size="small"-->
|
||||
<!-- style="overflow-y:auto;height:35vh;"-->
|
||||
<!-- >-->
|
||||
<!-- <template #bodyCell="{column, record, index}">-->
|
||||
<!-- <template v-if="column.dataIndex === 'index'">-->
|
||||
<!-- {{ index + 1 }}-->
|
||||
<!-- </template>-->
|
||||
<!-- <template v-else-if="column.dataIndex === '_actions'">-->
|
||||
<!-- <a-button-->
|
||||
<!-- class="btn-link-delete"-->
|
||||
<!-- danger-->
|
||||
<!-- size="small"-->
|
||||
<!-- type="text"-->
|
||||
<!-- @click="()=> removeVariable(record)"-->
|
||||
<!-- >-->
|
||||
<!-- 删除-->
|
||||
<!-- </a-button>-->
|
||||
<!-- </template>-->
|
||||
<!-- <template v-else>-->
|
||||
<!-- <a-input v-model:value="record[column.dataIndex]" size="small" />-->
|
||||
<!-- </template>-->
|
||||
<!-- </template>-->
|
||||
<!-- </a-table>-->
|
||||
<!-- </div>-->
|
||||
</a-tab-pane>
|
||||
</a-tabs>
|
||||
|
||||
@@ -146,11 +171,12 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, onMounted, type PropType, ref, watch } from 'vue';
|
||||
import { CheckOutlined } from '@ant-design/icons-vue';
|
||||
import type { ElementVariable, GraphTaskElement } from '../graph';
|
||||
import { CheckOutlined, PlusCircleOutlined, PlusOutlined } from '@ant-design/icons-vue';
|
||||
import type { ElementParameter, ElementVariable, GraphTaskElement } from '../graph';
|
||||
import type { BehaviorTree } from './tree';
|
||||
import type { Graph, Node, NodeProperties } from '@antv/x6';
|
||||
import { generateKey } from '@/utils/strings';
|
||||
import type { NodeCommand, Platform } from '../types';
|
||||
|
||||
const actionSpaceColumns = [
|
||||
{ title: '序号', dataIndex: 'index', key: 'index', width: 40 },
|
||||
@@ -161,15 +187,20 @@ const actionSpaceColumns = [
|
||||
];
|
||||
|
||||
export default defineComponent({
|
||||
components: { CheckOutlined },
|
||||
components: { CheckOutlined, PlusOutlined, PlusCircleOutlined },
|
||||
props: {
|
||||
tree: { type: [Object, null] as PropType<BehaviorTree | null | undefined>, required: false },
|
||||
treeEditing: { type: Boolean as PropType<boolean>, required: true, default: false },
|
||||
node: { type: [Object, null] as PropType<Node<NodeProperties> | null | undefined>, required: false },
|
||||
graph: { type: [Object, null] as PropType<Graph | null | undefined>, required: true },
|
||||
platforms: { type: Array as PropType<Platform[]>, required: true },
|
||||
nodeCommands: { type: Array as PropType<NodeCommand[]>, required: true },
|
||||
},
|
||||
emits: ['update-element', 'update-tree'],
|
||||
setup(props, { emit }) {
|
||||
const platforms = ref<Platform[]>(props.platforms ?? []);
|
||||
const nodeCommands = ref<NodeCommand[]>(props.nodeCommands ?? []);
|
||||
|
||||
const activeTopTabsKey = ref<string>('1');
|
||||
const activeBottomTabsKey = ref<string>('1');
|
||||
const activeBottomTabs2Key = ref<string>('1');
|
||||
@@ -179,10 +210,98 @@ export default defineComponent({
|
||||
const currentNode = ref<Node | null>(props.node ?? null);
|
||||
const currentElement = ref<GraphTaskElement | null>(null);
|
||||
|
||||
const load = () => {
|
||||
const emptyParameters = ref<ElementParameter[]>([]);
|
||||
const groupedParameters = ref<Array<ElementParameter[]>>([]);
|
||||
const multiableParameters = ref<boolean>(false);
|
||||
const groupedParametersActiveTab = ref<number>(0);
|
||||
|
||||
const createEmptyParameters = (): ElementParameter[] => {
|
||||
try {
|
||||
return JSON.parse(JSON.stringify(currentElement.value?.parameters ?? [])) as ElementParameter[];
|
||||
} catch (e: any) {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const dumpParameters = (): ElementParameter[] => {
|
||||
return JSON.parse(JSON.stringify(emptyParameters.value)) as ElementParameter[];
|
||||
};
|
||||
|
||||
const addParameterTab = () => {
|
||||
let newParameters = dumpParameters();
|
||||
// 新增一个空的参数分组
|
||||
groupedParameters.value.push(newParameters);
|
||||
// 自动切换到新增的分组
|
||||
groupedParametersActiveTab.value = groupedParameters.value.length - 1;
|
||||
};
|
||||
|
||||
|
||||
const removeParameterTab = (index: number) => {
|
||||
// 边界判断:防止删除不存在的分组 / 只剩一个分组时禁止删除
|
||||
if (index < 0 || index >= groupedParameters.value.length) return;
|
||||
if (groupedParameters.value.length <= 1) return;
|
||||
|
||||
// 从数组中删除对应索引的分组
|
||||
groupedParameters.value.splice(index, 1);
|
||||
|
||||
if (groupedParameters.value.length === 0) {
|
||||
groupedParameters.value.push(dumpParameters());
|
||||
}
|
||||
|
||||
// 删除后处理激活状态:
|
||||
// 如果删除的是最后一个分组,激活前一个
|
||||
if (groupedParametersActiveTab.value >= groupedParameters.value.length) {
|
||||
groupedParametersActiveTab.value = groupedParameters.value.length - 1;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const onEditParameterTab = (targetKey: number | MouseEvent, action: string) => {
|
||||
if (action === 'add') {
|
||||
addParameterTab();
|
||||
} else {
|
||||
removeParameterTab(targetKey as number);
|
||||
}
|
||||
};
|
||||
|
||||
const resolveGroupedParameters = () => {
|
||||
emptyParameters.value = createEmptyParameters();
|
||||
// 解构获取当前元素的关键属性,简化代码
|
||||
const { multiable, parameters } = currentElement.value || {};
|
||||
|
||||
// 1. 不满足多分组条件:直接清空分组
|
||||
if (multiable !== true || !parameters || parameters.length === 0) {
|
||||
groupedParameters.value = [];
|
||||
multiableParameters.value = multiable === true;
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 满足条件:根据 groupIndex 对参数进行分组
|
||||
// 第一步:用 Map 做临时分组(key=groupIndex,value=当前分组的参数数组)
|
||||
const groupMap = new Map<number, ElementParameter[]>();
|
||||
parameters.forEach(param => {
|
||||
const index = param.groupIndex;
|
||||
// 如果 Map 中没有该分组,先初始化空数组
|
||||
if (!groupMap.has(index)) {
|
||||
groupMap.set(index, []);
|
||||
}
|
||||
// 将当前参数推入对应分组
|
||||
groupMap.get(index)!.push(param);
|
||||
});
|
||||
|
||||
// 第二步:将 Map 转换为二维数组(按 groupIndex 升序排序)
|
||||
groupedParameters.value = Array.from(groupMap.entries())
|
||||
// 按分组索引从小到大排序(保证分组顺序正确)
|
||||
.sort((a, b) => a[0] - b[0])
|
||||
// 只保留分组后的参数数组,丢弃 key
|
||||
.map(item => item[1]);
|
||||
|
||||
multiableParameters.value = multiable === true && groupedParameters.value.length > 0;
|
||||
};
|
||||
|
||||
|
||||
const resolveNode = (n?: Node | null | undefined) => {
|
||||
groupedParametersActiveTab.value = 0;
|
||||
currentNode.value = n ?? null;
|
||||
if (n) {
|
||||
const data = n.getData();
|
||||
@@ -190,6 +309,7 @@ export default defineComponent({
|
||||
} else {
|
||||
currentElement.value = null;
|
||||
}
|
||||
resolveGroupedParameters();
|
||||
};
|
||||
|
||||
const addVariable = () => {
|
||||
@@ -220,6 +340,17 @@ export default defineComponent({
|
||||
if (currentNode.value && currentElement.value) {
|
||||
// 深拷贝当前元素数据
|
||||
const newElement = JSON.parse(JSON.stringify(currentElement.value)) as GraphTaskElement;
|
||||
|
||||
if (multiableParameters.value) {
|
||||
newElement.parameters = groupedParameters.value.flatMap((group, groupIndex) => {
|
||||
// 遍历每个分组,给组内所有参数统一设置/保持 groupIndex
|
||||
return group.map(param => ({
|
||||
...param,
|
||||
groupIndex: groupIndex // 强制保证:当前参数的分组索引 = 所在分组的索引
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
// 更新节点数据
|
||||
currentNode.value.replaceData(newElement);
|
||||
// 触发事件通知父组件
|
||||
@@ -227,6 +358,9 @@ export default defineComponent({
|
||||
}
|
||||
};
|
||||
|
||||
const load = () => {
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.node,
|
||||
(n?: Node | null | undefined) => resolveNode(n),
|
||||
@@ -249,11 +383,23 @@ export default defineComponent({
|
||||
{ deep: true, immediate: true },
|
||||
);
|
||||
|
||||
watch(() => groupedParameters.value, () => updateNode(), { deep: true });
|
||||
|
||||
watch(() => currentElement.value, () => updateNode(), { deep: true });
|
||||
|
||||
watch(() => props.nodeCommands, (n: NodeCommand[] | null | undefined) => nodeCommands.value = n ?? [], { deep: true, immediate: true });
|
||||
watch(() => props.platforms, (n: Platform[] | null | undefined) => platforms.value = n ?? [], { deep: true, immediate: true });
|
||||
|
||||
onMounted(() => load());
|
||||
|
||||
return {
|
||||
nodeCommands,
|
||||
platforms,
|
||||
addParameterTab,
|
||||
groupedParametersActiveTab,
|
||||
multiableParameters,
|
||||
onEditParameterTab,
|
||||
groupedParameters,
|
||||
actionSpaceColumns,
|
||||
activeTopTabsKey,
|
||||
activeBottomTabsKey,
|
||||
|
||||
@@ -19,6 +19,7 @@ export interface NodeTemplate {
|
||||
templateType: NullableString;
|
||||
englishName: NullableString;
|
||||
parameters: ElementParameter[],
|
||||
multiable?: boolean,
|
||||
}
|
||||
|
||||
export interface NodeDragTemplate extends NodeTemplate {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
</div>
|
||||
<a-list :data-source="behaviorTrees || []" size="small" style="min-height: 25vh">
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item>
|
||||
<a-list-item @click="()=> handleSelect(item)">
|
||||
<a-flex>
|
||||
<a-tooltip placement="bottom">
|
||||
<template #title>
|
||||
@@ -28,12 +28,12 @@
|
||||
<span>{{ substring(item.name, 15) }}</span>
|
||||
</a-tooltip>
|
||||
<a-flex class="ks-tree-actions">
|
||||
<span style="margin-right: 10px" @click="()=> handleSelect(item)"><EditFilled /></span>
|
||||
<!-- <span style="margin-right: 10px"><EditFilled /></span>-->
|
||||
<a-popconfirm
|
||||
title="确定删除?"
|
||||
@confirm="()=> handleDelete(item)"
|
||||
>
|
||||
<span class="ks-tree-action ks-tree-action-delete"><DeleteOutlined /></span>
|
||||
<span class="ks-tree-action ks-tree-action-delete" @click.stop><DeleteOutlined /></span>
|
||||
</a-popconfirm>
|
||||
</a-flex>
|
||||
</a-flex>
|
||||
|
||||
@@ -27,6 +27,7 @@ export const createGraphTaskElementFromTemplate = (
|
||||
category: template.type,
|
||||
group: template.group,
|
||||
description: template.description,
|
||||
multiable: template.multiable === true,
|
||||
order: 0,
|
||||
position: {
|
||||
x: realRect.x ?? 0,
|
||||
|
||||
@@ -67,6 +67,7 @@ export interface ElementParameter {
|
||||
defaultValue: NullableString,
|
||||
description: NullableString,
|
||||
templateType: NullableString,
|
||||
groupIndex: number,
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +85,7 @@ export interface GraphTaskElement extends GraphBaseElement {
|
||||
inputs: any;
|
||||
outputs: any;
|
||||
order: number;
|
||||
multiable:boolean,
|
||||
variables: ElementVariable[];
|
||||
parameters: ElementParameter[];
|
||||
children?: GraphTaskElement[],
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import { computed, type ComputedRef, ref, type Ref } from 'vue';
|
||||
import { computed, type ComputedRef, ref, type Ref, nextTick } from 'vue';
|
||||
import { type Dom, Graph, Node } from '@antv/x6';
|
||||
import type { NodeViewPositionEventArgs } from '@antv/x6/es/view/node/type';
|
||||
import { createGraphCanvas } from './canvas';
|
||||
@@ -24,6 +24,8 @@ export interface UseGraphCanvas {
|
||||
graph: ComputedRef<Graph>;
|
||||
zoomIn: () => void;
|
||||
zoomOut: () => void;
|
||||
destroyGraph: () => void;
|
||||
clearGraph: () => void;
|
||||
fitToScreen: () => void;
|
||||
centerContent: () => void;
|
||||
resizeCanvas: () => void;
|
||||
@@ -39,6 +41,36 @@ export const useGraphCanvas = (readonly: boolean = false): UseGraphCanvas => {
|
||||
const eventListener = new EventListener();
|
||||
const currentZoom = ref<number>(0);
|
||||
|
||||
|
||||
const clearGraph = ()=> {
|
||||
if (graph.value) {
|
||||
try {
|
||||
// graph.value.off();
|
||||
graph.value.clearCells();
|
||||
} catch (e) {
|
||||
console.error('清空画布失败:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const destroyGraph = ()=> {
|
||||
eventListener.clear();
|
||||
if (graph.value) {
|
||||
clearGraph();
|
||||
|
||||
// 等待 Vue 完成卸载
|
||||
nextTick(() => {
|
||||
graph.value?.dispose(); // 销毁 Graph 实例
|
||||
graph.value = null;
|
||||
if (container.value) {
|
||||
container.value.innerHTML = ''; // 清空容器内容
|
||||
}
|
||||
});
|
||||
} else if (container.value) {
|
||||
container.value.innerHTML = '';
|
||||
}
|
||||
}
|
||||
|
||||
const handleGraphEvent = (name: string, fn: Function) => {
|
||||
eventListener.on(name, fn);
|
||||
};
|
||||
@@ -183,6 +215,11 @@ export const useGraphCanvas = (readonly: boolean = false): UseGraphCanvas => {
|
||||
emitGraphEvent('node:click', ctx);
|
||||
});
|
||||
|
||||
graph.value.on('node:dblclick', (ctx: NodeViewPositionEventArgs<Dom.ClickEvent>) => {
|
||||
console.info('node:dblclick', ctx);
|
||||
emitGraphEvent('node:dblclick', ctx);
|
||||
});
|
||||
|
||||
// 监听节点选中事件
|
||||
graph.value.on('node:selected', ({ node }) => {
|
||||
console.info('node select', node);
|
||||
@@ -238,6 +275,8 @@ export const useGraphCanvas = (readonly: boolean = false): UseGraphCanvas => {
|
||||
return {
|
||||
container,
|
||||
readonly,
|
||||
destroyGraph,
|
||||
clearGraph,
|
||||
graph: graphInstance,
|
||||
eventListener,
|
||||
currentZoom,
|
||||
|
||||
21
modeler/src/views/decision/types/command.ts
Normal file
21
modeler/src/views/decision/types/command.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* This file is part of the kernelstudio package.
|
||||
*
|
||||
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import type { ApiDataResponse, NullableString } from '@/types';
|
||||
|
||||
export interface NodeCommand {
|
||||
id: number,
|
||||
command: NullableString,
|
||||
chineseName: NullableString,
|
||||
description: NullableString,
|
||||
}
|
||||
|
||||
export interface NodeCommandListResponse extends ApiDataResponse<NodeCommand[]> {
|
||||
|
||||
}
|
||||
@@ -7,4 +7,5 @@
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
export * from './platform'
|
||||
export * from './platform'
|
||||
export * from './command'
|
||||
@@ -18,6 +18,10 @@ export interface Platform {
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface PlatformListableResponse extends ApiDataResponse<Platform[]> {
|
||||
|
||||
}
|
||||
|
||||
export interface PlatformComponent {
|
||||
id: number,
|
||||
name: NullableString,
|
||||
|
||||
2
modeler/types/components.d.ts
vendored
2
modeler/types/components.d.ts
vendored
@@ -15,7 +15,6 @@ declare module 'vue' {
|
||||
ABadge: typeof import('ant-design-vue/es')['Badge']
|
||||
AButton: typeof import('ant-design-vue/es')['Button']
|
||||
ACard: typeof import('ant-design-vue/es')['Card']
|
||||
ACascader: typeof import('ant-design-vue/es')['Cascader']
|
||||
ACol: typeof import('ant-design-vue/es')['Col']
|
||||
ACollapse: typeof import('ant-design-vue/es')['Collapse']
|
||||
ACollapsePanel: typeof import('ant-design-vue/es')['CollapsePanel']
|
||||
@@ -60,7 +59,6 @@ declare global {
|
||||
const ABadge: typeof import('ant-design-vue/es')['Badge']
|
||||
const AButton: typeof import('ant-design-vue/es')['Button']
|
||||
const ACard: typeof import('ant-design-vue/es')['Card']
|
||||
const ACascader: typeof import('ant-design-vue/es')['Cascader']
|
||||
const ACol: typeof import('ant-design-vue/es')['Col']
|
||||
const ACollapse: typeof import('ant-design-vue/es')['Collapse']
|
||||
const ACollapsePanel: typeof import('ant-design-vue/es')['CollapsePanel']
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user