Search in sources :

Example 6 with Page

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

the class BaseDaoImpl method findPage.

@Override
public Page findPage(DetachedCriteria dc, int start, int limit) {
    Criteria c = dc.getExecutableCriteria(getSession());
    CriteriaImpl impl = (CriteriaImpl) c;
    Projection projection = impl.getProjection();
    ResultTransformer transformer = impl.getResultTransformer();
    List<CriteriaImpl.OrderEntry> orderEntries = (List<CriteriaImpl.OrderEntry>) ReflectionUtils.getFieldValue(impl, "orderEntries");
    ReflectionUtils.setFieldValue(impl, "orderEntries", new ArrayList<CriteriaImpl.OrderEntry>());
    // 执行Count查询
    c.setResultTransformer(CriteriaImpl.DISTINCT_ROOT_ENTITY);
    long total = (Long) c.setProjection(Projections.countDistinct("id")).uniqueResult();
    // 将之前的Projection和OrderBy条件重新设回去
    c.setProjection(projection);
    c.setResultTransformer(transformer);
    ReflectionUtils.setFieldValue(impl, "orderEntries", orderEntries);
    c.setFirstResult(start);
    c.setMaxResults(limit);
    List list = c.list();
    return new Page(start, limit, Integer.parseInt(String.valueOf(total)), (list == null ? new ArrayList() : list));
}
Also used : CriteriaImpl(org.hibernate.internal.CriteriaImpl) ResultTransformer(org.hibernate.transform.ResultTransformer) ArrayList(java.util.ArrayList) Projection(org.hibernate.criterion.Projection) ArrayList(java.util.ArrayList) List(java.util.List) Page(com.ngtesting.platform.vo.Page) Criteria(org.hibernate.Criteria) DetachedCriteria(org.hibernate.criterion.DetachedCriteria)

Example 7 with Page

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

the class MsgAction method list.

@AuthPassport(validate = true)
@RequestMapping(value = "list", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> list(HttpServletRequest request, @RequestBody JSONObject json) {
    Map<String, Object> ret = new HashMap<String, Object>();
    UserVo userVo = (UserVo) request.getSession().getAttribute(Constant.HTTP_SESSION_USER_KEY);
    String keywords = json.getString("keywords");
    String isRead = json.getString("isRead");
    int page = json.getInteger("page") == null ? 0 : json.getInteger("page") - 1;
    int pageSize = json.getInteger("pageSize") == null ? Constant.PAGE_SIZE : json.getInteger("pageSize");
    Page pageDate = msgService.listByPage(userVo.getId(), isRead, keywords, page, pageSize);
    List<UserVo> vos = msgService.genVos(pageDate.getItems());
    ret.put("collectionSize", pageDate.getTotal());
    ret.put("data", vos);
    ret.put("code", Constant.RespCode.SUCCESS.getCode());
    return ret;
}
Also used : UserVo(com.ngtesting.platform.vo.UserVo) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) Page(com.ngtesting.platform.vo.Page) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with Page

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

the class OrgGroupAction method list.

@AuthPassport(validate = true)
@RequestMapping(value = "list", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> list(HttpServletRequest request, @RequestBody JSONObject json) {
    Map<String, Object> ret = new HashMap<String, Object>();
    UserVo userVo = (UserVo) request.getSession().getAttribute(Constant.HTTP_SESSION_USER_KEY);
    Long orgId = userVo.getDefaultOrgId();
    String keywords = json.getString("keywords");
    String disabled = json.getString("disabled");
    int page = json.getInteger("page") == null ? 0 : json.getInteger("page") - 1;
    int pageSize = json.getInteger("pageSize") == null ? Constant.PAGE_SIZE : json.getInteger("pageSize");
    Page pageData = orgGroupService.listByPage(orgId, keywords, disabled, page, pageSize);
    List<OrgGroupVo> vos = orgGroupService.genVos(pageData.getItems());
    ret.put("collectionSize", pageData.getTotal());
    ret.put("data", vos);
    ret.put("code", Constant.RespCode.SUCCESS.getCode());
    return ret;
}
Also used : UserVo(com.ngtesting.platform.vo.UserVo) RelationOrgGroupUserVo(com.ngtesting.platform.vo.RelationOrgGroupUserVo) HashMap(java.util.HashMap) OrgGroupVo(com.ngtesting.platform.vo.OrgGroupVo) JSONObject(com.alibaba.fastjson.JSONObject) Page(com.ngtesting.platform.vo.Page) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 9 with Page

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

the class DocumentAction method list.

@AuthPassport(validate = true)
@RequestMapping(value = "list", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> list(HttpServletRequest request, @RequestBody JSONObject json) {
    Map<String, Object> ret = new HashMap<String, Object>();
    long eventId = json.getLong("eventId");
    int page = json.getInteger("page") == null ? 0 : json.getInteger("page") - 1;
    int pageSize = json.getInteger("pageSize") == null ? Constant.PAGE_SIZE : json.getInteger("pageSize");
    Page pageData = documentService.listByPage(eventId, page, pageSize, null);
    List<DocumentVo> vos = documentService.genVos(pageData.getItems());
    ret.put("collectionSize", pageData.getTotal());
    ret.put("data", vos);
    ret.put("code", Constant.RespCode.SUCCESS.getCode());
    return ret;
}
Also used : HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) Page(com.ngtesting.platform.vo.Page) DocumentVo(com.ngtesting.platform.vo.DocumentVo) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 10 with Page

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

the class SysRoleAction method list.

@AuthPassport(validate = true)
@RequestMapping(value = "list", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> list(HttpServletRequest request, @RequestBody JSONObject json) {
    Map<String, Object> ret = new HashMap<String, Object>();
    UserVo userVo = (UserVo) request.getSession().getAttribute(Constant.HTTP_SESSION_USER_KEY);
    Long orgId = json.getLong("orgId");
    String keywords = json.getString("keywords");
    String disabled = json.getString("disabled");
    int page = json.getInteger("page") == null ? 0 : json.getInteger("page") - 1;
    int pageSize = json.getInteger("pageSize") == null ? Constant.PAGE_SIZE : json.getInteger("pageSize");
    Page pageData = roleService.listByPage(orgId, keywords, disabled, page, pageSize);
    List<RoleVo> vos = roleService.genVos(pageData.getItems());
    ret.put("collectionSize", pageData.getTotal());
    ret.put("data", vos);
    ret.put("code", Constant.RespCode.SUCCESS.getCode());
    return ret;
}
Also used : RoleVo(com.ngtesting.platform.vo.RoleVo) UserVo(com.ngtesting.platform.vo.UserVo) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) Page(com.ngtesting.platform.vo.Page) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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