BZSysExCore.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using System;
  2. using System.ComponentModel;
  3. using WMS.Info;
  4. namespace WMS.BZServices
  5. {
  6. /// <summary>
  7. /// 描 述:消息类型
  8. /// </summary>
  9. [Description("异常类型")]
  10. public enum ESysExType
  11. {
  12. /// <summary>
  13. /// 登录IP限制
  14. /// </summary>
  15. [Description("登录时间限制")]
  16. FilterTimeError = -9,
  17. /// <summary>
  18. /// 登录IP限制
  19. /// </summary>
  20. [Description("登录IP限制")]
  21. FilterIPError = -8,
  22. /// <summary>
  23. /// 数据库连接配置异常
  24. /// </summary>
  25. [Description("数据库连接配置异常")]
  26. DbSetError = -7,
  27. /// <summary>
  28. /// 数据库连接异常
  29. /// </summary>
  30. [Description("数据库连接异常")]
  31. DbConnError = -6,
  32. /// <summary>
  33. /// 数据库连接异常
  34. /// </summary>
  35. [Description("密码初始化")]
  36. PwdInit = -5,
  37. /// <summary>
  38. /// 密码错误
  39. /// </summary>
  40. [Description("密码错误")]
  41. PwdError = -4,
  42. /// <summary>
  43. /// 密码过期
  44. /// </summary>
  45. [Description("密码过期")]
  46. PwdExpiration = -3,
  47. /// <summary>
  48. /// 密码过期
  49. /// </summary>
  50. [Description("登录超时")]
  51. LoginTimeout = -2,
  52. /// <summary>
  53. /// 异常清息
  54. /// </summary>
  55. [Description("异常清息")]
  56. Exception = -1,
  57. /// <summary>
  58. /// 失败清息
  59. /// </summary>
  60. [Description("失败清息")]
  61. Fail = 0,
  62. }
  63. public class BZSysExCore : Exception
  64. {
  65. /// <summary>
  66. /// 异常消息
  67. /// </summary>
  68. public string ExMsg { get; private set; }
  69. /// <summary>
  70. /// 内部异常
  71. /// </summary>
  72. public Exception Ex { get; private set; }
  73. /// <summary>
  74. /// 消息类型
  75. /// </summary>
  76. public ESysExType SysExType { get; private set; } = ESysExType.Exception;
  77. //带有一个字符串参数和一个内部异常信息参数的构造函数
  78. public BZSysExCore(ESysExType sysExType, string exMsg, Exception innerException) : base(exMsg, innerException)
  79. {
  80. Ex = innerException;
  81. ExMsg = exMsg;
  82. SysExType = sysExType;
  83. }
  84. public BZSysExCore(ESysExType sysExType, string exMsg) : base(exMsg)
  85. {
  86. ExMsg = exMsg;
  87. SysExType = sysExType;
  88. }
  89. /// <summary>
  90. /// 错误提示信息
  91. /// </summary>
  92. public static BZSysExCore ThrowFailException(string exMsg)
  93. {
  94. return new BZSysExCore(ESysExType.Fail, exMsg);
  95. }
  96. /// <summary>
  97. /// 错误提示信息
  98. /// </summary>
  99. public static BZSysExCore ThrowInEmpty()
  100. {
  101. return new BZSysExCore(ESysExType.Fail, "请求数据为空。");
  102. }
  103. /// <summary>
  104. /// token无效
  105. /// </summary>
  106. public static BZSysExCore ThrowToken()
  107. {
  108. return new BZSysExCore(ESysExType.LoginTimeout, "当前登录token无效,请重新登录后再操作。");
  109. }
  110. /// <summary>
  111. /// 登录超时
  112. /// </summary>
  113. public static BZSysExCore ThrowLoginTimeout()
  114. {
  115. return new BZSysExCore(ESysExType.LoginTimeout, "登录超时,请重新登录!");
  116. }
  117. /// <summary>
  118. /// 密码过期
  119. /// </summary>
  120. public static BZSysExCore ThrowPwdExpiration()
  121. {
  122. return new BZSysExCore(ESysExType.PwdExpiration, "用户密码已过期。");
  123. }
  124. /// <summary>
  125. /// 数据库连接配置文件异常
  126. /// </summary>
  127. public static BZSysExCore ThrowDbSetError()
  128. {
  129. return new BZSysExCore(ESysExType.DbSetError, "数据库连接配置文件异常,请联系管理员。");
  130. }
  131. /// <summary>
  132. /// 数据库连接配置文件异常
  133. /// </summary>
  134. public static BZSysExCore ThrowDbConnError(Exception ex)
  135. {
  136. return new BZSysExCore(ESysExType.DbConnError, ex.Message, ex);
  137. }
  138. public static BZSysExCore GetSysExCore(Exception ex)
  139. {
  140. if (ex is BZSysExCore)
  141. {
  142. return ex as BZSysExCore;
  143. }
  144. else
  145. {
  146. return new BZSysExCore(ESysExType.Exception, ex.Message, ex);
  147. }
  148. }
  149. public static ResInfo GetResErr(Exception ex, object data = null)
  150. {
  151. BZSysExCore ec;
  152. if (ex is BZSysExCore)
  153. {
  154. ec = ex as BZSysExCore;
  155. }
  156. else
  157. {
  158. ec = new BZSysExCore(ESysExType.Exception, ex.Message, ex);
  159. }
  160. EResponseCode rescode = EResponseCode.Fail;
  161. if (ec.SysExType == ESysExType.Exception)
  162. {
  163. rescode = EResponseCode.Exception;
  164. }
  165. else if (ec.SysExType == ESysExType.LoginTimeout)
  166. {
  167. rescode = EResponseCode.LoginTimeout;
  168. }
  169. else if (ec.SysExType == ESysExType.PwdExpiration)
  170. {
  171. rescode = EResponseCode.PwdExpiration;
  172. }
  173. else if (ec.SysExType == ESysExType.PwdInit)
  174. {
  175. rescode = EResponseCode.PwdInit;
  176. }
  177. else if (ec.SysExType == ESysExType.FilterIPError)
  178. {
  179. rescode = EResponseCode.FilterIPError;
  180. }
  181. else if (ec.SysExType == ESysExType.FilterTimeError)
  182. {
  183. rescode = EResponseCode.FilterTimeError;
  184. }
  185. ResInfo infos = new ResInfo();
  186. infos.code = rescode;
  187. infos.info = ex.Message;
  188. infos.data = data;
  189. return infos;
  190. //return new ResInfo() { code = rescode, info = ex.Message, data = data };
  191. }
  192. public static ResInfo GetResSucc(string Msg="", object data = null)
  193. {
  194. return new ResInfo() { code = EResponseCode.Success, data = data, info = string.IsNullOrWhiteSpace(Msg) ? "响应成功" : Msg };
  195. }
  196. }
  197. }