This commit is contained in:
laodaming
2023-11-21 15:07:44 +08:00
parent 787f33f555
commit be076197d2
5 changed files with 75 additions and 35 deletions

View File

@@ -2,11 +2,15 @@ package gmodel
import (
"gorm.io/gorm"
"time"
)
// ldap_user ldap_用户id递增表
type LdapUser struct {
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
UserDn *string `gorm:"index;default:'';" json:"user_dn"` //
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
}
type LdapUserModel struct {
db *gorm.DB

View File

@@ -6,3 +6,18 @@ import "context"
func (u *LdapUserModel) Create(ctx context.Context, data *LdapUser) error {
return u.db.WithContext(ctx).Model(&LdapUser{}).Create(&data).Error
}
func (u *LdapUserModel) Update(ctx context.Context, userDN string, data *LdapUser) error {
return u.db.WithContext(ctx).Model(&LdapUser{}).Where("user_dn = ?", userDN).Updates(&data).Error
}
func (u *LdapUserModel) Delete(ctx context.Context, id int64) error {
return u.db.WithContext(ctx).Model(&LdapUser{}).Where("id = ?", id).Delete(&LdapUser{}).Error
}
func (u *LdapUserModel) GetAllByIds(ctx context.Context, ids []int64) (resp []LdapUser, err error) {
if len(ids) == 0 {
return
}
err = u.db.WithContext(ctx).Model(&LdapUser{}).Where("id in (?)", ids).Find(&resp).Error
return resp, err
}