ResponseNew.cs
1.57 KB
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
using System;
using System.Collections.Generic;
using System.Text;
namespace Hh.Mes.POJO.Response
{
/// <summary>
/// 兼容PDA、和web 错误统一返回500,无数据也返回500
/// 401 Token失效
/// 200 成功,有数据,业务正常
/// </summary>
public class ResponseNew
{
// <summary>
/// 默认返回操作成功
///</summary>
public ResponseNew(bool statusx = true, string msg = "成功")
{
code = statusx ? 200 : 500;
status = statusx;
message = msg;
}
public int code { get; set; }
public string message { get; set; }
public bool status { get; set; }
public long count { get; set; }
/// <summary>
/// 登陆标识
/// </summary>
public string token { get; set; }
public dynamic data { get; set; }
/// <summary>
/// 统一返回前端失败
/// </summary>
/// <param name="msg">失败消息</param>
public virtual ResponseNew ResponseError(string msg = "业务数据操作失败",int codes=500)
{
code = codes;
message = msg;
status = false;
data = "[]";
return this;
}
/// <summary>
/// 统一返回前端成功
/// </summary>
public virtual ResponseNew ResponseSuccess(string msg = "业务数据操作成功!")
{
code = 200;
message = msg;
status = true;
return this;
}
}
}