Пример #1
0
  public int loadMarketAppSize(String appName, int categoryId, int topicId, String appStatus) {
    boolean isIn = false;
    List<Integer> ids = new ArrayList<Integer>();
    if (categoryId > 0) {
      AppCategory category =
          (AppCategory)
              getHibernateTemplate().find("from AppCategory a where a.id = " + categoryId).get(0);
      if (category.getParent() == null) {
        isIn = true;
        List<AppCategory> below = category.getAllCategoryBelow();
        for (AppCategory appCategory : below) {
          ids.add(appCategory.getId());
        }
      }
    }

    StringBuilder builder = new StringBuilder();
    builder.append("select count(m.id) from MarketApp m");
    if (topicId > 0) {
      builder.append(" left join m.appTopics a");
    }
    builder.append(" where 1=1");
    if (StringUtils.hasText(appName)) {
      String convertAppName = appName.toUpperCase();
      builder.append(
          " and m.appName like '%"
              + convertAppName
              + "%' or m.pinYingShort like '%"
              + convertAppName
              + "%' or m.pinYingFull like '%"
              + convertAppName
              + "%'");
    }
    if (categoryId > 0) {
      if (isIn) {
        builder.append(" and m.appCategory.id in (" + CHStringUtils.convertListToSQLIn(ids) + ")");
      } else {
        builder.append(" and m.appCategory.id = " + categoryId);
      }
    }
    if (!appStatus.equals("ALL")) {
      builder.append(" and m.appStatus = '" + appStatus + "'");
    }
    if (topicId > 0) {
      builder.append(" and a.id = " + topicId + "");
    }

    Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
    Query query = session.createQuery(builder.toString());

    return ((Long) query.list().get(0)).intValue();
  }
Пример #2
0
  /** ************************************推荐部分*************************************** */
  public List<MarketApp> loadRecommendApps(int categoryId, String appName) {
    List<MarketApp> apps = new ArrayList<MarketApp>();

    boolean isIn = false;
    List<Integer> ids = new ArrayList<Integer>();
    if (categoryId > 0) {
      AppCategory category =
          (AppCategory)
              getHibernateTemplate().find("from AppCategory a where a.id = " + categoryId).get(0);
      if (category.getParent() == null) {
        isIn = true;
        List<AppCategory> below = category.getAllCategoryBelow();
        for (AppCategory appCategory : below) {
          ids.add(appCategory.getId());
        }
      }
    }

    StringBuilder builder = new StringBuilder();
    builder.append("from MarketApp m where 1=1");
    if (StringUtils.hasText(appName)) {
      String convert = appName.toUpperCase();
      builder.append(
          " and (m.appName like '%"
              + appName
              + "%' or m.pinYingShort like '%"
              + convert
              + "%' or m.pinYingFull like '%"
              + convert
              + "%')");
    }
    if (categoryId > 0) {
      if (isIn) {
        builder.append(" and m.appCategory.id in (" + CHStringUtils.convertListToSQLIn(ids) + ")");
      } else {
        builder.append(" and m.appCategory.id = " + categoryId);
      }
    }
    builder.append(" and m.appStatus = 'PASSED' order by m.downloadTimes desc");

    Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
    Query query = session.createQuery(builder.toString());
    query.setMaxResults(20);
    query.setFirstResult(0);

    apps = query.list();
    return apps;
  }