fix: 优化微信授权服务的用户创建逻辑
移除冗余的用户ID赋值步骤,直接使用插入后返回的主键值填充日志,简化代码逻辑
This commit is contained in:
@ -236,7 +236,7 @@ public class WeChatAuthService(
|
|||||||
|
|
||||||
// 校验 WxUser 是否存在
|
// 校验 WxUser 是否存在
|
||||||
var wxUser = await wxUserRepository.Context.Queryable<WxUser>()
|
var wxUser = await wxUserRepository.Context.Queryable<WxUser>()
|
||||||
.Where(w => w.Id == wxUserId )
|
.Where(w => w.Id == wxUserId)
|
||||||
.FirstAsync();
|
.FirstAsync();
|
||||||
|
|
||||||
if (wxUser == null)
|
if (wxUser == null)
|
||||||
@ -260,11 +260,10 @@ public class WeChatAuthService(
|
|||||||
UpdatedAt = DateTime.Now
|
UpdatedAt = DateTime.Now
|
||||||
};
|
};
|
||||||
|
|
||||||
var userId = await wxUserRepository.Context.Insertable(newUser).ExecuteReturnIdentityAsync();
|
await wxUserRepository.Context.Insertable(newUser).ExecuteReturnIdentityAsync();
|
||||||
newUser.Id = userId;
|
|
||||||
|
|
||||||
logger.LogInformation("新用户创建成功,UserId: {UserId}, WxUserId: {WxUserId}, Name: {Name}",
|
logger.LogInformation("新用户创建成功,UserId: {UserId}, WxUserId: {WxUserId}, Name: {Name}",
|
||||||
userId, wxUserId, input.Name);
|
newUser.Id, wxUserId, input.Name);
|
||||||
|
|
||||||
// 为新用户创建默认宠物
|
// 为新用户创建默认宠物
|
||||||
try { await petService.CreateDefaultPetAsync(newUser.Id); }
|
try { await petService.CreateDefaultPetAsync(newUser.Id); }
|
||||||
|
|||||||
Reference in New Issue
Block a user