ResponseNew.cs 1.57 KB
using System;
using System.Collections.Generic;
using System.Text;

namespace Hh.Mes.POJO.Response
{
    /// <summary>
    /// 兼容PDA、和web 错误统一返回500,无数据也返回500
    /// 401 Token失效
    /// 200 成功,有数据,业务正常
    /// </summary>
    public class ResponseNew
    {
        // <summary>
        /// 默认返回操作成功
        ///</summary>
        public ResponseNew(bool statusx = true, string msg = "成功")
        {
            code = statusx ? 200 : 500;
            status = statusx;
            message = msg;
        }


        public int code { get; set; }

        public string message { get; set; }

        public bool status { get; set; }

        public long count { get; set; }

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


        public dynamic data { get; set; }


        /// <summary>
        /// 统一返回前端失败
        /// </summary>
        /// <param name="msg">失败消息</param>
        public virtual ResponseNew ResponseError(string msg = "业务数据操作失败",int codes=500)
        {
            code = codes;
            message = msg;
            status = false;
            data = "[]";
            return this;
        }

        /// <summary>
        /// 统一返回前端成功
        /// </summary>
        public virtual ResponseNew ResponseSuccess(string msg = "业务数据操作成功!")
        {
            code = 200;
            message = msg;
            status = true;
            return this;
        }
    }

}