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();
|
}
|
}
|
}
|