fusenapi/model/gmodel/ldap_users_logic.go
laodaming d6a25673bc fix
2023-11-10 15:24:25 +08:00

22 lines
584 B
Go

package gmodel
import (
"context"
"errors"
"gorm.io/gorm"
)
// TODO: 使用model的属性做你想做的
func (u *LdapUsersModel) CreateOrUpdate(ctx context.Context, appId string, openId string, data *LdapUsers) error {
var info LdapUsers
err := u.db.WithContext(ctx).Where("app_id = ? and open_id = ?", appId, openId).Take(&info).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return u.db.WithContext(ctx).Create(&data).Error
}
return err
}
return u.db.WithContext(ctx).Where("app_id = ? and open_id = ?", appId, openId).Updates(&data).Error
}