chore 优化代码

This commit is contained in:
2025-10-16 10:30:51 +08:00
parent f1c609b4be
commit 1f5bc3e971
367 changed files with 2705 additions and 3083 deletions

View File

@ -24,54 +24,15 @@ public class AdminDbContext :
IIdentityDbContext,
ITenantManagementDbContext
{
/* Add DbSet properties for your Aggregate Roots / Entities here. */
#region Entities from the modules
/* Notice: We only implemented IIdentityDbContext and ITenantManagementDbContext
* and replaced them for this DbContext. This allows you to perform JOIN
* queries for the entities of these modules over the repositories easily. You
* typically don't need that for other modules. But, if you need, you can
* implement the DbContext interface of the needed module and use ReplaceDbContext
* attribute just like IIdentityDbContext and ITenantManagementDbContext.
*
* More info: Replacing a DbContext of a module ensures that the related module
* uses this DbContext on runtime. Otherwise, it will use its own DbContext class.
*/
//Identity
public DbSet<IdentityUser> Users { get; set; }
public DbSet<IdentityRole> Roles { get; set; }
public DbSet<IdentityClaimType> ClaimTypes { get; set; }
public DbSet<OrganizationUnit> OrganizationUnits { get; set; }
public DbSet<IdentitySecurityLog> SecurityLogs { get; set; }
public DbSet<IdentityLinkUser> LinkUsers { get; set; }
public DbSet<IdentityUserDelegation> UserDelegations { get; set; }
public DbSet<IdentitySession> Sessions { get; set; }
// Tenant Management
public DbSet<Tenant> Tenants { get; set; }
public DbSet<TenantConnectionString> TenantConnectionStrings { get; set; }
#endregion
#region
public DbSet<Order> Orders { get; set; }
public DbSet<Worker> Workers { get; set; }
public DbSet<ServiceCategory> ServiceCategorys { get; set; }
#endregion
public AdminDbContext(DbContextOptions<AdminDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
/* Include modules to your migration db context */
builder.ConfigurePermissionManagement();
builder.ConfigureSettingManagement();
builder.ConfigureBackgroundJobs();
@ -80,14 +41,24 @@ public class AdminDbContext :
builder.ConfigureOpenIddict();
builder.ConfigureFeatureManagement();
builder.ConfigureTenantManagement();
/* Configure your own tables/entities inside here */
//builder.Entity<YourEntity>(b =>
//{
// b.ToTable(AdminConsts.DbTablePrefix + "YourEntities", AdminConsts.DbSchema);
// b.ConfigureByConvention(); //auto configure for the base class props
// //...
//});
}
}
public DbSet<IdentityUser> Users { get; set; }
public DbSet<IdentityRole> Roles { get; set; }
public DbSet<IdentityClaimType> ClaimTypes { get; set; }
public DbSet<OrganizationUnit> OrganizationUnits { get; set; }
public DbSet<IdentitySecurityLog> SecurityLogs { get; set; }
public DbSet<IdentityLinkUser> LinkUsers { get; set; }
public DbSet<IdentityUserDelegation> UserDelegations { get; set; }
public DbSet<IdentitySession> Sessions { get; set; }
public DbSet<Tenant> Tenants { get; set; }
public DbSet<TenantConnectionString> TenantConnectionStrings { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<ServiceCategory> ServiceCategories { get; set; }
public DbSet<HouseholdWorker> HouseholdWorkers { get; set; }
}

View File

@ -29,8 +29,8 @@ public class AdminDbContextFactory : IDesignTimeDbContextFactory<AdminDbContext>
{
var builder = new ConfigurationBuilder()
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../KonSoft.Admin.DbMigrator/"))
.AddJsonFile("appsettings.json", optional: false);
.AddJsonFile("appsettings.json", false);
return builder.Build();
}
}
}

View File

@ -1,13 +1,10 @@
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading;
using Volo.Abp.Threading;
namespace KonSoft.Admin.EntityFrameworkCore;
public static class AdminEfCoreEntityExtensionMappings
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
private static readonly OneTimeRunner OneTimeRunner = new();
public static void Configure()
{
@ -16,29 +13,29 @@ public static class AdminEfCoreEntityExtensionMappings
OneTimeRunner.Run(() =>
{
/* You can configure extra properties for the
* entities defined in the modules used by your application.
*
* This class can be used to map these extra properties to table fields in the database.
*
* USE THIS CLASS ONLY TO CONFIGURE EF CORE RELATED MAPPING.
* USE AdminModuleExtensionConfigurator CLASS (in the Domain.Shared project)
* FOR A HIGH LEVEL API TO DEFINE EXTRA PROPERTIES TO ENTITIES OF THE USED MODULES
*
* Example: Map a property to a table field:
/* You can configure extra properties for the
* entities defined in the modules used by your application.
*
* This class can be used to map these extra properties to table fields in the database.
*
* USE THIS CLASS ONLY TO CONFIGURE EF CORE RELATED MAPPING.
* USE AdminModuleExtensionConfigurator CLASS (in the Domain.Shared project)
* FOR A HIGH LEVEL API TO DEFINE EXTRA PROPERTIES TO ENTITIES OF THE USED MODULES
*
* Example: Map a property to a table field:
ObjectExtensionManager.Instance
.MapEfCoreProperty<IdentityUser, string>(
"MyProperty",
(entityBuilder, propertyBuilder) =>
{
propertyBuilder.HasMaxLength(128);
}
);
ObjectExtensionManager.Instance
.MapEfCoreProperty<IdentityUser, string>(
"MyProperty",
(entityBuilder, propertyBuilder) =>
{
propertyBuilder.HasMaxLength(128);
}
);
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/
});
}
}
}

View File

@ -1,6 +1,5 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Uow;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
@ -26,7 +25,7 @@ namespace KonSoft.Admin.EntityFrameworkCore;
typeof(AbpAuditLoggingEntityFrameworkCoreModule),
typeof(AbpTenantManagementEntityFrameworkCoreModule),
typeof(AbpFeatureManagementEntityFrameworkCoreModule)
)]
)]
public class AdminEntityFrameworkCoreModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
@ -41,17 +40,16 @@ public class AdminEntityFrameworkCoreModule : AbpModule
{
context.Services.AddAbpDbContext<AdminDbContext>(options =>
{
/* Remove "includeAllEntities: true" to create
* default repositories only for aggregate roots */
options.AddDefaultRepositories(includeAllEntities: true);
/* Remove "includeAllEntities: true" to create
* default repositories only for aggregate roots */
options.AddDefaultRepositories(true);
});
Configure<AbpDbContextOptions>(options =>
{
/* The main point to change your DBMS.
* See also AdminMigrationsDbContextFactory for EF Core tooling. */
/* The main point to change your DBMS.
* See also AdminMigrationsDbContextFactory for EF Core tooling. */
options.UseNpgsql();
});
}
}
}

View File

@ -1,52 +1,34 @@
using KonSoft.Admin.Entities;
using System.Diagnostics.CodeAnalysis;
using KonSoft.Admin.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
namespace KonSoft.Admin.EntityFrameworkCore.Configures
namespace KonSoft.Admin.EntityFrameworkCore.Configures;
public static class ApplicationDbContextModelBuilderExtensions
{
public static class ApplicationDbContextModelBuilderExtensions
public static void ConfigureApplication([NotNull] this ModelBuilder builder)
{
public static void ConfigureApplication([NotNull] this ModelBuilder builder)
Check.NotNull(builder, nameof(builder));
builder.Entity<Order>(b =>
{
Check.NotNull(builder, nameof(builder));
b.ToTable(AdminConsts.DbTablePrefix + nameof(Order) + AdminConsts.DbSchema);
builder.Entity<Order>(b =>
b.OwnsOne(o => o.Address, a =>
{
b.ToTable(AdminConsts.DbTablePrefix + nameof(Order) + AdminConsts.DbSchema);
b.OwnsOne(o => o.Address, a =>
{
a.Property(p => p.ContactName).HasColumnName("ContactName").HasMaxLength(50);
a.Property(p => p.ContactPhone).HasColumnName("ContactPhone").HasMaxLength(20);
a.Property(p => p.DetailAddress).HasColumnName("DetailAddress").HasMaxLength(200);
a.Property(p => p.City).HasColumnName("City").HasMaxLength(50);
a.Property(p => p.District).HasColumnName("District").HasMaxLength(50);
});
a.Property(p => p.ContactName).HasColumnName("ContactName").HasMaxLength(50);
a.Property(p => p.ContactPhone).HasColumnName("ContactPhone").HasMaxLength(20);
a.Property(p => p.DetailAddress).HasColumnName("DetailAddress").HasMaxLength(200);
a.Property(p => p.City).HasColumnName("City").HasMaxLength(50);
a.Property(p => p.District).HasColumnName("District").HasMaxLength(50);
});
builder.Entity<Worker>(b =>
{
b.ToTable(AdminConsts.DbTablePrefix + nameof(Worker) + AdminConsts.DbSchema);
});
builder.Entity<ServiceCategory>(b =>
{
b.ToTable(AdminConsts.DbTablePrefix + nameof(ServiceCategory) + AdminConsts.DbSchema);
});
}
});
builder.Entity<ServiceCategory>(b =>
{
b.ToTable(AdminConsts.DbTablePrefix + nameof(ServiceCategory) + AdminConsts.DbSchema);
});
}
}
}

View File

@ -1,8 +1,8 @@
using System;
using System.Threading.Tasks;
using KonSoft.Admin.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using KonSoft.Admin.Data;
using Volo.Abp.DependencyInjection;
namespace KonSoft.Admin.EntityFrameworkCore;
@ -31,4 +31,4 @@ public class EntityFrameworkCoreAdminDbSchemaMigrator
.Database
.MigrateAsync();
}
}
}

View File

@ -0,0 +1,16 @@
using KonSoft.Admin.Entities;
using KonSoft.Admin.IRepositories;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
namespace KonSoft.Admin.EntityFrameworkCore.Repositories;
public class HouseholdWorkerRepository : EfCoreRepository<TenantManagementDbContext, HouseholdWorker>,
IHouseholdWorkerRepository
{
public HouseholdWorkerRepository(IDbContextProvider<TenantManagementDbContext> dbContextProvider) : base(
dbContextProvider)
{
}
}

View File

@ -1,21 +1,13 @@
using KonSoft.Admin.Entities;
using KonSoft.Admin.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using KonSoft.Admin.IRepositories;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
namespace KonSoft.Admin.EntityFrameworkCore.Repositories
namespace KonSoft.Admin.EntityFrameworkCore.Repositories;
public class OrderRepository : EfCoreRepository<AdminDbContext, Order>, IOrderRepository
{
public class OrderRepository : EfCoreRepository<AdminDbContext, Order>, IOrderRepository
public OrderRepository(IDbContextProvider<AdminDbContext> dbContextProvider) : base(dbContextProvider)
{
public OrderRepository(IDbContextProvider<AdminDbContext> dbContextProvider) : base(dbContextProvider)
{
}
}
}
}

View File

@ -1,25 +1,25 @@
using KonSoft.Admin.Entities;
using KonSoft.Admin.Repositories;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using KonSoft.Admin.Entities;
using KonSoft.Admin.IRepositories;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
namespace KonSoft.Admin.EntityFrameworkCore.Repositories
{
public class ProductRepository : EfCoreRepository<AdminDbContext, Product>, IProductRepository
{
public ProductRepository(IDbContextProvider<AdminDbContext> dbContextProvider) : base(dbContextProvider)
{
}
namespace KonSoft.Admin.EntityFrameworkCore.Repositories;
public async Task<List<Product>> GetPageRootListAsync(int skipCount, int maxResultCount, Expression<Func<Product, bool>> where)
{
var queryable = await GetQueryableAsync();
return queryable.PageBy(skipCount, maxResultCount).Where(where).OrderBy(x => x.Order).ToList();
}
public class ProductRepository : EfCoreRepository<AdminDbContext, Product>, IProductRepository
{
public ProductRepository(IDbContextProvider<AdminDbContext> dbContextProvider) : base(dbContextProvider)
{
}
}
public async Task<List<Product>> GetPageRootListAsync(int skipCount, int maxResultCount,
Expression<Func<Product, bool>> where)
{
var queryable = await GetQueryableAsync();
return queryable.PageBy(skipCount, maxResultCount).Where(where).OrderBy(x => x.Order).ToList();
}
}

View File

@ -1,2 +1,3 @@
using System.Runtime.CompilerServices;
[assembly:InternalsVisibleToAttribute("KonSoft.Admin.EntityFrameworkCore.Tests")]
[assembly: InternalsVisibleToAttribute("KonSoft.Admin.EntityFrameworkCore.Tests")]