fusenapi/model/gmodel/ldap_users_logic.go

22 lines
584 B
Go
Raw Normal View History

2023-11-10 07:24:25 +00:00
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
}