Search in sources :

Example 11 with Page

use of com.ngtesting.platform.vo.Page in project ngtesting-platform by aaronchen2k.

the class UserServiceImpl method listByPage.

@Override
public Page listByPage(Long orgId, String keywords, String disabled, Integer currentPage, Integer itemsPerPage) {
    DetachedCriteria dc = DetachedCriteria.forClass(TestUser.class);
    dc.createAlias("orgSet", "companies");
    dc.add(Restrictions.eq("companies.id", orgId));
    dc.add(Restrictions.eq("deleted", Boolean.FALSE));
    if (StringUtil.isNotEmpty(keywords)) {
        dc.add(Restrictions.or(Restrictions.like("name", "%" + keywords + "%"), Restrictions.like("email", "%" + keywords + "%"), Restrictions.like("phone", "%" + keywords + "%")));
    }
    if (StringUtil.isNotEmpty(disabled)) {
        dc.add(Restrictions.eq("disabled", Boolean.valueOf(disabled)));
    }
    dc.addOrder(Order.asc("id"));
    Page page = findPage(dc, currentPage * itemsPerPage, itemsPerPage);
    return page;
}
Also used : DetachedCriteria(org.hibernate.criterion.DetachedCriteria) Page(com.ngtesting.platform.vo.Page)

Example 12 with Page

use of com.ngtesting.platform.vo.Page in project ngtesting-platform by aaronchen2k.

the class OrgGroupServiceImpl method listByPage.

@Override
public Page listByPage(Long orgId, String keywords, String disabled, Integer currentPage, Integer itemsPerPage) {
    DetachedCriteria dc = DetachedCriteria.forClass(TestOrgGroup.class);
    dc.add(Restrictions.eq("orgId", orgId));
    dc.add(Restrictions.eq("deleted", Boolean.FALSE));
    if (StringUtil.isNotEmpty(keywords)) {
        dc.add(Restrictions.like("name", "%" + keywords + "%"));
    }
    if (StringUtil.isNotEmpty(disabled)) {
        dc.add(Restrictions.eq("disabled", Boolean.valueOf(disabled)));
    }
    dc.addOrder(Order.asc("id"));
    Page page = findPage(dc, currentPage * itemsPerPage, itemsPerPage);
    return page;
}
Also used : DetachedCriteria(org.hibernate.criterion.DetachedCriteria) Page(com.ngtesting.platform.vo.Page)

Example 13 with Page

use of com.ngtesting.platform.vo.Page in project ngtesting-platform by aaronchen2k.

the class DocumentServiceImpl method listByPage.

@Override
public Page listByPage(long eventId, int currentPage, int itemsPerPage, DocType type) {
    DetachedCriteria dc = DetachedCriteria.forClass(TestDocument.class);
    dc.add(Restrictions.eq("eventId", eventId));
    if (type != null) {
        dc.add(Restrictions.eq("docType", type));
    }
    dc.add(Restrictions.eq("deleted", Boolean.FALSE));
    dc.add(Restrictions.eq("disabled", Boolean.FALSE));
    dc.addOrder(Order.asc("id"));
    Page page = findPage(dc, currentPage * itemsPerPage, itemsPerPage);
    return page;
}
Also used : DetachedCriteria(org.hibernate.criterion.DetachedCriteria) Page(com.ngtesting.platform.vo.Page)

Example 14 with Page

use of com.ngtesting.platform.vo.Page in project ngtesting-platform by aaronchen2k.

the class BaseDaoImpl method findPageByFetchedHql.

/**
 * <HQL分页查询>
 *
 * @param hql      HQL语句
 * @param countHql 查询记录条数的HQL语句
 * @param pageNo   下一页
 * @param pageSize 一页总条数
 * @param values   不定Object数组参数
 * @return Page的封装类,里面包含了页码的信息以及查询的数据List集合
 * @see com.ngtesting.platform.dao.BaseDao#findPageByFetchedHql(java.lang.String, java.lang.String, int, int, java.lang.Object[])
 */
@Override
public Page<Object> findPageByFetchedHql(String hql, String countHql, int pageNo, int pageSize, Object... values) {
    Page<Object> retValue = new Page<Object>();
    Query query = this.getSession().createQuery(hql);
    if (values != null) {
        for (int i = 0; i < values.length; i++) {
            query.setParameter(i, values[i]);
        }
    }
    int currentPage = pageNo > 1 ? pageNo : 1;
    retValue.setLimit(pageSize);
    if (countHql == null) {
        ScrollableResults results = query.scroll();
        results.last();
        // 设置总记录数
        retValue.setTotal(results.getRowNumber() + 1);
    } else {
        Long count = countByHql(countHql, values);
        retValue.setTotal(count.intValue());
    }
    List<Object> itemList = query.setFirstResult((currentPage - 1) * pageSize).setMaxResults(pageSize).list();
    if (itemList == null) {
        itemList = new ArrayList<Object>();
    }
    retValue.setItems(itemList);
    return retValue;
}
Also used : Query(org.hibernate.Query) Page(com.ngtesting.platform.vo.Page) ScrollableResults(org.hibernate.ScrollableResults)

Aggregations

Page (com.ngtesting.platform.vo.Page)14 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)9 JSONObject (com.alibaba.fastjson.JSONObject)4 AuthPassport (com.ngtesting.platform.util.AuthPassport)4 HashMap (java.util.HashMap)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 UserVo (com.ngtesting.platform.vo.UserVo)3 ArrayList (java.util.ArrayList)2 DocumentVo (com.ngtesting.platform.vo.DocumentVo)1 OrgGroupVo (com.ngtesting.platform.vo.OrgGroupVo)1 RelationOrgGroupUserVo (com.ngtesting.platform.vo.RelationOrgGroupUserVo)1 RoleVo (com.ngtesting.platform.vo.RoleVo)1 List (java.util.List)1 Criteria (org.hibernate.Criteria)1 Query (org.hibernate.Query)1 ScrollableResults (org.hibernate.ScrollableResults)1 Projection (org.hibernate.criterion.Projection)1 CriteriaImpl (org.hibernate.internal.CriteriaImpl)1 ResultTransformer (org.hibernate.transform.ResultTransformer)1