This commit is contained in:
xiaolipro 2024-05-23 17:36:08 +08:00
parent 87a2eec61b
commit 8f418b4fd7
23 changed files with 118 additions and 32 deletions

View File

@ -1,7 +1,7 @@
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <!-- <Nullable>enable</Nullable>-->
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<!-- <WarningsAsErrors>Nullable</WarningsAsErrors>--> <!-- <WarningsAsErrors>Nullable</WarningsAsErrors>-->
</PropertyGroup> </PropertyGroup>

View File

@ -16,7 +16,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\InterfaceForward.Application\InterfaceForward.Application.csproj" /> <ProjectReference Include="..\InterfaceForward.Application\InterfaceForward.Application.csproj" />
<ProjectReference Include="..\InterfaceForward.ServiceDefaults\InterfaceForward.ServiceDefaults.csproj"/> <ProjectReference Include="..\InterfaceForward.ServiceDefaults\InterfaceForward.ServiceDefaults.csproj"/>
<PackageReference Include="Fake.Autofac" Version="8.0.0-preview8.4" /> <PackageReference Include="Fake.Autofac" Version="8.0.0-preview8.5" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" /> <PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="10.0.0" /> <PackageReference Include="Serilog.Sinks.Elasticsearch" Version="10.0.0" />

View File

@ -1,6 +1,7 @@
using Fake.AspNetCore; using Fake.AspNetCore;
using Fake.AspNetCore.Auditing; using Fake.AspNetCore.Auditing;
using Fake.AspNetCore.Mvc.Conventions; using Fake.AspNetCore.Mvc.Conventions;
using Fake.AspNetCore.Mvc.Filters;
using Fake.Autofac; using Fake.Autofac;
using Fake.Modularity; using Fake.Modularity;
using InterfaceForward.Application; using InterfaceForward.Application;
@ -28,6 +29,7 @@ public class InterfaceForwardApiModule : FakeModule
services.AddFakeSwaggerGen() services.AddFakeSwaggerGen()
.AddFakeExceptionFilter() .AddFakeExceptionFilter()
.AddFakeValidationActionFilter() .AddFakeValidationActionFilter()
.AddFakeUnitOfWorkActionFilter()
.AddFakeAspNetCoreAuditing(); .AddFakeAspNetCoreAuditing();
services.AddCors(options => services.AddCors(options =>

View File

@ -27,6 +27,9 @@
"http://localhost:8888" "http://localhost:8888"
] ]
}, },
"ConnectionStrings":{
"Default": "server=baget.xiaolipro.cn;database=interface_forward;uid=dev;pwd=itd!@#123;charset=utf8mb4;"
},
"FeiShuNotice": { "FeiShuNotice": {
"Title": "InterfaceForward-Dev", "Title": "InterfaceForward-Dev",
"Webhook": "https://open.feishu.cn/open-apis/bot/v2/hook/255c44ff-5891-4902-9b6a-6d0250e745f7" "Webhook": "https://open.feishu.cn/open-apis/bot/v2/hook/255c44ff-5891-4902-9b6a-6d0250e745f7"

View File

@ -17,8 +17,8 @@
<PackageReference Include="DiffPlex" Version="1.7.2" /> <PackageReference Include="DiffPlex" Version="1.7.2" />
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" /> <PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" />
<PackageReference Include="DotNetCore.Natasha.CSharp" Version="5.2.2.1"/> <PackageReference Include="DotNetCore.Natasha.CSharp" Version="5.2.2.1"/>
<PackageReference Include="Fake.AspNetCore" Version="8.0.0-preview8.4" /> <PackageReference Include="Fake.AspNetCore" Version="8.0.0-preview8.5" />
<PackageReference Include="Fake.ObjectMapping.AutoMapper" Version="8.0.0-preview8.4" /> <PackageReference Include="Fake.ObjectMapping.AutoMapper" Version="8.0.0-preview8.5" />
<PackageReference Include="FreeRedis" Version="1.2.15" /> <PackageReference Include="FreeRedis" Version="1.2.15" />
</ItemGroup> </ItemGroup>

View File

@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Text; using System.Text;
using Fake.UnitOfWork;
using InterfaceForward.Application.Contracts.Dtos.App; using InterfaceForward.Application.Contracts.Dtos.App;
using InterfaceForward.Application.Helpers; using InterfaceForward.Application.Helpers;
using InterfaceForward.Application.OSS; using InterfaceForward.Application.OSS;

View File

@ -11,6 +11,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Fake.DomainDrivenDesign" Version="8.0.0-preview8.4" /> <PackageReference Include="Fake.DomainDrivenDesign" Version="8.0.0-preview8.5" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -7,6 +7,14 @@ namespace InterfaceForward.Repositories.App.Services
/// </summary> /// </summary>
public class AppRepository : BasicRepository<AppEntity>, IAppRepository, IScopedDependency public class AppRepository : BasicRepository<AppEntity>, IAppRepository, IScopedDependency
{ {
public IUpdateable<AppEntity> AsUpdateable()
{
return Context.Updateable<AppEntity>();
}
public IUpdateable<AppEntity> AsUpdateable(AppEntity updateObj)
{
return Context.Updateable(updateObj);
}
} }
} }

View File

@ -1,4 +1,5 @@
using InterfaceForward.Repositories.App.Entitys; using System.Linq.Expressions;
using InterfaceForward.Repositories.App.Entitys;
using InterfaceForward.Repositories.Interface.Entitys; using InterfaceForward.Repositories.Interface.Entitys;
namespace InterfaceForward.Repositories.App.Services namespace InterfaceForward.Repositories.App.Services
@ -8,6 +9,16 @@ namespace InterfaceForward.Repositories.App.Services
/// </summary> /// </summary>
public class AppScopeRepository : BasicRepository<AppScopeEntity>, IAppScopeRepository, IScopedDependency public class AppScopeRepository : BasicRepository<AppScopeEntity>, IAppScopeRepository, IScopedDependency
{ {
public Task<bool> UpdateAsync(Expression<Func<AppScopeEntity, object>> columns, Expression<Func<AppScopeEntity, bool>> whereExpression)
{
return Context.Updateable<AppScopeEntity>().Where(whereExpression).UpdateColumns(columns).ExecuteCommandHasChangeAsync();
}
public IUpdateable<AppScopeEntity> AsUpdateable()
{
return Context.Updateable<AppScopeEntity>();
}
public async Task<AppScopeEntity> GetAppScopeAsync(int appId, string interfaceCode) public async Task<AppScopeEntity> GetAppScopeAsync(int appId, string interfaceCode)
{ {
return await AsQueryable() return await AsQueryable()

View File

@ -7,8 +7,6 @@ namespace InterfaceForward.Repositories.App.Services;
/// </summary> /// </summary>
public interface IAppRepository:IBasicRepository<AppEntity> public interface IAppRepository:IBasicRepository<AppEntity>
{ {
ISugarQueryable<AppEntity> AsQueryable();
IUpdateable<AppEntity> AsUpdateable(); IUpdateable<AppEntity> AsUpdateable();
IUpdateable<AppEntity> AsUpdateable(AppEntity updateObj); IUpdateable<AppEntity> AsUpdateable(AppEntity updateObj);

View File

@ -8,7 +8,7 @@ namespace InterfaceForward.Repositories.App.Services
/// </summary> /// </summary>
public interface IAppScopeRepository public interface IAppScopeRepository
{ {
Task<bool> UpdateAsync(Expression<Func<AppScopeEntity, AppScopeEntity>> columns, Expression<Func<AppScopeEntity, bool>> whereExpression); Task<bool> UpdateAsync(Expression<Func<AppScopeEntity, object>> columns, Expression<Func<AppScopeEntity, bool>> whereExpression);
ISugarQueryable<AppScopeEntity> AsQueryable(); ISugarQueryable<AppScopeEntity> AsQueryable();

View File

@ -1,6 +1,8 @@
using System.Linq.Expressions; using System.Linq.Expressions;
using Fake; using Fake;
using Fake.SqlSugarCore; using Fake.DomainDrivenDesign.Entities;
using Fake.DomainDrivenDesign.Repositories.SqlSugarCore;
using Fake.UnitOfWork;
namespace InterfaceForward.Repositories; namespace InterfaceForward.Repositories;
@ -8,12 +10,18 @@ namespace InterfaceForward.Repositories;
/// 仓储基类实现 /// 仓储基类实现
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
public class BasicRepository<T> : SimpleClient<T>, IBasicRepository<T> where T : class, new() public class BasicRepository<T> : SqlSugarRepository<InterfaceForwardDbContext, T>, IBasicRepository<T> where T : class, IAggregateRoot, new()
{ {
public ISugarDbContextProvider<InterfaceForwardDbContext> DbContextProvider { get; set; } = null!; protected ISqlSugarClient Context => GetDbContextAsync().Result.SqlSugarClient;
public BasicRepository()
public ISugarQueryable<T> AsQueryable()
{ {
Context = DbContextProvider.GetDbContextAsync(default).Result.SqlSugarClient; return Context.Queryable<T>();
}
public async Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression)
{
return await AsQueryable().FirstAsync(whereExpression);
} }
public async Task<TResult> GetFirstAsync<TResult>(Expression<Func<T, bool>> whereExpression, public async Task<TResult> GetFirstAsync<TResult>(Expression<Func<T, bool>> whereExpression,
@ -22,10 +30,26 @@ public class BasicRepository<T> : SimpleClient<T>, IBasicRepository<T> where T :
return await Context.Queryable<T>().Where(whereExpression).Select(resultExpression).FirstAsync(); return await Context.Queryable<T>().Where(whereExpression).Select(resultExpression).FirstAsync();
} }
public async Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression)
{
return await AsQueryable().Where(whereExpression).ToListAsync();
}
public async Task<List<TResult>> GetListAsync<TResult>(Expression<Func<T, bool>> whereExpression, public async Task<List<TResult>> GetListAsync<TResult>(Expression<Func<T, bool>> whereExpression,
Expression<Func<T, TResult>> resultExpression) Expression<Func<T, TResult>> resultExpression)
{ {
return await Context.Queryable<T>().Where(whereExpression).Select(resultExpression).ToListAsync(); var ctx = await GetDbContextAsync();
return await ctx.SqlSugarClient.Queryable<T>().Where(whereExpression).Select(resultExpression).ToListAsync();
}
public async Task<int> CountAsync(Expression<Func<T, bool>> exp)
{
return await AsQueryable().Where(exp).CountAsync();
}
public async Task<bool> IsAnyAsync(Expression<Func<T, bool>> exp)
{
return await AsQueryable().Where(exp).AnyAsync();
} }
public async Task<bool> UpdateAsync(T entity, Expression<Func<T, object>>? ignoreColumns) public async Task<bool> UpdateAsync(T entity, Expression<Func<T, object>>? ignoreColumns)
@ -70,4 +94,19 @@ public class BasicRepository<T> : SimpleClient<T>, IBasicRepository<T> where T :
.SetColumns(nameof(ISoftDelete.IsDeleted), 1) .SetColumns(nameof(ISoftDelete.IsDeleted), 1)
.ExecuteCommandHasChangeAsync(); .ExecuteCommandHasChangeAsync();
} }
public async Task<bool> InsertAsync(T insertObj)
{
return await Context.Insertable(insertObj).ExecuteCommandAsync() > 0;
}
public async Task<int> InsertReturnIdentityAsync(T insertObj)
{
return await Context.Insertable(insertObj).ExecuteReturnIdentityAsync();
}
public async Task<bool> InsertRangeAsync(List<T> entities)
{
return await Context.Insertable(entities).ExecuteCommandAsync() > 0;
}
} }

View File

@ -1,5 +1,4 @@
using System.Linq.Expressions; using System.Linq.Expressions;
namespace InterfaceForward.Repositories; namespace InterfaceForward.Repositories;
public interface IBasicRepository<T> public interface IBasicRepository<T>
@ -11,7 +10,7 @@ public interface IBasicRepository<T>
/// </summary> /// </summary>
/// <param name="whereExpression"></param> /// <param name="whereExpression"></param>
/// <returns></returns> /// <returns></returns>
Task<T?> GetFirstAsync(Expression<Func<T, bool>> whereExpression); Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression);
Task<TResult> GetFirstAsync<TResult>(Expression<Func<T, bool>> whereExpression,Expression<Func<T, TResult>> resultExpression); Task<TResult> GetFirstAsync<TResult>(Expression<Func<T, bool>> whereExpression,Expression<Func<T, TResult>> resultExpression);

View File

@ -6,7 +6,7 @@ namespace InterfaceForward.Repositories.Interface.Entitys;
/// 接口映射明细表 /// 接口映射明细表
///</summary> ///</summary>
[SugarTable("t_interface_map_published")] [SugarTable("t_interface_map_published")]
public class InterfaceMapPublishedEntity: CreateAuditedEntity<int> public class InterfaceMapPublishedEntity: CreateAuditedEntity<int>,IAggregateRoot
{ {
///<summary> ///<summary>
/// id /// id

View File

@ -16,9 +16,15 @@ namespace InterfaceForward.Repositories.Interface.Services
.ToListAsync(); .ToListAsync();
} }
public async Task<bool> InsertOrUpdateAsync(InterfaceReturnConfigEntity data, CancellationToken cancellationToken)
{
Context.Ado.CancellationToken = cancellationToken;
return await Context.Storageable(data).ExecuteCommandAsync(cancellationToken) > 0;
}
public async Task DeleteConfigByIdAsync(int id) public async Task DeleteConfigByIdAsync(int id)
{ {
await AsUpdateable().SetColumns(x => x.IsDeleted == true) await Context.Updateable<InterfaceReturnConfigEntity>().SetColumns(x => x.IsDeleted == true)
.Where(x => x.Id == id).ExecuteCommandAsync(); .Where(x => x.Id == id).ExecuteCommandAsync();
} }
} }

View File

@ -7,7 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Fake.SqlSugarCore" Version="8.0.0-preview8.4" /> <PackageReference Include="Fake.SqlSugarCore" Version="8.0.0-preview8.5" />
<PackageReference Include="NEST" Version="7.17.5" /> <PackageReference Include="NEST" Version="7.17.5" />
</ItemGroup> </ItemGroup>

View File

@ -1,7 +1,24 @@
using Fake.Modularity; using Fake.Modularity;
using Fake.SqlSugarCore;
using Fake.UnitOfWork;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace InterfaceForward.Repositories; namespace InterfaceForward.Repositories;
[DependsOn(typeof(FakeUnitOfWorkModule))]
[DependsOn(typeof(FakeSqlSugarCoreModule))]
public class InterfaceForwardRepositoriesModule : FakeModule public class InterfaceForwardRepositoriesModule : FakeModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
context.Services.AddSugarDbContext<InterfaceForwardDbContext>(options =>
{
options.ConnectionString = configuration.GetConnectionString("Default")!;
options.DbType = DbType.MySql;
});
context.Services.AddScoped(typeof(IBasicRepository<>), typeof(BasicRepository<>));
}
} }

View File

@ -1,11 +1,13 @@
namespace InterfaceForward.Repositories.ServiceProvider.Entitys; using Fake.DomainDrivenDesign.Entities;
namespace InterfaceForward.Repositories.ServiceProvider.Entitys;
///<summary> ///<summary>
/// 服务商账户授权表 /// 服务商账户授权表
///</summary> ///</summary>
[SugarTable("t_service_provider_account_field_value")] [SugarTable("t_service_provider_account_field_value")]
public class ServiceProviderAccountFieldValueEntity public class ServiceProviderAccountFieldValueEntity: Entity<int>, IAggregateRoot
{ {
///<summary> ///<summary>
/// 自增主键 /// 自增主键

View File

@ -7,7 +7,7 @@ public class FixedParameterRepository : BasicRepository<FixedParameterEntity>,
{ {
public async Task UpdateFieldAsync(FixedParameterEntity entity) public async Task UpdateFieldAsync(FixedParameterEntity entity)
{ {
await AsUpdateable(entity) await Context.Updateable(entity)
.IgnoreColumns(x => new {x.ServiceProviderId, x.InterfaceId}) .IgnoreColumns(x => new {x.ServiceProviderId, x.InterfaceId})
.IgnoreColumns(ignoreAllNullColumns:true, ignoreAllDefaultValue:true) .IgnoreColumns(ignoreAllNullColumns:true, ignoreAllDefaultValue:true)
.ExecuteCommandAsync(); .ExecuteCommandAsync();

View File

@ -30,13 +30,13 @@ public class ServiceProviderAccountFieldValueRepository : BasicRepository<Servic
/// <inheritdoc /> /// <inheritdoc />
public async Task AddFieldValueRangeAsync(List<ServiceProviderAccountFieldValueEntity> entities) public async Task AddFieldValueRangeAsync(List<ServiceProviderAccountFieldValueEntity> entities)
{ {
await AsInsertable(entities).ExecuteCommandAsync(); await Context.Insertable(entities).ExecuteCommandAsync();
} }
/// <inheritdoc /> /// <inheritdoc />
public async Task BatchDeleteByAccountIdAsync(int accountId) public async Task BatchDeleteByAccountIdAsync(int accountId)
{ {
await AsDeleteable() await Context.Deleteable<ServiceProviderAccountFieldValueEntity>()
.Where(x => x.AccountId == accountId) .Where(x => x.AccountId == accountId)
.ExecuteCommandAsync(); .ExecuteCommandAsync();
} }

View File

@ -8,12 +8,12 @@ public class ServiceProviderAccountFieldRepository : BasicRepository<ServiceProv
{ {
public async Task AddAccountFieldRangeAsync(List<ServiceProviderAccountFieldEntity> entities) public async Task AddAccountFieldRangeAsync(List<ServiceProviderAccountFieldEntity> entities)
{ {
await AsInsertable(entities).ExecuteCommandAsync(); await Context.Insertable(entities).ExecuteCommandAsync();
} }
public async Task UpdateAccountFieldRangeAsync(List<ServiceProviderAccountFieldEntity> entities) public async Task UpdateAccountFieldRangeAsync(List<ServiceProviderAccountFieldEntity> entities)
{ {
await AsUpdateable(entities) await Context.Updateable(entities)
.UpdateColumns(x => new .UpdateColumns(x => new
{ {
x.FieldName, 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) public async Task BatchDeleteAccountFieldAsync(params int[] ids)
{ {
await AsUpdateable() await Context.Updateable<ServiceProviderAccountFieldEntity>()
.Where(x => ids.Contains(x.Id)) .Where(x => ids.Contains(x.Id))
.SetColumns(x => x.IsDeleted == true) .SetColumns(x => x.IsDeleted == true)
.ExecuteCommandAsync(); .ExecuteCommandAsync();

View File

@ -10,12 +10,12 @@ public class ServiceProviderAccountRepository : BasicRepository<ServiceProviderA
{ {
public async Task<int> AddAccountAsync(ServiceProviderAccountEntity entity) public async Task<int> AddAccountAsync(ServiceProviderAccountEntity entity)
{ {
return await AsInsertable(entity).ExecuteReturnIdentityAsync(); return await Context.Insertable(entity).ExecuteReturnIdentityAsync();
} }
public async Task UpdateAccountAsync(ServiceProviderAccountEntity entity) public async Task UpdateAccountAsync(ServiceProviderAccountEntity entity)
{ {
await AsUpdateable(entity) await Context.Updateable(entity)
.UpdateColumns(x => new { x.MainBodyId, x.AppId, x.UpdateTime, x.UpdateUserId }) .UpdateColumns(x => new { x.MainBodyId, x.AppId, x.UpdateTime, x.UpdateUserId })
.ExecuteCommandAsync(); .ExecuteCommandAsync();
} }

View File

@ -96,7 +96,7 @@ public class ServiceProviderRepository : BasicRepository<ServiceProviderEntity>,
public async Task UpdateServiceProviderAsync(ServiceProviderEntity entity) public async Task UpdateServiceProviderAsync(ServiceProviderEntity entity)
{ {
var update = AsUpdateable(entity); var update = Context.Updateable(entity);
await update.ExecuteCommandAsync(); await update.ExecuteCommandAsync();
} }