|
|
@ -3,6 +3,7 @@ package inventory
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
|
|
"github.com/cloudreve/Cloudreve/v4/ent"
|
|
|
|
"github.com/cloudreve/Cloudreve/v4/ent"
|
|
|
@ -44,6 +45,8 @@ type TaskClient interface {
|
|
|
|
List(ctx context.Context, args *ListTaskArgs) (*ListTaskResult, error)
|
|
|
|
List(ctx context.Context, args *ListTaskArgs) (*ListTaskResult, error)
|
|
|
|
// DeleteByIDs deletes the tasks with the given IDs.
|
|
|
|
// DeleteByIDs deletes the tasks with the given IDs.
|
|
|
|
DeleteByIDs(ctx context.Context, ids ...int) error
|
|
|
|
DeleteByIDs(ctx context.Context, ids ...int) error
|
|
|
|
|
|
|
|
// DeleteBy deletes the tasks with the given args.
|
|
|
|
|
|
|
|
DeleteBy(ctx context.Context, args *DeleteTaskArgs) error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
type (
|
|
|
@ -59,6 +62,12 @@ type (
|
|
|
|
*PaginationResults
|
|
|
|
*PaginationResults
|
|
|
|
Tasks []*ent.Task
|
|
|
|
Tasks []*ent.Task
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeleteTaskArgs struct {
|
|
|
|
|
|
|
|
NotAfter time.Time
|
|
|
|
|
|
|
|
Types []string
|
|
|
|
|
|
|
|
Status []task.Status
|
|
|
|
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func NewTaskClient(client *ent.Client, dbType conf.DBType, hasher hashid.Encoder) TaskClient {
|
|
|
|
func NewTaskClient(client *ent.Client, dbType conf.DBType, hasher hashid.Encoder) TaskClient {
|
|
|
@ -113,6 +122,23 @@ func (c *taskClient) DeleteByIDs(ctx context.Context, ids ...int) error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c *taskClient) DeleteBy(ctx context.Context, args *DeleteTaskArgs) error {
|
|
|
|
|
|
|
|
query := c.client.Task.
|
|
|
|
|
|
|
|
Delete().
|
|
|
|
|
|
|
|
Where(task.CreatedAtLTE(args.NotAfter))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(args.Status) > 0 {
|
|
|
|
|
|
|
|
query.Where(task.StatusIn(args.Status...))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(args.Types) > 0 {
|
|
|
|
|
|
|
|
query.Where(task.TypeIn(args.Types...))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_, err := query.Exec(ctx)
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *taskClient) Update(ctx context.Context, task *ent.Task, args *TaskArgs) (*ent.Task, error) {
|
|
|
|
func (c *taskClient) Update(ctx context.Context, task *ent.Task, args *TaskArgs) (*ent.Task, error) {
|
|
|
|
stm := c.client.Task.UpdateOne(task).
|
|
|
|
stm := c.client.Task.UpdateOne(task).
|
|
|
|
SetPublicState(args.PublicState)
|
|
|
|
SetPublicState(args.PublicState)
|
|
|
|