Пример #1
0
  /**
   * 获取热销宝贝数据
   *
   * @param catNo
   * @param startMonth
   * @param endMonth
   * @param shopType
   * @param pageParam
   * @return
   * @throws Exception
   */
  public PageEntity<HotGoods> getHotGoods(
      String uid,
      String catNo,
      String startMonth,
      String endMonth,
      String shopType,
      PageParam pageParam,
      String flag,
      String catPath)
      throws Exception {

    String catNoIns = "";
    if ("ind".equals(flag)) {
      Map<String, Object> leaf = this.getLeafListByCatPath2(catPath);
      catNoIns = StringUtils.strIn(leaf.get("leafNo").toString());
    } else if ("brand".equals(flag)) {
      catNoIns = catNo;
    }

    StringBuffer sb = new StringBuffer();

    List<Object> params = new ArrayList<Object>();
    params.add(startMonth);
    params.add(endMonth);

    sb.append(
            " select (@rowNum:=@rowNum+1) as rowNum,concat_ws(',',tt2.shop_id, tt2.item_id) as asid, tt1.* from (")
        .append(
            " select t2.prd_img,t2.prd_name,t1.avg_price, round(avg(t1.avg_price_tran),2) as avg_price_tran,sum(t1.sales_volume) as sales_volume,sum(t1.sales_amount) as sales_amount,")
        .append(
            " sum(t1.tran_count) as tran_count,t1.shop_name,t1.shop_id,t1.shop_type,t2.region,t2.item_id from  tbdaily.tb_tran_month t1 ")
        .append(
            " join tbbase.tb_base_product t2 on t1.shop_id = t2.shop_id and t1.item_id = t2.item_id")
        .append(
            " where 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(" and t2.cat_no in (" + catNoIns + ") GROUP BY t2.item_id");

    String pageSql = pageParam.buildSql(sb.toString());

    pageSql += " limit 0, 100";

    pageSql +=
        ") tt1"
            + " left join (select a1.shop_id, a1.item_id from tbweb.tb_attn_dir_detail a1 join tbweb.tb_attn_dir a2 on a2.adid = a1.adid"
            + " where a2.uid = ? group by a1.shop_id, a1.item_id)  tt2 on tt1.shop_id = tt2.shop_id and tt1.item_id = tt2.item_id ,(Select (@rowNum :=0) ) tt ";

    params.add(uid);

    List<HotGoods> list = sqlUtil.searchList(HotGoods.class, pageSql, params.toArray());

    return PageEntity.getPageEntity(pageParam, list);
  }
Пример #2
0
  /**
   * 热销店铺
   *
   * @param catNo
   * @param startMonth
   * @param endMonth
   * @param shopType
   * @param pageParam
   * @return
   * @throws Exception
   */
  public PageEntity<HotShop> getHotShops(
      String uid,
      String catNo,
      String startMonth,
      String endMonth,
      String shopType,
      PageParam pageParam,
      String flag)
      throws Exception {

    String catNoIns = "";
    if ("ind".equals(flag)) {
      Map<String, Object> leaf = this.getLeafListByCatNo2(catNo);
      catNoIns = StringUtils.strIn(leaf.get("leafNo").toString());
    } else if ("brand".equals(flag)) {
      catNoIns = catNo;
    }

    StringBuffer sb = new StringBuffer();

    List<Object> params = new ArrayList<Object>();
    params.add(startMonth);
    params.add(endMonth);

    sb.append("select (@rowNum:=@rowNum+1) as rowNum, tt2.asid, tt1.* from (")
        .append(
            " select t4.shop_name,t4.shop_img,t4.region,t3.sales_volume,t3.sales_amount,t3.tran_count,t3.shop_id,t4.shop_type from (")
        .append(
            " select t1.shop_id,sum(t1.sales_volume) as sales_volume,sum(t1.sales_amount) as sales_amount,")
        .append(" sum(t1.tran_count) as tran_count from  tbdaily.tb_tran_month t1")
        .append(
            " join tbbase.tb_base_product t2 on t1.shop_id = t2.shop_id and t1.item_id = t2.item_id")
        .append(
            " where 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(" and t1.cat_no in (" + catNoIns + ") group by t1.shop_id)")
        .append(" t3 join tbbase.tb_base_shop t4 on t3.shop_id = t4.shop_id GROUP BY t3.shop_id");

    String pageSql = pageParam.buildSql(sb.toString());

    pageSql += " limit 0, 100";

    pageSql +=
        ") tt1"
            + "  left join tbweb.tb_attn_shop tt2 on tt1.shop_id = tt2.shop_id and tt2.uid = ? and tt2.att_type = 1,(Select (@rowNum :=0) ) tt";

    params.add(uid);

    List<HotShop> list = sqlUtil.searchList(HotShop.class, pageSql, params.toArray());

    return PageEntity.getPageEntity(pageParam, list);
  }
Пример #3
0
  /**
   * 获取属性规模数据
   *
   * @param catNo
   * @param startMonth
   * @param endMonth
   * @param shopType
   * @param pageParam
   * @param propName
   * @return
   * @throws Exception
   */
  public List<CatData> getPropScale(
      String catNo,
      String startMonth,
      String endMonth,
      String shopType,
      PageParam pageParam,
      String propName,
      String chartWay)
      throws Exception {
    StringBuffer sb = new StringBuffer();

    List<Object> params = new ArrayList<Object>();

    params.add(propName);
    params.add(catNo);
    if (StringUtils.isNotBlank(startMonth)) {
      params.add(startMonth);
    } else {
      params.add(DateUtils.getCurMonth());
    }

    if (StringUtils.isNotBlank(endMonth)) {
      params.add(endMonth);
    } else {
      params.add(DateUtils.getCurMonth());
    }

    sb.append(
            "select t1.prop_value as cat_name,sum(t1.sales_volume) as sales_volume,sum(t1.sales_amount) as sales_amount,")
        .append(" sum(t1.tran_count) as tran_count 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 (StringUtils.isNotBlank(shopType)) {
      if (!"ALL".equals(shopType)) {
        sb.append(" and t1.shop_type = ?");
        params.add(shopType);
      }
    } else {
      sb.append(" and t1.shop_type = ?");
      params.add(FinalConstants.DEFAULT_SHOP_TYPE);
    }

    sb.append(" group by t1.prop_value");

    String pageSql = "";
    if (pageParam != null) {

      if (StringUtils.isNotBlank(chartWay)) {
        if ("volume".equals(chartWay)) {
          pageParam.setOrderColumn("sum(t1.sales_volume)");
        } else if ("amount".equals(chartWay)) {
          pageParam.setOrderColumn("sum(t1.sales_amount)");
        } else if ("count".equals(chartWay)) {
          pageParam.setOrderColumn("sum(t1.tran_count)");
        }
        pageParam.setOrderDir("desc");
      }

      pageSql = pageParam.buildSql(sb.toString());
    } else {

      if (StringUtils.isNotBlank(chartWay)) {
        if ("volume".equals(chartWay)) {
          pageSql = sb.append(" order by sum(t1.sales_volume) desc").toString();
        } else if ("amount".equals(chartWay)) {
          pageSql = sb.append(" order by sum(t1.sales_amount) desc").toString();
        } else if ("count".equals(chartWay)) {
          pageSql = sb.append(" order by sum(t1.tran_count) desc").toString();
        }
      }

      pageSql = sb.toString();
    }

    pageSql += " limit 0,20";

    List<CatData> list = sqlUtil.searchList(CatData.class, pageSql, params.toArray());

    // 统计占比
    double salesAmountTotal = 0, salesVolumeTotal = 0, tranCountTotal = 0;
    for (CatData catData : list) {

      salesAmountTotal += StringUtils.toDouble(catData.getSales_amount());
      salesVolumeTotal += StringUtils.toDouble(catData.getSales_volume());
      tranCountTotal += StringUtils.toDouble(catData.getTran_count());
    }

    for (CatData catData : list) {

      catData.setAmountWeight(
          StringUtils.formatPercent(
              StringUtils.toDouble(catData.getSales_amount()) / salesAmountTotal));
      catData.setCountWeight(
          StringUtils.formatPercent(
              StringUtils.toDouble(catData.getTran_count()) / tranCountTotal));
      catData.setVolumeWeight(
          StringUtils.formatPercent(
              StringUtils.toDouble(catData.getSales_volume()) / salesVolumeTotal));
    }

    return list;
  }
Пример #4
0
  /**
   * 统计类目的销量、销售额、成交次数
   *
   * @param leafList
   * @param startMonth
   * @param endMonth
   * @param shopType
   * @param pageParam
   * @return
   */
  private List<CatData> getCatDataByMonths(
      List<Map<String, Object>> leafList,
      String startMonth,
      String endMonth,
      String shopType,
      PageParam pageParam,
      String chartWay) {

    StringBuffer sb = new StringBuffer();

    sb.append(
        "select t2.cat_no,t3.cat_name,t2.sales_volume, round(t2.sales_volume/sum(t2.sales_volume)*100,2) as volumeWeight,t2.sales_amount, round(t2.sales_amount/sum(t2.sales_amount)*100,2) as amountWeight,t2.tran_count, round(t2.tran_count/sum(t2.tran_count)*100,2) as countWeight from (");

    if (StringUtils.isBlank(startMonth)) {
      startMonth = DateUtils.getCurMonth();
    }
    if (StringUtils.isBlank(endMonth)) {
      endMonth = DateUtils.getCurMonth();
    }
    if (StringUtils.isBlank(shopType)) {
      shopType = FinalConstants.DEFAULT_SHOP_TYPE;
    }

    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, ifnull(sum(t1.sales_volume),0) as sales_volume,ifnull(sum(t1.sales_amount),0) as sales_amount,ifnull(sum(t1.tran_count),0) as tran_count 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 group by t2.cat_no");

    String pageSql = "";
    if (pageParam != null) {

      if (StringUtils.isNotBlank(chartWay)) {
        pageParam.setoTag("t2");
        if ("volume".equals(chartWay)) {
          pageParam.setOrderColumn("sales_volume");
        } else if ("amount".equals(chartWay)) {
          pageParam.setOrderColumn("sales_amount");
        } else if ("count".equals(chartWay)) {
          pageParam.setOrderColumn("tran_count");
        }
        pageParam.setOrderDir("desc");
      }

      pageSql = pageParam.buildSql(sb.toString());

    } else {

      if (StringUtils.isNotBlank(chartWay)) {
        if ("volume".equals(chartWay)) {
          pageSql = sb.append(" order by t2.sales_volume desc").toString();
        } else if ("amount".equals(chartWay)) {
          pageSql = sb.append(" order by t2.sales_amount desc").toString();
        } else if ("count".equals(chartWay)) {
          pageSql = sb.append(" order by t2.tran_count desc").toString();
        }

      } else {
        pageSql = sb.append(" order by t3.cat_name_single desc").toString();
      }
    }

    List<CatData> list = sqlUtil.searchList(CatData.class, pageSql);

    return list;
  }