fix: 优化微信授权服务的用户创建逻辑

移除冗余的用户ID赋值步骤,直接使用插入后返回的主键值填充日志,简化代码逻辑
This commit is contained in:
glz
2026-06-15 09:38:15 +08:00
parent eb1a677612
commit 94799ee189

View File

@ -236,7 +236,7 @@ public class WeChatAuthService(
// 校验 WxUser 是否存在
var wxUser = await wxUserRepository.Context.Queryable<WxUser>()
.Where(w => w.Id == wxUserId )
.Where(w => w.Id == wxUserId)
.FirstAsync();
if (wxUser == null)
@ -260,11 +260,10 @@ public class WeChatAuthService(
UpdatedAt = DateTime.Now
};
var userId = await wxUserRepository.Context.Insertable(newUser).ExecuteReturnIdentityAsync();
newUser.Id = userId;
await wxUserRepository.Context.Insertable(newUser).ExecuteReturnIdentityAsync();
logger.LogInformation("新用户创建成功UserId: {UserId}, WxUserId: {WxUserId}, Name: {Name}",
userId, wxUserId, input.Name);
newUser.Id, wxUserId, input.Name);
// 为新用户创建默认宠物
try { await petService.CreateDefaultPetAsync(newUser.Id); }