Browse Source

修改分页查询 带入字表

master
boxu.zheng 1 year ago
parent
commit
edfb35e075
  1. 7
      Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Application.Contracts/AppBase/IZbxBase.cs
  2. 3
      Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Application.Contracts/AppBusiness/TestSchool/Dtos/CreateUpdateTestSchoolDto.cs
  3. 2
      Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Application.Contracts/AppBusiness/TestSchool/Dtos/TestSchoolDto.cs
  4. 59
      Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Application/AppBase/ZbxBase.cs
  5. 21
      Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Application/AppBusiness/TestSchool/TestSchoolAppService.cs
  6. 2
      Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Application/Faster.Zheng.Winin.Application.csproj
  7. 33
      Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Domain.Shared/Localization/Winin/zh-Hans.json
  8. 3
      Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.EntityFrameworkCore/AppBusiness/TestSchool/TestSchoolEfCoreQuerableExtensions.cs
  9. 1
      Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Web/Faster.Zheng.Winin.Web.csproj
  10. 79
      Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Web/WininWebModule.cs
  11. 3
      Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Web/appsettings.json
  12. 1734
      Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Web/package-lock.json
  13. 3
      Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Web/package.json

7
Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Application.Contracts/AppBase/IZbxBase.cs

@ -1,11 +1,14 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
namespace Faster.Zheng.Winin.AppBase;
public interface IZbxBase<TEntity, TEntityDto, TPagedAndSortedResultRequestDto, TKey, TCreateInput, TUpdateInput>
{
Task<List<TEntity>> GetPageListByFilterAsync(SfsRequestInputBase sfsRequestInputBase,
Task<PagedResultDto<TEntityDto>> GetPageListByFilterAsync(SfsRequestInputBase sfsRequestInputBase,
bool includeDetails = false, CancellationToken cancellationToken = default);
}

3
Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Application.Contracts/AppBusiness/TestSchool/Dtos/CreateUpdateTestSchoolDto.cs

@ -21,5 +21,6 @@ public class CreateUpdateTestSchoolDto
/// <summary>
///
/// </summary>
public List<WininPermissions.TestStudentDetail> Details { get; set; }
public List<TestStudentDetailDto> Details { get; set; } =
new List<TestStudentDetailDto>();
}

2
Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Application.Contracts/AppBusiness/TestSchool/Dtos/TestSchoolDto.cs

@ -25,5 +25,5 @@ public class TestSchoolDto : AuditedEntityDto<Guid>
/// <summary>
///
/// </summary>
public List<WininPermissions.TestStudentDetail> Details { get; set; }
public List<TestStudentDetailDto> Details { get; set; }
}

59
Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Application/AppBase/ZbxBase.cs

@ -7,11 +7,13 @@ using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Faster.Zheng.Winin.AppBase.Filters;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace Faster.Zheng.Winin.AppBase;
@ -22,7 +24,7 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto,
where TEntity : class, IEntity<TKey>
where TEntityDto : IEntityDto<TKey>
{
private IRepository<TEntity, TKey> _repository;
private readonly IRepository<TEntity, TKey> _repository;
public ZbxBase(IRepository<TEntity, TKey> repository) : base(repository)
{
@ -32,28 +34,52 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto,
#region 公开接口
/// <summary>
/// 分页查询
/// 分页查询】【有筛选条件】
/// </summary>
/// <param name="sfsRequestInputBase"></param>
/// <param name="includeDetails"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
//[HttpPost]
public async Task<List<TEntity>> GetPageListByFilterAsync(SfsRequestInputBase sfsRequestInputBase,
[HttpPost("api/[controller]/base/get-list-page-by-filter")]
public async Task<PagedResultDto<TEntityDto>> GetPageListByFilterAsync(SfsRequestInputBase sfsRequestInputBase,
bool includeDetails = false, CancellationToken cancellationToken = default)
{
var expression = sfsRequestInputBase.Condition.Filters?.Count > 0
? sfsRequestInputBase.Condition.Filters.ToLambda<TEntity>()
: p => true;
var result = await GetQueryListAsync(expression, sfsRequestInputBase.SkipCount,
var resultEntities = await GetQueryListAsync(expression, sfsRequestInputBase.SkipCount,
sfsRequestInputBase.MaxResultCount,
sfsRequestInputBase.Sorting, includeDetails, cancellationToken);
return result;
var resultDtos = ObjectMapper.Map<List<TEntity>, List<TEntityDto>>(resultEntities);
//获取总数
var totalCount =await GetCountAsync(expression, cancellationToken);
return new PagedResultDto<TEntityDto>(totalCount, resultDtos);
}
/// <summary>
/// 【记录数量查询】【有筛选条件】
/// </summary>
/// <param name="expression"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("api/[controller]/base/get-count-by-filter")]
private async Task<long> GetCountAsync(Expression<Func<TEntity, bool>> expression,
CancellationToken cancellationToken = default)
{
var count= await _repository.LongCountAsync(expression, cancellationToken: cancellationToken);
return count;
}
//[HttpPost]
/// <summary>
/// 【基础】-【新增】
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/[controller]/base/create")]
public override async Task<TEntityDto> CreateAsync(TCreateInput input)
{
await CheckCreatePolicyAsync();
@ -131,13 +157,24 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto,
return await MapToGetOutputDtoAsync(entity);
}
//[HttpDelete]
/// <summary>
/// 【基础】-【删除】
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete("api/[controller]/base/delete-by-id")]
public override async Task DeleteAsync(TKey id)
{
await _repository.DeleteAsync(id);
await base.DeleteAsync(id);
}
//[HttpPut]
/// <summary>
/// 【基础】-【修改】
/// </summary>
/// <param name="id"></param>
/// <param name="input"></param>
/// <returns></returns>
[HttpPut("api/[controller]/base/update-by-id")]
public override Task<TEntityDto> UpdateAsync(TKey id, TUpdateInput input)
{
return base.UpdateAsync(id, input);
@ -161,7 +198,7 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto,
int skipCount, int maxResultCount, string sorting,
bool includeDetails = false, CancellationToken cancellationToken = default)
{
var query = await Repository.GetQueryableAsync();
var query = await Repository.WithDetailsAsync();
var entities = query.Where(expression);
entities = GetSortingQueryable(entities, sorting);

21
Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Application/AppBusiness/TestSchool/TestSchoolAppService.cs

@ -1,17 +1,19 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Faster.Zheng.Winin.AppBase;
using Faster.Zheng.Winin.Permissions;
using Faster.Zheng.Winin.AppBusiness.TestSchool.Dtos;
using Faster.Zheng.Winin.Permissions;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace Faster.Zheng.Winin.AppBusiness.TestSchool;
/// <summary>
///
/// </summary>
public class TestSchoolAppService : ZbxBase<TestSchool, TestSchoolDto, Guid, PagedAndSortedResultRequestDto, CreateUpdateTestSchoolDto, CreateUpdateTestSchoolDto>,
public class TestSchoolAppService :
//【手动】修改基类
ZbxBase<TestSchool, TestSchoolDto, Guid, PagedAndSortedResultRequestDto, CreateUpdateTestSchoolDto, CreateUpdateTestSchoolDto>,
ITestSchoolAppService
{
protected override string GetPolicyName { get; set; } = WininPermissions.TestSchool.Default;
@ -27,4 +29,13 @@ public class TestSchoolAppService : ZbxBase<TestSchool, TestSchoolDto, Guid, Pag
_repository = repository;
}
/// <summary>
/// 测试
/// </summary>
/// <returns></returns>
[HttpPost]
public Task GetAA()
{
return null;
}
}

2
Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Application/Faster.Zheng.Winin.Application.csproj

@ -6,6 +6,7 @@
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>Faster.Zheng.Winin</RootNamespace>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
@ -14,6 +15,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.1" />
<PackageReference Include="Volo.Abp.Account.Application" Version="7.2.1" />
<PackageReference Include="Volo.Abp.Identity.Application" Version="7.2.1" />

33
Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Domain.Shared/Localization/Winin/zh-Hans.json

@ -3,6 +3,37 @@
"texts": {
"Menu:Home": "首页",
"Welcome": "欢迎",
"LongWelcomeMessage": "欢迎来到该应用程序. 这是一个基于ABP框架的启动项目. 有关更多信息, 请访问 abp.io."
"LongWelcomeMessage": "欢迎来到该应用程序. 这是一个基于ABP框架的启动项目. 有关更多信息, 请访问 abp.io.",
"Permission:TestSchool": "TestSchool",
"Permission:Create": "Create",
"Permission:Update": "Update",
"Permission:Delete": "Delete",
"Menu:TestSchool": "MenuTestSchool",
"TestSchool": "TestSchool",
"TestSchoolSchoolName": "学校名称",
"TestSchoolOrderType": "TestSchoolOrderType",
"TestSchoolDetails": "TestSchoolDetails",
"CreateTestSchool": "CreateTestSchool",
"EditTestSchool": "EditTestSchool",
"TestSchoolDeletionConfirmationMessage": "Are you sure to delete the testSchool {0}?",
"SuccessfullyDeleted": "Successfully deleted",
"TableFilter": "TableFilter",
"Permission:TestStudentDetail": "TestStudentDetail",
"Menu:TestStudentDetail": "MenuTestStudentDetail",
"TestStudentDetail": "TestStudentDetail",
"TestStudentDetailMasterId": "TestStudentDetailMasterId",
"TestStudentDetailStudentName": "TestStudentDetailStudentName",
"TestStudentDetailOrderType": "TestStudentDetailOrderType",
"CreateTestStudentDetail": "CreateTestStudentDetail",
"EditTestStudentDetail": "EditTestStudentDetail",
"TestStudentDetailDeletionConfirmationMessage": "Are you sure to delete the testStudentDetail {0}?",
"Permission:DemoCar": "DemoCar",
"Menu:DemoCar": "MenuDemoCar",
"DemoCar": "DemoCar",
"DemoCarCarName": "DemoCarCarName",
"DemoCarCarColor": "DemoCarCarColor",
"CreateDemoCar": "CreateDemoCar",
"EditDemoCar": "EditDemoCar",
"DemoCarDeletionConfirmationMessage": "Are you sure to delete the demoCar {0}?"
}
}

3
Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.EntityFrameworkCore/AppBusiness/TestSchool/TestSchoolEfCoreQuerableExtensions.cs

@ -16,7 +16,8 @@ public static class TestSchoolEfCoreQueryableExtensions
}
return queryable
// .Include(x => x.xxx) // TODO: AbpHelper generated
// 【手动】手动添加子表集合
.Include(x => x.Details) // TODO: AbpHelper generated
;
}
}

1
Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Web/Faster.Zheng.Winin.Web.csproj

@ -13,6 +13,7 @@
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
<PreserveCompilationReferences>true</PreserveCompilationReferences>
<UserSecretsId>Faster.Zheng.Winin-4681b4fd-151f-4221-84a4-929d86723e4c</UserSecretsId>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>

79
Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Web/WininWebModule.cs

@ -1,4 +1,6 @@
using System;
using System.IO;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
@ -37,6 +39,10 @@ using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.UI;
using Volo.Abp.UI.Navigation;
using Volo.Abp.VirtualFileSystem;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Volo.Abp.AspNetCore.ExceptionHandling;
using Volo.Abp.Settings;
using Polly;
namespace Faster.Zheng.Winin.Web;
@ -88,10 +94,18 @@ public class WininWebModule : AbpModule
ConfigureAuthentication(context);
ConfigureUrls(configuration);
ConfigureBundles();
//设置绕权
ConfigureUseAuth(context, configuration);
ConfigureAutoMapper();
ConfigureVirtualFileSystem(hostingEnvironment);
ConfigureNavigationServices();
ConfigureAutoApiControllers();
//向前端返回完整错误日志
ConfigureExceptionHandling();
ConfigureSwaggerServices(context.Services);
}
@ -171,6 +185,15 @@ public class WininWebModule : AbpModule
options.CustomSchemaIds(type => type.FullName);
}
);
//services.AddSwaggerGen(options =>
//{
// //var xmlPath = Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml");
// options.SwaggerDoc("v1", new OpenApiInfo { Title = "Api", Version = "v1", Description = "API", });
// var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);//获取应用程序所在目录(绝对,不受工作目录影响,建议采用此方法获取路径)
// var xmlPath = Path.Combine(basePath, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml");//接口action显示注释
// options.IncludeXmlComments(Path.Combine(basePath, "Faster.Zheng.Winin.Application.xml"), true);//分层实体显示注释
//});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
@ -178,6 +201,8 @@ public class WininWebModule : AbpModule
var app = context.GetApplicationBuilder();
var env = context.GetEnvironment();
ConfigureLanguage(app);
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
@ -208,8 +233,62 @@ public class WininWebModule : AbpModule
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Winin API");
});
//app.UseAbpSwaggerUI(options =>
//{
// var apiDescriptionGroups = context.ServiceProvider.GetRequiredService<IApiDescriptionGroupCollectionProvider>().ApiDescriptionGroups.Items;
// foreach (var description in apiDescriptionGroups)
// {
// if (description.GroupName is not null)
// {
// options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", description.GroupName);
// }
// else
// {
// options.SwaggerEndpoint($"/swagger/Default/swagger.json", "Default");
// }
// }
//});
app.UseAuditing();
app.UseAbpSerilogEnrichers();
app.UseConfiguredEndpoints();
}
#region 自定义
/// <summary>
/// 向前端返回完整错误日志
/// </summary>
private void ConfigureExceptionHandling()
{
Configure<AbpExceptionHandlingOptions>(options =>
{
options.SendExceptionsDetailsToClients = true; //向前端返回完整错误日志
});
}
/// <summary>
/// 默认使用中文的本地化文件
/// </summary>
private void ConfigureLanguage(IApplicationBuilder applicationBuilder)
{
applicationBuilder.ApplicationServices.GetService<ISettingDefinitionManager>()!.Get(LocalizationSettingNames.DefaultLanguage).DefaultValue = "zh-Hans";
}
/// <summary>
/// 设置绕权
/// </summary>
/// <param name="context"></param>
/// <param name="configuration"></param>
private void ConfigureUseAuth(ServiceConfigurationContext context, IConfiguration configuration)
{
var isAlwaysAllowAuthorization = configuration.GetValue<bool>("AlwaysAllowAuthorization");
if (isAlwaysAllowAuthorization)
{
//绕过授权服务
ServiceConfigurationContext.Services.AddAlwaysAllowAuthorization();
}
}
#endregion
}

3
Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Web/appsettings.json

@ -7,5 +7,6 @@
},
"StringEncryption": {
"DefaultPassPhrase": "Aj66rJI3krHbVhS6"
}
},
"AlwaysAllowAuthorization": "True"
}

1734
Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Web/package-lock.json

File diff suppressed because it is too large

3
Code/Be/Faster.Zheng.Winin/src/Faster.Zheng.Winin.Web/package.json

@ -4,5 +4,8 @@
"private": true,
"dependencies": {
"@abp/aspnetcore.mvc.ui.theme.leptonxlite": "~2.2.0-rc.1"
},
"devDependencies": {
"eslint": "^8.43.0"
}
}
Loading…
Cancel
Save