ResultCode.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.gyee.wisdom.adapter.common.result;
  2. /*
  3. * #1001~1999 区间表示参数错误
  4. * #2001~2999 区间表示用户错误
  5. * #3001~3999 区间表示权限异常
  6. */
  7. public enum ResultCode {
  8. /* 成功 */
  9. SUCCESS(2000, "成功"),
  10. /* 默认失败 */
  11. ERROR(4004, "失败"),
  12. ERROR_CONNECT(4005, "数据库连接异常"),
  13. ERROR_DATA(4006, "数据查询失败"),
  14. /* 参数错误:1000~1999 */
  15. PARAM_NOT_VALID(1001, "参数无效"),
  16. PARAM_IS_BLANK(1002, "参数为空"),
  17. PARAM_TYPE_ERROR(1003, "参数类型错误"),
  18. PARAM_NOT_COMPLETE(1004, "参数缺失"),
  19. /* 用户错误 */
  20. USER_NOT_LOGIN(2001, "用户未登录"),
  21. USER_ACCOUNT_ERROR(2002, "账号或密码错误"),
  22. USER_FAIL_LOGIN(2003, "登录失败"),
  23. /* 业务错误 */
  24. NO_PERMISSION(3001, "没有权限");
  25. private Integer code;
  26. private String message;
  27. ResultCode(Integer code) {
  28. this.code = code;
  29. }
  30. ResultCode(Integer code, String message) {
  31. this.code = code;
  32. this.message = message;
  33. }
  34. public Integer getCode() {
  35. return code;
  36. }
  37. public void setCode(Integer code) {
  38. this.code = code;
  39. }
  40. public String getMessage() {
  41. return message;
  42. }
  43. public void setMessage(String message) {
  44. this.message = message;
  45. }
  46. /**
  47. * 根据code获取message
  48. *
  49. * @param code
  50. * @return
  51. */
  52. public static String getMessageByCode(Integer code) {
  53. for (ResultCode ele : values()) {
  54. if (ele.getCode().equals(code)) {
  55. return ele.getMessage();
  56. }
  57. }
  58. return null;
  59. }
  60. }