GatewayResponse.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package com.cyksj.enums;
  2. import com.cyksj.dto.Result;
  3. import java.util.Map;
  4. /**
  5. * @author chan
  6. * @className GatewayResponse
  7. * @date 2020/7/29 3:06 下午
  8. */
  9. public enum GatewayResponse {
  10. /**
  11. * 成功
  12. */
  13. SUCCESS(GatewayApiCode.SUCCESS.getCode(), GatewayApiCode.SUCCESS.getMsg(),Boolean.TRUE),
  14. /**
  15. * 失败
  16. */
  17. FAIL(GatewayApiCode.METADATA_SYSTEM_ERROR.getCode(), GatewayApiCode.METADATA_SYSTEM_ERROR.getMsg(),Boolean.FALSE);
  18. GatewayResponse(Integer _code, String _msg, boolean flag) {
  19. this.code = _code;
  20. this.msg = _msg;
  21. this.flag = flag;
  22. }
  23. private Integer code;
  24. private String msg;
  25. private boolean flag;
  26. public Integer getCode() {
  27. return code;
  28. }
  29. public String getMsg() {
  30. return msg;
  31. }
  32. public boolean getFlag(){
  33. return flag;
  34. }
  35. public buildGateWay newBuilder() {
  36. return new buildGateWay(this);
  37. }
  38. public class buildGateWay {
  39. private Integer code;
  40. private String msg;
  41. private boolean flag;
  42. buildGateWay(GatewayResponse response) {
  43. this.code = response.getCode();
  44. this.msg = response.getMsg();
  45. this.flag = response.getFlag();
  46. }
  47. public buildGateWay buildGatewayCode(GatewayApiCode gateWayCode) {
  48. this.code = gateWayCode.getCode();
  49. this.msg = gateWayCode.getMsg();
  50. return this;
  51. }
  52. public buildGateWay setMsg(String _msg) {
  53. this.msg = _msg;
  54. return this;
  55. }
  56. public buildGateWay setCode(Integer code) {
  57. this.code = code;
  58. return this;
  59. }
  60. public <T> Result<T> toResult() {
  61. return buildMap();
  62. }
  63. public <T extends java.io.Serializable> Result<T> toResult(T model) {
  64. return Result.of(this.code,this.msg,this.flag,model);
  65. }
  66. @SuppressWarnings("rawtypes")
  67. public <T extends java.util.Collection> Result<T> toResult(T model) {
  68. return Result.of(this.code,this.msg,this.flag,model);
  69. }
  70. @SuppressWarnings("rawtypes")
  71. public <T> Result<T> toResult(T model) {
  72. return Result.of(this.code,this.msg,this.flag,model);
  73. }
  74. @SuppressWarnings("rawtypes")
  75. public <T extends Map> Result<T> toResult(T model) {
  76. return Result.of(this.code,this.msg,this.flag,model);
  77. }
  78. private <T> Result<T> buildMap() {
  79. return Result.of(this.code,this.msg,this.flag,null);
  80. }
  81. }
  82. }