refactor: 基础设施
This commit is contained in:
@@ -12,8 +12,9 @@ using Yi.Framework.Core.Exceptions;
|
|||||||
namespace Microsoft.AspNetCore.Builder
|
namespace Microsoft.AspNetCore.Builder
|
||||||
{
|
{
|
||||||
|
|
||||||
internal class ExceptionModle
|
internal class ExceptionModle
|
||||||
{
|
{
|
||||||
|
public int Code { get; set; }
|
||||||
public string? Message { get; set; }
|
public string? Message { get; set; }
|
||||||
public string? Details { get; set; }
|
public string? Details { get; set; }
|
||||||
}
|
}
|
||||||
@@ -36,10 +37,11 @@ namespace Microsoft.AspNetCore.Builder
|
|||||||
catch (BusinessException businessEx)
|
catch (BusinessException businessEx)
|
||||||
{
|
{
|
||||||
context.Response.ContentType = "application/json;charset=utf-8";
|
context.Response.ContentType = "application/json;charset=utf-8";
|
||||||
context.Response.StatusCode = businessEx.Code.GetHashCode();
|
//context.Response.StatusCode = businessEx.Code.GetHashCode();
|
||||||
|
|
||||||
var result = new ExceptionModle
|
var result = new ExceptionModle
|
||||||
{
|
{
|
||||||
|
Code = businessEx.Code.GetHashCode(),
|
||||||
Message = businessEx.Message,
|
Message = businessEx.Message,
|
||||||
Details = businessEx.Details,
|
Details = businessEx.Details,
|
||||||
};
|
};
|
||||||
@@ -57,10 +59,11 @@ namespace Microsoft.AspNetCore.Builder
|
|||||||
//系统错误,记录日志
|
//系统错误,记录日志
|
||||||
_logger.LogError(ex, $"授权失败:{ex.Message}");
|
_logger.LogError(ex, $"授权失败:{ex.Message}");
|
||||||
//await _errorHandle.Invoer(context, ex);
|
//await _errorHandle.Invoer(context, ex);
|
||||||
context.Response.StatusCode =(int)ex.Code;
|
context.Response.StatusCode = (int)ex.Code;
|
||||||
//系统错误,需要记录
|
//系统错误,需要记录
|
||||||
var result = new ExceptionModle
|
var result = new ExceptionModle
|
||||||
{
|
{
|
||||||
|
Code = ex.Code.GetHashCode(),
|
||||||
Message = ex.Message,
|
Message = ex.Message,
|
||||||
Details = "授权失败",
|
Details = "授权失败",
|
||||||
};
|
};
|
||||||
@@ -81,6 +84,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||||||
//系统错误,需要记录
|
//系统错误,需要记录
|
||||||
var result = new ExceptionModle
|
var result = new ExceptionModle
|
||||||
{
|
{
|
||||||
|
Code = 500,
|
||||||
Message = ex.Message,
|
Message = ex.Message,
|
||||||
Details = "系统错误",
|
Details = "系统错误",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,11 +43,7 @@ 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);
|
return await _DbQueryable.Where(whereExpression).OrderByIF(orderBy is not null, orderBy + " " + orderByType.ToString().ToLower()).ToPageListAsync(page.PageNum, page.PageSize);
|
||||||
}
|
}
|
||||||
public async Task<List<T>> GetPageListAsync(List<IConditionalModel> 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<bool> UpdateIgnoreNullAsync(T updateObj)
|
public async Task<bool> UpdateIgnoreNullAsync(T updateObj)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using SqlSugar;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -15,7 +14,5 @@ namespace Yi.Framework.Ddd.Dtos
|
|||||||
string? SortBy { get; set; }
|
string? SortBy { get; set; }
|
||||||
|
|
||||||
OrderByEnum SortType { get; set; }
|
OrderByEnum SortType { get; set; }
|
||||||
List<IConditionalModel> Conditions { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using SqlSugar;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -14,6 +13,5 @@ namespace Yi.Framework.Ddd.Dtos
|
|||||||
public int PageSize { get; set; } = int.MaxValue;
|
public int PageSize { get; set; } = int.MaxValue;
|
||||||
public string? SortBy { get; set; }
|
public string? SortBy { get; set; }
|
||||||
public OrderByEnum SortType { get; set; } = OrderByEnum.Desc;
|
public OrderByEnum SortType { get; set; } = OrderByEnum.Desc;
|
||||||
public List<IConditionalModel> Conditions { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,7 @@ namespace Yi.Framework.Ddd.Repositories
|
|||||||
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, IPagedAndSortedResultRequestDto page);
|
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, IPagedAndSortedResultRequestDto page);
|
||||||
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, IPagedAndSortedResultRequestDto page, Expression<Func<T, object>>? orderByExpression = null, OrderByEnum orderByType = OrderByEnum.Asc);
|
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, IPagedAndSortedResultRequestDto page, Expression<Func<T, object>>? orderByExpression = null, OrderByEnum orderByType = OrderByEnum.Asc);
|
||||||
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, IPagedAndSortedResultRequestDto page, string? orderBy, OrderByEnum orderByType = OrderByEnum.Asc);
|
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, IPagedAndSortedResultRequestDto page, string? orderBy, OrderByEnum orderByType = OrderByEnum.Asc);
|
||||||
Task<List<T>> GetPageListAsync(List<IConditionalModel> whereExpression, IPagedAndSortedResultRequestDto page, string? orderBy, OrderByEnum orderByType = OrderByEnum.Asc);
|
|
||||||
|
|
||||||
|
|
||||||
//插入
|
//插入
|
||||||
Task<bool> InsertAsync(T insertObj);
|
Task<bool> InsertAsync(T insertObj);
|
||||||
|
|||||||
@@ -91,86 +91,36 @@ where TEntityDto : IEntityDto<TKey>
|
|||||||
var entityDtos = new List<TGetListOutputDto>();
|
var entityDtos = new List<TGetListOutputDto>();
|
||||||
|
|
||||||
bool isPageList = true;
|
bool isPageList = true;
|
||||||
//这里还可以追加如果是审计日志,继续拼接条件即可
|
|
||||||
if (input is IPageTimeResultRequestDto timeInput)
|
|
||||||
{
|
|
||||||
if (timeInput.StartTime is not null)
|
|
||||||
{
|
|
||||||
timeInput.EndTime = timeInput.EndTime ?? DateTime.Now;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input is IPagedAndSortedResultRequestDto sortInput)
|
//if (totalCount > 0)
|
||||||
{
|
//{
|
||||||
var dependsOnbuild = sortInput.GetType().GetCustomAttributes(typeof(QueryParameterAttribute), false).FirstOrDefault() as QueryParameterAttribute;
|
|
||||||
if (dependsOnbuild is null)
|
//这里还可以追加如果是审计日志,继续拼接条件即可
|
||||||
|
if (input is IPageTimeResultRequestDto timeInput)
|
||||||
{
|
{
|
||||||
entities = await _repository.GetPageListAsync(_ => true, sortInput, sortInput.SortBy, sortInput.SortType);
|
if (timeInput.StartTime is not null)
|
||||||
|
{
|
||||||
|
timeInput.EndTime = timeInput.EndTime ?? DateTime.Now;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (input is IPagedAndSortedResultRequestDto sortInput)
|
||||||
|
{
|
||||||
|
entities = await _repository.GetPageListAsync(_ => true, sortInput,sortInput.SortBy, sortInput.SortType);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sortInput.Conditions = new List<IConditionalModel>();
|
isPageList = false;
|
||||||
System.Reflection.PropertyInfo[] properties = sortInput.GetType().GetProperties();
|
entities = await _repository.GetListAsync();
|
||||||
foreach (System.Reflection.PropertyInfo item in properties)
|
|
||||||
{
|
|
||||||
var query = item.GetCustomAttributes(typeof(QueryParameterAttribute), false).FirstOrDefault() as QueryParameterAttribute;
|
|
||||||
if (query is not null)
|
|
||||||
{
|
|
||||||
object value = item.GetValue(sortInput, null);
|
|
||||||
if (value is not null)
|
|
||||||
{
|
|
||||||
if (value.ToString() == "0")
|
|
||||||
{
|
|
||||||
if (query.VerifyIsZero)
|
|
||||||
{
|
|
||||||
sortInput.Conditions.Add(new ConditionalModel { FieldValue = value.ToString(), FieldName = item.Name, ConditionalType = (ConditionalType)(int)query.QueryOperator });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
switch (query.ColumnType)
|
|
||||||
{
|
|
||||||
case ColumnTypeEnum.datetime:
|
|
||||||
if (!string.IsNullOrEmpty(query.ColumnName))
|
|
||||||
{
|
|
||||||
DateTime dt = DateTime.Now;
|
|
||||||
DateTime.TryParse(value.ToString(), out dt);
|
|
||||||
sortInput.Conditions.Add(new ConditionalModel { FieldValue = dt.ToString("yyyy-MM-dd HH:mm:ss"), FieldName = query.ColumnName, ConditionalType = (ConditionalType)(int)query.QueryOperator });
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sortInput.Conditions.Add(new ConditionalModel { FieldValue = value.ToString(), FieldName = item.Name, ConditionalType = (ConditionalType)(int)query.QueryOperator });
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ColumnTypeEnum.@bool:
|
|
||||||
string _Value = "";
|
|
||||||
if ((bool)value)
|
|
||||||
{
|
|
||||||
_Value = "1";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
_Value = "0";
|
|
||||||
}
|
|
||||||
sortInput.Conditions.Add(new ConditionalModel { FieldValue = _Value, FieldName = item.Name, ConditionalType = (ConditionalType)(int)query.QueryOperator });
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
sortInput.Conditions.Add(new ConditionalModel { FieldValue = value.ToString(), FieldName = item.Name, ConditionalType = (ConditionalType)(int)query.QueryOperator });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
entities = await _repository.GetPageListAsync(sortInput.Conditions, sortInput, sortInput.SortBy, sortInput.SortType);
|
|
||||||
}
|
}
|
||||||
|
entityDtos = await MapToGetListOutputDtosAsync(entities);
|
||||||
}
|
//}
|
||||||
else
|
|
||||||
{
|
|
||||||
isPageList = false;
|
|
||||||
entities = await _repository.GetListAsync();
|
|
||||||
}
|
|
||||||
entityDtos = await MapToGetListOutputDtosAsync(entities);
|
|
||||||
//如果是分页查询,还需要统计数量
|
//如果是分页查询,还需要统计数量
|
||||||
if (isPageList)
|
if (isPageList)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -84,6 +84,13 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Yi.RBAC.Application.Identity.DeptService.GetListAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.DeptGetListInputVo)">
|
||||||
|
<summary>
|
||||||
|
多查
|
||||||
|
</summary>
|
||||||
|
<param name="input"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="T:Yi.RBAC.Application.Identity.MenuService">
|
<member name="T:Yi.RBAC.Application.Identity.MenuService">
|
||||||
<summary>
|
<summary>
|
||||||
Menu服务实现
|
Menu服务实现
|
||||||
|
|||||||
@@ -28,24 +28,24 @@ namespace Yi.RBAC.Application.Identity
|
|||||||
return await MapToGetListOutputDtosAsync(entities);
|
return await MapToGetListOutputDtosAsync(entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
///// <summary>
|
/// <summary>
|
||||||
///// 多查
|
/// 多查
|
||||||
///// </summary>
|
/// </summary>
|
||||||
///// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
///// <returns></returns>
|
/// <returns></returns>
|
||||||
//public override async Task<PagedResultDto<DeptGetListOutputDto>> GetListAsync(DeptGetListInputVo input)
|
public override async Task<PagedResultDto<DeptGetListOutputDto>> GetListAsync(DeptGetListInputVo input)
|
||||||
//{
|
{
|
||||||
// RefAsync<int> total = 0;
|
RefAsync<int> total = 0;
|
||||||
// var entities = await _DbQueryable
|
var entities = await _DbQueryable
|
||||||
// .WhereIF(!string.IsNullOrEmpty(input.DeptName), u => u.DeptName.Contains(input.DeptName!))
|
.WhereIF(!string.IsNullOrEmpty(input.DeptName), u => u.DeptName.Contains(input.DeptName!))
|
||||||
// .WhereIF(input.State is not null, u => u.State == input.State)
|
.WhereIF(input.State is not null, u => u.State == input.State)
|
||||||
// .OrderBy(u => u.OrderNum, OrderByType.Asc)
|
.OrderBy(u => u.OrderNum, OrderByType.Asc)
|
||||||
// .ToPageListAsync(input.PageNum, input.PageSize, total);
|
.ToPageListAsync(input.PageNum, input.PageSize, total);
|
||||||
// return new PagedResultDto<DeptGetListOutputDto>
|
return new PagedResultDto<DeptGetListOutputDto>
|
||||||
// {
|
{
|
||||||
// Items = await MapToGetListOutputDtosAsync(entities),
|
Items = await MapToGetListOutputDtosAsync(entities),
|
||||||
// Total = total
|
Total = total
|
||||||
// };
|
};
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,14 @@ namespace Yi.RBAC.Domain.Identity
|
|||||||
return claims;
|
return claims;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新密码
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <param name="newPassword"></param>
|
||||||
|
/// <param name="oldPassword"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="UserFriendlyException"></exception>
|
||||||
public async Task UpdatePasswordAsync(long userId, string newPassword, string oldPassword)
|
public async Task UpdatePasswordAsync(long userId, string newPassword, string oldPassword)
|
||||||
{
|
{
|
||||||
var user = await _repository.GetByIdAsync(userId);
|
var user = await _repository.GetByIdAsync(userId);
|
||||||
@@ -117,7 +125,12 @@ namespace Yi.RBAC.Domain.Identity
|
|||||||
await _repository.UpdateAsync(user);
|
await _repository.UpdateAsync(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 重置密码
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public async Task<bool> RestPasswordAsync(long userId, string password)
|
public async Task<bool> RestPasswordAsync(long userId, string password)
|
||||||
{
|
{
|
||||||
var user = await _repository.GetByIdAsync(userId);
|
var user = await _repository.GetByIdAsync(userId);
|
||||||
|
|||||||
Reference in New Issue
Block a user