2026-03-13 16:53:54 +08:00
|
|
|
//
|
|
|
|
|
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
package dao
|
|
|
|
|
|
|
|
|
|
import (
|
2026-03-27 19:25:18 +08:00
|
|
|
"ragflow/internal/entity"
|
2026-03-13 16:53:54 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// TaskDAO task data access object
|
|
|
|
|
type TaskDAO struct{}
|
|
|
|
|
|
|
|
|
|
// NewTaskDAO create task DAO
|
|
|
|
|
func NewTaskDAO() *TaskDAO {
|
|
|
|
|
return &TaskDAO{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create creates a new task
|
2026-03-27 19:25:18 +08:00
|
|
|
func (dao *TaskDAO) Create(task *entity.Task) error {
|
2026-03-13 16:53:54 +08:00
|
|
|
return DB.Create(task).Error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetByID gets task by ID
|
2026-03-27 19:25:18 +08:00
|
|
|
func (dao *TaskDAO) GetByID(id string) (*entity.Task, error) {
|
|
|
|
|
var task entity.Task
|
2026-03-13 16:53:54 +08:00
|
|
|
err := DB.Where("id = ?", id).First(&task).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &task, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteByDocIDs deletes tasks by document IDs (hard delete)
|
|
|
|
|
func (dao *TaskDAO) DeleteByDocIDs(docIDs []string) (int64, error) {
|
|
|
|
|
if len(docIDs) == 0 {
|
|
|
|
|
return 0, nil
|
|
|
|
|
}
|
2026-03-27 19:25:18 +08:00
|
|
|
result := DB.Unscoped().Where("doc_id IN ?", docIDs).Delete(&entity.Task{})
|
2026-03-13 16:53:54 +08:00
|
|
|
return result.RowsAffected, result.Error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteByTenantID deletes all tasks by tenant ID (hard delete via document join)
|
|
|
|
|
func (dao *TaskDAO) DeleteByTenantID(tenantID string) (int64, error) {
|
2026-03-27 19:25:18 +08:00
|
|
|
result := DB.Unscoped().Where("doc_id IN (SELECT id FROM document WHERE tenant_id = ?)", tenantID).Delete(&entity.Task{})
|
2026-03-13 16:53:54 +08:00
|
|
|
return result.RowsAffected, result.Error
|
|
|
|
|
}
|
2026-05-09 10:03:23 +08:00
|
|
|
|
2026-06-04 14:16:13 +08:00
|
|
|
// GetByDocID gets all tasks by document ID
|
|
|
|
|
func (dao *TaskDAO) GetByDocID(docID string) ([]*entity.Task, error) {
|
|
|
|
|
var tasks []*entity.Task
|
|
|
|
|
err := DB.Where("doc_id = ?", docID).Find(&tasks).Error
|
|
|
|
|
return tasks, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-09 10:03:23 +08:00
|
|
|
func (dao *TaskDAO) GetAllTasks() ([]*entity.Task, error) {
|
|
|
|
|
var tasks []*entity.Task
|
|
|
|
|
err := DB.Find(&tasks).Error
|
|
|
|
|
return tasks, err
|
|
|
|
|
}
|