重构:使用 MyBatis-Flex 迁移应用 ORM
将应用自管表的 JdbcClient 数据访问迁移为实体、Mapper、构造器查询和必要的显式 SQL。 保留 AgentScope 自管表及原有业务语义,并补充事务、查询与数据库集成测试。
This commit is contained in:
58
server/src/main/resources/mapper/AgentRunMapper.xml
Normal file
58
server/src/main/resources/mapper/AgentRunMapper.xml
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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.AgentRunMapper">
|
||||
|
||||
<!-- 以下更新均将“当前状态”写进 WHERE,更新行数就是状态机竞争结果。 -->
|
||||
<update id="completeWaiting">
|
||||
UPDATE app.agent_run
|
||||
SET status = 'COMPLETED', pending_interrupt = NULL, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = #{runId, typeHandler=tech.easyflow.manuagent.typehandler.UuidTypeHandler}
|
||||
AND status = 'WAITING_INPUT'
|
||||
</update>
|
||||
|
||||
<update id="interruptRunning">
|
||||
UPDATE app.agent_run
|
||||
SET status = 'INTERRUPTED', pending_interrupt = NULL,
|
||||
error_code = 'USER_STOPPED', error_message = '用户已停止运行',
|
||||
ended_at = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = #{runId, typeHandler=tech.easyflow.manuagent.typehandler.UuidTypeHandler}
|
||||
AND status = 'RUNNING'
|
||||
</update>
|
||||
|
||||
<update id="waitForInput">
|
||||
UPDATE app.agent_run
|
||||
SET status = 'WAITING_INPUT',
|
||||
pending_interrupt = #{interruptJson, jdbcType=OTHER,
|
||||
typeHandler=tech.easyflow.manuagent.typehandler.JsonbStringTypeHandler},
|
||||
ended_at = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = #{runId, typeHandler=tech.easyflow.manuagent.typehandler.UuidTypeHandler}
|
||||
AND status = 'RUNNING'
|
||||
</update>
|
||||
|
||||
<update id="completeRunning">
|
||||
UPDATE app.agent_run
|
||||
SET status = 'COMPLETED', pending_interrupt = NULL,
|
||||
ended_at = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = #{runId, typeHandler=tech.easyflow.manuagent.typehandler.UuidTypeHandler}
|
||||
AND status = 'RUNNING'
|
||||
</update>
|
||||
|
||||
<update id="failRunning">
|
||||
UPDATE app.agent_run
|
||||
SET status = 'FAILED', pending_interrupt = NULL,
|
||||
error_code = 'AGENT_RUN_FAILED', error_message = #{message},
|
||||
ended_at = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = #{runId, typeHandler=tech.easyflow.manuagent.typehandler.UuidTypeHandler}
|
||||
AND status = 'RUNNING'
|
||||
</update>
|
||||
|
||||
<update id="interruptRunningAfterRestart">
|
||||
UPDATE app.agent_run
|
||||
SET status = 'INTERRUPTED', pending_interrupt = NULL,
|
||||
error_code = 'PROCESS_RESTARTED', error_message = '服务重启,运行已中断',
|
||||
ended_at = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE status = 'RUNNING'
|
||||
</update>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user