重构:使用 MyBatis-Flex 迁移应用 ORM
将应用自管表的 JdbcClient 数据访问迁移为实体、Mapper、构造器查询和必要的显式 SQL。 保留 AgentScope 自管表及原有业务语义,并补充事务、查询与数据库集成测试。
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
package tech.easyflow.manuagent.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import com.mybatisflex.core.keygen.KeyGenerators;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.UUID;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import tech.easyflow.manuagent.typehandler.JsonbStringTypeHandler;
|
||||
import tech.easyflow.manuagent.typehandler.UuidTypeHandler;
|
||||
|
||||
/**
|
||||
* 映射 {@code app.agent_run} 表的 Agent 运行状态实体。
|
||||
*
|
||||
* <p>运行终态切换并不依赖 BaseMapper 的无条件更新,而由 Mapper XML 使用
|
||||
* {@code WHERE status = 'RUNNING'} 实现乐观状态机,避免停止、完成和失败并发覆盖。</p>
|
||||
*/
|
||||
@Table(value = "agent_run", schema = "app")
|
||||
public class AgentRunEntity {
|
||||
|
||||
/** Run 主键。 */
|
||||
@Id(keyType = KeyType.Generator, value = KeyGenerators.uuid)
|
||||
@Column(typeHandler = UuidTypeHandler.class)
|
||||
private UUID id;
|
||||
/** 所属项目。 */
|
||||
@Column(typeHandler = UuidTypeHandler.class)
|
||||
private UUID projectId;
|
||||
/** 恢复、重试场景下关联的父 Run。 */
|
||||
@Column(typeHandler = UuidTypeHandler.class)
|
||||
private UUID parentRunId;
|
||||
/** 本次 Run 固定使用的模型配置。 */
|
||||
@Column(typeHandler = UuidTypeHandler.class)
|
||||
private UUID modelConfigId;
|
||||
/** INITIAL、RESUME 或 RETRY。 */
|
||||
private String triggerType;
|
||||
/** 当前运行状态。 */
|
||||
private String status;
|
||||
/** 等待用户确认时保存的 Ask JSON。 */
|
||||
@Column(jdbcType = JdbcType.OTHER, typeHandler = JsonbStringTypeHandler.class)
|
||||
private String pendingInterrupt;
|
||||
/** 跨日志追踪标识。 */
|
||||
private String traceId;
|
||||
/** 失败或中断错误码。 */
|
||||
private String errorCode;
|
||||
/** 面向用户的失败信息。 */
|
||||
private String errorMessage;
|
||||
/** Run 开始时间。 */
|
||||
private OffsetDateTime startedAt;
|
||||
/** 进入终态或等待态的时间。 */
|
||||
private OffsetDateTime endedAt;
|
||||
/** 创建时间。 */
|
||||
private OffsetDateTime createdAt;
|
||||
/** 最后更新时间。 */
|
||||
private OffsetDateTime updatedAt;
|
||||
|
||||
public UUID getId() { return id; }
|
||||
public void setId(UUID id) { this.id = id; }
|
||||
public UUID getProjectId() { return projectId; }
|
||||
public void setProjectId(UUID projectId) { this.projectId = projectId; }
|
||||
public UUID getParentRunId() { return parentRunId; }
|
||||
public void setParentRunId(UUID parentRunId) { this.parentRunId = parentRunId; }
|
||||
public UUID getModelConfigId() { return modelConfigId; }
|
||||
public void setModelConfigId(UUID modelConfigId) { this.modelConfigId = modelConfigId; }
|
||||
public String getTriggerType() { return triggerType; }
|
||||
public void setTriggerType(String triggerType) { this.triggerType = triggerType; }
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
public String getPendingInterrupt() { return pendingInterrupt; }
|
||||
public void setPendingInterrupt(String pendingInterrupt) { this.pendingInterrupt = pendingInterrupt; }
|
||||
public String getTraceId() { return traceId; }
|
||||
public void setTraceId(String traceId) { this.traceId = traceId; }
|
||||
public String getErrorCode() { return errorCode; }
|
||||
public void setErrorCode(String errorCode) { this.errorCode = errorCode; }
|
||||
public String getErrorMessage() { return errorMessage; }
|
||||
public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }
|
||||
public OffsetDateTime getStartedAt() { return startedAt; }
|
||||
public void setStartedAt(OffsetDateTime startedAt) { this.startedAt = startedAt; }
|
||||
public OffsetDateTime getEndedAt() { return endedAt; }
|
||||
public void setEndedAt(OffsetDateTime endedAt) { this.endedAt = endedAt; }
|
||||
public OffsetDateTime getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(OffsetDateTime createdAt) { this.createdAt = createdAt; }
|
||||
public OffsetDateTime getUpdatedAt() { return updatedAt; }
|
||||
public void setUpdatedAt(OffsetDateTime updatedAt) { this.updatedAt = updatedAt; }
|
||||
}
|
||||
Reference in New Issue
Block a user