From 97bf39f031e1b9ead964baff0ac43e104b4e64c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=B8=8C?= <小希2899451377@qq.com> Date: Tue, 14 Feb 2023 19:01:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=88=E5=A4=9A=E6=9F=A5?= =?UTF-8?q?=EF=BC=89=E6=9F=A5=E8=AF=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/SqlsugarRepository.cs | 6 +- .../IPagedAndSortedResultRequestDto.cs | 5 +- .../Dtos/PagedAndSortedResultRequestDto.cs | 4 +- .../Repositories/IRepository.cs | 3 +- .../Services/ReadOnlyAppService.cs | 97 ++++++++++++++----- .../ApplicationSwaggerDoc.xml | 7 -- .../Identity/DeptService.cs | 38 ++++---- 7 files changed, 105 insertions(+), 55 deletions(-) diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Sqlsugar/Repositories/SqlsugarRepository.cs b/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Sqlsugar/Repositories/SqlsugarRepository.cs index d6043e94..0eb51e8c 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Sqlsugar/Repositories/SqlsugarRepository.cs +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Core.Sqlsugar/Repositories/SqlsugarRepository.cs @@ -43,7 +43,11 @@ namespace Yi.Framework.Core.Sqlsugar.Repositories { return await _DbQueryable.Where(whereExpression).OrderByIF(orderBy is not null, orderBy + " " + orderByType.ToString().ToLower()).ToPageListAsync(page.PageNum, page.PageSize); } - + public async Task> GetPageListAsync(List whereExpression, IPagedAndSortedResultRequestDto page, string? orderBy, OrderByEnum orderByType = OrderByEnum.Asc) + { + return await _DbQueryable.Where(whereExpression).OrderByIF(orderBy is not null, orderBy + " " + orderByType.ToString().ToLower()).ToPageListAsync(page.PageNum, page.PageSize); + } + public async Task UpdateIgnoreNullAsync(T updateObj) { diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Dtos/Abstract/IPagedAndSortedResultRequestDto.cs b/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Dtos/Abstract/IPagedAndSortedResultRequestDto.cs index 8f55de87..2f0c8026 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Dtos/Abstract/IPagedAndSortedResultRequestDto.cs +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Dtos/Abstract/IPagedAndSortedResultRequestDto.cs @@ -1,4 +1,5 @@ -using System; +using SqlSugar; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -14,5 +15,7 @@ namespace Yi.Framework.Ddd.Dtos string? SortBy { get; set; } OrderByEnum SortType { get; set; } + List Conditions { get; set; } } + } diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Dtos/PagedAndSortedResultRequestDto.cs b/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Dtos/PagedAndSortedResultRequestDto.cs index cde6606f..9cf2d30c 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Dtos/PagedAndSortedResultRequestDto.cs +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Dtos/PagedAndSortedResultRequestDto.cs @@ -1,4 +1,5 @@ -using System; +using SqlSugar; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -13,5 +14,6 @@ namespace Yi.Framework.Ddd.Dtos public int PageSize { get; set; } = int.MaxValue; public string? SortBy { get; set; } public OrderByEnum SortType { get; set; } = OrderByEnum.Desc; + public List Conditions { get; set; } } } diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Repositories/IRepository.cs b/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Repositories/IRepository.cs index b9605f86..8cfd463d 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Repositories/IRepository.cs +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Repositories/IRepository.cs @@ -32,7 +32,8 @@ namespace Yi.Framework.Ddd.Repositories Task> GetPageListAsync(Expression> whereExpression, IPagedAndSortedResultRequestDto page); Task> GetPageListAsync(Expression> whereExpression, IPagedAndSortedResultRequestDto page, Expression>? orderByExpression = null, OrderByEnum orderByType = OrderByEnum.Asc); Task> GetPageListAsync(Expression> whereExpression, IPagedAndSortedResultRequestDto page, string? orderBy, OrderByEnum orderByType = OrderByEnum.Asc); - + Task> GetPageListAsync(List whereExpression, IPagedAndSortedResultRequestDto page, string? orderBy, OrderByEnum orderByType = OrderByEnum.Asc); + //插入 Task InsertAsync(T insertObj); diff --git a/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Services/ReadOnlyAppService.cs b/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Services/ReadOnlyAppService.cs index 912dccd2..8a2bd75b 100644 --- a/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Services/ReadOnlyAppService.cs +++ b/Yi.Framework.Net6/src/framework/Yi.Framework.Ddd/Services/ReadOnlyAppService.cs @@ -90,36 +90,83 @@ where TEntityDto : IEntityDto var entityDtos = new List(); bool isPageList = true; - - //if (totalCount > 0) - //{ - - //这里还可以追加如果是审计日志,继续拼接条件即可 - if (input is IPageTimeResultRequestDto timeInput) + //这里还可以追加如果是审计日志,继续拼接条件即可 + if (input is IPageTimeResultRequestDto timeInput) + { + if (timeInput.StartTime is not null) { - if (timeInput.StartTime is not null) + timeInput.EndTime = timeInput.EndTime ?? DateTime.Now; + } + } + + if (input is IPagedAndSortedResultRequestDto sortInput) + { + sortInput.Conditions = new List(); + System.Reflection.PropertyInfo[] properties = sortInput.GetType().GetProperties(); + string[] vs = new string[] { "PageNum", "PageSize", "SortBy", "SortType", "Conditions" }; + string[] vs1 = new string[] { "Int32", "Int64", "Double", "Decimal", "String", "Nullable`1" }; + var diffproperties = properties.Where(p => !vs.Select(v => v).Contains(p.Name)).ToArray(); + var _properties1 = properties.Where(p => vs1.Select(v => v).Contains(p.PropertyType.Name)).ToArray(); + if (_properties1.Count() > 0 && diffproperties.Count() > 0 ) + { + foreach (System.Reflection.PropertyInfo item in _properties1) { - timeInput.EndTime = timeInput.EndTime ?? DateTime.Now; + if (vs.Contains(item.Name) || !vs1.Contains(item.PropertyType.Name)) + continue; + object value = item.GetValue(sortInput, null); + if (value is null) + { + continue; + } + else + { + if (item.PropertyType.Name.StartsWith("Nullable`1")) + { + sortInput.Conditions.Add(new ConditionalModel { FieldValue = value.ToString(), FieldName = item.Name, ConditionalType = ConditionalType.Equal }); + } + if (item.PropertyType.Name.StartsWith("Int64")) + { + + if ((long)value == (long)0) + continue; + else + sortInput.Conditions.Add(new ConditionalModel { FieldValue = value.ToString(), FieldName = item.Name, ConditionalType = ConditionalType.Equal }); + } + if (item.PropertyType.Name.StartsWith("String")) + { + if (!string.IsNullOrEmpty((string)value)) + { + sortInput.Conditions.Add(new ConditionalModel { FieldValue = value.ToString(), FieldName = item.Name, ConditionalType = ConditionalType.Like }); + } + + } + if (item.PropertyType.Name.StartsWith("DateTime")) + { + if (item.Name == "StartTime") + { + sortInput.Conditions.Add(new ConditionalModel { FieldValue = value.ToString(), FieldName = item.Name, ConditionalType = ConditionalType.GreaterThanOrEqual }); + } + else if (item.Name == "EndTime") + { + sortInput.Conditions.Add(new ConditionalModel { FieldValue = value.ToString(), FieldName = item.Name, ConditionalType = ConditionalType.LessThanOrEqual }); + } + } + } } + entities = await _repository.GetPageListAsync(sortInput.Conditions, sortInput, sortInput.SortBy, sortInput.SortType); + } + else { + entities = await _repository.GetPageListAsync(_=>true, sortInput, sortInput.SortBy, sortInput.SortType); } - - - - if (input is IPagedAndSortedResultRequestDto sortInput) - { - entities = await _repository.GetPageListAsync(_ => true, sortInput,sortInput.SortBy, sortInput.SortType); - } - - - else - { - isPageList = false; - entities = await _repository.GetListAsync(); - } - entityDtos = await MapToGetListOutputDtosAsync(entities); - //} - + + } + else + { + isPageList = false; + entities = await _repository.GetListAsync(); + } + entityDtos = await MapToGetListOutputDtosAsync(entities); //如果是分页查询,还需要统计数量 if (isPageList) { diff --git a/Yi.Framework.Net6/src/project/rbac/Yi.RBAC.Application/ApplicationSwaggerDoc.xml b/Yi.Framework.Net6/src/project/rbac/Yi.RBAC.Application/ApplicationSwaggerDoc.xml index 67079074..d1b5fb09 100644 --- a/Yi.Framework.Net6/src/project/rbac/Yi.RBAC.Application/ApplicationSwaggerDoc.xml +++ b/Yi.Framework.Net6/src/project/rbac/Yi.RBAC.Application/ApplicationSwaggerDoc.xml @@ -84,13 +84,6 @@ - - - 多查 - - - - Menu服务实现 diff --git a/Yi.Framework.Net6/src/project/rbac/Yi.RBAC.Application/Identity/DeptService.cs b/Yi.Framework.Net6/src/project/rbac/Yi.RBAC.Application/Identity/DeptService.cs index 624a2110..96bd907c 100644 --- a/Yi.Framework.Net6/src/project/rbac/Yi.RBAC.Application/Identity/DeptService.cs +++ b/Yi.Framework.Net6/src/project/rbac/Yi.RBAC.Application/Identity/DeptService.cs @@ -28,24 +28,24 @@ namespace Yi.RBAC.Application.Identity return await MapToGetListOutputDtosAsync(entities); } - /// - /// 多查 - /// - /// - /// - public override async Task> GetListAsync(DeptGetListInputVo input) - { - RefAsync total = 0; - var entities = await _DbQueryable - .WhereIF(!string.IsNullOrEmpty(input.DeptName), u => u.DeptName.Contains(input.DeptName!)) - .WhereIF(input.State is not null, u => u.State == input.State) - .OrderBy(u => u.OrderNum, OrderByType.Asc) - .ToPageListAsync(input.PageNum, input.PageSize, total); - return new PagedResultDto - { - Items = await MapToGetListOutputDtosAsync(entities), - Total = total - }; - } + ///// + ///// 多查 + ///// + ///// + ///// + //public override async Task> GetListAsync(DeptGetListInputVo input) + //{ + // RefAsync total = 0; + // var entities = await _DbQueryable + // .WhereIF(!string.IsNullOrEmpty(input.DeptName), u => u.DeptName.Contains(input.DeptName!)) + // .WhereIF(input.State is not null, u => u.State == input.State) + // .OrderBy(u => u.OrderNum, OrderByType.Asc) + // .ToPageListAsync(input.PageNum, input.PageSize, total); + // return new PagedResultDto + // { + // Items = await MapToGetListOutputDtosAsync(entities), + // Total = total + // }; + //} } }