重构:使用 MyBatis-Flex 迁移应用 ORM
将应用自管表的 JdbcClient 数据访问迁移为实体、Mapper、构造器查询和必要的显式 SQL。 保留 AgentScope 自管表及原有业务语义,并补充事务、查询与数据库集成测试。
This commit is contained in:
63
server/src/main/resources/mapper/ModelConfigMapper.xml
Normal file
63
server/src/main/resources/mapper/ModelConfigMapper.xml
Normal file
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="tech.easyflow.manuagent.mapper.ModelConfigMapper">
|
||||
|
||||
<!--
|
||||
JSONB 参数必须显式使用 JsonbStringTypeHandler。这样即使 Lambda Wrapper 在 Spring 初始化前
|
||||
触发了 MyBatis-Flex 的全局 TableInfo 缓存,模型写入仍不会退化为 VARCHAR 参数绑定。
|
||||
-->
|
||||
<insert id="insertModel">
|
||||
INSERT INTO app.model_config(
|
||||
id, name, provider, base_url, model_id,
|
||||
api_key_ciphertext, api_key_hint, key_version,
|
||||
config_json, capabilities_json, enabled, is_default, created_by)
|
||||
VALUES (
|
||||
#{model.id, typeHandler=tech.easyflow.manuagent.typehandler.UuidTypeHandler},
|
||||
#{model.name},
|
||||
#{model.provider},
|
||||
#{model.baseUrl},
|
||||
#{model.modelId},
|
||||
#{model.apiKeyCiphertext},
|
||||
#{model.apiKeyHint},
|
||||
#{model.keyVersion},
|
||||
#{model.configJson, jdbcType=OTHER, typeHandler=tech.easyflow.manuagent.typehandler.JsonbStringTypeHandler},
|
||||
#{model.capabilitiesJson, jdbcType=OTHER, typeHandler=tech.easyflow.manuagent.typehandler.JsonbStringTypeHandler},
|
||||
COALESCE(#{model.enabled}, TRUE),
|
||||
COALESCE(#{model.defaultModel}, FALSE),
|
||||
#{model.createdBy, typeHandler=tech.easyflow.manuagent.typehandler.UuidTypeHandler})
|
||||
</insert>
|
||||
|
||||
<!--
|
||||
API Key 为空表示保留已有密钥;更新时间统一由数据库生成,避免应用时钟和数据库时钟混用。
|
||||
-->
|
||||
<update id="updateModel">
|
||||
UPDATE app.model_config
|
||||
SET name = #{model.name},
|
||||
base_url = #{model.baseUrl},
|
||||
model_id = #{model.modelId},
|
||||
config_json = #{model.configJson, jdbcType=OTHER, typeHandler=tech.easyflow.manuagent.typehandler.JsonbStringTypeHandler},
|
||||
capabilities_json = #{model.capabilitiesJson, jdbcType=OTHER, typeHandler=tech.easyflow.manuagent.typehandler.JsonbStringTypeHandler},
|
||||
<if test="model.apiKeyCiphertext != null">
|
||||
api_key_ciphertext = #{model.apiKeyCiphertext},
|
||||
api_key_hint = #{model.apiKeyHint},
|
||||
key_version = #{model.keyVersion},
|
||||
</if>
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = #{model.id, typeHandler=tech.easyflow.manuagent.typehandler.UuidTypeHandler}
|
||||
</update>
|
||||
|
||||
<!-- 以下两条语句保持迁移前的执行顺序和条件,不额外引入模型启用状态判断。 -->
|
||||
<update id="clearDefault">
|
||||
UPDATE app.model_config
|
||||
SET is_default = FALSE
|
||||
WHERE is_default
|
||||
</update>
|
||||
|
||||
<update id="setDefault">
|
||||
UPDATE app.model_config
|
||||
SET is_default = TRUE,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = #{id, typeHandler=tech.easyflow.manuagent.typehandler.UuidTypeHandler}
|
||||
</update>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user