添加dto模式的demo测试
This commit is contained in:
@@ -192,14 +192,14 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Login(Yi.Framework.DTOModel.LoginDto)">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Login(Yi.Framework.DTOModel.Base.Dto.LoginDto)">
|
||||
<summary>
|
||||
没啥说,登录
|
||||
</summary>
|
||||
<param name="loginDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Register(Yi.Framework.DTOModel.RegisterDto)">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Register(Yi.Framework.DTOModel.Base.Dto.RegisterDto)">
|
||||
<summary>
|
||||
没啥说,注册
|
||||
</summary>
|
||||
@@ -224,7 +224,7 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.UpdatePassword(Yi.Framework.DTOModel.UpdatePasswordDto)">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.UpdatePassword(Yi.Framework.DTOModel.Base.Dto.UpdatePasswordDto)">
|
||||
<summary>
|
||||
自己更新密码
|
||||
</summary>
|
||||
@@ -438,21 +438,21 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.GiveRoleSetMenu(Yi.Framework.DTOModel.GiveRoleSetMenuDto)">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.GiveRoleSetMenu(Yi.Framework.DTOModel.Base.Dto.GiveRoleSetMenuDto)">
|
||||
<summary>
|
||||
给多用户设置多角色
|
||||
</summary>
|
||||
<param name="giveRoleSetMenuDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.Add(Yi.Framework.DTOModel.RoleInfoDto)">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.Add(Yi.Framework.DTOModel.Base.Dto.RoleInfoDto)">
|
||||
<summary>
|
||||
添加角色包含菜单
|
||||
</summary>
|
||||
<param name="roleDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.Update(Yi.Framework.DTOModel.RoleInfoDto)">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.Update(Yi.Framework.DTOModel.Base.Dto.RoleInfoDto)">
|
||||
<summary>
|
||||
更新角色信息
|
||||
</summary>
|
||||
@@ -466,7 +466,7 @@
|
||||
<param name="isDel"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.UpdateDataScpoce(Yi.Framework.DTOModel.RoleInfoDto)">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.RoleController.UpdateDataScpoce(Yi.Framework.DTOModel.Base.Dto.RoleInfoDto)">
|
||||
<summary>
|
||||
更改角色数据权限
|
||||
</summary>
|
||||
@@ -501,7 +501,7 @@
|
||||
<param name="isDel"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.GiveUserSetRole(Yi.Framework.DTOModel.GiveUserSetRoleDto)">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.GiveUserSetRole(Yi.Framework.DTOModel.Base.Dto.GiveUserSetRoleDto)">
|
||||
<summary>
|
||||
给多用户设置多角色
|
||||
</summary>
|
||||
@@ -515,21 +515,21 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.Update(Yi.Framework.DTOModel.UserInfoDto)">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.Update(Yi.Framework.DTOModel.Base.Dto.UserInfoDto)">
|
||||
<summary>
|
||||
更新用户信息
|
||||
</summary>
|
||||
<param name="userDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.UpdateProfile(Yi.Framework.DTOModel.UserInfoDto)">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.UpdateProfile(Yi.Framework.DTOModel.Base.Dto.UserInfoDto)">
|
||||
<summary>
|
||||
更新个人中心信息
|
||||
</summary>
|
||||
<param name="userDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.Add(Yi.Framework.DTOModel.UserInfoDto)">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.Add(Yi.Framework.DTOModel.Base.Dto.UserInfoDto)">
|
||||
<summary>
|
||||
添加用户
|
||||
</summary>
|
||||
@@ -701,5 +701,41 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Brick.IFServer.Controllers.StudentController.Create(Yi.Framework.DTOModel.RABC.Student.StudentCreateInput)">
|
||||
<summary>
|
||||
增
|
||||
</summary>
|
||||
<param name="studentCreateInput"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Brick.IFServer.Controllers.StudentController.GetById(System.Guid)">
|
||||
<summary>
|
||||
查
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Brick.IFServer.Controllers.StudentController.GetLsit">
|
||||
<summary>
|
||||
查
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Brick.IFServer.Controllers.StudentController.Del(System.Collections.Generic.List{System.Guid})">
|
||||
<summary>
|
||||
删
|
||||
</summary>
|
||||
<param name="ids"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Brick.IFServer.Controllers.StudentController.Update(System.Guid,Yi.Framework.DTOModel.RABC.Student.StudentUpdateInput)">
|
||||
<summary>
|
||||
更
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="studentUpdateInput"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -6,8 +6,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Attribute;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel.Vo;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Interface.BBS;
|
||||
using Yi.Framework.Model.BBS.Entitys;
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel.Vo;
|
||||
using Yi.Framework.DTOModel.Base.Vo;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Interface.BBS;
|
||||
using Yi.Framework.Model.BBS.Entitys;
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel.Vo;
|
||||
using Yi.Framework.DTOModel.Base.Vo;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Interface.BBS;
|
||||
using Yi.Framework.Model.BBS.Entitys;
|
||||
|
||||
@@ -12,7 +12,7 @@ using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.Core.Cache;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.DTOModel.Base.Dto;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Interface.RABC;
|
||||
using Yi.Framework.Model.RABC.Entitys;
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.DTOModel.Base.Dto;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Interface.RABC;
|
||||
using Yi.Framework.Model.RABC.Entitys;
|
||||
|
||||
@@ -10,7 +10,7 @@ using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Common.Enum;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.DTOModel.Base.Dto;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Interface.RABC;
|
||||
using Yi.Framework.Model.RABC.Entitys;
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel.RABC.Student;
|
||||
using Yi.Framework.Interface.RABC;
|
||||
|
||||
namespace Brick.IFServer.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class StudentController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly ILogger<StudentController> _logger;
|
||||
private readonly IStudentService _studentService;
|
||||
public StudentController(ILogger<StudentController> logger, IStudentService studentService)
|
||||
{
|
||||
_logger = logger;
|
||||
_studentService = studentService;
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[Route("ErrorTest")]
|
||||
public Result<bool> ErrorTest()
|
||||
{
|
||||
_studentService.GetError();
|
||||
return Result<bool>.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><>
|
||||
/// </summary>
|
||||
/// <param name="studentCreateInput"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result<StudentGetOutput>> Create(StudentCreateInput studentCreateInput)
|
||||
{
|
||||
var result = await _studentService.CreateAsync(studentCreateInput);
|
||||
|
||||
return Result<StudentGetOutput>.Success().SetData(result);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><>
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
public async Task<Result<StudentGetOutput>> GetById(Guid id)
|
||||
{
|
||||
var result = await _studentService.GetByIdAsync(id);
|
||||
return Result<StudentGetOutput>.Success().SetData(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><>
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result<List<StudentListOutput>>> GetLsit()
|
||||
{
|
||||
var result = await _studentService.GetListAsync();
|
||||
|
||||
return Result<List<StudentListOutput>>.Success().SetData(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ɾ
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
public async Task<Result<bool>> Del(List<Guid> ids)
|
||||
{
|
||||
await _studentService.DeleteAsync(ids);
|
||||
return Result<bool>.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><>
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="studentUpdateInput"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[Route("{id}")]
|
||||
public async Task<Result<StudentGetOutput>> Update(Guid id, StudentUpdateInput studentUpdateInput)
|
||||
{
|
||||
var result = await _studentService.UpdateAsync(id, studentUpdateInput);
|
||||
return Result<StudentGetOutput>.Success().SetData(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -4,10 +4,10 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System
|
||||
namespace Yi.Framework.Common.Attribute
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AutowiredAttribute : Attribute
|
||||
public class AutowiredAttribute : System.Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yi.Framework.Common.Enum;
|
||||
|
||||
namespace Yi.Framework.Common.Exceptions;
|
||||
|
||||
[Serializable]
|
||||
public class BusinessException : Exception,
|
||||
IHasErrorCode,
|
||||
IHasErrorDetails,
|
||||
IHasLogLevel
|
||||
{
|
||||
public ResultCodeEnum Code { get; set; }
|
||||
|
||||
public string Details { get; set; }
|
||||
|
||||
public LogLevel LogLevel { get; set; }
|
||||
|
||||
public BusinessException(
|
||||
ResultCodeEnum code = ResultCodeEnum.NotSuccess,
|
||||
string message = null,
|
||||
string details = null,
|
||||
Exception innerException = null,
|
||||
LogLevel logLevel = LogLevel.Warning)
|
||||
: base(message, innerException)
|
||||
{
|
||||
Code = code;
|
||||
Details = details;
|
||||
LogLevel = logLevel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 序列化参数的构造函数
|
||||
/// </summary>
|
||||
public BusinessException(SerializationInfo serializationInfo, StreamingContext context)
|
||||
: base(serializationInfo, context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public BusinessException WithData(string name, object value)
|
||||
{
|
||||
Data[name] = value;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yi.Framework.Common.Enum;
|
||||
|
||||
namespace Yi.Framework.Common.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="Exception"/><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><D5B9><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public static class ExceptionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// ʹ<><CAB9> <see cref="ExceptionDispatchInfo.Capture"/> <20>ٴ<EFBFBD><D9B4>׳<EFBFBD><D7B3>쳣
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception to be re-thrown</param>
|
||||
public static void ReThrow(this Exception exception)
|
||||
{
|
||||
ExceptionDispatchInfo.Capture(exception).Throw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><>ȡ<EFBFBD>쳣<EFBFBD>е<EFBFBD><D0B5><EFBFBD>־<EFBFBD>ȼ<EFBFBD>
|
||||
/// </summary>
|
||||
/// <param name="exception"></param>
|
||||
/// <param name="defaultLevel"></param>
|
||||
/// <returns></returns>
|
||||
public static LogLevel GetLogLevel(this Exception exception, LogLevel defaultLevel = LogLevel.Error)
|
||||
{
|
||||
return (exception as IHasLogLevel)?.LogLevel ?? defaultLevel;
|
||||
}
|
||||
/// <summary>
|
||||
/// <20><>ȡ<EFBFBD>쳣<EFBFBD>е<EFBFBD><D0B5><EFBFBD>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
/// <param name="exception"></param>
|
||||
/// <param name="defaultLevel"></param>
|
||||
/// <returns></returns>
|
||||
public static ResultCodeEnum GetLogErrorCode(this Exception exception, ResultCodeEnum defaultCode = ResultCodeEnum.NotSuccess)
|
||||
{
|
||||
return (exception as IHasErrorCode)?.Code ?? defaultCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Yi.Framework.Common.Enum;
|
||||
|
||||
namespace Yi.Framework.Common.Exceptions;
|
||||
|
||||
public interface IHasErrorCode
|
||||
{
|
||||
ResultCodeEnum Code { get; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Yi.Framework.Common.Exceptions;
|
||||
|
||||
public interface IHasErrorDetails
|
||||
{
|
||||
string Details { get; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Yi.Framework.Common.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><see cref="LogLevel"/> <20><><EFBFBD>ԵĽӿ<C4BD>
|
||||
/// </summary>
|
||||
public interface IHasLogLevel
|
||||
{
|
||||
/// <summary>
|
||||
/// Log severity.
|
||||
/// </summary>
|
||||
LogLevel LogLevel { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yi.Framework.Common.Enum;
|
||||
|
||||
namespace Yi.Framework.Common.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// <20>û<EFBFBD><C3BB>Ѻ<EFBFBD><D1BA>쳣
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class UserFriendlyException : BusinessException
|
||||
{
|
||||
public UserFriendlyException(
|
||||
string message,
|
||||
ResultCodeEnum code = ResultCodeEnum.NotSuccess,
|
||||
string details = null,
|
||||
Exception innerException = null,
|
||||
LogLevel logLevel = LogLevel.Warning)
|
||||
: base(
|
||||
code,
|
||||
message,
|
||||
details,
|
||||
innerException,
|
||||
logLevel)
|
||||
{
|
||||
Details = details;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9>캯<EFBFBD><ECBAAF>
|
||||
/// </summary>
|
||||
public UserFriendlyException(SerializationInfo serializationInfo, StreamingContext context)
|
||||
: base(serializationInfo, context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,66 +7,66 @@ namespace Yi.Framework.Common.Models
|
||||
public class Result
|
||||
{
|
||||
public static IStringLocalizer<LocalLanguage> _local;
|
||||
public ResultCodeEnum code { get; set; }
|
||||
public ResultCodeEnum Code { get; set; }
|
||||
|
||||
public bool status { get; set; }
|
||||
public string message { get; set; }
|
||||
public object data { get; set; }
|
||||
public static Result Expire(ResultCodeEnum code, string msg="")
|
||||
public bool Status { get; set; }
|
||||
public string Message { get; set; }
|
||||
public object Data { get; set; }
|
||||
public static Result Expire(ResultCodeEnum Code, string msg="")
|
||||
{
|
||||
return new Result() { code = code, status=false, message = Get(msg, "token_expiration") };
|
||||
return new Result() { Code = Code, Status=false, Message = Get(msg, "token_expiration") };
|
||||
}
|
||||
public static Result Error(string msg = "")
|
||||
{
|
||||
return new Result() { code = ResultCodeEnum.NotSuccess,status=false, message =Get(msg, "fail") };
|
||||
return new Result() { Code = ResultCodeEnum.NotSuccess, Status = false, Message = Get(msg, "fail") };
|
||||
}
|
||||
public static Result Success(string msg = "")
|
||||
{
|
||||
return new Result() { code = ResultCodeEnum.Success,status=true, message =Get( msg, "succeed" )};
|
||||
return new Result() { Code = ResultCodeEnum.Success, Status = true, Message = Get( msg, "succeed" )};
|
||||
}
|
||||
public static Result SuccessError(string msg = "")
|
||||
{
|
||||
return new Result() { code = ResultCodeEnum.Success, status = false, message = Get(msg, "fail") };
|
||||
return new Result() { Code = ResultCodeEnum.Success, Status = false, Message = Get(msg, "fail") };
|
||||
}
|
||||
|
||||
|
||||
public static Result UnAuthorize(string msg = "")
|
||||
{
|
||||
return new Result() { code = ResultCodeEnum.NoPermission,status=false, message = Get(msg, "unAuthorize") };
|
||||
return new Result() { Code = ResultCodeEnum.NoPermission, Status = false, Message = Get(msg, "unAuthorize") };
|
||||
}
|
||||
public Result SetStatus(bool _status)
|
||||
public Result SetStatus(bool _Status)
|
||||
{
|
||||
if (_status)
|
||||
if (_Status)
|
||||
{
|
||||
this.code = ResultCodeEnum.Success;
|
||||
this.message = "操作成功";
|
||||
this.Code = ResultCodeEnum.Success;
|
||||
this.Message = "操作成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.code = code = ResultCodeEnum.NotSuccess;
|
||||
this.message = "操作失败";
|
||||
this.Code = ResultCodeEnum.NotSuccess;
|
||||
this.Message = "操作失败";
|
||||
}
|
||||
this.status = _status;
|
||||
this.Status = _Status;
|
||||
return this;
|
||||
}
|
||||
public Result SetData(object obj)
|
||||
{
|
||||
this.data = obj;
|
||||
this.Data = obj;
|
||||
return this;
|
||||
}
|
||||
public Result SetCode(ResultCodeEnum Code)
|
||||
{
|
||||
this.code = Code;
|
||||
this.Code = Code;
|
||||
return this;
|
||||
}
|
||||
public Result StatusFalse()
|
||||
{
|
||||
this.status = false;
|
||||
this.Status = false;
|
||||
return this;
|
||||
}
|
||||
public Result StatusTrue()
|
||||
{
|
||||
this.status = true;
|
||||
this.Status = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -81,31 +81,31 @@ namespace Yi.Framework.Common.Models
|
||||
}
|
||||
public class Result<T>
|
||||
{
|
||||
public ResultCodeEnum code { get; set; }
|
||||
public string message { get; set; }
|
||||
public T data { get; set; }
|
||||
public ResultCodeEnum Code { get; set; }
|
||||
public string Message { get; set; }
|
||||
public T Data { get; set; }
|
||||
public static Result<T> Error(string msg = "fail")
|
||||
{
|
||||
return new Result<T>() { code = ResultCodeEnum.NotSuccess, message = msg };
|
||||
return new Result<T>() { Code = ResultCodeEnum.NotSuccess, Message = msg };
|
||||
}
|
||||
public static Result<T> Success(string msg = "succeed")
|
||||
{
|
||||
return new Result<T>() { code = ResultCodeEnum.Success, message = msg };
|
||||
return new Result<T>() { Code = ResultCodeEnum.Success, Message = msg };
|
||||
}
|
||||
public static Result<T> UnAuthorize(string msg = "unAuthorize")
|
||||
{
|
||||
return new Result<T>() { code = ResultCodeEnum.NoPermission, message = msg };
|
||||
return new Result<T>() { Code = ResultCodeEnum.NoPermission, Message = msg };
|
||||
}
|
||||
|
||||
public Result<T> SetData(T TValue)
|
||||
{
|
||||
this.data = TValue;
|
||||
this.Data = TValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Result<T> SetCode(ResultCodeEnum Code)
|
||||
{
|
||||
this.code = Code;
|
||||
this.Code = Code;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
namespace Yi.Framework.DTOModel.Base.Dto
|
||||
{
|
||||
public class GiveRoleSetMenuDto
|
||||
{
|
||||
@@ -4,11 +4,11 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
namespace Yi.Framework.DTOModel.Base.Dto
|
||||
{
|
||||
public class GiveUserSetRoleDto
|
||||
{
|
||||
public List<long> UserIds { get; set; }
|
||||
public List<long> RoleIds { get; set;}
|
||||
public List<long> RoleIds { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
namespace Yi.Framework.DTOModel.Base.Dto
|
||||
{
|
||||
public class LoginDto
|
||||
{
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
namespace Yi.Framework.DTOModel.Base.Dto
|
||||
{
|
||||
public class RegisterDto
|
||||
{
|
||||
@@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.RABC.Entitys;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
namespace Yi.Framework.DTOModel.Base.Dto
|
||||
{
|
||||
public class RoleInfoDto
|
||||
{
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
namespace Yi.Framework.DTOModel.Base.Dto
|
||||
{
|
||||
public class UpdatePasswordDto
|
||||
{
|
||||
@@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.RABC.Entitys;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
namespace Yi.Framework.DTOModel.Base.Dto
|
||||
{
|
||||
public class UserInfoDto
|
||||
{
|
||||
@@ -5,15 +5,15 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.RABC.Entitys;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
namespace Yi.Framework.DTOModel.Base.Dto
|
||||
{
|
||||
public class UserRoleMenuDto
|
||||
{
|
||||
public UserEntity User { get; set; }=new ();
|
||||
public UserEntity User { get; set; } = new();
|
||||
public HashSet<RoleEntity> Roles { get; set; } = new();
|
||||
public HashSet<MenuEntity> Menus { get; set; }=new();
|
||||
public HashSet<MenuEntity> Menus { get; set; } = new();
|
||||
|
||||
public List<string> RoleCodes { get; set; } =new();
|
||||
public List<string> RoleCodes { get; set; } = new();
|
||||
public List<string> PermissionCodes { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel.Vo
|
||||
namespace Yi.Framework.DTOModel.Base.Vo
|
||||
{
|
||||
public class ArticleVo
|
||||
{
|
||||
@@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel.Vo
|
||||
namespace Yi.Framework.DTOModel.Base.Vo
|
||||
{
|
||||
public class CommentVo
|
||||
{
|
||||
@@ -51,11 +51,11 @@ namespace Yi.Framework.DTOModel.Vo
|
||||
/// <summary>
|
||||
/// 被回复的用户信息
|
||||
///</summary>
|
||||
public UserVo? UserInfo { get; set; }
|
||||
public UserVo UserInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建评论的用户信息
|
||||
///</summary>
|
||||
public UserVo? CreateUserInfo { get; set; }
|
||||
public UserVo CreateUserInfo { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel.Vo
|
||||
namespace Yi.Framework.DTOModel.Base.Vo
|
||||
{
|
||||
/// <summary>
|
||||
/// 前端只需要这些数据即可
|
||||
@@ -0,0 +1,22 @@
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.RABC.Entitys;
|
||||
|
||||
namespace Yi.Framework.DTOModel.RABC.Student.MapperConfig
|
||||
{
|
||||
public class StudentProfile : Profile
|
||||
{
|
||||
public StudentProfile()
|
||||
{
|
||||
CreateMap<StudentCreateInput, StudentEntity>();
|
||||
CreateMap<StudentUpdateInput, StudentEntity>();
|
||||
CreateMap<StudentCreateUpdateInput, StudentEntity>();
|
||||
CreateMap<StudentEntity, StudentGetOutput>();
|
||||
CreateMap<StudentEntity, StudentListOutput>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yi.Framework.DTOModel.RABC.Student
|
||||
{
|
||||
public class StudentCreateInput
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Remark { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yi.Framework.DTOModel.RABC.Student
|
||||
{
|
||||
public class StudentCreateUpdateInput
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Remark { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Yi.Framework.Model.Base;
|
||||
|
||||
namespace Yi.Framework.DTOModel.RABC.Student
|
||||
{
|
||||
public class StudentGetOutput : EntityDto<Guid>
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Remark { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Yi.Framework.Model.Base;
|
||||
|
||||
namespace Yi.Framework.DTOModel.RABC.Student
|
||||
{
|
||||
public class StudentListOutput : EntityDto<Guid>
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Remark { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yi.Framework.DTOModel.RABC.Student
|
||||
{
|
||||
public class StudentUpdateInput
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Remark { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,4 +8,9 @@
|
||||
<ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="BBS\" />
|
||||
<Folder Include="Shop\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -7,6 +7,7 @@ using System;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AspNetCoreExtensions;
|
||||
using Yi.Framework.WebCore.BuilderExtend;
|
||||
using Yi.Framework.WebCore.CommonExtend;
|
||||
|
||||
namespace Yi.Framework.ElasticSearchProcessor
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.DTOModel.Base.Dto;
|
||||
using Yi.Framework.Interface.Base;
|
||||
using Yi.Framework.Model.RABC.Entitys;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.DTOModel.RABC.Student;
|
||||
using Yi.Framework.Interface.Base.Crud;
|
||||
|
||||
namespace Yi.Framework.Interface.RABC
|
||||
{
|
||||
public interface IStudentService : ICrudAppService<StudentGetOutput, StudentListOutput, Guid, StudentCreateInput, StudentUpdateInput>
|
||||
{
|
||||
void GetError();
|
||||
Task<List<StudentListOutput>> GetListAsync();
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface.Base;
|
||||
using Yi.Framework.Model.RABC.Entitys;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.DTOModel.Base.Dto;
|
||||
|
||||
namespace Yi.Framework.Interface.RABC
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Yi.Framework.Model.Base
|
||||
/// Returns an array of ordered keys for this entity.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
object[] GetKeys();
|
||||
//object[] GetKeys();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using Yi.Framework.Model.Base;
|
||||
|
||||
namespace Yi.Framework.Model.RABC.Entitys
|
||||
{
|
||||
[SugarTable("Student")]
|
||||
public class StudentEntity : IEntity<Guid>, IMultiTenant
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Remark { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "TenantId")]
|
||||
public Guid? TenantId { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ namespace Yi.Framework.OcelotGateway.WebCore
|
||||
//--------------------------------------管道执行---------------------------------------------
|
||||
GateStartBuilder.Run(dataContext);
|
||||
//--------------------------------------处理结果---------------------------------------------
|
||||
if (dataContext.Result.status)
|
||||
if (dataContext.Result.Status)
|
||||
{
|
||||
//--------------------------------------中间件执行---------------------------------------------
|
||||
await next(context);
|
||||
|
||||
@@ -9,9 +9,9 @@ using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using Yi.Framework.Common.IOCOptions;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.Core.ConsulExtend;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AspNetCoreExtensions;
|
||||
using Yi.Framework.WebCore.CommonExtend;
|
||||
|
||||
namespace Yi.Framework.SMSProcessor
|
||||
{
|
||||
|
||||
@@ -15,7 +15,6 @@ using Yi.Framework.Common.IOCOptions;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Common.QueueModel;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.Core.ConsulExtend;
|
||||
using Yi.Framework.Core.SMS;
|
||||
|
||||
namespace Yi.Framework.SMSProcessor
|
||||
|
||||
@@ -4,13 +4,13 @@ using System.Threading.Tasks;
|
||||
using System;
|
||||
using Yi.Framework.Common.Base;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.RABC.Entitys;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.Service.Base;
|
||||
using Yi.Framework.Uow.Interceptors;
|
||||
using Yi.Framework.Interface.RABC;
|
||||
using Yi.Framework.DTOModel.Base.Dto;
|
||||
|
||||
namespace Yi.Framework.Service.RABC
|
||||
{
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Exceptions;
|
||||
using Yi.Framework.DTOModel.RABC.Student;
|
||||
using Yi.Framework.Interface.RABC;
|
||||
using Yi.Framework.Model.RABC.Entitys;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.Service.Base.Crud;
|
||||
|
||||
namespace Yi.Framework.Service.RABC
|
||||
{
|
||||
public class StudentService : CrudAppService<StudentEntity, StudentGetOutput, StudentListOutput, Guid, StudentCreateInput, StudentUpdateInput>, IStudentService
|
||||
{
|
||||
public StudentService(IRepository<StudentEntity> repository, IMapper mapper) : base(repository, mapper)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<StudentListOutput>> GetListAsync()
|
||||
{
|
||||
return await MapToGetListOutputDtosAsync(await Repository.GetListAsync());
|
||||
}
|
||||
|
||||
public void GetError()
|
||||
{
|
||||
throw new ApplicationException("查询错误");
|
||||
}
|
||||
public void GetError2()
|
||||
{
|
||||
throw new UserFriendlyException("友好错误");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 校验配置项是否已存在
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
//private async Task ValidateKeyAsync(string key, Guid? id = null)
|
||||
//{
|
||||
// Expression<Func<StudentEntity, bool>> expression = e => e.Name == key;
|
||||
// if (id.HasValue)
|
||||
// {
|
||||
// expression = expression.And(e => e.Id != id.Value);
|
||||
// }
|
||||
// var existsData = await Repository.GetListAsync(expression);
|
||||
// if (existsData != null)
|
||||
// {
|
||||
// throw new UserFriendlyException();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,12 @@ using Yi.Framework.Common.Base;
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.RABC.Entitys;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.Service.Base;
|
||||
using Yi.Framework.Interface.RABC;
|
||||
using Yi.Framework.DTOModel.Base.Dto;
|
||||
|
||||
namespace Yi.Framework.Service.RABC
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Yi.Framework.DTOModel.RABC.Student.MapperConfig;
|
||||
using Yi.Framework.WebCore.Mapper;
|
||||
|
||||
namespace Yi.Framework.WebCore.AspNetCoreExtensions
|
||||
@@ -13,7 +14,9 @@ namespace Yi.Framework.WebCore.AspNetCoreExtensions
|
||||
{
|
||||
public static IServiceCollection AddAutoMapperService(this IServiceCollection services)
|
||||
{
|
||||
services.AddAutoMapper(typeof(AutoMapperProfile));
|
||||
//这里会通过反射自动注入的,先临时这样
|
||||
services.AddAutoMapper(typeof(AutoMapperProfile),typeof(StudentProfile));
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
@@ -6,7 +6,7 @@ using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Common.Enum;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Core.Cache;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.DTOModel.Base.Dto;
|
||||
using Yi.Framework.Model.RABC.Entitys;
|
||||
using Yi.Framework.WebCore.CommonExtend;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.DTOModel.Vo;
|
||||
using Yi.Framework.DTOModel.Base.Vo;
|
||||
using Yi.Framework.Model.BBS.Entitys;
|
||||
using Yi.Framework.Model.RABC.Entitys;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using log4net.Core;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
@@ -7,6 +8,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Enum;
|
||||
using Yi.Framework.Common.Exceptions;
|
||||
using Yi.Framework.Common.Models;
|
||||
|
||||
namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
@@ -17,11 +19,12 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
public class ErrorHandExtension
|
||||
{
|
||||
private readonly RequestDelegate next;
|
||||
private ILogger<ErrorHandExtension> _logger;
|
||||
public ErrorHandExtension(RequestDelegate next,ILogger<ErrorHandExtension> logger)
|
||||
//private readonly IErrorHandle _errorHandle;
|
||||
public ErrorHandExtension(RequestDelegate next/*, IErrorHandle errorHandle*/)
|
||||
{
|
||||
this.next = next;
|
||||
_logger = logger;
|
||||
//this._logger = loggerFactory.CreateLogger<ErrorHandExtension>();
|
||||
//_errorHandle = errorHandle;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
@@ -30,14 +33,19 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
{
|
||||
await next(context);
|
||||
}
|
||||
catch (BusinessException businessEx)
|
||||
{
|
||||
var statusCode = 200;
|
||||
await HandleExceptionAsync(context, statusCode, businessEx.Message, businessEx.Code);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//await _errorHandle.Invoer(context, ex);
|
||||
var statusCode = context.Response.StatusCode;
|
||||
if (ex is ArgumentException)
|
||||
{
|
||||
statusCode = 200;
|
||||
}
|
||||
_logger.LogError($"中间件抓取错误\r\n错误信息:{ex.Message}\r\n堆栈信息“{ex.StackTrace}");
|
||||
await HandleExceptionAsync(context, statusCode, ex.Message);
|
||||
}
|
||||
finally
|
||||
@@ -45,9 +53,9 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
var statusCode = context.Response.StatusCode;
|
||||
var msg = "";
|
||||
|
||||
switch (statusCode)
|
||||
switch (statusCode)
|
||||
{
|
||||
case 401: msg = "未授权";break;
|
||||
case 401: msg = "未授权"; break;
|
||||
case 403: msg = "未授权"; break;
|
||||
case 404: msg = "未找到服务"; break;
|
||||
case 502: msg = "请求错误"; break;
|
||||
@@ -59,22 +67,20 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||
}
|
||||
}
|
||||
//异常错误信息捕获,将错误信息用Json方式返回
|
||||
private static Task HandleExceptionAsync(HttpContext context, int statusCode, string msg)
|
||||
private static Task HandleExceptionAsync(HttpContext context, int statusCode, string msg, ResultCodeEnum code = ResultCodeEnum.NotSuccess)
|
||||
{
|
||||
Result resp;
|
||||
Result result;
|
||||
if (statusCode == 401)
|
||||
{
|
||||
resp = Result.UnAuthorize(msg);
|
||||
result = Result.UnAuthorize(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
resp = Result.Error(msg);
|
||||
result = Result.Error(msg).SetCode(code);
|
||||
}
|
||||
resp.SetCode((ResultCodeEnum)statusCode);
|
||||
var result = JsonConvert.SerializeObject(resp);
|
||||
|
||||
context.Response.ContentType = "application/json;charset=utf-8";
|
||||
|
||||
return context.Response.WriteAsync(result);
|
||||
return context.Response.WriteAsync(JsonConvert.SerializeObject(result));
|
||||
}
|
||||
}
|
||||
//扩展方法
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Yi.Framework.Common.Const;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Interface.RABC;
|
||||
|
||||
namespace Yi.Framework.XUnitTest
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Yi.Framework.XUnitTest
|
||||
host.ConfigureAppConfiguration(builder =>
|
||||
{
|
||||
builder.AddJsonFile("appsettings.json");
|
||||
builder.AddJsonFile("appsettings.Development.json");
|
||||
//builder.AddJsonFile("appsettings.Development.json");
|
||||
});
|
||||
host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
||||
host.ConfigureContainer<ContainerBuilder>(containerBuilder =>
|
||||
@@ -51,6 +51,10 @@ namespace Yi.Framework.XUnitTest
|
||||
_iServiceCollection = services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 这里配置服务
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
public void ConfigureTrueServices(IServiceCollection services)
|
||||
{
|
||||
services.AddQuartzService();
|
||||
@@ -58,6 +62,10 @@ namespace Yi.Framework.XUnitTest
|
||||
_iServiceCollection = services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 这里兼容配置管道
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
public void Configure(IServiceProvider services)
|
||||
{
|
||||
var appBuild = WebApplication.CreateBuilder();
|
||||
|
||||
@@ -16,11 +16,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.Development.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
|
||||
Reference in New Issue
Block a user