wuxw
2021-04-23 e9be8d15ab3ee20685793e16071c56485b32e33a
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
package com.java110.vo.api.machine;
 
import com.alibaba.fastjson.JSONObject;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
 
import java.io.Serializable;
 
/**
 * @ClassName MachineResDataVo
 * @Description 转述于 和硬件交互对象bean
 * @Author wuxw
 * @Date 2020/1/25 23:09
 * @Version 1.0
 * add by wuxw 2020/1/25
 **/
public class MachineResDataVo implements Serializable {
 
    public static final String CODE_ERROR = "-1";
    public static final String CODE_SUCCESS = "0";
 
    public MachineResDataVo() {
    }
 
    public MachineResDataVo(String code, String message) {
        this(code, message, new JSONObject());
    }
 
    public MachineResDataVo(String code, String message, JSONObject data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
 
    private String code;
    private String message;
    private JSONObject data;
 
    public String getCode() {
        return code;
    }
 
    public void setCode(String code) {
        this.code = code;
    }
 
    public String getMessage() {
        return message;
    }
 
    public void setMessage(String message) {
        this.message = message;
    }
 
    public JSONObject getData() {
        return data;
    }
 
    public void setData(JSONObject data) {
        this.data = data;
    }
 
    /**
     * 获取封装好格式报文
     * @param code
     * @param message
     * @return
     */
    public static ResponseEntity<String> getResData(String code, String message) {
        return getResData(code, message, new JSONObject());
    }
 
    /**
     * 获取封装好格式报文
     * @param code
     * @param message
     * @param data
     * @return
     */
    public static ResponseEntity<String> getResData(String code, String message, JSONObject data) {
        ResponseEntity<String> responseEntity = null;
        MachineResDataVo machineResDataVo = new MachineResDataVo(code, message, data);
        if (CODE_SUCCESS.equals(code)) {
            responseEntity = new ResponseEntity<>(JSONObject.toJSONString(machineResDataVo), HttpStatus.OK);
        } else {
            responseEntity = new ResponseEntity<>(JSONObject.toJSONString(machineResDataVo), HttpStatus.BAD_REQUEST);
        }
 
        return responseEntity;
    }
}