Compare commits
4 Commits
9d54395c29
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 956d3f69ea | |||
|
|
8b3fe9b548 | ||
|
|
db30244cd1 | ||
|
|
c9bc62fb8c |
@@ -70,6 +70,12 @@
|
||||
<groupId>com.solution</groupId>
|
||||
<artifactId>solution-algo</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.solution</groupId>
|
||||
<artifactId>solution-rule</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<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:
|
||||
# 主库数据源
|
||||
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
|
||||
password: 123456
|
||||
# password: 123456
|
||||
password: 1234
|
||||
# 从库数据源
|
||||
slave:
|
||||
# 从数据源开关/默认关闭
|
||||
|
||||
@@ -67,13 +67,15 @@ spring:
|
||||
# redis 配置
|
||||
redis:
|
||||
# 地址
|
||||
host: 192.168.166.71
|
||||
# host: 192.168.166.71
|
||||
host: 127.0.0.1
|
||||
# 端口,默认为6379
|
||||
port: 6379
|
||||
# 数据库索引
|
||||
database: 0
|
||||
# 密码
|
||||
password:
|
||||
# password:
|
||||
password: 123456
|
||||
# 连接超时时间
|
||||
timeout: 10s
|
||||
lettuce:
|
||||
@@ -104,6 +106,8 @@ mybatis:
|
||||
mapperLocations: classpath*:mapper/**/*Mapper.xml
|
||||
# 加载全局的配置文件
|
||||
configLocation: classpath:mybatis/mybatis-config.xml
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
|
||||
# PageHelper分页插件
|
||||
pagehelper:
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.solution.algo;
|
||||
/*
|
||||
* This file is part of the kernelstudio package.
|
||||
*
|
||||
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.type.CollectionType;
|
||||
import com.solution.algo.domain.AlgorithmConfig;
|
||||
import org.apache.ibatis.type.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@MappedTypes(List.class)
|
||||
@MappedJdbcTypes({
|
||||
JdbcType.VARCHAR,
|
||||
JdbcType.BLOB
|
||||
})
|
||||
public class AlgorithmConfigTypeHandler extends BaseTypeHandler<List<AlgorithmConfig>>
|
||||
implements TypeHandler<List<AlgorithmConfig>> {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private final CollectionType collectionType = objectMapper.getTypeFactory()
|
||||
.constructCollectionType(List.class, AlgorithmConfig.class);
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, List<AlgorithmConfig> parameter, JdbcType jdbcType)
|
||||
throws SQLException {
|
||||
ps.setString(i, serialize(parameter));
|
||||
}
|
||||
|
||||
public String serialize(List<AlgorithmConfig> indicatorConfig) {
|
||||
if (null != indicatorConfig) {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(indicatorConfig);
|
||||
} catch (Exception e) {
|
||||
logger.error("Can not serialize", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<AlgorithmConfig> deserialize(String config) throws SQLException {
|
||||
if (StringUtils.hasText(config)) {
|
||||
try {
|
||||
return objectMapper.readValue(config, collectionType);
|
||||
} catch (Exception e) {
|
||||
logger.error("Can not deserialize", e);
|
||||
}
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AlgorithmConfig> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String jsonValue = rs.getString(columnName);
|
||||
return deserialize(jsonValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AlgorithmConfig> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String jsonValue = rs.getString(columnIndex);
|
||||
return deserialize(jsonValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AlgorithmConfig> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String jsonValue = cs.getString(columnIndex);
|
||||
return deserialize(jsonValue);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,6 +38,9 @@ public class Algorithm
|
||||
@Excel(name = "算法配置")
|
||||
private String algoConfig;
|
||||
|
||||
/** 算法配置 */
|
||||
private List<AlgorithmConfig> algoConfigList;
|
||||
|
||||
/** 算法参数定义信息 */
|
||||
private List<AlgorithmParam> algorithmParamList;
|
||||
|
||||
@@ -111,6 +114,14 @@ public class Algorithm
|
||||
this.algorithmParamList = algorithmParamList;
|
||||
}
|
||||
|
||||
public List<AlgorithmConfig> getAlgoConfigList() {
|
||||
return algoConfigList;
|
||||
}
|
||||
|
||||
public void setAlgoConfigList(List<AlgorithmConfig> algoConfigList) {
|
||||
this.algoConfigList = algoConfigList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.solution.algo.domain;
|
||||
/*
|
||||
* This file is part of the kernelstudio package.
|
||||
*
|
||||
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class AlgorithmConfig implements Serializable {
|
||||
|
||||
private String name;
|
||||
|
||||
private String operation;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
public void setOperation(String operation) {
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="codePath" column="code_path" />
|
||||
<result property="description" column="description" />
|
||||
<result property="algoConfig" column="algo_config" />
|
||||
<result property="algoConfigList" column="algo_config_list" typeHandler="com.solution.algo.AlgorithmConfigTypeHandler" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="AlgorithmAlgorithmParamResult" type="Algorithm" extends="AlgorithmResult">
|
||||
@@ -26,7 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectAlgorithmVo">
|
||||
select id, name, type, code_path, description, algo_config from algorithm
|
||||
select id, name, type, code_path, description, algo_config, algo_config_list from algorithm
|
||||
</sql>
|
||||
|
||||
<select id="selectAlgorithmList" parameterType="Algorithm" resultMap="AlgorithmAlgorithmParamResult">
|
||||
@@ -60,6 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="codePath != null">code_path,</if>
|
||||
<if test="description != null">description,</if>
|
||||
<if test="algoConfig != null">algo_config,</if>
|
||||
<if test="algoConfigList != null">algo_config_list,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="name != null and name != ''">#{name},</if>
|
||||
@@ -67,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="codePath != null">#{codePath},</if>
|
||||
<if test="description != null">#{description},</if>
|
||||
<if test="algoConfig != null">#{algoConfig},</if>
|
||||
<if test="algoConfigList != null">#{algoConfigList,typeHandler=com.solution.algo.AlgorithmConfigTypeHandler},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
@@ -78,6 +81,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="codePath != null">code_path = #{codePath},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="algoConfig != null">algo_config = #{algoConfig},</if>
|
||||
<if test="algoConfigList != null">algo_config_list = #{algoConfigList,typeHandler=com.solution.algo.AlgorithmConfigTypeHandler},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
@@ -113,6 +113,12 @@
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.25</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</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";
|
||||
}
|
||||
@@ -38,7 +38,7 @@ export const routes: RouteRecordRaw[] = [
|
||||
name: 'decision-algorithm-management',
|
||||
path: '/app/decision/algorithm/management',
|
||||
meta: {
|
||||
title: '规则管理',
|
||||
title: '指挥决策规则库管理',
|
||||
},
|
||||
component: () => import('@/views/decision/algorithm/management.vue'),
|
||||
},
|
||||
|
||||
@@ -1370,11 +1370,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
.ant-btn-default {
|
||||
background: #7dd3f9;
|
||||
border-color: #7dd3f9;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.btn-field {
|
||||
min-width: 120px;
|
||||
@@ -1560,8 +1555,90 @@
|
||||
}
|
||||
}
|
||||
|
||||
.ant-btn-default{
|
||||
&.ant-btn-dangerous{
|
||||
background: transparent;
|
||||
|
||||
|
||||
|
||||
.ant-empty-small {
|
||||
margin-block: 8px;
|
||||
color: rgb(207 207 207 / 66%);
|
||||
}
|
||||
.ant-btn >span {
|
||||
display: inline-block;
|
||||
float: inherit;
|
||||
}
|
||||
|
||||
.ant-btn,
|
||||
.ant-input {
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.ant-btn-primary {
|
||||
color: #eee;
|
||||
//border-color: #1b5b7d;
|
||||
//background: linear-gradient(90deg, #1e4c65 0%, #0b3a62 100%);
|
||||
border-color: #29759c;
|
||||
background: linear-gradient(0deg, #0f374c 0, #154c69 100%);
|
||||
&.selected,
|
||||
&:not(:disabled):hover,
|
||||
&:hover,
|
||||
&:active {
|
||||
border-color: #166094;
|
||||
background: linear-gradient(90deg, #3687bc 0%, #074375 100%);
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-btn-default {
|
||||
&.ant-btn-dangerous{
|
||||
background: transparent!important;
|
||||
}
|
||||
|
||||
color: #eee;
|
||||
//border-color: #144087;
|
||||
//background: linear-gradient(90deg, #0f4a7c 0%, #0a365b 100%);
|
||||
border-color: #1c468b;
|
||||
background: linear-gradient(0deg, #14223b 0, #1c468b 100%);
|
||||
&.selected,
|
||||
&:not(:disabled):hover,
|
||||
&:hover,
|
||||
&:active {
|
||||
color: #fff;
|
||||
border-color: #166094;
|
||||
background: linear-gradient(90deg, #3687bc 0%, #074375 100%);
|
||||
}
|
||||
&:disabled,
|
||||
&.disabled{
|
||||
color: #a9a3a3;
|
||||
&:hover{
|
||||
color:#eee;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn-field {
|
||||
min-width: 120px;
|
||||
background: #5796b2;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
border-radius: 2px;
|
||||
color: #fff;
|
||||
padding: 5px;
|
||||
border: 1px solid #5796b2;
|
||||
|
||||
.anticon {
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
&:hover,
|
||||
&.selected {
|
||||
background: #19b0ff;
|
||||
border-color: #19b0ff;
|
||||
}
|
||||
|
||||
&.gold {
|
||||
background: transparent;
|
||||
border-color: #b5b39d;
|
||||
color: #b5b39d;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,10 @@ export const createAlgorithm = (algorithm: Algorithm): Promise<BasicResponse> =>
|
||||
return req.postJson('/algo/algorithm', algorithm);
|
||||
};
|
||||
|
||||
export const runAlgorithm = (algorithm: Algorithm): Promise<BasicResponse> => {
|
||||
return req.postJson('/algo/algorithm/run', algorithm);
|
||||
};
|
||||
|
||||
export const updateAlgorithm = (algorithm: Algorithm): Promise<BasicResponse> => {
|
||||
return req.putJson('/algo/algorithm', algorithm);
|
||||
};
|
||||
|
||||
@@ -21,3 +21,22 @@ export const algorithmTypes = [
|
||||
name: '队形',
|
||||
}
|
||||
]
|
||||
|
||||
export const algorithmConfigOperations = [
|
||||
{
|
||||
type: '+',
|
||||
name: '加',
|
||||
},
|
||||
{
|
||||
type: '-',
|
||||
name: '减',
|
||||
},
|
||||
{
|
||||
type: '*',
|
||||
name: '乘',
|
||||
},
|
||||
{
|
||||
type: '/',
|
||||
name: '除',
|
||||
},
|
||||
]
|
||||
@@ -68,7 +68,7 @@
|
||||
:rules="[{ required: true, message: '请输入业务类型!', trigger: ['input', 'change'] }]"
|
||||
:name="['type']"
|
||||
>
|
||||
<a-select allow-clear v-model:value="selectedAlgorithm.type" @change="(v: any)=> selectedAlgorithm.type = v">
|
||||
<a-select placeholder="请选择业务类型" allow-clear v-model:value="selectedAlgorithm.type" @change="(v: any)=> selectedAlgorithm.type = v">
|
||||
<a-select-option v-for="a in algorithmTypes" :value="a.type">{{ a.name }}</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
@@ -81,14 +81,6 @@
|
||||
<a-input v-model:value="selectedAlgorithm.codePath" placeholder="请输入算法文件路径" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
label="算法配置"
|
||||
:rules="[{ required: true, message: '请输入算法配置', trigger: ['input', 'change'] }]"
|
||||
:name="['algoConfig']"
|
||||
>
|
||||
<a-textarea v-model:value="selectedAlgorithm.algoConfig" placeholder="请输入算法配置" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
label="算法描述"
|
||||
:rules="[{ required: false, message: '请输入算法描述', trigger: ['input', 'change'] }]"
|
||||
@@ -127,11 +119,51 @@
|
||||
</a-form-item-rest>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
label="算法配置"
|
||||
:rules="[{ required: false, message: '请输入算法配置', trigger: ['input', 'change'] }]"
|
||||
:name="['algoConfig']"
|
||||
>
|
||||
<a-form-item-rest>
|
||||
<div class="ks-algorithm-param-list">
|
||||
<div class="ks-algorithm-param-item" v-for="(t,index) in selectedAlgorithm.algoConfigList">
|
||||
<a-row :gutter="15">
|
||||
<a-col :span="7">
|
||||
<a-select placeholder="请选择参数" v-model:value="t.name" @change="(v: any)=> t.name = v">
|
||||
<a-select-option :value="v.paramName" v-for="v in selectedAlgorithm.algorithmParamList">{{v.paramName}}</a-select-option>
|
||||
</a-select>
|
||||
</a-col>
|
||||
<a-col :span="7">
|
||||
<a-select placeholder="请选择操作" v-model:value="t.operation" @change="(v: any)=> t.operation = v">
|
||||
<a-select-option :value="o.type" v-for="o in algorithmConfigOperations">{{o.name}} {{o.type}}</a-select-option>
|
||||
</a-select>
|
||||
</a-col>
|
||||
<a-col :span="3">
|
||||
<a-space class="ks-algorithm-param-actions">
|
||||
<MinusCircleOutlined @click="()=> handleMinusConfig(index)" />
|
||||
<PlusCircleOutlined @click="handleAddConfig" v-if="index === 0" />
|
||||
</a-space>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</div>
|
||||
</div>
|
||||
</a-form-item-rest>
|
||||
|
||||
</a-form-item>
|
||||
|
||||
|
||||
<a-form-item
|
||||
:wrapper-col="{offset: 6}"
|
||||
>
|
||||
<a-space>
|
||||
<a-button @click="handleSave">保存规则</a-button>
|
||||
<a-button @click="handleSave" type="primary">保存规则</a-button>
|
||||
<a-popconfirm
|
||||
v-if="selectedAlgorithm && selectedAlgorithm.id > 0"
|
||||
title="确定运行?"
|
||||
@confirm="handleRun"
|
||||
>
|
||||
<a-button>运行规则</a-button>
|
||||
</a-popconfirm>
|
||||
<a-popconfirm
|
||||
v-if="selectedAlgorithm && selectedAlgorithm.id > 0"
|
||||
title="确定删除?"
|
||||
@@ -159,10 +191,10 @@ import { onMounted, ref } from 'vue';
|
||||
import { type FormInstance, message } from 'ant-design-vue';
|
||||
import { MinusCircleOutlined, PlusCircleOutlined, PlusOutlined } from '@ant-design/icons-vue';
|
||||
import Layout from '../layout.vue';
|
||||
import { createAlgorithm, deleteAlgorithm, findAlgorithmsByQuery, updateAlgorithm } from './api';
|
||||
import { createAlgorithm, deleteAlgorithm, findAlgorithmsByQuery, updateAlgorithm, runAlgorithm } from './api';
|
||||
import type { Algorithm, AlgorithmParam, AlgorithmRequest } from './types';
|
||||
import { substring } from '@/utils/strings';
|
||||
import { algorithmTypes } from './config';
|
||||
import { algorithmTypes,algorithmConfigOperations } from './config';
|
||||
import type { NullableString } from '@/types';
|
||||
|
||||
const query = ref<Partial<AlgorithmRequest>>({
|
||||
@@ -192,14 +224,46 @@ const defaultAlgorithm: Algorithm = {
|
||||
description: null,
|
||||
// 算法配置
|
||||
algoConfig: null,
|
||||
// 算法配置
|
||||
algoConfigList: [],
|
||||
// 算法参数定义信息
|
||||
algorithmParamList: [
|
||||
{ ...defaultAlgorithmParam },
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
const resolveItem = (item: Algorithm) => {
|
||||
let newItem = JSON.parse(JSON.stringify(item))
|
||||
if (!newItem.algorithmParamList) {
|
||||
newItem.algorithmParamList = [];
|
||||
}
|
||||
if (newItem.algorithmParamList.length === 0) {
|
||||
newItem.algorithmParamList.push({ ...defaultAlgorithmParam });
|
||||
}
|
||||
|
||||
try{
|
||||
newItem.algoConfigList = JSON.parse(newItem.algoConfigList)
|
||||
} catch (e: any){
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
if(!newItem.algoConfigList){
|
||||
newItem.algoConfigList = []
|
||||
}
|
||||
|
||||
if(newItem.algoConfigList.length === 0){
|
||||
newItem.algoConfigList.push({
|
||||
name: undefined,
|
||||
operation: undefined,
|
||||
})
|
||||
}
|
||||
return newItem;
|
||||
};
|
||||
|
||||
const algorithms = ref<Algorithm[]>([]);
|
||||
const algorithmsTotal = ref<number>(0);
|
||||
const selectedAlgorithm = ref<Algorithm>(JSON.parse(JSON.stringify(defaultAlgorithm)));
|
||||
const selectedAlgorithm = ref<Algorithm>(resolveItem(defaultAlgorithm));
|
||||
const formRef = ref<FormInstance | null>(null);
|
||||
|
||||
const getAlgorithmTypeName = (type: NullableString): NullableString => {
|
||||
@@ -211,7 +275,7 @@ const load = () => {
|
||||
algorithms.value = [];
|
||||
algorithmsTotal.value = 0;
|
||||
formRef.value?.resetFields();
|
||||
selectedAlgorithm.value = JSON.parse(JSON.stringify(defaultAlgorithm));
|
||||
selectedAlgorithm.value = resolveItem(defaultAlgorithm);
|
||||
|
||||
findAlgorithmsByQuery(query.value).then(r => {
|
||||
algorithms.value = r.rows ?? [];
|
||||
@@ -219,19 +283,13 @@ const load = () => {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const handleCreate = () => {
|
||||
selectedAlgorithm.value = JSON.parse(JSON.stringify(defaultAlgorithm));
|
||||
selectedAlgorithm.value = resolveItem(defaultAlgorithm);
|
||||
};
|
||||
|
||||
const handleSelect = (item: Algorithm) => {
|
||||
let newItem = JSON.parse(JSON.stringify(item))
|
||||
if (!newItem.algorithmParamList) {
|
||||
newItem.algorithmParamList = [];
|
||||
}
|
||||
if (newItem.algorithmParamList.length === 0) {
|
||||
newItem.algorithmParamList.push({ ...defaultAlgorithmParam });
|
||||
}
|
||||
selectedAlgorithm.value = newItem;
|
||||
selectedAlgorithm.value = resolveItem(item);
|
||||
};
|
||||
|
||||
const handleAdd = () => {
|
||||
@@ -248,6 +306,20 @@ const handleMinus = (index: number) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddConfig = () => {
|
||||
selectedAlgorithm.value.algoConfigList.push({ name: null, operation: null });
|
||||
};
|
||||
|
||||
const handleMinusConfig = (index: number) => {
|
||||
const paramList = selectedAlgorithm.value.algoConfigList;
|
||||
if (index === 0 && selectedAlgorithm.value.algoConfigList.length === 1) {
|
||||
selectedAlgorithm.value.algoConfigList = [{ name: null, operation: null }];
|
||||
} else if (index >= 0 && index < paramList.length && paramList.length > 1) {
|
||||
paramList.splice(index, 1);
|
||||
selectedAlgorithm.value.algoConfigList = [...paramList];
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (selectedAlgorithm.value && selectedAlgorithm.value.id > 0) {
|
||||
deleteAlgorithm(selectedAlgorithm.value.id).then(r => {
|
||||
@@ -265,11 +337,26 @@ const handleSave = () => {
|
||||
if (formRef.value) {
|
||||
formRef.value.validate().then(() => {
|
||||
let res = null;
|
||||
if (selectedAlgorithm.value.id > 0) {
|
||||
res = updateAlgorithm(selectedAlgorithm.value);
|
||||
} else {
|
||||
res = createAlgorithm(selectedAlgorithm.value);
|
||||
let savedValue: Algorithm = JSON.parse(JSON.stringify(selectedAlgorithm.value)) as any as Algorithm;
|
||||
let algoConfig = '';
|
||||
if( savedValue.algoConfigList ){
|
||||
savedValue.algoConfigList.forEach(o=> {
|
||||
if(o.name){
|
||||
algoConfig = algoConfig + o.name;
|
||||
}
|
||||
if(o.operation){
|
||||
algoConfig = algoConfig + o.operation;
|
||||
}
|
||||
})
|
||||
}
|
||||
savedValue.algoConfig = algoConfig;
|
||||
|
||||
if (savedValue.id > 0) {
|
||||
res = updateAlgorithm(savedValue);
|
||||
} else {
|
||||
res = createAlgorithm(savedValue);
|
||||
}
|
||||
|
||||
if (res) {
|
||||
res.then(r => {
|
||||
if (r.code === 200) {
|
||||
@@ -284,6 +371,20 @@ const handleSave = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleRun = ()=> {
|
||||
if (formRef.value) {
|
||||
formRef.value.validate().then(() => {
|
||||
runAlgorithm(selectedAlgorithm.value).then(r => {
|
||||
if (r.code === 200) {
|
||||
message.info(r.msg ?? '运行成功');
|
||||
} else {
|
||||
message.error(r.msg ?? '运行失败');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const handleChange = (page: number, pageSize: number) => {
|
||||
query.value.pageNum = page;
|
||||
query.value.pageSize = pageSize;
|
||||
|
||||
@@ -20,6 +20,11 @@ export interface AlgorithmParam {
|
||||
description: NullableString,
|
||||
}
|
||||
|
||||
export interface AlgorithmConfig {
|
||||
name: NullableString,
|
||||
operation: NullableString,
|
||||
}
|
||||
|
||||
export interface Algorithm {
|
||||
|
||||
id: number,
|
||||
@@ -33,6 +38,8 @@ export interface Algorithm {
|
||||
description: NullableString,
|
||||
// 算法配置
|
||||
algoConfig: NullableString,
|
||||
// 算法配置
|
||||
algoConfigList: AlgorithmConfig[],
|
||||
// 算法参数定义信息
|
||||
algorithmParamList: AlgorithmParam[]
|
||||
}
|
||||
|
||||
8
pom.xml
8
pom.xml
@@ -231,6 +231,13 @@
|
||||
<version>${solution.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 规则模块-->
|
||||
<dependency>
|
||||
<groupId>com.solution</groupId>
|
||||
<artifactId>solution-rule</artifactId>
|
||||
<version>${solution.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
@@ -244,6 +251,7 @@
|
||||
<module>auto-solution-quartz</module>
|
||||
<module>auto-solution-generator</module>
|
||||
<module>auto-solution-common</module>
|
||||
<module>solution-rule</module>
|
||||
</modules>
|
||||
<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