wuxw
2022-01-15 e3aed650aa4e232f4583a00fc3de088276a2188b
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
package com.java110.vo;
 
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
 
import java.io.Serializable;
 
/**
 * @ClassName ResultVo
 * @Description TODO
 * @Author wuxw
 * @Date 2020/5/28 18:41
 * @Version 1.0
 * add by wuxw 2020/5/28
 **/
public class ResultVo implements Serializable {
 
    public static final int CODE_ERROR = 404;// 未知异常
 
    public static final int CODE_OK = 0; // 成功
 
    public static final int CODE_MACHINE_OK = 0; // 成功
 
    public static final int CODE_MACHINE_ERROR = -1; // 未知异常
 
    public static final int CODE_UNAUTHORIZED = 401; //认证失败
    public static final int CODE_WECHAT_UNAUTHORIZED = 1401; //认证失败
    public static final int CODE_BUSINESS_VERIFICATION = 5010; //业务校验未通过
 
    public static final int ORDER_ERROR = 500; //订单调度异常
 
 
    public static final String MSG_ERROR = "未知异常";// 未知异常
 
    public static final String MSG_OK = "成功"; // 成功
 
    public static final String MSG_UNAUTHORIZED = "认证失败"; //认证失败
 
    public static final int DEFAULT_RECORD = 1;
    public static final int DEFAULT_TOTAL = 1;
 
    public static final int CODE_WAIT_PAY = 41;// 支付未完成
 
    public static final String EMPTY_ARRAY = "[]";
 
    // 分页页数
    private int page;
    // 行数
    private int rows;
 
    //页数
    private int records;
 
    // 总记录数
    private long total;
 
    //状态
    private int code;
 
    //错误提示
    private String msg;
 
    //数据对象
    private Object data;
 
    //用来存放大计、小计金额
    private Object sumTotal;
 
    //所需数据
    private Object rep;
 
    public ResultVo() {
    }
 
    public ResultVo(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
 
    public ResultVo(Object data) {
        this.code = CODE_OK;
        this.msg = MSG_OK;
        this.data = data;
    }
 
    public ResultVo(int records, int total, Object data) {
        this.code = CODE_OK;
        this.msg = MSG_OK;
        this.records = records;
        this.total = total;
        this.data = data;
    }
 
    public ResultVo(int records, long total, Object data) {
        this.code = CODE_OK;
        this.msg = MSG_OK;
        this.records = records;
        this.total = total;
        this.data = data;
    }
 
    public ResultVo(int records, int total, Object data, Object sumTotal) {
        this.code = CODE_OK;
        this.msg = MSG_OK;
        this.records = records;
        this.total = total;
        this.data = data;
        this.sumTotal = sumTotal;
    }
 
    public ResultVo(int records, int total, Object data, Object sumTotal, Object rep) {
        this.code = CODE_OK;
        this.msg = MSG_OK;
        this.records = records;
        this.total = total;
        this.data = data;
        this.sumTotal = sumTotal;
        this.rep = rep;
    }
 
    public ResultVo(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
 
    public ResultVo(int records, int total, int code, String msg, Object data) {
        this.records = records;
        this.total = total;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
 
    public int getPage() {
        return page;
    }
 
    public void setPage(int page) {
        this.page = page;
    }
 
    public int getRows() {
        return rows;
    }
 
    public void setRows(int rows) {
        this.rows = rows;
    }
 
    public int getRecords() {
        return records;
    }
 
    public void setRecords(int records) {
        this.records = records;
    }
 
    public long getTotal() {
        return total;
    }
 
    public void setTotal(int total) {
        this.total = total;
    }
 
    public int getCode() {
        return code;
    }
 
    public void setCode(int code) {
        this.code = code;
    }
 
    public String getMsg() {
        return msg;
    }
 
    public void setMsg(String msg) {
        this.msg = msg;
    }
 
    public Object getData() {
        return data;
    }
 
    public void setData(Object data) {
        this.data = data;
    }
 
    public Object getSumTotal() {
        return sumTotal;
    }
 
    public void setSumTotal(Object sumTotal) {
        this.sumTotal = sumTotal;
    }
 
    public Object getRep() {
        return rep;
    }
 
    public void setRep(Object rep) {
        this.rep = rep;
    }
 
    @Override
    public String toString() {
        return JSONObject.toJSONString(this, SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteDateUseDateFormat);
    }
 
 
    /**
     * 创建ResponseEntity对象
     *
     * @param data 数据对象
     * @return
     */
    public static ResponseEntity<String> createResponseEntity(Object data) {
        ResultVo resultVo = new ResultVo(DEFAULT_RECORD, DEFAULT_TOTAL, data);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }
 
    /**
     * 创建ResponseEntity对象
     *
     * @param resultVo 数据对象
     * @return
     */
    public static ResponseEntity<String> createResponseEntity(ResultVo resultVo) {
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }
 
    /**
     * 成功通用回复
     *
     * @return
     */
    public static ResponseEntity<String> success() {
        ResultVo resultVo = new ResultVo(CODE_OK, MSG_OK);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }
 
    /**
     * 成功通用回复
     *
     * @return
     */
    public static ResponseEntity<String> error(String msg,HttpStatus status) {
        ResultVo resultVo = new ResultVo(CODE_ERROR, msg);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), status);
        return responseEntity;
    }
 
    /**
     * 成功通用回复
     *
     * @return
     */
    public static ResponseEntity<String> error(String msg) {
        ResultVo resultVo = new ResultVo(CODE_ERROR, msg);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }
 
    /**
     * 成功通用回复
     *
     * @return
     */
    public static ResponseEntity<String> error(String msg,Object data) {
        ResultVo resultVo = new ResultVo(CODE_ERROR, msg,data);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }
 
    /**
     * 创建ResponseEntity对象
     *
     * @param records 页数
     * @param total   总记录数
     * @param data    数据对象
     * @return
     */
    public static ResponseEntity<String> createResponseEntity(int records, int total, Object data) {
        ResultVo resultVo = new ResultVo(records, total, data);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }
 
    /**
     * 创建ResponseEntity对象
     *
     * @param records
     * @param total
     * @param data
     * @param sumTotal
     * @return
     */
    public static ResponseEntity<String> createResponseEntity(int records, int total, Object data, Object sumTotal) {
        ResultVo resultVo = new ResultVo(records, total, data, sumTotal);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }
 
    /**
     * 页面跳转
     *
     * @param url
     * @return
     */
    public static ResponseEntity<String> redirectPage(String url) {
        HttpHeaders headers = new HttpHeaders();
        headers.add(HttpHeaders.LOCATION, url);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>("", headers, HttpStatus.FOUND);
        return responseEntity;
    }
 
    /**
     * 创建ResponseEntity对象
     *
     * @param code 状态嘛
     * @param msg  返回信息
     * @param data 数据对象
     * @return
     */
    public static ResponseEntity<String> createResponseEntity(int code, String msg, Object data) {
        ResultVo resultVo = new ResultVo(code, msg, data);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }
 
    /**
     * 创建ResponseEntity对象
     *
     * @param code 状态嘛
     * @param msg  返回信息
     * @return
     */
    public static ResponseEntity<String> createResponseEntity(int code, String msg) {
        ResultVo resultVo = new ResultVo(code, msg);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }
 
    /**
     * 创建ResponseEntity对象
     *
     * @param records 页数
     * @param total   总记录数
     * @param code    状态嘛
     * @param msg     返回信息
     * @param data    数据对象
     * @return
     */
    public static ResponseEntity<String> createResponseEntity(int records, int total, int code, String msg, Object data) {
        ResultVo resultVo = new ResultVo(records, total, code, msg, data);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }
 
 
}