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.
|
||||
*
|
||||
* (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
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import com.assess.business.domain.IndicatorConfig;
|
||||
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;
|
||||
@@ -20,62 +21,67 @@ 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(IndicatorConfig.class)
|
||||
@MappedTypes(List.class)
|
||||
@MappedJdbcTypes({
|
||||
JdbcType.VARCHAR,
|
||||
JdbcType.BLOB
|
||||
})
|
||||
public class IndicatorConfigTypeHandler extends BaseTypeHandler<IndicatorConfig>
|
||||
implements TypeHandler<IndicatorConfig> {
|
||||
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, IndicatorConfig parameter, JdbcType jdbcType)
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, List<AlgorithmConfig> parameter, JdbcType jdbcType)
|
||||
throws SQLException {
|
||||
ps.setString(i, serialize(parameter));
|
||||
}
|
||||
|
||||
public String serialize(IndicatorConfig indicatorConfig) {
|
||||
if (null != indicatorConfig){
|
||||
public String serialize(List<AlgorithmConfig> indicatorConfig) {
|
||||
if (null != indicatorConfig) {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(indicatorConfig);
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
logger.error("Can not serialize", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IndicatorConfig deserialize(String config) throws SQLException {
|
||||
if (StringUtils.hasText(config)){
|
||||
public List<AlgorithmConfig> deserialize(String config) throws SQLException {
|
||||
if (StringUtils.hasText(config)) {
|
||||
try {
|
||||
return objectMapper.readValue(config, IndicatorConfig.class);
|
||||
} catch (Exception e){
|
||||
return objectMapper.readValue(config, collectionType);
|
||||
} catch (Exception e) {
|
||||
logger.error("Can not deserialize", e);
|
||||
}
|
||||
}
|
||||
return new IndicatorConfig();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@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);
|
||||
return deserialize(jsonValue);
|
||||
}
|
||||
|
||||
@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);
|
||||
return deserialize(jsonValue);
|
||||
}
|
||||
|
||||
@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);
|
||||
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)
|
||||
|
||||
@@ -7,6 +7,29 @@ package com.solution.algo.domain;
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* 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="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>
|
||||
|
||||
Reference in New Issue
Block a user