This commit is contained in:
xiaolipro 2026-06-10 17:57:43 +08:00
parent dab31a7c8f
commit c1219e0238
14 changed files with 47 additions and 45 deletions

3
.gitignore vendored
View File

@ -14,4 +14,5 @@ Logs/
node_modules/ node_modules/
*.lscache *.lscache
/src/SimpleAdmin.Api/wwwroot/

6
Directory.Build.props Normal file
View File

@ -0,0 +1,6 @@
<Project>
<PropertyGroup>
<!-- All Fake packages -->
<FakePackageVersion>8.0.5.12</FakePackageVersion>
</PropertyGroup>
</Project>

View File

@ -10,11 +10,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "items", "items", "{BE5132AD
NuGet.Config = NuGet.Config NuGet.Config = NuGet.Config
SPEC.md = SPEC.md SPEC.md = SPEC.md
开发复刻说明.md = 开发复刻说明.md 开发复刻说明.md = 开发复刻说明.md
oms表结构与接口设计2026040802.md = oms表结构与接口设计2026040802.md
.gitignore = .gitignore .gitignore = .gitignore
.dockerignore = .dockerignore .dockerignore = .dockerignore
oms表结构与接口设计20260427.md = oms表结构与接口设计20260427.md oms表结构与接口设计20260427.md = oms表结构与接口设计20260427.md
db.sql = db.sql db.sql = db.sql
Directory.Build.props = Directory.Build.props
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleAdmin.Api", "src\SimpleAdmin.Api\SimpleAdmin.Api.csproj", "{229ED167-9ECC-4736-8DFB-522EEA8FF680}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleAdmin.Api", "src\SimpleAdmin.Api\SimpleAdmin.Api.csproj", "{229ED167-9ECC-4736-8DFB-522EEA8FF680}"

View File

@ -19,6 +19,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASqlBuilderProvider_002Ecs_002Fl_003AC_0021_003FUsers_003FBSI_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F38bf349295324397b2c739e7e632b4bd2d5000_003F71_003F77c8fbe4_003FSqlBuilderProvider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASqlBuilderProvider_002Ecs_002Fl_003AC_0021_003FUsers_003FBSI_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F38bf349295324397b2c739e7e632b4bd2d5000_003F71_003F77c8fbe4_003FSqlBuilderProvider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASqlSugarClient_002Ecs_002Fl_003AC_0021_003FUsers_003FBSI_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F38bf349295324397b2c739e7e632b4bd2d5000_003Fe8_003Ffcf6435d_003FSqlSugarClient_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASqlSugarClient_002Ecs_002Fl_003AC_0021_003FUsers_003FBSI_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F38bf349295324397b2c739e7e632b4bd2d5000_003Fe8_003Ffcf6435d_003FSqlSugarClient_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASqlSugarProvider_002Ecs_002Fl_003AC_0021_003FUsers_003FBSI_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F38bf349295324397b2c739e7e632b4bd2d5000_003F26_003Fce9a7a77_003FSqlSugarProvider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASqlSugarProvider_002Ecs_002Fl_003AC_0021_003FUsers_003FBSI_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F38bf349295324397b2c739e7e632b4bd2d5000_003F26_003Fce9a7a77_003FSqlSugarProvider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUnauthorizedAccessException_002Ecs_002Fl_003AC_0021_003FUsers_003FBSI_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3e10648195244ebfa276c71cb5b3f877c90750_003F74_003F8418b441_003FUnauthorizedAccessException_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=9c7e285e_002D68dc_002D4e8e_002D88cb_002De8df37de5da5/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &amp;lt;src&amp;gt;\&amp;lt;SimpleAdmin.Api.IntegrationTests&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD; <s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=9c7e285e_002D68dc_002D4e8e_002D88cb_002De8df37de5da5/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &amp;lt;src&amp;gt;\&amp;lt;SimpleAdmin.Api.IntegrationTests&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;Project Location="D:\my\itfx\admin\src\SimpleAdmin.Api.IntegrationTests" Presentation="&amp;lt;src&amp;gt;\&amp;lt;SimpleAdmin.Api.IntegrationTests&amp;gt;" /&gt;&#xD; &lt;Project Location="D:\my\itfx\admin\src\SimpleAdmin.Api.IntegrationTests" Presentation="&amp;lt;src&amp;gt;\&amp;lt;SimpleAdmin.Api.IntegrationTests&amp;gt;" /&gt;&#xD;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary> &lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>

View File

@ -16,9 +16,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Fake.ObjectMapping.AutoMapper" Version="8.0.5.11" /> <PackageReference Include="Fake.ObjectMapping.AutoMapper" Version="$(FakePackageVersion)" />
<PackageReference Include="Fake.Rbac.Application" Version="8.0.5.11" /> <PackageReference Include="Fake.Rbac.Application" Version="$(FakePackageVersion)" />
<PackageReference Include="Fake.Rbac.Infrastructure" Version="8.0.5.11" /> <PackageReference Include="Fake.Rbac.Infrastructure" Version="$(FakePackageVersion)" />
<PackageReference Include="MiniExcel" Version="1.43.1" /> <PackageReference Include="MiniExcel" Version="1.43.1" />
</ItemGroup> </ItemGroup>

View File

@ -23,9 +23,9 @@ public class CustomerService : ApplicationService
private ICustomerRepository CustomerRepository => LazyServiceProvider.GetRequiredService<ICustomerRepository>(); private ICustomerRepository CustomerRepository => LazyServiceProvider.GetRequiredService<ICustomerRepository>();
private IUserService UserService => LazyServiceProvider.GetRequiredService<IUserService>(); private UserService UserService => LazyServiceProvider.GetRequiredService<UserService>();
private IRoleService RoleService => LazyServiceProvider.GetRequiredService<IRoleService>(); private RoleService RoleService => LazyServiceProvider.GetRequiredService<RoleService>();
private FakeRbacDbContext RbacDbContext => LazyServiceProvider.GetRequiredService<FakeRbacDbContext>(); private FakeRbacDbContext RbacDbContext => LazyServiceProvider.GetRequiredService<FakeRbacDbContext>();

View File

@ -7,8 +7,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Fake.DomainDrivenDesign" Version="8.0.5.11" /> <PackageReference Include="Fake.Ddd.Domain" Version="$(FakePackageVersion)" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.214" /> <PackageReference Include="Fake.SqlSugarCore" Version="$(FakePackageVersion)" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -3,7 +3,7 @@ using Fake.Modularity;
namespace Oms.Domain; namespace Oms.Domain;
[DependsOn(typeof(FakeDomainDrivenDesignModule))] [DependsOn(typeof(FakeDddDomainModule))]
public class OmsDomainModule : FakeModule public class OmsDomainModule : FakeModule
{ {
} }

View File

@ -7,7 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Fake.SqlSugarCore" Version="8.0.5.11" /> <PackageReference Include="Fake.SqlSugarCore" Version="$(FakePackageVersion)" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -2,7 +2,6 @@ using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims; using System.Security.Claims;
using Fake.Application; using Fake.Application;
using Fake.Domain.Exceptions; using Fake.Domain.Exceptions;
using Fake.Helpers;
using Fake.Rbac.Application.Dtos.Auth; using Fake.Rbac.Application.Dtos.Auth;
using Fake.Rbac.Application.Dtos.Menu; using Fake.Rbac.Application.Dtos.Menu;
using Fake.Rbac.Application.Dtos.User; using Fake.Rbac.Application.Dtos.User;
@ -11,10 +10,8 @@ using Fake.Rbac.Application.Services;
using Fake.Rbac.Domain.Managers; using Fake.Rbac.Domain.Managers;
using Fake.Rbac.Domain.UserAggregate; using Fake.Rbac.Domain.UserAggregate;
using Fake.Rbac.Infrastructure; using Fake.Rbac.Infrastructure;
using Fake.Security.Claims; using Fake.Users;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Oms.Application.Shared; using Oms.Application.Shared;
@ -33,8 +30,8 @@ namespace SimpleAdmin.Api.Auth;
[ApiExplorerSettings(GroupName = "RBAC")] [ApiExplorerSettings(GroupName = "RBAC")]
public class AuthService( public class AuthService(
AccountManager accountManager, AccountManager accountManager,
IUserService userService, UserService userService,
IMenuService menuService, MenuService menuService,
IJwtService jwtService, IJwtService jwtService,
IUserRepository userRepository, IUserRepository userRepository,
IWebHostEnvironment webHostEnvironment, IWebHostEnvironment webHostEnvironment,
@ -43,6 +40,8 @@ public class AuthService(
ICustomerRepository customerRepository) ICustomerRepository customerRepository)
: ApplicationService : ApplicationService
{ {
private Guid CurrentUserGuid => CurrentUser.FindClaimValueOrNull(ClaimTypes.NameIdentifier)!.To<Guid>();
/// <summary> /// <summary>
/// 用户或客户登录。 /// 用户或客户登录。
/// </summary> /// </summary>
@ -116,12 +115,10 @@ public class AuthService(
if (IsCustomerPrincipal()) if (IsCustomerPrincipal())
{ {
var currentUserId = CurrentUser.Id ?? throw new UnauthorizedAccessException("用户未登录"); return await BuildAdminUserInfoAsync(CurrentUserGuid, cancellationToken);
return await BuildAdminUserInfoAsync(currentUserId, cancellationToken);
} }
var userId = CurrentUser.Id ?? throw new UnauthorizedAccessException("用户未登录"); return await BuildAdminUserInfoAsync(CurrentUserGuid, cancellationToken);
return await BuildAdminUserInfoAsync(userId, cancellationToken);
} }
/// <summary> /// <summary>
@ -138,9 +135,8 @@ public class AuthService(
await ChangeCustomerPasswordAsync(input.OldPassword, input.NewPassword, cancellationToken); await ChangeCustomerPasswordAsync(input.OldPassword, input.NewPassword, cancellationToken);
return; return;
} }
var userId = CurrentUser.Id ?? throw new UnauthorizedAccessException("用户未登录"); await accountManager.UpdatePasswordAsync(CurrentUserGuid, input.OldPassword, input.NewPassword, cancellationToken);
await accountManager.UpdatePasswordAsync(userId, input.OldPassword, input.NewPassword, cancellationToken);
} }
/// <summary> /// <summary>
@ -154,7 +150,7 @@ public class AuthService(
{ {
EnsureAdminPrincipal(); EnsureAdminPrincipal();
var userId = CurrentUser.Id ?? throw new UnauthorizedAccessException("用户未登录"); var userId = CurrentUserGuid;
var user = await userRepository.FirstAsync(u => u.Id == userId, cancellationToken: cancellationToken); var user = await userRepository.FirstAsync(u => u.Id == userId, cancellationToken: cancellationToken);
user.Update(input.Name, input.Email); user.Update(input.Name, input.Email);
await userRepository.UpdateAsync(user, cancellationToken: cancellationToken); await userRepository.UpdateAsync(user, cancellationToken: cancellationToken);
@ -173,7 +169,7 @@ public class AuthService(
{ {
EnsureAdminPrincipal(); EnsureAdminPrincipal();
var userId = CurrentUser.Id ?? throw new UnauthorizedAccessException("用户未登录"); var userId = CurrentUserGuid;
if (file == null || file.Length == 0) if (file == null || file.Length == 0)
{ {
throw new DomainException("请选择要上传的文件"); throw new DomainException("请选择要上传的文件");
@ -415,7 +411,7 @@ public class AuthService(
return new CustomerPrincipalContext return new CustomerPrincipalContext
{ {
PrincipalId = CurrentUser.Id ?? throw new UnauthorizedAccessException("客户未登录"), PrincipalId = CurrentUserGuid,
Customer = customer, Customer = customer,
DisplayName = customer.WechatNickname ?? customer.CustomerName, DisplayName = customer.WechatNickname ?? customer.CustomerName,
AccountCode = customer.CustomerCode, AccountCode = customer.CustomerCode,

View File

@ -4,7 +4,7 @@ using Fake.Rbac.Application.Services;
namespace SimpleAdmin.Api.Auth; namespace SimpleAdmin.Api.Auth;
public class CustomerRoleSeedContributor(IRoleService roleService) : IDataSeedContributor public class CustomerRoleSeedContributor(RoleService roleService) : IDataSeedContributor
{ {
public const string CustomerRoleCode = "Customer"; public const string CustomerRoleCode = "Customer";
public const string CustomerRoleName = "客户"; public const string CustomerRoleName = "客户";

View File

@ -6,21 +6,13 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Fake.Autofac" Version="8.0.5.11" /> <PackageReference Include="Fake.Autofac" Version="$(FakePackageVersion)" />
<PackageReference Include="Fake.Consul" Version="8.0.5.11" /> <PackageReference Include="Fake.Consul" Version="$(FakePackageVersion)" />
<PackageReference Include="Fake.Rbac.Application" Version="8.0.5.11" /> <PackageReference Include="Fake.Rbac.Application" Version="$(FakePackageVersion)" />
<PackageReference Include="Fake.Serilog" Version="8.0.5.11" /> <PackageReference Include="Fake.Serilog" Version="$(FakePackageVersion)" />
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" /> <PackageReference Include="Serilog.AspNetCore" Version="8.0.3"/>
</ItemGroup>
<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -4,12 +4,14 @@ using Fake.Modularity;
using Fake.Rbac.Application; using Fake.Rbac.Application;
using Fake.Rbac.Infrastructure; using Fake.Rbac.Infrastructure;
using Fake.AspNetCore.Auditing; using Fake.AspNetCore.Auditing;
using Fake.AspNetCore.Mvc; using Fake.AspNetCore.Authentication;
using Fake.AspNetCore.ExceptionHandling;
using Fake.AspNetCore.Newtonsoft;
using Fake.AspNetCore.Swagger;
using Fake.FeiShu; using Fake.FeiShu;
using Fake.Security.Claims; using Fake.Security.Claims;
using Fake.Serilog; using Fake.Serilog;
using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.Logging;
using Oms.Application; using Oms.Application;
using Oms.SqlSugarCore; using Oms.SqlSugarCore;
using SimpleAdmin.Api.Auth; using SimpleAdmin.Api.Auth;
@ -53,6 +55,9 @@ public class SimpleAdminApiModule : FakeModule
settings.TypePredicate = type => type != typeof(Fake.Rbac.Application.Services.AuthService); settings.TypePredicate = type => type != typeof(Fake.Rbac.Application.Services.AuthService);
}); });
}); });
//Json格式化全局处理
context.Services.AddFakeNewtonsoft();
services.AddFakeAspNetCoreAuditing(); services.AddFakeAspNetCoreAuditing();

View File

@ -14,7 +14,7 @@ namespace SimpleAdmin.Api;
/// 自定义simple-admin auth jwt service /// 自定义simple-admin auth jwt service
/// </summary> /// </summary>
[Dependency(Replace = true)] [Dependency(Replace = true)]
public class SimpleJwtService(IOptions<JwtOptions> jwtOptions, IUserService userService, FakeRbacDbContext rbacDbContext) public class SimpleJwtService(IOptions<FakeJwtOptions> jwtOptions, UserService userService, FakeRbacDbContext rbacDbContext)
: JwtService(jwtOptions, userService) : JwtService(jwtOptions, userService)
{ {
public override async Task<List<Claim>> GenerateClaimsByUserIdAsync(Guid userId, public override async Task<List<Claim>> GenerateClaimsByUserIdAsync(Guid userId,
@ -28,6 +28,7 @@ public class SimpleJwtService(IOptions<JwtOptions> jwtOptions, IUserService user
{ {
claims.RemoveAll(x => x.Type == FakeClaimTypes.UserId); claims.RemoveAll(x => x.Type == FakeClaimTypes.UserId);
claims.Add(new Claim(FakeClaimTypes.UserId, mapId.Value.ToString())); claims.Add(new Claim(FakeClaimTypes.UserId, mapId.Value.ToString()));
claims.Add(new Claim(ClaimTypes.NameIdentifier, userId.ToString()));
} }
return claims; return claims;