Пример #1
0
  @Override
  protected Resultable querySelectionsResult(
      QueryFactory queryFactory, int rows, int page, String[] selections, Order order) {
    String hql =
        "From MsgSend As m Where m.userName=:userName And m.id In (:id) Order By m.sendTime Desc, m.id Desc";
    String countHql =
        "Select count(m.id) From MsgSend As m Where m.userName=:userName And m.id In (:id) ";

    HqlQueryable query = queryFactory.createHqlQuery(hql, countHql);

    query.setParameter("id", getIds(Long.class));
    query.setParameter("userName", EwcmsContextUtil.getUserName());

    setDateFormat(DATE_FORMAT);

    return query.setRow(rows).setPage(page).queryResult();
  }
Пример #2
0
  @Override
  protected Resultable queryResult(
      QueryFactory queryFactory, String cacheKey, int rows, int page, Order order) {
    String hql = "From MsgSend As m Where m.userName=:userName ";
    String countHql = "Select count(m.id) From MsgSend As m Where m.userName=:userName ";

    Long id = getParameterValue(Long.class, "id", "查询编号错误,应该是整型");
    if (isNotNull(id)) {
      hql += " And m.id=:id ";
      countHql += " And m.id=:id";
    }
    String title = getParameterValue(String.class, "title", "");
    if (isStringNotEmpty(title)) {
      hql += " And m.title Like :title";
      countHql += " And m.title Like :title";
    }
    String sendTimeStart = getParameterValue(String.class, "sendTimeStart", "");
    if (isStringNotEmpty(sendTimeStart)) {
      hql += " And m.sendTime>=:sendTimeStart";
      countHql += " And m.sendTime>=:sendTimeStart";
    }
    String sendTimeEnd = getParameterValue(String.class, "sendTimeEnd", "");
    if (isStringNotEmpty(sendTimeEnd)) {
      hql += " And m.sendTime<=:sendTimeEnd";
      countHql += " And m.sendTime<=:sendTimeEnd";
    }
    String type = getParameterValue(String.class, "type", "");
    if (isStringNotEmpty(type) && !type.equals("-1")) {
      hql += " And m.type=:type";
      countHql += " And m.type=:type";
    }

    hql += " Order By m.sendTime Desc, m.id Desc";

    HqlQueryable query = queryFactory.createHqlQuery(hql, countHql);
    if (isNotNull(id)) {
      query.setParameter("id", id);
    }
    if (isStringNotEmpty(title)) {
      query.setParameter("title", "%" + title + "%");
    }
    if (isStringNotEmpty(sendTimeStart)) {
      try {
        query.setParameter("sendTimeStart", DATE_FORMAT.parse(sendTimeStart));
      } catch (ParseException e) {
        e.printStackTrace();
      }
    }
    if (isStringNotEmpty(sendTimeEnd)) {
      try {
        query.setParameter("sendTimeEnd", DATE_FORMAT.parse(sendTimeEnd));
      } catch (ParseException e) {
        e.printStackTrace();
      }
    }
    if (isStringNotEmpty(type) && !type.equals("-1")) {
      query.setParameter("type", Type.valueOf(type));
    }

    query.setParameter("userName", EwcmsContextUtil.getUserName());

    setDateFormat(DATE_FORMAT);

    return query.setRow(rows).setPage(page).queryCacheResult(cacheKey);
  }