package com.liangjian.dataplatform.member.entity.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.List;

/**
 * @Author: 黄子奇
 * @Date: 2019/8/28 11:14
 *
 * 由于前端要用的结构是
 * {
 *     items:[...],
 *     totalCount: number
 * }
 * 为了配合前端，使用这个自定义的结构返回，而不直接使用jpa自带的Page
 */
@ApiModel("列表响应对象")
public class PageResult<T> extends ResultObject<T> implements Serializable {

    private static final long serialVersionUID = 4641690674252953991L;

    @ApiModelProperty("数据")
    private List<T> items;

    @ApiModelProperty("总数据量")
    private Long totalCount;

    public PageResult(List<T> items, Long totalCount) {
        super(null, true, null,null);
        this.items = items;
        this.totalCount = totalCount;
    }

    public static <T> PageResult<T> success(List<T> items, Long totalCount) {
        return new PageResult<>(items, totalCount);
    }

    public static <T> PageResult<T> error(String msg) {
        PageResult<T> res = new PageResult<>(null,null);
        res.setMsg(msg);
        res.setSuccess(false);
        return res;
    }

    public List<T> getItems() {
        return items;
    }

    public void setItems(List<T> items) {
        this.items = items;
    }

    public Long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Long totalCount) {
        this.totalCount = totalCount;
    }

}
