shichongfu
2023-04-25 ce0b49552668d3331055e2b1a1447a743dc54939
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.product.admin.util;
 
import com.alibaba.fastjson.JSON;
import com.product.admin.config.SystemCode;
 
 
import java.util.HashMap;
import java.util.Map;
 
public class ResultInfo {
 
    /**
     * 返回成功
     *
     * @param data 返回数据
     * @throws
     */
    public static String success(Object data) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("code", SystemCode.SYSTEM_OPERATION_SUCCESS.getValue());
        resultMap.put("msg", SystemCode.SYSTEM_OPERATION_SUCCESS.getText());
        resultMap.put("status", "success");
        resultMap.put("data", data);
        if (data == null) {
            resultMap.put("data", new String[]{});
        }
        return JSON.toJSONString(resultMap);
    }
    
    /**
     * websocket心跳检测成功
     *
     * @param data 返回数据
     * @throws
     */
    public static String success() {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("code", 201);
        resultMap.put("msg", SystemCode.SYSTEM_OPERATION_SUCCESS.getText());
        resultMap.put("status", "fail");
        return JSON.toJSONString(resultMap);
    }
    
    /**
     * websocket心跳检测失败
     *
     * @param data 返回数据
     * @throws
     */
    public static String fail(Object data, String code, String text) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("code", code);
        resultMap.put("msg", text);
        resultMap.put("status", "fail");
        resultMap.put("data", data);
        if (data == null) {
            resultMap.put("data", new String[]{});
        }
        return JSON.toJSONString(resultMap);
    }
 
}