添加dto模式的demo测试

This commit is contained in:
chenchun
2023-01-01 23:51:05 +08:00
parent b9384afd5d
commit 5d7d115910
55 changed files with 582 additions and 98 deletions

View File

@@ -192,14 +192,14 @@
</summary> </summary>
<returns></returns> <returns></returns>
</member> </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>
没啥说,登录 没啥说,登录
</summary> </summary>
<param name="loginDto"></param> <param name="loginDto"></param>
<returns></returns> <returns></returns>
</member> </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>
没啥说,注册 没啥说,注册
</summary> </summary>
@@ -224,7 +224,7 @@
</summary> </summary>
<returns></returns> <returns></returns>
</member> </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>
自己更新密码 自己更新密码
</summary> </summary>
@@ -438,21 +438,21 @@
</summary> </summary>
<returns></returns> <returns></returns>
</member> </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>
给多用户设置多角色 给多用户设置多角色
</summary> </summary>
<param name="giveRoleSetMenuDto"></param> <param name="giveRoleSetMenuDto"></param>
<returns></returns> <returns></returns>
</member> </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>
添加角色包含菜单 添加角色包含菜单
</summary> </summary>
<param name="roleDto"></param> <param name="roleDto"></param>
<returns></returns> <returns></returns>
</member> </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>
更新角色信息 更新角色信息
</summary> </summary>
@@ -466,7 +466,7 @@
<param name="isDel"></param> <param name="isDel"></param>
<returns></returns> <returns></returns>
</member> </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>
更改角色数据权限 更改角色数据权限
</summary> </summary>
@@ -501,7 +501,7 @@
<param name="isDel"></param> <param name="isDel"></param>
<returns></returns> <returns></returns>
</member> </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>
给多用户设置多角色 给多用户设置多角色
</summary> </summary>
@@ -515,21 +515,21 @@
<param name="id"></param> <param name="id"></param>
<returns></returns> <returns></returns>
</member> </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>
更新用户信息 更新用户信息
</summary> </summary>
<param name="userDto"></param> <param name="userDto"></param>
<returns></returns> <returns></returns>
</member> </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>
更新个人中心信息 更新个人中心信息
</summary> </summary>
<param name="userDto"></param> <param name="userDto"></param>
<returns></returns> <returns></returns>
</member> </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>
添加用户 添加用户
</summary> </summary>
@@ -701,5 +701,41 @@
</summary> </summary>
<returns></returns> <returns></returns>
</member> </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> </members>
</doc> </doc>

View File

@@ -6,8 +6,8 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Common.Attribute;
using Yi.Framework.Common.Models; using Yi.Framework.Common.Models;
using Yi.Framework.DTOModel.Vo;
using Yi.Framework.Interface; using Yi.Framework.Interface;
using Yi.Framework.Interface.BBS; using Yi.Framework.Interface.BBS;
using Yi.Framework.Model.BBS.Entitys; using Yi.Framework.Model.BBS.Entitys;

View File

@@ -7,7 +7,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Common.Models; using Yi.Framework.Common.Models;
using Yi.Framework.DTOModel.Vo; using Yi.Framework.DTOModel.Base.Vo;
using Yi.Framework.Interface; using Yi.Framework.Interface;
using Yi.Framework.Interface.BBS; using Yi.Framework.Interface.BBS;
using Yi.Framework.Model.BBS.Entitys; using Yi.Framework.Model.BBS.Entitys;

View File

@@ -7,7 +7,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Common.Models; using Yi.Framework.Common.Models;
using Yi.Framework.DTOModel.Vo; using Yi.Framework.DTOModel.Base.Vo;
using Yi.Framework.Interface; using Yi.Framework.Interface;
using Yi.Framework.Interface.BBS; using Yi.Framework.Interface.BBS;
using Yi.Framework.Model.BBS.Entitys; using Yi.Framework.Model.BBS.Entitys;

View File

@@ -12,7 +12,7 @@ using Yi.Framework.Common.Helper;
using Yi.Framework.Common.Models; using Yi.Framework.Common.Models;
using Yi.Framework.Core; using Yi.Framework.Core;
using Yi.Framework.Core.Cache; using Yi.Framework.Core.Cache;
using Yi.Framework.DTOModel; using Yi.Framework.DTOModel.Base.Dto;
using Yi.Framework.Interface; using Yi.Framework.Interface;
using Yi.Framework.Interface.RABC; using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys; using Yi.Framework.Model.RABC.Entitys;

View File

@@ -6,7 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Common.Models; using Yi.Framework.Common.Models;
using Yi.Framework.DTOModel; using Yi.Framework.DTOModel.Base.Dto;
using Yi.Framework.Interface; using Yi.Framework.Interface;
using Yi.Framework.Interface.RABC; using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys; using Yi.Framework.Model.RABC.Entitys;

View File

@@ -10,7 +10,7 @@ using Yi.Framework.Common.Const;
using Yi.Framework.Common.Enum; using Yi.Framework.Common.Enum;
using Yi.Framework.Common.Helper; using Yi.Framework.Common.Helper;
using Yi.Framework.Common.Models; using Yi.Framework.Common.Models;
using Yi.Framework.DTOModel; using Yi.Framework.DTOModel.Base.Dto;
using Yi.Framework.Interface; using Yi.Framework.Interface;
using Yi.Framework.Interface.RABC; using Yi.Framework.Interface.RABC;
using Yi.Framework.Model.RABC.Entitys; using Yi.Framework.Model.RABC.Entitys;

View File

@@ -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);
}
}
}

View File

@@ -4,10 +4,10 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace System namespace Yi.Framework.Common.Attribute
{ {
[AttributeUsage(AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Property)]
public class AutowiredAttribute : Attribute public class AutowiredAttribute : System.Attribute
{ {
} }
} }

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,8 @@
using Yi.Framework.Common.Enum;
namespace Yi.Framework.Common.Exceptions;
public interface IHasErrorCode
{
ResultCodeEnum Code { get; }
}

View File

@@ -0,0 +1,6 @@
namespace Yi.Framework.Common.Exceptions;
public interface IHasErrorDetails
{
string Details { get; }
}

View File

@@ -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; }
}

View File

@@ -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)
{
}
}

View File

@@ -7,66 +7,66 @@ namespace Yi.Framework.Common.Models
public class Result public class Result
{ {
public static IStringLocalizer<LocalLanguage> _local; public static IStringLocalizer<LocalLanguage> _local;
public ResultCodeEnum code { get; set; } public ResultCodeEnum Code { get; set; }
public bool status { get; set; } public bool Status { get; set; }
public string message { get; set; } public string Message { get; set; }
public object data { get; set; } public object Data { get; set; }
public static Result Expire(ResultCodeEnum code, string msg="") 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 = "") 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 = "") 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 = "") 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 = "") 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.Code = ResultCodeEnum.Success;
this.message = "操作成功"; this.Message = "操作成功";
} }
else else
{ {
this.code = code = ResultCodeEnum.NotSuccess; this.Code = ResultCodeEnum.NotSuccess;
this.message = "操作失败"; this.Message = "操作失败";
} }
this.status = _status; this.Status = _Status;
return this; return this;
} }
public Result SetData(object obj) public Result SetData(object obj)
{ {
this.data = obj; this.Data = obj;
return this; return this;
} }
public Result SetCode(ResultCodeEnum Code) public Result SetCode(ResultCodeEnum Code)
{ {
this.code = Code; this.Code = Code;
return this; return this;
} }
public Result StatusFalse() public Result StatusFalse()
{ {
this.status = false; this.Status = false;
return this; return this;
} }
public Result StatusTrue() public Result StatusTrue()
{ {
this.status = true; this.Status = true;
return this; return this;
} }
@@ -81,31 +81,31 @@ namespace Yi.Framework.Common.Models
} }
public class Result<T> public class Result<T>
{ {
public ResultCodeEnum code { get; set; } public ResultCodeEnum Code { get; set; }
public string message { get; set; } public string Message { get; set; }
public T data { get; set; } public T Data { get; set; }
public static Result<T> Error(string msg = "fail") 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") 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") 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) public Result<T> SetData(T TValue)
{ {
this.data = TValue; this.Data = TValue;
return this; return this;
} }
public Result<T> SetCode(ResultCodeEnum Code) public Result<T> SetCode(ResultCodeEnum Code)
{ {
this.code = Code; this.Code = Code;
return this; return this;
} }
} }

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Yi.Framework.DTOModel namespace Yi.Framework.DTOModel.Base.Dto
{ {
public class GiveRoleSetMenuDto public class GiveRoleSetMenuDto
{ {

View File

@@ -4,11 +4,11 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Yi.Framework.DTOModel namespace Yi.Framework.DTOModel.Base.Dto
{ {
public class GiveUserSetRoleDto public class GiveUserSetRoleDto
{ {
public List<long> UserIds { get; set; } public List<long> UserIds { get; set; }
public List<long> RoleIds { get; set;} public List<long> RoleIds { get; set; }
} }
} }

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Yi.Framework.DTOModel namespace Yi.Framework.DTOModel.Base.Dto
{ {
public class LoginDto public class LoginDto
{ {

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Yi.Framework.DTOModel namespace Yi.Framework.DTOModel.Base.Dto
{ {
public class RegisterDto public class RegisterDto
{ {

View File

@@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Model.RABC.Entitys; using Yi.Framework.Model.RABC.Entitys;
namespace Yi.Framework.DTOModel namespace Yi.Framework.DTOModel.Base.Dto
{ {
public class RoleInfoDto public class RoleInfoDto
{ {

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Yi.Framework.DTOModel namespace Yi.Framework.DTOModel.Base.Dto
{ {
public class UpdatePasswordDto public class UpdatePasswordDto
{ {

View File

@@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Model.RABC.Entitys; using Yi.Framework.Model.RABC.Entitys;
namespace Yi.Framework.DTOModel namespace Yi.Framework.DTOModel.Base.Dto
{ {
public class UserInfoDto public class UserInfoDto
{ {

View File

@@ -5,15 +5,15 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Model.RABC.Entitys; using Yi.Framework.Model.RABC.Entitys;
namespace Yi.Framework.DTOModel namespace Yi.Framework.DTOModel.Base.Dto
{ {
public class UserRoleMenuDto public class UserRoleMenuDto
{ {
public UserEntity User { get; set; }=new (); public UserEntity User { get; set; } = new();
public HashSet<RoleEntity> Roles { 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(); public List<string> PermissionCodes { get; set; } = new();
} }
} }

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Yi.Framework.DTOModel.Vo namespace Yi.Framework.DTOModel.Base.Vo
{ {
public class ArticleVo public class ArticleVo
{ {

View File

@@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Yi.Framework.DTOModel.Vo namespace Yi.Framework.DTOModel.Base.Vo
{ {
public class CommentVo public class CommentVo
{ {
@@ -51,11 +51,11 @@ namespace Yi.Framework.DTOModel.Vo
/// <summary> /// <summary>
/// 被回复的用户信息 /// 被回复的用户信息
///</summary> ///</summary>
public UserVo? UserInfo { get; set; } public UserVo UserInfo { get; set; }
/// <summary> /// <summary>
/// 创建评论的用户信息 /// 创建评论的用户信息
///</summary> ///</summary>
public UserVo? CreateUserInfo { get; set; } public UserVo CreateUserInfo { get; set; }
} }
} }

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Yi.Framework.DTOModel.Vo namespace Yi.Framework.DTOModel.Base.Vo
{ {
/// <summary> /// <summary>
/// 前端只需要这些数据即可 /// 前端只需要这些数据即可

View File

@@ -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>();
}
}
}

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -8,4 +8,9 @@
<ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" /> <ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="BBS\" />
<Folder Include="Shop\" />
</ItemGroup>
</Project> </Project>

View File

@@ -7,6 +7,7 @@ using System;
using Yi.Framework.WebCore; using Yi.Framework.WebCore;
using Yi.Framework.WebCore.AspNetCoreExtensions; using Yi.Framework.WebCore.AspNetCoreExtensions;
using Yi.Framework.WebCore.BuilderExtend; using Yi.Framework.WebCore.BuilderExtend;
using Yi.Framework.WebCore.CommonExtend;
namespace Yi.Framework.ElasticSearchProcessor namespace Yi.Framework.ElasticSearchProcessor
{ {

View File

@@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Common.Models; using Yi.Framework.Common.Models;
using Yi.Framework.DTOModel; using Yi.Framework.DTOModel.Base.Dto;
using Yi.Framework.Interface.Base; using Yi.Framework.Interface.Base;
using Yi.Framework.Model.RABC.Entitys; using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository; using Yi.Framework.Repository;

View File

@@ -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();
}
}

View File

@@ -2,10 +2,10 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using System; using System;
using Yi.Framework.Common.Models; using Yi.Framework.Common.Models;
using Yi.Framework.DTOModel;
using Yi.Framework.Interface.Base; using Yi.Framework.Interface.Base;
using Yi.Framework.Model.RABC.Entitys; using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository; using Yi.Framework.Repository;
using Yi.Framework.DTOModel.Base.Dto;
namespace Yi.Framework.Interface.RABC namespace Yi.Framework.Interface.RABC
{ {

View File

@@ -16,7 +16,7 @@ namespace Yi.Framework.Model.Base
/// Returns an array of ordered keys for this entity. /// Returns an array of ordered keys for this entity.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
object[] GetKeys(); //object[] GetKeys();
} }
/// <summary> /// <summary>

View File

@@ -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; }
}
}

View File

@@ -41,7 +41,7 @@ namespace Yi.Framework.OcelotGateway.WebCore
//--------------------------------------管道执行--------------------------------------------- //--------------------------------------管道执行---------------------------------------------
GateStartBuilder.Run(dataContext); GateStartBuilder.Run(dataContext);
//--------------------------------------处理结果--------------------------------------------- //--------------------------------------处理结果---------------------------------------------
if (dataContext.Result.status) if (dataContext.Result.Status)
{ {
//--------------------------------------中间件执行--------------------------------------------- //--------------------------------------中间件执行---------------------------------------------
await next(context); await next(context);

View File

@@ -9,9 +9,9 @@ using Microsoft.Extensions.Logging;
using System; using System;
using Yi.Framework.Common.IOCOptions; using Yi.Framework.Common.IOCOptions;
using Yi.Framework.Core; using Yi.Framework.Core;
using Yi.Framework.Core.ConsulExtend;
using Yi.Framework.WebCore; using Yi.Framework.WebCore;
using Yi.Framework.WebCore.AspNetCoreExtensions; using Yi.Framework.WebCore.AspNetCoreExtensions;
using Yi.Framework.WebCore.CommonExtend;
namespace Yi.Framework.SMSProcessor namespace Yi.Framework.SMSProcessor
{ {

View File

@@ -15,7 +15,6 @@ using Yi.Framework.Common.IOCOptions;
using Yi.Framework.Common.Models; using Yi.Framework.Common.Models;
using Yi.Framework.Common.QueueModel; using Yi.Framework.Common.QueueModel;
using Yi.Framework.Core; using Yi.Framework.Core;
using Yi.Framework.Core.ConsulExtend;
using Yi.Framework.Core.SMS; using Yi.Framework.Core.SMS;
namespace Yi.Framework.SMSProcessor namespace Yi.Framework.SMSProcessor

View File

@@ -4,13 +4,13 @@ using System.Threading.Tasks;
using System; using System;
using Yi.Framework.Common.Base; using Yi.Framework.Common.Base;
using Yi.Framework.Common.Models; using Yi.Framework.Common.Models;
using Yi.Framework.DTOModel;
using Yi.Framework.Interface; using Yi.Framework.Interface;
using Yi.Framework.Model.RABC.Entitys; using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository; using Yi.Framework.Repository;
using Yi.Framework.Service.Base; using Yi.Framework.Service.Base;
using Yi.Framework.Uow.Interceptors; using Yi.Framework.Uow.Interceptors;
using Yi.Framework.Interface.RABC; using Yi.Framework.Interface.RABC;
using Yi.Framework.DTOModel.Base.Dto;
namespace Yi.Framework.Service.RABC namespace Yi.Framework.Service.RABC
{ {

View File

@@ -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();
// }
//}
}
}

View File

@@ -7,12 +7,12 @@ using Yi.Framework.Common.Base;
using Yi.Framework.Common.Const; using Yi.Framework.Common.Const;
using Yi.Framework.Common.Helper; using Yi.Framework.Common.Helper;
using Yi.Framework.Common.Models; using Yi.Framework.Common.Models;
using Yi.Framework.DTOModel;
using Yi.Framework.Interface; using Yi.Framework.Interface;
using Yi.Framework.Model.RABC.Entitys; using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.Repository; using Yi.Framework.Repository;
using Yi.Framework.Service.Base; using Yi.Framework.Service.Base;
using Yi.Framework.Interface.RABC; using Yi.Framework.Interface.RABC;
using Yi.Framework.DTOModel.Base.Dto;
namespace Yi.Framework.Service.RABC namespace Yi.Framework.Service.RABC
{ {

View File

@@ -2,6 +2,7 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.IO; using System.IO;
using Yi.Framework.DTOModel.RABC.Student.MapperConfig;
using Yi.Framework.WebCore.Mapper; using Yi.Framework.WebCore.Mapper;
namespace Yi.Framework.WebCore.AspNetCoreExtensions namespace Yi.Framework.WebCore.AspNetCoreExtensions
@@ -13,7 +14,9 @@ namespace Yi.Framework.WebCore.AspNetCoreExtensions
{ {
public static IServiceCollection AddAutoMapperService(this IServiceCollection services) public static IServiceCollection AddAutoMapperService(this IServiceCollection services)
{ {
services.AddAutoMapper(typeof(AutoMapperProfile)); //这里会通过反射自动注入的,先临时这样
services.AddAutoMapper(typeof(AutoMapperProfile),typeof(StudentProfile));
return services; return services;
} }
} }

View File

@@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;

View File

@@ -6,7 +6,7 @@ using Yi.Framework.Common.Const;
using Yi.Framework.Common.Enum; using Yi.Framework.Common.Enum;
using Yi.Framework.Common.Models; using Yi.Framework.Common.Models;
using Yi.Framework.Core.Cache; using Yi.Framework.Core.Cache;
using Yi.Framework.DTOModel; using Yi.Framework.DTOModel.Base.Dto;
using Yi.Framework.Model.RABC.Entitys; using Yi.Framework.Model.RABC.Entitys;
using Yi.Framework.WebCore.CommonExtend; using Yi.Framework.WebCore.CommonExtend;

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; 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.BBS.Entitys;
using Yi.Framework.Model.RABC.Entitys; using Yi.Framework.Model.RABC.Entitys;

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Builder; using log4net.Core;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
@@ -7,6 +8,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Common.Enum; using Yi.Framework.Common.Enum;
using Yi.Framework.Common.Exceptions;
using Yi.Framework.Common.Models; using Yi.Framework.Common.Models;
namespace Yi.Framework.WebCore.MiddlewareExtend namespace Yi.Framework.WebCore.MiddlewareExtend
@@ -17,11 +19,12 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
public class ErrorHandExtension public class ErrorHandExtension
{ {
private readonly RequestDelegate next; private readonly RequestDelegate next;
private ILogger<ErrorHandExtension> _logger; //private readonly IErrorHandle _errorHandle;
public ErrorHandExtension(RequestDelegate next,ILogger<ErrorHandExtension> logger) public ErrorHandExtension(RequestDelegate next/*, IErrorHandle errorHandle*/)
{ {
this.next = next; this.next = next;
_logger = logger; //this._logger = loggerFactory.CreateLogger<ErrorHandExtension>();
//_errorHandle = errorHandle;
} }
public async Task Invoke(HttpContext context) public async Task Invoke(HttpContext context)
@@ -30,14 +33,19 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
{ {
await next(context); await next(context);
} }
catch (BusinessException businessEx)
{
var statusCode = 200;
await HandleExceptionAsync(context, statusCode, businessEx.Message, businessEx.Code);
}
catch (Exception ex) catch (Exception ex)
{ {
//await _errorHandle.Invoer(context, ex);
var statusCode = context.Response.StatusCode; var statusCode = context.Response.StatusCode;
if (ex is ArgumentException) if (ex is ArgumentException)
{ {
statusCode = 200; statusCode = 200;
} }
_logger.LogError($"中间件抓取错误\r\n错误信息{ex.Message}\r\n堆栈信息“{ex.StackTrace}");
await HandleExceptionAsync(context, statusCode, ex.Message); await HandleExceptionAsync(context, statusCode, ex.Message);
} }
finally finally
@@ -45,9 +53,9 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
var statusCode = context.Response.StatusCode; var statusCode = context.Response.StatusCode;
var msg = ""; var msg = "";
switch (statusCode) switch (statusCode)
{ {
case 401: msg = "未授权";break; case 401: msg = "未授权"; break;
case 403: msg = "未授权"; break; case 403: msg = "未授权"; break;
case 404: msg = "未找到服务"; break; case 404: msg = "未找到服务"; break;
case 502: msg = "请求错误"; break; case 502: msg = "请求错误"; break;
@@ -59,22 +67,20 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
} }
} }
//异常错误信息捕获将错误信息用Json方式返回 //异常错误信息捕获将错误信息用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) if (statusCode == 401)
{ {
resp = Result.UnAuthorize(msg); result = Result.UnAuthorize(msg);
} }
else 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"; context.Response.ContentType = "application/json;charset=utf-8";
return context.Response.WriteAsync(JsonConvert.SerializeObject(result));
return context.Response.WriteAsync(result);
} }
} }
//扩展方法 //扩展方法

View File

@@ -1,6 +1,7 @@
using Yi.Framework.Common.Const; using Yi.Framework.Common.Const;
using Yi.Framework.Core; using Yi.Framework.Core;
using Yi.Framework.Interface; using Yi.Framework.Interface;
using Yi.Framework.Interface.RABC;
namespace Yi.Framework.XUnitTest namespace Yi.Framework.XUnitTest
{ {

View File

@@ -22,7 +22,7 @@ namespace Yi.Framework.XUnitTest
host.ConfigureAppConfiguration(builder => host.ConfigureAppConfiguration(builder =>
{ {
builder.AddJsonFile("appsettings.json"); builder.AddJsonFile("appsettings.json");
builder.AddJsonFile("appsettings.Development.json"); //builder.AddJsonFile("appsettings.Development.json");
}); });
host.UseServiceProviderFactory(new AutofacServiceProviderFactory()); host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
host.ConfigureContainer<ContainerBuilder>(containerBuilder => host.ConfigureContainer<ContainerBuilder>(containerBuilder =>
@@ -51,6 +51,10 @@ namespace Yi.Framework.XUnitTest
_iServiceCollection = services; _iServiceCollection = services;
} }
/// <summary>
/// 这里配置服务
/// </summary>
/// <param name="services"></param>
public void ConfigureTrueServices(IServiceCollection services) public void ConfigureTrueServices(IServiceCollection services)
{ {
services.AddQuartzService(); services.AddQuartzService();
@@ -58,6 +62,10 @@ namespace Yi.Framework.XUnitTest
_iServiceCollection = services; _iServiceCollection = services;
} }
/// <summary>
/// 这里兼容配置管道
/// </summary>
/// <param name="services"></param>
public void Configure(IServiceProvider services) public void Configure(IServiceProvider services)
{ {
var appBuild = WebApplication.CreateBuilder(); var appBuild = WebApplication.CreateBuilder();

View File

@@ -16,11 +16,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="appsettings.json"> <Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile> <ExcludeFromSingleFile>true</ExcludeFromSingleFile>