Response.cs 3.88 KB
namespace Hh.Mes.POJO.Response
{
    public class Response
    {
        /// <summary>
        /// 默认返回操作成功
        /// </summary>
        public Response(bool status = true, string msg = "业务数据操作成功!")
        {
            Code = status ? (int)RetCode.SUCCESS : (int)RetCode.INTERNAL_SERVER_ERROR;
            Status = status;
            Message = msg;
        }


        public int Code { get; set; }

        public string Message { get; set; }

        public bool Status { get; set; }

        public int Count { get; set; }

        /// <summary>
        /// 登陆标识
        /// </summary>
        public string Token { get; set; }


        public dynamic Result { get; set; }

        /// <summary>
        /// 统一返回前端失败
        /// </summary>
        /// <param name="msg">失败消息</param>
        public virtual void ResponseErr(string msg)
        {
            Code = (int)RetCode.FAIL;
            Message = msg;
            Status = false;
        }

        /// <summary>
        /// 统一返回前端失败
        /// </summary>
        /// <param name="msg">失败消息</param>
        public virtual Response ResponseError(string msg = "业务数据操作失败")
        {
            Code = (int)RetCode.INTERNAL_SERVER_ERROR;
            Message = msg;
            Status = false;
            return this;
        }
        /// <summary>
        /// 统一返回前端成功
        /// </summary>
        public virtual Response ResponseSuccess(string msg = "业务数据操作成功!")
        {
            Code = (int)RetCode.SUCCESS;
            Message = msg;
            Status = true;
            return this;
        }
    }

    public class Response<T> : Response
    {
        /// <summary>
        /// 回传的结果
        /// </summary>
        public new T Result { get; set; }


        public Response(bool status, string msg) : base(status, msg)
        {
        }

        public Response()
        {
        }
    }

    public class ResponseUpstream<T> : Response<T>
    {
        public string plmeid { get; set; }

        //public string flag { get { return Code == (int)RetCode.SUCCESS ? "1" : "0"; } }

        //public string msg { get { return Message; } }

        public ResponseUpstream(string plmeid, bool status = true, string msg = "业务数据操作成功!") : base(status, msg)
        {
            this.plmeid = plmeid;
        }
    }
    public class MOMResult
    {
        public string PLMEID { get; set; }

        public string MSG { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string STATUS { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string TEMPCODE { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string FLAG { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string HEAD { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string DATAS { get; set; }
    }


    public enum RetCode
    {
        OK = 0,
        /// <summary>
        /// 成功
        /// </summary>
        SUCCESS = 200,

        /// <summary>
        /// 失败
        /// </summary>
        FAIL = 400,

        /// <summary>
        /// 未认证(签名错误)
        /// </summary>
        UNAUTHORIZED = 401,

        /// <summary>
        /// 找不到请求文件
        /// </summary>
        NoHandlerFoundException = 404,

        /// <summary>
        /// 未登录 
        /// </summary>
        UNAUTHEN = 401,

        /// <summary>
        /// 未授权,拒绝访问
        /// </summary>
        UNAUTHZ = 403,

        /// <summary>
        /// 服务器内部错误
        /// </summary>
        INTERNAL_SERVER_ERROR = 500,

        /// <summary>
        /// 业务处理错误
        /// </summary>
        Business_ERROR = 600,

    }
}