Compare commits
66 Commits
2198e108a4
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| 25e6ac1cbe | |||
| 8b2f4dab89 | |||
| 4f60d68c4f | |||
| b63ad360d0 | |||
|
|
c724a7acf7 | ||
|
|
185e490560 | ||
|
|
d13359c803 | ||
|
|
65ea1cfd6b | ||
|
|
4455d38a61 | ||
|
|
6dd4392f0c | ||
|
|
974f403784 | ||
|
|
82bbfb83ca | ||
|
|
fc7b5e6c63 | ||
|
|
8dc867acb6 | ||
|
|
c17197d6e5 | ||
| 76022cf09a | |||
| 4ff5bf500c | |||
| be417189e0 | |||
| a88d74ea1d | |||
|
|
c2bfb43d41 | ||
|
|
c5d81a4c52 | ||
|
|
6d76cb8d5e | ||
|
|
b97837ec6a | ||
|
|
f2e81c6e5c | ||
|
|
83a38c6db8 | ||
|
|
22e71a24d3 | ||
|
|
6019738aca | ||
| 7847dbc89f | |||
| cc01c9ece8 | |||
| 8f29e230d0 | |||
| 711d7bf3da | |||
|
|
29e17773af | ||
|
|
db97d8a026 | ||
|
|
2e55254412 | ||
|
|
1504c3fc1b | ||
|
|
0cf4c9b47e | ||
|
|
fa0c93044c | ||
|
|
33a77428db | ||
| 26a89a66d1 | |||
| f72105134f |
@@ -76,6 +76,11 @@
|
||||
<artifactId>solution-rule</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.solution</groupId>
|
||||
<artifactId>solution-scene</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.solution.web.controller.behaviour;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.solution.system.domain.AfsimScenario;
|
||||
import com.solution.web.core.BehaviortreeProcessor;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -43,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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询行为树主列表
|
||||
*/
|
||||
@@ -116,15 +121,4 @@ public class BehaviortreeController extends BaseController
|
||||
return toAjax(behaviortreeService.deleteBehaviortreeByIds(ids));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存场景配置
|
||||
*/
|
||||
@ApiOperation("保存场景配置")
|
||||
@PostMapping("/saveSceneConfig")
|
||||
@Log(title = "行为树主", businessType = BusinessType.INSERT)
|
||||
public AjaxResult saveSceneConfig(@RequestBody AfsimScenario afsimScenario)
|
||||
{
|
||||
return toAjax(behaviortreeService.insert(afsimScenario));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -52,4 +53,46 @@ public class FireRuleController extends BaseController {
|
||||
public AjaxResult getCommPlatformComponentNames(Integer scenarioId){
|
||||
return success(ruleService.getCommPlatformComponentNames(scenarioId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据场景id获取所有平台及其组件
|
||||
* @param scenarioId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/platforms/{scenarioId}")
|
||||
public AjaxResult platformsScenarioId(@PathVariable Integer scenarioId){
|
||||
return success(ruleService.findPlatformComponents(scenarioId));
|
||||
}
|
||||
|
||||
@GetMapping("/platforms")
|
||||
public AjaxResult platforms(){
|
||||
return success(ruleService.findAllPlatformComponents());
|
||||
}
|
||||
|
||||
@GetMapping("/platforms/basic")
|
||||
public AjaxResult platformsBasic(){
|
||||
return success(ruleService.findAllBasicPlatformComponents());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据平台id获取平台下所有组件
|
||||
* @param platformId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/component/{platformId}")
|
||||
@ApiOperation("根据平台id获取平台下所有组件")
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.solution.web.controller.scene;
|
||||
|
||||
import com.solution.common.annotation.Log;
|
||||
import com.solution.common.core.controller.BaseController;
|
||||
import com.solution.common.core.domain.AjaxResult;
|
||||
import com.solution.common.core.page.TableDataInfo;
|
||||
import com.solution.common.enums.BusinessType;
|
||||
import com.solution.scene.domain.AfsimScenario;
|
||||
import com.solution.scene.domain.AfsimScenarioForm;
|
||||
import com.solution.scene.service.SceneService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 场景管理
|
||||
*/
|
||||
@Api("场景管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/scene")
|
||||
public class SceneController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private SceneService sceneService;
|
||||
|
||||
/**
|
||||
* 保存场景配置
|
||||
*/
|
||||
@ApiOperation("保存场景配置")
|
||||
@PostMapping("/saveSceneConfig")
|
||||
@Log(title = "行为树主", businessType = BusinessType.INSERT)
|
||||
public AjaxResult saveSceneConfig(@RequestBody AfsimScenario afsimScenario)
|
||||
{
|
||||
return toAjax(sceneService.saveOrUpdate(afsimScenario));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取场景列表
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获取场景列表")
|
||||
public TableDataInfo list(){
|
||||
startPage();
|
||||
List<AfsimScenario> list = sceneService.selectSceneList();
|
||||
return getDataTable(list);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.solution.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.solution.system.domain.AfsimScenario;
|
||||
import com.solution.system.domain.Behaviortree;
|
||||
|
||||
/**
|
||||
@@ -13,6 +12,9 @@ import com.solution.system.domain.Behaviortree;
|
||||
*/
|
||||
public interface BehaviortreeMapper
|
||||
{
|
||||
|
||||
Behaviortree findOneByPlatformId(Integer platformId);
|
||||
|
||||
/**
|
||||
* 查询行为树主
|
||||
*
|
||||
@@ -60,11 +62,4 @@ public interface BehaviortreeMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteBehaviortreeByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 保存场景配置
|
||||
* @param afsimScenario
|
||||
* @return
|
||||
*/
|
||||
int insert(AfsimScenario afsimScenario);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.solution.system.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.solution.system.domain.AfsimScenario;
|
||||
import com.solution.system.domain.Behaviortree;
|
||||
|
||||
/**
|
||||
@@ -13,6 +12,9 @@ import com.solution.system.domain.Behaviortree;
|
||||
*/
|
||||
public interface IBehaviortreeService
|
||||
{
|
||||
|
||||
Behaviortree findOneByPlatformId(Integer platformId);
|
||||
|
||||
/**
|
||||
* 查询行为树主
|
||||
*
|
||||
@@ -60,11 +62,4 @@ public interface IBehaviortreeService
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteBehaviortreeById(Long id);
|
||||
|
||||
/**
|
||||
* 保存场景配置
|
||||
* @param afsimScenario
|
||||
* @return
|
||||
*/
|
||||
int insert(AfsimScenario afsimScenario);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.util.List;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.solution.common.constant.ExceptionConstants;
|
||||
import com.solution.system.domain.AfsimScenario;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.solution.system.mapper.BehaviortreeMapper;
|
||||
@@ -23,6 +22,12 @@ public class BehaviortreeServiceImpl implements IBehaviortreeService
|
||||
@Autowired
|
||||
private BehaviortreeMapper behaviortreeMapper;
|
||||
|
||||
@Override
|
||||
public Behaviortree findOneByPlatformId(Integer platformId)
|
||||
{
|
||||
return behaviortreeMapper.findOneByPlatformId(platformId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询行为树主
|
||||
*
|
||||
@@ -94,17 +99,4 @@ public class BehaviortreeServiceImpl implements IBehaviortreeService
|
||||
{
|
||||
return behaviortreeMapper.deleteBehaviortreeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存场景配置
|
||||
* @param afsimScenario
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int insert(AfsimScenario afsimScenario) {
|
||||
if(ObjectUtil.isEmpty(afsimScenario) || ObjectUtil.isEmpty(afsimScenario.getCommunicationGraph())){
|
||||
throw new RuntimeException(ExceptionConstants.SCENE_CONFIG_NOT_NULL);
|
||||
}
|
||||
return behaviortreeMapper.insert(afsimScenario);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
@@ -55,7 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<insert id="insert" parameterType="com.solution.system.domain.AfsimScenario">
|
||||
<insert id="insert" parameterType="com.solution.scene.domain.AfsimScenario">
|
||||
INSERT INTO afsim_scenario (name, description, scenario_path, communication_graph)
|
||||
VALUES (#{name}, #{description}, #{scenarioPath}, #{communicationGraph})
|
||||
</insert>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -6,4 +6,6 @@ public class PlatformAndModuleConstants {
|
||||
public static final String RED_NEBO_M_1 = "red_nebo_m_1";
|
||||
|
||||
public static final String RED_NEBO_M_2 = "red_nebo_m_2";
|
||||
|
||||
public static final String RED_TANK_1 = "red_tank_1";
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
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.util.List;
|
||||
|
||||
public class Platform extends BasicPlatform {
|
||||
|
||||
private List<PlatformComponent> components;
|
||||
|
||||
public List<PlatformComponent> getComponents() {
|
||||
return components;
|
||||
}
|
||||
|
||||
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,30 @@
|
||||
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;
|
||||
|
||||
//目标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;
|
||||
}
|
||||
@@ -14,4 +14,7 @@ public class PlatformComponentNamesVO {
|
||||
|
||||
@ApiModelProperty("该平台下的组件名称列表(去重)")
|
||||
private List<String> componentNames;
|
||||
|
||||
@ApiModelProperty("平台描述")
|
||||
private String platformDescription;
|
||||
}
|
||||
@@ -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. 参数校验
|
||||
@@ -38,8 +43,6 @@ public class WarplaneHandler extends AbstractRuleChainHandler {
|
||||
|
||||
List<PlatformWeaponAggregateVO> resultWeapons = new ArrayList<>();
|
||||
|
||||
//TODO获取所有组件以及count
|
||||
|
||||
Iterator<WeaponModelDTO> iterator = dtoList.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
WeaponModelDTO dto = iterator.next();
|
||||
@@ -54,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,8 @@
|
||||
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;
|
||||
import com.solution.rule.domain.vo.PlatformComponentNamesVO;
|
||||
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||
@@ -32,4 +35,16 @@ public interface FireRuleMapper {
|
||||
List<PlatformComponentNamesVO> getCommPlatformComponentNames(Integer scenarioId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据平台id获取平台下所有组件
|
||||
* @param platformId
|
||||
* @return
|
||||
*/
|
||||
List<PlatformComponent> getComponents(Integer platformId);
|
||||
|
||||
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,6 +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;
|
||||
|
||||
@@ -29,4 +33,29 @@ public interface FireRuleService {
|
||||
* @return
|
||||
*/
|
||||
List<PlatformComponentNamesVO> getCommPlatformComponentNames(Integer scenarioId);
|
||||
|
||||
/**
|
||||
* 根据平台id获取平台下所有组件
|
||||
* @param platformId
|
||||
* @return
|
||||
*/
|
||||
List<PlatformComponent> getComponents(Integer platformId);
|
||||
|
||||
/**
|
||||
* 根据场景id获取所有平台及其组件
|
||||
* @param scenarioId
|
||||
* @return
|
||||
*/
|
||||
List<Platform> findPlatformComponents(Integer scenarioId);
|
||||
|
||||
List<Platform> findAllPlatformComponents();
|
||||
|
||||
List<BasicPlatform> findAllBasicPlatformComponents();
|
||||
|
||||
/**
|
||||
* 开始执行规则匹配
|
||||
* @param task
|
||||
* @return
|
||||
*/
|
||||
Task executeTask(Task task);
|
||||
}
|
||||
|
||||
@@ -3,21 +3,27 @@ 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.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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -30,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)){
|
||||
@@ -142,6 +154,38 @@ public class FireRuleServiceImpl implements FireRuleService {
|
||||
return ruleMapper.getCommPlatformComponentNames(scenarioId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据平台id获取平台下所有组件
|
||||
* @param platformId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<PlatformComponent> getComponents(Integer platformId) {
|
||||
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
|
||||
@@ -153,4 +197,24 @@ public class FireRuleServiceImpl implements FireRuleService {
|
||||
}
|
||||
return componentCountVOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Platform> findPlatformComponents(Integer scenarioId) {
|
||||
List<Platform> platforms = ruleMapper.findPlatformComponents(scenarioId);
|
||||
if(!CollUtil.isEmpty(platforms)){
|
||||
return platforms;
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Platform> findAllPlatformComponents() {
|
||||
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>
|
||||
@@ -0,0 +1,124 @@
|
||||
<?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.rule.mapper.FireRuleMapper">
|
||||
|
||||
|
||||
<resultMap id="platformComponentCountMap" type="com.solution.rule.domain.vo.WeaponModelVO">
|
||||
<result property="platformName" column="platform_name"/>
|
||||
<result property="componentName" column="component_name"/>
|
||||
<result property="count" column="count"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="PlatformComponentNamesVOResultMap" type="com.solution.rule.domain.vo.PlatformComponentNamesVO">
|
||||
<result property="platformName" column="platformName"/>
|
||||
<result property="platformDescription" column="description"/>
|
||||
<collection property="componentNames" ofType="java.lang.String">
|
||||
<result column="componentName"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="getWeapon" resultMap="platformComponentCountMap">
|
||||
SELECT
|
||||
p.name AS platform_name,
|
||||
pc.name AS component_name,
|
||||
COUNT(pc.name) AS count
|
||||
FROM platform p
|
||||
LEFT JOIN platform_component pc ON p.id = pc.platform_id
|
||||
GROUP BY p.id, p.name, pc.name
|
||||
ORDER BY p.id, pc.name
|
||||
|
||||
</select>
|
||||
|
||||
<select id="getPlatformComponentNames" resultType="com.solution.rule.domain.vo.WeaponModelVO">
|
||||
SELECT DISTINCT
|
||||
p.name AS platformName,
|
||||
pc.name AS componentName
|
||||
FROM platform p
|
||||
INNER JOIN platform_component pc ON p.id = pc.platform_id
|
||||
WHERE pc.name IS NOT NULL
|
||||
ORDER BY p.name, pc.name
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getModuleAndCount" resultType="com.solution.rule.domain.vo.ComponentCountVO">
|
||||
SELECT
|
||||
name AS componentName,
|
||||
COUNT(*) AS count
|
||||
FROM platform_component
|
||||
WHERE name IS NOT NULL
|
||||
GROUP BY name
|
||||
ORDER BY count DESC;
|
||||
</select>
|
||||
|
||||
<select id="getCommPlatformComponentNames" resultMap="PlatformComponentNamesVOResultMap"
|
||||
parameterType="java.lang.Integer">
|
||||
SELECT
|
||||
p.name AS platformName,
|
||||
pc.name AS componentName,
|
||||
p.description AS description
|
||||
FROM platform p
|
||||
INNER JOIN platform_component pc ON p.id = pc.platform_id
|
||||
WHERE pc.type = 'comm'
|
||||
AND p.scenario_id = #{scenarioId}
|
||||
</select>
|
||||
<select id="getComponents" resultType="com.solution.rule.domain.PlatformComponent"
|
||||
parameterType="java.lang.Integer">
|
||||
SELECT id,name,type,description,platform_id
|
||||
FROM platform_component
|
||||
WHERE platform_id = #{platformId}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<resultMap id="VPlatformComponentMap" type="com.solution.rule.domain.PlatformComponent">
|
||||
<result property="id" column="id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="type" column="type"/>
|
||||
<result property="description" column="description"/>
|
||||
<result property="platformId" column="platform_id"/>
|
||||
<result property="num" column="num"/>
|
||||
</resultMap>
|
||||
<select id="findComponentsByPlatformId" resultMap="VPlatformComponentMap">
|
||||
SELECT * FROM platform_component
|
||||
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"/>
|
||||
<result property="description" column="description"/>
|
||||
<collection property="components"
|
||||
ofType="com.solution.rule.domain.PlatformComponent"
|
||||
column="id"
|
||||
select="findComponentsByPlatformId"/>
|
||||
</resultMap>
|
||||
<select id="findPlatformComponents" resultMap="VPlatformMap"
|
||||
parameterType="java.lang.Integer">
|
||||
SELECT DISTINCT
|
||||
p.*,
|
||||
pc.*
|
||||
FROM platform p
|
||||
LEFT JOIN platform_component pc ON p.id = pc.platform_id
|
||||
WHERE pc.type = 'comm'
|
||||
AND p.scenario_id = #{scenarioId}
|
||||
ORDER BY p.name,pc.name
|
||||
</select>
|
||||
|
||||
<select id="findAllPlatformComponents" resultMap="VPlatformMap">
|
||||
SELECT *
|
||||
FROM platform
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,66 +0,0 @@
|
||||
<?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.rule.mapper.FireRuleMapper">
|
||||
|
||||
|
||||
<resultMap id="platformComponentCountMap" type="com.solution.rule.domain.vo.WeaponModelVO">
|
||||
<result property="platformName" column="platform_name"/>
|
||||
<result property="componentName" column="component_name"/>
|
||||
<result property="count" column="count"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="PlatformComponentNamesVOResultMap" type="com.solution.rule.domain.vo.PlatformComponentNamesVO">
|
||||
<result property="platformName" column="platformName"/>
|
||||
<collection property="componentNames" ofType="java.lang.String">
|
||||
<result column="componentName"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="getWeapon" resultMap="platformComponentCountMap">
|
||||
SELECT
|
||||
p.name AS platform_name,
|
||||
pc.name AS component_name,
|
||||
COUNT(pc.name) AS count
|
||||
FROM platform p
|
||||
LEFT JOIN platform_component pc ON p.id = pc.platform_id
|
||||
GROUP BY p.id, p.name, pc.name
|
||||
ORDER BY p.id, pc.name
|
||||
|
||||
</select>
|
||||
|
||||
<select id="getPlatformComponentNames" resultType="com.solution.rule.domain.vo.WeaponModelVO">
|
||||
SELECT DISTINCT
|
||||
p.name AS platformName,
|
||||
pc.name AS componentName
|
||||
FROM platform p
|
||||
INNER JOIN platform_component pc ON p.id = pc.platform_id
|
||||
WHERE pc.name IS NOT NULL
|
||||
ORDER BY p.name, pc.name
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getModuleAndCount" resultType="com.solution.rule.domain.vo.ComponentCountVO">
|
||||
SELECT
|
||||
name AS componentName,
|
||||
COUNT(*) AS count
|
||||
FROM platform_component
|
||||
WHERE name IS NOT NULL
|
||||
GROUP BY name
|
||||
ORDER BY count DESC;
|
||||
</select>
|
||||
|
||||
<select id="getCommPlatformComponentNames" resultMap="PlatformComponentNamesVOResultMap"
|
||||
parameterType="java.lang.Integer">
|
||||
SELECT
|
||||
p.name AS platformName,
|
||||
pc.name AS componentName
|
||||
FROM platform p
|
||||
INNER JOIN platform_component pc ON p.id = pc.platform_id
|
||||
WHERE pc.type = "comm"
|
||||
AND p.scenario_id = #{scenarioId}
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
133
auto-solution-rule/src/main/resources/rules/README.md
Normal file
133
auto-solution-rule/src/main/resources/rules/README.md
Normal file
@@ -0,0 +1,133 @@
|
||||
# fire-rule.drl 说明文档
|
||||
|
||||
本文档对应当前 `auto-solution-rule/src/main/resources/rules/fire-rule.drl` 的实现,分为三部分:
|
||||
- 业务人员修改
|
||||
- 业务人员理解
|
||||
- 开发人员理解
|
||||
|
||||
---
|
||||
|
||||
## 一、业务人员修改(只改这里)
|
||||
|
||||
只改 `buildBusinessConfig()` 的配置值,不要改 `rule/function` 代码。
|
||||
|
||||
### 1) 武器匹配配置
|
||||
- `map_air_targets`:蓝方空中目标 -> 红方武器(逗号分隔,多选)
|
||||
- `map_ground_targets`:蓝方地面目标 -> 红方武器
|
||||
- `map_armor_targets`:蓝方装甲目标 -> 红方武器
|
||||
- `map_artillery_targets`:蓝方炮类目标 -> 红方武器
|
||||
- `map_missile_targets`:蓝方导弹能力目标 -> 红方武器
|
||||
- `enableAirRule/enableGroundRule/enableArmorRule/enableMissileVehicleRule`:是否启用对应策略
|
||||
- `allowMultiGroup`:是否允许多组策略叠加
|
||||
|
||||
### 2) 导弹联动配置
|
||||
- `enableMissileLinkage`:导弹联动开关
|
||||
- `missileCountOffset`:红方导弹数量偏移
|
||||
- `missileRangeOffset`:红方导弹范围偏移
|
||||
- `minBlueMissileCountForLinkage`:蓝方导弹数量触发阈值
|
||||
|
||||
### 3) targetId 绑定配置
|
||||
- `enableTargetAutoBind`:是否自动给红方武器写 `targetId`
|
||||
- `minTargetBindRatio`:最低绑定比例(例:`0.7`)
|
||||
- `allowReserveWithoutTarget`:是否允许少量红方武器 `targetId` 为空
|
||||
|
||||
### 4) 阵位部署配置
|
||||
- `enablePositionRules`:阵位规则总开关
|
||||
- `fireUnitSpacingMeters`:火力单元间距(米)
|
||||
- `airDeployZonePreference`:飞机优先区(`combat`/`defense`)
|
||||
- `defensePriorityWeapons`:优先防区部署武器(逗号分隔)
|
||||
- `groundDeployHeight` / `airDeployHeight`:地面/空中部署高度
|
||||
- 区域输入固定来自 `blueTask.warZoneLocation` 与 `blueTask.defZoneLocation`(各 4 点经纬度)
|
||||
|
||||
### 5) 航迹策略配置
|
||||
- `enableTrajectoryRules`:航迹规则总开关
|
||||
- `strategyMode`:`auto/shortest/flank/interfere`
|
||||
- `enableShortest/enableFlank/enableInterfere`:策略开关
|
||||
- `nearDefDistanceMeters`、`farDefDistanceMeters`、`fastSpeedThreshold`:智能选择阈值
|
||||
- `flankOffsetMeters`:绕后偏移
|
||||
- `interfereOffsetMeters`、`interfereZigzagAmplitude`:干扰偏移与摆动
|
||||
- `keepBlueHeight`:是否沿用蓝方高度
|
||||
- `redTrackHeightOverride`:不沿用时红方统一高度
|
||||
|
||||
---
|
||||
|
||||
## 二、业务人员理解(规则在做什么)
|
||||
|
||||
### 1) 武器匹配
|
||||
- 根据蓝方武器类型匹配红方武器。
|
||||
- 映射可多选,可关闭,可允许不命中。
|
||||
|
||||
### 2) 组件与参数
|
||||
- 红方武器自动补组件和参数。
|
||||
- 炮类武器组件限制为“炮弹”,单位“范围米”。
|
||||
|
||||
### 3) 任务自动命名
|
||||
- 任务名按红方最终武器自动生成,确保名称和武器一致。
|
||||
|
||||
### 4) 目标绑定
|
||||
- 红方武器 `targetId` 自动绑定蓝方 `equipmentId`。
|
||||
- 支持同类优先匹配和绑定比例控制。
|
||||
- 允许少量空目标做火力冗余。
|
||||
|
||||
### 5) 阵位部署
|
||||
- 依据作战区/防区多边形(4点)生成部署点。
|
||||
- 飞机按偏好区部署,重火力优先防区。
|
||||
- 支持“每 N 米一个火力单元”覆盖。
|
||||
|
||||
### 6) 航迹生成
|
||||
- 红方 `trackPoints` 根据蓝方 `trackPoints` 生成。
|
||||
- 点数保持一致。
|
||||
- 策略可手动选或自动选:
|
||||
- near+fast -> shortest
|
||||
- far+fast -> interfere
|
||||
- 其他 -> flank
|
||||
|
||||
### 7) 阵位输入示例(Task 字段)
|
||||
```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 }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 三、开发人员理解(维护重点)
|
||||
|
||||
### 1) 主要规则链(agenda-group: 打击任务)
|
||||
- `红方武器自适应装配规则`
|
||||
- `导弹联动增强规则`
|
||||
- `任务自动匹配规则`
|
||||
- `阵位规则-区域解析与点位生成`
|
||||
- `阵位规则-武器部署赋位`
|
||||
- `航迹规则-生成红方航迹`
|
||||
|
||||
`任务匹配1/2`、`装备组件匹配`、`组件参数匹配` 为 legacy 占位。
|
||||
|
||||
### 2) 关键函数
|
||||
- 武器装配:`configureRedWeaponsByBlue(...)`
|
||||
- 导弹联动:`applyMissileLinkage(...)`
|
||||
- 任务命名:`assignTaskNameByRedWeapons(...)`
|
||||
- 目标绑定:`bindTargetIdsForRedWeapons(...)`
|
||||
- 阵位部署:`prepareDeploymentPools(...)`、`applyWeaponDeployment(...)`
|
||||
- 航迹生成:`applyTrajectoryGeneration(...)`、`chooseTrajectoryStrategy(...)`、`generateRedTrackPoints(...)`
|
||||
|
||||
### 3) Drools 注意事项
|
||||
- DRL function 避免泛型签名(如 `List<Coordinate>`),统一用原始 `List/Map`。
|
||||
- 读取配置统一走 `readIntCfg/readBooleanCfg/readDoubleCfg`。
|
||||
- 新规则尽量参数化放进 `buildBusinessConfig()`,不要硬编码常量在函数里。
|
||||
|
||||
### 4) 输入约定
|
||||
- 阵位:`blueTask.warZoneLocation/defZoneLocation`(`List<Coordinate>`,4 点)
|
||||
- 航迹:`blueTask.trackPoints` 非空才会生成红方航迹
|
||||
- 目标绑定:蓝方武器应提供 `equipmentId`
|
||||
1750
auto-solution-rule/src/main/resources/rules/fire-rule.drl
Normal file
1750
auto-solution-rule/src/main/resources/rules/fire-rule.drl
Normal file
File diff suppressed because it is too large
Load Diff
41
auto-solution-scene/pom.xml
Normal file
41
auto-solution-scene/pom.xml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>solution</artifactId>
|
||||
<groupId>com.solution</groupId>
|
||||
<version>3.9.1</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>solution-scene</artifactId>
|
||||
|
||||
<description>
|
||||
scene模块
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.solution</groupId>
|
||||
<artifactId>solution-rule</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 通用工具-->
|
||||
<dependency>
|
||||
<groupId>com.solution</groupId>
|
||||
<artifactId>solution-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,4 +1,6 @@
|
||||
package com.solution.system.domain;
|
||||
package com.solution.scene.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 场景配置表
|
||||
@@ -11,6 +13,16 @@ public class AfsimScenario {
|
||||
private String scenarioPath;
|
||||
private String communicationGraph; // 用于存储场景中的通讯关系
|
||||
|
||||
public List<ScenarioRelation> getRelations() {
|
||||
return relations;
|
||||
}
|
||||
|
||||
public void setRelations(List<ScenarioRelation> relations) {
|
||||
this.relations = relations;
|
||||
}
|
||||
|
||||
private List<ScenarioRelation> relations;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.solution.scene.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.util.List;
|
||||
|
||||
public class AfsimScenarioForm extends AfsimScenario {
|
||||
|
||||
private List<ScenarioRelation> relations;
|
||||
|
||||
public List<ScenarioRelation> getRelations() {
|
||||
return relations;
|
||||
}
|
||||
|
||||
public void setRelations(List<ScenarioRelation> relations) {
|
||||
this.relations = relations;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.solution.scene.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 com.solution.rule.domain.Platform;
|
||||
import com.solution.rule.domain.PlatformComponent;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ScenarioRelation implements Serializable {
|
||||
|
||||
private String edgeId;
|
||||
|
||||
private String sourceId;
|
||||
|
||||
private String sourcePort;
|
||||
|
||||
private Platform sourcePlatform;
|
||||
|
||||
private PlatformComponent sourceComponent;
|
||||
|
||||
private String targetId;
|
||||
|
||||
private String targetPort;
|
||||
|
||||
private Platform targetPlatform;
|
||||
|
||||
private PlatformComponent targetComponent;
|
||||
|
||||
public String getEdgeId() {
|
||||
return edgeId;
|
||||
}
|
||||
|
||||
public void setEdgeId(String edgeId) {
|
||||
this.edgeId = edgeId;
|
||||
}
|
||||
|
||||
public String getSourceId() {
|
||||
return sourceId;
|
||||
}
|
||||
|
||||
public void setSourceId(String sourceId) {
|
||||
this.sourceId = sourceId;
|
||||
}
|
||||
|
||||
public String getSourcePort() {
|
||||
return sourcePort;
|
||||
}
|
||||
|
||||
public void setSourcePort(String sourcePort) {
|
||||
this.sourcePort = sourcePort;
|
||||
}
|
||||
|
||||
public Platform getSourcePlatform() {
|
||||
return sourcePlatform;
|
||||
}
|
||||
|
||||
public void setSourcePlatform(Platform sourcePlatform) {
|
||||
this.sourcePlatform = sourcePlatform;
|
||||
}
|
||||
|
||||
public PlatformComponent getSourceComponent() {
|
||||
return sourceComponent;
|
||||
}
|
||||
|
||||
public void setSourceComponent(PlatformComponent sourceComponent) {
|
||||
this.sourceComponent = sourceComponent;
|
||||
}
|
||||
|
||||
public String getTargetId() {
|
||||
return targetId;
|
||||
}
|
||||
|
||||
public void setTargetId(String targetId) {
|
||||
this.targetId = targetId;
|
||||
}
|
||||
|
||||
public String getTargetPort() {
|
||||
return targetPort;
|
||||
}
|
||||
|
||||
public void setTargetPort(String targetPort) {
|
||||
this.targetPort = targetPort;
|
||||
}
|
||||
|
||||
public Platform getTargetPlatform() {
|
||||
return targetPlatform;
|
||||
}
|
||||
|
||||
public void setTargetPlatform(Platform targetPlatform) {
|
||||
this.targetPlatform = targetPlatform;
|
||||
}
|
||||
|
||||
public PlatformComponent getTargetComponent() {
|
||||
return targetComponent;
|
||||
}
|
||||
|
||||
public void setTargetComponent(PlatformComponent targetComponent) {
|
||||
this.targetComponent = targetComponent;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.solution.scene.mapper;
|
||||
|
||||
import com.solution.scene.domain.AfsimScenarioForm;
|
||||
import com.solution.scene.domain.ScenarioRelation;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PlatFormCommunicationMapper {
|
||||
|
||||
/**
|
||||
* 存储通信关系
|
||||
* @param scenaryId,afsimScenarios
|
||||
*/
|
||||
int insert(@Param("scenaryId") Integer scenaryId,
|
||||
@Param("afsimScenarios") List<ScenarioRelation> afsimScenarios);
|
||||
|
||||
|
||||
/**
|
||||
* 删除通信关系
|
||||
* @param scenaryId
|
||||
* @return
|
||||
*/
|
||||
int delete(Integer scenaryId);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.solution.scene.mapper;
|
||||
|
||||
import com.solution.scene.domain.AfsimScenario;
|
||||
import com.solution.scene.domain.AfsimScenarioForm;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SceneMapper {
|
||||
|
||||
/**
|
||||
* 保存场景配置
|
||||
* @param afsimScenario
|
||||
* @return
|
||||
*/
|
||||
int insert(AfsimScenario afsimScenario);
|
||||
|
||||
int update(AfsimScenario afsimScenario);
|
||||
|
||||
|
||||
/**
|
||||
* 获取场景列表
|
||||
* @return
|
||||
*/
|
||||
List<AfsimScenario> selectSceneList();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.solution.scene.service;
|
||||
|
||||
import com.solution.scene.domain.AfsimScenario;
|
||||
import com.solution.scene.domain.AfsimScenarioForm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SceneService {
|
||||
|
||||
/**
|
||||
* 保存场景配置
|
||||
* @param afsimScenario
|
||||
* @return
|
||||
*/
|
||||
int insert(AfsimScenario afsimScenario);
|
||||
|
||||
int update(AfsimScenarioForm afsimScenario);
|
||||
|
||||
int saveOrUpdate(AfsimScenario afsimScenario);
|
||||
|
||||
/**
|
||||
* 获取场景列表
|
||||
* @return
|
||||
*/
|
||||
List<AfsimScenario> selectSceneList();
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.solution.scene.service.impl;
|
||||
|
||||
import com.solution.scene.domain.AfsimScenario;
|
||||
import com.solution.scene.domain.AfsimScenarioForm;
|
||||
import com.solution.scene.mapper.PlatFormCommunicationMapper;
|
||||
import com.solution.scene.mapper.SceneMapper;
|
||||
import com.solution.scene.service.SceneService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class SceneServiceImpl implements SceneService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private SceneMapper sceneMapper;
|
||||
|
||||
@Autowired
|
||||
private PlatFormCommunicationMapper platFormCommunicationMapper;
|
||||
|
||||
@Override
|
||||
public int insert(AfsimScenario afsimScenario) {
|
||||
return sceneMapper.insert(afsimScenario);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(AfsimScenarioForm afsimScenario) {
|
||||
return sceneMapper.update(afsimScenario);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public int saveOrUpdate(AfsimScenario afsimScenario) {
|
||||
if (null != afsimScenario.getId() && afsimScenario.getId() > 0) {
|
||||
// 更新场景
|
||||
int updated = sceneMapper.update(afsimScenario);
|
||||
// 先删除通信关系
|
||||
platFormCommunicationMapper.delete(afsimScenario.getId());
|
||||
// 再插入通信关系
|
||||
if (afsimScenario.getRelations() != null && !afsimScenario.getRelations().isEmpty()) {
|
||||
platFormCommunicationMapper.insert(afsimScenario.getId(), afsimScenario.getRelations());
|
||||
}
|
||||
return updated;
|
||||
} else {
|
||||
// 新增场景
|
||||
int inserted = sceneMapper.insert(afsimScenario);
|
||||
// 确保获取到生成的 ID
|
||||
if (afsimScenario.getId() != null && afsimScenario.getRelations() != null && !afsimScenario.getRelations().isEmpty()) {
|
||||
// 存储通信关系
|
||||
platFormCommunicationMapper.insert(afsimScenario.getId(), afsimScenario.getRelations());
|
||||
}
|
||||
return inserted;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取场景列表
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<AfsimScenario> selectSceneList() {
|
||||
return sceneMapper.selectSceneList();
|
||||
}
|
||||
}
|
||||
@@ -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.scene.mapper.PlatFormCommunicationMapper">
|
||||
|
||||
|
||||
<insert id="insert" parameterType="com.solution.scene.domain.AfsimScenarioForm">
|
||||
INSERT INTO platform_communication (scenary_id, command_platform, subordinate_platform, command_comm, subordinate_comm)
|
||||
VALUES
|
||||
<foreach collection="afsimScenarios" item="item" separator=",">
|
||||
(#{scenaryId}, #{item.sourcePlatform.name}, #{item.targetPlatform.name}, #{item.sourceComponent.name}, #{item.targetComponent.name})
|
||||
</foreach>
|
||||
</insert>
|
||||
<delete id="delete" parameterType="java.lang.Integer">
|
||||
DELETE FROM platform_communication
|
||||
WHERE scenary_id = #{scenaryId}
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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.scene.mapper.SceneMapper">
|
||||
|
||||
<resultMap id="SceneMap" type="com.solution.scene.domain.AfsimScenario">
|
||||
<result property="id" column="id" />
|
||||
<result property="name" column="name" />
|
||||
<result property="description" column="description" />
|
||||
<result property="scenarioPath" column="scenario_path" />
|
||||
<result property="communicationGraph" column="communication_graph" />
|
||||
</resultMap>
|
||||
|
||||
<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})
|
||||
</insert>
|
||||
|
||||
<select id="selectSceneList" resultMap="SceneMap">
|
||||
SELECT id, name, description, scenario_path, communication_graph FROM afsim_scenario
|
||||
</select>
|
||||
|
||||
<insert id="update" parameterType="com.solution.scene.domain.AfsimScenario">
|
||||
update afsim_scenario
|
||||
set name=#{name},
|
||||
description=#{description},
|
||||
scenario_path=#{scenarioPath},
|
||||
communication_graph=#{communicationGraph}
|
||||
where id=#{id}
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
1
modeler/src/assets/icons/platform.svg
Normal file
1
modeler/src/assets/icons/platform.svg
Normal file
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1773577091908" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7408" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M285.952 623.616c-94.464 0-171.264-76.8-171.264-171.264s76.8-171.264 171.264-171.264c11.008 0 21.76 1.024 32.512 3.072 16.64 3.072 27.648 19.2 24.32 35.84-3.072 16.64-19.2 27.648-35.84 24.32-6.912-1.28-13.824-2.048-20.736-2.048-60.672 0-109.824 49.152-109.824 109.824s49.152 109.824 109.824 109.824c16.896 0 30.72 13.824 30.72 30.72s-14.08 30.976-30.976 30.976z" fill="#FFFFFF" p-id="7409"></path><path d="M313.088 343.296c-13.824 0-26.624-9.472-29.952-23.552-3.84-15.872-5.632-32.256-5.632-48.896 0-116.48 94.72-211.456 211.456-211.456 55.552 0 108.032 21.504 147.712 60.16 39.68 38.912 62.208 90.624 63.488 146.176 0.512 16.896-13.056 30.976-29.952 31.488h-0.768c-16.64 0-30.208-13.312-30.72-29.952-1.792-80.64-69.12-146.432-150.016-146.432-82.688 0-150.016 67.328-150.016 150.016 0 11.776 1.28 23.296 4.096 34.816 3.84 16.384-6.4 33.024-22.784 36.864-2.304 0.512-4.608 0.768-6.912 0.768z" fill="#FFFFFF" p-id="7410"></path><path d="M702.72 623.616c-16.896 0-30.72-13.824-30.72-30.72s13.824-30.72 30.72-30.72c73.472 0 133.12-59.648 133.12-133.12s-59.648-133.12-133.12-133.12c-8.96 0-18.176 1.024-26.88 2.816-16.64 3.328-32.768-7.424-36.352-24.064-3.328-16.64 7.424-32.768 23.808-36.352 12.8-2.56 26.112-3.84 39.168-3.84 107.264 0 194.56 87.296 194.56 194.56s-87.04 194.56-194.304 194.56z" fill="#FFFFFF" p-id="7411"></path><path d="M286.976 562.176h415.744v61.44H286.976z" fill="#FFFFFF" p-id="7412"></path><path d="M272.896 794.88H209.152v-61.44h63.744c4.608 0 8.448-3.84 8.448-8.448V599.04h61.44v125.952c0 38.656-31.232 69.888-69.888 69.888zM474.112 608.256h61.44v189.44h-61.44zM837.376 807.68H734.72c-38.4 0-69.888-31.232-69.888-69.888v-129.792h61.44v129.792c0 4.608 3.84 8.448 8.448 8.448h102.656v61.44z" fill="#FFFFFF" p-id="7413"></path><path d="M142.336 875.776c-59.392 0-107.52-48.128-107.52-107.52s48.128-107.52 107.52-107.52 107.52 48.128 107.52 107.52-48.128 107.52-107.52 107.52z m0-153.6c-25.344 0-46.08 20.736-46.08 46.08s20.736 46.08 46.08 46.08 46.08-20.736 46.08-46.08-20.736-46.08-46.08-46.08zM501.76 977.152c-59.392 0-107.52-48.128-107.52-107.52s48.128-107.52 107.52-107.52 107.52 48.128 107.52 107.52-48.384 107.52-107.52 107.52z m0-153.6c-25.344 0-46.08 20.736-46.08 46.08s20.736 46.08 46.08 46.08 46.08-20.736 46.08-46.08-20.736-46.08-46.08-46.08zM888.576 881.664c-59.392 0-107.52-48.128-107.52-107.52s48.128-107.52 107.52-107.52 107.52 48.128 107.52 107.52-48.384 107.52-107.52 107.52z m0-153.6c-25.344 0-46.08 20.736-46.08 46.08s20.736 46.08 46.08 46.08 46.08-20.736 46.08-46.08-20.736-46.08-46.08-46.08z" fill="#FFFFFF" p-id="7414"></path></svg>
|
||||
|
After Width: | Height: | Size: 2.8 KiB |
@@ -32,7 +32,15 @@ export const routes: RouteRecordRaw[] = [
|
||||
meta: {
|
||||
title: '决策树',
|
||||
},
|
||||
component: () => import('@/views/decision/designer.vue'),
|
||||
component: () => import('@/views/decision/designer/designer.vue'),
|
||||
},
|
||||
{
|
||||
name: 'decision-communication',
|
||||
path: '/app/decision/communication',
|
||||
meta: {
|
||||
title: '通信',
|
||||
},
|
||||
component: () => import('@/views/decision/communication/communication.vue'),
|
||||
},
|
||||
{
|
||||
name: 'decision-algorithm-management',
|
||||
@@ -42,4 +50,12 @@ export const routes: RouteRecordRaw[] = [
|
||||
},
|
||||
component: () => import('@/views/decision/algorithm/management.vue'),
|
||||
},
|
||||
{
|
||||
name: 'decision-fire-rule',
|
||||
path: '/app/decision/fire-rule',
|
||||
meta: {
|
||||
title: '活力规则',
|
||||
},
|
||||
component: () => import('@/views/decision/rule/management.vue'),
|
||||
},
|
||||
]
|
||||
@@ -1204,7 +1204,7 @@
|
||||
.ant-tabs-content {
|
||||
//padding: 15px;
|
||||
padding: 4px;
|
||||
background: #041832;
|
||||
background: #041b36db;
|
||||
}
|
||||
|
||||
&.settings-tab,
|
||||
@@ -1291,6 +1291,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
.ant-select:not(.ant-select-customize-input) .ant-select-selector{
|
||||
border: 1px solid #475f71
|
||||
}
|
||||
|
||||
.ant-input-affix-wrapper.ant-input-password input:-webkit-autofill,
|
||||
.ant-input-affix-wrapper.ant-input-password input:-webkit-autofill:hover,
|
||||
.ant-input-affix-wrapper.ant-input-password input:-webkit-autofill:focus,
|
||||
@@ -1647,4 +1651,184 @@
|
||||
.anticon{
|
||||
color: #eeeeee;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.ant-switch {
|
||||
background: rgb(8 30 59);
|
||||
}
|
||||
|
||||
|
||||
.ks-algorithm-card {
|
||||
.ant-card-head-title {
|
||||
span.text {
|
||||
display: block;
|
||||
line-height: 30px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ks-sidebar-header {
|
||||
line-height: 40px;
|
||||
background: #081d36;
|
||||
min-height: 40px;
|
||||
background: url(@/assets/icons/card-head.png) left / 180% 100%;
|
||||
padding: 0 10px;
|
||||
|
||||
.ks-sidebar-title {
|
||||
color: #7ae8fc;
|
||||
font-size: 16px;
|
||||
.icon {
|
||||
background: url(@/assets/icons/list.png) center / 100% 100%;
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
display: block;
|
||||
margin-top: 7px;
|
||||
}
|
||||
.text{
|
||||
margin-left: 40px;
|
||||
font-size: 16px;
|
||||
color: #eee;
|
||||
}
|
||||
}
|
||||
|
||||
.ks-sidebar-add {
|
||||
position: absolute;
|
||||
right: 7px;
|
||||
top: 8px;
|
||||
font-size: 12px;
|
||||
|
||||
.anticon {
|
||||
display: block;
|
||||
float: left;
|
||||
line-height: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-list {
|
||||
&.ks-sidebar-list {
|
||||
.ant-list-item {
|
||||
cursor: pointer;
|
||||
transition: all 0.5s;
|
||||
border-left: 2px solid transparent;
|
||||
position: relative;
|
||||
|
||||
&.selected,
|
||||
&:hover {
|
||||
background: #0a1b3c;
|
||||
border-left: 2px solid #11377e;
|
||||
}
|
||||
}
|
||||
|
||||
.ks-sidebar-list-type {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
|
||||
.ant-badge {
|
||||
.ant-badge-count {
|
||||
color: #c3c2c2;
|
||||
background: #333f7d;
|
||||
box-shadow: 0 0 0 1px #325478;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-list-item-meta {
|
||||
.ant-list-item-meta-title {
|
||||
color: #7ae8fc;
|
||||
}
|
||||
|
||||
.ant-list-item-meta-description {
|
||||
color: #4d8c98;
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ks-sidebar-list-param-list {
|
||||
padding: 15px;
|
||||
border: 1px solid #475f71;
|
||||
border-radius: 2px;
|
||||
|
||||
.ks-sidebar-list-param-item {
|
||||
margin-bottom: 15px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
.ks-sidebar-list-param-actions {
|
||||
.anticon {
|
||||
color: #7ae8fc;
|
||||
font-size: 20px;
|
||||
display: block;
|
||||
line-height: 26px;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
.ant-collapse {
|
||||
.ant-list-sm {
|
||||
.ant-list-item {
|
||||
padding: 4px 15px;
|
||||
cursor: pointer;
|
||||
color: rgb(130 196 233);
|
||||
position: relative;
|
||||
|
||||
.ks-tree-actions {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: #0d2d4e;
|
||||
|
||||
.ks-tree-actions {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
&.ks-trees-collapse {
|
||||
|
||||
.ant-collapse-content-box {
|
||||
padding: 0;
|
||||
height: 40vh;
|
||||
position: relative;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.create-tree-icon {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ant-list-item {
|
||||
padding: 3px 5px;
|
||||
cursor: pointer;
|
||||
color: rgb(130 196 233);
|
||||
|
||||
&:hover {
|
||||
background: #0d2d4e;
|
||||
}
|
||||
}
|
||||
|
||||
.ks-model-builder-body .ks-model-builder-left .ant-collapse {
|
||||
&.platform-collapse{
|
||||
.ant-collapse-content-box{
|
||||
max-height: 45.5vh;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
新增
|
||||
</a-button>
|
||||
</div>
|
||||
<a-list item-layout="horizontal" :data-source="algorithms" class="ks-algorithm-list">
|
||||
<a-list item-layout="horizontal" :data-source="algorithms" class="ks-sidebar-list">
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item @click="()=> handleSelect(item)" :class="selectedAlgorithm?.id === item.id ? 'selected' : null">
|
||||
<a-list-item-meta :description="substring(item.description,20)">
|
||||
<template #title>
|
||||
<span class="ks-algorithm-name">{{ substring(item.name, 20) }}</span>
|
||||
<span class="ks-algorithm-type"><a-badge size="small" :count="getAlgorithmTypeName(item.type)"></a-badge></span>
|
||||
<span class="ks-sidebar-list-type"><a-badge size="small" :count="getAlgorithmTypeName(item.type)"></a-badge></span>
|
||||
</template>
|
||||
</a-list-item-meta>
|
||||
</a-list-item>
|
||||
@@ -95,8 +95,8 @@
|
||||
:name="['algorithmParamList']"
|
||||
>
|
||||
<a-form-item-rest>
|
||||
<div class="ks-algorithm-param-list">
|
||||
<div class="ks-algorithm-param-item" v-for="(item,index) in selectedAlgorithm.algorithmParamList">
|
||||
<div class="ks-sidebar-list-param-list">
|
||||
<div class="ks-sidebar-list-param-item" v-for="(item,index) in selectedAlgorithm.algorithmParamList">
|
||||
<a-row :gutter="15">
|
||||
<a-col :span="7">
|
||||
<a-input v-model:value="item.paramName" placeholder="请输入参数名" />
|
||||
@@ -108,7 +108,7 @@
|
||||
<a-input v-model:value="item.description" placeholder="请输入描述" />
|
||||
</a-col>
|
||||
<a-col :span="3">
|
||||
<a-space class="ks-algorithm-param-actions">
|
||||
<a-space class="ks-sidebar-list-param-actions">
|
||||
<MinusCircleOutlined @click="()=> handleMinus(index)" />
|
||||
<PlusCircleOutlined @click="handleAdd" v-if="index === 0" />
|
||||
</a-space>
|
||||
@@ -125,8 +125,8 @@
|
||||
:name="['algoConfig']"
|
||||
>
|
||||
<a-form-item-rest>
|
||||
<div class="ks-algorithm-param-list">
|
||||
<div class="ks-algorithm-param-item" v-for="(t,index) in selectedAlgorithm.algoConfigList">
|
||||
<div class="ks-sidebar-list-param-list">
|
||||
<div class="ks-sidebar-list-param-item" v-for="(t,index) in selectedAlgorithm.algoConfigList">
|
||||
<a-row :gutter="15">
|
||||
<a-col :span="7">
|
||||
<a-select placeholder="请选择参数" v-model:value="t.name" @change="(v: any)=> t.name = v">
|
||||
@@ -139,7 +139,7 @@
|
||||
</a-select>
|
||||
</a-col>
|
||||
<a-col :span="3">
|
||||
<a-space class="ks-algorithm-param-actions">
|
||||
<a-space class="ks-sidebar-list-param-actions">
|
||||
<MinusCircleOutlined @click="()=> handleMinusConfig(index)" />
|
||||
<PlusCircleOutlined @click="handleAddConfig" v-if="index === 0" />
|
||||
</a-space>
|
||||
@@ -274,8 +274,11 @@ const getAlgorithmTypeName = (type: NullableString): NullableString => {
|
||||
const load = () => {
|
||||
algorithms.value = [];
|
||||
algorithmsTotal.value = 0;
|
||||
formRef.value?.resetFields();
|
||||
selectedAlgorithm.value = resolveItem(defaultAlgorithm);
|
||||
|
||||
if(selectedAlgorithm.value.id <= 0){
|
||||
formRef.value?.resetFields();
|
||||
selectedAlgorithm.value = resolveItem(defaultAlgorithm);
|
||||
}
|
||||
|
||||
findAlgorithmsByQuery(query.value).then(r => {
|
||||
algorithms.value = r.rows ?? [];
|
||||
@@ -290,6 +293,7 @@ const handleCreate = () => {
|
||||
|
||||
const handleSelect = (item: Algorithm) => {
|
||||
selectedAlgorithm.value = resolveItem(item);
|
||||
formRef.value?.resetFields();
|
||||
};
|
||||
|
||||
const handleAdd = () => {
|
||||
@@ -394,120 +398,3 @@ const handleChange = (page: number, pageSize: number) => {
|
||||
onMounted(() => load());
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
.ks-algorithm-card {
|
||||
.ant-card-head-title {
|
||||
span.text {
|
||||
display: block;
|
||||
line-height: 30px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ks-sidebar-header {
|
||||
line-height: 40px;
|
||||
padding: 5px 15px;
|
||||
background: #081d36;
|
||||
min-height: 40px;
|
||||
background: url(@/assets/icons/card-head.png) left / 180% 100%;
|
||||
padding: 0 10px;
|
||||
|
||||
.ks-sidebar-title {
|
||||
color: #7ae8fc;
|
||||
font-size: 16px;
|
||||
.icon {
|
||||
background: url(@/assets/icons/list.png) center / 100% 100%;
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
display: block;
|
||||
margin-top: 7px;
|
||||
}
|
||||
.text{
|
||||
margin-left: 40px;
|
||||
font-size: 16px;
|
||||
color: #eee;
|
||||
}
|
||||
}
|
||||
|
||||
.ks-sidebar-add {
|
||||
position: absolute;
|
||||
right: 7px;
|
||||
top: 8px;
|
||||
font-size: 12px;
|
||||
|
||||
.anticon {
|
||||
display: block;
|
||||
float: left;
|
||||
line-height: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-list {
|
||||
&.ks-algorithm-list {
|
||||
.ant-list-item {
|
||||
cursor: pointer;
|
||||
transition: all 0.5s;
|
||||
border-left: 2px solid transparent;
|
||||
position: relative;
|
||||
|
||||
&.selected,
|
||||
&:hover {
|
||||
background: #0a1b3c;
|
||||
border-left: 2px solid #11377e;
|
||||
}
|
||||
}
|
||||
|
||||
.ks-algorithm-type {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
|
||||
.ant-badge {
|
||||
.ant-badge-count {
|
||||
color: #c3c2c2;
|
||||
background: #333f7d;
|
||||
box-shadow: 0 0 0 1px #325478;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-list-item-meta {
|
||||
.ant-list-item-meta-title {
|
||||
color: #7ae8fc;
|
||||
}
|
||||
|
||||
.ant-list-item-meta-description {
|
||||
color: #4d8c98;
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ks-algorithm-param-list {
|
||||
padding: 15px;
|
||||
border: 1px solid #475f71;
|
||||
border-radius: 2px;
|
||||
|
||||
.ks-algorithm-param-item {
|
||||
margin-bottom: 15px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
.ks-algorithm-param-actions {
|
||||
.anticon {
|
||||
color: #7ae8fc;
|
||||
font-size: 20px;
|
||||
display: block;
|
||||
line-height: 26px;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -8,33 +8,14 @@
|
||||
*/
|
||||
|
||||
import { HttpRequestClient } from '@/utils/request';
|
||||
import type { BehaviorTree, BehaviorTreeDetailsResponse, BehaviorTreePageResponse, BehaviorTreeRequest, NodeTemplatesResponse } from './types';
|
||||
import type { BasicResponse } from '@/types';
|
||||
import type { PlatformListableResponse } from './types';
|
||||
|
||||
const req = HttpRequestClient.create<BasicResponse>({
|
||||
baseURL: '/api',
|
||||
});
|
||||
|
||||
export const findNodeTemplates = (): Promise<NodeTemplatesResponse> => {
|
||||
return req.get('/system/nodetemplate/all');
|
||||
};
|
||||
|
||||
export const findTreesByQuery = (query: Partial<BehaviorTreeRequest> = {}): Promise<BehaviorTreePageResponse> => {
|
||||
return req.get<BehaviorTreePageResponse>('/system/behaviortree/list', query);
|
||||
};
|
||||
|
||||
export const findOneTreeById = (id: number): Promise<BehaviorTreeDetailsResponse> => {
|
||||
return req.get(`/system/behaviortree/${id}`);
|
||||
};
|
||||
|
||||
export const deleteOneTreeById = (id: number): Promise<BehaviorTreeDetailsResponse> => {
|
||||
return req.delete(`/system/behaviortree/${id}`);
|
||||
};
|
||||
|
||||
export const updateTree = (rt: Partial<BehaviorTree>): Promise<BasicResponse> => {
|
||||
return req.postJson(`/system/behaviortree`, rt);
|
||||
};
|
||||
|
||||
export const createTree = (rt: Partial<BehaviorTree>): Promise<BasicResponse> => {
|
||||
return req.putJson(`/system/behaviortree`, rt);
|
||||
};
|
||||
export const findAllBasicPlatforms = (): Promise<PlatformListableResponse> => {
|
||||
return req.get<PlatformListableResponse>('/system/firerule/platforms/basic');
|
||||
};
|
||||
33
modeler/src/views/decision/communication/api.ts
Normal file
33
modeler/src/views/decision/communication/api.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 { HttpRequestClient } from '@/utils/request';
|
||||
import type { Scenario, ScenarioPageableResponse, ScenarioRequest } from './types';
|
||||
import type { PlatformWithComponentsResponse } from '../types';
|
||||
import type { BasicResponse } from '@/types';
|
||||
|
||||
const req = HttpRequestClient.create<BasicResponse>({
|
||||
baseURL: '/api',
|
||||
});
|
||||
|
||||
export const findScenarioByQuery = (_query: Partial<ScenarioRequest> = {}): Promise<ScenarioPageableResponse> => {
|
||||
return req.get('/system/scene/list', _query);
|
||||
};
|
||||
|
||||
export const deleteOneScenarioById = (id: number): Promise<BasicResponse> => {
|
||||
return req.delete(`/system/behaviortree/${id}`);
|
||||
};
|
||||
|
||||
export const findPlatformWithComponents = (id: number): Promise<PlatformWithComponentsResponse> => {
|
||||
return req.get(`/system/firerule/platforms/${id}`);
|
||||
};
|
||||
|
||||
export const saveScenario = (scenario: Scenario): Promise<BasicResponse> => {
|
||||
return req.postJson(`/system/scene/saveSceneConfig`,scenario);
|
||||
};
|
||||
446
modeler/src/views/decision/communication/communication.vue
Normal file
446
modeler/src/views/decision/communication/communication.vue
Normal file
@@ -0,0 +1,446 @@
|
||||
<template>
|
||||
<Wrapper>
|
||||
<a-layout class="bg-transparent" style="background: transparent">
|
||||
<Header />
|
||||
<a-layout class="ks-layout-body">
|
||||
<div class="ks-model-builder-body">
|
||||
<div class="ks-model-builder-left">
|
||||
<PlatformCard
|
||||
ref="scenariosCardRef"
|
||||
@create="handleCreate"
|
||||
@select="handleSelect"
|
||||
/>
|
||||
<NodesCard
|
||||
v-if="currentScenario && currentScenario.id >0"
|
||||
:scenario="currentScenario"
|
||||
@drag-item-start="handleDragStart"
|
||||
@drag-item-end="handleDragEnd"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="ks-model-builder-content" style="width: calc(100% - 250px);">
|
||||
<div class="ks-model-builder-actions">
|
||||
<a-space>
|
||||
<a-button v-if="graph && currentScenario" class="ks-model-builder-save" size="small" @click="handleSave">
|
||||
<CheckOutlined />
|
||||
<span>保存</span>
|
||||
</a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
<!-- 画布容器,添加拖放事件 -->
|
||||
<div
|
||||
ref="canvas"
|
||||
class="ks-model-builder-canvas"
|
||||
@dragenter="handleDragEnter"
|
||||
@dragleave="handleDragLeave"
|
||||
@drop="handleDrop"
|
||||
@dragover.prevent
|
||||
></div>
|
||||
<TeleportContainer />
|
||||
</div>
|
||||
</div>
|
||||
</a-layout>
|
||||
</a-layout>
|
||||
</Wrapper>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import {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';
|
||||
import { CheckCircleOutlined, CheckOutlined, RollbackOutlined, SaveOutlined } from '@ant-design/icons-vue';
|
||||
import { Wrapper } from '@/components/wrapper';
|
||||
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
||||
import Header from '../header.vue';
|
||||
|
||||
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';
|
||||
|
||||
const TeleportContainer = defineComponent(getTeleport());
|
||||
|
||||
registerScenarioElement();
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
PlatformCard,
|
||||
NodesCard,
|
||||
Wrapper,
|
||||
Header,
|
||||
SaveOutlined,
|
||||
CheckCircleOutlined,
|
||||
CheckOutlined,
|
||||
RollbackOutlined,
|
||||
TeleportContainer,
|
||||
},
|
||||
setup() {
|
||||
const router = useRouter();
|
||||
const canvas = ref<HTMLDivElement | null>(null);
|
||||
const graph = ref<Graph | null>(null);
|
||||
const currentZoom = ref<number>(1);
|
||||
const draggedNodeData = ref<PlatformWithComponents | null>(null);
|
||||
const isDraggingOver = ref(false);
|
||||
const currentScenarioEditing = ref<boolean>(false);
|
||||
const currentScenario = ref<Scenario | null>(null);
|
||||
const currentGraph = ref<GraphContainer | null>(null);
|
||||
const selectedModelNode = ref<Node<NodeProperties> | null>(null);
|
||||
const selectedNodeTaskElement = ref<GraphTaskElement | null>(null);
|
||||
const changed = ref<boolean>(false);
|
||||
const scenariosCardRef = ref<InstanceType<typeof PlatformCard> | null>(null);
|
||||
|
||||
const {
|
||||
handleGraphEvent,
|
||||
createCanvas,
|
||||
zoomIn,
|
||||
zoomOut,
|
||||
fitToScreen,
|
||||
centerContent,
|
||||
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;
|
||||
};
|
||||
|
||||
// 处理拖动结束
|
||||
const handleDragEnd = () => {
|
||||
isDraggingOver.value = false;
|
||||
};
|
||||
|
||||
// 处理拖动进入
|
||||
const handleDragEnter = (e: DragEvent) => {
|
||||
safePreventDefault(e);
|
||||
safeStopPropagation(e);
|
||||
isDraggingOver.value = true;
|
||||
};
|
||||
|
||||
// 处理拖动离开
|
||||
const handleDragLeave = (e: DragEvent) => {
|
||||
safePreventDefault(e);
|
||||
safeStopPropagation(e);
|
||||
|
||||
if (canvas.value && e.relatedTarget &&
|
||||
typeof e.relatedTarget === 'object' &&
|
||||
'nodeType' in e.relatedTarget) {
|
||||
// 使用 Element 类型而不是 x6 的 Node 类型
|
||||
if (!canvas.value.contains(e.relatedTarget as Element)) {
|
||||
isDraggingOver.value = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 处理放置
|
||||
const handleDrop = (e: DragEvent) => {
|
||||
console.info('handleDrop', e);
|
||||
safePreventDefault(e);
|
||||
safeStopPropagation(e);
|
||||
isDraggingOver.value = false;
|
||||
currentScenarioEditing.value = false;
|
||||
|
||||
if (!currentScenario.value) {
|
||||
message.error('请先选择场景.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!graph.value || !canvas.value || !draggedNodeData.value) {
|
||||
message.error('无法放置节点,缺少必要数据');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 获取拖动的数据
|
||||
const pwc = draggedNodeData.value as PlatformWithComponents;
|
||||
|
||||
// if (!hasElements(graph.value as Graph)) {
|
||||
// message.error('请先添加根节点.');
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (hasRootElementNode(graph.value as Graph)) {
|
||||
// message.error('根节点已经存在.');
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 计算相对于画布的位置(考虑缩放)
|
||||
const rect = canvas.value.getBoundingClientRect();
|
||||
const scale = currentZoom.value || 1;
|
||||
const x = (e.clientX - rect.left) / scale;
|
||||
const y = (e.clientY - rect.top) / scale;
|
||||
|
||||
console.log('放置节点:', { ...pwc, x, y });
|
||||
|
||||
// 创建节点数据
|
||||
const settingTaskElement: GraphTaskElement = createGraphTaskElementFromScenario(pwc, { x, y });
|
||||
// 创建节点
|
||||
const settingTaskNode = createGraphScenarioElement(settingTaskElement);
|
||||
console.info('create settingTaskNode: ', settingTaskElement, settingTaskNode);
|
||||
|
||||
// 将节点添加到画布
|
||||
graph.value?.addNode(settingTaskNode as any);
|
||||
console.log('节点已添加到画布:', settingTaskNode.id);
|
||||
|
||||
// 重置拖动数据
|
||||
draggedNodeData.value = null;
|
||||
} catch (error) {
|
||||
console.error('放置节点时出错:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSelect = (scenario: Scenario) => {
|
||||
let nodeGraph: GraphContainer | null = null;
|
||||
try {
|
||||
nodeGraph = JSON.parse(scenario.communicationGraph as unknown as string) as unknown as GraphContainer;
|
||||
} catch (e: any) {
|
||||
console.error('parse error,cause:', e);
|
||||
}
|
||||
if (!nodeGraph) {
|
||||
nodeGraph = {
|
||||
nodes: [],
|
||||
edges: [],
|
||||
};
|
||||
}
|
||||
currentScenario.value = {
|
||||
...scenario,
|
||||
graph: nodeGraph,
|
||||
relations: []
|
||||
};
|
||||
currentScenarioEditing.value = true;
|
||||
createElements();
|
||||
};
|
||||
|
||||
const createElements = () => {
|
||||
nextTick(() => {
|
||||
try {
|
||||
graph.value?.clearCells();
|
||||
} catch (e: any) {
|
||||
console.error('clear cells error, cause:', e);
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (currentScenario.value?.graph && graph.value) {
|
||||
if (currentScenario.value?.graph.nodes) {
|
||||
currentScenario.value?.graph.nodes.forEach(ele => {
|
||||
const node = createGraphScenarioElement(ele as GraphTaskElement);
|
||||
// 将节点添加到画布
|
||||
graph.value?.addNode(node as Node);
|
||||
});
|
||||
}
|
||||
if (currentScenario.value?.graph.edges) {
|
||||
// 然后添加所有边,确保包含桩点信息
|
||||
setTimeout(() => {
|
||||
currentScenario.value?.graph.edges.forEach(edgeData => {
|
||||
graph.value?.addEdge({
|
||||
...edgeData,
|
||||
...createLineOptions(),
|
||||
});
|
||||
});
|
||||
}, 100); // 延迟一会儿,免得连线错位
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
};
|
||||
|
||||
const handleCreate = () => {
|
||||
currentScenario.value = {
|
||||
id: 0,
|
||||
name: null,
|
||||
description: null,
|
||||
communicationGraph: null,
|
||||
relations: [],
|
||||
graph: {
|
||||
edges: [],
|
||||
nodes: [],
|
||||
},
|
||||
};
|
||||
currentGraph.value = {
|
||||
edges: [],
|
||||
nodes: [],
|
||||
};
|
||||
selectedModelNode.value = null;
|
||||
selectedNodeTaskElement.value = null;
|
||||
|
||||
createElements();
|
||||
};
|
||||
|
||||
// 初始化X6画布
|
||||
const initGraph = () => {
|
||||
if (!canvas.value) {
|
||||
console.error('画布容器不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
graph.value = createCanvas(canvas.value);
|
||||
console.log('画布初始化成功');
|
||||
createElements();
|
||||
|
||||
// 监听缩放变化
|
||||
handleGraphEvent('scale', ({ sx }: { sx: number }) => {
|
||||
currentZoom.value = sx;
|
||||
});
|
||||
|
||||
handleGraphEvent('blank:click', () => {
|
||||
selectedModelNode.value = null;
|
||||
selectedNodeTaskElement.value = null;
|
||||
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)
|
||||
if(element && element.platformId ){
|
||||
window.location.href = `/app/decision/designer?platform=${element.platformId}`
|
||||
} else {
|
||||
window.location.href = '/app/decision/designer'
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
selectedModelNode.value = node;
|
||||
selectedNodeTaskElement.value = JSON.parse(JSON.stringify(newElement || {})) as GraphTaskElement;
|
||||
});
|
||||
|
||||
// 监听节点鼠标事件,显示/隐藏连接点
|
||||
handleGraphEvent('node:mouseenter', (_ctx: any) => {
|
||||
});
|
||||
|
||||
handleGraphEvent('node:mouseleave', (_ctx: any) => {
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('初始化画布失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 监听窗口大小变化
|
||||
const handleResize = () => {
|
||||
nextTick(() => {
|
||||
resizeCanvas();
|
||||
});
|
||||
};
|
||||
|
||||
const init = () => {
|
||||
console.info('init');
|
||||
nextTick(() => {
|
||||
initGraph();
|
||||
window.addEventListener('resize', handleResize);
|
||||
console.log('节点挂载完成');
|
||||
});
|
||||
};
|
||||
|
||||
const handleUpdateElement = (element: GraphTaskElement) => {
|
||||
// 更新选中的节点数据
|
||||
if (selectedModelNode.value) {
|
||||
selectedModelNode.value.replaceData(element);
|
||||
}
|
||||
console.info('handleUpdateElement', element);
|
||||
// 更新本地引用
|
||||
selectedNodeTaskElement.value = element;
|
||||
changed.value = true;
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
const graphData: GraphContainer = resolveGraph(graph.value as Graph);
|
||||
|
||||
const relations = resolveConnectionRelation(graph.value as Graph);
|
||||
console.error('relations',relations)
|
||||
|
||||
console.info('handleSave', graphData);
|
||||
if (!currentScenario.value) {
|
||||
message.error('当前决策树不存在');
|
||||
return;
|
||||
}
|
||||
const newScenario: Scenario = {
|
||||
...currentScenario.value,
|
||||
graph: graphData,
|
||||
communicationGraph: JSON.stringify(graphData),
|
||||
relations: relations
|
||||
};
|
||||
if (!newScenario.name) {
|
||||
message.error('场景名称不能为空.');
|
||||
return;
|
||||
}
|
||||
let res = null;
|
||||
if (currentScenario.value.id > 0) {
|
||||
res = saveScenario(newScenario);
|
||||
} else {
|
||||
res = saveScenario(newScenario);
|
||||
}
|
||||
res.then(r => {
|
||||
if (r.code === 200) {
|
||||
scenariosCardRef.value?.refresh();
|
||||
message.success(r.msg ?? '操作成功.');
|
||||
} else {
|
||||
message.error(r.msg ?? '操作失败.');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
init();
|
||||
});
|
||||
|
||||
// 清理
|
||||
onBeforeUnmount(() => destroy());
|
||||
|
||||
return {
|
||||
scenariosCardRef,
|
||||
handleCreate,
|
||||
currentScenarioEditing,
|
||||
currentScenario,
|
||||
currentGraph,
|
||||
selectedNodeTaskElement,
|
||||
selectedModelNode,
|
||||
graph,
|
||||
canvas,
|
||||
zoomIn,
|
||||
zoomOut,
|
||||
fitToScreen,
|
||||
centerContent,
|
||||
handleDragStart,
|
||||
handleDragEnd,
|
||||
handleDragEnter,
|
||||
handleDragLeave,
|
||||
handleDrop,
|
||||
isDraggingOver,
|
||||
handleSave,
|
||||
handleUpdateElement,
|
||||
handleSelect,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
322
modeler/src/views/decision/communication/node.vue
Normal file
322
modeler/src/views/decision/communication/node.vue
Normal file
@@ -0,0 +1,322 @@
|
||||
<template>
|
||||
<a-dropdown :trigger="['contextmenu']" @openChange="handleVisibleChange">
|
||||
<a-card
|
||||
:class="[
|
||||
'ks-scenario-node',
|
||||
`ks-scenario-${element?.category ?? 'model'}-node`
|
||||
]"
|
||||
hoverable
|
||||
>
|
||||
<template #title>
|
||||
<a-space>
|
||||
<span class="ks-scenario-node-title">{{ element?.description ?? element?.name ?? '-' }}</span>
|
||||
</a-space>
|
||||
</template>
|
||||
|
||||
<!-- 节点内容区域 -->
|
||||
<div class="w-full">
|
||||
<div class="ks-scenario-node-content">
|
||||
<div
|
||||
v-for="(item, index) in element?.components || []"
|
||||
:key="item.id || index"
|
||||
class="ks-scenario-node-row"
|
||||
>
|
||||
<div
|
||||
:data-port="`in-${item.id || index}`"
|
||||
:port="`in-${item.id || index}`"
|
||||
:title="`入桩: ${item.name}`"
|
||||
class="port port-in"
|
||||
magnet="passive"
|
||||
:data-item="JSON.stringify(item)"
|
||||
>
|
||||
<div class="triangle-left"></div>
|
||||
</div>
|
||||
|
||||
<!-- child名称 -->
|
||||
<div class="ks-scenario-node-name">
|
||||
{{ substring(item.description ?? item.name, 20) }}
|
||||
</div>
|
||||
|
||||
<!-- 右侧出桩:只能作为连线源 -->
|
||||
<div
|
||||
:data-port="`out-${item.id || index}`"
|
||||
:port="`out-${item.id || index}`"
|
||||
:title="`出桩: ${item.name}`"
|
||||
class="port port-out"
|
||||
magnet="active"
|
||||
:data-item="JSON.stringify(item)"
|
||||
>
|
||||
<div class="triangle-right" ></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
|
||||
<template #overlay>
|
||||
<a-menu @click="handleMenuClick">
|
||||
<a-menu-item key="delete">
|
||||
<template #icon>
|
||||
<DeleteOutlined />
|
||||
</template>
|
||||
删除
|
||||
</a-menu-item>
|
||||
</a-menu>
|
||||
</template>
|
||||
</a-dropdown>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, onMounted, onUnmounted, ref } from 'vue';
|
||||
import { elementProps, type ModelElement } from '../graph';
|
||||
|
||||
import { DeleteOutlined, SettingOutlined } from '@ant-design/icons-vue';
|
||||
import type { Graph } from '@antv/x6';
|
||||
import { substring } from '@/utils/strings';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ModelElement',
|
||||
components: {
|
||||
SettingOutlined,
|
||||
DeleteOutlined,
|
||||
},
|
||||
props: elementProps,
|
||||
setup(_props) {
|
||||
const element = ref<ModelElement | null>(
|
||||
_props.node ? (_props.node.getData() as ModelElement) : null,
|
||||
);
|
||||
const updateKey = ref(0);
|
||||
const isMenuVisible = ref(false);
|
||||
|
||||
// 获取画布实例
|
||||
const getGraph = (): Graph | null => {
|
||||
return _props.graph as Graph || null;
|
||||
};
|
||||
|
||||
// 监听节点数据变化
|
||||
const handleDataChange = () => {
|
||||
if (_props.node) {
|
||||
element.value = _props.node.getData() as ModelElement;
|
||||
} else {
|
||||
element.value = null;
|
||||
}
|
||||
updateKey.value++;
|
||||
};
|
||||
|
||||
const handleVisibleChange = (visible: boolean) => {
|
||||
isMenuVisible.value = visible;
|
||||
};
|
||||
|
||||
const handleMenuClick = ({ key }: { key: string }) => {
|
||||
if (key === 'delete') {
|
||||
handleDelete();
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (!_props.node) return;
|
||||
|
||||
const graph = getGraph();
|
||||
if (graph) {
|
||||
try {
|
||||
// 先删除关联边
|
||||
const connectedEdges = graph.getConnectedEdges(_props.node);
|
||||
connectedEdges.forEach(edge => graph.removeEdge(edge));
|
||||
// 再删除节点
|
||||
graph.removeNode(_props.node);
|
||||
console.info(`节点 ${_props.node.id} 已删除`);
|
||||
} catch (error) {
|
||||
console.error('删除节点失败:', error);
|
||||
}
|
||||
}
|
||||
isMenuVisible.value = false;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
_props.node?.on('change:data', handleDataChange);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
_props.node?.off('change:data', handleDataChange);
|
||||
});
|
||||
|
||||
return {
|
||||
element,
|
||||
substring,
|
||||
handleMenuClick,
|
||||
handleVisibleChange,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
.ks-scenario-node {
|
||||
background: linear-gradient(150deg, rgba(108, 99, 255) 1%, rgba(108, 99, 255) 100%);
|
||||
border-radius: 8px;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
background: #1e2533;
|
||||
border: 1px solid #4a7aff;
|
||||
|
||||
border: 2px solid #000000;
|
||||
|
||||
&:hover {
|
||||
border: 2px solid #4a7aff;
|
||||
box-shadow: 0 0 10px rgba(74, 122, 255, 0.3);
|
||||
}
|
||||
|
||||
.ant-card-head {
|
||||
border: 0;
|
||||
height: 28px;
|
||||
min-height: 25px;
|
||||
border-radius: 0;
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
font-weight: normal;
|
||||
padding: 0 20px;
|
||||
//background: linear-gradient(to bottom, #3a4c70, #2d3a56);
|
||||
border-top-left-radius: 8px;
|
||||
border-top-right-radius: 8px;
|
||||
background: linear-gradient(to bottom, rgba(108, 99, 255, 0.15), rgba(108, 99, 255, 0.05));
|
||||
//background: url('@/assets/icons/bg-node-head.png') center / 100% 100%;
|
||||
//background: linear-gradient(to bottom, rgb(234 234 234 / 20%), rgb(191 191 191 / 58%));
|
||||
background: url('@/assets/icons/card-head-red.png') center / 100% 100%;
|
||||
}
|
||||
|
||||
.ks-scenario-node-icon {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
display: block;
|
||||
position: absolute;
|
||||
left: 8px;
|
||||
top: 6px;
|
||||
background: url('@/assets/icons/icon-node.svg') center / 100% 100%;
|
||||
}
|
||||
|
||||
.ks-scenario-node-title {
|
||||
font-size: 12px;
|
||||
color: #fff;
|
||||
margin-top: -7px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.ant-card-body {
|
||||
color: #f5f5f5;
|
||||
height: calc(100% - 25px);
|
||||
border-radius: 0;
|
||||
font-size: 12px;
|
||||
padding: 10px 30px !important;
|
||||
//border-top: 1px solid rgba(108, 99, 255, 0.5);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
box-shadow: 0 0 10px rgba(74, 122, 255, 0.3);
|
||||
|
||||
white-space: normal; // 恢复默认的换行行为
|
||||
word-wrap: break-word; // 允许长单词换行
|
||||
word-break: break-all; // 允许在任意字符处换行
|
||||
line-height: 1.4; // 增加行高提升可读性
|
||||
box-shadow: 0 0 10px rgba(74, 122, 255, 0.3);
|
||||
}
|
||||
|
||||
|
||||
// 连接桩容器样式
|
||||
.ks-scenario-node-content {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.ks-scenario-node-row {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
min-height: 24px;
|
||||
}
|
||||
|
||||
.port {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 50%;
|
||||
cursor: crosshair;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 0 0 2px rgb(108, 99, 255, 0.8);
|
||||
z-index: 10;
|
||||
magnet: true;
|
||||
position: relative;
|
||||
|
||||
.triangle-left {
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-top: 4px solid transparent;
|
||||
border-right: 5px solid #5da1df;
|
||||
border-bottom: 4px solid transparent;
|
||||
position: absolute;
|
||||
left: -8px;
|
||||
top: 0.5px;
|
||||
magnet: passive;
|
||||
}
|
||||
|
||||
/* 右三角形 */
|
||||
.triangle-right {
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-top: 4px solid transparent;
|
||||
border-left: 5px solid #5da1df;
|
||||
border-bottom: 4px solid transparent;
|
||||
position: absolute;
|
||||
right: -8px;
|
||||
top: 0.5px;
|
||||
magnet: passive;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 左侧入桩样式
|
||||
.port-in {
|
||||
//background-color: #3c82f6;
|
||||
margin-right: 8px;
|
||||
//border: 1px solid #093866;
|
||||
magnet: passive;
|
||||
box-shadow: none;
|
||||
width: 13px;
|
||||
height: 13px;
|
||||
display: block;
|
||||
//background: url('@/assets/icons/point.svg') center / 100% 100%;
|
||||
border: 2px solid #5da1df;
|
||||
|
||||
position: absolute;
|
||||
//top: 7px;
|
||||
left: -17px;
|
||||
}
|
||||
|
||||
.port-out {
|
||||
margin-left: 8px;
|
||||
margin-right: 5px;
|
||||
magnet: active;
|
||||
box-shadow: none;
|
||||
width: 13px;
|
||||
height: 13px;
|
||||
display: block;
|
||||
border: 2px solid #5da1df;
|
||||
background:#5da1df;
|
||||
|
||||
position: absolute;
|
||||
right: -17px;
|
||||
}
|
||||
|
||||
// 节点文本样式
|
||||
.ks-scenario-node-name {
|
||||
flex: 1;
|
||||
line-height: 24px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
110
modeler/src/views/decision/communication/nodes-card.vue
Normal file
110
modeler/src/views/decision/communication/nodes-card.vue
Normal file
@@ -0,0 +1,110 @@
|
||||
<template>
|
||||
<div class="w-full">
|
||||
<a-collapse v-model:activeKey="activeKey" :accordion="true" class="platform-collapse">
|
||||
<a-collapse-panel key="1">
|
||||
<template #header>
|
||||
<span class="ks-model-builder-title-icon icon-model"></span>平台名称
|
||||
</template>
|
||||
<div class="w-full h-full">
|
||||
<a-row>
|
||||
<a-col v-for="nm in templateData" :span="12">
|
||||
<div
|
||||
:key="nm.id"
|
||||
class="ks-model-drag-item"
|
||||
@dragend="handleDragEnd"
|
||||
@dragstart="handleDragStart($event, nm)"
|
||||
>
|
||||
<img :alt="nm.description ?? nm.name ?? ''" class="icon" src="@/assets/icons/model.svg" />
|
||||
<span class="desc">{{ nm.description ?? nm.name }}</span>
|
||||
</div>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</div>
|
||||
</a-collapse-panel>
|
||||
</a-collapse>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, type PropType, ref, watch } from 'vue';
|
||||
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
||||
import { findPlatformWithComponents } from './api';
|
||||
import { type Scenario } from './types';
|
||||
import { type PlatformWithComponents } from '../types';
|
||||
|
||||
export default defineComponent({
|
||||
emits: ['drag-item-start', 'drag-item-end'],
|
||||
props: {
|
||||
scenario: {
|
||||
type: Object as PropType<Scenario>,
|
||||
required: true,
|
||||
}
|
||||
},
|
||||
setup(props, { emit }) {
|
||||
|
||||
const activeKey = ref<number>(1);
|
||||
const templateData = ref<PlatformWithComponents[]>([]);
|
||||
const isDraggingOver = ref<boolean>(false);
|
||||
const draggedNodeData = ref<PlatformWithComponents | null>(null);
|
||||
const currentScenario = ref<Scenario|null>(props.scenario)
|
||||
|
||||
const handleDragStart = (e: DragEvent, nm: PlatformWithComponents) => {
|
||||
let dragNode: PlatformWithComponents = { ...nm };
|
||||
draggedNodeData.value = dragNode as PlatformWithComponents;
|
||||
|
||||
if (e.dataTransfer) {
|
||||
e.dataTransfer.setData('text/plain', JSON.stringify(draggedNodeData.value));
|
||||
e.dataTransfer.effectAllowed = 'copyMove';
|
||||
|
||||
const dragPreview = document.createElement('div');
|
||||
dragPreview.textContent = dragNode.name || '';
|
||||
dragPreview.style.cssText = `
|
||||
position: absolute;
|
||||
top: -1000px;
|
||||
padding: 6px 12px;
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
border-radius: 6px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
`;
|
||||
document.body.appendChild(dragPreview);
|
||||
e.dataTransfer.setDragImage(dragPreview, dragPreview.offsetWidth / 2, dragPreview.offsetHeight / 2);
|
||||
emit('drag-item-start', dragNode, isDraggingOver.value, e);
|
||||
console.log('开始拖动:', dragNode);
|
||||
setTimeout(() => document.body.removeChild(dragPreview), 0);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDragEnd = (e: DragEvent) => {
|
||||
safePreventDefault(e);
|
||||
safeStopPropagation(e);
|
||||
isDraggingOver.value = false;
|
||||
console.log('拖动结束');
|
||||
emit('drag-item-end', isDraggingOver.value, e);
|
||||
};
|
||||
|
||||
|
||||
const load = (id: number)=> {
|
||||
findPlatformWithComponents(id).then(re=> {
|
||||
templateData.value = re.data ?? []
|
||||
})
|
||||
}
|
||||
|
||||
watch(()=> props.scenario,(n: Scenario|null|undefined )=> {
|
||||
if(n){
|
||||
load(n.id);
|
||||
}
|
||||
}, {deep: true, immediate: true} )
|
||||
|
||||
return {
|
||||
activeKey,
|
||||
templateData,
|
||||
handleDragStart,
|
||||
handleDragEnd,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
</script>
|
||||
143
modeler/src/views/decision/communication/platform-card.vue
Normal file
143
modeler/src/views/decision/communication/platform-card.vue
Normal file
@@ -0,0 +1,143 @@
|
||||
<template>
|
||||
<a-collapse v-model:activeKey="activeKey" :accordion="false" class="ks-trees-collapse">
|
||||
<a-collapse-panel key="1" style="position: relative">
|
||||
<template #header>
|
||||
<a-flex>
|
||||
<span class="ks-model-builder-title-icon icon-model"></span>
|
||||
<span style="color: #82c4e9;font-size: 16px;">场景</span>
|
||||
<!-- <span style="position: absolute; right: 15px;"><PlusOutlined @click="$emit('create-tree')"/></span>-->
|
||||
</a-flex>
|
||||
</template>
|
||||
<div class="w-full" style="padding: 5px;">
|
||||
<a-flex>
|
||||
<a-input-search v-model:value="scenarioQuery.name" allowClear placeholder="场景名称" size="small" @search="loadTress" />
|
||||
<!-- <a-button size="small" style="margin-left: 10px;">-->
|
||||
<!-- <PlusOutlined style="margin-top: 0px;display: block;" @click="$emit('create-tree')" />-->
|
||||
<!-- </a-button>-->
|
||||
</a-flex>
|
||||
</div>
|
||||
<a-list :data-source="scenario || []" size="small" style="min-height: 25vh">
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item>
|
||||
<a-flex>
|
||||
<a-tooltip placement="bottom">
|
||||
<template #title>
|
||||
<p>名称: {{ item.name }}</p>
|
||||
<p>说明: {{ item.description }}</p>
|
||||
</template>
|
||||
<span>{{ substring(item.name, 15) }}</span>
|
||||
</a-tooltip>
|
||||
<a-flex class="ks-tree-actions">
|
||||
<span style="margin-right: 10px" @click="()=> handleSelect(item)"><EditFilled /></span>
|
||||
<!-- <a-popconfirm-->
|
||||
<!-- title="确定删除?"-->
|
||||
<!-- @confirm="()=> handleDelete(item)"-->
|
||||
<!-- >-->
|
||||
<!-- <span class="ks-tree-action ks-tree-action-delete"><DeleteOutlined /></span>-->
|
||||
<!-- </a-popconfirm>-->
|
||||
</a-flex>
|
||||
</a-flex>
|
||||
</a-list-item>
|
||||
</template>
|
||||
</a-list>
|
||||
<a-pagination
|
||||
v-if="totalTress > Number(scenarioQuery?.pageSize ?? 0)"
|
||||
v-model:current="scenarioQuery.pageNum"
|
||||
:page-size="scenarioQuery.pageSize"
|
||||
:total="totalTress"
|
||||
simple size="small" @change="handleChange" />
|
||||
</a-collapse-panel>
|
||||
</a-collapse>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, onMounted, ref } from 'vue';
|
||||
import { CheckOutlined, DeleteOutlined, EditFilled, PlusOutlined } from '@ant-design/icons-vue';
|
||||
import type { Scenario, ScenarioRequest } from './types';
|
||||
import { deleteOneScenarioById, findScenarioByQuery } from './api';
|
||||
import { substring } from '@/utils/strings';
|
||||
|
||||
export default defineComponent({
|
||||
emits: ['select', 'create'],
|
||||
components: {
|
||||
CheckOutlined,
|
||||
PlusOutlined,
|
||||
DeleteOutlined,
|
||||
EditFilled,
|
||||
},
|
||||
setup(_props, { emit }) {
|
||||
const scenario = ref<Scenario[]>([]);
|
||||
const scenarioQuery = ref<Partial<ScenarioRequest>>({
|
||||
name: null,
|
||||
pageNum: 1,
|
||||
pageSize: 8,
|
||||
});
|
||||
const activeKey = ref<number>(1);
|
||||
const totalTress = ref<number>(0);
|
||||
|
||||
const loadTress = () => {
|
||||
findScenarioByQuery(scenarioQuery.value).then(r => {
|
||||
scenario.value = r.rows;
|
||||
totalTress.value = r.total ?? 0;
|
||||
// emit('select', r.rows[0]);
|
||||
});
|
||||
};
|
||||
|
||||
const handleChange = (page: number, pageSize: number) => {
|
||||
scenarioQuery.value.pageNum = page;
|
||||
scenarioQuery.value.pageSize = pageSize;
|
||||
loadTress();
|
||||
};
|
||||
|
||||
const handleDelete = (item: Scenario) => {
|
||||
deleteOneScenarioById(item.id).then(r => {
|
||||
if (r.code === 200) {
|
||||
loadTress();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: '名称',
|
||||
dataIndex: 'name',
|
||||
},
|
||||
];
|
||||
|
||||
const handleSelect = (record: Scenario) => {
|
||||
emit('select', record);
|
||||
};
|
||||
|
||||
const customRow = (record: Scenario) => {
|
||||
return {
|
||||
onClick: (event: any) => {
|
||||
emit('select', record, event);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const refresh = () => loadTress();
|
||||
|
||||
onMounted(() => {
|
||||
loadTress();
|
||||
});
|
||||
|
||||
return {
|
||||
refresh,
|
||||
totalTress,
|
||||
substring,
|
||||
activeKey,
|
||||
scenario,
|
||||
scenarioQuery,
|
||||
loadTress,
|
||||
columns,
|
||||
customRow,
|
||||
handleSelect,
|
||||
handleChange,
|
||||
handleDelete,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
@@ -18,10 +18,10 @@
|
||||
import { register } from '@antv/x6-vue-shape';
|
||||
import ModelElement from './node.vue';
|
||||
|
||||
export const registerNodeElement = () => {
|
||||
console.info('registerNodeElement');
|
||||
export const registerScenarioElement = () => {
|
||||
console.info('registerScenarioElement');
|
||||
register({
|
||||
shape: 'task',
|
||||
shape: 'scenario',
|
||||
component: ModelElement,
|
||||
width: 120,
|
||||
attrs: {
|
||||
135
modeler/src/views/decision/communication/relation.ts
Normal file
135
modeler/src/views/decision/communication/relation.ts
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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 { Edge, Graph, Node } from '@antv/x6';
|
||||
import type { PlatformRelation } from './types';
|
||||
import type { Platform, PlatformComponent } from '../types';
|
||||
import type { GraphTaskElement } from '../graph';
|
||||
|
||||
/**
|
||||
* 解析节点端口连接关系(去重版)
|
||||
* @param graph X6 画布实例
|
||||
* @returns 去重后的端口连接关系列表
|
||||
*/
|
||||
export function resolveConnectionRelation(graph: Graph): PlatformRelation[] {
|
||||
const edges: Edge[] = graph.getEdges();
|
||||
const items: PlatformRelation[] = [];
|
||||
const existsKeys: Set<string> = new Set(); // 改用 Set 提升查询性能
|
||||
const tempEdgeIds: Set<string> = new Set(); // 存储临时边 ID
|
||||
|
||||
// 过滤无效/临时边
|
||||
const validEdges = edges.filter(edge => {
|
||||
// 过滤临时边(X6 拖拽连线时生成的未完成边)
|
||||
const isTempEdge = edge?.attr('line/stroke') === 'transparent' || edge.id.includes('temp');
|
||||
if (isTempEdge) {
|
||||
tempEdgeIds.add(edge.id);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 过滤未正确关联节点的边
|
||||
const sourceCell = edge.getSourceCell();
|
||||
const targetCell = edge.getTargetCell();
|
||||
if (!sourceCell || !targetCell || !(sourceCell instanceof Node) || !(targetCell instanceof Node)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 过滤端口 ID 为空的边
|
||||
const sourcePortId = edge.getSourcePortId();
|
||||
const targetPortId = edge.getTargetPortId();
|
||||
if (!sourcePortId || !targetPortId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
validEdges.forEach(edge => {
|
||||
try {
|
||||
const sourceCell = edge.getSourceCell() as Node;
|
||||
const targetCell = edge.getTargetCell() as Node;
|
||||
|
||||
const sourcePortId = edge.getSourcePortId()!;
|
||||
const targetPortId = edge.getTargetPortId()!;
|
||||
|
||||
// 1. 获取端口 DOM 元素和数据
|
||||
const sourceView = graph.findViewByCell(sourceCell);
|
||||
const targetView = graph.findViewByCell(targetCell);
|
||||
if (!sourceView || !targetView) return;
|
||||
|
||||
const sourcePortEl = sourceView.container.querySelector(`[data-port="${sourcePortId}"]`);
|
||||
const targetPortEl = targetView.container.querySelector(`[data-port="${targetPortId}"]`);
|
||||
if (!sourcePortEl || !targetPortEl) return;
|
||||
|
||||
// 2. 解析端口数据
|
||||
let sourcePortData: PlatformComponent | null = null;
|
||||
let targetPortData: PlatformComponent | null = null;
|
||||
try {
|
||||
const sourceDataAttr = sourcePortEl.getAttribute('data-item');
|
||||
sourcePortData = sourceDataAttr ? JSON.parse(sourceDataAttr) : null;
|
||||
} catch (e) {
|
||||
console.warn(`解析源节点 ${sourceCell.id} 端口 ${sourcePortId} 数据失败`, e);
|
||||
return; // 数据解析失败直接跳过
|
||||
}
|
||||
try {
|
||||
const targetDataAttr = targetPortEl.getAttribute('data-item');
|
||||
targetPortData = targetDataAttr ? JSON.parse(targetDataAttr) : null;
|
||||
} catch (e) {
|
||||
console.warn(`解析目标节点 ${targetCell.id} 端口 ${targetPortId} 数据失败`, e);
|
||||
return; // 数据解析失败直接跳过
|
||||
}
|
||||
|
||||
// 过滤端口数据为空的情况
|
||||
if (!sourcePortData || !targetPortData) return;
|
||||
|
||||
// 解析节点平台数据
|
||||
const sourceData = sourceCell.getData() as GraphTaskElement;
|
||||
const targetData = targetCell.getData() as GraphTaskElement;
|
||||
|
||||
// 过滤平台数据不完整的节点
|
||||
if (!sourceData.platformId || !targetData.platformId) return;
|
||||
|
||||
const sourcePlatform: Platform = {
|
||||
id: sourceData.platformId as number,
|
||||
key: sourceData.key,
|
||||
name: sourceData.name,
|
||||
description: sourceData.description,
|
||||
scenarioId: sourceData.scenarioId as number,
|
||||
};
|
||||
|
||||
const targetPlatform: Platform = {
|
||||
id: targetData.platformId as number,
|
||||
key: targetData.key,
|
||||
name: targetData.name,
|
||||
description: targetData.description,
|
||||
scenarioId: targetData.scenarioId as number,
|
||||
};
|
||||
|
||||
// 生成唯一标识(支持单向/双向去重
|
||||
const uniqueKey = `${sourceCell.id}@${sourcePortId}->${targetCell.id}@${targetPortId}`;
|
||||
|
||||
if (!existsKeys.has(uniqueKey)) {
|
||||
existsKeys.add(uniqueKey);
|
||||
items.push({
|
||||
sourceId: sourceCell.id,
|
||||
sourcePort: sourcePortId,
|
||||
sourcePlatform: sourcePlatform,
|
||||
sourceComponent: sourcePortData,
|
||||
targetId: targetCell.id,
|
||||
targetPort: targetPortId,
|
||||
targetPlatform: targetPlatform,
|
||||
targetComponent: targetPortData,
|
||||
edgeId: edge.id,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`解析边 ${edge.id} 连接关系失败`, error);
|
||||
}
|
||||
});
|
||||
return items;
|
||||
}
|
||||
46
modeler/src/views/decision/communication/types.ts
Normal file
46
modeler/src/views/decision/communication/types.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 { NullableString, PageableResponse } from '@/types';
|
||||
import type { GraphContainer } from '../graph';
|
||||
import type { Platform, PlatformComponent } from '../types';
|
||||
|
||||
export interface PlatformRelation {
|
||||
sourceId: NullableString,
|
||||
sourcePort: NullableString,
|
||||
sourcePlatform: Platform,
|
||||
sourceComponent: PlatformComponent,
|
||||
targetId: NullableString,
|
||||
targetPort: NullableString,
|
||||
targetPlatform: Platform,
|
||||
targetComponent: PlatformComponent,
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
|
||||
export interface Scenario {
|
||||
id: number,
|
||||
name: NullableString,
|
||||
description: NullableString,
|
||||
// 用于存储场景中的通讯关系
|
||||
communicationGraph: NullableString,
|
||||
graph: GraphContainer
|
||||
relations: PlatformRelation[]
|
||||
}
|
||||
|
||||
export interface ScenarioRequest extends Scenario {
|
||||
pageNum: number,
|
||||
pageSize: number,
|
||||
}
|
||||
|
||||
export interface ScenarioPageableResponse extends PageableResponse<Scenario> {
|
||||
|
||||
}
|
||||
|
||||
129
modeler/src/views/decision/communication/utils.ts
Normal file
129
modeler/src/views/decision/communication/utils.ts
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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 { GraphRect, GraphTaskElement } from '../graph';
|
||||
import { generateKey } from '@/utils/strings';
|
||||
import type { PlatformWithComponents } from '../types';
|
||||
|
||||
export const createGraphTaskElementFromScenario = (
|
||||
platform: PlatformWithComponents,
|
||||
rect?: GraphRect,
|
||||
): GraphTaskElement => {
|
||||
let realRect = { width: 120, height: 80, x: 0, y: 0, ...rect || {} };
|
||||
console.info('rect', rect);
|
||||
return {
|
||||
id: 0,
|
||||
key: generateKey(),
|
||||
type: 'scenario',
|
||||
name: platform.name,
|
||||
platformId: platform.id,
|
||||
scenarioId: platform.scenarioId,
|
||||
components: platform.components ?? [],
|
||||
template: 0,
|
||||
templateType: null,
|
||||
category: null,
|
||||
multiable: false,
|
||||
group: null,
|
||||
description: platform.description,
|
||||
order: 0,
|
||||
position: {
|
||||
x: realRect.x ?? 0,
|
||||
y: realRect.y ?? 0,
|
||||
},
|
||||
width: realRect.width,
|
||||
height: realRect.height,
|
||||
inputs: null,
|
||||
outputs: null,
|
||||
parameters: [],
|
||||
variables: [],
|
||||
} as GraphTaskElement;
|
||||
};
|
||||
|
||||
const portsGroups = {
|
||||
in: {
|
||||
position: 'left', // 入桩在左侧
|
||||
attrs: {
|
||||
circle: {
|
||||
r: 6,
|
||||
magnet: 'passive', // 被动吸附(仅作为连线目标)
|
||||
stroke: '#5da1df',
|
||||
strokeWidth: 2,
|
||||
fill: '#fff',
|
||||
},
|
||||
},
|
||||
},
|
||||
out: {
|
||||
position: 'right', // 出桩在右侧
|
||||
attrs: {
|
||||
circle: {
|
||||
r: 6,
|
||||
magnet: 'active', // 主动吸附(作为连线源)
|
||||
stroke: '#5da1df',
|
||||
strokeWidth: 2,
|
||||
fill: '#5da1df',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const createGraphScenarioElement = (element: GraphTaskElement): any => {
|
||||
let realHeight = 120;
|
||||
let width: number = 250;
|
||||
if (!realHeight) {
|
||||
realHeight = 120;
|
||||
}
|
||||
if(element?.components){
|
||||
if(element?.components?.length > 2){
|
||||
realHeight = 90 + element?.components?.length * 25
|
||||
} else if(element?.components?.length <=1){
|
||||
realHeight = 120
|
||||
}
|
||||
}
|
||||
|
||||
// const portsItems = (element.components || []).map((comp, index) => {
|
||||
// const compId = comp.id || index;
|
||||
// return [
|
||||
// // 入桩(对应 DOM: data-port="in-${compId}")
|
||||
// {
|
||||
// id: `in-${compId}`, // portId 必须和 DOM 的 data-port 一致
|
||||
// group: 'in',
|
||||
// data: comp, // 直接存储 port 数据,避免后续解析 DOM
|
||||
// },
|
||||
// // 出桩(对应 DOM: data-port="out-${compId}")
|
||||
// {
|
||||
// id: `out-${compId}`,
|
||||
// group: 'out',
|
||||
// data: comp,
|
||||
// },
|
||||
// ];
|
||||
// }).flat(); // 扁平化数组
|
||||
|
||||
return {
|
||||
shape: 'scenario',
|
||||
id: element.key,
|
||||
position: {
|
||||
x: element.position?.x || 0,
|
||||
y: element.position?.y || 0,
|
||||
},
|
||||
size: {
|
||||
width: width,
|
||||
height: realHeight,
|
||||
},
|
||||
attrs: {
|
||||
label: {
|
||||
text: element.name,
|
||||
},
|
||||
},
|
||||
data: element,
|
||||
// ports: {
|
||||
// groups: portsGroups,
|
||||
// items: portsItems,
|
||||
// },
|
||||
};
|
||||
};
|
||||
45
modeler/src/views/decision/designer/api.ts
Normal file
45
modeler/src/views/decision/designer/api.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 { NodeTemplatesResponse } from './template';
|
||||
import type { BehaviorTree, BehaviorTreeDetailsResponse, BehaviorTreePageResponse, BehaviorTreeRequest } from './tree';
|
||||
import type { BasicResponse } from '@/types';
|
||||
|
||||
const req = HttpRequestClient.create<BasicResponse>({
|
||||
baseURL: '/api',
|
||||
});
|
||||
|
||||
export const findNodeTemplates = (): Promise<NodeTemplatesResponse> => {
|
||||
return req.get('/system/nodetemplate/all');
|
||||
};
|
||||
|
||||
export const findTreesByQuery = (query: Partial<BehaviorTreeRequest> = {}): Promise<BehaviorTreePageResponse> => {
|
||||
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}`);
|
||||
};
|
||||
|
||||
export const deleteOneTreeById = (id: number): Promise<BehaviorTreeDetailsResponse> => {
|
||||
return req.delete(`/system/behaviortree/${id}`);
|
||||
};
|
||||
|
||||
export const updateTree = (rt: Partial<BehaviorTree>): Promise<BasicResponse> => {
|
||||
return req.postJson(`/system/behaviortree`, rt);
|
||||
};
|
||||
|
||||
export const createTree = (rt: Partial<BehaviorTree>): Promise<BasicResponse> => {
|
||||
return req.putJson(`/system/behaviortree`, rt);
|
||||
};
|
||||
@@ -19,27 +19,12 @@
|
||||
<div class="ks-model-builder-content">
|
||||
<div class="ks-model-builder-actions">
|
||||
<a-space>
|
||||
<!-- <a-tooltip v-if="graph && currentBehaviorTree" placement="top">-->
|
||||
<!-- <template #title>-->
|
||||
<!-- 保存-->
|
||||
<!-- </template>-->
|
||||
<!-- <a-popconfirm-->
|
||||
<!-- title="确定保存?"-->
|
||||
<!-- @confirm="handleSave"-->
|
||||
<!-- >-->
|
||||
<!-- <a-button class="ks-model-builder-save" size="small">-->
|
||||
<!-- <CheckOutlined />-->
|
||||
<!-- <span>保存</span>-->
|
||||
<!-- </a-button>-->
|
||||
<!-- </a-popconfirm>-->
|
||||
<!-- </a-tooltip>-->
|
||||
<a-button v-if="graph && currentBehaviorTree" class="ks-model-builder-save" size="small" @click="handleSave">
|
||||
<CheckOutlined />
|
||||
<span>保存</span>
|
||||
</a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
<!-- 画布容器,添加拖放事件 -->
|
||||
<div
|
||||
ref="canvas"
|
||||
class="ks-model-builder-canvas"
|
||||
@@ -52,6 +37,7 @@
|
||||
</div>
|
||||
<Properties
|
||||
v-if="graph"
|
||||
:platforms="platforms"
|
||||
:element="selectedNodeTaskElement"
|
||||
:graph="graph as any"
|
||||
:node="selectedModelNode as any"
|
||||
@@ -66,22 +52,24 @@
|
||||
|
||||
<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 { Wrapper } from '@/components/wrapper';
|
||||
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
||||
import Header from './header.vue';
|
||||
import Header from '../header.vue';
|
||||
import Properties from './properties.vue';
|
||||
import type { BehaviorTree, NodeDragTemplate, NodeTemplate } from './types';
|
||||
import type { GraphTaskElement, NodeGraph } from './builder/element';
|
||||
import { useGraphCanvas } from './builder/hooks';
|
||||
import { registerNodeElement } from './builder/register';
|
||||
import { createLineOptions } from './builder/line';
|
||||
import { createTree, findOneTreeById, updateTree } from './api';
|
||||
import { createGraphTaskElement, hasElements, hasRootElementNode, resolveNodeGraph } from './builder/utils';
|
||||
import { createGraphTaskElementFromTemplate } from './utils/node';
|
||||
import type { NodeDragTemplate } from './template';
|
||||
import type { BehaviorTree } from './tree';
|
||||
import { createGraphTaskElementFromTemplate } from './utils';
|
||||
|
||||
import { createGraphTaskElement, createLineOptions, type GraphContainer, type GraphTaskElement, hasElements, hasRootElementNode, resolveGraph, useGraphCanvas } from '../graph';
|
||||
import { registerNodeElement } from './register';
|
||||
import { findAllBasicPlatforms } from '../api';
|
||||
import type { Platform } from '../types';
|
||||
import { createTree, findOneTreeById, updateTree, findOneTreeByPlatformId } from './api';
|
||||
import TressCard from './trees-card.vue';
|
||||
import NodesCard from './nodes-card.vue';
|
||||
|
||||
@@ -103,6 +91,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);
|
||||
@@ -110,11 +99,12 @@ export default defineComponent({
|
||||
const isDraggingOver = ref(false);
|
||||
const currentTreeEditing = ref<boolean>(false);
|
||||
const currentBehaviorTree = ref<BehaviorTree | null>(null);
|
||||
const currentNodeGraph = ref<NodeGraph | null>(null);
|
||||
const currentGraph = ref<GraphContainer | null>(null);
|
||||
const selectedModelNode = ref<Node<NodeProperties> | null>(null);
|
||||
const selectedNodeTaskElement = ref<GraphTaskElement | null>(null);
|
||||
const changed = ref<boolean>(false);
|
||||
const treesCardRef = ref<InstanceType<typeof TressCard> | null>(null);
|
||||
const platforms = ref<Platform[]>([]);
|
||||
|
||||
const {
|
||||
handleGraphEvent,
|
||||
@@ -124,8 +114,23 @@ 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 handleDragStart = (nm: NodeDragTemplate) => {
|
||||
draggedNodeData.value = nm;
|
||||
@@ -216,12 +221,14 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const handleSelectTree = (tree: BehaviorTree) => {
|
||||
destroyGraph();
|
||||
|
||||
console.info('handleSelectTree', tree);
|
||||
findOneTreeById(tree.id).then(r => {
|
||||
if (r.data) {
|
||||
let nodeGraph: NodeGraph | null = null;
|
||||
let nodeGraph: GraphContainer | null = null;
|
||||
try {
|
||||
nodeGraph = JSON.parse(r.data?.xmlContent as unknown as string) as unknown as NodeGraph;
|
||||
nodeGraph = JSON.parse(r.data?.xmlContent as unknown as string) as unknown as GraphContainer;
|
||||
} catch (e: any) {
|
||||
console.error('parse error,cause:', e);
|
||||
}
|
||||
@@ -236,7 +243,9 @@ export default defineComponent({
|
||||
graph: nodeGraph,
|
||||
};
|
||||
currentTreeEditing.value = true;
|
||||
createElements();
|
||||
nextTick(() => {
|
||||
initGraph();
|
||||
});
|
||||
} else {
|
||||
message.error(r.msg ?? '行为树不存在.');
|
||||
}
|
||||
@@ -244,12 +253,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) {
|
||||
@@ -277,6 +282,8 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const handleCreateTree = () => {
|
||||
destroyGraph();
|
||||
|
||||
currentBehaviorTree.value = {
|
||||
id: 0,
|
||||
name: '行为树',
|
||||
@@ -290,14 +297,16 @@ export default defineComponent({
|
||||
},
|
||||
updatedAt: null,
|
||||
};
|
||||
currentNodeGraph.value = {
|
||||
currentGraph.value = {
|
||||
edges: [],
|
||||
nodes: [],
|
||||
};
|
||||
selectedModelNode.value = null;
|
||||
selectedNodeTaskElement.value = null;
|
||||
|
||||
createElements();
|
||||
nextTick(() => {
|
||||
initGraph();
|
||||
});
|
||||
};
|
||||
|
||||
// 初始化X6画布
|
||||
@@ -355,6 +364,18 @@ export default defineComponent({
|
||||
initGraph();
|
||||
window.addEventListener('resize', handleResize);
|
||||
console.log('节点挂载完成');
|
||||
|
||||
const platformId = currentRoute.query.platform;
|
||||
if (platformId) {
|
||||
const id = Number(platformId);
|
||||
if (!isNaN(id)) {
|
||||
findOneTreeByPlatformId(id).then(r => {
|
||||
if (r.data) {
|
||||
handleSelectTree(r.data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -370,7 +391,7 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
const graphData: NodeGraph = resolveNodeGraph(graph.value as Graph);
|
||||
const graphData: GraphContainer = resolveGraph(graph.value as Graph);
|
||||
console.info('handleSave', graphData);
|
||||
if (!currentBehaviorTree.value) {
|
||||
message.error('当前决策树不存在');
|
||||
@@ -408,28 +429,19 @@ export default defineComponent({
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
init();
|
||||
loadPlatforms();
|
||||
});
|
||||
|
||||
// 清理
|
||||
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 {
|
||||
platforms,
|
||||
treesCardRef,
|
||||
handleCreateTree,
|
||||
currentTreeEditing,
|
||||
currentBehaviorTree,
|
||||
currentNodeGraph,
|
||||
currentGraph,
|
||||
selectedNodeTaskElement,
|
||||
selectedModelNode,
|
||||
graph,
|
||||
@@ -48,8 +48,8 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, onMounted, onUnmounted, ref } from 'vue';
|
||||
import { elementProps } from './props';
|
||||
import type { ModelElement } from './element';
|
||||
import { elementProps, type ModelElement } from '../graph';
|
||||
|
||||
import { DeleteOutlined, SettingOutlined } from '@ant-design/icons-vue';
|
||||
import type { Graph } from '@antv/x6';
|
||||
import { substring } from '@/utils/strings';
|
||||
@@ -71,7 +71,7 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, onMounted, ref } from 'vue';
|
||||
import type { NodeDragTemplate, NodeTemplate } from './types';
|
||||
import type { NodeDragTemplate, NodeTemplate } from './template';
|
||||
import { findNodeTemplates } from './api';
|
||||
import { safePreventDefault, safeStopPropagation } from '@/utils/event';
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user