skyouc
2025-02-17 708a39865b7b0d7a0aae3fad98c282aaa8b93b13
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
package com.vincent.rsf.framework.common;
 
import java.util.HashMap;
 
/**
 * Created by vincent on 2019-06-09
 */
public class R extends HashMap<String, Object> {
 
    private static final long serialVersionUID = 1L;
 
    private static final String CODE = "code";
    private static final String MSG = "msg";
    private static final String DATA = "data";
 
    public R(Integer code, String msg){
        super.put(CODE, code);
        super.put(MSG, msg);
    }
 
    public static R ok(){
        return parse(BaseRes.OK);
    }
 
    public static R ok(String msg){
        R r = ok();
        r.put(MSG, msg);
        return r;
    }
 
    public static R ok(Object obj){
        return parse(BaseRes.OK).add(obj);
    }
 
    public static R error(){
        return parse(BaseRes.ERROR);
    }
 
    public static R error(String msg){
        R r = error();
        r.put(MSG, msg);
        return r;
    }
 
    public R add(Object obj){
        this.put(DATA, obj);
        return this;
    }
 
    public static R parse(String message){
        if(Cools.isEmpty(message)){
            return parse(BaseRes.ERROR);
        }
        String[] msg = message.split("-");
        if (msg.length == 2) {
            return new R(Integer.parseInt(msg[0].replaceAll(" ", "")), msg[1]);
        } else {
            return parse("500-".concat(message));
        }
    }
 
}