package cn.com.qmth.stmms.biz.common;

import org.springframework.data.domain.Page;

public class BaseQueryService<T> {

    public void checkQuery(BaseQuery<T> query) {
        if (query.getPageNumber() < 1) {
            query.setPageNumber(1);
        }
        if (query.getPageSize() < 1) {
            query.setPageSize(10);
        }
    }

    public void fillResult(Page<T> result, BaseQuery<T> query) {
        if (result != null) {
            query.setTotalCount(result.getTotalElements());
            query.setTotalPage(result.getTotalPages());
            query.setCurrentCount(result.getNumberOfElements());
            query.setResult(result.getContent());
        } else {
            query.setTotalCount(0);
            query.setTotalPage(0);
            query.setCurrentCount(0);
        }
    }
}
