|
|
// 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 dao
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
"gorm.io/gorm/clause"
|
|
|
"gorm.io/gorm/schema"
|
|
|
|
|
|
"gorm.io/gen"
|
|
|
"gorm.io/gen/field"
|
|
|
|
|
|
"gorm.io/plugin/dbresolver"
|
|
|
|
|
|
"joybuywork/internal/repository/model"
|
|
|
)
|
|
|
|
|
|
func newCompany(db *gorm.DB, opts ...gen.DOOption) company {
|
|
|
_company := company{}
|
|
|
|
|
|
_company.companyDo.UseDB(db, opts...)
|
|
|
_company.companyDo.UseModel(&model.Company{})
|
|
|
|
|
|
tableName := _company.companyDo.TableName()
|
|
|
_company.ALL = field.NewAsterisk(tableName)
|
|
|
_company.ID = field.NewInt64(tableName, "id")
|
|
|
_company.CreatedAt = field.NewInt64(tableName, "created_at")
|
|
|
_company.UpdatedAt = field.NewInt64(tableName, "updated_at")
|
|
|
_company.IsDel = field.NewInt8(tableName, "is_del")
|
|
|
_company.HashID = field.NewString(tableName, "hash_id")
|
|
|
_company.Uscid = field.NewString(tableName, "uscid")
|
|
|
_company.ShortName = field.NewString(tableName, "short_name")
|
|
|
_company.Phone = field.NewString(tableName, "phone")
|
|
|
_company.AppName = field.NewString(tableName, "app_name")
|
|
|
_company.FullName = field.NewString(tableName, "full_name")
|
|
|
_company.IsCert = field.NewInt8(tableName, "is_cert")
|
|
|
|
|
|
_company.fillFieldMap()
|
|
|
|
|
|
return _company
|
|
|
}
|
|
|
|
|
|
type company struct {
|
|
|
companyDo companyDo
|
|
|
|
|
|
ALL field.Asterisk
|
|
|
ID field.Int64
|
|
|
CreatedAt field.Int64
|
|
|
UpdatedAt field.Int64
|
|
|
IsDel field.Int8 // 是否已删除(1-是,0-否)
|
|
|
HashID field.String // 对外id
|
|
|
Uscid field.String // 营业执照编号
|
|
|
ShortName field.String // 企业简称
|
|
|
Phone field.String // 申请通过后公司显示手机号
|
|
|
AppName field.String // 申请通过后公司站点名称
|
|
|
FullName field.String // 企业全称
|
|
|
IsCert field.Int8 // 是否为认证企业(0-否,1-是)
|
|
|
|
|
|
fieldMap map[string]field.Expr
|
|
|
}
|
|
|
|
|
|
func (c company) Table(newTableName string) *company {
|
|
|
c.companyDo.UseTable(newTableName)
|
|
|
return c.updateTableName(newTableName)
|
|
|
}
|
|
|
|
|
|
func (c company) As(alias string) *company {
|
|
|
c.companyDo.DO = *(c.companyDo.As(alias).(*gen.DO))
|
|
|
return c.updateTableName(alias)
|
|
|
}
|
|
|
|
|
|
func (c *company) updateTableName(table string) *company {
|
|
|
c.ALL = field.NewAsterisk(table)
|
|
|
c.ID = field.NewInt64(table, "id")
|
|
|
c.CreatedAt = field.NewInt64(table, "created_at")
|
|
|
c.UpdatedAt = field.NewInt64(table, "updated_at")
|
|
|
c.IsDel = field.NewInt8(table, "is_del")
|
|
|
c.HashID = field.NewString(table, "hash_id")
|
|
|
c.Uscid = field.NewString(table, "uscid")
|
|
|
c.ShortName = field.NewString(table, "short_name")
|
|
|
c.Phone = field.NewString(table, "phone")
|
|
|
c.AppName = field.NewString(table, "app_name")
|
|
|
c.FullName = field.NewString(table, "full_name")
|
|
|
c.IsCert = field.NewInt8(table, "is_cert")
|
|
|
|
|
|
c.fillFieldMap()
|
|
|
|
|
|
return c
|
|
|
}
|
|
|
|
|
|
func (c *company) WithContext(ctx context.Context) *companyDo { return c.companyDo.WithContext(ctx) }
|
|
|
|
|
|
func (c company) TableName() string { return c.companyDo.TableName() }
|
|
|
|
|
|
func (c company) Alias() string { return c.companyDo.Alias() }
|
|
|
|
|
|
func (c *company) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|
|
_f, ok := c.fieldMap[fieldName]
|
|
|
if !ok || _f == nil {
|
|
|
return nil, false
|
|
|
}
|
|
|
_oe, ok := _f.(field.OrderExpr)
|
|
|
return _oe, ok
|
|
|
}
|
|
|
|
|
|
func (c *company) fillFieldMap() {
|
|
|
c.fieldMap = make(map[string]field.Expr, 11)
|
|
|
c.fieldMap["id"] = c.ID
|
|
|
c.fieldMap["created_at"] = c.CreatedAt
|
|
|
c.fieldMap["updated_at"] = c.UpdatedAt
|
|
|
c.fieldMap["is_del"] = c.IsDel
|
|
|
c.fieldMap["hash_id"] = c.HashID
|
|
|
c.fieldMap["uscid"] = c.Uscid
|
|
|
c.fieldMap["short_name"] = c.ShortName
|
|
|
c.fieldMap["phone"] = c.Phone
|
|
|
c.fieldMap["app_name"] = c.AppName
|
|
|
c.fieldMap["full_name"] = c.FullName
|
|
|
c.fieldMap["is_cert"] = c.IsCert
|
|
|
}
|
|
|
|
|
|
func (c company) clone(db *gorm.DB) company {
|
|
|
c.companyDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
|
return c
|
|
|
}
|
|
|
|
|
|
func (c company) replaceDB(db *gorm.DB) company {
|
|
|
c.companyDo.ReplaceDB(db)
|
|
|
return c
|
|
|
}
|
|
|
|
|
|
type companyDo struct{ gen.DO }
|
|
|
|
|
|
func (c companyDo) Debug() *companyDo {
|
|
|
return c.withDO(c.DO.Debug())
|
|
|
}
|
|
|
|
|
|
func (c companyDo) WithContext(ctx context.Context) *companyDo {
|
|
|
return c.withDO(c.DO.WithContext(ctx))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) ReadDB() *companyDo {
|
|
|
return c.Clauses(dbresolver.Read)
|
|
|
}
|
|
|
|
|
|
func (c companyDo) WriteDB() *companyDo {
|
|
|
return c.Clauses(dbresolver.Write)
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Session(config *gorm.Session) *companyDo {
|
|
|
return c.withDO(c.DO.Session(config))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Clauses(conds ...clause.Expression) *companyDo {
|
|
|
return c.withDO(c.DO.Clauses(conds...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Returning(value interface{}, columns ...string) *companyDo {
|
|
|
return c.withDO(c.DO.Returning(value, columns...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Not(conds ...gen.Condition) *companyDo {
|
|
|
return c.withDO(c.DO.Not(conds...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Or(conds ...gen.Condition) *companyDo {
|
|
|
return c.withDO(c.DO.Or(conds...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Select(conds ...field.Expr) *companyDo {
|
|
|
return c.withDO(c.DO.Select(conds...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Where(conds ...gen.Condition) *companyDo {
|
|
|
return c.withDO(c.DO.Where(conds...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *companyDo {
|
|
|
return c.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Order(conds ...field.Expr) *companyDo {
|
|
|
return c.withDO(c.DO.Order(conds...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Distinct(cols ...field.Expr) *companyDo {
|
|
|
return c.withDO(c.DO.Distinct(cols...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Omit(cols ...field.Expr) *companyDo {
|
|
|
return c.withDO(c.DO.Omit(cols...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Join(table schema.Tabler, on ...field.Expr) *companyDo {
|
|
|
return c.withDO(c.DO.Join(table, on...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) LeftJoin(table schema.Tabler, on ...field.Expr) *companyDo {
|
|
|
return c.withDO(c.DO.LeftJoin(table, on...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) RightJoin(table schema.Tabler, on ...field.Expr) *companyDo {
|
|
|
return c.withDO(c.DO.RightJoin(table, on...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Group(cols ...field.Expr) *companyDo {
|
|
|
return c.withDO(c.DO.Group(cols...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Having(conds ...gen.Condition) *companyDo {
|
|
|
return c.withDO(c.DO.Having(conds...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Limit(limit int) *companyDo {
|
|
|
return c.withDO(c.DO.Limit(limit))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Offset(offset int) *companyDo {
|
|
|
return c.withDO(c.DO.Offset(offset))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *companyDo {
|
|
|
return c.withDO(c.DO.Scopes(funcs...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Unscoped() *companyDo {
|
|
|
return c.withDO(c.DO.Unscoped())
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Create(values ...*model.Company) error {
|
|
|
if len(values) == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
return c.DO.Create(values)
|
|
|
}
|
|
|
|
|
|
func (c companyDo) CreateInBatches(values []*model.Company, batchSize int) error {
|
|
|
return c.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 (c companyDo) Save(values ...*model.Company) error {
|
|
|
if len(values) == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
return c.DO.Save(values)
|
|
|
}
|
|
|
|
|
|
func (c companyDo) First() (*model.Company, error) {
|
|
|
if result, err := c.DO.First(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
return result.(*model.Company), nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Take() (*model.Company, error) {
|
|
|
if result, err := c.DO.Take(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
return result.(*model.Company), nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Last() (*model.Company, error) {
|
|
|
if result, err := c.DO.Last(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
return result.(*model.Company), nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Find() ([]*model.Company, error) {
|
|
|
result, err := c.DO.Find()
|
|
|
return result.([]*model.Company), err
|
|
|
}
|
|
|
|
|
|
func (c companyDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Company, err error) {
|
|
|
buf := make([]*model.Company, 0, batchSize)
|
|
|
err = c.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 (c companyDo) FindInBatches(result *[]*model.Company, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
|
return c.DO.FindInBatches(result, batchSize, fc)
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Attrs(attrs ...field.AssignExpr) *companyDo {
|
|
|
return c.withDO(c.DO.Attrs(attrs...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Assign(attrs ...field.AssignExpr) *companyDo {
|
|
|
return c.withDO(c.DO.Assign(attrs...))
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Joins(fields ...field.RelationField) *companyDo {
|
|
|
for _, _f := range fields {
|
|
|
c = *c.withDO(c.DO.Joins(_f))
|
|
|
}
|
|
|
return &c
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Preload(fields ...field.RelationField) *companyDo {
|
|
|
for _, _f := range fields {
|
|
|
c = *c.withDO(c.DO.Preload(_f))
|
|
|
}
|
|
|
return &c
|
|
|
}
|
|
|
|
|
|
func (c companyDo) FirstOrInit() (*model.Company, error) {
|
|
|
if result, err := c.DO.FirstOrInit(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
return result.(*model.Company), nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (c companyDo) FirstOrCreate() (*model.Company, error) {
|
|
|
if result, err := c.DO.FirstOrCreate(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
return result.(*model.Company), nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (c companyDo) FindByPage(offset int, limit int) (result []*model.Company, count int64, err error) {
|
|
|
result, err = c.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 = c.Offset(-1).Limit(-1).Count()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (c companyDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
|
|
count, err = c.Count()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
err = c.Offset(offset).Limit(limit).Scan(result)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Scan(result interface{}) (err error) {
|
|
|
return c.DO.Scan(result)
|
|
|
}
|
|
|
|
|
|
func (c companyDo) Delete(models ...*model.Company) (result gen.ResultInfo, err error) {
|
|
|
return c.DO.Delete(models)
|
|
|
}
|
|
|
|
|
|
func (c *companyDo) withDO(do gen.Dao) *companyDo {
|
|
|
c.DO = *do.(*gen.DO)
|
|
|
return c
|
|
|
}
|