jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace HH.WMS.Common.Response
{
    public class DataResponse
    {
        public bool success { get; private set; }
        public string errCode { get; private set; }
        public string errMsg { get; private set; }
        public object data { get; set; }
 
        /// <summary>
        /// 返回错误
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static DataResponse Error(string msg)
        {
            var result = new DataResponse();
            result.success = false;
            result.errMsg = msg;
            result.errCode = EnumValue(ErrorEnum.SystemError);
            return result;
        }
 
        public static DataResponse Error(string msg, ErrorEnum errCode)
        {
            var result = new DataResponse();
            result.success = false;
            result.errMsg = msg;
            result.errCode = EnumValue(errCode);
            return result;
        }
 
        public static DataResponse Error(string msg, HH.WMS.Common.External.LogPara logPara)
        {
            var result = new DataResponse();
            result.success = false;
            result.errMsg = msg;
            result.errCode = EnumValue(ErrorEnum.SystemError);
            Log.Detail(logPara, "结果异常,原因:" + msg);
            return result;
        }
 
        /// <summary>
        /// 返回错误
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="className"></param>
        /// <returns></returns>
        public static DataResponse Error(string msg, string className)
        {
            var result = new DataResponse();
            result.success = false;
            result.errMsg = msg;
            result.errCode = EnumValue(ErrorEnum.SystemError);
            //  Log.ApiDebug(className, msg);
            return result;
        }
 
        /// <summary>
        /// 返回正确
        /// </summary>
        /// <returns></returns>
        public static DataResponse Normal()
        {
            var result = new DataResponse();
            result.success = true;
            result.errMsg = "";
            result.errCode = EnumValue(ErrorEnum.Normal);
            return result;
        }
 
        public static DataResponse Normal(string msg)
        {
            var result = new DataResponse();
            result.success = true;
            result.errMsg = msg;
            result.errCode = EnumValue(ErrorEnum.Normal);
            return result;
        }
 
        public static DataResponse Data(bool success, ErrorEnum errCode, string errMsg, object data)
        {
            var result = new DataResponse();
            result.success = success;
            result.errCode = EnumValue(errCode);
            result.errMsg = errMsg;
            result.data = data;
            return result;
        }
 
        public string Describe()
        {
            return "结果:" + (success ? "成功!" : "失败!" + errMsg);
        }
 
        public static string EnumValue(ErrorEnum error)
        {
            return ((int)error).ToString();
        }
    }
}