|
@@ -0,0 +1,104 @@
|
|
|
+package cn.minbb.job.data;
|
|
|
+
|
|
|
+import io.swagger.annotations.ApiModel;
|
|
|
+import io.swagger.annotations.ApiModelProperty;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.NoArgsConstructor;
|
|
|
+
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.Collection;
|
|
|
+
|
|
|
+@AllArgsConstructor
|
|
|
+@ApiModel(value = "请求结果数据", description = "请求结果数据模型")
|
|
|
+@Data
|
|
|
+@NoArgsConstructor
|
|
|
+public class ResponseResult<T extends Serializable> implements Serializable {
|
|
|
+
|
|
|
+ @ApiModelProperty(value = "是否处理成功", name = "success", example = "true")
|
|
|
+ private Boolean success = Boolean.TRUE;
|
|
|
+
|
|
|
+ @ApiModelProperty(value = "返回码", name = "code", example = "0")
|
|
|
+ private Integer code = 0;
|
|
|
+
|
|
|
+ @ApiModelProperty(value = "提示信息", name = "message")
|
|
|
+ private String message = "";
|
|
|
+
|
|
|
+ @ApiModelProperty(value = "返回数据", name = "data")
|
|
|
+ private T data;
|
|
|
+
|
|
|
+ @ApiModelProperty(value = "返回数据集", name = "dataset")
|
|
|
+ private Collection<T> dataset;
|
|
|
+
|
|
|
+ @ApiModelProperty(value = "返回对象", name = "object")
|
|
|
+ private Object object;
|
|
|
+
|
|
|
+ public static <T extends Serializable> ResponseResult.Builder<T> ok(Boolean success) {
|
|
|
+ return new ResultBuilder<>(success);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class ResultBuilder<T extends Serializable> implements Builder<T> {
|
|
|
+
|
|
|
+ private Boolean success;
|
|
|
+ private Integer code;
|
|
|
+ private String message;
|
|
|
+ private T data;
|
|
|
+ private Collection<T> dataset;
|
|
|
+ private Object object;
|
|
|
+
|
|
|
+ public ResultBuilder(Boolean success) {
|
|
|
+ this.code = Const.ReturnCode.SUCCESS;
|
|
|
+ this.message = Const.ReturnMessage.SUCCESS;
|
|
|
+ this.success = success;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Builder<T> code(Integer code) {
|
|
|
+ this.code = code;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Builder<T> message(String message) {
|
|
|
+ this.message = message;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Builder<T> data(T data) {
|
|
|
+ this.data = data;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Builder<T> dataset(Collection<T> dataset) {
|
|
|
+ this.dataset = dataset;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Builder<T> object(Object object) {
|
|
|
+ this.object = object;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseResult<T> build() {
|
|
|
+ return new ResponseResult<>(success, code, message, data, dataset, object);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public interface Builder<T extends Serializable> {
|
|
|
+ Builder<T> code(Integer code);
|
|
|
+
|
|
|
+ Builder<T> message(String message);
|
|
|
+
|
|
|
+ Builder<T> data(T data);
|
|
|
+
|
|
|
+ Builder<T> dataset(Collection<T> dataset);
|
|
|
+
|
|
|
+ Builder<T> object(Object object);
|
|
|
+
|
|
|
+ ResponseResult<T> build();
|
|
|
+ }
|
|
|
+}
|