23 Commits

Author SHA1 Message Date
MHW
5c83b561cc 逻辑修改 2026-04-13 17:58:01 +08:00
bb45ff557b 新增根据行为树ID获取下属平台的接口 2026-04-13 17:33:28 +08:00
254401d8f1 支持根据行为树加载下属平台并优化属性面板显示 2026-04-13 17:26:50 +08:00
d8c238a9bb Merge remote-tracking branch 'origin/master' 2026-04-13 17:15:51 +08:00
MHW
aefc2c688e 逻辑修改 2026-04-13 17:13:34 +08:00
MHW
5f1ba38c6b 逻辑修改 2026-04-13 17:10:52 +08:00
MHW
e57f0f19d5 根据场景id显示所有行为树 2026-04-13 17:02:08 +08:00
79364b951d 修复类型导入缺失及Props类型断言格式 2026-04-13 16:41:11 +08:00
1270bd7d02 Merge remote-tracking branch 'origin/master' 2026-04-13 16:40:51 +08:00
MHW
b424774f3b 实体重复修改bug修复 2026-04-13 16:34:05 +08:00
MHW
766425bae5 实体重复修改 2026-04-13 16:31:56 +08:00
MHW
0e6b6d9f45 查询行为树所属平台的下属 2026-04-13 16:16:24 +08:00
50c1cc5bf2 修复行为树复制参数传递错误 2026-04-13 15:33:46 +08:00
7c71a38f68 添加前端行为树复制接口 2026-04-13 15:24:59 +08:00
3946bc561a 添加行为树复制功能 2026-04-13 14:25:50 +08:00
5179ab785c Merge commit '5276a6b16fdf0e345bd0a952abc998c1bf4e3725' 2026-04-13 14:22:14 +08:00
MHW
5276a6b16f 复制行为树 2026-04-13 14:19:18 +08:00
c0da7bd0d9 画布动态尺寸 2026-04-13 12:22:30 +08:00
MHW
dafd7115a8 Merge branch 'refs/heads/develop' 2026-04-13 10:39:47 +08:00
MHW
1061020791 复制行为树 2026-04-13 10:39:37 +08:00
MHW
045117011b docker-compose 2026-04-11 13:46:02 +08:00
MHW
8a0dfb1ab8 sql改 2026-04-09 16:10:15 +08:00
MHW
08030c77c2 sql改 2026-04-09 16:06:40 +08:00
31 changed files with 831 additions and 20 deletions

View File

@@ -1,7 +1,7 @@
# 复制为 .env 后 docker compose 会自动加载
# copy .env.example .env
MYSQL_ROOT_PASSWORD=1234
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=autosolution_db
MYSQL_PORT=3307

114
DEPLOY_OFFLINE.md Normal file
View File

@@ -0,0 +1,114 @@
# Docker 离线部署说明(方式 A)
执行 `docker compose up -d` 即可启动。
## 1. 交付清单
请将以下内容放在同一目录(示例:`app/`):
- `docker-compose.yml`
- `.env`(或将 `.env.example` 复制为 `.env` 后修改)
- `bundle-images.tar`(包含 `auto-solution-admin`、`mysql:8.0`、`redis:7-alpine`)
- `docker/mysql/init/01-ruoyi-table.sql`
- `docker/mysql/init/02-ruoyi-extra.sql`
- `docker/mysql/init/03-data.sql`
目录示例:
```text
app/
├─ docker-compose.yml
├─ .env
├─ bundle-images.tar
└─ docker/
└─ mysql/
└─ init/
├─ 00-create-db.sql
├─ 03-data.sql
```
## 2. 首次部署
在 `app` 目录执行:
```bash
docker load -i bundle-images.tar
docker compose down -v
docker compose up -d
```
说明:
- `down -v` 会删除旧数据卷,确保 MySQL 首次初始化时执行 `docker/mysql/init` 下的 SQL。
- SQL 执行顺序按文件名字典序,务必保持 `01 -> 02 -> 03`。
## 3. 启动验证
```bash
docker ps
docker inspect autosolution-mysql --format '{{.State.Health.Status}}'
docker logs --tail 100 autosolution-mysql
docker logs --tail 100 autosolution-app
```
期望结果:
- `autosolution-mysql` 状态为 `healthy`
- `autosolution-app` 状态为 `Up`
## 4. 访问地址
- 后端默认端口:`1777`
- 访问地址:`http://<服务器IP>:1777`
## 5. 常见问题
### 5.1 `Table 'autosolution_db.sys_config' doesn't exist`
原因:初始化 SQL 未执行或执行失败。
处理:
1. 确认 `docker/mysql/init` 下 SQL 文件存在且顺序正确
2. 执行:
```bash
docker compose down -v
docker compose up -d
```
3. 查看 MySQL 日志定位 SQL 报错:
```bash
docker logs --tail 300 autosolution-mysql
```
### 5.2 `dependency failed to start: container autosolution-mysql is unhealthy`
原因:MySQL 未通过健康检查(通常是 SQL 未执行完成或报错)。
处理:
```bash
docker logs --tail 300 autosolution-mysql
```
根据日志修复 SQL 后重新 `down -v` 再启动。
## 6. 版本升级
替换新的 `bundle-images.tar`(及必要 SQL)后执行:
```bash
docker load -i bundle-images.tar
docker compose down
docker compose up -d
```
如果本次升级包含库初始化变更并要求重建,请改用:
```bash
docker compose down -v
docker compose up -d
```

View File

@@ -97,6 +97,19 @@ public class BehaviortreeController extends BaseController
return toAjax(behaviortreeProcessor.create(behaviortree));
}
/**
* 复制行为树
*/
@ApiOperation("复制行为树")
@PreAuthorize("@ss.hasPermi('system:behaviortree:add')")
@Log(title = "行为树主", businessType = BusinessType.INSERT)
@PostMapping("/copy")
public AjaxResult copy(@RequestBody Behaviortree behaviortree)
{
//return toAjax(behaviortreeService.copy(behaviortree));
return toAjax(behaviortreeProcessor.copy(behaviortree));
}
/**
* 修改行为树主
*/
@@ -121,4 +134,18 @@ public class BehaviortreeController extends BaseController
return toAjax(behaviortreeService.deleteBehaviortreeByIds(ids));
}
/**
* 根据行为树id获取该行为树的下属
* @param treeId
* @return
*/
@ApiOperation("根据行为树id获取该行为树的下属")
@PreAuthorize("@ss.hasPermi('system:behaviortree:query')")
@GetMapping("/underling/{treeId}")
public AjaxResult getUnderling(@PathVariable Integer treeId)
{
return success(behaviortreeService.getUnderling(treeId));
}
}

View File

@@ -55,4 +55,13 @@ public class SceneController extends BaseController {
{
return success(sceneService.findOneById(id));
}
/**
* 根据场景id获取场景下所有行为树
*/
@GetMapping("/getAllTree/{id}")
@ApiOperation("根据场景id获取场景下所有行为树")
public AjaxResult getAllTree(@PathVariable Integer id){
return success(sceneService.getAllTree(id));
}
}

View File

@@ -8,8 +8,10 @@ package com.solution.web.core;
* that was distributed with this source code.
*/
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.solution.common.constant.ExceptionConstants;
import com.solution.system.domain.*;
import com.solution.system.service.IBehaviortreeService;
import com.solution.system.service.INodeconnectionService;
@@ -20,6 +22,7 @@ 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.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
@@ -56,6 +59,7 @@ public class BehaviortreeProcessor {
return result;
}
@Transactional(rollbackFor = Exception.class)
public int update(Behaviortree behaviortree) {
int result = behaviortreeService.updateBehaviortree(behaviortree);
@@ -74,7 +78,7 @@ public class BehaviortreeProcessor {
}
private void processGraph(Behaviortree behaviortree) {
//代码丢失 原:libertyspy 改:MHW
Graph graph = null;
try {
graph = objectMapper.readValue(behaviortree.getXmlContent(), Graph.class);
@@ -223,4 +227,23 @@ public class BehaviortreeProcessor {
}
/**
* 复制行为树
* @param behaviortree
* @return
*/
public int copy(Behaviortree behaviortree) {
if(ObjectUtil.isEmpty(behaviortree)){
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
}
String name = behaviortree.getName();
String newName = name + "_" + behaviortree.getId();
String englishName = behaviortree.getEnglishName();
String newEnglishName = englishName + "_" + behaviortree.getId();
behaviortree.setEnglishName(newEnglishName);
behaviortree.setName(newName);
return this.create(behaviortree);
}
}

View File

@@ -49,6 +49,17 @@ public class Behaviortree extends BaseEntity
@Excel(name = "平台ID")
private Integer platformId;
@Excel(name = "场景ID")
private Integer scenarioId;
public Integer getScenarioId() {
return scenarioId;
}
public void setScenarioId(Integer scenarioId) {
this.scenarioId = scenarioId;
}
public Integer getPlatformId() {
return platformId;
}

View File

@@ -0,0 +1,40 @@
package com.solution.system.domain;
import lombok.Data;
/**
* 平台通信关系表
*/
@Data
public class PlatformCommunication {
/**
* 主键ID
*/
private Integer id;
/**
* 指挥平台名称/ID
*/
private String commandPlatform;
/**
* 下属平台名称/ID
*/
private String subordinatePlatform;
/**
* 指挥通信方式/内容
*/
private String commandComm;
/**
* 下属通信方式/内容
*/
private String subordinateComm;
/**
* 想定ID
*/
private Integer scenaryId;
}

View File

@@ -0,0 +1,31 @@
package com.solution.system.domain;
import lombok.Data;
/**
* 平台表
*/
@Data
public class PlatformTree {
/**
* 主键
*/
private Integer id;
/**
* 平台名称
*/
private String name;
/**
* 描述
*/
private String description;
/**
* 平台出现在想定上的想定id
*/
private Integer scenarioId;
}

View File

@@ -0,0 +1,16 @@
package com.solution.system.mapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface PlatformCommunicationMapper {
/**
* 根据平台name获取平台下属英文名
* @param name
* @return
*/
List<String> getUnderlingBytreeId(String name);
}

View File

@@ -0,0 +1,24 @@
package com.solution.system.mapper;
import com.solution.system.domain.PlatformTree;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface PlatformMapper {
/**
* 根据行为树id获取行为树所属平台
* @param id
* @return
*/
PlatformTree getPlatformByTreeId(Integer id);
/**
* 根据下属平台英文名获取中文名返回
* @param underlingEnglishName
* @return
*/
List<String> selectPlatformChineseName(List<String> underlingEnglishName);
}

View File

@@ -62,4 +62,11 @@ public interface IBehaviortreeService
* @return 结果
*/
public int deleteBehaviortreeById(Long id);
/**
* 根据行为树id获取该行为树的下属
* @param treeId
* @return
*/
List<String> getUnderling(Integer treeId);
}

View File

@@ -2,8 +2,12 @@ package com.solution.system.service.impl;
import java.util.List;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.solution.common.constant.ExceptionConstants;
import com.solution.system.domain.PlatformTree;
import com.solution.system.mapper.PlatformCommunicationMapper;
import com.solution.system.mapper.PlatformMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.solution.system.mapper.BehaviortreeMapper;
@@ -22,6 +26,12 @@ public class BehaviortreeServiceImpl implements IBehaviortreeService
@Autowired
private BehaviortreeMapper behaviortreeMapper;
@Autowired
private PlatformCommunicationMapper platformCommunicationMapper;
@Autowired
private PlatformMapper platformMapper;
@Override
public Behaviortree findOneByPlatformId(Integer platformId)
{
@@ -99,4 +109,30 @@ public class BehaviortreeServiceImpl implements IBehaviortreeService
{
return behaviortreeMapper.deleteBehaviortreeById(id);
}
/**
* 根据行为树id获取该行为树的下属
* @param treeId
* @return
*/
@Override
public List<String> getUnderling(Integer treeId) {
if(null == treeId){
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
}
Behaviortree behaviortree = behaviortreeMapper.selectBehaviortreeById(Long.valueOf(treeId));
if(ObjectUtil.isEmpty(behaviortree) || null == behaviortree.getId()){
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
}
//根据行为树id获取行为树所属平台
PlatformTree platform = platformMapper.getPlatformByTreeId(behaviortree.getPlatformId());
//根据平台name获取平台下属英文名
List<String> underlingEnglishName = platformCommunicationMapper.getUnderlingBytreeId(platform.getName());
//根据下属平台英文名获取中文名返回
List<String> underlingChineseName = platformMapper.selectPlatformChineseName(underlingEnglishName);
if(CollUtil.isEmpty(underlingChineseName)){
throw new RuntimeException("该平台暂无下属");
}
return underlingChineseName;
}
}

View File

@@ -5,13 +5,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<mapper namespace="com.solution.system.mapper.BehaviortreeMapper">
<resultMap type="Behaviortree" id="BehaviortreeResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="description" column="description" />
<result property="createdAt" column="created_at" />
<result property="updatedAt" column="updated_at" />
<result property="englishName" column="english_name" />
<result property="xmlContent" column="xml_content" />
<result property="id" column="id" />
<result property="name" column="name" />
<result property="description" column="description" />
<result property="createdAt" column="created_at" />
<result property="updatedAt" column="updated_at" />
<result property="englishName" column="english_name"/>
<result property="xmlContent" column="xml_content" />
<result property="platformId" column="platform_id" />
<result property="scenarioId" column="scenario_id" />
</resultMap>
<select id="findOneByPlatformId" resultMap="BehaviortreeResult">
@@ -37,7 +39,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectBehaviortreeById" parameterType="Long" resultMap="BehaviortreeResult">
<include refid="selectBehaviortreeVo"/>
select id, name, description, created_at, updated_at, english_name,graph, xml_content ,platform_id, scenario_id from behaviortree
where id = #{id}
</select>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.solution.system.mapper.PlatformCommunicationMapper">
<select id="getUnderlingBytreeId" resultType="java.lang.String" parameterType="java.lang.Integer">
SELECT subordinate_platform
FROM platform_communication
WHERE subordinate_platform = #{name}
</select>
</mapper>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.solution.system.mapper.PlatformMapper">
<select id="getPlatformByTreeId" resultType="com.solution.system.domain.PlatformTree"
parameterType="java.lang.Integer">
SELECT id , name , description, scenario_id
FROM platform
WHERE id = #{id}
</select>
<select id="selectPlatformChineseName" resultType="java.lang.String"
parameterType="java.util.List">
SELECT description
FROM platform
WHERE name IN
<foreach item="item" collection="underlingEnglishName" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>

View File

@@ -20,16 +20,21 @@ import com.solution.rule.domain.ultimately.vo.FireRuleRedPlatformSlotVO;
import com.solution.rule.domain.ultimately.vo.FireRuleRedWeaponSlotVO;
import com.solution.rule.domain.ultimately.vo.FireRuleOutputVO;
import com.solution.rule.domain.ultimately.vo.FireRuleRouteTrackPointVO;
import com.solution.rule.domain.ultimately.vo.FireRuleSceneGroupNodeVO;
import com.solution.rule.domain.ultimately.vo.FireRuleSceneTaskNodeVO;
import com.solution.rule.domain.ultimately.vo.FireRuleSceneTaskPayloadVO;
import com.solution.rule.domain.ultimately.vo.FireRuleTrackParamVO;
import com.solution.rule.domain.ultimately.vo.FireRuleTrackRouteVO;
import com.solution.rule.domain.ultimately.vo.FireRuleWingmanDataVO;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -231,6 +236,241 @@ public final class FireRuleRedWeaponOutputFillHelper {
}
}
/**
* 编组规则:按红方装备列表分组,写入 {@link FireRuleTrackParamVO#getGroups}(JSON 键 Groups),
* groupType=addGroup,drawName=领队装备名+后缀;僚机 wingmanData 中 name 为红方 equipmentId。
* 多蓝方任务循环时与航迹一致:在已有 Groups 上追加,且 group id 与已有项冲突时自动加后缀。
*/
@SuppressWarnings("rawtypes")
public static void fillTrackParamGroups(FireRuleOutputVO out, FireRuleTaskInputDTO blueTask, Map params) {
if (out == null || blueTask == null) {
return;
}
boolean enabled = Boolean.parseBoolean(String.valueOf(params.getOrDefault("groupRuleEnabled", true)));
if (!enabled) {
return;
}
List<FireRuleRedWeaponEquipmentVO> reds = out.getRedWeapons();
if (reds == null || reds.isEmpty()) {
return;
}
ensureTrackParam(out);
String dirMode = str(params, "trackPointDirectionMode", "head2next");
double fallbackBrg = readDouble(params, "trackFallbackBearingDeg", readDouble(params, "fallbackBearingDeg", 0d));
double mainBearing = computeTrackBearingDeg(blueTask, dirMode, fallbackBrg);
String mode = str(params, "groupFormationMode", "onePerRed");
int clusterSize = readInt(params, "groupClusterSize", 3);
if (clusterSize < 1) {
clusterSize = 1;
}
int minWing = readInt(params, "groupMinMembersForWingman", 2);
List<List<FireRuleRedWeaponEquipmentVO>> buckets = splitRedsIntoGroups(reds, mode, clusterSize);
List<FireRuleSceneGroupNodeVO> batch = new ArrayList<>();
String blueSeg = sanitizeRouteIdSegment(nz(blueTask.getId()));
int gidx = 0;
for (List<FireRuleRedWeaponEquipmentVO> bucket : buckets) {
if (bucket == null || bucket.isEmpty()) {
continue;
}
FireRuleRedWeaponEquipmentVO leader = pickGroupLeader(bucket, params);
if (leader == null) {
continue;
}
FireRuleSceneGroupNodeVO node = new FireRuleSceneGroupNodeVO();
String baseId = "group_" + blueSeg + "_" + gidx;
node.setId(ensureUniqueGroupId(out.getTrackParam(), baseId));
String suffix = str(params, "groupDrawNameSuffix", "编组");
boolean withIndex = Boolean.parseBoolean(String.valueOf(params.getOrDefault("groupDrawNameWithIndex", false)));
String drawName = nz(leader.getName()) + suffix;
if (withIndex) {
drawName += (gidx + 1);
}
node.setDrawName(drawName);
node.setGroupType("addGroup");
node.setName("addGroup");
node.setLeader(nz(leader.getEquipmentId()));
node.setSort(System.currentTimeMillis() + gidx);
node.setWingmanData(buildWingmanData(bucket, leader, mainBearing, params, minWing));
batch.add(node);
gidx++;
}
mergeGroupsIntoTrackParam(out.getTrackParam(), batch);
}
private static List<List<FireRuleRedWeaponEquipmentVO>> splitRedsIntoGroups(
List<FireRuleRedWeaponEquipmentVO> reds, String mode, int clusterSize) {
List<FireRuleRedWeaponEquipmentVO> clean = new ArrayList<>();
for (FireRuleRedWeaponEquipmentVO r : reds) {
if (r != null) {
clean.add(r);
}
}
List<List<FireRuleRedWeaponEquipmentVO>> out = new ArrayList<>();
if (clean.isEmpty()) {
return out;
}
if ("singleGroup".equalsIgnoreCase(mode)) {
out.add(clean);
return out;
}
if ("clusterByCount".equalsIgnoreCase(mode)) {
for (int i = 0; i < clean.size(); i += clusterSize) {
int end = Math.min(i + clusterSize, clean.size());
out.add(new ArrayList<>(clean.subList(i, end)));
}
return out;
}
for (FireRuleRedWeaponEquipmentVO r : clean) {
out.add(Collections.singletonList(r));
}
return out;
}
private static FireRuleRedWeaponEquipmentVO pickGroupLeader(List<FireRuleRedWeaponEquipmentVO> bucket, Map params) {
if (bucket == null || bucket.isEmpty()) {
return null;
}
String mode = str(params, "groupLeaderPickMode", "byHitRateThenId");
FireRuleRedWeaponEquipmentVO best = bucket.get(0);
for (int i = 1; i < bucket.size(); i++) {
FireRuleRedWeaponEquipmentVO cur = bucket.get(i);
if ("byId".equalsIgnoreCase(mode)) {
if (compareEquipmentId(cur, best) < 0) {
best = cur;
}
} else {
if (isBetterLeaderByHitRateThenId(cur, best)) {
best = cur;
}
}
}
return best;
}
private static boolean isBetterLeaderByHitRateThenId(FireRuleRedWeaponEquipmentVO cand, FireRuleRedWeaponEquipmentVO inc) {
double rc = leaderRad(cand);
double ri = leaderRad(inc);
int c = Double.compare(rc, ri);
if (c > 0) {
return true;
}
if (c < 0) {
return false;
}
return compareEquipmentId(cand, inc) < 0;
}
private static double leaderRad(FireRuleRedWeaponEquipmentVO w) {
if (w == null || w.getSuccessTargetRad() == null) {
return -1d;
}
return w.getSuccessTargetRad().doubleValue();
}
private static int compareEquipmentId(FireRuleRedWeaponEquipmentVO a, FireRuleRedWeaponEquipmentVO b) {
String sa = a != null ? nz(a.getEquipmentId()) : "";
String sb = b != null ? nz(b.getEquipmentId()) : "";
return sa.compareTo(sb);
}
private static List<FireRuleWingmanDataVO> buildWingmanData(
List<FireRuleRedWeaponEquipmentVO> bucket,
FireRuleRedWeaponEquipmentVO leader,
double mainBearing,
Map params,
int minMembersForWingman) {
if (bucket == null || leader == null || bucket.size() < minMembersForWingman) {
return Collections.emptyList();
}
double distBase = readDouble(params, "wingmanDistanceBaseMeters", 100);
double distStep = readDouble(params, "wingmanDistanceStepMeters", 50);
double angBase = readDouble(params, "wingmanAngleBaseDeg", 50);
double angStep = readDouble(params, "wingmanAngleStepDeg", 15);
double altBase = readDouble(params, "wingmanAltBaseMeters", 40);
double altScale = readDouble(params, "wingmanAltScale", 1.0);
List<FireRuleWingmanDataVO> list = new ArrayList<>();
int wmIdx = 0;
for (FireRuleRedWeaponEquipmentVO r : bucket) {
if (r == null || r == leader) {
continue;
}
FireRuleWingmanDataVO w = new FireRuleWingmanDataVO();
w.setKey(wmIdx);
w.setName(nz(r.getEquipmentId()));
w.setDistance((int) Math.round(distBase + wmIdx * distStep));
double deg = normDeg(mainBearing + angBase + wmIdx * angStep);
w.setAngle(String.format(Locale.US, "%.1f", deg));
Double lh = extractFirstPlatformHeight(leader);
Double wh = extractFirstPlatformHeight(r);
double delta = 0d;
if (lh != null && wh != null) {
delta = wh - lh;
}
w.setAlt((int) Math.round(altBase + altScale * delta));
list.add(w);
wmIdx++;
}
return list;
}
private static Double extractFirstPlatformHeight(FireRuleRedWeaponEquipmentVO red) {
if (red == null || red.getSubComponents() == null || red.getSubComponents().getPlatform() == null) {
return null;
}
for (FireRuleRedPlatformSlotVO pl : red.getSubComponents().getPlatform()) {
if (pl == null || pl.getPositions() == null || pl.getPositions().size() < 3) {
continue;
}
return pl.getPositions().get(2);
}
return null;
}
private static double normDeg(double deg) {
double a = deg % 360d;
if (a < 0) {
a += 360d;
}
return a;
}
private static String ensureUniqueGroupId(FireRuleTrackParamVO tp, String baseId) {
Set<String> seen = new HashSet<>();
if (tp.getGroups() != null) {
for (FireRuleSceneGroupNodeVO g : tp.getGroups()) {
if (g != null && !isBlank(g.getId())) {
seen.add(g.getId());
}
}
}
if (!seen.contains(baseId)) {
return baseId;
}
int k = 1;
while (seen.contains(baseId + "_" + k)) {
k++;
}
return baseId + "_" + k;
}
private static void mergeGroupsIntoTrackParam(FireRuleTrackParamVO tp, List<FireRuleSceneGroupNodeVO> batch) {
if (tp == null || batch == null || batch.isEmpty()) {
return;
}
List<FireRuleSceneGroupNodeVO> cur = tp.getGroups();
if (cur == null) {
cur = new ArrayList<>();
} else {
cur = new ArrayList<>(cur);
}
cur.addAll(batch);
tp.setGroups(cur);
}
private static void ensureTrackParam(FireRuleOutputVO out) {
if (out.getTrackParam() == null) {
out.setTrackParam(new FireRuleTrackParamVO());

View File

@@ -245,6 +245,22 @@ public final class RuleFunction {
FireRuleRedWeaponOutputFillHelper.fillTrackParamAndBindMoveRoute(out, fact.getTask(), p);
}
/**
* 编组规则:填充 {@link com.solution.rule.domain.ultimately.vo.FireRuleTrackParamVO#getGroups}(groupType=addGroup)与僚机 wingmanData。
*/
@SuppressWarnings("rawtypes")
public static void groupFormation(DroolsFact fact, Map globalParams) {
if (fact == null || fact.getTask() == null || fact.getFireRuleOutputVO() == null) {
return;
}
Map<String, Object> p = castParams(globalParams);
boolean enabled = Boolean.parseBoolean(String.valueOf(p.getOrDefault("groupRuleEnabled", true)));
if (!enabled) {
return;
}
FireRuleRedWeaponOutputFillHelper.fillTrackParamGroups(fact.getFireRuleOutputVO(), fact.getTask(), p);
}
@SuppressWarnings("unchecked")
private static Map<String, Object> castParams(Map raw) {
return raw == null ? new java.util.HashMap<>() : (Map<String, Object>) raw;

View File

@@ -7,6 +7,7 @@ import static com.solution.rule.utils.RuleFunction.equipmentRule;
import static com.solution.rule.utils.RuleFunction.target;
import static com.solution.rule.utils.RuleFunction.position;
import static com.solution.rule.utils.RuleFunction.trackRoute;
import static com.solution.rule.utils.RuleFunction.groupFormation;
global java.util.Map globalParams;
@@ -176,6 +177,29 @@ function Map buildParam(){
param.put("trackJamWobbleMeters", 400);
param.put("trackJamSegments", 4);
// ===================== 编组规则参数(写入 TrackParam.Groups + wingmanData) =====================
// groupRuleEnabled:是否生成编组节点。
param.put("groupRuleEnabled", true);
// groupDrawNameSuffix:drawName = 领队装备 Name + 此后缀(默认「编组」)
param.put("groupDrawNameSuffix", "编组");
// groupDrawNameWithIndex:是否在 drawName 末尾追加序号(避免多组同名),如 J15编组1
param.put("groupDrawNameWithIndex", false);
// groupFormationMode:onePerRed(每件红装一组) / clusterByCount(按固定人数分组) / singleGroup(全部一组)
param.put("groupFormationMode", "onePerRed");
// groupClusterSize:clusterByCount 模式下每组人数上限(>=1)
param.put("groupClusterSize", 3);
// groupLeaderPickMode:byHitRateThenId(命中率高优先,平手 equipmentId 小) / byId(equipmentId 字典序最小)
param.put("groupLeaderPickMode", "byHitRateThenId");
// groupMinMembersForWingman:组内人数达到该值才生成 wingmanData(否则仅 leader 壳,僚机列表为空)
param.put("groupMinMembersForWingman", 2);
// wingman 几何参数(相对蓝方主航向 mainBearing 叠加)
param.put("wingmanDistanceBaseMeters", 100);
param.put("wingmanDistanceStepMeters", 50);
param.put("wingmanAngleBaseDeg", 50);
param.put("wingmanAngleStepDeg", 15);
param.put("wingmanAltBaseMeters", 40);
param.put("wingmanAltScale", 1.0);
return param;
}
@@ -218,3 +242,13 @@ then
globalParams.putAll(buildParam());
trackRoute($fact, globalParams);
end
rule "编组匹配"
salience 60
when
$fact : DroolsFact(task != null)
then
// 显式编组规则:填充 TrackParam.Groups(groupType=addGroup)与 wingmanData
globalParams.putAll(buildParam());
groupFormation($fact, globalParams);
end

View File

@@ -36,6 +36,11 @@
<artifactId>springfox-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.solution</groupId>
<artifactId>solution-behaviour</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -2,6 +2,7 @@ package com.solution.scene.mapper;
import com.solution.scene.domain.AfsimScenario;
import com.solution.scene.domain.AfsimScenarioForm;
import com.solution.system.domain.Behaviortree;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@@ -26,4 +27,11 @@ public interface SceneMapper {
List<AfsimScenario> selectSceneList();
AfsimScenario findOneById(Long id);
/**
* 根据场景id获取场景下所有行为树
* @param id
* @return
*/
List<Behaviortree> selectAllTreeBySceneId(Integer id);
}

View File

@@ -2,6 +2,7 @@ package com.solution.scene.service;
import com.solution.scene.domain.AfsimScenario;
import com.solution.scene.domain.AfsimScenarioForm;
import com.solution.system.domain.Behaviortree;
import java.util.List;
@@ -25,4 +26,11 @@ public interface SceneService {
List<AfsimScenario> selectSceneList();
AfsimScenario findOneById(Long id);
/**
* 根据场景id获取场景下所有行为树
* @param id
* @return
*/
List<Behaviortree> getAllTree(Integer id);
}

View File

@@ -1,10 +1,13 @@
package com.solution.scene.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.solution.common.constant.ExceptionConstants;
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 com.solution.system.domain.Behaviortree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -70,4 +73,21 @@ public class SceneServiceImpl implements SceneService {
return sceneMapper.findOneById(id);
}
/**
* 根据场景id获取场景下所有行为树
* @param id
* @return
*/
@Override
public List<Behaviortree> getAllTree(Integer id) {
if(null == id || id <= 0){
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
}
List<Behaviortree> allTree = sceneMapper.selectAllTreeBySceneId(id);
if(CollUtil.isEmpty(allTree)){
throw new RuntimeException("该场景下不存在行为树");
}
return allTree;
}
}

View File

@@ -25,6 +25,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectSceneList" resultMap="SceneMap">
SELECT id, name, description, scenario_path, communication_graph FROM afsim_scenario
</select>
<select id="selectAllTreeBySceneId" resultType="com.solution.system.domain.Behaviortree"
parameterType="java.lang.Integer">
SELECT id, name, description, created_at, updated_at, english_name, graph,xml_content,platform_id,scenario_id
FROM behaviortree
WHERE scenario_id=#{id}
</select>
<insert id="update" parameterType="com.solution.scene.domain.AfsimScenario">
update afsim_scenario

View File

@@ -7,7 +7,7 @@
services:
mysql:
image: mysql:8.0
image: autosolution-mysql-preloaded:latest
container_name: autosolution-mysql
restart: unless-stopped
environment:
@@ -24,7 +24,11 @@ services:
- mysql_data:/var/lib/mysql
- ./docker/mysql/init:/docker-entrypoint-initdb.d:ro
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-p${MYSQL_ROOT_PASSWORD:-root}"]
test:
[
"CMD-SHELL",
"mysql -h 127.0.0.1 -uroot -p$MYSQL_ROOT_PASSWORD -Nse 'SELECT 1 FROM information_schema.tables WHERE table_schema=\"$MYSQL_DATABASE\" AND table_name=\"sys_config\" LIMIT 1' | grep -q 1",
]
interval: 10s
timeout: 5s
retries: 10

View File

@@ -28,6 +28,10 @@ export const findOneTreeByPlatformId = (platformId: number): Promise<BehaviorTre
return req.get(`/system/behaviortree/platform/${platformId}`);
};
export const findSubPlatforms = (treeId: number): Promise<BehaviorTreeDetailsResponse> => {
return req.get(`/system/behaviortree/underling/${treeId}`);
};
export const findOneTreeById = (id: number): Promise<BehaviorTreeDetailsResponse> => {
return req.get(`/system/behaviortree/${id}`);
};
@@ -40,6 +44,10 @@ export const updateTree = (rt: Partial<BehaviorTree>): Promise<BasicResponse> =>
return req.postJson(`/system/behaviortree`, rt);
};
export const copyTree = (rt: Partial<BehaviorTree>): Promise<BasicResponse> => {
return req.postJson(`/system/behaviortree/copy`, rt);
};
export const createTree = (rt: Partial<BehaviorTree>): Promise<BasicResponse> => {
return req.putJson(`/system/behaviortree`, rt);
};

View File

@@ -43,10 +43,11 @@
<Properties
v-if="graph"
:platforms="platforms"
:sub-platforms="subPlatforms"
:nodeCommands="nodeCommands"
:element="selectedNodeTaskElement"
:graph="graph as any"
:node="selectedModelNode as any"
:graph="(graph as any)"
:node="(selectedModelNode as any)"
:tree="currentBehaviorTree"
:tree-editing="currentTreeEditing"
@update-element="handleUpdateElement" />
@@ -74,8 +75,8 @@ import { createGraphTaskElementFromTemplate } from './utils';
import { createGraphTaskElement, createLineOptions, type GraphContainer, type GraphTaskElement, hasElements, hasRootElementNode, resolveGraph, useGraphCanvas } from '../graph';
import { registerNodeElement } from './register';
import { findAllBasicPlatforms, findAllNodeCommands } from '../api';
import type { Platform } from '../types';
import { createTree, findOneTreeById, findOneTreeByPlatformId, updateTree } from './api';
import type { NodeCommand, Platform } from '../types';
import { createTree, findOneTreeById, findOneTreeByPlatformId, updateTree, findSubPlatforms } from './api';
import TressCard from './trees-card.vue';
import NodesCard from './nodes-card.vue';
@@ -112,6 +113,7 @@ export default defineComponent({
const changed = ref<boolean>(false);
const treesCardRef = ref<InstanceType<typeof TressCard> | null>(null);
const platforms = ref<Platform[]>([]);
const subPlatforms = ref<Platform[]>([]);
const nodeCommands = ref<NodeCommand[]>([])
const currentScenarioId = ref<number | null>(null);
const currentPlatformId = ref<number | null>(null);
@@ -153,6 +155,27 @@ export default defineComponent({
loadNodeCommands();
}
// 加载下属平台
const loadSubPlatforms = (treeId: number) => {
console.log(treeId);
if (!treeId || treeId <= 0) {
subPlatforms.value = [];
return;
}
findSubPlatforms(treeId).then(r => {
if (r.data && Array.isArray(r.data)) {
subPlatforms.value = r.data as Platform[];
} else {
subPlatforms.value = [];
}
}).catch(err => {
console.error('加载下属平台失败:', err);
subPlatforms.value = [];
});
};
// 处理拖动开始
const handleDragStart = (nm: NodeDragTemplate) => {
draggedNodeData.value = nm;
@@ -267,6 +290,10 @@ export default defineComponent({
graph: nodeGraph,
};
currentTreeEditing.value = true;
// 加载下属平台
loadSubPlatforms(r.data.id);
nextTick(() => {
initGraph();
});
@@ -343,6 +370,7 @@ export default defineComponent({
};
selectedModelNode.value = null;
selectedNodeTaskElement.value = null;
subPlatforms.value = []; // 重置下属平台
nextTick(() => {
initGraph();
@@ -487,6 +515,7 @@ export default defineComponent({
nodeCommands,
currentScenarioId,
platforms,
subPlatforms,
treesCardRef,
handleCreateTree,
currentTreeEditing,

View File

@@ -101,7 +101,7 @@
size="small"
type="editable-card"
@edit="onEditParameterTab">
<a-tab-pane v-for="(grouped,index) in groupedParameters" :key="index" :tab="`平台 ${index + 1}`" :closable="true">
<a-tab-pane v-for="(grouped,index) in groupedParameters" :key="index" :tab="getPlatformTabName(index)" :closable="true">
<a-form-item v-for="setting in grouped" :label="setting.description">
<a-input-number v-if="setting.dataType === 'double'"
v-model:value="setting.defaultValue"
@@ -109,7 +109,7 @@
<a-select :placeholder="`请选择${setting.description}`"
allow-clear
v-else-if="setting.paramKey === 'platforms'" v-model:value="setting.defaultValue">
<a-select-option v-for="pl in platforms" :value="pl.name">{{pl.description}}</a-select-option>
<a-select-option v-for="pl in getAvailablePlatforms()" :value="pl.name">{{pl.description}}</a-select-option>
</a-select>
<a-select :placeholder="`请选择${setting.description}`"
allow-clear
@@ -194,11 +194,13 @@ export default defineComponent({
node: { type: [Object, null] as PropType<Node<NodeProperties> | null | undefined>, required: false },
graph: { type: [Object, null] as PropType<Graph | null | undefined>, required: true },
platforms: { type: Array as PropType<Platform[]>, required: true },
subPlatforms: { type: Array as PropType<Platform[]>, required: false, default: () => [] },
nodeCommands: { type: Array as PropType<NodeCommand[]>, required: true },
},
emits: ['update-element', 'update-tree'],
setup(props, { emit }) {
const platforms = ref<Platform[]>(props.platforms ?? []);
const subPlatforms = ref<Platform[]>(props.subPlatforms ?? []);
const nodeCommands = ref<NodeCommand[]>(props.nodeCommands ?? []);
const activeTopTabsKey = ref<string>('1');
@@ -299,6 +301,41 @@ export default defineComponent({
multiableParameters.value = multiable === true && groupedParameters.value.length > 0;
};
// 获取平台Tab显示名称
const getPlatformTabName = (index: number): string => {
if (!currentTree.value?.platformId) {
return `平台 ${index + 1}`;
}
// 查找当前行为树绑定的平台
const currentPlatform = platforms.value.find(p => p.id === currentTree.value?.platformId);
if (!currentPlatform) {
return `平台 ${index + 1}`;
}
// 如果有多个分组,显示平台名称和索引
if (groupedParameters.value.length > 1) {
return `${currentPlatform.name || '未知平台'}-${index + 1}`;
}
return currentPlatform.name || '平台';
};
// 获取可用的平台列表(包括当前平台和其下属平台)
const getAvailablePlatforms = (): Platform[] => {
if (!currentTree.value?.platformId) {
return platforms.value;
}
// 如果有下属平台,返回下属平台列表
if (subPlatforms.value && subPlatforms.value.length > 0) {
return subPlatforms.value;
}
// 否则返回所有平台
return platforms.value;
};
const resolveNode = (n?: Node | null | undefined) => {
groupedParametersActiveTab.value = 0;
@@ -389,6 +426,7 @@ export default defineComponent({
watch(() => props.nodeCommands, (n: NodeCommand[] | null | undefined) => nodeCommands.value = n ?? [], { deep: true, immediate: true });
watch(() => props.platforms, (n: Platform[] | null | undefined) => platforms.value = n ?? [], { deep: true, immediate: true });
watch(() => props.subPlatforms, (n: Platform[] | null | undefined) => subPlatforms.value = n ?? [], { deep: true, immediate: true });
onMounted(() => load());
@@ -400,6 +438,8 @@ export default defineComponent({
multiableParameters,
onEditParameterTab,
groupedParameters,
getPlatformTabName,
getAvailablePlatforms,
actionSpaceColumns,
activeTopTabsKey,
activeBottomTabsKey,

View File

@@ -29,6 +29,12 @@
</a-tooltip>
<a-flex class="ks-tree-actions">
<!-- <span style="margin-right: 10px"><EditFilled /></span>-->
<a-popconfirm
title="确定复制?"
@confirm="()=> handleCopy(item)"
>
<span class="ks-tree-action ks-tree-action-copy" @click.stop style="margin-right: 10px"><CopyOutlined /></span>
</a-popconfirm>
<a-popconfirm
title="确定删除?"
@confirm="()=> handleDelete(item)"
@@ -51,15 +57,16 @@
<script lang="ts">
import { defineComponent, onMounted, ref } from 'vue';
import { CheckOutlined, DeleteOutlined, EditFilled, PlusOutlined } from '@ant-design/icons-vue';
import { CheckOutlined, CopyOutlined, DeleteOutlined, EditFilled, PlusOutlined } from '@ant-design/icons-vue';
import type { BehaviorTree, BehaviorTreeRequest } from './tree';
import { deleteOneTreeById, findTreesByQuery } from './api';
import { copyTree, deleteOneTreeById, findTreesByQuery } from './api';
import { substring } from '@/utils/strings';
export default defineComponent({
emits: ['select-tree', 'create-tree'],
components: {
CheckOutlined,
CopyOutlined,
PlusOutlined,
DeleteOutlined,
EditFilled,
@@ -95,6 +102,14 @@ export default defineComponent({
});
};
const handleCopy = (item: BehaviorTree) => {
copyTree(item).then(r => {
if (r.code === 200) {
loadTress();
}
});
};
const columns = [
{
title: '名称',
@@ -133,6 +148,7 @@ export default defineComponent({
handleSelect,
handleChange,
handleDelete,
handleCopy,
};
},
});

View File

@@ -104,6 +104,7 @@ export const createGraphConnectingAttributes = (): Partial<Connecting> => {
export const createGraphCanvas = (container: HTMLDivElement, readonly: boolean = false): Graph => {
const graph = new Graph({
container: container,
autoResize: true,
grid: {
size: 20,
visible: true,