修改User模块,同步原始代码

This commit is contained in:
chfei committed 2026-10-23 15:42:37 +08:00
1 parent 4a5fada435
commit 78b0c2bb2e
47 files changed
+2939 -193

No files matched your search

@@ -1,43 +1,35 @@
using MAX.Core.DependencyInjection;
using MAX.Framework.Validation;
using MAX.Core.DependencyInjection;
using MAX.Framework.Commons;
using Store.Users.Contracts;
using Store.Users.Contracts.Dtos;
using Store.Users.Entities;
using Store.Users.Mappers;
using Store.Users.Repositories;
using System;
using System.Collections.Generic;
using System.Text;
namespace Store.Users.Services;
namespace Store.Users.Services
internal sealed class UserQueryService(IUserRepository repository) : IUserQueryService, ITransientDependency
{
internal class UserQueryService : IUserQueryService, ITransientDependency
{
private readonly IUserRepository _userRepository;
public async Task<UserInfo> GetUser(string userName)
{
RequestValidator.Validate(new UserNameRequest { UserName = userName?.Trim()! });
UserInputChecks.Length(userName.Trim(), 20, "用户名");
var user = await repository.GetUser(userName.Trim()) ?? throw new AppException("用户不存在");
return new UserMapper().ToInfo(user);
}
}
public UserQueryService(IUserRepository userRepository)
{
_userRepository = userRepository;
}
public async Task<UserInfo> GetUser(string userName)
{
var sql = _userRepository.Where(a => a.UserName == userName).ToSql();
var user = await _userRepository.Where(a => a.UserName == userName).FirstAsync();
if (user != null)
{
if (user.IsMainUser == false)
{
var mainUser = await _userRepository.Where(a => a.UserName == user.ParentUserName).FirstAsync();
if (mainUser != null)
{
user.OemId = mainUser.OemId;
user.PostagePerOrder = mainUser.PostagePerOrder;
user.RefundPostagePerOrder = mainUser.RefundPostagePerOrder;
user.GiftOemAmountPerOrder = mainUser.GiftOemAmountPerOrder;
user.SyncLogisticsPerOrder = mainUser.SyncLogisticsPerOrder;
}
}
}
return new UserMapper().ToInfo(user);
}
}
internal sealed class UserAuthenticationService(IFreeSql orm, IUserQueryService query)
: IUserAuthenticationService, ITransientDependency
{
public async Task<UserInfo?> Authenticate(string userName, string password, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
if (!RequestValidator.TryValidate(new UserLoginRequest { UserName = userName?.Trim()!, Password = password }, out _))
return null;
if (userName.Trim().Length > 20 || password.Length > 128) return null;
var user = await orm.Select<UserEntity>().Where(u => u.UserName == userName.Trim()).FirstAsync(cancellationToken);
if (user == null || !UserPassword.Verify(user, password)) return null;
return await query.GetUser(user.UserName);
}
}