123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using System.Security.Claims;
- namespace OASystem.API.Controllers;
- /// <summary>
- /// 控制器基类
- /// </summary>
- //[Authorize]
- [ApiController]
- public class ControllerBase : Microsoft.AspNetCore.Mvc.ControllerBase
- {
- protected virtual string? CurrentUserId => HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
- protected virtual void Logs(string str)
- {
- Log.Error(str);
- }
- protected virtual JsonView JsonView(object obj)
- {
- return new JsonView { Code = StatusCodes.Status200OK, Msg = "操作成功", Data = obj };
- }
- protected virtual JsonView JsonView(object obj, int count)
- {
- return new JsonView { Code = StatusCodes.Status200OK, Msg = "操作成功", Data = obj, Count = count };
- }
- protected virtual JsonView JsonView(string msg)
- {
- return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = msg };
- }
- protected virtual JsonView JsonView(bool s)
- {
- if (s)
- {
- return new JsonView { Code = StatusCodes.Status200OK, Msg = "操作成功" };
- }
- else
- {
- return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = "操作失败" };
- }
- }
- protected virtual JsonView JsonView(bool s, string msg)
- {
- if (s)
- {
- return new JsonView { Code = StatusCodes.Status200OK, Msg = msg };
- }
- else
- {
- return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = msg };
- }
- }
- protected virtual JsonView JsonView(bool s, string msg, object obj)
- {
- if (s)
- {
- return new JsonView { Code = StatusCodes.Status200OK, Msg = msg, Data = obj };
- }
- else
- {
- return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = msg };
- }
- }
- protected virtual JsonView JsonView(bool s, string msg, object obj, int count)
- {
- if (s)
- {
- return new JsonView { Code = StatusCodes.Status200OK, Msg = msg, Data = obj, Count = count };
- }
- else
- {
- return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = msg };
- }
- }
- protected virtual JsonView JsonView(int code, string msg, object obj)
- {
- return new JsonView { Code = code, Msg = msg, Data = obj };
- }
- }
|