Response.cs
4.54 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
namespace Hh.Mes.POJO.Response
{
public class Response
{
/// <summary>
/// 默认返回操作成功
/// </summary>
public Response(bool status = true, string msg = "业务数据操作成功!")
{
Code = status ? (int)RetCode.SUCCESS : (int)RetCode.INTERNAL_SERVER_ERROR;
Status = status;
Message = msg;
}
public int Code { get; set; }
public string Message { get; set; }
public bool Status { get; set; }
public int Count { get; set; }
/// <summary>
/// 登陆标识
/// </summary>
public string Token { get; set; }
public dynamic Result { get; set; }
/// <summary>
/// 统一返回前端失败
/// </summary>
/// <param name="msg">失败消息</param>
public virtual void ResponseErr(string msg)
{
Code = (int)RetCode.FAIL;
Message = msg;
Status = false;
}
/// <summary>
/// 统一返回前端失败
/// </summary>
/// <param name="msg">失败消息</param>
public virtual Response ResponseError(string msg = "业务数据操作失败")
{
Code = (int)RetCode.INTERNAL_SERVER_ERROR;
Message = msg;
Status = false;
return this;
}
/// <summary>
/// 统一返回前端成功
/// </summary>
public virtual Response ResponseSuccess(string msg = "业务数据操作成功!")
{
Code = (int)RetCode.SUCCESS;
Message = msg;
Status = true;
return this;
}
}
public class Response<T> : Response
{
/// <summary>
/// 回传的结果
/// </summary>
public new T Result { get; set; }
public Response(bool status, string msg) : base(status, msg)
{
}
public Response()
{
}
}
public class ResponseUpstream<T> : Response<T>
{
public string plmeid { get; set; }
//public string flag { get { return Code == (int)RetCode.SUCCESS ? "1" : "0"; } }
//public string msg { get { return Message; } }
public ResponseUpstream(string plmeid, bool status = true, string msg = "业务数据操作成功!") : base(status, msg)
{
this.plmeid = plmeid;
}
}
/// <summary>
/// wms
/// </summary>
public class ResponseWms
{
// <summary>
/// 默认返回操作成功
///</summary>
public ResponseWms(bool status = true, string msg = "业务数据操作成功")
{
code = status ? 200 : 500;
this.status = status;
this.msg = msg;
}
public int code { get; set; }
public string msg { get; set; }
public bool status { get; set; }
public dynamic result { get; set; }
/// <summary>
/// 登陆标识
/// </summary>
public string token { get; set; }
/// <summary>
/// 统一返回失败
/// </summary>
public virtual ResponseWms ResponseError(string msg = "业务数据操作失败", int code = 500)
{
this.code = code;
this.msg = msg;
this.status = false;
result = "[]";
return this;
}
/// <summary>
/// 统一返回成功
/// </summary>
public virtual ResponseWms ResponseSuccess(string msg = "业务数据操作成功!")
{
code = 200;
this.msg = msg;
status = true;
return this;
}
}
public enum RetCode
{
OK = 0,
/// <summary>
/// 成功
/// </summary>
SUCCESS = 200,
/// <summary>
/// 失败
/// </summary>
FAIL = 400,
/// <summary>
/// 未认证(签名错误)
/// </summary>
UNAUTHORIZED = 401,
/// <summary>
/// 找不到请求文件
/// </summary>
NoHandlerFoundException = 404,
/// <summary>
/// 未登录
/// </summary>
UNAUTHEN = 401,
/// <summary>
/// 未授权,拒绝访问
/// </summary>
UNAUTHZ = 403,
/// <summary>
/// 服务器内部错误
/// </summary>
INTERNAL_SERVER_ERROR = 500,
/// <summary>
/// 业务处理错误
/// </summary>
Business_ERROR = 600,
}
}