123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- "github.com/suyuan32/simple-admin-job/ent/sopstage"
- "github.com/suyuan32/simple-admin-job/ent/soptask"
- )
- // SopTaskCreate is the builder for creating a SopTask entity.
- type SopTaskCreate struct {
- config
- mutation *SopTaskMutation
- hooks []Hook
- }
- // SetCreatedAt sets the "created_at" field.
- func (stc *SopTaskCreate) SetCreatedAt(t time.Time) *SopTaskCreate {
- stc.mutation.SetCreatedAt(t)
- return stc
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (stc *SopTaskCreate) SetNillableCreatedAt(t *time.Time) *SopTaskCreate {
- if t != nil {
- stc.SetCreatedAt(*t)
- }
- return stc
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (stc *SopTaskCreate) SetUpdatedAt(t time.Time) *SopTaskCreate {
- stc.mutation.SetUpdatedAt(t)
- return stc
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (stc *SopTaskCreate) SetNillableUpdatedAt(t *time.Time) *SopTaskCreate {
- if t != nil {
- stc.SetUpdatedAt(*t)
- }
- return stc
- }
- // SetStatus sets the "status" field.
- func (stc *SopTaskCreate) SetStatus(u uint8) *SopTaskCreate {
- stc.mutation.SetStatus(u)
- return stc
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (stc *SopTaskCreate) SetNillableStatus(u *uint8) *SopTaskCreate {
- if u != nil {
- stc.SetStatus(*u)
- }
- return stc
- }
- // SetName sets the "name" field.
- func (stc *SopTaskCreate) SetName(s string) *SopTaskCreate {
- stc.mutation.SetName(s)
- return stc
- }
- // SetBotWxidList sets the "bot_wxid_list" field.
- func (stc *SopTaskCreate) SetBotWxidList(s []string) *SopTaskCreate {
- stc.mutation.SetBotWxidList(s)
- return stc
- }
- // SetType sets the "type" field.
- func (stc *SopTaskCreate) SetType(i int) *SopTaskCreate {
- stc.mutation.SetType(i)
- return stc
- }
- // SetNillableType sets the "type" field if the given value is not nil.
- func (stc *SopTaskCreate) SetNillableType(i *int) *SopTaskCreate {
- if i != nil {
- stc.SetType(*i)
- }
- return stc
- }
- // SetPlanStartTime sets the "plan_start_time" field.
- func (stc *SopTaskCreate) SetPlanStartTime(t time.Time) *SopTaskCreate {
- stc.mutation.SetPlanStartTime(t)
- return stc
- }
- // SetNillablePlanStartTime sets the "plan_start_time" field if the given value is not nil.
- func (stc *SopTaskCreate) SetNillablePlanStartTime(t *time.Time) *SopTaskCreate {
- if t != nil {
- stc.SetPlanStartTime(*t)
- }
- return stc
- }
- // SetPlanEndTime sets the "plan_end_time" field.
- func (stc *SopTaskCreate) SetPlanEndTime(t time.Time) *SopTaskCreate {
- stc.mutation.SetPlanEndTime(t)
- return stc
- }
- // SetNillablePlanEndTime sets the "plan_end_time" field if the given value is not nil.
- func (stc *SopTaskCreate) SetNillablePlanEndTime(t *time.Time) *SopTaskCreate {
- if t != nil {
- stc.SetPlanEndTime(*t)
- }
- return stc
- }
- // SetCreatorID sets the "creator_id" field.
- func (stc *SopTaskCreate) SetCreatorID(s string) *SopTaskCreate {
- stc.mutation.SetCreatorID(s)
- return stc
- }
- // SetNillableCreatorID sets the "creator_id" field if the given value is not nil.
- func (stc *SopTaskCreate) SetNillableCreatorID(s *string) *SopTaskCreate {
- if s != nil {
- stc.SetCreatorID(*s)
- }
- return stc
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (stc *SopTaskCreate) SetDeletedAt(t time.Time) *SopTaskCreate {
- stc.mutation.SetDeletedAt(t)
- return stc
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (stc *SopTaskCreate) SetNillableDeletedAt(t *time.Time) *SopTaskCreate {
- if t != nil {
- stc.SetDeletedAt(*t)
- }
- return stc
- }
- // SetID sets the "id" field.
- func (stc *SopTaskCreate) SetID(u uint64) *SopTaskCreate {
- stc.mutation.SetID(u)
- return stc
- }
- // AddTaskStageIDs adds the "task_stages" edge to the SopStage entity by IDs.
- func (stc *SopTaskCreate) AddTaskStageIDs(ids ...uint64) *SopTaskCreate {
- stc.mutation.AddTaskStageIDs(ids...)
- return stc
- }
- // AddTaskStages adds the "task_stages" edges to the SopStage entity.
- func (stc *SopTaskCreate) AddTaskStages(s ...*SopStage) *SopTaskCreate {
- ids := make([]uint64, len(s))
- for i := range s {
- ids[i] = s[i].ID
- }
- return stc.AddTaskStageIDs(ids...)
- }
- // Mutation returns the SopTaskMutation object of the builder.
- func (stc *SopTaskCreate) Mutation() *SopTaskMutation {
- return stc.mutation
- }
- // Save creates the SopTask in the database.
- func (stc *SopTaskCreate) Save(ctx context.Context) (*SopTask, error) {
- stc.defaults()
- return withHooks(ctx, stc.sqlSave, stc.mutation, stc.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (stc *SopTaskCreate) SaveX(ctx context.Context) *SopTask {
- v, err := stc.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (stc *SopTaskCreate) Exec(ctx context.Context) error {
- _, err := stc.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (stc *SopTaskCreate) ExecX(ctx context.Context) {
- if err := stc.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (stc *SopTaskCreate) defaults() {
- if _, ok := stc.mutation.CreatedAt(); !ok {
- v := soptask.DefaultCreatedAt()
- stc.mutation.SetCreatedAt(v)
- }
- if _, ok := stc.mutation.UpdatedAt(); !ok {
- v := soptask.DefaultUpdatedAt()
- stc.mutation.SetUpdatedAt(v)
- }
- if _, ok := stc.mutation.Status(); !ok {
- v := soptask.DefaultStatus
- stc.mutation.SetStatus(v)
- }
- if _, ok := stc.mutation.GetType(); !ok {
- v := soptask.DefaultType
- stc.mutation.SetType(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (stc *SopTaskCreate) check() error {
- if _, ok := stc.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SopTask.created_at"`)}
- }
- if _, ok := stc.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "SopTask.updated_at"`)}
- }
- if _, ok := stc.mutation.Name(); !ok {
- return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "SopTask.name"`)}
- }
- if v, ok := stc.mutation.Name(); ok {
- if err := soptask.NameValidator(v); err != nil {
- return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "SopTask.name": %w`, err)}
- }
- }
- if _, ok := stc.mutation.GetType(); !ok {
- return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "SopTask.type"`)}
- }
- return nil
- }
- func (stc *SopTaskCreate) sqlSave(ctx context.Context) (*SopTask, error) {
- if err := stc.check(); err != nil {
- return nil, err
- }
- _node, _spec := stc.createSpec()
- if err := sqlgraph.CreateNode(ctx, stc.driver, _spec); err != nil {
- if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- if _spec.ID.Value != _node.ID {
- id := _spec.ID.Value.(int64)
- _node.ID = uint64(id)
- }
- stc.mutation.id = &_node.ID
- stc.mutation.done = true
- return _node, nil
- }
- func (stc *SopTaskCreate) createSpec() (*SopTask, *sqlgraph.CreateSpec) {
- var (
- _node = &SopTask{config: stc.config}
- _spec = sqlgraph.NewCreateSpec(soptask.Table, sqlgraph.NewFieldSpec(soptask.FieldID, field.TypeUint64))
- )
- if id, ok := stc.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = id
- }
- if value, ok := stc.mutation.CreatedAt(); ok {
- _spec.SetField(soptask.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := stc.mutation.UpdatedAt(); ok {
- _spec.SetField(soptask.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if value, ok := stc.mutation.Status(); ok {
- _spec.SetField(soptask.FieldStatus, field.TypeUint8, value)
- _node.Status = value
- }
- if value, ok := stc.mutation.Name(); ok {
- _spec.SetField(soptask.FieldName, field.TypeString, value)
- _node.Name = value
- }
- if value, ok := stc.mutation.BotWxidList(); ok {
- _spec.SetField(soptask.FieldBotWxidList, field.TypeJSON, value)
- _node.BotWxidList = value
- }
- if value, ok := stc.mutation.GetType(); ok {
- _spec.SetField(soptask.FieldType, field.TypeInt, value)
- _node.Type = value
- }
- if value, ok := stc.mutation.PlanStartTime(); ok {
- _spec.SetField(soptask.FieldPlanStartTime, field.TypeTime, value)
- _node.PlanStartTime = value
- }
- if value, ok := stc.mutation.PlanEndTime(); ok {
- _spec.SetField(soptask.FieldPlanEndTime, field.TypeTime, value)
- _node.PlanEndTime = value
- }
- if value, ok := stc.mutation.CreatorID(); ok {
- _spec.SetField(soptask.FieldCreatorID, field.TypeString, value)
- _node.CreatorID = value
- }
- if value, ok := stc.mutation.DeletedAt(); ok {
- _spec.SetField(soptask.FieldDeletedAt, field.TypeTime, value)
- _node.DeletedAt = value
- }
- if nodes := stc.mutation.TaskStagesIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: soptask.TaskStagesTable,
- Columns: []string{soptask.TaskStagesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges = append(_spec.Edges, edge)
- }
- return _node, _spec
- }
- // SopTaskCreateBulk is the builder for creating many SopTask entities in bulk.
- type SopTaskCreateBulk struct {
- config
- err error
- builders []*SopTaskCreate
- }
- // Save creates the SopTask entities in the database.
- func (stcb *SopTaskCreateBulk) Save(ctx context.Context) ([]*SopTask, error) {
- if stcb.err != nil {
- return nil, stcb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(stcb.builders))
- nodes := make([]*SopTask, len(stcb.builders))
- mutators := make([]Mutator, len(stcb.builders))
- for i := range stcb.builders {
- func(i int, root context.Context) {
- builder := stcb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*SopTaskMutation)
- if !ok {
- return nil, fmt.Errorf("unexpected mutation type %T", m)
- }
- if err := builder.check(); err != nil {
- return nil, err
- }
- builder.mutation = mutation
- var err error
- nodes[i], specs[i] = builder.createSpec()
- if i < len(mutators)-1 {
- _, err = mutators[i+1].Mutate(root, stcb.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, stcb.driver, spec); err != nil {
- if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- }
- }
- if err != nil {
- return nil, err
- }
- mutation.id = &nodes[i].ID
- if specs[i].ID.Value != nil && nodes[i].ID == 0 {
- id := specs[i].ID.Value.(int64)
- nodes[i].ID = uint64(id)
- }
- mutation.done = true
- return nodes[i], nil
- })
- for i := len(builder.hooks) - 1; i >= 0; i-- {
- mut = builder.hooks[i](mut)
- }
- mutators[i] = mut
- }(i, ctx)
- }
- if len(mutators) > 0 {
- if _, err := mutators[0].Mutate(ctx, stcb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (stcb *SopTaskCreateBulk) SaveX(ctx context.Context) []*SopTask {
- v, err := stcb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (stcb *SopTaskCreateBulk) Exec(ctx context.Context) error {
- _, err := stcb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (stcb *SopTaskCreateBulk) ExecX(ctx context.Context) {
- if err := stcb.Exec(ctx); err != nil {
- panic(err)
- }
- }
|