CommAsyncResult.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package com.shkpr.service.alambizplugin.dto;
  2. import com.fasterxml.jackson.annotation.JsonFormat;
  3. import com.shkpr.service.alambizplugin.constants.CommAsyncStatusEnum;
  4. import lombok.Data;
  5. import org.springframework.format.annotation.DateTimeFormat;
  6. import java.time.LocalDateTime;
  7. import java.util.List;
  8. import java.util.Map;
  9. /**
  10. * 通用异步结果
  11. *
  12. * @author 欧阳劲驰
  13. * @since 1.0.0
  14. */
  15. @Data
  16. public class CommAsyncResult<T> {
  17. /**
  18. * id
  19. */
  20. private String id;
  21. /**
  22. * 检查状态:0:进行中,1:成功,2:失败,3:不存在
  23. */
  24. private Integer status;
  25. /**
  26. * 操作人
  27. */
  28. private String operator;
  29. /**
  30. * 子项key
  31. */
  32. private List<String> subitemKeys;
  33. /**
  34. * 结果数据
  35. */
  36. private T data;
  37. /**
  38. * 请求检查时间
  39. */
  40. @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh_CN", timezone = "Asia/Shanghai")
  41. @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  42. private LocalDateTime requestTime;
  43. /**
  44. * 完成检查时间
  45. */
  46. @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh_CN", timezone = "Asia/Shanghai")
  47. @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  48. private LocalDateTime completeTime;
  49. /**
  50. * 数据更新时间
  51. */
  52. @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh_CN", timezone = "Asia/Shanghai")
  53. @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  54. private Map<String, LocalDateTime> refreshTimes;
  55. /**
  56. * 进行中
  57. */
  58. public static <T> CommAsyncResult<T> inProgress(String id, LocalDateTime requestTime, String operator) {
  59. CommAsyncResult<T> result = new CommAsyncResult<>();
  60. result.setId(id);
  61. result.setStatus(CommAsyncStatusEnum.IN_PROGRESS.getCode());
  62. result.setRequestTime(requestTime);
  63. result.setOperator(operator);
  64. return result;
  65. }
  66. /**
  67. * 成功
  68. */
  69. public static <T> CommAsyncResult<T> success(String id) {
  70. CommAsyncResult<T> result = new CommAsyncResult<>();
  71. result.setId(id);
  72. result.setStatus(CommAsyncStatusEnum.SUCCESS.getCode());
  73. result.setRequestTime(LocalDateTime.now());
  74. return result;
  75. }
  76. /**
  77. * 失败
  78. */
  79. public static <T> CommAsyncResult<T> fail(String id) {
  80. CommAsyncResult<T> result = new CommAsyncResult<>();
  81. result.setId(id);
  82. result.setStatus(CommAsyncStatusEnum.FAIL.getCode());
  83. result.setRequestTime(LocalDateTime.now());
  84. return result;
  85. }
  86. }