开始业务模块
This commit is contained in:
@@ -73,7 +73,7 @@ namespace Yi.Framework.Auth.JwtBearer.Authentication
|
||||
AuthenticateResult result = AuthenticateResult.Fail("未发现授权令牌");
|
||||
_context.Request.Headers.TryGetValue("Authorization", out StringValues values);
|
||||
string valStr = values.ToString();
|
||||
if (!string.IsNullOrWhiteSpace(valStr))
|
||||
if (!string.IsNullOrWhiteSpace(valStr) && valStr.Length>10)
|
||||
{
|
||||
var tokenHeader = valStr.Substring(0, 6);
|
||||
if (tokenHeader == "Bearer")
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace Yi.Framework.Autofac.Extensions
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
services.AddAutoMapper(profileList.ToArray());
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,11 @@ namespace Yi.Framework.Core.Sqlsugar.Repositories
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> UpdateIgnoreNullAsync(T updateObj)
|
||||
{
|
||||
return await _Db.Updateable(updateObj).IgnoreColumns(true).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
public override async Task<bool> DeleteAsync(T deleteObj)
|
||||
{
|
||||
//逻辑删除
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Yi.Framework.Core.Exceptions
|
||||
IHasErrorDetails,
|
||||
IHasLogLevel
|
||||
{
|
||||
public ResultCodeEnum Code { get; set; }
|
||||
public int Code { get; set; }
|
||||
|
||||
public string? Details { get; set; }
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Yi.Framework.Core.Exceptions
|
||||
LogLevel logLevel = LogLevel.Warning)
|
||||
: base(message, innerException)
|
||||
{
|
||||
Code = code;
|
||||
Code =(int) code;
|
||||
Details = details;
|
||||
LogLevel = logLevel;
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ namespace Yi.Framework.Core.Exceptions
|
||||
IHasErrorDetails,
|
||||
IHasLogLevel
|
||||
{
|
||||
public ResultCodeEnum Code { get; set; }
|
||||
public int Code { get; set; }
|
||||
|
||||
public string? Details { get; set; }
|
||||
|
||||
public LogLevel LogLevel { get; set; }
|
||||
|
||||
public BusinessException(
|
||||
ResultCodeEnum code = ResultCodeEnum.NotSuccess,
|
||||
int code = (int)ResultCodeEnum.NotSuccess,
|
||||
string? message = null,
|
||||
string? details = null,
|
||||
Exception? innerException = null,
|
||||
|
||||
@@ -35,8 +35,8 @@ public static class ExceptionExtensions
|
||||
/// <param name="exception"></param>
|
||||
/// <param name="defaultLevel"></param>
|
||||
/// <returns></returns>
|
||||
public static ResultCodeEnum GetLogErrorCode(this Exception exception, ResultCodeEnum defaultCode = ResultCodeEnum.NotSuccess)
|
||||
public static int GetLogErrorCode(this Exception exception, ResultCodeEnum defaultCode = ResultCodeEnum.NotSuccess)
|
||||
{
|
||||
return (exception as IHasErrorCode)?.Code ?? defaultCode;
|
||||
return (exception as IHasErrorCode)?.Code ?? (int)defaultCode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ namespace Yi.Framework.Core.Exceptions
|
||||
{
|
||||
internal interface IHasErrorCode
|
||||
{
|
||||
ResultCodeEnum Code { get; }
|
||||
int Code { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,24 @@ using Yi.Framework.Core.Enums;
|
||||
|
||||
namespace Yi.Framework.Core.Exceptions
|
||||
{
|
||||
public class UserFriendlyException: BusinessException
|
||||
public class UserFriendlyException : BusinessException
|
||||
{
|
||||
public UserFriendlyException(
|
||||
string message,
|
||||
int code = (int)ResultCodeEnum.NotSuccess,
|
||||
string? details = null,
|
||||
Exception? innerException = null,
|
||||
LogLevel logLevel = LogLevel.Warning)
|
||||
: base(
|
||||
code,
|
||||
message,
|
||||
details,
|
||||
innerException,
|
||||
logLevel)
|
||||
{
|
||||
Details = details;
|
||||
}
|
||||
|
||||
public UserFriendlyException(
|
||||
string message,
|
||||
ResultCodeEnum code = ResultCodeEnum.NotSuccess,
|
||||
@@ -18,7 +34,7 @@ namespace Yi.Framework.Core.Exceptions
|
||||
Exception? innerException = null,
|
||||
LogLevel logLevel = LogLevel.Warning)
|
||||
: base(
|
||||
code,
|
||||
(int)code,
|
||||
message,
|
||||
details,
|
||||
innerException,
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Yi.Framework.Ddd.Entities
|
||||
[Serializable]
|
||||
public abstract class Entity<TKey> : Entity, IEntity<TKey>, IEntity
|
||||
{
|
||||
public virtual TKey Id { get; protected set; }
|
||||
public virtual TKey Id { get; set; }
|
||||
|
||||
protected Entity()
|
||||
{
|
||||
|
||||
@@ -18,6 +18,6 @@ namespace Yi.Framework.Ddd.Entities
|
||||
//
|
||||
// 摘要:
|
||||
// Unique identifier for this entity.
|
||||
TKey Id { get;}
|
||||
TKey Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace Yi.Framework.Ddd.Repositories
|
||||
Task<bool> UpdateAsync(T updateObj);
|
||||
Task<bool> UpdateRangeAsync(List<T> updateObjs);
|
||||
Task<bool> UpdateAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression);
|
||||
Task<bool> UpdateIgnoreNullAsync(T updateObj);
|
||||
|
||||
//删除
|
||||
Task<bool> DeleteAsync(T deleteObj);
|
||||
|
||||
@@ -82,6 +82,12 @@ namespace Yi.Framework.Ddd.Services
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected virtual Task<TEntity> MapToEntityAsync(TUpdateInput updateInput)
|
||||
{
|
||||
var entity = _mapper.Map<TEntity>(updateInput);
|
||||
return Task.FromResult(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增
|
||||
/// </summary>
|
||||
@@ -125,12 +131,14 @@ namespace Yi.Framework.Ddd.Services
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
var entity = await _repository.GetByIdAsync(id);
|
||||
|
||||
var entity = await MapToEntityAsync(input);
|
||||
entity.Id = id;
|
||||
await _repository.UpdateIgnoreNullAsync(entity);
|
||||
|
||||
await MapToEntityAsync(input, entity);
|
||||
await _repository.UpdateAsync(entity);
|
||||
var newEntity = await _repository.GetByIdAsync(id);
|
||||
|
||||
return await MapToGetOutputDtoAsync(entity);
|
||||
return await MapToGetOutputDtoAsync(newEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ where TEntityDto : IEntityDto<TKey>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public async Task<TGetOutputDto> GetAsync(TKey id)
|
||||
public virtual async Task<TGetOutputDto> GetAsync(TKey id)
|
||||
{
|
||||
if (id is null)
|
||||
{
|
||||
@@ -79,7 +79,7 @@ where TEntityDto : IEntityDto<TKey>
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
|
||||
public virtual async Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
|
||||
{
|
||||
|
||||
var totalCount = await _repository.CountAsync(_ => true);
|
||||
|
||||
Reference in New Issue
Block a user