zhaojs
2023-09-27 74098f1401afe40f961d1d167bb18dd0a71c4d59
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using CommonUtil;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
 
namespace Api.Operater.Controllers
{
    public class BaseController : ControllerBase
    {
 
        #region 统一返回方法
 
        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="rtData"></param>
        /// <returns></returns>
        [NonAction]
        public IActionResult Success<T>(T rtData)
        {
            return Ok(new
            {
                success = true,
                result = rtData
            });
        }
 
 
        /// <summary>
        /// 成功返回分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rtData"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        [NonAction]
        public IActionResult Success<T>(T rtData, int currentPage, int pageSize, int totalCount)
        {
            return Ok(new
            {
                success = true,
                result = new TopPageResultDTO<T>
                {
                    PageNo = currentPage,
                    TotalCount = totalCount,
                    PageSize = pageSize,
                    Data = rtData
                }
            });
        }
 
 
        /// <summary>
        /// 返回错误
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        [NonAction]
        public IActionResult Error(string errMsg)
        {
 
            return Ok(new
            {
                success = false,
                error = new
                {
                    code = "-32006",
                    message = errMsg
                }
            });
        }
 
        #endregion
    }
}