// Code generated by sql2gorm. DO NOT EDIT. package repo import ( "context" "time" "github.com/samber/do" "gorm.io/gorm" ) func init(){ do.Provide[OrganizationRepo](nil,NewOrganization) } type OrganizationStatus int const( OrganizationDisableStatus OrganizationStatus = 0 OrganizationEnableStatus OrganizationStatus = 1 ) // 组织表 type Organization struct { ID uint `gorm:"column:id;primary_key;AUTO_INCREMENT"` // id Name string `gorm:"column:name;NOT NULL"` // 组织名 ParentID uint `gorm:"column:parent_id;default:0"` // 上级组织id Sort uint `gorm:"column:sort;default:0"` // 层级序号 Status int `gorm:"column:status;default:1"` // 状态:0-无效,1-有效 Path string `gorm:"column:path"` // 全路径 Leaders string `gorm:"column:leaders"` CreatedBy string `gorm:"column:created_by"` // 创建人 CreatedOn time.Time `gorm:"column:created_on;default:CURRENT_TIMESTAMP;NOT NULL"` // 记录创建时间 ModifiedBy string `gorm:"column:modified_by"` // 修改人 ModifiedOn time.Time `gorm:"column:modified_on;default:CURRENT_TIMESTAMP"` // 记录修改时间 } func (m *Organization) TableName() string { return "organization" } type OrganizationRepo interface{ Create(ctx context.Context,org Organization)(id uint,err error) Save(ctx context.Context,org Organization)(error) GetById(ctx context.Context,id uint)(org Organization,err error) DelById(ctx context.Context,id uint)(err error) GetOrgs(ctx context.Context)(org []Organization,err error) ExistOrgId(ctx context.Context,id uint)(bool,error) SetStatus(ctx context.Context,id uint,status OrganizationStatus)error } type orginizationRepo struct{ db *gorm.DB } func NewOrganization(i *do.Injector)(OrganizationRepo,error){ return &orginizationRepo{ db:do.MustInvoke[*gorm.DB](i), },nil } func (o *orginizationRepo)Create(ctx context.Context,org Organization)(id uint,err error){ err = o.db.Create(org).Error id = org.ID return } func (o *orginizationRepo)Save(ctx context.Context,org Organization)(error){ return o.db.Save(&org).Error } func (o *orginizationRepo)GetById(ctx context.Context,id uint)(org Organization,err error){ err = o.db.Where("id = ?",id).Take(&org).Error return } func (o *orginizationRepo)DelById(ctx context.Context,id uint)(err error){ return o.db.Where("id = ?",id).Delete(&Organization{}).Error } func (o *orginizationRepo)GetOrgs(ctx context.Context)(orgs []Organization,err error){ err = o.db.Model(&Organization{}).Find(&orgs).Error return } func (o *orginizationRepo)ExistOrgId(ctx context.Context,id uint)(bool,error){ var count int64 = 0 err := o.db.Where("id = ?",id).Count(&count).Error if count >0{ return false,err } return true,err } func (o *orginizationRepo)SetStatus(ctx context.Context,id uint,status OrganizationStatus)error{ return o.db.Where("id = ?",id).Update("status",status).Error }