Parcourir la source

物料页面后台

FEI il y a 3 semaines
Parent
révision
b6c78e7fd9

+ 73
- 0
sto/src/main/java/com/shinsoft/sto/model/system/ResponseCodeMsg.java Voir le fichier

@@ -0,0 +1,73 @@
1
+package com.shinsoft.sto.model.system;
2
+
3
+/**
4
+ * 响应码和消息常量
5
+ */
6
+public class ResponseCodeMsg {
7
+    
8
+    // 成功状态码和消息 - 与 JSONTools.java 保持一致
9
+    public static final String CODE_SUCCESS = "0";
10
+    public static final String MSG_OK = "操作成功";
11
+    
12
+    // 异常状态码和消息
13
+    public static final String CODE_EX = "500";
14
+    public static final String MSG_EX = "系统异常";
15
+    
16
+    public static final String CODE_NULL = "400";
17
+    public static final String MSG_NULL = "参数为空";
18
+    
19
+    // 其他常用状态码
20
+    public static final String CODE_FAIL = "-1";
21
+    public static final String MSG_FAIL = "操作失败";
22
+    
23
+    public static final String CODE_VALIDATE_ERROR = "401";
24
+    public static final String MSG_VALIDATE_ERROR = "参数校验失败";
25
+    
26
+    public static final String CODE_UNAUTHORIZED = "403";
27
+    public static final String MSG_UNAUTHORIZED = "未授权";
28
+    
29
+    public static final String CODE_NOT_FOUND = "404";
30
+    public static final String MSG_NOT_FOUND = "资源不存在";
31
+    
32
+    // 私有构造方法,防止实例化
33
+    private ResponseCodeMsg() {
34
+    }
35
+    
36
+    /**
37
+     * 根据状态码获取对应的消息
38
+     */
39
+    public static String getMessageByCode(String code) {
40
+        switch (code) {
41
+            case CODE_SUCCESS:
42
+                return MSG_OK;
43
+            case CODE_EX:
44
+                return MSG_EX;
45
+            case CODE_NULL:
46
+                return MSG_NULL;
47
+            case CODE_FAIL:
48
+                return MSG_FAIL;
49
+            case CODE_VALIDATE_ERROR:
50
+                return MSG_VALIDATE_ERROR;
51
+            case CODE_UNAUTHORIZED:
52
+                return MSG_UNAUTHORIZED;
53
+            case CODE_NOT_FOUND:
54
+                return MSG_NOT_FOUND;
55
+            default:
56
+                return "未知状态码";
57
+        }
58
+    }
59
+    
60
+    /**
61
+     * 判断状态码是否表示成功
62
+     */
63
+    public static boolean isSuccess(String code) {
64
+        return CODE_SUCCESS.equals(code);
65
+    }
66
+    
67
+    /**
68
+     * 判断状态码是否表示失败
69
+     */
70
+    public static boolean isFail(String code) {
71
+        return !isSuccess(code);
72
+    }
73
+}

+ 135
- 0
sto/src/main/java/com/shinsoft/sto/model/system/ResultJSON.java Voir le fichier

@@ -0,0 +1,135 @@
1
+package com.shinsoft.sto.model.system;
2
+
3
+import java.io.Serializable;
4
+
5
+/**
6
+ * 统一响应结果封装类
7
+ */
8
+public class ResultJSON implements Serializable {
9
+
10
+    private static final long serialVersionUID = 1L;
11
+
12
+    /**
13
+     * 状态码
14
+     */
15
+    private String code;
16
+
17
+    /**
18
+     * 消息
19
+     */
20
+    private String msg;
21
+
22
+    /**
23
+     * 数据
24
+     */
25
+    private Object data;
26
+
27
+    // 构造方法 - 兼容 JSONTools.java 中的使用
28
+    public ResultJSON() {
29
+    }
30
+
31
+    public ResultJSON(String code, String msg) {
32
+        this.code = code;
33
+        this.msg = msg;
34
+    }
35
+
36
+    public ResultJSON(String code, String msg, Object data) {
37
+        this.code = code;
38
+        this.msg = msg;
39
+        this.data = data;
40
+    }
41
+
42
+    // 兼容 int 类型 code 的构造方法(JSONTools.java 中使用了 int 参数)
43
+    public ResultJSON(int code, String msg) {
44
+        this.code = String.valueOf(code);
45
+        this.msg = msg;
46
+    }
47
+
48
+    public ResultJSON(int code, String msg, Object data) {
49
+        this.code = String.valueOf(code);
50
+        this.msg = msg;
51
+        this.data = data;
52
+    }
53
+
54
+    // 成功相关静态方法 - 使用 ResponseCodeMsg 常量
55
+    public static ResultJSON success() {
56
+        return new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, ResponseCodeMsg.MSG_OK);
57
+    }
58
+
59
+    public static ResultJSON success(String msg) {
60
+        return new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, msg);
61
+    }
62
+
63
+    public static ResultJSON success(Object data) {
64
+        return new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, ResponseCodeMsg.MSG_OK, data);
65
+    }
66
+
67
+    public static ResultJSON success(String msg, Object data) {
68
+        return new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, msg, data);
69
+    }
70
+
71
+    // 错误相关静态方法
72
+    public static ResultJSON error() {
73
+        return new ResultJSON(ResponseCodeMsg.CODE_FAIL, ResponseCodeMsg.MSG_FAIL);
74
+    }
75
+
76
+    public static ResultJSON error(String msg) {
77
+        return new ResultJSON(ResponseCodeMsg.CODE_FAIL, msg);
78
+    }
79
+
80
+    public static ResultJSON error(String code, String msg) {
81
+        return new ResultJSON(code, msg);
82
+    }
83
+
84
+    public static ResultJSON error(String code, String msg, Object data) {
85
+        return new ResultJSON(code, msg, data);
86
+    }
87
+
88
+    // 兼容 int 类型 code 的错误方法
89
+    public static ResultJSON error(int code, String msg) {
90
+        return new ResultJSON(code, msg);
91
+    }
92
+
93
+    public static ResultJSON error(int code, String msg, Object data) {
94
+        return new ResultJSON(code, msg, data);
95
+    }
96
+
97
+    // Getter 和 Setter 方法
98
+    public String getCode() {
99
+        return code;
100
+    }
101
+
102
+    public void setCode(String code) {
103
+        this.code = code;
104
+    }
105
+
106
+    public String getMsg() {
107
+        return msg;
108
+    }
109
+
110
+    public void setMsg(String msg) {
111
+        this.msg = msg;
112
+    }
113
+
114
+    public Object getData() {
115
+        return data;
116
+    }
117
+
118
+    public void setData(Object data) {
119
+        this.data = data;
120
+    }
121
+
122
+    // 判断是否成功的方法
123
+    public boolean isSuccess() {
124
+        return ResponseCodeMsg.CODE_SUCCESS.equals(this.code);
125
+    }
126
+
127
+    @Override
128
+    public String toString() {
129
+        return "ResultJSON{" +
130
+                "code='" + code + '\'' +
131
+                ", msg='" + msg + '\'' +
132
+                ", data=" + data +
133
+                '}';
134
+    }
135
+}

+ 36
- 0
sto/src/main/java/com/shinsoft/sto/model/system/selectModel.java Voir le fichier

@@ -0,0 +1,36 @@
1
+package com.shinsoft.sto.model.system;
2
+
3
+//package com.shinsoft.sto.model.common;
4
+
5
+/**
6
+ * 下拉框选项模型
7
+ */
8
+public class selectModel {
9
+
10
+    private String value;
11
+    private String label;
12
+
13
+    public selectModel() {
14
+    }
15
+
16
+    public selectModel(String value, String label) {
17
+        this.value = value;
18
+        this.label = label;
19
+    }
20
+
21
+    public String getValue() {
22
+        return value;
23
+    }
24
+
25
+    public void setValue(String value) {
26
+        this.value = value;
27
+    }
28
+
29
+    public String getLabel() {
30
+        return label;
31
+    }
32
+
33
+    public void setLabel(String label) {
34
+        this.label = label;
35
+    }
36
+}

+ 29
- 0
sto/src/main/java/com/shinsoft/sto/tools/JSONTools.java Voir le fichier

@@ -0,0 +1,29 @@
1
+package com.shinsoft.sto.tools;
2
+
3
+import com.alibaba.fastjson.JSON;
4
+import com.alibaba.fastjson.serializer.SerializerFeature;
5
+import com.shinsoft.sto.model.system.ResponseCodeMsg;
6
+import com.shinsoft.sto.model.system.ResultJSON;
7
+
8
+public class JSONTools {
9
+    public   static  String toString(Object object){
10
+        ResultJSON  result =  new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, ResponseCodeMsg.MSG_OK, object);
11
+        return JSON.toJSONString(result,SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullBooleanAsFalse);
12
+    }
13
+    public   static  String toString(int exCode,String exMessage){
14
+        ResultJSON  result =  new ResultJSON(exCode, exMessage, null);
15
+        return JSON.toJSONString(result,SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullBooleanAsFalse);
16
+    }
17
+    public  static  String toString(Object object,String format){
18
+        ResultJSON  result =  new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, ResponseCodeMsg.MSG_OK, object);
19
+        return JSON.toJSONStringWithDateFormat(result,format,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullBooleanAsFalse);
20
+    }
21
+    public  static  String toStringyyyyMMdd(Object object){
22
+        ResultJSON  result =  new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, ResponseCodeMsg.MSG_OK, object);
23
+        return JSON.toJSONStringWithDateFormat(result,"yyyy-MM-dd",SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullBooleanAsFalse);
24
+    }
25
+    public  static  String toStringyyyyMMddHHmmss(Object object){
26
+        ResultJSON  result =  new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, ResponseCodeMsg.MSG_OK, object);
27
+        return JSON.toJSONStringWithDateFormat(result,"yyyy-MM-dd HH:mm:ss",SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullBooleanAsFalse);
28
+    }
29
+}

Loading…
Annuler
Enregistrer