From db30244cd1842678a697089b1a01453904e89c5b Mon Sep 17 00:00:00 2001 From: libertyspy Date: Mon, 9 Feb 2026 21:03:57 +0800 Subject: [PATCH] Initial commit --- .../algo/AlgorithmConfigTypeHandler.java | 83 +++++++++++ .../solution/algo/domain/AlgorithmConfig.java | 12 ++ modeler/src/router/config.ts | 2 +- modeler/src/style.less | 16 +-- .../src/views/decision/algorithm/config.ts | 19 +++ .../views/decision/algorithm/management.vue | 130 ++++++++++++++---- modeler/src/views/decision/algorithm/types.ts | 7 + 7 files changed, 232 insertions(+), 37 deletions(-) create mode 100644 auto-solution-algo/src/main/java/com/solution/algo/AlgorithmConfigTypeHandler.java create mode 100644 auto-solution-algo/src/main/java/com/solution/algo/domain/AlgorithmConfig.java diff --git a/auto-solution-algo/src/main/java/com/solution/algo/AlgorithmConfigTypeHandler.java b/auto-solution-algo/src/main/java/com/solution/algo/AlgorithmConfigTypeHandler.java new file mode 100644 index 0000000..2600596 --- /dev/null +++ b/auto-solution-algo/src/main/java/com/solution/algo/AlgorithmConfigTypeHandler.java @@ -0,0 +1,83 @@ +package com.assess.business.handler; +/* + * This file is part of the kernelstudio package. + * + * (c) 2014-2025 zlin + * + * 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 + implements TypeHandler { + + 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); + } + +} diff --git a/auto-solution-algo/src/main/java/com/solution/algo/domain/AlgorithmConfig.java b/auto-solution-algo/src/main/java/com/solution/algo/domain/AlgorithmConfig.java new file mode 100644 index 0000000..07cc503 --- /dev/null +++ b/auto-solution-algo/src/main/java/com/solution/algo/domain/AlgorithmConfig.java @@ -0,0 +1,12 @@ +package com.solution.algo.domain; +/* + * This file is part of the kernelstudio package. + * + * (c) 2014-2026 zlin + * + * For the full copyright and license information, please view the LICENSE file + * that was distributed with this source code. + */ + +public class AlgorithmConfig { +} diff --git a/modeler/src/router/config.ts b/modeler/src/router/config.ts index 03b586f..8a751d4 100644 --- a/modeler/src/router/config.ts +++ b/modeler/src/router/config.ts @@ -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'), }, diff --git a/modeler/src/style.less b/modeler/src/style.less index 80c05d2..f4aef21 100644 --- a/modeler/src/style.less +++ b/modeler/src/style.less @@ -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, diff --git a/modeler/src/views/decision/algorithm/config.ts b/modeler/src/views/decision/algorithm/config.ts index 2663aa5..2a8a31d 100644 --- a/modeler/src/views/decision/algorithm/config.ts +++ b/modeler/src/views/decision/algorithm/config.ts @@ -20,4 +20,23 @@ export const algorithmTypes = [ type: 'formation', name: '队形', } +] + +export const algorithmConfigOperations = [ + { + type: '+', + name: '加', + }, + { + type: '-', + name: '减', + }, + { + type: '*', + name: '乘', + }, + { + type: '/', + name: '除', + }, ] \ No newline at end of file diff --git a/modeler/src/views/decision/algorithm/management.vue b/modeler/src/views/decision/algorithm/management.vue index 38a9c48..43bab84 100644 --- a/modeler/src/views/decision/algorithm/management.vue +++ b/modeler/src/views/decision/algorithm/management.vue @@ -68,7 +68,7 @@ :rules="[{ required: true, message: '请输入业务类型!', trigger: ['input', 'change'] }]" :name="['type']" > - + {{ a.name }} @@ -81,14 +81,6 @@ - - - - + + +
+
+ + + + {{v.paramName}} + + + + + {{o.name}} {{o.type}} + + + + + + + + + +
+
+
+ +
+ + @@ -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>({ @@ -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([]); const algorithmsTotal = ref(0); -const selectedAlgorithm = ref(JSON.parse(JSON.stringify(defaultAlgorithm))); +const selectedAlgorithm = ref(resolveItem(defaultAlgorithm)); const formRef = ref(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) { diff --git a/modeler/src/views/decision/algorithm/types.ts b/modeler/src/views/decision/algorithm/types.ts index 6252b63..0232433 100644 --- a/modeler/src/views/decision/algorithm/types.ts +++ b/modeler/src/views/decision/algorithm/types.ts @@ -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[] }