UPDATE: fk
This commit is contained in:
@@ -1,15 +1,16 @@
|
|||||||
package com.assess.business.handler;
|
package com.solution.algo;
|
||||||
/*
|
/*
|
||||||
* This file is part of the kernelstudio package.
|
* This file is part of the kernelstudio package.
|
||||||
*
|
*
|
||||||
* (c) 2014-2025 zlin <admin@kernelstudio.com>
|
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE file
|
* For the full copyright and license information, please view the LICENSE file
|
||||||
* that was distributed with this source code.
|
* that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.assess.business.domain.IndicatorConfig;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
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.apache.ibatis.type.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -20,62 +21,67 @@ import java.sql.CallableStatement;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@MappedTypes(IndicatorConfig.class)
|
@MappedTypes(List.class)
|
||||||
@MappedJdbcTypes({
|
@MappedJdbcTypes({
|
||||||
JdbcType.VARCHAR,
|
JdbcType.VARCHAR,
|
||||||
JdbcType.BLOB
|
JdbcType.BLOB
|
||||||
})
|
})
|
||||||
public class IndicatorConfigTypeHandler extends BaseTypeHandler<IndicatorConfig>
|
public class AlgorithmConfigTypeHandler extends BaseTypeHandler<List<AlgorithmConfig>>
|
||||||
implements TypeHandler<IndicatorConfig> {
|
implements TypeHandler<List<AlgorithmConfig>> {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
private final CollectionType collectionType = objectMapper.getTypeFactory()
|
||||||
|
.constructCollectionType(List.class, AlgorithmConfig.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNonNullParameter(PreparedStatement ps, int i, IndicatorConfig parameter, JdbcType jdbcType)
|
public void setNonNullParameter(PreparedStatement ps, int i, List<AlgorithmConfig> parameter, JdbcType jdbcType)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
ps.setString(i, serialize(parameter));
|
ps.setString(i, serialize(parameter));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String serialize(IndicatorConfig indicatorConfig) {
|
public String serialize(List<AlgorithmConfig> indicatorConfig) {
|
||||||
if (null != indicatorConfig){
|
if (null != indicatorConfig) {
|
||||||
try {
|
try {
|
||||||
return objectMapper.writeValueAsString(indicatorConfig);
|
return objectMapper.writeValueAsString(indicatorConfig);
|
||||||
} catch (Exception e){
|
} catch (Exception e) {
|
||||||
logger.error("Can not serialize", e);
|
logger.error("Can not serialize", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndicatorConfig deserialize(String config) throws SQLException {
|
public List<AlgorithmConfig> deserialize(String config) throws SQLException {
|
||||||
if (StringUtils.hasText(config)){
|
if (StringUtils.hasText(config)) {
|
||||||
try {
|
try {
|
||||||
return objectMapper.readValue(config, IndicatorConfig.class);
|
return objectMapper.readValue(config, collectionType);
|
||||||
} catch (Exception e){
|
} catch (Exception e) {
|
||||||
logger.error("Can not deserialize", e);
|
logger.error("Can not deserialize", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new IndicatorConfig();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndicatorConfig getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
public List<AlgorithmConfig> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||||
String jsonValue = rs.getString(columnName);
|
String jsonValue = rs.getString(columnName);
|
||||||
return deserialize(jsonValue);
|
return deserialize(jsonValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndicatorConfig getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
public List<AlgorithmConfig> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||||
String jsonValue = rs.getString(columnIndex);
|
String jsonValue = rs.getString(columnIndex);
|
||||||
return deserialize(jsonValue);
|
return deserialize(jsonValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndicatorConfig getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
public List<AlgorithmConfig> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||||
String jsonValue = cs.getString(columnIndex);
|
String jsonValue = cs.getString(columnIndex);
|
||||||
return deserialize(jsonValue);
|
return deserialize(jsonValue);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ public class Algorithm
|
|||||||
@Excel(name = "算法配置")
|
@Excel(name = "算法配置")
|
||||||
private String algoConfig;
|
private String algoConfig;
|
||||||
|
|
||||||
|
/** 算法配置 */
|
||||||
|
private List<AlgorithmConfig> algoConfigList;
|
||||||
|
|
||||||
/** 算法参数定义信息 */
|
/** 算法参数定义信息 */
|
||||||
private List<AlgorithmParam> algorithmParamList;
|
private List<AlgorithmParam> algorithmParamList;
|
||||||
|
|
||||||
@@ -111,6 +114,14 @@ public class Algorithm
|
|||||||
this.algorithmParamList = algorithmParamList;
|
this.algorithmParamList = algorithmParamList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<AlgorithmConfig> getAlgoConfigList() {
|
||||||
|
return algoConfigList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlgoConfigList(List<AlgorithmConfig> algoConfigList) {
|
||||||
|
this.algoConfigList = algoConfigList;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
|||||||
@@ -7,6 +7,29 @@ package com.solution.algo.domain;
|
|||||||
* For the full copyright and license information, please view the LICENSE file
|
* For the full copyright and license information, please view the LICENSE file
|
||||||
* that was distributed with this source code.
|
* that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class AlgorithmConfig {
|
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="codePath" column="code_path" />
|
||||||
<result property="description" column="description" />
|
<result property="description" column="description" />
|
||||||
<result property="algoConfig" column="algo_config" />
|
<result property="algoConfig" column="algo_config" />
|
||||||
|
<result property="algoConfigList" column="algo_config_list" typeHandler="com.solution.algo.AlgorithmConfigTypeHandler" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<resultMap id="AlgorithmAlgorithmParamResult" type="Algorithm" extends="AlgorithmResult">
|
<resultMap id="AlgorithmAlgorithmParamResult" type="Algorithm" extends="AlgorithmResult">
|
||||||
@@ -26,7 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectAlgorithmVo">
|
<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>
|
</sql>
|
||||||
|
|
||||||
<select id="selectAlgorithmList" parameterType="Algorithm" resultMap="AlgorithmAlgorithmParamResult">
|
<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="codePath != null">code_path,</if>
|
||||||
<if test="description != null">description,</if>
|
<if test="description != null">description,</if>
|
||||||
<if test="algoConfig != null">algo_config,</if>
|
<if test="algoConfig != null">algo_config,</if>
|
||||||
|
<if test="algoConfigList != null">algo_config_list,</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="name != null and name != ''">#{name},</if>
|
<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="codePath != null">#{codePath},</if>
|
||||||
<if test="description != null">#{description},</if>
|
<if test="description != null">#{description},</if>
|
||||||
<if test="algoConfig != null">#{algoConfig},</if>
|
<if test="algoConfig != null">#{algoConfig},</if>
|
||||||
|
<if test="algoConfigList != null">#{algoConfigList,typeHandler=com.solution.algo.AlgorithmConfigTypeHandler},</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
@@ -78,6 +81,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="codePath != null">code_path = #{codePath},</if>
|
<if test="codePath != null">code_path = #{codePath},</if>
|
||||||
<if test="description != null">description = #{description},</if>
|
<if test="description != null">description = #{description},</if>
|
||||||
<if test="algoConfig != null">algo_config = #{algoConfig},</if>
|
<if test="algoConfig != null">algo_config = #{algoConfig},</if>
|
||||||
|
<if test="algoConfigList != null">algo_config_list = #{algoConfigList,typeHandler=com.solution.algo.AlgorithmConfigTypeHandler},</if>
|
||||||
</trim>
|
</trim>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|||||||
Reference in New Issue
Block a user