Compare commits
1 Commits
8b3fe9b548
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 956d3f69ea |
@@ -70,6 +70,12 @@
|
|||||||
<groupId>com.solution</groupId>
|
<groupId>com.solution</groupId>
|
||||||
<artifactId>solution-algo</artifactId>
|
<artifactId>solution-algo</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.solution</groupId>
|
||||||
|
<artifactId>solution-rule</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
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.dto.RequestDTO;
|
||||||
|
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||||
|
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||||
|
import com.solution.rule.service.RuleService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Api("火力规则")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/system/firerule")
|
||||||
|
public class RuleController extends BaseController {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RuleService ruleService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始执行规则匹配
|
||||||
|
* @param sceneType 场景参数
|
||||||
|
* @param weaponModelDTO 敌方参数
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/start")
|
||||||
|
@ApiOperation("开始执行规则匹配")
|
||||||
|
public AjaxResult execute(Integer sceneType, WeaponModelDTO weaponModelDTO){
|
||||||
|
return success(ruleService.execute(sceneType,weaponModelDTO));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有武器平台和组件
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/weapon")
|
||||||
|
@ApiOperation("获取所有武器平台和组件")
|
||||||
|
public AjaxResult getPlatformComponentNames(){
|
||||||
|
return success(ruleService.getPlatformComponentNames());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,9 +6,11 @@ spring:
|
|||||||
druid:
|
druid:
|
||||||
# 主库数据源
|
# 主库数据源
|
||||||
master:
|
master:
|
||||||
url: jdbc:mysql://192.168.166.71:3306/behaviortreedb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
# url: jdbc:mysql://192.168.166.71:3306/behaviortreedb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
|
url: jdbc:mysql://localhost:3306/autosolution_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
username: root
|
username: root
|
||||||
password: 123456
|
# password: 123456
|
||||||
|
password: 1234
|
||||||
# 从库数据源
|
# 从库数据源
|
||||||
slave:
|
slave:
|
||||||
# 从数据源开关/默认关闭
|
# 从数据源开关/默认关闭
|
||||||
|
|||||||
@@ -67,13 +67,15 @@ spring:
|
|||||||
# redis 配置
|
# redis 配置
|
||||||
redis:
|
redis:
|
||||||
# 地址
|
# 地址
|
||||||
host: 192.168.166.71
|
# host: 192.168.166.71
|
||||||
|
host: 127.0.0.1
|
||||||
# 端口,默认为6379
|
# 端口,默认为6379
|
||||||
port: 6379
|
port: 6379
|
||||||
# 数据库索引
|
# 数据库索引
|
||||||
database: 0
|
database: 0
|
||||||
# 密码
|
# 密码
|
||||||
password:
|
# password:
|
||||||
|
password: 123456
|
||||||
# 连接超时时间
|
# 连接超时时间
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
lettuce:
|
lettuce:
|
||||||
@@ -104,6 +106,8 @@ mybatis:
|
|||||||
mapperLocations: classpath*:mapper/**/*Mapper.xml
|
mapperLocations: classpath*:mapper/**/*Mapper.xml
|
||||||
# 加载全局的配置文件
|
# 加载全局的配置文件
|
||||||
configLocation: classpath:mybatis/mybatis-config.xml
|
configLocation: classpath:mybatis/mybatis-config.xml
|
||||||
|
configuration:
|
||||||
|
map-underscore-to-camel-case: true
|
||||||
|
|
||||||
# PageHelper分页插件
|
# PageHelper分页插件
|
||||||
pagehelper:
|
pagehelper:
|
||||||
|
|||||||
@@ -113,6 +113,12 @@
|
|||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.8.25</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.solution.common.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 火力规则常量
|
||||||
|
*/
|
||||||
|
public class ExceptionConstants {
|
||||||
|
|
||||||
|
public static final String PARAMETER_EXCEPTION = "参数异常";
|
||||||
|
|
||||||
|
public static final String RESULT_EXCEPTION = "结果异常";
|
||||||
|
|
||||||
|
public static final String NOT_FOUND_CARRIAGE_CHAIN_HANDLER = "not found carriage chain handler!";
|
||||||
|
|
||||||
|
public static final String NOT_FOUND_F22_COMPONENT = "未找到 F-22 组件";
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.solution.common.constant;
|
||||||
|
|
||||||
|
|
||||||
|
public class PlatformAndModuleConstants {
|
||||||
|
|
||||||
|
public static final String F22 = "f22";
|
||||||
|
}
|
||||||
8
pom.xml
8
pom.xml
@@ -231,6 +231,13 @@
|
|||||||
<version>${solution.version}</version>
|
<version>${solution.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 规则模块-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.solution</groupId>
|
||||||
|
<artifactId>solution-rule</artifactId>
|
||||||
|
<version>${solution.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
@@ -244,6 +251,7 @@
|
|||||||
<module>auto-solution-quartz</module>
|
<module>auto-solution-quartz</module>
|
||||||
<module>auto-solution-generator</module>
|
<module>auto-solution-generator</module>
|
||||||
<module>auto-solution-common</module>
|
<module>auto-solution-common</module>
|
||||||
|
<module>solution-rule</module>
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
|||||||
39
solution-rule/pom.xml
Normal file
39
solution-rule/pom.xml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>solution</artifactId>
|
||||||
|
<groupId>com.solution</groupId>
|
||||||
|
<version>3.9.1</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>solution-rule</artifactId>
|
||||||
|
|
||||||
|
<description>
|
||||||
|
rule模块
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- 通用工具-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.solution</groupId>
|
||||||
|
<artifactId>solution-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.solution.rule.domain;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 平台挂载的组件实体类
|
||||||
|
* 对应表 platform_component
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ApiModel(value = "平台组件对象", description = "平台所挂载的武器、雷达、通信等组件")
|
||||||
|
public class PlatformComponent {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "组件ID,主键自增")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "组件名称(具体型号)")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "组件类型:weapon(武器)、radar(雷达)、comm(通信)")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "组件描述信息")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "所属平台ID,关联platform表")
|
||||||
|
private Integer platformId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "组件数量")
|
||||||
|
private Long num;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.solution.rule.domain;
|
||||||
|
|
||||||
|
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||||
|
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class RuleParam {
|
||||||
|
|
||||||
|
private WeaponModelVO weaponModelVO;
|
||||||
|
|
||||||
|
private WeaponModelDTO weaponModelDTO;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
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,23 @@
|
|||||||
|
package com.solution.rule.domain.dto;
|
||||||
|
|
||||||
|
import com.solution.rule.domain.PlatformComponent;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WeaponModelDTO {
|
||||||
|
|
||||||
|
@ApiModelProperty("平台id")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ApiModelProperty("平台名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty("平台描述")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@ApiModelProperty("平台组件")
|
||||||
|
private List<PlatformComponent> components;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.solution.rule.domain.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
// 组件计数VO
|
||||||
|
@Data
|
||||||
|
@ApiModel("组件计数信息")
|
||||||
|
public class ComponentCountVO {
|
||||||
|
@ApiModelProperty("组件名称")
|
||||||
|
private String componentName;
|
||||||
|
|
||||||
|
@ApiModelProperty("组件数量")
|
||||||
|
private Long count;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.solution.rule.domain.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiModel("平台组件名称聚合")
|
||||||
|
public class PlatformComponentNamesVO {
|
||||||
|
@ApiModelProperty("平台名称")
|
||||||
|
private String platformName;
|
||||||
|
|
||||||
|
@ApiModelProperty("该平台下的组件名称列表(去重)")
|
||||||
|
private List<String> componentNames;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.solution.rule.domain.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
// 平台武器聚合VO
|
||||||
|
@Data
|
||||||
|
@ApiModel("平台武器聚合信息")
|
||||||
|
public class PlatformWeaponAggregateVO {
|
||||||
|
@ApiModelProperty("平台名称")
|
||||||
|
private String platformName;
|
||||||
|
|
||||||
|
@ApiModelProperty("该平台下的组件列表")
|
||||||
|
private List<ComponentCountVO> components;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.solution.rule.domain.vo;
|
||||||
|
|
||||||
|
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WeaponModelVO {
|
||||||
|
|
||||||
|
@ApiModelProperty("平台名称")
|
||||||
|
private String platformName;
|
||||||
|
|
||||||
|
@ApiModelProperty("组件名称")
|
||||||
|
private String componentName;
|
||||||
|
|
||||||
|
@ApiModelProperty("组件数量")
|
||||||
|
private Long count;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.solution.rule.enums;
|
||||||
|
|
||||||
|
public enum SceneType {
|
||||||
|
|
||||||
|
DEFENSE(0, "防御"),
|
||||||
|
AIRBORNE(1, "空降");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
SceneType(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 SceneType fromCode(int code) {
|
||||||
|
for (SceneType type : values()) {
|
||||||
|
if (type.code == code) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("未知的场景类型编码: " + code);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.solution.rule.handler;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.solution.rule.domain.RuleParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 规则链抽象类
|
||||||
|
*/
|
||||||
|
public abstract class AbstractRuleChainHandler {
|
||||||
|
|
||||||
|
|
||||||
|
private AbstractRuleChainHandler nextHandler;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行过滤方法
|
||||||
|
* @param ruleParam
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract RuleParam doHandler(RuleParam ruleParam);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行下一个处理器
|
||||||
|
* @param ruleParam
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public RuleParam doNextHandler(RuleParam ruleParam){
|
||||||
|
if(ObjectUtil.isEmpty(nextHandler) || ObjectUtil.isNotEmpty(ruleParam)){
|
||||||
|
return ruleParam;
|
||||||
|
}
|
||||||
|
return nextHandler.doHandler(ruleParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置下游handler
|
||||||
|
* @param nextHandler
|
||||||
|
*/
|
||||||
|
public void setNextHandler(AbstractRuleChainHandler nextHandler) {
|
||||||
|
this.nextHandler = nextHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.solution.rule.handler;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.solution.common.constant.ExceptionConstants;
|
||||||
|
import com.solution.rule.domain.RuleParam;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 封装规则处理链
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class RuleChainHandler {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private List<AbstractRuleChainHandler> chainHandlers;
|
||||||
|
|
||||||
|
private AbstractRuleChainHandler firstHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组装处理链
|
||||||
|
*/
|
||||||
|
@PostConstruct
|
||||||
|
private void constructChain(){
|
||||||
|
if (CollUtil.isEmpty(chainHandlers)) {
|
||||||
|
throw new RuntimeException(ExceptionConstants.NOT_FOUND_CARRIAGE_CHAIN_HANDLER);
|
||||||
|
}
|
||||||
|
this.firstHandler = chainHandlers.get(0);
|
||||||
|
for (int i = 0; i < chainHandlers.size(); i++) {
|
||||||
|
if(i == (chainHandlers.size() - 1)){
|
||||||
|
chainHandlers.get(i).setNextHandler(null);
|
||||||
|
}else {
|
||||||
|
chainHandlers.get(i).setNextHandler(chainHandlers.get(i + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public RuleParam findRuleParam(RuleParam ruleParam){
|
||||||
|
return firstHandler.doHandler(ruleParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.solution.rule.handler;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.solution.common.constant.ExceptionConstants;
|
||||||
|
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.domain.vo.WeaponModelVO;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 战斗机处理链
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class WarplaneHandler extends AbstractRuleChainHandler{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RuleParam doHandler(RuleParam ruleParam) {
|
||||||
|
if(ObjectUtil.isEmpty(ruleParam) || ObjectUtil.isEmpty(ruleParam.getWeaponModelDTO())){
|
||||||
|
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
|
||||||
|
}
|
||||||
|
WeaponModelDTO weaponModelDTO = ruleParam.getWeaponModelDTO();
|
||||||
|
List<PlatformComponent> platformComponents = weaponModelDTO.getComponents().stream()
|
||||||
|
.filter(component -> PlatformAndModuleConstants.F22.equals(component.getName()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollUtil.isEmpty(platformComponents)) {
|
||||||
|
throw new RuntimeException(ExceptionConstants.NOT_FOUND_F22_COMPONENT);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.solution.rule.mapper;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ModelDetailMapper {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.solution.rule.mapper;
|
||||||
|
|
||||||
|
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||||
|
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface RuleMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有武器平台和组件
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<WeaponModelVO> getWeapon();
|
||||||
|
|
||||||
|
List<WeaponModelVO> getPlatformComponentNames();
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.solution.rule.service;
|
||||||
|
|
||||||
|
import com.solution.rule.domain.dto.RequestDTO;
|
||||||
|
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||||
|
import com.solution.rule.domain.vo.PlatformComponentNamesVO;
|
||||||
|
import com.solution.rule.domain.vo.PlatformWeaponAggregateVO;
|
||||||
|
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface RuleService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始执行规则匹配
|
||||||
|
* @param sceneType
|
||||||
|
* @param weaponModelDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
WeaponModelVO execute(Integer sceneType, WeaponModelDTO weaponModelDTO);
|
||||||
|
|
||||||
|
List<PlatformWeaponAggregateVO> getWeapon();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有武器平台和组件
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<PlatformComponentNamesVO> getPlatformComponentNames();
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package com.solution.rule.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.solution.common.constant.ExceptionConstants;
|
||||||
|
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||||
|
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.RuleMapper;
|
||||||
|
import com.solution.rule.service.RuleService;
|
||||||
|
import com.solution.rule.strategy.SceneStrategy;
|
||||||
|
import com.solution.rule.strategy.SceneStrategyFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RuleServiceImpl implements RuleService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SceneStrategyFactory strategyFactory;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RuleMapper ruleMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WeaponModelVO execute(Integer sceneType, WeaponModelDTO weaponModelDTO) {
|
||||||
|
if(ObjectUtil.isNull(sceneType) || ObjectUtil.isEmpty(weaponModelDTO)){
|
||||||
|
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
|
||||||
|
}
|
||||||
|
//TODO 查数据库获取我方装备
|
||||||
|
List<PlatformWeaponAggregateVO> weapon = this.getWeapon();
|
||||||
|
|
||||||
|
SceneStrategy strategy = strategyFactory.getStrategy(sceneType);
|
||||||
|
WeaponModelVO result = strategy.execute(weaponModelDTO);
|
||||||
|
if(ObjectUtil.isEmpty(result)){
|
||||||
|
throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PlatformWeaponAggregateVO> getWeapon() {
|
||||||
|
List<WeaponModelVO> flatList = ruleMapper.getWeapon();
|
||||||
|
if (CollUtil.isEmpty(flatList)) {
|
||||||
|
throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, List<WeaponModelVO>> groupByPlatform = flatList.stream()
|
||||||
|
.collect(Collectors.groupingBy(WeaponModelVO::getPlatformName));
|
||||||
|
|
||||||
|
List<PlatformWeaponAggregateVO> result = new ArrayList<>();
|
||||||
|
for (Map.Entry<String, List<WeaponModelVO>> entry : groupByPlatform.entrySet()) {
|
||||||
|
PlatformWeaponAggregateVO platformVO = new PlatformWeaponAggregateVO();
|
||||||
|
platformVO.setPlatformName(entry.getKey());
|
||||||
|
|
||||||
|
List<ComponentCountVO> components = entry.getValue().stream()
|
||||||
|
.map(item -> {
|
||||||
|
ComponentCountVO comp = new ComponentCountVO();
|
||||||
|
comp.setComponentName(item.getComponentName());
|
||||||
|
comp.setCount(item.getCount());
|
||||||
|
return comp;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
platformVO.setComponents(components);
|
||||||
|
|
||||||
|
result.add(platformVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有武器平台和组件
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<PlatformComponentNamesVO> getPlatformComponentNames() {
|
||||||
|
List<WeaponModelVO> flatList = ruleMapper.getPlatformComponentNames();
|
||||||
|
if (CollUtil.isEmpty(flatList)) {
|
||||||
|
throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, List<String>> groupByPlatform = flatList.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
WeaponModelVO::getPlatformName,
|
||||||
|
Collectors.mapping(WeaponModelVO::getComponentName, Collectors.toList())
|
||||||
|
));
|
||||||
|
|
||||||
|
return groupByPlatform.entrySet().stream()
|
||||||
|
.map(entry -> {
|
||||||
|
PlatformComponentNamesVO vo = new PlatformComponentNamesVO();
|
||||||
|
vo.setPlatformName(entry.getKey());
|
||||||
|
vo.setComponentNames(entry.getValue());
|
||||||
|
return vo;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.solution.rule.strategy;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.solution.common.constant.ExceptionConstants;
|
||||||
|
import com.solution.rule.domain.RuleParam;
|
||||||
|
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||||
|
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||||
|
import com.solution.rule.enums.SceneType;
|
||||||
|
import com.solution.rule.handler.RuleChainHandler;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class AirborneStrategy implements SceneStrategy{
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RuleChainHandler ruleChainHandler;
|
||||||
|
/**
|
||||||
|
* 空降场景处理
|
||||||
|
* @param weaponModelDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public WeaponModelVO execute(WeaponModelDTO weaponModelDTO) {
|
||||||
|
if(ObjectUtil.isEmpty(weaponModelDTO)){
|
||||||
|
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
|
||||||
|
}
|
||||||
|
RuleParam ruleParam = new RuleParam();
|
||||||
|
ruleParam.setWeaponModelDTO(weaponModelDTO);
|
||||||
|
ruleParam = ruleChainHandler.findRuleParam(ruleParam);
|
||||||
|
if(ObjectUtil.isEmpty(ruleParam.getWeaponModelVO())){
|
||||||
|
throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION);
|
||||||
|
}
|
||||||
|
return ruleParam.getWeaponModelVO();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SceneType getSceneType() {
|
||||||
|
return SceneType.AIRBORNE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.solution.rule.strategy;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.solution.common.constant.ExceptionConstants;
|
||||||
|
import com.solution.rule.domain.RuleParam;
|
||||||
|
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||||
|
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||||
|
import com.solution.rule.enums.SceneType;
|
||||||
|
import com.solution.rule.handler.RuleChainHandler;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DefenseStrategy implements SceneStrategy{
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RuleChainHandler ruleChainHandler;
|
||||||
|
/**
|
||||||
|
* 防御场景处理
|
||||||
|
* @param weaponModelDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public WeaponModelVO execute(WeaponModelDTO weaponModelDTO) {
|
||||||
|
if(ObjectUtil.isEmpty(weaponModelDTO)){
|
||||||
|
throw new RuntimeException(ExceptionConstants.PARAMETER_EXCEPTION);
|
||||||
|
}
|
||||||
|
RuleParam ruleParam = new RuleParam();
|
||||||
|
ruleParam.setWeaponModelDTO(weaponModelDTO);
|
||||||
|
ruleParam = ruleChainHandler.findRuleParam(ruleParam);
|
||||||
|
if(ObjectUtil.isEmpty(ruleParam.getWeaponModelVO())){
|
||||||
|
throw new RuntimeException(ExceptionConstants.RESULT_EXCEPTION);
|
||||||
|
}
|
||||||
|
return ruleParam.getWeaponModelVO();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SceneType getSceneType() {
|
||||||
|
return SceneType.DEFENSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.solution.rule.strategy;
|
||||||
|
|
||||||
|
import com.solution.rule.domain.dto.RequestDTO;
|
||||||
|
import com.solution.rule.domain.dto.WeaponModelDTO;
|
||||||
|
import com.solution.rule.domain.vo.WeaponModelVO;
|
||||||
|
import com.solution.rule.enums.SceneType;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public interface SceneStrategy {
|
||||||
|
|
||||||
|
WeaponModelVO execute(WeaponModelDTO weaponModelDTO);
|
||||||
|
|
||||||
|
SceneType getSceneType();
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.solution.rule.strategy;
|
||||||
|
|
||||||
|
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 SceneStrategyFactory {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private List<SceneStrategy> strategyList;
|
||||||
|
|
||||||
|
private final Map<SceneType, SceneStrategy> strategyMap = new EnumMap<>(SceneType.class);
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
for (SceneStrategy strategy : strategyList) {
|
||||||
|
SceneType type = strategy.getSceneType();
|
||||||
|
if (strategyMap.containsKey(type)) {
|
||||||
|
throw new IllegalStateException("重复的场景类型: " + type);
|
||||||
|
}
|
||||||
|
strategyMap.put(type, strategy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据前端传递的数字编码获取对应的策略
|
||||||
|
* @param code 前端传递的数字
|
||||||
|
* @return 策略实现
|
||||||
|
* @throws IllegalArgumentException 如果编码无效或策略未注册
|
||||||
|
*/
|
||||||
|
public SceneStrategy getStrategy(int code) {
|
||||||
|
SceneType type = SceneType.fromCode(code);
|
||||||
|
SceneStrategy strategy = strategyMap.get(type);
|
||||||
|
if (strategy == null) {
|
||||||
|
throw new IllegalArgumentException("未找到编码 " + code + " 对应的策略实现");
|
||||||
|
}
|
||||||
|
return strategy;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
solution-rule/src/main/resources/mapper/rule/RuleMapper.xml
Normal file
37
solution-rule/src/main/resources/mapper/rule/RuleMapper.xml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.solution.rule.mapper.RuleMapper">
|
||||||
|
|
||||||
|
|
||||||
|
<resultMap id="platformComponentCountMap" type="com.solution.rule.domain.vo.WeaponModelVO">
|
||||||
|
<result property="platformName" column="platform_name"/>
|
||||||
|
<result property="componentName" column="component_name"/>
|
||||||
|
<result property="count" column="count"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<select id="getWeapon" resultMap="platformComponentCountMap">
|
||||||
|
SELECT
|
||||||
|
p.name AS platform_name,
|
||||||
|
pc.name AS component_name,
|
||||||
|
COUNT(pc.name) AS count
|
||||||
|
FROM platform p
|
||||||
|
LEFT JOIN platform_component pc ON p.id = pc.platform_id
|
||||||
|
GROUP BY p.id, p.name, pc.name
|
||||||
|
ORDER BY p.id, pc.name
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getPlatformComponentNames" resultType="com.solution.rule.domain.vo.WeaponModelVO">
|
||||||
|
SELECT DISTINCT
|
||||||
|
p.name AS platformName,
|
||||||
|
pc.name AS componentName
|
||||||
|
FROM platform p
|
||||||
|
INNER JOIN platform_component pc ON p.id = pc.platform_id
|
||||||
|
WHERE pc.name IS NOT NULL
|
||||||
|
ORDER BY p.name, pc.name
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user