Merge branch 'refs/heads/develop'
# Conflicts: # auto-solution-rule/src/main/java/com/solution/rule/service/FireRuleService.java # modeler/src/style.less
This commit is contained in:
@@ -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;
|
||||
@@ -73,4 +74,15 @@ public class FireRuleController extends BaseController {
|
||||
public AjaxResult getComponents(@PathVariable Integer platformId){
|
||||
return success(ruleService.getComponents(platformId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始执行规则匹配
|
||||
* @param task 敌方参数
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/rule")
|
||||
@ApiOperation("开始执行规则匹配")
|
||||
public AjaxResult execute(@RequestBody Task task){
|
||||
return success(ruleService.executeTask(task));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,55 @@
|
||||
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>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,7 +1,6 @@
|
||||
package com.solution.rule.service;
|
||||
|
||||
import com.solution.rule.domain.FireRuleExecuteDTO;
|
||||
import com.solution.rule.domain.Platform;
|
||||
import com.solution.rule.domain.PlatformComponent;
|
||||
import com.solution.rule.domain.vo.PlatformComponentNamesVO;
|
||||
import com.solution.rule.domain.vo.PlatformWeaponAggregateVO;
|
||||
@@ -45,4 +44,11 @@ public interface FireRuleService {
|
||||
* @return
|
||||
*/
|
||||
List<Platform> findPlatformComponents(Integer scenarioId);
|
||||
|
||||
/**
|
||||
* 开始执行规则匹配
|
||||
* @param task
|
||||
* @return
|
||||
*/
|
||||
Task executeTask(Task task);
|
||||
}
|
||||
|
||||
@@ -8,14 +8,20 @@ import com.solution.rule.domain.Platform;
|
||||
import com.solution.rule.domain.PlatformComponent;
|
||||
import com.solution.rule.domain.RuleParam;
|
||||
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||
import com.solution.rule.domain.simplerulepojo.Task;
|
||||
import com.solution.rule.domain.simplerulepojo.Weapon;
|
||||
import com.solution.rule.domain.vo.ComponentCountVO;
|
||||
import com.solution.rule.domain.vo.PlatformComponentNamesVO;
|
||||
import com.solution.rule.domain.vo.PlatformWeaponAggregateVO;
|
||||
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||
import com.solution.rule.mapper.FireRuleMapper;
|
||||
import com.solution.rule.service.FireRuleService;
|
||||
import com.solution.rule.simpstrategy.FireRUleType;
|
||||
import com.solution.rule.simpstrategy.FireRuleStrategy;
|
||||
import com.solution.rule.simpstrategy.FireRuleStrategyFactory;
|
||||
import com.solution.rule.strategy.SceneStrategy;
|
||||
import com.solution.rule.strategy.SceneStrategyFactory;
|
||||
import org.kie.api.KieBase;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -33,9 +39,15 @@ public class FireRuleServiceImpl implements FireRuleService {
|
||||
@Autowired
|
||||
private SceneStrategyFactory strategyFactory;
|
||||
|
||||
@Autowired
|
||||
private FireRuleStrategyFactory fireStrategyFactory;
|
||||
|
||||
@Autowired
|
||||
private FireRuleMapper ruleMapper;
|
||||
|
||||
@Autowired
|
||||
private KieBase kieBase;
|
||||
|
||||
/* @Override
|
||||
public WeaponModelVO execute(Integer sceneType, WeaponModelDTO weaponModelDTO) {
|
||||
if(ObjectUtil.isNull(sceneType) || ObjectUtil.isEmpty(weaponModelDTO)){
|
||||
@@ -155,6 +167,28 @@ public class FireRuleServiceImpl implements FireRuleService {
|
||||
return ruleMapper.getComponents(platformId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行任务
|
||||
* @param task
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Task executeTask(Task task) {
|
||||
if(ObjectUtil.isEmpty(task)){
|
||||
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
|
||||
}
|
||||
String dataType = task.getDataType();
|
||||
if("打击".contains(dataType)){
|
||||
FireRuleStrategy strategy = fireStrategyFactory.getStrategy(0);
|
||||
task = strategy.mappingTask(task);
|
||||
} else {
|
||||
FireRuleStrategy strategy = fireStrategyFactory.getStrategy(1);
|
||||
task = strategy.mappingTask(task);
|
||||
}
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有组件以及数量
|
||||
* @return
|
||||
|
||||
@@ -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>
|
||||
315
auto-solution-rule/src/main/resources/rules/README.md
Normal file
315
auto-solution-rule/src/main/resources/rules/README.md
Normal file
@@ -0,0 +1,315 @@
|
||||
# fire-rule.drl 维护说明(业务+开发)
|
||||
|
||||
本文档对应 `auto-solution-rule/src/main/resources/rules/fire-rule.drl` 当前版本,重点说明:
|
||||
- 业务人员改哪里
|
||||
- 每个参数改了会产生什么效果
|
||||
- 如何快速判断规则是否“命中/不命中”
|
||||
|
||||
## 1. 先看这一个入口:业务可改区
|
||||
|
||||
只改 `//TODO` 下的 `buildBusinessConfig()`,其他函数不要改。
|
||||
|
||||
`buildBusinessConfig()` 里每个参数的效果如下。
|
||||
|
||||
## 2. 参数-效果对照(给业务人员)
|
||||
|
||||
### 2.1 武器名称映射(改名字,不改逻辑)
|
||||
- `redStrikeDroneName`:空中反制组中的无人机名称。
|
||||
- `redArmedHelicopterName`:空中反制组中的武装直升机名称。
|
||||
- `redHowitzerName`:地面反制组中的迫榴炮名称。
|
||||
- `redVehicleMortarName`:地面反制组中的车载迫击炮名称。
|
||||
- `redAaWeaponName`:空中反制组中的防空导弹武器名称。
|
||||
- `redAtRocketName`:装甲反制组中的反坦克火箭名称。
|
||||
- `redAtMissileSystemName`:装甲反制组中的反坦克导弹系统名称。
|
||||
- `redMissileVehicleName`:导弹补充组中的导弹发射车名称。
|
||||
|
||||
### 2.2 白名单开关(决定“是否匹配”)
|
||||
- `enableAirRule`:`true` 时,蓝方空中目标会触发红方空中反制组;`false` 时该组永不触发。
|
||||
- `enableGroundRule`:`true` 时,蓝方地面目标会触发红方炮类反制组;`false` 时不触发。
|
||||
- `enableArmorRule`:`true` 时,蓝方装甲目标会触发红方反坦克组;`false` 时不触发。
|
||||
- `enableMissileVehicleRule`:`true` 时,蓝方有导弹能力可追加导弹发射车;`false` 时不追加。
|
||||
- `enableMissileLinkage`:`true` 时开启导弹数量/范围联动;`false` 时不做导弹联动增强。
|
||||
- `allowMultiGroup`:
|
||||
- `true`:同一批输入可命中多组策略并叠加武器;
|
||||
- `false`:只命中第一组,后续组不再生效(更“死规则”)。
|
||||
- `enableArmedHelicopterOnAir`:空中组中是否包含武装直升机。
|
||||
|
||||
### 2.3 蓝方类型到红方方案映射(核心,可多选)
|
||||
|
||||
先解释你提到的 “k”:
|
||||
- 这里的 `k` 就是 **key(键名)**,例如 `map_armor_targets`。
|
||||
- `v` 是 **value(值)**,例如 `反坦克火箭,反坦克导弹系统`。
|
||||
- 规则实际含义就是:`key` 决定“哪类蓝方目标”,`value` 决定“红方上哪些武器”。
|
||||
|
||||
映射键名中文对照:
|
||||
- `map_air_targets`:蓝方是空中目标时,红方使用哪些武器。
|
||||
- `map_ground_targets`:蓝方是地面目标时,红方使用哪些武器。
|
||||
- `map_armor_targets`:蓝方是装甲目标(坦克/装甲车)时,红方使用哪些武器。
|
||||
- `map_artillery_targets`:蓝方是炮类目标时,红方使用哪些武器。
|
||||
- `map_missile_targets`:蓝方有导弹能力时,红方使用哪些武器。
|
||||
|
||||
映射规则说明:
|
||||
- 值必须是红方武器库内合法名称,否则该项会被忽略。
|
||||
- 为空时视为该组不配置,允许不命中。
|
||||
- 示例:`map_armor_targets=反坦克火箭,反坦克导弹系统` 表示坦克可同时触发两种红方反制武器。
|
||||
|
||||
### 2.4 数量和阈值(决定“匹配后给多少”)
|
||||
- `defaultAirNum`:空中组默认数量。
|
||||
- `defaultGroundNum`:地面/装甲组默认数量。
|
||||
- `defaultMissileVehicleNum`:导弹发射车默认数量。
|
||||
- `shellRangeDefault`:炮类组件参数值,单位固定 `范围米`。
|
||||
- `missileCountOffset`:红方导弹数量 = 蓝方导弹数量 + 偏移量。
|
||||
- `missileRangeOffset`:红方导弹范围 = 蓝方导弹范围 + 偏移量(单位 `破坏范围米`)。
|
||||
- `blueMissileRangeDefault`:蓝方导弹范围缺失时采用的默认值。
|
||||
- `minBlueMissileCountForLinkage`:蓝方导弹数量达到该值才触发联动增强。
|
||||
|
||||
### 2.5 targetId 自动绑定参数(新增)
|
||||
- `enableTargetAutoBind`:是否自动给红方武器写入 `targetId`。
|
||||
- `minTargetBindRatio`:最低绑定比例(例如 `0.7` 表示至少 70% 红方武器有目标)。
|
||||
- `allowReserveWithoutTarget`:
|
||||
- `true`:允许少量红方武器 `targetId` 为空(火力冗余)。
|
||||
- `false`:尽量给每个红方武器分配目标。
|
||||
|
||||
绑定规则说明(固定,不需要业务改代码):
|
||||
- 绑定来源是蓝方武器 `equipmentId`。
|
||||
- 匹配优先级按武器类型:
|
||||
- 防空类红方武器优先绑定蓝方空中目标
|
||||
- 反装甲类红方武器优先绑定蓝方装甲目标
|
||||
- 炮类红方武器优先绑定蓝方炮类/地面目标
|
||||
- 导弹发射车优先绑定蓝方导弹能力目标
|
||||
- 当优先池不足时自动回退到地面池/全目标池,保证大部分武器有目标。
|
||||
|
||||
### 2.6 阵位规则参数(新增)
|
||||
- `enablePositionRules`:阵位规则总开关。
|
||||
- 阵位输入来源:`blueTask.warZoneLocation` 与 `blueTask.defZoneLocation`(各 4 个经纬点)。
|
||||
- `fireUnitSpacingMeters`:防区/作战区点位间距(米),例如 `100` 代表约每 100 米一个火力单元。
|
||||
- `airDeployZonePreference`:飞机优先部署区域(`combat` 或 `defense`)。
|
||||
- `defensePriorityWeapons`:优先部署在防区的武器名单(逗号分隔)。
|
||||
- `groundDeployHeight` / `airDeployHeight`:地面/空中武器部署高度。
|
||||
|
||||
阵位规则效果:
|
||||
- 新增两条规则:
|
||||
- `阵位规则-区域解析与点位生成`
|
||||
- `阵位规则-武器部署赋位`
|
||||
- 飞机可在任意区(按偏好区优先);反坦克等重火力优先防区。
|
||||
- 在多边形区域内按间距生成候选点,并给红方武器写入 `weapon.coordinate`。
|
||||
|
||||
阵位输入示例(仅经纬度,4点):
|
||||
|
||||
```json
|
||||
{
|
||||
"warZoneLocation": [
|
||||
{ "longitude": 116.3801, "latitude": 39.9001 },
|
||||
{ "longitude": 116.3901, "latitude": 39.9001 },
|
||||
{ "longitude": 116.3901, "latitude": 39.9101 },
|
||||
{ "longitude": 116.3801, "latitude": 39.9101 }
|
||||
],
|
||||
"defZoneLocation": [
|
||||
{ "longitude": 116.3825, "latitude": 39.9025 },
|
||||
{ "longitude": 116.3875, "latitude": 39.9025 },
|
||||
{ "longitude": 116.3875, "latitude": 39.9075 },
|
||||
{ "longitude": 116.3825, "latitude": 39.9075 }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 2.7 航迹规则参数(新增)
|
||||
- `enableTrajectoryRules`:航迹规则总开关。
|
||||
- `strategyMode`:`auto/shortest/flank/interfere`。
|
||||
- `auto`:智能选择策略。
|
||||
- 其他值:强制使用指定策略(若该策略被禁用会自动回退)。
|
||||
- `enableShortest` / `enableFlank` / `enableInterfere`:各策略开关。
|
||||
- `nearDefDistanceMeters`:蓝方末端点到防区的“近距离阈值”。
|
||||
- `farDefDistanceMeters`:蓝方末端点到防区的“远距离阈值”。
|
||||
- `fastSpeedThreshold`:蓝方平均速度达到该值视为“高速”。
|
||||
- `flankOffsetMeters`:绕后追击偏移幅度(越大绕后越明显)。
|
||||
- `interfereOffsetMeters`:干扰轨迹基础偏移。
|
||||
- `interfereZigzagAmplitude`:干扰轨迹锯齿振幅(越大摆动越明显)。
|
||||
- `keepBlueHeight`:是否沿用蓝方高度。
|
||||
- `redTrackHeightOverride`:不沿用时红方统一高度。
|
||||
|
||||
航迹智能选择逻辑:
|
||||
- `near + fast` -> `shortest`(最短距离追击)
|
||||
- `far + fast` -> `interfere`(干扰/诱偏)
|
||||
- 其他 -> `flank`(绕后追击)
|
||||
|
||||
不生成保护:
|
||||
- 蓝方 `trackPoints` 为空,或 `defZoneLocation` 点数不足(<3),则不生成红方航迹。
|
||||
|
||||
## 3. 当前规则行为(简版)
|
||||
|
||||
- `装备组件匹配`、`组件参数匹配`:已作为 `legacy` 占位,不承担当前业务决策。
|
||||
- 主决策在 `红方武器自适应装配规则`:调用 `configureRedWeaponsByBlue(...)`,按“映射配置”添加武器。
|
||||
- 导弹增强在 `导弹联动增强规则`:调用 `applyMissileLinkage(...)`,受开关和阈值控制。
|
||||
- 任务命名在 `任务自动匹配规则`:调用 `assignTaskNameByRedWeapons(...)`,按红方最终武器自动生成任务名和 `dataType`。
|
||||
- 炮类约束:命中炮类条件时,炮类武器只保留 `炮弹` 组件,单位 `范围米`。
|
||||
- `targetId` 绑定:在装配后自动执行,尽量为红方武器绑定蓝方 `equipmentId`,允许少量空值冗余。
|
||||
- 阵位部署:按多边形区域和武器类型自动赋位,保证防区火力覆盖。
|
||||
- 航迹生成:根据蓝方 `trackPoints` 生成红方 `trackPoints`,点数与蓝方一致,支持三套策略和智能选择。
|
||||
|
||||
## 3.1 任务名称自动匹配(新增)
|
||||
|
||||
任务命名依据:**红方最终武器**(不是蓝方任务名关键字)。
|
||||
|
||||
当前分类优先级:
|
||||
- 导弹突击(导弹发射车)
|
||||
- 防空压制(防空导弹武器/火力打击无人机/武装直升机)
|
||||
- 反装甲打击(反坦克火箭/反坦克导弹系统)
|
||||
- 炮火压制(迫榴炮/车载迫击炮)
|
||||
- 通用打击(兜底)
|
||||
|
||||
业务可调模板(在 `buildBusinessConfig()`):
|
||||
- `taskName_missile_strike` / `taskDataType_missile_strike`
|
||||
- `taskName_air_defence` / `taskDataType_air_defence`
|
||||
- `taskName_anti_armor` / `taskDataType_anti_armor`
|
||||
- `taskName_artillery` / `taskDataType_artillery`
|
||||
- `taskName_general` / `taskDataType_general`
|
||||
|
||||
效果说明:
|
||||
- 只改这些模板文字,不改函数,也能改变最终任务展示名。
|
||||
- 若分类与武器不一致,会自动回落到 `通用打击任务`,避免“任务名和武器不符”。
|
||||
|
||||
## 4. 快速修改示例(业务常用)
|
||||
|
||||
- 想让规则更“死”:
|
||||
- 把 `allowMultiGroup` 改成 `false`。
|
||||
- 想让“坦克只上反坦克火箭,不上导弹系统”:
|
||||
- 把 `map_armor_targets` 改成 `反坦克火箭`。
|
||||
- 想让“坦克同时上火箭和导弹系统”:
|
||||
- 把 `map_armor_targets` 改成 `反坦克火箭,反坦克导弹系统`。
|
||||
- 想允许更多不命中:
|
||||
- 关闭部分开关,例如 `enableGroundRule=false`、`enableArmorRule=false`。
|
||||
- 想让导弹联动更难触发:
|
||||
- 提高 `minBlueMissileCountForLinkage`,例如从 `1` 调到 `3`。
|
||||
- 想提升炮类打击范围:
|
||||
- 调大 `shellRangeDefault`,例如 `1500 -> 1800`。
|
||||
|
||||
## 5. 测试 JSON(按你项目常用的 Task 入参格式)
|
||||
|
||||
说明:下面 JSON 是 **单个 Task** 格式,不是 `FactTask` 包装格式。
|
||||
如果你的执行入口最终需要 `FactTask`,则由开发在服务层把“蓝方 Task + 红方 Task”组装后再 `insert` 规则引擎。
|
||||
|
||||
### 5.1 不命中样例(蓝方 Task)
|
||||
说明:该样例仅用于蓝方任务输入结构校验;若业务把对应映射留空或关闭开关,则允许不命中。
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "blue-miss-001",
|
||||
"side": "蓝方",
|
||||
"dataType": "打击",
|
||||
"threatLevel": "2",
|
||||
"taskWeapons": [
|
||||
{
|
||||
"name": "攻击直升机",
|
||||
"supportType": "overhead",
|
||||
"number": 1,
|
||||
"components": []
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 5.2 命中样例(蓝方 Task)
|
||||
说明:该蓝方输入同时包含空中和装甲特征,且有导弹组件,满足命中与联动测试条件。
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "blue-hit-001",
|
||||
"side": "蓝方",
|
||||
"dataType": "打击",
|
||||
"threatLevel": "3",
|
||||
"taskWeapons": [
|
||||
{
|
||||
"name": "攻击直升机",
|
||||
"supportType": "overhead",
|
||||
"number": 2,
|
||||
"components": [
|
||||
{
|
||||
"deviceName": "机载导弹",
|
||||
"componentParams": [
|
||||
{
|
||||
"attDefaultValue": "260",
|
||||
"attExplain": "破坏范围米",
|
||||
"number": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "主战坦克",
|
||||
"supportType": "ground",
|
||||
"number": 2,
|
||||
"components": []
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 5.3 红方初始 Task 样例(通常为空列表)
|
||||
说明:用于和蓝方 Task 组装成规则输入对象。
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "red-init-001",
|
||||
"side": "红方",
|
||||
"dataType": "打击",
|
||||
"threatLevel": "1",
|
||||
"taskWeapons": []
|
||||
}
|
||||
```
|
||||
|
||||
### 5.4 航迹规则不生成样例(缺防区)
|
||||
```json
|
||||
{
|
||||
"id": "blue-track-miss-001",
|
||||
"side": "蓝方",
|
||||
"dataType": "打击",
|
||||
"threatLevel": "2",
|
||||
"defZoneLocation": [],
|
||||
"trackPoints": [
|
||||
{ "index": 0, "longitude": 116.3801, "latitude": 39.9001, "height": 100, "speed": 210 },
|
||||
{ "index": 1, "longitude": 116.3810, "latitude": 39.9010, "height": 100, "speed": 220 }
|
||||
],
|
||||
"taskWeapons": []
|
||||
}
|
||||
```
|
||||
|
||||
### 5.5 航迹规则命中样例(可生成)
|
||||
```json
|
||||
{
|
||||
"id": "blue-track-hit-001",
|
||||
"side": "蓝方",
|
||||
"dataType": "打击",
|
||||
"threatLevel": "3",
|
||||
"defZoneLocation": [
|
||||
{ "longitude": 116.4001, "latitude": 39.9201 },
|
||||
{ "longitude": 116.4051, "latitude": 39.9201 },
|
||||
{ "longitude": 116.4051, "latitude": 39.9251 },
|
||||
{ "longitude": 116.4001, "latitude": 39.9251 }
|
||||
],
|
||||
"trackPoints": [
|
||||
{ "index": 0, "longitude": 116.3801, "latitude": 39.9001, "height": 120, "speed": 240 },
|
||||
{ "index": 1, "longitude": 116.3840, "latitude": 39.9040, "height": 120, "speed": 245 },
|
||||
{ "index": 2, "longitude": 116.3880, "latitude": 39.9080, "height": 120, "speed": 250 },
|
||||
{ "index": 3, "longitude": 116.3920, "latitude": 39.9120, "height": 120, "speed": 248 }
|
||||
],
|
||||
"taskWeapons": []
|
||||
}
|
||||
```
|
||||
|
||||
## 6. 开发人员说明(放在末尾)
|
||||
|
||||
- **入口约定**:业务仅改 `buildBusinessConfig()`,开发改函数实现时不要破坏该入口。
|
||||
- **类型约定**:配置读取统一走 `readIntCfg(...)` / `readBooleanCfg(...)`,避免 `Map` 强转异常。
|
||||
- **策略收敛**:`configureRedWeaponsByBlue(...)` 使用 `matchedAny + allowMultiGroup` 控制“单组命中/多组叠加”。
|
||||
- **映射解析**:通过 `parseMappedWeaponNames(...)` 将逗号分隔配置解析为武器列表,非法名称会被 `isValidRedWeaponNameByConfig(...)` 过滤。
|
||||
- **联动门控**:`applyMissileLinkage(...)` 必须同时满足:
|
||||
- `enableMissileLinkage=true`
|
||||
- 蓝方导弹数量 `>= minBlueMissileCountForLinkage`
|
||||
- **目标绑定**:`bindTargetIdsForRedWeapons(...)` 基于蓝方 `equipmentId` 分配 `targetId`,支持“优先匹配 + 绑定率阈值 + 冗余空目标”。
|
||||
- **阵位部署**:`prepareDeploymentPools(...)` + `applyWeaponDeployment(...)` 负责区域解析、点位生成与部署赋位。
|
||||
- **航迹生成**:`applyTrajectoryGeneration(...)` + `chooseTrajectoryStrategy(...)` + `generateRedTrackPoints(...)` 负责红方航迹策略生成。
|
||||
- **任务命名**:`assignTaskNameByRedWeapons(...)` 仅基于红方最终武器,避免旧版按蓝方 `drawName` 关键字造成误判。
|
||||
- **legacy 区域**:`装备组件匹配`、`组件参数匹配` 及 legacy 函数区只保留回滚,不建议继续扩展。
|
||||
- **新增武器建议**:优先补 `isAirWeapon/isGroundWeapon/isArmorWeapon/isArtilleryWeapon` 分类,再补 `ensureBasicRedComponents(...)` 模板。
|
||||
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
@@ -1204,7 +1204,7 @@
|
||||
.ant-tabs-content {
|
||||
//padding: 15px;
|
||||
padding: 4px;
|
||||
background: #041832;
|
||||
background: #041b36db;
|
||||
}
|
||||
|
||||
&.settings-tab,
|
||||
@@ -1642,189 +1642,3 @@
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-input-group-addon {
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
66
requirements.md
Normal file
66
requirements.md
Normal file
@@ -0,0 +1,66 @@
|
||||
**1.项目概述**:
|
||||
|
||||
	军事沙盘游戏,是一个Spring Boot框架,若依开发平台前后端分离版, 主要为了服务别的服务调用我的接口,我自动生成火力配置,主要是做火力规则。
|
||||
|
||||
**2.大致需求**:
|
||||
|
||||
	我现在需要根据入参的json(超级大,将近1.3M,2w多行)使用Drools(项目中rule模块已经引入依赖)系统完成规则的建立,并且每个drl文件中的注释要清楚,因为后续要加入WorBench让不懂开发的人员修改我的规则(暂时先不用)
|
||||
|
||||
并且要注意出传入的json如果过大需要注意OOM,并且注入Drools中的实体过多也有可能OOM,理解整个需求文档之后,设计怎么接收参数,插入Drools,保证不会出现OOM!因为传入的JSON总体来说有不少需要用到,但是有一些细致的参数可能又不需要匹配上!
|
||||
|
||||
2.1需求详细:
|
||||
|
||||
我需要根据传入的json匹配我的规则,然后再json中填写红方任务下的武器、武器参数、部署位置、航迹等位置的数据
|
||||
|
||||
2.1.1 允许出现蓝方武器,红方没有应对的武器的情况,证明红方武器不够
|
||||
|
||||
2.1.2 允许出现返回的红方任务中的部分json字段为空,原样返回,因为我的规则不需要把所有数据填上去(具体需要填那些我会在第三部分具体规则设计中写出来)
|
||||
|
||||
2.2 注意事项:
|
||||
|
||||
2.2.1 Json很大,需要使用流式解析,接收时拿到需要的数据,具体需要那些参数我会把Json参考文件(区域防御场景设计_2026-01-14 11_49_10_带注释)放到和本文件同级的位置,你自己取阅读,决定,只要匹配我下方的规则就行;
|
||||
|
||||
2.2.3 整个火力规则接口的里面需要用到的数据都是传入的json中的,没有数据库操作,包括输出的json也是传入的json,只是需要把json中红方的任务内容填上去(允许有规则匹配不上导致参数为空)
|
||||
|
||||
	注释要求:
|
||||
|
||||
	 1.任何注释都不要在行尾进行注释,放在上方
|
||||
|
||||
	 2.实体类的属性注释和方法(函数)内部的注释要使用//,类注释和方法上的注释使用/\* \*/
|
||||
|
||||
**3.具体规则设计**:
|
||||
|
||||
**只需要在json中填写红方任务下的内容,具体的规则需要体现在Drools的drl文件中,必须添加注释,供业务人员修改规则**
|
||||
|
||||
3.1 需要设计装备匹配的规则,主要有装备类型的匹配,比如蓝方有空中武器,需要根据航迹,经纬高,来决定我方使用何种武器(从json的红方装备拿,拿id填写到weaponId上就行,在weaponId附近有一个targetId要填写这个武器对应的是蓝方的什么武器,其他的参数需要你理解填写上去,不理解的不要乱填,所有数据都在传入的json中),还需要根据蓝方的数量做匹配,理论上应该>= 蓝方数量(允许出现小于,因为红方获取数量武器不够),还需要根据威胁等级字段名:threatLevel 取值范围(1-3来决定使用那些红方武器进行打击)
|
||||
|
||||
允许你根据传入json(蓝方已有条件和红方已有条件)设计其他匹配的规则,但是要标明注释,根据那些参数,怎么使用,修改
|
||||
|
||||
3.2 需要设计阵位的规则,根据蓝方的阵位部署,红方的武器需要部署在红方的防区和作战区,作战区域字段名:warTerritory ,防区类型字段名:airspaceType 3是防区的意思(注意必须是红方的防区或者作战区,作战区不分红蓝方)
|
||||
|
||||
|
||||
|
||||
3.3 需要设计航迹的规则,根据蓝方任务编队的航迹来决定我方任务的航迹,可以根据高度、速度、航向角、经纬高等参数设计规则,不管使用最短距离算法,还是绕后打击算法都可以(最好在Drools中提供规则,标明怎么使用,修改)
|
||||
|
||||
3.4 需要做任务类型的匹配,如果蓝方是干扰任务,红方需要根据红方的反干扰武器进行匹配,具体匹配可以同3.1的规则,但是任务类型不同
|
||||
|
||||
3.5 上述所有规则都需要贴合实际,并且规则中不需要考虑任务的开始结束时间
|
||||
|
||||
|
||||
|
||||
**4.JSON辅助理解**
|
||||
|
||||
本点是辅助你理解传入的JSON
|
||||
|
||||
4.1 Tasks下是蓝红方的所有任务,我需要根据蓝方的任务做红方的任务匹配,并且匹配红方任务下的武器装备
|
||||
|
||||
4.2 RefAttributeObject下是所有武器的参数,注意要区分这个武器是蓝方还是红方,attDefaultValue字段是这个武器的值,attExplain是值的单位
|
||||
|
||||
4.3 ScenarioBase和Options这两个我的整个规则系统中不需要关心,Environment这个字段里面是环境的配置,你自由决定内部参数参不参与规则
|
||||
|
||||
4.4 ForceSides用来区分红蓝方,Equipments是所有装备(注意区分红蓝方)
|
||||
|
||||
4.5 所有的武器装备,参数,任务,都没有形成直接的上下级结构,都是通过id来关联
|
||||
|
||||
4.6 taskName不用关心,Groups暂时不用关心(后续可能会需要)
|
||||
|
||||
323
scheme.md
Normal file
323
scheme.md
Normal file
@@ -0,0 +1,323 @@
|
||||
# 火力规则实现方案(scheme)— 详细版
|
||||
|
||||
本文档供**后续智能体或开发人员**按步骤实现代码使用。依据 [requirements.md](requirements.md) 与样例 JSON(`区域防御场景设计_2026-01-14 11_49_10_带注释.json`)。需求中提及但样例中**未出现**的字段(如 `threatLevel`、`warTerritory`、`airspaceType`)在代码中预留 **Optional / 占位事实类字段**,规则写骨架注释即可,**不要阻塞主流程编译**。
|
||||
|
||||
---
|
||||
|
||||
## 1. 目标与边界(实现时必须遵守)
|
||||
|
||||
| 项 | 说明 |
|
||||
|----|------|
|
||||
| 输入 | 单份超大军事场景 JSON(约 1.3MB 级),**无数据库** |
|
||||
| 输出 | **同一 JSON 结构**;仅对**红方任务**下业务约定字段做补全;其它键值保持输入原样 |
|
||||
| 引擎 | Drools 7.x(见 `auto-solution-rule/pom.xml` 的 `drools.version`) |
|
||||
| 注释规范(Java/DRL) | 与 requirements 一致:**禁止行尾注释**;类/公开 API 用 `/** */`;字段与函数体内用 `//` |
|
||||
| 不参与匹配 | `ScenarioBase`、`Options`;`taskName`、`Groups`;任务开始/结束时间 |
|
||||
| 允许 | 红方武器不足以覆盖蓝方;红方任务部分字段匹配不上则**保持空或原值** |
|
||||
|
||||
---
|
||||
|
||||
## 2. JSON 结构参考(实现时的路径依据)
|
||||
|
||||
根路径:`MilitaryScenario`(注意:样例文件在部分 key 后带有 `// 注释`,**标准 Jackson 默认不能解析**。实现时三选一:① 调用方传标准 JSON;② 服务端先 **strip 行尾 `//...`** 再解析;③ 使用 `jackson-core` 自定义或第三方「带注释 JSON」解析。下文路径均指**去掉注释后的逻辑结构**。)
|
||||
|
||||
### 2.1 顶层键(与 `MilitaryScenario` 同级)
|
||||
|
||||
实现时至少关心:
|
||||
|
||||
```
|
||||
MilitaryScenario
|
||||
├── RefAttributeObject # Map:key=设备 refId(字符串),value=属性对象数组
|
||||
├── ForceSides # 数组:阵营
|
||||
├── Equipments # 数组:装备
|
||||
├── Tasks # 数组:任务(红+蓝+…)
|
||||
├── Environment # 可选,默认可不进规则
|
||||
├── ScenarioBase # 忽略
|
||||
└── Options # 忽略
|
||||
```
|
||||
|
||||
(若实际文件还有其它顶层字段,**原样透传**,不要删除。)
|
||||
|
||||
### 2.2 `ForceSides[]`(阵营表)
|
||||
|
||||
每条典型字段:
|
||||
|
||||
- `ObjectHandle`:阵营 UUID(字符串)
|
||||
- `ForceSideName`:如「红方」「蓝方」「白方」
|
||||
|
||||
**实现要点**:建立 `Map<String, String>`:`sideUuid -> sideName`,以及反向查询。红方 UUID 用于与 `Equipments.OwnerForceSide`、`task.task.sideId` 等比对。
|
||||
|
||||
### 2.3 `RefAttributeObject`(属性字典)
|
||||
|
||||
- 类型:对象,**子 key 为 refId**(与装备里 `device.refId`、`device.id` 等引用对齐)。
|
||||
- 值:数组,元素字段包括但不限于:`attDef`、`attDefaultValue`、`attExplain`、`attName`。
|
||||
|
||||
**实现要点**:不必把所有属性塞进 Drools。解析阶段可构建:
|
||||
|
||||
- `Map<String, Map<String, String>> refIdToAttDefValue`:仅保留规则会用到的 `attDef`(若未知则先存全量 **按 refId 分桶的 List**,但单桶过大时要按 attDef 过滤,避免 OOM)。
|
||||
|
||||
### 2.4 `Equipments[]`(装备)
|
||||
|
||||
典型字段:
|
||||
|
||||
- `OwnerForceSide`:所属阵营 UUID
|
||||
- `EquipmentID`:装备实例 id
|
||||
- `SupportType`、`Platform_type`、`Name` 等:用于类型与展示
|
||||
- `SubComponents`:对象,键如 `weapon`、`sensor`、`platform`、`jammer`、`communication` 等,值为**组件数组**
|
||||
|
||||
组件项常见字段:
|
||||
|
||||
- `ObjectHandle`、`deviceId`、`soleId`
|
||||
- `device`:`{ id, name, refId }`
|
||||
- `ParentPlat`:父平台 id
|
||||
- `platform` 类下可能有 `positions`:`[经度, 纬度, 高度]`
|
||||
|
||||
**实现要点**:为规则准备**红方装备摘要列表**(扁平结构,见第 5 节),不要 deep clone 整个 `SubComponents`。
|
||||
|
||||
### 2.5 `Tasks[]`(任务)
|
||||
|
||||
外层常见:
|
||||
|
||||
- `id`:任务 id
|
||||
- `side`:字符串,如「蓝方」(**以样例为准**)
|
||||
- `dataType`:如 `taskPlane`
|
||||
- `task`:内层大对象
|
||||
|
||||
内层 `task` 常见:
|
||||
|
||||
- `side`、`sideId`(阵营 UUID)
|
||||
- `type`:任务类型,如 `interference`、`assault`、`policePatrol`
|
||||
- `speed`:数值
|
||||
- `execute`:**数组**,每项含 `type` 及多种列表字段
|
||||
|
||||
`execute[]` 内常见列表(名称以样例为准):
|
||||
|
||||
- `targetList[]`:常含 `weaponId`、`targetId`、`ID`、以及若干战术字段
|
||||
- `disturbList[]`:干扰相关,可含 `weaponId`、`targetId`
|
||||
- 其它 `*List`:按任务类型存在与否不同
|
||||
|
||||
**红方识别**(实现逻辑,按优先级):
|
||||
|
||||
1. `task.task.sideId` 或外层推导的阵营 UUID **等于** 红方 `ForceSides.ObjectHandle`;或
|
||||
2. `task.side` / 外层 `side` 字符串等于「红方」(需与 `ForceSideName` 一致)。
|
||||
|
||||
**仅对识别为红方的任务**执行写回;蓝方任务只读,用于生成「对手事实」。
|
||||
|
||||
### 2.6 需求字段与样例缺失
|
||||
|
||||
| 需求字段 | 样例中状态 | 代码策略 |
|
||||
|----------|------------|----------|
|
||||
| `threatLevel` (1–3) | 未检索到 | Java 事实类保留 `Integer threatLevel`,默认 null;DRL 用 `threatLevel != null` Guard |
|
||||
| `warTerritory`、`airspaceType` | 未检索到 | 事实类预留 `String`/`Integer`;阵位规则文件先写注释骨架 |
|
||||
|
||||
---
|
||||
|
||||
## 3. 总体数据流(智能体实现顺序)
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
P1[预处理可选: 去注释]
|
||||
P2[第一遍流式: 建索引]
|
||||
P3[第二遍或同遍: 收集蓝方摘要 + 红方可写槽位]
|
||||
P4[组装 Drools 事实]
|
||||
P5[KieSession fireAllRules]
|
||||
P6[应用 Rule 输出到内存补丁结构]
|
||||
P7[写回 JSON: Tree 或 流式]
|
||||
P1 --> P2 --> P3 --> P4 --> P5 --> P6 --> P7
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. OOM 与解析策略(必须写进实现)
|
||||
|
||||
### 4.1 禁止
|
||||
|
||||
- 使用 `ObjectMapper.readTree(整个 InputStream)` 默认把 1.3MB+ 全树常驻且复制多份。
|
||||
- `insertAll(全部 Equipment)`、`insertAll(全部 Task)` 进入 KieSession。
|
||||
- 无界 `String` 拼接整文件多次。
|
||||
|
||||
### 4.2 推荐
|
||||
|
||||
1. **Jackson `JsonParser` + `JsonToken`** 顺序扫描;仅当 `currentName` 属于目标段时深入读取。
|
||||
2. **分块构建索引**:`RefAttributeObject`、`ForceSides`、`Equipments` 各用 `Map` / 紧凑 DTO 列表;数字与字符串优先,避免嵌套 `Map` 过深。
|
||||
3. **Tasks**:流式读数组,每元素解析为「任务摘要对象」或**仅红方**保留完整 `task` 子树的 **JsonNode 引用**(若采用 DOM 则只保留红方子树,蓝方只保留摘要)。
|
||||
4. **写回**:
|
||||
- **方案 A(推荐起步)**:第一遍用流式解析 + 若内存允许用 `JsonNode` 仅替换 `Tasks` 下红方节点(需评估内存);
|
||||
- **方案 B**:两遍文件:第一遍偏移量/路径索引,第二遍 `JsonGenerator` 复制并覆盖红方字段。
|
||||
|
||||
智能体实现时可先 **方案 A + 设置 Jackson 流式配置**,在压测后再切方案 B。
|
||||
|
||||
### 4.3 Drools 工作内存
|
||||
|
||||
- 单次 `fireAllRules` 前插入事实数建议:**O(蓝方任务数 + 红方候选装备数 + 红方待填槽位数)**,每项为**小对象**(< 1KB 量级为宜)。
|
||||
- 规则执行完后 **`dispose()`** KieSession,避免泄漏。
|
||||
|
||||
---
|
||||
|
||||
## 5. Java 侧建议类型(包名可按项目调整)
|
||||
|
||||
建议包:`com.solution.rule.firepower`(或沿用 `com.solution.rule` 下子包),避免与旧 `WarplaneHandler` 混在同一责任链。
|
||||
|
||||
### 5.1 索引与上下文(非 Drools Fact,解析阶段使用)
|
||||
|
||||
| 类名(建议) | 职责 |
|
||||
|--------------|------|
|
||||
| `ScenarioIndexes` | 持有 `sideIdToName`、`redSideId`、`blueSideId`(可多蓝多红时扩展为 Set)、`refAttributes` 精简索引 |
|
||||
| `EquipmentSummary` | 单条红方可用装备:`equipmentId`、`ownerSideId`、`platformType`、`weaponComponentIds`(List<String>)、可选 `positionLonLatAlt` |
|
||||
| `BlueTaskFact` | 单条蓝方任务摘要:`taskId`、`taskType`、`speed`、`sideId`、从 `execute` 抽出的 **打击/干扰目标 id 列表**、**航迹摘要**(见下) |
|
||||
| `TrackSummary` | 可选:`routeId` 或关键点 `List<double[]>`(经纬高),从蓝方编队/平台关联推导(若样例中路径复杂,第一版可只填 `speed` + 单点位置) |
|
||||
| `RedTaskFillSlot` | 描述一处待填写位置:`taskId`、`executeIndex`、`listName`(如 `targetList`)、`itemIndex`、指向 Map 或 JsonNode 的**可变引用**(或用 `Consumer` 写回) |
|
||||
|
||||
### 5.2 Drools 事实(插入 KieSession)
|
||||
|
||||
| 类名(建议) | 说明 |
|
||||
|--------------|------|
|
||||
| `OpponentContext` | 当前正在处理的蓝方任务/目标封装(可多条规则共享) |
|
||||
| `RedInventory` | 红方可用武器/装备 id 及剩余数量(数量规则 3.1 用) |
|
||||
| `MatchResult` | 规则填写结果:`selectedWeaponId`、`targetId`、`reasonCode`(便于日志) |
|
||||
| `ThreatContext` | 预留 `Integer threatLevel` |
|
||||
| `PositionContext` | 预留防区/作战区相关字段 |
|
||||
|
||||
事实类使用 **可修改 JavaBean**(Drools 7 常用),在规则中 `modify()` 或 **通过全局服务**写回 `RedTaskFillSlot`(若用全局服务,需 `KieSession.setGlobal(...)`)。
|
||||
|
||||
### 5.3 规则与 Java 交互方式(二选一,文档推荐前者)
|
||||
|
||||
1. **纯规则修改 Fact**:`MatchResult` 填好后,Java 在 `fireAllRules` 后遍历 Fact 应用到 JSON。
|
||||
2. **全局写回器**:`globals.put("fillService", bean)`,drl 中调用 `fillService.apply(...)`(需在 drl 声明 `import` 与 `global`)。
|
||||
|
||||
智能体选一种即可,**全项目统一**。
|
||||
|
||||
---
|
||||
|
||||
## 6. Drools 规则文件组织
|
||||
|
||||
目录:[`auto-solution-rule/src/main/resources/rules/`](auto-solution-rule/src/main/resources/rules/)(以实际 `DroolsConfig` 的 `classpath*:rules/*.*` 为准)。
|
||||
|
||||
| 文件 | package 建议 | 内容 |
|
||||
|------|----------------|------|
|
||||
| `fire-package.drl` | `rules.fire` | 仅 `package`、`import`、**中文块注释说明修改须知** |
|
||||
| `fire-task-type.drl` | 同上 | `task.type`:干扰 vs 打击 vs 巡逻等分支;salience 最高或单独 agenda-group `task-type` |
|
||||
| `fire-equipment-match.drl` | 同上 | 装备类型、数量 ≥ 蓝方、`weaponId`/`targetId` 绑定;引用 `RedInventory` |
|
||||
| `fire-position.drl` | 同上 | 阵位:预留条件,注释写「待 warTerritory/airspaceType 路径确认」 |
|
||||
| `fire-track.drl` | 同上 | 航迹:高度、速度、航向、经纬高;注释说明可调参数 |
|
||||
| `fire-fallback.drl` | 同上 | 无匹配时的默认策略或显式「不填写」 |
|
||||
|
||||
**删除或覆盖**无效的 [`fire-rule.drl`](auto-solution-rule/src/main/resources/rules/fire-rule.drl) 占位内容,保证 `KieBuilder` 能 `buildAll()` 成功。
|
||||
|
||||
**Salience 建议**(数值越大越先执行,按项目再调):
|
||||
|
||||
- 任务类型分支:100
|
||||
- 装备匹配:80
|
||||
- 阵位:60
|
||||
- 航迹:40
|
||||
- 兜底:-10
|
||||
|
||||
**agenda-group**(可选):`task-type` → `equipment` → `position` → `track`,Java 中按序 `getAgenda().getAgendaGroup("xxx").setFocus()`。
|
||||
|
||||
---
|
||||
|
||||
## 7. 规则与需求章节映射(DRL 注释必须写清)
|
||||
|
||||
| requirements 章节 | DRL 落点 | 注释必须说明 |
|
||||
|-------------------|----------|--------------|
|
||||
| 3.1 装备匹配 | `fire-equipment-match.drl` | 依据哪些 Fact 字段;如何改「优先级」 |
|
||||
| 3.2 阵位 | `fire-position.drl` | 红方防区/作战区判定条件(占位) |
|
||||
| 3.3 航迹 | `fire-track.drl` | 最短距离/绕后等可选策略的切换方式 |
|
||||
| 3.4 任务类型(干扰↔反干扰) | `fire-task-type.drl` | 与 3.1 的差异 |
|
||||
| 3.5 贴合实际、不考虑时间 | 各文件 | 不写时间条件 |
|
||||
|
||||
---
|
||||
|
||||
## 8. 解析算法伪代码(供智能体翻译为 Java)
|
||||
|
||||
```
|
||||
function process(inputStream) -> OutputStream:
|
||||
bytesOrReader = optionalStripJsonComments(inputStream) // 若需要
|
||||
|
||||
indexes = new ScenarioIndexes()
|
||||
blueFacts = new ArrayList<BlueTaskFact>()
|
||||
redSlots = new ArrayList<RedTaskFillSlot>()
|
||||
redEquipSummaries = new ArrayList<EquipmentSummary>()
|
||||
|
||||
parser = JsonFactory.createParser(bytesOrReader)
|
||||
while parser.nextToken() != END_OBJECT:
|
||||
if field == "RefAttributeObject":
|
||||
indexes.refAttributes = parseRefAttributeObjectStream(parser)
|
||||
else if field == "ForceSides":
|
||||
indexes.parseForceSides(parser) // 设置 redSideId / blueSideId
|
||||
else if field == "Equipments":
|
||||
for each equipment object in stream:
|
||||
if owner == indexes.redSideId:
|
||||
redEquipSummaries.add(summarize(equipment))
|
||||
else if field == "Tasks":
|
||||
for each task object in stream:
|
||||
if isRedTask(task, indexes):
|
||||
redSlots.addAll(collectFillSlots(task)) // 只记录需规则填的槽位
|
||||
else if isBlueTask(task, indexes):
|
||||
blueFacts.add(summarizeBlue(task))
|
||||
|
||||
session = kieBase.newKieSession()
|
||||
try:
|
||||
session.insert(new RedInventory(redEquipSummaries))
|
||||
for b : blueFacts: session.insert(b)
|
||||
for slot : redSlots: session.insert(slot)
|
||||
// globals if needed
|
||||
session.fireAllRules()
|
||||
applyFactsToJson(modelOrPatches)
|
||||
finally:
|
||||
session.dispose()
|
||||
|
||||
return serialize(modelOrPatches)
|
||||
```
|
||||
|
||||
`collectFillSlots`:遍历 `task.execute[*]` 下各 `*List`,对 `weaponId`/`targetId` 为空且业务约定需要填的项注册 `RedTaskFillSlot`(第一版可只处理 `targetList`)。
|
||||
|
||||
---
|
||||
|
||||
## 9. Spring 接口层建议
|
||||
|
||||
- **Controller**(可放在 `auto-solution-admin` 或独立 API 模块):
|
||||
- `POST /api/firepower/plan`(路径自定)
|
||||
- `Content-Type: application/json`
|
||||
- 方法参数:`HttpServletRequest.getInputStream()` 或 `InputStreamResource`,**不要** `@RequestBody String` 若可避免。
|
||||
- **Service**:`FirepowerRuleService#apply(InputStream in, OutputStream out)`,异常包装为业务码,**不要吞掉栈**。
|
||||
|
||||
---
|
||||
|
||||
## 10. 与现有模块的衔接(避免冲突)
|
||||
|
||||
| 文件/类 | 动作 |
|
||||
|---------|------|
|
||||
| [`DroolsConfig`](auto-solution-rule/src/main/java/com/solution/rule/config/DroolsConfig.java) | 保持;新增 drl 放入 `rules/` |
|
||||
| [`JsonStreamParser`](auto-solution-rule/src/main/java/com/solution/rule/parser/JsonStreamParser.java) | 重写或新建 `MilitaryScenarioStreamParser`,与注释中假数据结构脱钩 |
|
||||
| `TaskJsonDTO` 等 | 与样例不一致时:**以样例为准** 新建 `firepower` 包 DTO,或 `JsonNode` |
|
||||
| [`WarplaneHandler`](auto-solution-rule/src/main/java/com/solution/rule/handler/WarplaneHandler.java) | **不要**强行合并;新链路独立 Bean |
|
||||
|
||||
---
|
||||
|
||||
## 11. 测试与验收(智能体应补充用例)
|
||||
|
||||
1. **单元测试**:`MilitaryScenarioStreamParser` 对**小样本 JSON**(截取 `Tasks` 一条 + `ForceSides` + 一条 `Equipments`)解析结果符合预期索引。
|
||||
2. **规则测试**:使用 Drools `KieSessionTest` 或 JUnit 手动 `insert` 事实,断言 `MatchResult`。
|
||||
3. **集成测试**:完整样例文件跑通不 OOM(JVM `-Xmx` 限制下观察);输出 JSON **除红方任务外字节级或键序**尽量一致(键序若难一致,至少结构等价)。
|
||||
|
||||
---
|
||||
|
||||
## 12. 实现检查清单(按顺序勾选)
|
||||
|
||||
1. [ ] 确定 JSON 注释处理策略并实现 `strip` 或约束调用方。
|
||||
2. [ ] 实现 `ScenarioIndexes` + 流式解析 `RefAttributeObject`、`ForceSides`、`Equipments`。
|
||||
3. [ ] 实现 `Tasks` 遍历 + 红/蓝识别 + `RedTaskFillSlot` 收集。
|
||||
4. [ ] 定义 Drools 事实类 + `kie-module` 可编译的 `fire-*.drl`。
|
||||
5. [ ] 实现 `FirepowerRuleService`:`newKieSession` → `insert` → `fireAllRules` → 应用结果。
|
||||
6. [ ] 实现写回:JsonNode 或流式生成。
|
||||
7. [ ] Controller + 集成测试 + 日志(规则命中原因)。
|
||||
|
||||
---
|
||||
|
||||
## 13. 修订记录
|
||||
|
||||
| 日期 | 说明 |
|
||||
|------|------|
|
||||
| 2026-03-26 | 初稿 |
|
||||
| 2026-03-26 | 详细版:路径说明、类设计、伪代码、DRL 分层、检查清单、测试要求 |
|
||||
202
t.txt
Normal file
202
t.txt
Normal file
@@ -0,0 +1,202 @@
|
||||
"Tasks": [
|
||||
{
|
||||
"color": "rgb(220,39,39)",
|
||||
"dataType": "taskPlane",
|
||||
"drawName": "xxx随队干扰任务",
|
||||
"editPermission": [
|
||||
"edits",
|
||||
"noHidden",
|
||||
"noGroups",
|
||||
"del",
|
||||
"downLoad"
|
||||
],
|
||||
"groupType": "tasks",
|
||||
"id": "0614808c-6621-40a0-b254-d13d2959fc19",
|
||||
"idKey": "id",
|
||||
"isSelected": false,
|
||||
"name": "xxx随队干扰任务",
|
||||
"parentId": "56a96b1b-14a8-4daf-a2d0-47c7faa4b831_taskPlane",
|
||||
"permission": [
|
||||
"14bc8ff9-3c93-4218-b01a-e144add196f9",
|
||||
"56a96b1b-14a8-4daf-a2d0-47c7faa4b831"
|
||||
],
|
||||
"show": true,
|
||||
"side": "红方",
|
||||
"sort": 1774271360496,
|
||||
"task": {
|
||||
"at_time": 0,
|
||||
"attackId": "b4256ee6-50a6-4bd0-a358-eb1e772a8e3f",
|
||||
"color": "rgb(220,39,39)",
|
||||
"departureAirport": "",
|
||||
"execute": [
|
||||
{
|
||||
"disturbList": [
|
||||
{
|
||||
"arrayPositionId": "",
|
||||
"at_time": "1200",
|
||||
"deceiveType": "",
|
||||
"decoyLen": "",
|
||||
"decoyNum": "",
|
||||
"disturbPos": [],
|
||||
"disturbStrength": "100",
|
||||
"disturbStyle": [
|
||||
"0"
|
||||
],
|
||||
"disturbTime": "1",
|
||||
"disturbTimes": [],
|
||||
"dragAcceleSpeed": "",
|
||||
"dragSpeed": "",
|
||||
"dragTime": "",
|
||||
"endTime": "2000",
|
||||
"followFormation": "",
|
||||
"groupId": "d5aa0dc8-8baa-4d3b-9eb6-a268c5da7633",
|
||||
"interferTargetList": [
|
||||
"xxx车__933e3796-792f-41f7-ac96-70174c9c24af__b52c23cb-80a5-408d-9868-2ae2a3db5187"
|
||||
],
|
||||
"keepTime": "",
|
||||
"podPosition": "",
|
||||
"routeId": "",
|
||||
"stopTime": "",
|
||||
"targetId": "",
|
||||
"weaponId": "",
|
||||
"weaponType": ""
|
||||
}
|
||||
],
|
||||
"droneSwarmList": [
|
||||
{
|
||||
"ID": "32a86eed-5f14-43ed-95e0-0bb111ef2602",
|
||||
"at_time": "",
|
||||
"decoyNum": "",
|
||||
"disturbNum": "",
|
||||
"droneNum": "",
|
||||
"dropPosition": "",
|
||||
"hitNum": "",
|
||||
"load": "",
|
||||
"targetId": "",
|
||||
"weaponId": "",
|
||||
"weaponType": ""
|
||||
}
|
||||
],
|
||||
"earlyWaringList": [
|
||||
{
|
||||
"PositionRouteId": "",
|
||||
"arrayPositionId": "",
|
||||
"at_time": "",
|
||||
"earlyWarTactics": "",
|
||||
"endTime": ""
|
||||
}
|
||||
],
|
||||
"floatAirList": [
|
||||
{
|
||||
"Direction": "",
|
||||
"FlySpeed": "",
|
||||
"at_time": "",
|
||||
"load": ""
|
||||
}
|
||||
],
|
||||
"moveRouteId": "",
|
||||
"netAttackList": [
|
||||
{
|
||||
"arrayPositionId": "",
|
||||
"at_time": "",
|
||||
"endTime": "",
|
||||
"node": ""
|
||||
}
|
||||
],
|
||||
"patrolList": [
|
||||
{
|
||||
"PositionRouteId": "",
|
||||
"arrayPositionId": "",
|
||||
"endTime": "",
|
||||
"patrolRules": "",
|
||||
"patrolTeams": "",
|
||||
"startTime": ""
|
||||
}
|
||||
],
|
||||
"refulList": [
|
||||
{
|
||||
"arrayPositionId": "",
|
||||
"at_time": "",
|
||||
"fulHeight": "",
|
||||
"hangTime": "",
|
||||
"hangTimeH": "",
|
||||
"refulRule": "",
|
||||
"targetId": ""
|
||||
}
|
||||
],
|
||||
"spyonList": [
|
||||
{
|
||||
"PositionRouteId": "",
|
||||
"arrayPositionId": "",
|
||||
"at_time": "",
|
||||
"endTime": "",
|
||||
"spyonArea": "",
|
||||
"spyonTactics": "",
|
||||
"spyonTeams": ""
|
||||
}
|
||||
],
|
||||
"targetList": [
|
||||
{
|
||||
"ID": "b3515b7e-bc28-47f5-8be5-1cab0e25097e",
|
||||
"arrayPositionId": "",
|
||||
"arrayPositionIdBak": "",
|
||||
"at_time": {
|
||||
"timeUp": true,
|
||||
"value": 0
|
||||
},
|
||||
"attackType": "",
|
||||
"boost": "",
|
||||
"bootTime": "",
|
||||
"companion": "",
|
||||
"cruiseRouteId": "",
|
||||
"cruiseRouteOffset": [
|
||||
{
|
||||
"UpOrDown": true,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"BeforeOrAfter": true,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"LeftOrRight": true,
|
||||
"value": 0
|
||||
}
|
||||
],
|
||||
"decoyNum": "0",
|
||||
"decoyTime": "0",
|
||||
"disturbNum": "0",
|
||||
"disturbStartTime": "0",
|
||||
"droneNum": "",
|
||||
"fireType": "absolute",
|
||||
"hitNum": "",
|
||||
"launchAngle": "",
|
||||
"launchAzimuth": "",
|
||||
"noFlyZone": "",
|
||||
"orbitInclination": "",
|
||||
"refulId": "",
|
||||
"salvo": {
|
||||
"salvoUp": true,
|
||||
"value": 0
|
||||
},
|
||||
"strategy": [],
|
||||
"targetId": "",
|
||||
"times_interval": 1,
|
||||
"weaponId": "",
|
||||
"weaponRelease": "",
|
||||
"weaponType": "",
|
||||
"weaponUseCount": 1
|
||||
}
|
||||
],
|
||||
"type": "interference"
|
||||
}
|
||||
],
|
||||
"landAirport": "",
|
||||
"missionList": [],
|
||||
"name": "xxx随队干扰任务",
|
||||
"side": "红方",
|
||||
"sideId": "56a96b1b-14a8-4daf-a2d0-47c7faa4b831",
|
||||
"speed": 600,
|
||||
"type": "interference",
|
||||
"weaponId": ""
|
||||
},
|
||||
20229
区域防御场景设计_2026-01-14 11_49_10_带注释.json
Normal file
20229
区域防御场景设计_2026-01-14 11_49_10_带注释.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user