diff --git a/common.props b/common.props index 6dfdd8f..5bdca0a 100644 --- a/common.props +++ b/common.props @@ -1,7 +1,7 @@ latest - enable + enable diff --git a/src/InterfaceForward.Api/InterfaceForward.Api.csproj b/src/InterfaceForward.Api/InterfaceForward.Api.csproj index 51a3bbe..7672114 100644 --- a/src/InterfaceForward.Api/InterfaceForward.Api.csproj +++ b/src/InterfaceForward.Api/InterfaceForward.Api.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/InterfaceForward.Api/InterfaceForwardApiModule.cs b/src/InterfaceForward.Api/InterfaceForwardApiModule.cs index 4f52e70..a2acc56 100644 --- a/src/InterfaceForward.Api/InterfaceForwardApiModule.cs +++ b/src/InterfaceForward.Api/InterfaceForwardApiModule.cs @@ -1,6 +1,7 @@ using Fake.AspNetCore; using Fake.AspNetCore.Auditing; using Fake.AspNetCore.Mvc.Conventions; +using Fake.AspNetCore.Mvc.Filters; using Fake.Autofac; using Fake.Modularity; using InterfaceForward.Application; @@ -28,6 +29,7 @@ public class InterfaceForwardApiModule : FakeModule services.AddFakeSwaggerGen() .AddFakeExceptionFilter() .AddFakeValidationActionFilter() + .AddFakeUnitOfWorkActionFilter() .AddFakeAspNetCoreAuditing(); services.AddCors(options => diff --git a/src/InterfaceForward.Api/appsettings.json b/src/InterfaceForward.Api/appsettings.json index a3c9a1e..0a4208d 100644 --- a/src/InterfaceForward.Api/appsettings.json +++ b/src/InterfaceForward.Api/appsettings.json @@ -27,6 +27,9 @@ "http://localhost:8888" ] }, + "ConnectionStrings":{ + "Default": "server=baget.xiaolipro.cn;database=interface_forward;uid=dev;pwd=itd!@#123;charset=utf8mb4;" + }, "FeiShuNotice": { "Title": "InterfaceForward-Dev", "Webhook": "https://open.feishu.cn/open-apis/bot/v2/hook/255c44ff-5891-4902-9b6a-6d0250e745f7" diff --git a/src/InterfaceForward.Application/InterfaceForward.Application.csproj b/src/InterfaceForward.Application/InterfaceForward.Application.csproj index 5f69f77..48745e6 100644 --- a/src/InterfaceForward.Application/InterfaceForward.Application.csproj +++ b/src/InterfaceForward.Application/InterfaceForward.Application.csproj @@ -17,8 +17,8 @@ - - + + diff --git a/src/InterfaceForward.Application/Services/App/AppsService.cs b/src/InterfaceForward.Application/Services/App/AppsService.cs index 28ebdb7..42cd0ab 100644 --- a/src/InterfaceForward.Application/Services/App/AppsService.cs +++ b/src/InterfaceForward.Application/Services/App/AppsService.cs @@ -1,5 +1,6 @@ using System.ComponentModel.DataAnnotations; using System.Text; +using Fake.UnitOfWork; using InterfaceForward.Application.Contracts.Dtos.App; using InterfaceForward.Application.Helpers; using InterfaceForward.Application.OSS; diff --git a/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj b/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj index df62c1c..c63d79b 100644 --- a/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj +++ b/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj @@ -11,6 +11,6 @@ - + diff --git a/src/InterfaceForward.Repositories/App/Services/AppRepository.cs b/src/InterfaceForward.Repositories/App/Services/AppRepository.cs index 35ae6ea..7b6ac73 100644 --- a/src/InterfaceForward.Repositories/App/Services/AppRepository.cs +++ b/src/InterfaceForward.Repositories/App/Services/AppRepository.cs @@ -7,6 +7,14 @@ namespace InterfaceForward.Repositories.App.Services /// public class AppRepository : BasicRepository, IAppRepository, IScopedDependency { + public IUpdateable AsUpdateable() + { + return Context.Updateable(); + } + public IUpdateable AsUpdateable(AppEntity updateObj) + { + return Context.Updateable(updateObj); + } } } diff --git a/src/InterfaceForward.Repositories/App/Services/AppScopeRepository.cs b/src/InterfaceForward.Repositories/App/Services/AppScopeRepository.cs index 7961629..5e4f63c 100644 --- a/src/InterfaceForward.Repositories/App/Services/AppScopeRepository.cs +++ b/src/InterfaceForward.Repositories/App/Services/AppScopeRepository.cs @@ -1,4 +1,5 @@ -using InterfaceForward.Repositories.App.Entitys; +using System.Linq.Expressions; +using InterfaceForward.Repositories.App.Entitys; using InterfaceForward.Repositories.Interface.Entitys; namespace InterfaceForward.Repositories.App.Services @@ -8,6 +9,16 @@ namespace InterfaceForward.Repositories.App.Services /// public class AppScopeRepository : BasicRepository, IAppScopeRepository, IScopedDependency { + public Task UpdateAsync(Expression> columns, Expression> whereExpression) + { + return Context.Updateable().Where(whereExpression).UpdateColumns(columns).ExecuteCommandHasChangeAsync(); + } + + public IUpdateable AsUpdateable() + { + return Context.Updateable(); + } + public async Task GetAppScopeAsync(int appId, string interfaceCode) { return await AsQueryable() diff --git a/src/InterfaceForward.Repositories/App/Services/IAppRepository.cs b/src/InterfaceForward.Repositories/App/Services/IAppRepository.cs index 0a26013..ddc632f 100644 --- a/src/InterfaceForward.Repositories/App/Services/IAppRepository.cs +++ b/src/InterfaceForward.Repositories/App/Services/IAppRepository.cs @@ -7,8 +7,6 @@ namespace InterfaceForward.Repositories.App.Services; /// public interface IAppRepository:IBasicRepository { - ISugarQueryable AsQueryable(); - IUpdateable AsUpdateable(); IUpdateable AsUpdateable(AppEntity updateObj); diff --git a/src/InterfaceForward.Repositories/App/Services/IAppScopeRepository.cs b/src/InterfaceForward.Repositories/App/Services/IAppScopeRepository.cs index e6506af..5d054aa 100644 --- a/src/InterfaceForward.Repositories/App/Services/IAppScopeRepository.cs +++ b/src/InterfaceForward.Repositories/App/Services/IAppScopeRepository.cs @@ -8,7 +8,7 @@ namespace InterfaceForward.Repositories.App.Services /// public interface IAppScopeRepository { - Task UpdateAsync(Expression> columns, Expression> whereExpression); + Task UpdateAsync(Expression> columns, Expression> whereExpression); ISugarQueryable AsQueryable(); diff --git a/src/InterfaceForward.Repositories/BasicRepository.cs b/src/InterfaceForward.Repositories/BasicRepository.cs index 08b0e65..01ce14c 100644 --- a/src/InterfaceForward.Repositories/BasicRepository.cs +++ b/src/InterfaceForward.Repositories/BasicRepository.cs @@ -1,6 +1,8 @@ using System.Linq.Expressions; using Fake; -using Fake.SqlSugarCore; +using Fake.DomainDrivenDesign.Entities; +using Fake.DomainDrivenDesign.Repositories.SqlSugarCore; +using Fake.UnitOfWork; namespace InterfaceForward.Repositories; @@ -8,12 +10,18 @@ namespace InterfaceForward.Repositories; /// 仓储基类实现 /// /// -public class BasicRepository : SimpleClient, IBasicRepository where T : class, new() +public class BasicRepository : SqlSugarRepository, IBasicRepository where T : class, IAggregateRoot, new() { - public ISugarDbContextProvider DbContextProvider { get; set; } = null!; - public BasicRepository() + protected ISqlSugarClient Context => GetDbContextAsync().Result.SqlSugarClient; + + public ISugarQueryable AsQueryable() { - Context = DbContextProvider.GetDbContextAsync(default).Result.SqlSugarClient; + return Context.Queryable(); + } + + public async Task GetFirstAsync(Expression> whereExpression) + { + return await AsQueryable().FirstAsync(whereExpression); } public async Task GetFirstAsync(Expression> whereExpression, @@ -22,10 +30,26 @@ public class BasicRepository : SimpleClient, IBasicRepository where T : return await Context.Queryable().Where(whereExpression).Select(resultExpression).FirstAsync(); } + public async Task> GetListAsync(Expression> whereExpression) + { + return await AsQueryable().Where(whereExpression).ToListAsync(); + } + public async Task> GetListAsync(Expression> whereExpression, Expression> resultExpression) { - return await Context.Queryable().Where(whereExpression).Select(resultExpression).ToListAsync(); + var ctx = await GetDbContextAsync(); + return await ctx.SqlSugarClient.Queryable().Where(whereExpression).Select(resultExpression).ToListAsync(); + } + + public async Task CountAsync(Expression> exp) + { + return await AsQueryable().Where(exp).CountAsync(); + } + + public async Task IsAnyAsync(Expression> exp) + { + return await AsQueryable().Where(exp).AnyAsync(); } public async Task UpdateAsync(T entity, Expression>? ignoreColumns) @@ -64,10 +88,25 @@ public class BasicRepository : SimpleClient, IBasicRepository where T : // tips: required where if (where == default) return false; - + return await Context.Updateable() .Where(where) .SetColumns(nameof(ISoftDelete.IsDeleted), 1) .ExecuteCommandHasChangeAsync(); } + + public async Task InsertAsync(T insertObj) + { + return await Context.Insertable(insertObj).ExecuteCommandAsync() > 0; + } + + public async Task InsertReturnIdentityAsync(T insertObj) + { + return await Context.Insertable(insertObj).ExecuteReturnIdentityAsync(); + } + + public async Task InsertRangeAsync(List entities) + { + return await Context.Insertable(entities).ExecuteCommandAsync() > 0; + } } \ No newline at end of file diff --git a/src/InterfaceForward.Repositories/IBasicRepository.cs b/src/InterfaceForward.Repositories/IBasicRepository.cs index 83d4726..7eecccc 100644 --- a/src/InterfaceForward.Repositories/IBasicRepository.cs +++ b/src/InterfaceForward.Repositories/IBasicRepository.cs @@ -1,5 +1,4 @@ using System.Linq.Expressions; - namespace InterfaceForward.Repositories; public interface IBasicRepository @@ -11,7 +10,7 @@ public interface IBasicRepository /// /// /// - Task GetFirstAsync(Expression> whereExpression); + Task GetFirstAsync(Expression> whereExpression); Task GetFirstAsync(Expression> whereExpression,Expression> resultExpression); diff --git a/src/InterfaceForward.Repositories/Interface/Entitys/InterfaceMapPublishedEntity.cs b/src/InterfaceForward.Repositories/Interface/Entitys/InterfaceMapPublishedEntity.cs index 88ca907..21e266e 100644 --- a/src/InterfaceForward.Repositories/Interface/Entitys/InterfaceMapPublishedEntity.cs +++ b/src/InterfaceForward.Repositories/Interface/Entitys/InterfaceMapPublishedEntity.cs @@ -6,7 +6,7 @@ namespace InterfaceForward.Repositories.Interface.Entitys; /// 接口映射明细表 /// [SugarTable("t_interface_map_published")] -public class InterfaceMapPublishedEntity: CreateAuditedEntity +public class InterfaceMapPublishedEntity: CreateAuditedEntity,IAggregateRoot { /// /// id diff --git a/src/InterfaceForward.Repositories/Interface/Services/InterfaceReturnConfigRepository.cs b/src/InterfaceForward.Repositories/Interface/Services/InterfaceReturnConfigRepository.cs index 7a5d852..6ba5622 100644 --- a/src/InterfaceForward.Repositories/Interface/Services/InterfaceReturnConfigRepository.cs +++ b/src/InterfaceForward.Repositories/Interface/Services/InterfaceReturnConfigRepository.cs @@ -16,9 +16,15 @@ namespace InterfaceForward.Repositories.Interface.Services .ToListAsync(); } + public async Task InsertOrUpdateAsync(InterfaceReturnConfigEntity data, CancellationToken cancellationToken) + { + Context.Ado.CancellationToken = cancellationToken; + return await Context.Storageable(data).ExecuteCommandAsync(cancellationToken) > 0; + } + public async Task DeleteConfigByIdAsync(int id) { - await AsUpdateable().SetColumns(x => x.IsDeleted == true) + await Context.Updateable().SetColumns(x => x.IsDeleted == true) .Where(x => x.Id == id).ExecuteCommandAsync(); } } diff --git a/src/InterfaceForward.Repositories/InterfaceForward.Repositories.csproj b/src/InterfaceForward.Repositories/InterfaceForward.Repositories.csproj index cd2c8a8..48c57d8 100644 --- a/src/InterfaceForward.Repositories/InterfaceForward.Repositories.csproj +++ b/src/InterfaceForward.Repositories/InterfaceForward.Repositories.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/InterfaceForward.Repositories/InterfaceForwardRepositoriesModule.cs b/src/InterfaceForward.Repositories/InterfaceForwardRepositoriesModule.cs index 2498fcf..c2c2c81 100644 --- a/src/InterfaceForward.Repositories/InterfaceForwardRepositoriesModule.cs +++ b/src/InterfaceForward.Repositories/InterfaceForwardRepositoriesModule.cs @@ -1,7 +1,24 @@ using Fake.Modularity; +using Fake.SqlSugarCore; +using Fake.UnitOfWork; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; namespace InterfaceForward.Repositories; +[DependsOn(typeof(FakeUnitOfWorkModule))] +[DependsOn(typeof(FakeSqlSugarCoreModule))] public class InterfaceForwardRepositoriesModule : FakeModule { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + context.Services.AddSugarDbContext(options => + { + options.ConnectionString = configuration.GetConnectionString("Default")!; + options.DbType = DbType.MySql; + }); + + context.Services.AddScoped(typeof(IBasicRepository<>), typeof(BasicRepository<>)); + } } \ No newline at end of file diff --git a/src/InterfaceForward.Repositories/ServiceProvider/Entitys/ServiceProviderAccountFieldValueEntity.cs b/src/InterfaceForward.Repositories/ServiceProvider/Entitys/ServiceProviderAccountFieldValueEntity.cs index 55b7468..4c17255 100644 --- a/src/InterfaceForward.Repositories/ServiceProvider/Entitys/ServiceProviderAccountFieldValueEntity.cs +++ b/src/InterfaceForward.Repositories/ServiceProvider/Entitys/ServiceProviderAccountFieldValueEntity.cs @@ -1,11 +1,13 @@ -namespace InterfaceForward.Repositories.ServiceProvider.Entitys; +using Fake.DomainDrivenDesign.Entities; + +namespace InterfaceForward.Repositories.ServiceProvider.Entitys; /// /// 服务商账户授权表 /// [SugarTable("t_service_provider_account_field_value")] -public class ServiceProviderAccountFieldValueEntity +public class ServiceProviderAccountFieldValueEntity: Entity, IAggregateRoot { /// /// 自增主键 diff --git a/src/InterfaceForward.Repositories/ServiceProvider/Services/FixedParameterRepository.cs b/src/InterfaceForward.Repositories/ServiceProvider/Services/FixedParameterRepository.cs index 42f2a49..b8970d1 100644 --- a/src/InterfaceForward.Repositories/ServiceProvider/Services/FixedParameterRepository.cs +++ b/src/InterfaceForward.Repositories/ServiceProvider/Services/FixedParameterRepository.cs @@ -7,7 +7,7 @@ public class FixedParameterRepository : BasicRepository, { public async Task UpdateFieldAsync(FixedParameterEntity entity) { - await AsUpdateable(entity) + await Context.Updateable(entity) .IgnoreColumns(x => new {x.ServiceProviderId, x.InterfaceId}) .IgnoreColumns(ignoreAllNullColumns:true, ignoreAllDefaultValue:true) .ExecuteCommandAsync(); diff --git a/src/InterfaceForward.Repositories/ServiceProvider/Services/IServiceProviderAccountFieldValueRepository.cs b/src/InterfaceForward.Repositories/ServiceProvider/Services/IServiceProviderAccountFieldValueRepository.cs index 2638ec4..1a19962 100644 --- a/src/InterfaceForward.Repositories/ServiceProvider/Services/IServiceProviderAccountFieldValueRepository.cs +++ b/src/InterfaceForward.Repositories/ServiceProvider/Services/IServiceProviderAccountFieldValueRepository.cs @@ -30,13 +30,13 @@ public class ServiceProviderAccountFieldValueRepository : BasicRepository public async Task AddFieldValueRangeAsync(List entities) { - await AsInsertable(entities).ExecuteCommandAsync(); + await Context.Insertable(entities).ExecuteCommandAsync(); } /// public async Task BatchDeleteByAccountIdAsync(int accountId) { - await AsDeleteable() + await Context.Deleteable() .Where(x => x.AccountId == accountId) .ExecuteCommandAsync(); } diff --git a/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderAccountFieldRepository.cs b/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderAccountFieldRepository.cs index 7f3145b..a6d93db 100644 --- a/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderAccountFieldRepository.cs +++ b/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderAccountFieldRepository.cs @@ -8,12 +8,12 @@ public class ServiceProviderAccountFieldRepository : BasicRepository entities) { - await AsInsertable(entities).ExecuteCommandAsync(); + await Context.Insertable(entities).ExecuteCommandAsync(); } public async Task UpdateAccountFieldRangeAsync(List entities) { - await AsUpdateable(entities) + await Context.Updateable(entities) .UpdateColumns(x => new { x.FieldName, @@ -65,7 +65,7 @@ where a.Id = @accountId and a.IsDeleted = 0 and b.IsDeleted = 0", public async Task BatchDeleteAccountFieldAsync(params int[] ids) { - await AsUpdateable() + await Context.Updateable() .Where(x => ids.Contains(x.Id)) .SetColumns(x => x.IsDeleted == true) .ExecuteCommandAsync(); diff --git a/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderAccountRepository.cs b/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderAccountRepository.cs index 018f85f..5755eb5 100644 --- a/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderAccountRepository.cs +++ b/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderAccountRepository.cs @@ -10,12 +10,12 @@ public class ServiceProviderAccountRepository : BasicRepository AddAccountAsync(ServiceProviderAccountEntity entity) { - return await AsInsertable(entity).ExecuteReturnIdentityAsync(); + return await Context.Insertable(entity).ExecuteReturnIdentityAsync(); } public async Task UpdateAccountAsync(ServiceProviderAccountEntity entity) { - await AsUpdateable(entity) + await Context.Updateable(entity) .UpdateColumns(x => new { x.MainBodyId, x.AppId, x.UpdateTime, x.UpdateUserId }) .ExecuteCommandAsync(); } diff --git a/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderRepository.cs b/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderRepository.cs index 84cdfe8..d13cbd9 100644 --- a/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderRepository.cs +++ b/src/InterfaceForward.Repositories/ServiceProvider/Services/ServiceProviderRepository.cs @@ -96,7 +96,7 @@ public class ServiceProviderRepository : BasicRepository, public async Task UpdateServiceProviderAsync(ServiceProviderEntity entity) { - var update = AsUpdateable(entity); + var update = Context.Updateable(entity); await update.ExecuteCommandAsync(); }