refactor: 后端仓库层收口(A4:任务/项目/笔记/专员/动作定义)
把 B 档(此前尚无仓库的对象)的 api 裸查询收进仓库,api 层裸 store.DB 从 162 降到 96(口径:internal/ 下非测试 .go,不含 internal/repository/ 自身)。 新增 7 个仓库:TaskRecordRepo / TaskArtifactRepo / TaskRunRepo / ProjectRepo / StudyNoteRepo / SpecialistRepo / ActionDefinitionRepo。 按对象补齐的方法: - TaskRecordRepo:GetByID / GetByIDForOwners / ListBySpecialistKey / ListByOwners / ListByProject / CountBySpecialistKey / ClearProject / DeleteCascade - ProjectRepo:GetByIDForOwners / ListByOwners - StudyNoteRepo:ListByUser / GetByID - SpecialistRepo:GetByKey / GetByID / Query / List / CountByKey - TaskArtifactRepo / TaskRunRepo:GetByID / ListByTask - ActionDefinitionRepo:List / GetByID / GetByKey 几条口径改由仓库单点持有,避免各处手写漂移: - 归属过滤抽成 ownerScope:owners 为空时套恒假条件(空集),绝不退化成全表。 specialists/runtime 的 MyTaskQuery / ProjectQuery 随之删除,调用方改用 MyTaskOwners + 仓库方法 —— 任务与项目共用同一套归属口径。 - 「任务 + 交付物 + 运行记录三张表同事务级联删除」从 handler 收进 DeleteCascade, 不留没有任务的孤儿交付物;删项目只解除其下任务的 project_id 归属(置 NULL, 不是 0),不删任务本身 —— 任务是「做过的事」,删一个分组不该把它一起抹掉。 - 专员目录的 state 档位(默认 active / all 仅管理员 / system / 其它精确匹配, 且除显式要 system 外一律排除 system 记录)收进 SpecialistRepo.List。 - GetByKey 有意不过滤 state:调用方口径不同(建任务时要能查到,对话取 prompt 时要拒绝 inactive),口径留在调用方,仓库只负责取数。顺带把「按 key 找专员」 从 4 个文件里各写一遍收敛成一处。 - ActionDefinitionRepo.List 不替调用方定 state 默认值 ——「不传 state 就只看 active」是列表接口的契约,由 handler 解析 query 后传入。 - StudyNoteRepo.GetByID 不判归属,越权检查留在 handler(那里能把「不存在」与 「不是你的」分别回成 404 / 403)。 保留未动:skills/api/office_handlers.go 里两处 store.DB.Transaction —— 运行记录 与交付物要在同一个事务里落库,QueryBuilder 不带事务,维持原样并就地注明。 验证:go build ./... 与 go vet ./... 干净,go test ./... 6 个包全绿。 另用独立验证程序走真实路由 + 真实 HTTP,对数据库副本跑 148 项断言全绿 (覆盖跨用户越权 404、空 owners 退化成空集、级联删除、解除归属置 NULL、 笔记按用户隔离、专员 key 唯一性排除自身、管理员 state=all 仍排除 system 等)。 另对其中 10 条关键语义做了变异测试:逐条注入反向实现,确认断言确实会失败, 捕获 10 / 漏掉 0。变异测试同时暴露并修掉了验证体系自身的两个漏洞: - 「state=all 排除 system」这条规则此前没有任何断言能观察到 —— 默认档被 state=active 挡着、system 档被 state=system 挡着,删掉实现也不会红; - 变异驱动只跑 HTTP 断言、不跑 go test,导致针对单元测试注入的变异 (拒绝已下线专员的 prompt)永远逮不到。 验证程序为一次性脚手架,验证完成后已删除(tmp_vfy_b/)。 原始 data/eai_agentplatform.db 全程未触碰(mtime 仍为 2026-09-17 15:14)。 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"eai_agentplatform/backend/internal/model"
|
||||
)
|
||||
|
||||
// ActionDefinition 原子执行动作定义仓库。
|
||||
type ActionDefinitionRepo struct{ *QueryBuilder }
|
||||
|
||||
// List 全部动作定义(sort_order ASC, id ASC)。
|
||||
//
|
||||
// 这里不替调用方定 state 默认值:列表接口「不传 state 就只看 active」是接口契约,
|
||||
// 由 handler 解析 query 参数后把结果传进来。
|
||||
func (r ActionDefinitionRepo) List(state string) []model.ActionDefinition {
|
||||
q := r.Type(&model.ActionDefinition{})
|
||||
if state != "" {
|
||||
q = q.Where("state = ?", state)
|
||||
}
|
||||
var items []model.ActionDefinition
|
||||
if q.Order("sort_order ASC, id ASC").Find(&items) {
|
||||
return items
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetByID 按 ID 取。
|
||||
func (r ActionDefinitionRepo) GetByID(id uint) (model.ActionDefinition, bool) {
|
||||
var a model.ActionDefinition
|
||||
if r.Type(&a).Where("id = ?", id).First(&a) {
|
||||
return a, true
|
||||
}
|
||||
return model.ActionDefinition{}, false
|
||||
}
|
||||
|
||||
// GetByKey 按 key 取(key 上有唯一索引)。
|
||||
func (r ActionDefinitionRepo) GetByKey(key string) (model.ActionDefinition, bool) {
|
||||
var a model.ActionDefinition
|
||||
if r.Type(&a).Where("key = ?", key).First(&a) {
|
||||
return a, true
|
||||
}
|
||||
return model.ActionDefinition{}, false
|
||||
}
|
||||
|
||||
// Insert 新建。
|
||||
func (r ActionDefinitionRepo) Insert(a *model.ActionDefinition) bool {
|
||||
return r.QueryBuilder.Insert(a)
|
||||
}
|
||||
|
||||
// Update 更新。
|
||||
func (r ActionDefinitionRepo) Update(a *model.ActionDefinition) bool {
|
||||
return r.Save(a)
|
||||
}
|
||||
|
||||
// Delete 硬删除。
|
||||
func (r ActionDefinitionRepo) Delete(a *model.ActionDefinition) bool {
|
||||
return r.QueryBuilder.Delete(a)
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"eai_agentplatform/backend/internal/model"
|
||||
)
|
||||
|
||||
// Project 项目仓库(任务的容器)。
|
||||
type ProjectRepo struct{ *QueryBuilder }
|
||||
|
||||
// GetByIDForOwners 按 ID 取项目,且必须归属于 owners 里的一员。
|
||||
//
|
||||
// owners 为空时查不到任何东西(而不是查到全部)——跟任务同一套归属口径,
|
||||
// 别人的项目和不存在的项目在这里不做区分,调用方一律回 404。
|
||||
func (r ProjectRepo) GetByIDForOwners(id uint, owners []string) (model.Project, bool) {
|
||||
var p model.Project
|
||||
if ownerScope(r.Type(&p), owners).Where("id = ?", id).First(&p) {
|
||||
return p, true
|
||||
}
|
||||
return model.Project{}, false
|
||||
}
|
||||
|
||||
// ListByOwners 「我的项目」:置顶的排前面,其余按最近动过的排。
|
||||
// limit <= 0 表示不设上限。
|
||||
func (r ProjectRepo) ListByOwners(owners []string, limit int) []model.Project {
|
||||
q := ownerScope(r.Type(&model.Project{}), owners)
|
||||
if limit > 0 {
|
||||
q = q.Limit(limit)
|
||||
}
|
||||
var items []model.Project
|
||||
if q.Order("pinned DESC, updated_at DESC, id DESC").Find(&items) {
|
||||
return items
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Insert 新建项目。
|
||||
func (r ProjectRepo) Insert(p *model.Project) bool {
|
||||
return r.QueryBuilder.Insert(p)
|
||||
}
|
||||
|
||||
// Update 更新项目。
|
||||
func (r ProjectRepo) Update(p *model.Project) bool {
|
||||
return r.Save(p)
|
||||
}
|
||||
|
||||
// Delete 删除项目。
|
||||
//
|
||||
// 项目里的任务**不删**——先由调用方把它们的 project_id 置空(见
|
||||
// TaskRecordRepo.ClearProject),再删项目本身。
|
||||
func (r ProjectRepo) Delete(p *model.Project) bool {
|
||||
return r.QueryBuilder.Delete(p)
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
specialistmodel "eai_agentplatform/backend/internal/specialists/model"
|
||||
)
|
||||
|
||||
// Specialist 数字员工专员目录仓库。
|
||||
//
|
||||
// 模型定义在 specialists 领域包内(internal/specialists/model),取数统一走这里——
|
||||
// 「按 key 找专员」原先在 4 个文件里各写了一遍,散着改迟早分叉。
|
||||
type SpecialistRepo struct{ *QueryBuilder }
|
||||
|
||||
// GetByKey 按 key 取专员,**不限 state**。
|
||||
//
|
||||
// 不过滤 state 是有意的:调用方对「停用的专员算不算数」口径不同——
|
||||
// 建任务时要能查到(任务挂在已下线的专员上仍要能解释),
|
||||
// 而对话取 prompt 时要拒绝 inactive。把口径留在调用方,这里只负责取数。
|
||||
func (r SpecialistRepo) GetByKey(key string) (specialistmodel.Specialist, bool) {
|
||||
var s specialistmodel.Specialist
|
||||
if r.Type(&s).Where("key = ?", key).First(&s) {
|
||||
return s, true
|
||||
}
|
||||
return specialistmodel.Specialist{}, false
|
||||
}
|
||||
|
||||
// GetByID 按 ID 取专员。
|
||||
func (r SpecialistRepo) GetByID(id uint) (specialistmodel.Specialist, bool) {
|
||||
var s specialistmodel.Specialist
|
||||
if r.Type(&s).Where("id = ?", id).First(&s) {
|
||||
return s, true
|
||||
}
|
||||
return specialistmodel.Specialist{}, false
|
||||
}
|
||||
|
||||
// Query 返回专员表的查询构建器(已 Type 好)。
|
||||
//
|
||||
// 给「带自己那套 state 策略」的调用方用——比如按 key 取且非管理员只认 active、
|
||||
// 或者按 state 分档计数。这类策略是各接口自己的口径,不在这里替它们定。
|
||||
func (r SpecialistRepo) Query() *QueryBuilder {
|
||||
return r.QueryBuilder.Query().Type(&specialistmodel.Specialist{})
|
||||
}
|
||||
|
||||
// List 专员目录列表(sort_order ASC, id ASC)。
|
||||
//
|
||||
// state 的档位是接口契约,调用方直接透传 query 参数:
|
||||
// - ""(默认):仅 active —— 员工浏览视角
|
||||
// - "all":管理员看全部状态,非管理员仍只看 active
|
||||
// - "system":仅 system(通用助手那条内置记录)
|
||||
// - 其它:按该状态精确匹配
|
||||
//
|
||||
// 除显式要 system 外,一律排除 system 记录——它是内置的通用助手,
|
||||
// 不该混进专员目录里让人当成一个可选的专员。
|
||||
func (r SpecialistRepo) List(tier, marketTag, state string, isAdmin bool) []specialistmodel.Specialist {
|
||||
q := r.Type(&specialistmodel.Specialist{})
|
||||
if tier != "" {
|
||||
q = q.Where("tier = ?", tier)
|
||||
}
|
||||
if marketTag != "" {
|
||||
q = q.Where("market_tag = ?", marketTag)
|
||||
}
|
||||
switch state {
|
||||
case "":
|
||||
q = q.Where("state = ?", "active")
|
||||
case "all":
|
||||
if !isAdmin {
|
||||
q = q.Where("state = ?", "active")
|
||||
}
|
||||
case "system":
|
||||
q = q.Where("state = ?", "system")
|
||||
default:
|
||||
q = q.Where("state = ?", state)
|
||||
}
|
||||
if state != "system" {
|
||||
q = q.Where("state <> ?", "system")
|
||||
}
|
||||
var items []specialistmodel.Specialist
|
||||
if q.Order("sort_order ASC, id ASC").Find(&items) {
|
||||
return items
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CountByKey 按 key 统计(唯一性检查)。excludeID 用于更新时排除自身,nil 表示不排除。
|
||||
func (r SpecialistRepo) CountByKey(key string, excludeID *uint) int64 {
|
||||
q := r.Inner().Model(&specialistmodel.Specialist{}).Where("key = ?", key)
|
||||
if excludeID != nil {
|
||||
q = q.Where("id <> ?", *excludeID)
|
||||
}
|
||||
var c int64
|
||||
q.Count(&c)
|
||||
return c
|
||||
}
|
||||
|
||||
// Insert 新建专员。
|
||||
func (r SpecialistRepo) Insert(s *specialistmodel.Specialist) bool {
|
||||
return r.QueryBuilder.Insert(s)
|
||||
}
|
||||
|
||||
// Update 更新专员。
|
||||
func (r SpecialistRepo) Update(s *specialistmodel.Specialist) bool {
|
||||
return r.Save(s)
|
||||
}
|
||||
|
||||
// Delete 硬删除专员。
|
||||
//
|
||||
// 表上没有软删字段,删了就是删了——跟「停用」(state=inactive)是两回事:
|
||||
// 停用还留着记录、还能查到,删除会让挂在它名下的历史任务失去解释依据。
|
||||
func (r SpecialistRepo) Delete(id uint) bool {
|
||||
return r.Type(&specialistmodel.Specialist{}).Where("id = ?", id).Delete(&specialistmodel.Specialist{})
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"eai_agentplatform/backend/internal/model"
|
||||
)
|
||||
|
||||
// StudyNote 学习笔记仓库(员工私人笔记,按 user_id 隔离)。
|
||||
type StudyNoteRepo struct{ *QueryBuilder }
|
||||
|
||||
// ListByUser 某用户的笔记,最近改过的在前。
|
||||
//
|
||||
// itemType 为空表示不按内容类型过滤;itemID 为 nil 表示不按内容 ID 过滤
|
||||
// (指针而非 0 值,是因为 company 类笔记的 item_id 本来就固定是 0)。
|
||||
func (r StudyNoteRepo) ListByUser(userID uint, itemType string, itemID *uint) []model.StudyNote {
|
||||
q := r.Type(&model.StudyNote{}).Where("user_id = ?", userID)
|
||||
if itemType != "" {
|
||||
q = q.Where("item_type = ?", itemType)
|
||||
}
|
||||
if itemID != nil {
|
||||
q = q.Where("item_id = ?", *itemID)
|
||||
}
|
||||
var items []model.StudyNote
|
||||
if q.Order("updated_at DESC").Find(&items) {
|
||||
return items
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetByID 按 ID 取笔记。**不在这里判归属**——越权检查留在 handler,
|
||||
// 那里能把「不存在」和「不是你的」分别回成 404 / 403。
|
||||
func (r StudyNoteRepo) GetByID(id uint) (model.StudyNote, bool) {
|
||||
var n model.StudyNote
|
||||
if r.Type(&n).Where("id = ?", id).First(&n) {
|
||||
return n, true
|
||||
}
|
||||
return model.StudyNote{}, false
|
||||
}
|
||||
|
||||
// Insert 新建笔记。
|
||||
func (r StudyNoteRepo) Insert(n *model.StudyNote) bool {
|
||||
return r.QueryBuilder.Insert(n)
|
||||
}
|
||||
|
||||
// Update 更新笔记。
|
||||
func (r StudyNoteRepo) Update(n *model.StudyNote) bool {
|
||||
return r.Save(n)
|
||||
}
|
||||
|
||||
// Delete 删除笔记(硬删,表上没有软删字段)。
|
||||
func (r StudyNoteRepo) Delete(n *model.StudyNote) bool {
|
||||
return r.QueryBuilder.Delete(n)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"eai_agentplatform/backend/internal/model"
|
||||
)
|
||||
|
||||
// TaskArtifact 专员交付物仓库。
|
||||
type TaskArtifactRepo struct{ *QueryBuilder }
|
||||
|
||||
// GetByID 按 ID 取交付物。
|
||||
func (r TaskArtifactRepo) GetByID(id uint) (model.TaskArtifact, bool) {
|
||||
var a model.TaskArtifact
|
||||
if r.Type(&a).Where("id = ?", id).First(&a) {
|
||||
return a, true
|
||||
}
|
||||
return model.TaskArtifact{}, false
|
||||
}
|
||||
|
||||
// ListByTask 某任务的全部交付物(最近产出的在前)。
|
||||
func (r TaskArtifactRepo) ListByTask(taskID uint) []model.TaskArtifact {
|
||||
var items []model.TaskArtifact
|
||||
if r.Type(&items).Where("task_id = ?", taskID).
|
||||
Order("created_at DESC, id DESC").Find(&items) {
|
||||
return items
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Insert 新建交付物。
|
||||
func (r TaskArtifactRepo) Insert(a *model.TaskArtifact) bool {
|
||||
return r.QueryBuilder.Insert(a)
|
||||
}
|
||||
|
||||
// Update 更新交付物(状态流转走这里)。
|
||||
func (r TaskArtifactRepo) Update(a *model.TaskArtifact) bool {
|
||||
return r.Save(a)
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
"eai_agentplatform/backend/internal/model"
|
||||
)
|
||||
|
||||
// TaskRecord 专员事项/任务仓库。
|
||||
//
|
||||
// 任务是这个聚合的根:交付物(task_artifact)与运行记录(task_run)都挂在它下面,
|
||||
// 所以级联删除也放在这里,而不是让 handler 去协调三个仓库。
|
||||
type TaskRecordRepo struct{ *QueryBuilder }
|
||||
|
||||
// GetByID 按 ID 取任务。
|
||||
func (r TaskRecordRepo) GetByID(id uint) (model.TaskRecord, bool) {
|
||||
var t model.TaskRecord
|
||||
if r.Type(&t).Where("id = ?", id).First(&t) {
|
||||
return t, true
|
||||
}
|
||||
return model.TaskRecord{}, false
|
||||
}
|
||||
|
||||
// GetByIDForOwners 按 ID 取任务,且必须归属于 owners 里的一员。
|
||||
//
|
||||
// owners 为空时查不到任何东西(而不是查到全部):归属标识缺失时必须退化成
|
||||
// 「什么都看不到」,绝不能反过来退化成「看所有人的」。
|
||||
func (r TaskRecordRepo) GetByIDForOwners(id uint, owners []string) (model.TaskRecord, bool) {
|
||||
var t model.TaskRecord
|
||||
if ownerScope(r.Type(&t), owners).Where("id = ?", id).First(&t) {
|
||||
return t, true
|
||||
}
|
||||
return model.TaskRecord{}, false
|
||||
}
|
||||
|
||||
// ListBySpecialistKey 某专员名下的全部任务(最近更新的在前)。
|
||||
func (r TaskRecordRepo) ListBySpecialistKey(specialistKey string) []model.TaskRecord {
|
||||
var items []model.TaskRecord
|
||||
if r.Type(&items).Where("specialist_key = ?", specialistKey).
|
||||
Order("updated_at DESC, id DESC").Find(&items) {
|
||||
return items
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListByOwners 「我的任务」:置顶的排前面,其余按最近动过的排。
|
||||
// limit <= 0 表示不设上限。
|
||||
func (r TaskRecordRepo) ListByOwners(owners []string, limit int) []model.TaskRecord {
|
||||
q := ownerScope(r.Type(&model.TaskRecord{}), owners)
|
||||
if limit > 0 {
|
||||
q = q.Limit(limit)
|
||||
}
|
||||
var items []model.TaskRecord
|
||||
if q.Order("pinned DESC, updated_at DESC, id DESC").Find(&items) {
|
||||
return items
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListByProject 项目下的任务(最近更新的在前)。limit <= 0 表示不设上限。
|
||||
func (r TaskRecordRepo) ListByProject(projectID uint, limit int) []model.TaskRecord {
|
||||
q := r.Type(&model.TaskRecord{}).Where("project_id = ?", projectID)
|
||||
if limit > 0 {
|
||||
q = q.Limit(limit)
|
||||
}
|
||||
var items []model.TaskRecord
|
||||
if q.Order("updated_at DESC, id DESC").Find(&items) {
|
||||
return items
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CountBySpecialistKey 统计某专员名下的任务数(首次进入时判断要不要铺底任务)。
|
||||
func (r TaskRecordRepo) CountBySpecialistKey(specialistKey string) int64 {
|
||||
var c int64
|
||||
r.Inner().Model(&model.TaskRecord{}).Where("specialist_key = ?", specialistKey).Count(&c)
|
||||
return c
|
||||
}
|
||||
|
||||
// Insert 新建任务。
|
||||
func (r TaskRecordRepo) Insert(t *model.TaskRecord) bool {
|
||||
return r.QueryBuilder.Insert(t)
|
||||
}
|
||||
|
||||
// Update 更新任务。
|
||||
func (r TaskRecordRepo) Update(t *model.TaskRecord) bool {
|
||||
return r.Save(t)
|
||||
}
|
||||
|
||||
// Delete 删除单条任务(不动它的交付物与运行记录,级联请用 DeleteCascade)。
|
||||
func (r TaskRecordRepo) Delete(t *model.TaskRecord) bool {
|
||||
return r.QueryBuilder.Delete(t)
|
||||
}
|
||||
|
||||
// ClearProject 把项目下的任务全部解除归属(project_id 置空)。
|
||||
//
|
||||
// 任务是「做过的事」,删一个分组不该把它一起抹掉,所以只解除归属、不删记录。
|
||||
func (r TaskRecordRepo) ClearProject(projectID uint) bool {
|
||||
return r.Type(&model.TaskRecord{}).Where("project_id = ?", projectID).
|
||||
UpdateColumn("project_id", nil)
|
||||
}
|
||||
|
||||
// DeleteCascade 删任务,连同它的交付物与运行记录。
|
||||
//
|
||||
// 三张表必须一起成功或一起失败——留下没有任务的交付物,详情页就再也点不进去了。
|
||||
func (r TaskRecordRepo) DeleteCascade(id uint) bool {
|
||||
err := r.Inner().Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Where("task_id = ?", id).Delete(&model.TaskArtifact{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Where("task_id = ?", id).Delete(&model.TaskRun{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Delete(&model.TaskRecord{}, id).Error
|
||||
})
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// ownerScope 给查询套上归属范围。owners 为空时套一个恒假条件(空集,不是全表)。
|
||||
func ownerScope(q *QueryBuilder, owners []string) *QueryBuilder {
|
||||
if len(owners) == 0 {
|
||||
return q.Where("1 = 0")
|
||||
}
|
||||
return q.Where("owner IN ?", owners)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"eai_agentplatform/backend/internal/model"
|
||||
)
|
||||
|
||||
// TaskRun 专员动作运行记录仓库。
|
||||
//
|
||||
// 运行记录只增不改:一次动作一条,是任务详情的「时间线/回放」底稿。
|
||||
type TaskRunRepo struct{ *QueryBuilder }
|
||||
|
||||
// GetByID 按 ID 取运行记录。
|
||||
func (r TaskRunRepo) GetByID(id uint) (model.TaskRun, bool) {
|
||||
var run model.TaskRun
|
||||
if r.Type(&run).Where("id = ?", id).First(&run) {
|
||||
return run, true
|
||||
}
|
||||
return model.TaskRun{}, false
|
||||
}
|
||||
|
||||
// ListByTask 某任务的全部运行记录(最近开始的在前)。
|
||||
func (r TaskRunRepo) ListByTask(taskID uint) []model.TaskRun {
|
||||
var items []model.TaskRun
|
||||
if r.Type(&items).Where("task_id = ?", taskID).
|
||||
Order("started_at DESC, id DESC").Find(&items) {
|
||||
return items
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Insert 追加一条运行记录。
|
||||
func (r TaskRunRepo) Insert(run *model.TaskRun) bool {
|
||||
return r.QueryBuilder.Insert(run)
|
||||
}
|
||||
Reference in New Issue
Block a user