Initial commit

This commit is contained in:
libertyspy
2026-02-09 21:03:57 +08:00
parent c9bc62fb8c
commit db30244cd1
7 changed files with 232 additions and 37 deletions

View File

@@ -0,0 +1,83 @@
package com.assess.business.handler;
/*
* This file is part of the kernelstudio package.
*
* (c) 2014-2025 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.assess.business.domain.IndicatorConfig;
import com.fasterxml.jackson.databind.ObjectMapper;
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;
@Component
@MappedTypes(IndicatorConfig.class)
@MappedJdbcTypes({
JdbcType.VARCHAR,
JdbcType.BLOB
})
public class IndicatorConfigTypeHandler extends BaseTypeHandler<IndicatorConfig>
implements TypeHandler<IndicatorConfig> {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final ObjectMapper objectMapper = new ObjectMapper();
@Override
public void setNonNullParameter(PreparedStatement ps, int i, IndicatorConfig parameter, JdbcType jdbcType)
throws SQLException {
ps.setString(i, serialize(parameter));
}
public String serialize(IndicatorConfig indicatorConfig) {
if (null != indicatorConfig){
try {
return objectMapper.writeValueAsString(indicatorConfig);
} catch (Exception e){
logger.error("Can not serialize", e);
}
}
return null;
}
public IndicatorConfig deserialize(String config) throws SQLException {
if (StringUtils.hasText(config)){
try {
return objectMapper.readValue(config, IndicatorConfig.class);
} catch (Exception e){
logger.error("Can not deserialize", e);
}
}
return new IndicatorConfig();
}
@Override
public IndicatorConfig getNullableResult(ResultSet rs, String columnName) throws SQLException {
String jsonValue = rs.getString(columnName);
return deserialize(jsonValue);
}
@Override
public IndicatorConfig getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
String jsonValue = rs.getString(columnIndex);
return deserialize(jsonValue);
}
@Override
public IndicatorConfig getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
String jsonValue = cs.getString(columnIndex);
return deserialize(jsonValue);
}
}

View File

@@ -0,0 +1,12 @@
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.
*/
public class AlgorithmConfig {
}

View File

@@ -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'),
},

View File

@@ -1370,11 +1370,6 @@
}
}
.ant-btn-default {
background: #7dd3f9;
border-color: #7dd3f9;
color: #000;
}
.btn-field {
min-width: 120px;
@@ -1560,11 +1555,7 @@
}
}
.ant-btn-default{
&.ant-btn-dangerous{
background: transparent!important;
}
}
.ant-empty-small {
@@ -1598,11 +1589,14 @@
}
.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, #284e91 0, #2c5dad 100%);
background: linear-gradient(0deg, #14223b 0, #1c468b 100%);
&.selected,
&:not(:disabled):hover,

View File

@@ -21,3 +21,22 @@ export const algorithmTypes = [
name: '队形',
}
]
export const algorithmConfigOperations = [
{
type: '+',
name: '加',
},
{
type: '-',
name: '减',
},
{
type: '*',
name: '乘',
},
{
type: '/',
name: '除',
},
]

View File

@@ -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,6 +119,39 @@
</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}"
>
@@ -169,7 +194,7 @@ import Layout from '../layout.vue';
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>>({
@@ -199,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 => {
@@ -218,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 ?? [];
@@ -226,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 = () => {
@@ -255,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 => {
@@ -272,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) {

View File

@@ -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[]
}