26-03-13-14:36:火力规则简单实现-删除重复模块
This commit is contained in:
@@ -1,39 +0,0 @@
|
|||||||
<?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>
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.solution.rule.mapper;
|
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface ModelDetailMapper {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE mapper
|
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.solution.rule.mapper.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