50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
package schema
|
|
|
|
import (
|
|
"likedream-goframe/internal/ent/schema/mix"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/entsql"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// CpTask holds the schema definition for the CpTask entity.
|
|
type CpTask struct {
|
|
ent.Schema
|
|
}
|
|
|
|
// Fields of the CpTask.
|
|
func (CpTask) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Int64("cp_user_id"),
|
|
field.Int64("user_id"),
|
|
field.Enum("task_type").Values("collection", "sign", "sleep_check"),
|
|
field.String("title").NotEmpty(),
|
|
field.Int("frequency").Default(0),
|
|
field.Enum("task_status").Values("not_start", "doing", "done", "fail", "pause", "unknown"),
|
|
field.Int("success_count").Default(0),
|
|
field.Text("form_data").Optional(),
|
|
field.Enum("step").Values("form", "execute", "complete"),
|
|
field.Enum("notification_type").Values("none", "cp_user_email", "system_user_email"),
|
|
field.Int("execute_hour").Optional().Nillable(),
|
|
field.Int("execute_minute").Optional().Nillable(),
|
|
field.Int64("next_execute_time").Optional().Nillable(),
|
|
}
|
|
}
|
|
|
|
// Edges of the CpTask.
|
|
func (CpTask) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.From("cp_user", CpUser.Type).Ref("cptasks").Field("cp_user_id").Unique().Required().Annotations(entsql.OnDelete(entsql.Cascade)),
|
|
edge.From("sys_user", SysUser.Type).Ref("cp_task").Field("user_id").Unique().Required().Annotations(entsql.OnDelete(entsql.Cascade)),
|
|
edge.To("cp_task_logs", CpTaskLog.Type).Annotations(entsql.OnDelete(entsql.Cascade)), // 任务拥有的cp任务日志
|
|
}
|
|
}
|
|
|
|
func (CpTask) Mixin() []ent.Mixin {
|
|
return []ent.Mixin{
|
|
mix.MixinTime{},
|
|
}
|
|
}
|