Example #1
0
  /**
   * 封装获取行业趋势的数据业务逻辑
   *
   * @param leafList
   * @param startMonth
   * @param endMonth
   * @param shopType
   * @return
   */
  private List<Map<String, Object>> getIndTrendDatas(
      List<Map<String, Object>> leafList, String startMonth, String endMonth, String shopType) {

    List<String> monthList = DateUtils.getMonthListBetweenDates(startMonth, endMonth);
    StringBuffer colTags = new StringBuffer();
    StringBuffer colTags2 = new StringBuffer();
    StringBuffer colTags3 = new StringBuffer();
    StringBuffer cols = new StringBuffer();
    StringBuffer cols2 = new StringBuffer();
    StringBuffer cols3 = new StringBuffer();
    for (int i = 0; i < monthList.size(); i++) {

      String month = monthList.get(i);

      String cTag = "a" + month.replace("-", "");
      colTags.append(cTag);

      String cTag2 = "b" + month.replace("-", "");
      colTags2.append(cTag2);

      String cTag3 = "c" + month.replace("-", "");
      colTags3.append(cTag3);

      cols.append("ifnull(sum(if(t1.tran_month='")
          .append(month)
          .append("',t1.sales_volume,0)),0) as ")
          .append(cTag);

      cols2
          .append("ifnull(sum(if(t1.tran_month='")
          .append(month)
          .append("',t1.sales_amount,0)),0) as ")
          .append(cTag2);

      cols3
          .append("ifnull(sum(if(t1.tran_month='")
          .append(month)
          .append("',t1.tran_count,0)),0) as ")
          .append(cTag3);

      if (i != monthList.size() - 1) {

        colTags.append(",");
        cols.append(",");

        colTags2.append(",");
        cols2.append(",");

        colTags3.append(",");
        cols3.append(",");
      }
    }

    StringBuffer sb = new StringBuffer();

    sb.append("select t2.cat_no,t3.cat_name,")
        .append(colTags)
        .append(",")
        .append(colTags2)
        .append(",")
        .append(colTags3)
        .append(" from (");

    for (int i = 0; i < leafList.size(); i++) {

      Map<String, Object> leaf = leafList.get(i);

      sb.append("select '")
          .append(leaf.get("cat_no"))
          .append("' as cat_no,")
          .append(cols)
          .append(",")
          .append(cols2)
          .append(",")
          .append(cols3)
          .append(" from tbdaily.tb_tran_month_cat t1")
          .append(" where t1.cat_no in (")
          .append(StringUtils.strIn(leaf.get("leafNo").toString()))
          .append(")")
          .append(
              " and str_to_date(t1.tran_month,'%Y-%m') between str_to_date('"
                  + startMonth
                  + "', '%Y-%m') and str_to_date('"
                  + endMonth
                  + "', '%Y-%m') ");

      if (!"ALL".equals(shopType)) {
        sb.append(" and t1.shop_type = '" + shopType + "'");
      }

      if (i != leafList.size() - 1) {
        sb.append(" union all ");
      }
    }

    sb.append(
        " ) t2 left join tbbase.tb_base_cat_api t3 on t2.cat_no = t3.cat_no order by t3.cat_name_single");

    return sqlUtil.searchList(sb.toString());
  }
Example #2
0
  /**
   * 属性趋势(TOP20)
   *
   * @param catNo
   * @param startMonth
   * @param endMonth
   * @param shopType
   * @param propName
   * @return
   */
  public List<Map<String, Object>> getPropTrend(
      String catNo, String startMonth, String endMonth, String shopType, String propName) {
    List<String> monthList = DateUtils.getMonthListBetweenDates(startMonth, endMonth);
    StringBuffer colTags = new StringBuffer();
    StringBuffer colTags2 = new StringBuffer();
    StringBuffer colTags3 = new StringBuffer();
    StringBuffer cols = new StringBuffer();
    StringBuffer cols2 = new StringBuffer();
    StringBuffer cols3 = new StringBuffer();
    for (int i = 0; i < monthList.size(); i++) {

      String month = monthList.get(i);

      String cTag = "a" + month.replace("-", "");
      colTags.append(cTag);

      String cTag2 = "b" + month.replace("-", "");
      colTags2.append(cTag2);

      String cTag3 = "c" + month.replace("-", "");
      colTags3.append(cTag3);

      cols.append("ifnull(sum(if(t1.tran_month='")
          .append(month)
          .append("',t1.sales_volume,0)),0) as ")
          .append(cTag);

      cols2
          .append("ifnull(sum(if(t1.tran_month='")
          .append(month)
          .append("',t1.sales_amount,0)),0) as ")
          .append(cTag2);

      cols3
          .append("ifnull(sum(if(t1.tran_month='")
          .append(month)
          .append("',t1.tran_count,0)),0) as ")
          .append(cTag3);

      if (i != monthList.size() - 1) {

        colTags.append(",");
        cols.append(",");

        colTags2.append(",");
        cols2.append(",");

        colTags3.append(",");
        cols3.append(",");
      }
    }

    StringBuffer sb = new StringBuffer();
    List<Object> params = new ArrayList<Object>();
    params.add(propName);
    params.add(catNo);
    params.add(startMonth);
    params.add(endMonth);
    sb.append("select * from (select t1.prop_value as cat_name,")
        .append(cols)
        .append(",")
        .append(cols2)
        .append(",")
        .append(cols3)
        .append(" from tbdaily.tb_tran_month_prop t1")
        .append(
            " join tbbase.tb_base_cat_prop t2 on t1.cat_no = t2.cat_no and t1.prop_name = t2.prop_name")
        .append(" where t1.prop_name = ? and t1.cat_no = ?")
        .append(
            " and str_to_date(t1.tran_month,'%Y-%m') between str_to_date(?, '%Y-%m') and str_to_date(?, '%Y-%m')");

    if (!"ALL".equals(shopType)) {
      sb.append(" and t1.shop_type = ?");
      params.add(shopType);
    }
    sb.append(" group by t1.prop_value limit 0,20) t");

    return sqlUtil.searchList(sb.toString(), params.toArray());
  }