// Code generated by ent, DO NOT EDIT. package ent import ( "fmt" "strings" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/suyuan32/simple-admin-job/ent/task" ) // Task is the model entity for the Task schema. type Task struct { config `json:"-"` // ID of the ent. ID uint64 `json:"id,omitempty"` // Create Time | 创建日期 CreatedAt time.Time `json:"created_at,omitempty"` // Update Time | 修改日期 UpdatedAt time.Time `json:"updated_at,omitempty"` // Status 1: normal 2: ban | 状态 1 正常 2 禁用 Status uint8 `json:"status,omitempty"` // Task Name | 任务名称 Name string `json:"name,omitempty"` // Task Group | 任务分组 TaskGroup string `json:"task_group,omitempty"` // Cron expression | 定时任务表达式 CronExpression string `json:"cron_expression,omitempty"` // Cron Pattern | 任务的模式 (用于区分和确定要执行的任务) Pattern string `json:"pattern,omitempty"` // The data used in cron (JSON string) | 任务需要的数据(JSON 字符串) Payload string `json:"payload,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the TaskQuery when eager-loading is set. Edges TaskEdges `json:"edges"` selectValues sql.SelectValues } // TaskEdges holds the relations/edges for other nodes in the graph. type TaskEdges struct { // TaskLogs holds the value of the task_logs edge. TaskLogs []*TaskLog `json:"task_logs,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. loadedTypes [1]bool } // TaskLogsOrErr returns the TaskLogs value or an error if the edge // was not loaded in eager-loading. func (e TaskEdges) TaskLogsOrErr() ([]*TaskLog, error) { if e.loadedTypes[0] { return e.TaskLogs, nil } return nil, &NotLoadedError{edge: "task_logs"} } // scanValues returns the types for scanning values from sql.Rows. func (*Task) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { case task.FieldID, task.FieldStatus: values[i] = new(sql.NullInt64) case task.FieldName, task.FieldTaskGroup, task.FieldCronExpression, task.FieldPattern, task.FieldPayload: values[i] = new(sql.NullString) case task.FieldCreatedAt, task.FieldUpdatedAt: values[i] = new(sql.NullTime) default: values[i] = new(sql.UnknownType) } } return values, nil } // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Task fields. func (t *Task) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } for i := range columns { switch columns[i] { case task.FieldID: value, ok := values[i].(*sql.NullInt64) if !ok { return fmt.Errorf("unexpected type %T for field id", value) } t.ID = uint64(value.Int64) case task.FieldCreatedAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field created_at", values[i]) } else if value.Valid { t.CreatedAt = value.Time } case task.FieldUpdatedAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field updated_at", values[i]) } else if value.Valid { t.UpdatedAt = value.Time } case task.FieldStatus: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field status", values[i]) } else if value.Valid { t.Status = uint8(value.Int64) } case task.FieldName: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field name", values[i]) } else if value.Valid { t.Name = value.String } case task.FieldTaskGroup: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field task_group", values[i]) } else if value.Valid { t.TaskGroup = value.String } case task.FieldCronExpression: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field cron_expression", values[i]) } else if value.Valid { t.CronExpression = value.String } case task.FieldPattern: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field pattern", values[i]) } else if value.Valid { t.Pattern = value.String } case task.FieldPayload: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field payload", values[i]) } else if value.Valid { t.Payload = value.String } default: t.selectValues.Set(columns[i], values[i]) } } return nil } // Value returns the ent.Value that was dynamically selected and assigned to the Task. // This includes values selected through modifiers, order, etc. func (t *Task) Value(name string) (ent.Value, error) { return t.selectValues.Get(name) } // QueryTaskLogs queries the "task_logs" edge of the Task entity. func (t *Task) QueryTaskLogs() *TaskLogQuery { return NewTaskClient(t.config).QueryTaskLogs(t) } // Update returns a builder for updating this Task. // Note that you need to call Task.Unwrap() before calling this method if this Task // was returned from a transaction, and the transaction was committed or rolled back. func (t *Task) Update() *TaskUpdateOne { return NewTaskClient(t.config).UpdateOne(t) } // Unwrap unwraps the Task entity that was returned from a transaction after it was closed, // so that all future queries will be executed through the driver which created the transaction. func (t *Task) Unwrap() *Task { _tx, ok := t.config.driver.(*txDriver) if !ok { panic("ent: Task is not a transactional entity") } t.config.driver = _tx.drv return t } // String implements the fmt.Stringer. func (t *Task) String() string { var builder strings.Builder builder.WriteString("Task(") builder.WriteString(fmt.Sprintf("id=%v, ", t.ID)) builder.WriteString("created_at=") builder.WriteString(t.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("updated_at=") builder.WriteString(t.UpdatedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("status=") builder.WriteString(fmt.Sprintf("%v", t.Status)) builder.WriteString(", ") builder.WriteString("name=") builder.WriteString(t.Name) builder.WriteString(", ") builder.WriteString("task_group=") builder.WriteString(t.TaskGroup) builder.WriteString(", ") builder.WriteString("cron_expression=") builder.WriteString(t.CronExpression) builder.WriteString(", ") builder.WriteString("pattern=") builder.WriteString(t.Pattern) builder.WriteString(", ") builder.WriteString("payload=") builder.WriteString(t.Payload) builder.WriteByte(')') return builder.String() } // Tasks is a parsable slice of Task. type Tasks []*Task