敏捷工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.3 KiB

2 years ago
  1. package com.whn.hellospring.common;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. public class Status {
  5. private boolean state;
  6. private String errorCode;
  7. private String message;
  8. private Map<String, Object> data;
  9. public Status(StateMessage stateMessage) {
  10. this.state = stateMessage.getState();
  11. this.errorCode = stateMessage.getErrorCode();
  12. this.message = stateMessage.getMessage();
  13. data = new HashMap<>();
  14. }
  15. public static Status result(StateMessage stateMessage,Map<String, Object> dataMap){
  16. Status status = new Status(stateMessage);
  17. status.setData(dataMap);
  18. return status;
  19. }
  20. /**
  21. * 返回客户端数据类型
  22. *
  23. * @param stateMessage 返回客户端消息
  24. * @param value 返回客户端值
  25. */
  26. public Status(StateMessage stateMessage, Object value) {
  27. this.state = stateMessage.getState();
  28. this.errorCode = stateMessage.getErrorCode();
  29. this.message = stateMessage.getMessage();
  30. data = new HashMap<>();
  31. data.put("result", value);
  32. }
  33. /**
  34. * 返回客户端数据类型
  35. *
  36. * @param stateMessage 返回客户端消息
  37. * @param map 返回客户端数据集合
  38. */
  39. public Status(StateMessage stateMessage, Map<String, Object> map) {
  40. this.state = stateMessage.getState();
  41. this.errorCode = stateMessage.getErrorCode();
  42. this.message = stateMessage.getMessage();
  43. data = new HashMap<>();
  44. data.putAll(map);
  45. }
  46. public boolean getState() {
  47. return state;
  48. }
  49. public void setState(boolean state) {
  50. this.state = state;
  51. }
  52. public String getMessage() {
  53. return message;
  54. }
  55. public void setMessage(String message) {
  56. this.message = message;
  57. }
  58. public Object getData() {
  59. return data;
  60. }
  61. public void setData(Map<String, Object> dataMap) {
  62. this.data = dataMap;
  63. }
  64. public void setData(String key, Object value) {
  65. this.data.put(key, value);
  66. }
  67. @Override
  68. public String toString() {
  69. return "Status [state=" + state + ", message=" + message + ", data=" + data + "]";
  70. }
  71. public String getErrorCode() {
  72. return errorCode;
  73. }
  74. public void setErrorCode(String errorCode) {
  75. this.errorCode = errorCode;
  76. }
  77. }