// 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 models

import (
	"context"

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

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

	"gorm.io/plugin/dbresolver"

	"ppms-fj/internal/colComment/model"
)

func newSysBbzdb(db *gorm.DB, opts ...gen.DOOption) sysBbzdb {
	_sysBbzdb := sysBbzdb{}

	_sysBbzdb.sysBbzdbDo.UseDB(db, opts...)
	_sysBbzdb.sysBbzdbDo.UseModel(&model.SysBbzdb{})

	tableName := _sysBbzdb.sysBbzdbDo.TableName()
	_sysBbzdb.ALL = field.NewAsterisk(tableName)
	_sysBbzdb.ID = field.NewFloat64(tableName, "ID")
	_sysBbzdb.Bbmc = field.NewString(tableName, "BBMC")
	_sysBbzdb.Dybm = field.NewString(tableName, "DYBM")
	_sysBbzdb.Zwzl = field.NewString(tableName, "ZWZL")
	_sysBbzdb.Sscs = field.NewString(tableName, "SSCS")
	_sysBbzdb.Bblb = field.NewString(tableName, "BBLB")
	_sysBbzdb.Zbbm = field.NewString(tableName, "ZBBM")
	_sysBbzdb.Lastupdatetime = field.NewFloat64(tableName, "LASTUPDATETIME")

	_sysBbzdb.fillFieldMap()

	return _sysBbzdb
}

type sysBbzdb struct {
	sysBbzdbDo sysBbzdbDo

	ALL            field.Asterisk
	ID             field.Float64
	Bbmc           field.String
	Dybm           field.String
	Zwzl           field.String
	Sscs           field.String
	Bblb           field.String
	Zbbm           field.String
	Lastupdatetime field.Float64

	fieldMap map[string]field.Expr
}

func (s sysBbzdb) Table(newTableName string) *sysBbzdb {
	s.sysBbzdbDo.UseTable(newTableName)
	return s.updateTableName(newTableName)
}

func (s sysBbzdb) As(alias string) *sysBbzdb {
	s.sysBbzdbDo.DO = *(s.sysBbzdbDo.As(alias).(*gen.DO))
	return s.updateTableName(alias)
}

func (s *sysBbzdb) updateTableName(table string) *sysBbzdb {
	s.ALL = field.NewAsterisk(table)
	s.ID = field.NewFloat64(table, "ID")
	s.Bbmc = field.NewString(table, "BBMC")
	s.Dybm = field.NewString(table, "DYBM")
	s.Zwzl = field.NewString(table, "ZWZL")
	s.Sscs = field.NewString(table, "SSCS")
	s.Bblb = field.NewString(table, "BBLB")
	s.Zbbm = field.NewString(table, "ZBBM")
	s.Lastupdatetime = field.NewFloat64(table, "LASTUPDATETIME")

	s.fillFieldMap()

	return s
}

func (s *sysBbzdb) WithContext(ctx context.Context) *sysBbzdbDo { return s.sysBbzdbDo.WithContext(ctx) }

func (s sysBbzdb) TableName() string { return s.sysBbzdbDo.TableName() }

func (s sysBbzdb) Alias() string { return s.sysBbzdbDo.Alias() }

func (s sysBbzdb) Columns(cols ...field.Expr) gen.Columns { return s.sysBbzdbDo.Columns(cols...) }

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

func (s *sysBbzdb) fillFieldMap() {
	s.fieldMap = make(map[string]field.Expr, 8)
	s.fieldMap["ID"] = s.ID
	s.fieldMap["BBMC"] = s.Bbmc
	s.fieldMap["DYBM"] = s.Dybm
	s.fieldMap["ZWZL"] = s.Zwzl
	s.fieldMap["SSCS"] = s.Sscs
	s.fieldMap["BBLB"] = s.Bblb
	s.fieldMap["ZBBM"] = s.Zbbm
	s.fieldMap["LASTUPDATETIME"] = s.Lastupdatetime
}

func (s sysBbzdb) clone(db *gorm.DB) sysBbzdb {
	s.sysBbzdbDo.ReplaceConnPool(db.Statement.ConnPool)
	return s
}

func (s sysBbzdb) replaceDB(db *gorm.DB) sysBbzdb {
	s.sysBbzdbDo.ReplaceDB(db)
	return s
}

type sysBbzdbDo struct{ gen.DO }

func (s sysBbzdbDo) Debug() *sysBbzdbDo {
	return s.withDO(s.DO.Debug())
}

func (s sysBbzdbDo) WithContext(ctx context.Context) *sysBbzdbDo {
	return s.withDO(s.DO.WithContext(ctx))
}

func (s sysBbzdbDo) ReadDB() *sysBbzdbDo {
	return s.Clauses(dbresolver.Read)
}

func (s sysBbzdbDo) WriteDB() *sysBbzdbDo {
	return s.Clauses(dbresolver.Write)
}

func (s sysBbzdbDo) Session(config *gorm.Session) *sysBbzdbDo {
	return s.withDO(s.DO.Session(config))
}

func (s sysBbzdbDo) Clauses(conds ...clause.Expression) *sysBbzdbDo {
	return s.withDO(s.DO.Clauses(conds...))
}

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

func (s sysBbzdbDo) Not(conds ...gen.Condition) *sysBbzdbDo {
	return s.withDO(s.DO.Not(conds...))
}

func (s sysBbzdbDo) Or(conds ...gen.Condition) *sysBbzdbDo {
	return s.withDO(s.DO.Or(conds...))
}

func (s sysBbzdbDo) Select(conds ...field.Expr) *sysBbzdbDo {
	return s.withDO(s.DO.Select(conds...))
}

func (s sysBbzdbDo) Where(conds ...gen.Condition) *sysBbzdbDo {
	return s.withDO(s.DO.Where(conds...))
}

func (s sysBbzdbDo) Order(conds ...field.Expr) *sysBbzdbDo {
	return s.withDO(s.DO.Order(conds...))
}

func (s sysBbzdbDo) Distinct(cols ...field.Expr) *sysBbzdbDo {
	return s.withDO(s.DO.Distinct(cols...))
}

func (s sysBbzdbDo) Omit(cols ...field.Expr) *sysBbzdbDo {
	return s.withDO(s.DO.Omit(cols...))
}

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

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

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

func (s sysBbzdbDo) Group(cols ...field.Expr) *sysBbzdbDo {
	return s.withDO(s.DO.Group(cols...))
}

func (s sysBbzdbDo) Having(conds ...gen.Condition) *sysBbzdbDo {
	return s.withDO(s.DO.Having(conds...))
}

func (s sysBbzdbDo) Limit(limit int) *sysBbzdbDo {
	return s.withDO(s.DO.Limit(limit))
}

func (s sysBbzdbDo) Offset(offset int) *sysBbzdbDo {
	return s.withDO(s.DO.Offset(offset))
}

func (s sysBbzdbDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *sysBbzdbDo {
	return s.withDO(s.DO.Scopes(funcs...))
}

func (s sysBbzdbDo) Unscoped() *sysBbzdbDo {
	return s.withDO(s.DO.Unscoped())
}

func (s sysBbzdbDo) Create(values ...*model.SysBbzdb) error {
	if len(values) == 0 {
		return nil
	}
	return s.DO.Create(values)
}

func (s sysBbzdbDo) CreateInBatches(values []*model.SysBbzdb, batchSize int) error {
	return s.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 (s sysBbzdbDo) Save(values ...*model.SysBbzdb) error {
	if len(values) == 0 {
		return nil
	}
	return s.DO.Save(values)
}

func (s sysBbzdbDo) First() (*model.SysBbzdb, error) {
	if result, err := s.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysBbzdb), nil
	}
}

func (s sysBbzdbDo) Take() (*model.SysBbzdb, error) {
	if result, err := s.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysBbzdb), nil
	}
}

func (s sysBbzdbDo) Last() (*model.SysBbzdb, error) {
	if result, err := s.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysBbzdb), nil
	}
}

func (s sysBbzdbDo) Find() ([]*model.SysBbzdb, error) {
	result, err := s.DO.Find()
	return result.([]*model.SysBbzdb), err
}

func (s sysBbzdbDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.SysBbzdb, err error) {
	buf := make([]*model.SysBbzdb, 0, batchSize)
	err = s.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 (s sysBbzdbDo) FindInBatches(result *[]*model.SysBbzdb, batchSize int, fc func(tx gen.Dao, batch int) error) error {
	return s.DO.FindInBatches(result, batchSize, fc)
}

func (s sysBbzdbDo) Attrs(attrs ...field.AssignExpr) *sysBbzdbDo {
	return s.withDO(s.DO.Attrs(attrs...))
}

func (s sysBbzdbDo) Assign(attrs ...field.AssignExpr) *sysBbzdbDo {
	return s.withDO(s.DO.Assign(attrs...))
}

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

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

func (s sysBbzdbDo) FirstOrInit() (*model.SysBbzdb, error) {
	if result, err := s.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysBbzdb), nil
	}
}

func (s sysBbzdbDo) FirstOrCreate() (*model.SysBbzdb, error) {
	if result, err := s.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysBbzdb), nil
	}
}

func (s sysBbzdbDo) FindByPage(offset int, limit int) (result []*model.SysBbzdb, count int64, err error) {
	result, err = s.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 = s.Offset(-1).Limit(-1).Count()
	return
}

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

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

func (s sysBbzdbDo) Scan(result interface{}) (err error) {
	return s.DO.Scan(result)
}

func (s sysBbzdbDo) Delete(models ...*model.SysBbzdb) (result gen.ResultInfo, err error) {
	return s.DO.Delete(models)
}

func (s *sysBbzdbDo) withDO(do gen.Dao) *sysBbzdbDo {
	s.DO = *do.(*gen.DO)
	return s
}
