// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.

package query

import (
	"context"

	"gorm.io/gorm"
	"gorm.io/gorm/clause"
	"gorm.io/gorm/schema"

	"gorm.io/gen"
	"gorm.io/gen/field"

	"gorm.io/plugin/dbresolver"

	"gadmin/internal/gorm/model"
)

func newReportDayDisconnect(db *gorm.DB, opts ...gen.DOOption) reportDayDisconnect {
	_reportDayDisconnect := reportDayDisconnect{}

	_reportDayDisconnect.reportDayDisconnectDo.UseDB(db, opts...)
	_reportDayDisconnect.reportDayDisconnectDo.UseModel(&model.ReportDayDisconnect{})

	tableName := _reportDayDisconnect.reportDayDisconnectDo.TableName()
	_reportDayDisconnect.ALL = field.NewAsterisk(tableName)
	_reportDayDisconnect.ID = field.NewInt64(tableName, "id")
	_reportDayDisconnect.Date = field.NewString(tableName, "date")
	_reportDayDisconnect.ChannelID = field.NewString(tableName, "channel_id")
	_reportDayDisconnect.ServerID = field.NewInt32(tableName, "server_id")
	_reportDayDisconnect.DisCount = field.NewInt64(tableName, "dis_count")
	_reportDayDisconnect.DisUsers = field.NewInt64(tableName, "dis_users")
	_reportDayDisconnect.ReCount = field.NewInt64(tableName, "re_count")
	_reportDayDisconnect.ReUsers = field.NewInt64(tableName, "re_users")
	_reportDayDisconnect.NewDisCount = field.NewInt64(tableName, "new_dis_count")
	_reportDayDisconnect.NewDisUsers = field.NewInt64(tableName, "new_dis_users")
	_reportDayDisconnect.NewReCount = field.NewInt64(tableName, "new_re_count")
	_reportDayDisconnect.NewReUsers = field.NewInt64(tableName, "new_re_users")
	_reportDayDisconnect.MobileDisCount = field.NewInt64(tableName, "mobile_dis_count")
	_reportDayDisconnect.MobileDisUsers = field.NewInt64(tableName, "mobile_dis_users")
	_reportDayDisconnect.MobileReCount = field.NewInt64(tableName, "mobile_re_count")
	_reportDayDisconnect.MobileReUsers = field.NewInt64(tableName, "mobile_re_users")
	_reportDayDisconnect.WifiDisCount = field.NewInt64(tableName, "wifi_dis_count")
	_reportDayDisconnect.WifiDisUsers = field.NewInt64(tableName, "wifi_dis_users")
	_reportDayDisconnect.WifiReCount = field.NewInt64(tableName, "wifi_re_count")
	_reportDayDisconnect.WifiReUsers = field.NewInt64(tableName, "wifi_re_users")

	_reportDayDisconnect.fillFieldMap()

	return _reportDayDisconnect
}

type reportDayDisconnect struct {
	reportDayDisconnectDo

	ALL            field.Asterisk
	ID             field.Int64  // ID
	Date           field.String // 日期
	ChannelID      field.String // 渠道ID
	ServerID       field.Int32  // 服务器ID
	DisCount       field.Int64  // 断线次数
	DisUsers       field.Int64  // 断线人数
	ReCount        field.Int64  // 重连次数
	ReUsers        field.Int64  // 重连人数
	NewDisCount    field.Int64  // 新手断线次数
	NewDisUsers    field.Int64  // 新手断线人数
	NewReCount     field.Int64  // 新手重连次数
	NewReUsers     field.Int64  // 新手重连人数
	MobileDisCount field.Int64  // 移动网断线次数
	MobileDisUsers field.Int64  // 移动网断线人数
	MobileReCount  field.Int64  // 移动网重连次数
	MobileReUsers  field.Int64  // 移动网重连人数
	WifiDisCount   field.Int64  // wifi网断线次数
	WifiDisUsers   field.Int64  // wifi断线人数
	WifiReCount    field.Int64  // wifi重连次数
	WifiReUsers    field.Int64  // wifi重连人数

	fieldMap map[string]field.Expr
}

func (r reportDayDisconnect) Table(newTableName string) *reportDayDisconnect {
	r.reportDayDisconnectDo.UseTable(newTableName)
	return r.updateTableName(newTableName)
}

func (r reportDayDisconnect) As(alias string) *reportDayDisconnect {
	r.reportDayDisconnectDo.DO = *(r.reportDayDisconnectDo.As(alias).(*gen.DO))
	return r.updateTableName(alias)
}

func (r *reportDayDisconnect) updateTableName(table string) *reportDayDisconnect {
	r.ALL = field.NewAsterisk(table)
	r.ID = field.NewInt64(table, "id")
	r.Date = field.NewString(table, "date")
	r.ChannelID = field.NewString(table, "channel_id")
	r.ServerID = field.NewInt32(table, "server_id")
	r.DisCount = field.NewInt64(table, "dis_count")
	r.DisUsers = field.NewInt64(table, "dis_users")
	r.ReCount = field.NewInt64(table, "re_count")
	r.ReUsers = field.NewInt64(table, "re_users")
	r.NewDisCount = field.NewInt64(table, "new_dis_count")
	r.NewDisUsers = field.NewInt64(table, "new_dis_users")
	r.NewReCount = field.NewInt64(table, "new_re_count")
	r.NewReUsers = field.NewInt64(table, "new_re_users")
	r.MobileDisCount = field.NewInt64(table, "mobile_dis_count")
	r.MobileDisUsers = field.NewInt64(table, "mobile_dis_users")
	r.MobileReCount = field.NewInt64(table, "mobile_re_count")
	r.MobileReUsers = field.NewInt64(table, "mobile_re_users")
	r.WifiDisCount = field.NewInt64(table, "wifi_dis_count")
	r.WifiDisUsers = field.NewInt64(table, "wifi_dis_users")
	r.WifiReCount = field.NewInt64(table, "wifi_re_count")
	r.WifiReUsers = field.NewInt64(table, "wifi_re_users")

	r.fillFieldMap()

	return r
}

func (r *reportDayDisconnect) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
	_f, ok := r.fieldMap[fieldName]
	if !ok || _f == nil {
		return nil, false
	}
	_oe, ok := _f.(field.OrderExpr)
	return _oe, ok
}

func (r *reportDayDisconnect) fillFieldMap() {
	r.fieldMap = make(map[string]field.Expr, 20)
	r.fieldMap["id"] = r.ID
	r.fieldMap["date"] = r.Date
	r.fieldMap["channel_id"] = r.ChannelID
	r.fieldMap["server_id"] = r.ServerID
	r.fieldMap["dis_count"] = r.DisCount
	r.fieldMap["dis_users"] = r.DisUsers
	r.fieldMap["re_count"] = r.ReCount
	r.fieldMap["re_users"] = r.ReUsers
	r.fieldMap["new_dis_count"] = r.NewDisCount
	r.fieldMap["new_dis_users"] = r.NewDisUsers
	r.fieldMap["new_re_count"] = r.NewReCount
	r.fieldMap["new_re_users"] = r.NewReUsers
	r.fieldMap["mobile_dis_count"] = r.MobileDisCount
	r.fieldMap["mobile_dis_users"] = r.MobileDisUsers
	r.fieldMap["mobile_re_count"] = r.MobileReCount
	r.fieldMap["mobile_re_users"] = r.MobileReUsers
	r.fieldMap["wifi_dis_count"] = r.WifiDisCount
	r.fieldMap["wifi_dis_users"] = r.WifiDisUsers
	r.fieldMap["wifi_re_count"] = r.WifiReCount
	r.fieldMap["wifi_re_users"] = r.WifiReUsers
}

func (r reportDayDisconnect) clone(db *gorm.DB) reportDayDisconnect {
	r.reportDayDisconnectDo.ReplaceConnPool(db.Statement.ConnPool)
	return r
}

func (r reportDayDisconnect) replaceDB(db *gorm.DB) reportDayDisconnect {
	r.reportDayDisconnectDo.ReplaceDB(db)
	return r
}

type reportDayDisconnectDo struct{ gen.DO }

func (r reportDayDisconnectDo) Debug() *reportDayDisconnectDo {
	return r.withDO(r.DO.Debug())
}

func (r reportDayDisconnectDo) WithContext(ctx context.Context) *reportDayDisconnectDo {
	return r.withDO(r.DO.WithContext(ctx))
}

func (r reportDayDisconnectDo) ReadDB() *reportDayDisconnectDo {
	return r.Clauses(dbresolver.Read)
}

func (r reportDayDisconnectDo) WriteDB() *reportDayDisconnectDo {
	return r.Clauses(dbresolver.Write)
}

func (r reportDayDisconnectDo) Session(config *gorm.Session) *reportDayDisconnectDo {
	return r.withDO(r.DO.Session(config))
}

func (r reportDayDisconnectDo) Clauses(conds ...clause.Expression) *reportDayDisconnectDo {
	return r.withDO(r.DO.Clauses(conds...))
}

func (r reportDayDisconnectDo) Returning(value interface{}, columns ...string) *reportDayDisconnectDo {
	return r.withDO(r.DO.Returning(value, columns...))
}

func (r reportDayDisconnectDo) Not(conds ...gen.Condition) *reportDayDisconnectDo {
	return r.withDO(r.DO.Not(conds...))
}

func (r reportDayDisconnectDo) Or(conds ...gen.Condition) *reportDayDisconnectDo {
	return r.withDO(r.DO.Or(conds...))
}

func (r reportDayDisconnectDo) Select(conds ...field.Expr) *reportDayDisconnectDo {
	return r.withDO(r.DO.Select(conds...))
}

func (r reportDayDisconnectDo) Where(conds ...gen.Condition) *reportDayDisconnectDo {
	return r.withDO(r.DO.Where(conds...))
}

func (r reportDayDisconnectDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *reportDayDisconnectDo {
	return r.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}

func (r reportDayDisconnectDo) Order(conds ...field.Expr) *reportDayDisconnectDo {
	return r.withDO(r.DO.Order(conds...))
}

func (r reportDayDisconnectDo) Distinct(cols ...field.Expr) *reportDayDisconnectDo {
	return r.withDO(r.DO.Distinct(cols...))
}

func (r reportDayDisconnectDo) Omit(cols ...field.Expr) *reportDayDisconnectDo {
	return r.withDO(r.DO.Omit(cols...))
}

func (r reportDayDisconnectDo) Join(table schema.Tabler, on ...field.Expr) *reportDayDisconnectDo {
	return r.withDO(r.DO.Join(table, on...))
}

func (r reportDayDisconnectDo) LeftJoin(table schema.Tabler, on ...field.Expr) *reportDayDisconnectDo {
	return r.withDO(r.DO.LeftJoin(table, on...))
}

func (r reportDayDisconnectDo) RightJoin(table schema.Tabler, on ...field.Expr) *reportDayDisconnectDo {
	return r.withDO(r.DO.RightJoin(table, on...))
}

func (r reportDayDisconnectDo) Group(cols ...field.Expr) *reportDayDisconnectDo {
	return r.withDO(r.DO.Group(cols...))
}

func (r reportDayDisconnectDo) Having(conds ...gen.Condition) *reportDayDisconnectDo {
	return r.withDO(r.DO.Having(conds...))
}

func (r reportDayDisconnectDo) Limit(limit int) *reportDayDisconnectDo {
	return r.withDO(r.DO.Limit(limit))
}

func (r reportDayDisconnectDo) Offset(offset int) *reportDayDisconnectDo {
	return r.withDO(r.DO.Offset(offset))
}

func (r reportDayDisconnectDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *reportDayDisconnectDo {
	return r.withDO(r.DO.Scopes(funcs...))
}

func (r reportDayDisconnectDo) Unscoped() *reportDayDisconnectDo {
	return r.withDO(r.DO.Unscoped())
}

func (r reportDayDisconnectDo) Create(values ...*model.ReportDayDisconnect) error {
	if len(values) == 0 {
		return nil
	}
	return r.DO.Create(values)
}

func (r reportDayDisconnectDo) CreateInBatches(values []*model.ReportDayDisconnect, batchSize int) error {
	return r.DO.CreateInBatches(values, batchSize)
}

// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (r reportDayDisconnectDo) Save(values ...*model.ReportDayDisconnect) error {
	if len(values) == 0 {
		return nil
	}
	return r.DO.Save(values)
}

func (r reportDayDisconnectDo) First() (*model.ReportDayDisconnect, error) {
	if result, err := r.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.ReportDayDisconnect), nil
	}
}

func (r reportDayDisconnectDo) Take() (*model.ReportDayDisconnect, error) {
	if result, err := r.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.ReportDayDisconnect), nil
	}
}

func (r reportDayDisconnectDo) Last() (*model.ReportDayDisconnect, error) {
	if result, err := r.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.ReportDayDisconnect), nil
	}
}

func (r reportDayDisconnectDo) Find() ([]*model.ReportDayDisconnect, error) {
	result, err := r.DO.Find()
	return result.([]*model.ReportDayDisconnect), err
}

func (r reportDayDisconnectDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ReportDayDisconnect, err error) {
	buf := make([]*model.ReportDayDisconnect, 0, batchSize)
	err = r.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
		defer func() { results = append(results, buf...) }()
		return fc(tx, batch)
	})
	return results, err
}

func (r reportDayDisconnectDo) FindInBatches(result *[]*model.ReportDayDisconnect, batchSize int, fc func(tx gen.Dao, batch int) error) error {
	return r.DO.FindInBatches(result, batchSize, fc)
}

func (r reportDayDisconnectDo) Attrs(attrs ...field.AssignExpr) *reportDayDisconnectDo {
	return r.withDO(r.DO.Attrs(attrs...))
}

func (r reportDayDisconnectDo) Assign(attrs ...field.AssignExpr) *reportDayDisconnectDo {
	return r.withDO(r.DO.Assign(attrs...))
}

func (r reportDayDisconnectDo) Joins(fields ...field.RelationField) *reportDayDisconnectDo {
	for _, _f := range fields {
		r = *r.withDO(r.DO.Joins(_f))
	}
	return &r
}

func (r reportDayDisconnectDo) Preload(fields ...field.RelationField) *reportDayDisconnectDo {
	for _, _f := range fields {
		r = *r.withDO(r.DO.Preload(_f))
	}
	return &r
}

func (r reportDayDisconnectDo) FirstOrInit() (*model.ReportDayDisconnect, error) {
	if result, err := r.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.ReportDayDisconnect), nil
	}
}

func (r reportDayDisconnectDo) FirstOrCreate() (*model.ReportDayDisconnect, error) {
	if result, err := r.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.ReportDayDisconnect), nil
	}
}

func (r reportDayDisconnectDo) FindByPage(offset int, limit int) (result []*model.ReportDayDisconnect, count int64, err error) {
	result, err = r.Offset(offset).Limit(limit).Find()
	if err != nil {
		return
	}

	if size := len(result); 0 < limit && 0 < size && size < limit {
		count = int64(size + offset)
		return
	}

	count, err = r.Offset(-1).Limit(-1).Count()
	return
}

func (r reportDayDisconnectDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
	count, err = r.Count()
	if err != nil {
		return
	}

	err = r.Offset(offset).Limit(limit).Scan(result)
	return
}

func (r reportDayDisconnectDo) Scan(result interface{}) (err error) {
	return r.DO.Scan(result)
}

func (r reportDayDisconnectDo) Delete(models ...*model.ReportDayDisconnect) (result gen.ResultInfo, err error) {
	return r.DO.Delete(models)
}

func (r *reportDayDisconnectDo) withDO(do gen.Dao) *reportDayDisconnectDo {
	r.DO = *do.(*gen.DO)
	return r
}
