This commit is contained in:
eson 2023-09-08 10:52:51 +08:00
parent ac6a81dedd
commit 9ad045c8f4

View File

@ -216,38 +216,31 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
err = txUserInfo.Where("user_id = ?", uinfo.UserId).Take(nil).Error err = txUserInfo.Where("user_id = ?", uinfo.UserId).Take(nil).Error
// txUserInfo.Statement.Table // txUserInfo.Statement.Table
if err == nil { if err != nil {
if err == gorm.ErrRecordNotFound {
err = txUserInfo.Create(uinfo).Error
if err == gorm.ErrRecordNotFound {
return nil
}
}
} else {
updatesql := `UPDATE %s updatesql := `UPDATE %s
SET metadata = CASE SET metadata = CASE
WHEN metadata IS NULL THEN '%s' WHEN metadata IS NULL THEN ?
ELSE JSON_MERGE_PATCH(metadata, '%s') ELSE JSON_MERGE_PATCH(metadata, ?)
END END
WHERE id = ?;` WHERE id = ?;`
updatesql = fmt.Sprintf(updatesql, txUserInfo.Statement.Table) updatesql = fmt.Sprintf(updatesql, txUserInfo.Statement.Table)
txUserInfo.Raw(updatesql, metadata, metadata, uinfo.UserId)
txUserInfo.Raw(`UPDATE fusen.fs_change_code
SET metadata = CASE
WHEN metadata IS NULL THEN '%s'
ELSE JSON_MERGE_PATCH(metadata, '%s')
END
WHERE id = ?;`)
} }
if err == gorm.ErrRecordNotFound {
err = txUserInfo.Create(uinfo).Error
if err == gorm.ErrRecordNotFound {
return nil
}
}
return err return err
}) })
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
return nil return nil
} }
return err return err
} }