// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"
	"wechat-api/ent/batchmsg"
	"wechat-api/ent/predicate"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// BatchMsgUpdate is the builder for updating BatchMsg entities.
type BatchMsgUpdate struct {
	config
	hooks    []Hook
	mutation *BatchMsgMutation
}

// Where appends a list predicates to the BatchMsgUpdate builder.
func (bmu *BatchMsgUpdate) Where(ps ...predicate.BatchMsg) *BatchMsgUpdate {
	bmu.mutation.Where(ps...)
	return bmu
}

// SetUpdatedAt sets the "updated_at" field.
func (bmu *BatchMsgUpdate) SetUpdatedAt(t time.Time) *BatchMsgUpdate {
	bmu.mutation.SetUpdatedAt(t)
	return bmu
}

// SetDeletedAt sets the "deleted_at" field.
func (bmu *BatchMsgUpdate) SetDeletedAt(t time.Time) *BatchMsgUpdate {
	bmu.mutation.SetDeletedAt(t)
	return bmu
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableDeletedAt(t *time.Time) *BatchMsgUpdate {
	if t != nil {
		bmu.SetDeletedAt(*t)
	}
	return bmu
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (bmu *BatchMsgUpdate) ClearDeletedAt() *BatchMsgUpdate {
	bmu.mutation.ClearDeletedAt()
	return bmu
}

// SetStatus sets the "status" field.
func (bmu *BatchMsgUpdate) SetStatus(u uint8) *BatchMsgUpdate {
	bmu.mutation.ResetStatus()
	bmu.mutation.SetStatus(u)
	return bmu
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableStatus(u *uint8) *BatchMsgUpdate {
	if u != nil {
		bmu.SetStatus(*u)
	}
	return bmu
}

// AddStatus adds u to the "status" field.
func (bmu *BatchMsgUpdate) AddStatus(u int8) *BatchMsgUpdate {
	bmu.mutation.AddStatus(u)
	return bmu
}

// ClearStatus clears the value of the "status" field.
func (bmu *BatchMsgUpdate) ClearStatus() *BatchMsgUpdate {
	bmu.mutation.ClearStatus()
	return bmu
}

// SetBatchNo sets the "batch_no" field.
func (bmu *BatchMsgUpdate) SetBatchNo(s string) *BatchMsgUpdate {
	bmu.mutation.SetBatchNo(s)
	return bmu
}

// SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableBatchNo(s *string) *BatchMsgUpdate {
	if s != nil {
		bmu.SetBatchNo(*s)
	}
	return bmu
}

// ClearBatchNo clears the value of the "batch_no" field.
func (bmu *BatchMsgUpdate) ClearBatchNo() *BatchMsgUpdate {
	bmu.mutation.ClearBatchNo()
	return bmu
}

// SetTaskName sets the "task_name" field.
func (bmu *BatchMsgUpdate) SetTaskName(s string) *BatchMsgUpdate {
	bmu.mutation.SetTaskName(s)
	return bmu
}

// SetNillableTaskName sets the "task_name" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableTaskName(s *string) *BatchMsgUpdate {
	if s != nil {
		bmu.SetTaskName(*s)
	}
	return bmu
}

// ClearTaskName clears the value of the "task_name" field.
func (bmu *BatchMsgUpdate) ClearTaskName() *BatchMsgUpdate {
	bmu.mutation.ClearTaskName()
	return bmu
}

// SetFromwxid sets the "fromwxid" field.
func (bmu *BatchMsgUpdate) SetFromwxid(s string) *BatchMsgUpdate {
	bmu.mutation.SetFromwxid(s)
	return bmu
}

// SetNillableFromwxid sets the "fromwxid" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableFromwxid(s *string) *BatchMsgUpdate {
	if s != nil {
		bmu.SetFromwxid(*s)
	}
	return bmu
}

// ClearFromwxid clears the value of the "fromwxid" field.
func (bmu *BatchMsgUpdate) ClearFromwxid() *BatchMsgUpdate {
	bmu.mutation.ClearFromwxid()
	return bmu
}

// SetMsg sets the "msg" field.
func (bmu *BatchMsgUpdate) SetMsg(s string) *BatchMsgUpdate {
	bmu.mutation.SetMsg(s)
	return bmu
}

// SetNillableMsg sets the "msg" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableMsg(s *string) *BatchMsgUpdate {
	if s != nil {
		bmu.SetMsg(*s)
	}
	return bmu
}

// ClearMsg clears the value of the "msg" field.
func (bmu *BatchMsgUpdate) ClearMsg() *BatchMsgUpdate {
	bmu.mutation.ClearMsg()
	return bmu
}

// SetTag sets the "tag" field.
func (bmu *BatchMsgUpdate) SetTag(s string) *BatchMsgUpdate {
	bmu.mutation.SetTag(s)
	return bmu
}

// SetNillableTag sets the "tag" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableTag(s *string) *BatchMsgUpdate {
	if s != nil {
		bmu.SetTag(*s)
	}
	return bmu
}

// ClearTag clears the value of the "tag" field.
func (bmu *BatchMsgUpdate) ClearTag() *BatchMsgUpdate {
	bmu.mutation.ClearTag()
	return bmu
}

// SetTagids sets the "tagids" field.
func (bmu *BatchMsgUpdate) SetTagids(s string) *BatchMsgUpdate {
	bmu.mutation.SetTagids(s)
	return bmu
}

// SetNillableTagids sets the "tagids" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableTagids(s *string) *BatchMsgUpdate {
	if s != nil {
		bmu.SetTagids(*s)
	}
	return bmu
}

// ClearTagids clears the value of the "tagids" field.
func (bmu *BatchMsgUpdate) ClearTagids() *BatchMsgUpdate {
	bmu.mutation.ClearTagids()
	return bmu
}

// SetTotal sets the "total" field.
func (bmu *BatchMsgUpdate) SetTotal(i int32) *BatchMsgUpdate {
	bmu.mutation.ResetTotal()
	bmu.mutation.SetTotal(i)
	return bmu
}

// SetNillableTotal sets the "total" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableTotal(i *int32) *BatchMsgUpdate {
	if i != nil {
		bmu.SetTotal(*i)
	}
	return bmu
}

// AddTotal adds i to the "total" field.
func (bmu *BatchMsgUpdate) AddTotal(i int32) *BatchMsgUpdate {
	bmu.mutation.AddTotal(i)
	return bmu
}

// ClearTotal clears the value of the "total" field.
func (bmu *BatchMsgUpdate) ClearTotal() *BatchMsgUpdate {
	bmu.mutation.ClearTotal()
	return bmu
}

// SetSuccess sets the "success" field.
func (bmu *BatchMsgUpdate) SetSuccess(i int32) *BatchMsgUpdate {
	bmu.mutation.ResetSuccess()
	bmu.mutation.SetSuccess(i)
	return bmu
}

// SetNillableSuccess sets the "success" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableSuccess(i *int32) *BatchMsgUpdate {
	if i != nil {
		bmu.SetSuccess(*i)
	}
	return bmu
}

// AddSuccess adds i to the "success" field.
func (bmu *BatchMsgUpdate) AddSuccess(i int32) *BatchMsgUpdate {
	bmu.mutation.AddSuccess(i)
	return bmu
}

// ClearSuccess clears the value of the "success" field.
func (bmu *BatchMsgUpdate) ClearSuccess() *BatchMsgUpdate {
	bmu.mutation.ClearSuccess()
	return bmu
}

// SetFail sets the "fail" field.
func (bmu *BatchMsgUpdate) SetFail(i int32) *BatchMsgUpdate {
	bmu.mutation.ResetFail()
	bmu.mutation.SetFail(i)
	return bmu
}

// SetNillableFail sets the "fail" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableFail(i *int32) *BatchMsgUpdate {
	if i != nil {
		bmu.SetFail(*i)
	}
	return bmu
}

// AddFail adds i to the "fail" field.
func (bmu *BatchMsgUpdate) AddFail(i int32) *BatchMsgUpdate {
	bmu.mutation.AddFail(i)
	return bmu
}

// ClearFail clears the value of the "fail" field.
func (bmu *BatchMsgUpdate) ClearFail() *BatchMsgUpdate {
	bmu.mutation.ClearFail()
	return bmu
}

// SetStartTime sets the "start_time" field.
func (bmu *BatchMsgUpdate) SetStartTime(t time.Time) *BatchMsgUpdate {
	bmu.mutation.SetStartTime(t)
	return bmu
}

// SetNillableStartTime sets the "start_time" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableStartTime(t *time.Time) *BatchMsgUpdate {
	if t != nil {
		bmu.SetStartTime(*t)
	}
	return bmu
}

// ClearStartTime clears the value of the "start_time" field.
func (bmu *BatchMsgUpdate) ClearStartTime() *BatchMsgUpdate {
	bmu.mutation.ClearStartTime()
	return bmu
}

// SetStopTime sets the "stop_time" field.
func (bmu *BatchMsgUpdate) SetStopTime(t time.Time) *BatchMsgUpdate {
	bmu.mutation.SetStopTime(t)
	return bmu
}

// SetNillableStopTime sets the "stop_time" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableStopTime(t *time.Time) *BatchMsgUpdate {
	if t != nil {
		bmu.SetStopTime(*t)
	}
	return bmu
}

// ClearStopTime clears the value of the "stop_time" field.
func (bmu *BatchMsgUpdate) ClearStopTime() *BatchMsgUpdate {
	bmu.mutation.ClearStopTime()
	return bmu
}

// SetSendTime sets the "send_time" field.
func (bmu *BatchMsgUpdate) SetSendTime(t time.Time) *BatchMsgUpdate {
	bmu.mutation.SetSendTime(t)
	return bmu
}

// SetNillableSendTime sets the "send_time" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableSendTime(t *time.Time) *BatchMsgUpdate {
	if t != nil {
		bmu.SetSendTime(*t)
	}
	return bmu
}

// ClearSendTime clears the value of the "send_time" field.
func (bmu *BatchMsgUpdate) ClearSendTime() *BatchMsgUpdate {
	bmu.mutation.ClearSendTime()
	return bmu
}

// SetType sets the "type" field.
func (bmu *BatchMsgUpdate) SetType(i int32) *BatchMsgUpdate {
	bmu.mutation.ResetType()
	bmu.mutation.SetType(i)
	return bmu
}

// SetNillableType sets the "type" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableType(i *int32) *BatchMsgUpdate {
	if i != nil {
		bmu.SetType(*i)
	}
	return bmu
}

// AddType adds i to the "type" field.
func (bmu *BatchMsgUpdate) AddType(i int32) *BatchMsgUpdate {
	bmu.mutation.AddType(i)
	return bmu
}

// ClearType clears the value of the "type" field.
func (bmu *BatchMsgUpdate) ClearType() *BatchMsgUpdate {
	bmu.mutation.ClearType()
	return bmu
}

// SetOrganizationID sets the "organization_id" field.
func (bmu *BatchMsgUpdate) SetOrganizationID(u uint64) *BatchMsgUpdate {
	bmu.mutation.ResetOrganizationID()
	bmu.mutation.SetOrganizationID(u)
	return bmu
}

// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableOrganizationID(u *uint64) *BatchMsgUpdate {
	if u != nil {
		bmu.SetOrganizationID(*u)
	}
	return bmu
}

// AddOrganizationID adds u to the "organization_id" field.
func (bmu *BatchMsgUpdate) AddOrganizationID(u int64) *BatchMsgUpdate {
	bmu.mutation.AddOrganizationID(u)
	return bmu
}

// SetCtype sets the "ctype" field.
func (bmu *BatchMsgUpdate) SetCtype(u uint64) *BatchMsgUpdate {
	bmu.mutation.ResetCtype()
	bmu.mutation.SetCtype(u)
	return bmu
}

// SetNillableCtype sets the "ctype" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableCtype(u *uint64) *BatchMsgUpdate {
	if u != nil {
		bmu.SetCtype(*u)
	}
	return bmu
}

// AddCtype adds u to the "ctype" field.
func (bmu *BatchMsgUpdate) AddCtype(u int64) *BatchMsgUpdate {
	bmu.mutation.AddCtype(u)
	return bmu
}

// SetCc sets the "cc" field.
func (bmu *BatchMsgUpdate) SetCc(s string) *BatchMsgUpdate {
	bmu.mutation.SetCc(s)
	return bmu
}

// SetNillableCc sets the "cc" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableCc(s *string) *BatchMsgUpdate {
	if s != nil {
		bmu.SetCc(*s)
	}
	return bmu
}

// ClearCc clears the value of the "cc" field.
func (bmu *BatchMsgUpdate) ClearCc() *BatchMsgUpdate {
	bmu.mutation.ClearCc()
	return bmu
}

// SetPhone sets the "phone" field.
func (bmu *BatchMsgUpdate) SetPhone(s string) *BatchMsgUpdate {
	bmu.mutation.SetPhone(s)
	return bmu
}

// SetNillablePhone sets the "phone" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillablePhone(s *string) *BatchMsgUpdate {
	if s != nil {
		bmu.SetPhone(*s)
	}
	return bmu
}

// ClearPhone clears the value of the "phone" field.
func (bmu *BatchMsgUpdate) ClearPhone() *BatchMsgUpdate {
	bmu.mutation.ClearPhone()
	return bmu
}

// SetTemplateName sets the "template_name" field.
func (bmu *BatchMsgUpdate) SetTemplateName(s string) *BatchMsgUpdate {
	bmu.mutation.SetTemplateName(s)
	return bmu
}

// SetNillableTemplateName sets the "template_name" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableTemplateName(s *string) *BatchMsgUpdate {
	if s != nil {
		bmu.SetTemplateName(*s)
	}
	return bmu
}

// ClearTemplateName clears the value of the "template_name" field.
func (bmu *BatchMsgUpdate) ClearTemplateName() *BatchMsgUpdate {
	bmu.mutation.ClearTemplateName()
	return bmu
}

// SetTemplateCode sets the "template_code" field.
func (bmu *BatchMsgUpdate) SetTemplateCode(s string) *BatchMsgUpdate {
	bmu.mutation.SetTemplateCode(s)
	return bmu
}

// SetNillableTemplateCode sets the "template_code" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableTemplateCode(s *string) *BatchMsgUpdate {
	if s != nil {
		bmu.SetTemplateCode(*s)
	}
	return bmu
}

// ClearTemplateCode clears the value of the "template_code" field.
func (bmu *BatchMsgUpdate) ClearTemplateCode() *BatchMsgUpdate {
	bmu.mutation.ClearTemplateCode()
	return bmu
}

// SetLang sets the "lang" field.
func (bmu *BatchMsgUpdate) SetLang(s string) *BatchMsgUpdate {
	bmu.mutation.SetLang(s)
	return bmu
}

// SetNillableLang sets the "lang" field if the given value is not nil.
func (bmu *BatchMsgUpdate) SetNillableLang(s *string) *BatchMsgUpdate {
	if s != nil {
		bmu.SetLang(*s)
	}
	return bmu
}

// ClearLang clears the value of the "lang" field.
func (bmu *BatchMsgUpdate) ClearLang() *BatchMsgUpdate {
	bmu.mutation.ClearLang()
	return bmu
}

// Mutation returns the BatchMsgMutation object of the builder.
func (bmu *BatchMsgUpdate) Mutation() *BatchMsgMutation {
	return bmu.mutation
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (bmu *BatchMsgUpdate) Save(ctx context.Context) (int, error) {
	if err := bmu.defaults(); err != nil {
		return 0, err
	}
	return withHooks(ctx, bmu.sqlSave, bmu.mutation, bmu.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (bmu *BatchMsgUpdate) SaveX(ctx context.Context) int {
	affected, err := bmu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

// Exec executes the query.
func (bmu *BatchMsgUpdate) Exec(ctx context.Context) error {
	_, err := bmu.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (bmu *BatchMsgUpdate) ExecX(ctx context.Context) {
	if err := bmu.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (bmu *BatchMsgUpdate) defaults() error {
	if _, ok := bmu.mutation.UpdatedAt(); !ok {
		if batchmsg.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized batchmsg.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := batchmsg.UpdateDefaultUpdatedAt()
		bmu.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (bmu *BatchMsgUpdate) check() error {
	if v, ok := bmu.mutation.OrganizationID(); ok {
		if err := batchmsg.OrganizationIDValidator(v); err != nil {
			return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "BatchMsg.organization_id": %w`, err)}
		}
	}
	return nil
}

func (bmu *BatchMsgUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := bmu.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(batchmsg.Table, batchmsg.Columns, sqlgraph.NewFieldSpec(batchmsg.FieldID, field.TypeUint64))
	if ps := bmu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := bmu.mutation.UpdatedAt(); ok {
		_spec.SetField(batchmsg.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := bmu.mutation.DeletedAt(); ok {
		_spec.SetField(batchmsg.FieldDeletedAt, field.TypeTime, value)
	}
	if bmu.mutation.DeletedAtCleared() {
		_spec.ClearField(batchmsg.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := bmu.mutation.Status(); ok {
		_spec.SetField(batchmsg.FieldStatus, field.TypeUint8, value)
	}
	if value, ok := bmu.mutation.AddedStatus(); ok {
		_spec.AddField(batchmsg.FieldStatus, field.TypeUint8, value)
	}
	if bmu.mutation.StatusCleared() {
		_spec.ClearField(batchmsg.FieldStatus, field.TypeUint8)
	}
	if value, ok := bmu.mutation.BatchNo(); ok {
		_spec.SetField(batchmsg.FieldBatchNo, field.TypeString, value)
	}
	if bmu.mutation.BatchNoCleared() {
		_spec.ClearField(batchmsg.FieldBatchNo, field.TypeString)
	}
	if value, ok := bmu.mutation.TaskName(); ok {
		_spec.SetField(batchmsg.FieldTaskName, field.TypeString, value)
	}
	if bmu.mutation.TaskNameCleared() {
		_spec.ClearField(batchmsg.FieldTaskName, field.TypeString)
	}
	if value, ok := bmu.mutation.Fromwxid(); ok {
		_spec.SetField(batchmsg.FieldFromwxid, field.TypeString, value)
	}
	if bmu.mutation.FromwxidCleared() {
		_spec.ClearField(batchmsg.FieldFromwxid, field.TypeString)
	}
	if value, ok := bmu.mutation.Msg(); ok {
		_spec.SetField(batchmsg.FieldMsg, field.TypeString, value)
	}
	if bmu.mutation.MsgCleared() {
		_spec.ClearField(batchmsg.FieldMsg, field.TypeString)
	}
	if value, ok := bmu.mutation.Tag(); ok {
		_spec.SetField(batchmsg.FieldTag, field.TypeString, value)
	}
	if bmu.mutation.TagCleared() {
		_spec.ClearField(batchmsg.FieldTag, field.TypeString)
	}
	if value, ok := bmu.mutation.Tagids(); ok {
		_spec.SetField(batchmsg.FieldTagids, field.TypeString, value)
	}
	if bmu.mutation.TagidsCleared() {
		_spec.ClearField(batchmsg.FieldTagids, field.TypeString)
	}
	if value, ok := bmu.mutation.Total(); ok {
		_spec.SetField(batchmsg.FieldTotal, field.TypeInt32, value)
	}
	if value, ok := bmu.mutation.AddedTotal(); ok {
		_spec.AddField(batchmsg.FieldTotal, field.TypeInt32, value)
	}
	if bmu.mutation.TotalCleared() {
		_spec.ClearField(batchmsg.FieldTotal, field.TypeInt32)
	}
	if value, ok := bmu.mutation.Success(); ok {
		_spec.SetField(batchmsg.FieldSuccess, field.TypeInt32, value)
	}
	if value, ok := bmu.mutation.AddedSuccess(); ok {
		_spec.AddField(batchmsg.FieldSuccess, field.TypeInt32, value)
	}
	if bmu.mutation.SuccessCleared() {
		_spec.ClearField(batchmsg.FieldSuccess, field.TypeInt32)
	}
	if value, ok := bmu.mutation.Fail(); ok {
		_spec.SetField(batchmsg.FieldFail, field.TypeInt32, value)
	}
	if value, ok := bmu.mutation.AddedFail(); ok {
		_spec.AddField(batchmsg.FieldFail, field.TypeInt32, value)
	}
	if bmu.mutation.FailCleared() {
		_spec.ClearField(batchmsg.FieldFail, field.TypeInt32)
	}
	if value, ok := bmu.mutation.StartTime(); ok {
		_spec.SetField(batchmsg.FieldStartTime, field.TypeTime, value)
	}
	if bmu.mutation.StartTimeCleared() {
		_spec.ClearField(batchmsg.FieldStartTime, field.TypeTime)
	}
	if value, ok := bmu.mutation.StopTime(); ok {
		_spec.SetField(batchmsg.FieldStopTime, field.TypeTime, value)
	}
	if bmu.mutation.StopTimeCleared() {
		_spec.ClearField(batchmsg.FieldStopTime, field.TypeTime)
	}
	if value, ok := bmu.mutation.SendTime(); ok {
		_spec.SetField(batchmsg.FieldSendTime, field.TypeTime, value)
	}
	if bmu.mutation.SendTimeCleared() {
		_spec.ClearField(batchmsg.FieldSendTime, field.TypeTime)
	}
	if value, ok := bmu.mutation.GetType(); ok {
		_spec.SetField(batchmsg.FieldType, field.TypeInt32, value)
	}
	if value, ok := bmu.mutation.AddedType(); ok {
		_spec.AddField(batchmsg.FieldType, field.TypeInt32, value)
	}
	if bmu.mutation.TypeCleared() {
		_spec.ClearField(batchmsg.FieldType, field.TypeInt32)
	}
	if value, ok := bmu.mutation.OrganizationID(); ok {
		_spec.SetField(batchmsg.FieldOrganizationID, field.TypeUint64, value)
	}
	if value, ok := bmu.mutation.AddedOrganizationID(); ok {
		_spec.AddField(batchmsg.FieldOrganizationID, field.TypeUint64, value)
	}
	if value, ok := bmu.mutation.Ctype(); ok {
		_spec.SetField(batchmsg.FieldCtype, field.TypeUint64, value)
	}
	if value, ok := bmu.mutation.AddedCtype(); ok {
		_spec.AddField(batchmsg.FieldCtype, field.TypeUint64, value)
	}
	if value, ok := bmu.mutation.Cc(); ok {
		_spec.SetField(batchmsg.FieldCc, field.TypeString, value)
	}
	if bmu.mutation.CcCleared() {
		_spec.ClearField(batchmsg.FieldCc, field.TypeString)
	}
	if value, ok := bmu.mutation.Phone(); ok {
		_spec.SetField(batchmsg.FieldPhone, field.TypeString, value)
	}
	if bmu.mutation.PhoneCleared() {
		_spec.ClearField(batchmsg.FieldPhone, field.TypeString)
	}
	if value, ok := bmu.mutation.TemplateName(); ok {
		_spec.SetField(batchmsg.FieldTemplateName, field.TypeString, value)
	}
	if bmu.mutation.TemplateNameCleared() {
		_spec.ClearField(batchmsg.FieldTemplateName, field.TypeString)
	}
	if value, ok := bmu.mutation.TemplateCode(); ok {
		_spec.SetField(batchmsg.FieldTemplateCode, field.TypeString, value)
	}
	if bmu.mutation.TemplateCodeCleared() {
		_spec.ClearField(batchmsg.FieldTemplateCode, field.TypeString)
	}
	if value, ok := bmu.mutation.Lang(); ok {
		_spec.SetField(batchmsg.FieldLang, field.TypeString, value)
	}
	if bmu.mutation.LangCleared() {
		_spec.ClearField(batchmsg.FieldLang, field.TypeString)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, bmu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{batchmsg.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	bmu.mutation.done = true
	return n, nil
}

// BatchMsgUpdateOne is the builder for updating a single BatchMsg entity.
type BatchMsgUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *BatchMsgMutation
}

// SetUpdatedAt sets the "updated_at" field.
func (bmuo *BatchMsgUpdateOne) SetUpdatedAt(t time.Time) *BatchMsgUpdateOne {
	bmuo.mutation.SetUpdatedAt(t)
	return bmuo
}

// SetDeletedAt sets the "deleted_at" field.
func (bmuo *BatchMsgUpdateOne) SetDeletedAt(t time.Time) *BatchMsgUpdateOne {
	bmuo.mutation.SetDeletedAt(t)
	return bmuo
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableDeletedAt(t *time.Time) *BatchMsgUpdateOne {
	if t != nil {
		bmuo.SetDeletedAt(*t)
	}
	return bmuo
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (bmuo *BatchMsgUpdateOne) ClearDeletedAt() *BatchMsgUpdateOne {
	bmuo.mutation.ClearDeletedAt()
	return bmuo
}

// SetStatus sets the "status" field.
func (bmuo *BatchMsgUpdateOne) SetStatus(u uint8) *BatchMsgUpdateOne {
	bmuo.mutation.ResetStatus()
	bmuo.mutation.SetStatus(u)
	return bmuo
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableStatus(u *uint8) *BatchMsgUpdateOne {
	if u != nil {
		bmuo.SetStatus(*u)
	}
	return bmuo
}

// AddStatus adds u to the "status" field.
func (bmuo *BatchMsgUpdateOne) AddStatus(u int8) *BatchMsgUpdateOne {
	bmuo.mutation.AddStatus(u)
	return bmuo
}

// ClearStatus clears the value of the "status" field.
func (bmuo *BatchMsgUpdateOne) ClearStatus() *BatchMsgUpdateOne {
	bmuo.mutation.ClearStatus()
	return bmuo
}

// SetBatchNo sets the "batch_no" field.
func (bmuo *BatchMsgUpdateOne) SetBatchNo(s string) *BatchMsgUpdateOne {
	bmuo.mutation.SetBatchNo(s)
	return bmuo
}

// SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableBatchNo(s *string) *BatchMsgUpdateOne {
	if s != nil {
		bmuo.SetBatchNo(*s)
	}
	return bmuo
}

// ClearBatchNo clears the value of the "batch_no" field.
func (bmuo *BatchMsgUpdateOne) ClearBatchNo() *BatchMsgUpdateOne {
	bmuo.mutation.ClearBatchNo()
	return bmuo
}

// SetTaskName sets the "task_name" field.
func (bmuo *BatchMsgUpdateOne) SetTaskName(s string) *BatchMsgUpdateOne {
	bmuo.mutation.SetTaskName(s)
	return bmuo
}

// SetNillableTaskName sets the "task_name" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableTaskName(s *string) *BatchMsgUpdateOne {
	if s != nil {
		bmuo.SetTaskName(*s)
	}
	return bmuo
}

// ClearTaskName clears the value of the "task_name" field.
func (bmuo *BatchMsgUpdateOne) ClearTaskName() *BatchMsgUpdateOne {
	bmuo.mutation.ClearTaskName()
	return bmuo
}

// SetFromwxid sets the "fromwxid" field.
func (bmuo *BatchMsgUpdateOne) SetFromwxid(s string) *BatchMsgUpdateOne {
	bmuo.mutation.SetFromwxid(s)
	return bmuo
}

// SetNillableFromwxid sets the "fromwxid" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableFromwxid(s *string) *BatchMsgUpdateOne {
	if s != nil {
		bmuo.SetFromwxid(*s)
	}
	return bmuo
}

// ClearFromwxid clears the value of the "fromwxid" field.
func (bmuo *BatchMsgUpdateOne) ClearFromwxid() *BatchMsgUpdateOne {
	bmuo.mutation.ClearFromwxid()
	return bmuo
}

// SetMsg sets the "msg" field.
func (bmuo *BatchMsgUpdateOne) SetMsg(s string) *BatchMsgUpdateOne {
	bmuo.mutation.SetMsg(s)
	return bmuo
}

// SetNillableMsg sets the "msg" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableMsg(s *string) *BatchMsgUpdateOne {
	if s != nil {
		bmuo.SetMsg(*s)
	}
	return bmuo
}

// ClearMsg clears the value of the "msg" field.
func (bmuo *BatchMsgUpdateOne) ClearMsg() *BatchMsgUpdateOne {
	bmuo.mutation.ClearMsg()
	return bmuo
}

// SetTag sets the "tag" field.
func (bmuo *BatchMsgUpdateOne) SetTag(s string) *BatchMsgUpdateOne {
	bmuo.mutation.SetTag(s)
	return bmuo
}

// SetNillableTag sets the "tag" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableTag(s *string) *BatchMsgUpdateOne {
	if s != nil {
		bmuo.SetTag(*s)
	}
	return bmuo
}

// ClearTag clears the value of the "tag" field.
func (bmuo *BatchMsgUpdateOne) ClearTag() *BatchMsgUpdateOne {
	bmuo.mutation.ClearTag()
	return bmuo
}

// SetTagids sets the "tagids" field.
func (bmuo *BatchMsgUpdateOne) SetTagids(s string) *BatchMsgUpdateOne {
	bmuo.mutation.SetTagids(s)
	return bmuo
}

// SetNillableTagids sets the "tagids" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableTagids(s *string) *BatchMsgUpdateOne {
	if s != nil {
		bmuo.SetTagids(*s)
	}
	return bmuo
}

// ClearTagids clears the value of the "tagids" field.
func (bmuo *BatchMsgUpdateOne) ClearTagids() *BatchMsgUpdateOne {
	bmuo.mutation.ClearTagids()
	return bmuo
}

// SetTotal sets the "total" field.
func (bmuo *BatchMsgUpdateOne) SetTotal(i int32) *BatchMsgUpdateOne {
	bmuo.mutation.ResetTotal()
	bmuo.mutation.SetTotal(i)
	return bmuo
}

// SetNillableTotal sets the "total" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableTotal(i *int32) *BatchMsgUpdateOne {
	if i != nil {
		bmuo.SetTotal(*i)
	}
	return bmuo
}

// AddTotal adds i to the "total" field.
func (bmuo *BatchMsgUpdateOne) AddTotal(i int32) *BatchMsgUpdateOne {
	bmuo.mutation.AddTotal(i)
	return bmuo
}

// ClearTotal clears the value of the "total" field.
func (bmuo *BatchMsgUpdateOne) ClearTotal() *BatchMsgUpdateOne {
	bmuo.mutation.ClearTotal()
	return bmuo
}

// SetSuccess sets the "success" field.
func (bmuo *BatchMsgUpdateOne) SetSuccess(i int32) *BatchMsgUpdateOne {
	bmuo.mutation.ResetSuccess()
	bmuo.mutation.SetSuccess(i)
	return bmuo
}

// SetNillableSuccess sets the "success" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableSuccess(i *int32) *BatchMsgUpdateOne {
	if i != nil {
		bmuo.SetSuccess(*i)
	}
	return bmuo
}

// AddSuccess adds i to the "success" field.
func (bmuo *BatchMsgUpdateOne) AddSuccess(i int32) *BatchMsgUpdateOne {
	bmuo.mutation.AddSuccess(i)
	return bmuo
}

// ClearSuccess clears the value of the "success" field.
func (bmuo *BatchMsgUpdateOne) ClearSuccess() *BatchMsgUpdateOne {
	bmuo.mutation.ClearSuccess()
	return bmuo
}

// SetFail sets the "fail" field.
func (bmuo *BatchMsgUpdateOne) SetFail(i int32) *BatchMsgUpdateOne {
	bmuo.mutation.ResetFail()
	bmuo.mutation.SetFail(i)
	return bmuo
}

// SetNillableFail sets the "fail" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableFail(i *int32) *BatchMsgUpdateOne {
	if i != nil {
		bmuo.SetFail(*i)
	}
	return bmuo
}

// AddFail adds i to the "fail" field.
func (bmuo *BatchMsgUpdateOne) AddFail(i int32) *BatchMsgUpdateOne {
	bmuo.mutation.AddFail(i)
	return bmuo
}

// ClearFail clears the value of the "fail" field.
func (bmuo *BatchMsgUpdateOne) ClearFail() *BatchMsgUpdateOne {
	bmuo.mutation.ClearFail()
	return bmuo
}

// SetStartTime sets the "start_time" field.
func (bmuo *BatchMsgUpdateOne) SetStartTime(t time.Time) *BatchMsgUpdateOne {
	bmuo.mutation.SetStartTime(t)
	return bmuo
}

// SetNillableStartTime sets the "start_time" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableStartTime(t *time.Time) *BatchMsgUpdateOne {
	if t != nil {
		bmuo.SetStartTime(*t)
	}
	return bmuo
}

// ClearStartTime clears the value of the "start_time" field.
func (bmuo *BatchMsgUpdateOne) ClearStartTime() *BatchMsgUpdateOne {
	bmuo.mutation.ClearStartTime()
	return bmuo
}

// SetStopTime sets the "stop_time" field.
func (bmuo *BatchMsgUpdateOne) SetStopTime(t time.Time) *BatchMsgUpdateOne {
	bmuo.mutation.SetStopTime(t)
	return bmuo
}

// SetNillableStopTime sets the "stop_time" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableStopTime(t *time.Time) *BatchMsgUpdateOne {
	if t != nil {
		bmuo.SetStopTime(*t)
	}
	return bmuo
}

// ClearStopTime clears the value of the "stop_time" field.
func (bmuo *BatchMsgUpdateOne) ClearStopTime() *BatchMsgUpdateOne {
	bmuo.mutation.ClearStopTime()
	return bmuo
}

// SetSendTime sets the "send_time" field.
func (bmuo *BatchMsgUpdateOne) SetSendTime(t time.Time) *BatchMsgUpdateOne {
	bmuo.mutation.SetSendTime(t)
	return bmuo
}

// SetNillableSendTime sets the "send_time" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableSendTime(t *time.Time) *BatchMsgUpdateOne {
	if t != nil {
		bmuo.SetSendTime(*t)
	}
	return bmuo
}

// ClearSendTime clears the value of the "send_time" field.
func (bmuo *BatchMsgUpdateOne) ClearSendTime() *BatchMsgUpdateOne {
	bmuo.mutation.ClearSendTime()
	return bmuo
}

// SetType sets the "type" field.
func (bmuo *BatchMsgUpdateOne) SetType(i int32) *BatchMsgUpdateOne {
	bmuo.mutation.ResetType()
	bmuo.mutation.SetType(i)
	return bmuo
}

// SetNillableType sets the "type" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableType(i *int32) *BatchMsgUpdateOne {
	if i != nil {
		bmuo.SetType(*i)
	}
	return bmuo
}

// AddType adds i to the "type" field.
func (bmuo *BatchMsgUpdateOne) AddType(i int32) *BatchMsgUpdateOne {
	bmuo.mutation.AddType(i)
	return bmuo
}

// ClearType clears the value of the "type" field.
func (bmuo *BatchMsgUpdateOne) ClearType() *BatchMsgUpdateOne {
	bmuo.mutation.ClearType()
	return bmuo
}

// SetOrganizationID sets the "organization_id" field.
func (bmuo *BatchMsgUpdateOne) SetOrganizationID(u uint64) *BatchMsgUpdateOne {
	bmuo.mutation.ResetOrganizationID()
	bmuo.mutation.SetOrganizationID(u)
	return bmuo
}

// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableOrganizationID(u *uint64) *BatchMsgUpdateOne {
	if u != nil {
		bmuo.SetOrganizationID(*u)
	}
	return bmuo
}

// AddOrganizationID adds u to the "organization_id" field.
func (bmuo *BatchMsgUpdateOne) AddOrganizationID(u int64) *BatchMsgUpdateOne {
	bmuo.mutation.AddOrganizationID(u)
	return bmuo
}

// SetCtype sets the "ctype" field.
func (bmuo *BatchMsgUpdateOne) SetCtype(u uint64) *BatchMsgUpdateOne {
	bmuo.mutation.ResetCtype()
	bmuo.mutation.SetCtype(u)
	return bmuo
}

// SetNillableCtype sets the "ctype" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableCtype(u *uint64) *BatchMsgUpdateOne {
	if u != nil {
		bmuo.SetCtype(*u)
	}
	return bmuo
}

// AddCtype adds u to the "ctype" field.
func (bmuo *BatchMsgUpdateOne) AddCtype(u int64) *BatchMsgUpdateOne {
	bmuo.mutation.AddCtype(u)
	return bmuo
}

// SetCc sets the "cc" field.
func (bmuo *BatchMsgUpdateOne) SetCc(s string) *BatchMsgUpdateOne {
	bmuo.mutation.SetCc(s)
	return bmuo
}

// SetNillableCc sets the "cc" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableCc(s *string) *BatchMsgUpdateOne {
	if s != nil {
		bmuo.SetCc(*s)
	}
	return bmuo
}

// ClearCc clears the value of the "cc" field.
func (bmuo *BatchMsgUpdateOne) ClearCc() *BatchMsgUpdateOne {
	bmuo.mutation.ClearCc()
	return bmuo
}

// SetPhone sets the "phone" field.
func (bmuo *BatchMsgUpdateOne) SetPhone(s string) *BatchMsgUpdateOne {
	bmuo.mutation.SetPhone(s)
	return bmuo
}

// SetNillablePhone sets the "phone" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillablePhone(s *string) *BatchMsgUpdateOne {
	if s != nil {
		bmuo.SetPhone(*s)
	}
	return bmuo
}

// ClearPhone clears the value of the "phone" field.
func (bmuo *BatchMsgUpdateOne) ClearPhone() *BatchMsgUpdateOne {
	bmuo.mutation.ClearPhone()
	return bmuo
}

// SetTemplateName sets the "template_name" field.
func (bmuo *BatchMsgUpdateOne) SetTemplateName(s string) *BatchMsgUpdateOne {
	bmuo.mutation.SetTemplateName(s)
	return bmuo
}

// SetNillableTemplateName sets the "template_name" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableTemplateName(s *string) *BatchMsgUpdateOne {
	if s != nil {
		bmuo.SetTemplateName(*s)
	}
	return bmuo
}

// ClearTemplateName clears the value of the "template_name" field.
func (bmuo *BatchMsgUpdateOne) ClearTemplateName() *BatchMsgUpdateOne {
	bmuo.mutation.ClearTemplateName()
	return bmuo
}

// SetTemplateCode sets the "template_code" field.
func (bmuo *BatchMsgUpdateOne) SetTemplateCode(s string) *BatchMsgUpdateOne {
	bmuo.mutation.SetTemplateCode(s)
	return bmuo
}

// SetNillableTemplateCode sets the "template_code" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableTemplateCode(s *string) *BatchMsgUpdateOne {
	if s != nil {
		bmuo.SetTemplateCode(*s)
	}
	return bmuo
}

// ClearTemplateCode clears the value of the "template_code" field.
func (bmuo *BatchMsgUpdateOne) ClearTemplateCode() *BatchMsgUpdateOne {
	bmuo.mutation.ClearTemplateCode()
	return bmuo
}

// SetLang sets the "lang" field.
func (bmuo *BatchMsgUpdateOne) SetLang(s string) *BatchMsgUpdateOne {
	bmuo.mutation.SetLang(s)
	return bmuo
}

// SetNillableLang sets the "lang" field if the given value is not nil.
func (bmuo *BatchMsgUpdateOne) SetNillableLang(s *string) *BatchMsgUpdateOne {
	if s != nil {
		bmuo.SetLang(*s)
	}
	return bmuo
}

// ClearLang clears the value of the "lang" field.
func (bmuo *BatchMsgUpdateOne) ClearLang() *BatchMsgUpdateOne {
	bmuo.mutation.ClearLang()
	return bmuo
}

// Mutation returns the BatchMsgMutation object of the builder.
func (bmuo *BatchMsgUpdateOne) Mutation() *BatchMsgMutation {
	return bmuo.mutation
}

// Where appends a list predicates to the BatchMsgUpdate builder.
func (bmuo *BatchMsgUpdateOne) Where(ps ...predicate.BatchMsg) *BatchMsgUpdateOne {
	bmuo.mutation.Where(ps...)
	return bmuo
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (bmuo *BatchMsgUpdateOne) Select(field string, fields ...string) *BatchMsgUpdateOne {
	bmuo.fields = append([]string{field}, fields...)
	return bmuo
}

// Save executes the query and returns the updated BatchMsg entity.
func (bmuo *BatchMsgUpdateOne) Save(ctx context.Context) (*BatchMsg, error) {
	if err := bmuo.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, bmuo.sqlSave, bmuo.mutation, bmuo.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (bmuo *BatchMsgUpdateOne) SaveX(ctx context.Context) *BatchMsg {
	node, err := bmuo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (bmuo *BatchMsgUpdateOne) Exec(ctx context.Context) error {
	_, err := bmuo.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (bmuo *BatchMsgUpdateOne) ExecX(ctx context.Context) {
	if err := bmuo.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (bmuo *BatchMsgUpdateOne) defaults() error {
	if _, ok := bmuo.mutation.UpdatedAt(); !ok {
		if batchmsg.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized batchmsg.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := batchmsg.UpdateDefaultUpdatedAt()
		bmuo.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (bmuo *BatchMsgUpdateOne) check() error {
	if v, ok := bmuo.mutation.OrganizationID(); ok {
		if err := batchmsg.OrganizationIDValidator(v); err != nil {
			return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "BatchMsg.organization_id": %w`, err)}
		}
	}
	return nil
}

func (bmuo *BatchMsgUpdateOne) sqlSave(ctx context.Context) (_node *BatchMsg, err error) {
	if err := bmuo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(batchmsg.Table, batchmsg.Columns, sqlgraph.NewFieldSpec(batchmsg.FieldID, field.TypeUint64))
	id, ok := bmuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "BatchMsg.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := bmuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, batchmsg.FieldID)
		for _, f := range fields {
			if !batchmsg.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != batchmsg.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := bmuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := bmuo.mutation.UpdatedAt(); ok {
		_spec.SetField(batchmsg.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := bmuo.mutation.DeletedAt(); ok {
		_spec.SetField(batchmsg.FieldDeletedAt, field.TypeTime, value)
	}
	if bmuo.mutation.DeletedAtCleared() {
		_spec.ClearField(batchmsg.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := bmuo.mutation.Status(); ok {
		_spec.SetField(batchmsg.FieldStatus, field.TypeUint8, value)
	}
	if value, ok := bmuo.mutation.AddedStatus(); ok {
		_spec.AddField(batchmsg.FieldStatus, field.TypeUint8, value)
	}
	if bmuo.mutation.StatusCleared() {
		_spec.ClearField(batchmsg.FieldStatus, field.TypeUint8)
	}
	if value, ok := bmuo.mutation.BatchNo(); ok {
		_spec.SetField(batchmsg.FieldBatchNo, field.TypeString, value)
	}
	if bmuo.mutation.BatchNoCleared() {
		_spec.ClearField(batchmsg.FieldBatchNo, field.TypeString)
	}
	if value, ok := bmuo.mutation.TaskName(); ok {
		_spec.SetField(batchmsg.FieldTaskName, field.TypeString, value)
	}
	if bmuo.mutation.TaskNameCleared() {
		_spec.ClearField(batchmsg.FieldTaskName, field.TypeString)
	}
	if value, ok := bmuo.mutation.Fromwxid(); ok {
		_spec.SetField(batchmsg.FieldFromwxid, field.TypeString, value)
	}
	if bmuo.mutation.FromwxidCleared() {
		_spec.ClearField(batchmsg.FieldFromwxid, field.TypeString)
	}
	if value, ok := bmuo.mutation.Msg(); ok {
		_spec.SetField(batchmsg.FieldMsg, field.TypeString, value)
	}
	if bmuo.mutation.MsgCleared() {
		_spec.ClearField(batchmsg.FieldMsg, field.TypeString)
	}
	if value, ok := bmuo.mutation.Tag(); ok {
		_spec.SetField(batchmsg.FieldTag, field.TypeString, value)
	}
	if bmuo.mutation.TagCleared() {
		_spec.ClearField(batchmsg.FieldTag, field.TypeString)
	}
	if value, ok := bmuo.mutation.Tagids(); ok {
		_spec.SetField(batchmsg.FieldTagids, field.TypeString, value)
	}
	if bmuo.mutation.TagidsCleared() {
		_spec.ClearField(batchmsg.FieldTagids, field.TypeString)
	}
	if value, ok := bmuo.mutation.Total(); ok {
		_spec.SetField(batchmsg.FieldTotal, field.TypeInt32, value)
	}
	if value, ok := bmuo.mutation.AddedTotal(); ok {
		_spec.AddField(batchmsg.FieldTotal, field.TypeInt32, value)
	}
	if bmuo.mutation.TotalCleared() {
		_spec.ClearField(batchmsg.FieldTotal, field.TypeInt32)
	}
	if value, ok := bmuo.mutation.Success(); ok {
		_spec.SetField(batchmsg.FieldSuccess, field.TypeInt32, value)
	}
	if value, ok := bmuo.mutation.AddedSuccess(); ok {
		_spec.AddField(batchmsg.FieldSuccess, field.TypeInt32, value)
	}
	if bmuo.mutation.SuccessCleared() {
		_spec.ClearField(batchmsg.FieldSuccess, field.TypeInt32)
	}
	if value, ok := bmuo.mutation.Fail(); ok {
		_spec.SetField(batchmsg.FieldFail, field.TypeInt32, value)
	}
	if value, ok := bmuo.mutation.AddedFail(); ok {
		_spec.AddField(batchmsg.FieldFail, field.TypeInt32, value)
	}
	if bmuo.mutation.FailCleared() {
		_spec.ClearField(batchmsg.FieldFail, field.TypeInt32)
	}
	if value, ok := bmuo.mutation.StartTime(); ok {
		_spec.SetField(batchmsg.FieldStartTime, field.TypeTime, value)
	}
	if bmuo.mutation.StartTimeCleared() {
		_spec.ClearField(batchmsg.FieldStartTime, field.TypeTime)
	}
	if value, ok := bmuo.mutation.StopTime(); ok {
		_spec.SetField(batchmsg.FieldStopTime, field.TypeTime, value)
	}
	if bmuo.mutation.StopTimeCleared() {
		_spec.ClearField(batchmsg.FieldStopTime, field.TypeTime)
	}
	if value, ok := bmuo.mutation.SendTime(); ok {
		_spec.SetField(batchmsg.FieldSendTime, field.TypeTime, value)
	}
	if bmuo.mutation.SendTimeCleared() {
		_spec.ClearField(batchmsg.FieldSendTime, field.TypeTime)
	}
	if value, ok := bmuo.mutation.GetType(); ok {
		_spec.SetField(batchmsg.FieldType, field.TypeInt32, value)
	}
	if value, ok := bmuo.mutation.AddedType(); ok {
		_spec.AddField(batchmsg.FieldType, field.TypeInt32, value)
	}
	if bmuo.mutation.TypeCleared() {
		_spec.ClearField(batchmsg.FieldType, field.TypeInt32)
	}
	if value, ok := bmuo.mutation.OrganizationID(); ok {
		_spec.SetField(batchmsg.FieldOrganizationID, field.TypeUint64, value)
	}
	if value, ok := bmuo.mutation.AddedOrganizationID(); ok {
		_spec.AddField(batchmsg.FieldOrganizationID, field.TypeUint64, value)
	}
	if value, ok := bmuo.mutation.Ctype(); ok {
		_spec.SetField(batchmsg.FieldCtype, field.TypeUint64, value)
	}
	if value, ok := bmuo.mutation.AddedCtype(); ok {
		_spec.AddField(batchmsg.FieldCtype, field.TypeUint64, value)
	}
	if value, ok := bmuo.mutation.Cc(); ok {
		_spec.SetField(batchmsg.FieldCc, field.TypeString, value)
	}
	if bmuo.mutation.CcCleared() {
		_spec.ClearField(batchmsg.FieldCc, field.TypeString)
	}
	if value, ok := bmuo.mutation.Phone(); ok {
		_spec.SetField(batchmsg.FieldPhone, field.TypeString, value)
	}
	if bmuo.mutation.PhoneCleared() {
		_spec.ClearField(batchmsg.FieldPhone, field.TypeString)
	}
	if value, ok := bmuo.mutation.TemplateName(); ok {
		_spec.SetField(batchmsg.FieldTemplateName, field.TypeString, value)
	}
	if bmuo.mutation.TemplateNameCleared() {
		_spec.ClearField(batchmsg.FieldTemplateName, field.TypeString)
	}
	if value, ok := bmuo.mutation.TemplateCode(); ok {
		_spec.SetField(batchmsg.FieldTemplateCode, field.TypeString, value)
	}
	if bmuo.mutation.TemplateCodeCleared() {
		_spec.ClearField(batchmsg.FieldTemplateCode, field.TypeString)
	}
	if value, ok := bmuo.mutation.Lang(); ok {
		_spec.SetField(batchmsg.FieldLang, field.TypeString, value)
	}
	if bmuo.mutation.LangCleared() {
		_spec.ClearField(batchmsg.FieldLang, field.TypeString)
	}
	_node = &BatchMsg{config: bmuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, bmuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{batchmsg.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	bmuo.mutation.done = true
	return _node, nil
}
