springBoot+@SelectProvider的用法

package com.yanshu.dao;


import java.util.List;
import java.util.Map;


import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.mockito.internal.stubbing.defaultanswers.ReturnsSmartNulls;


@Mapper
public interface OrdersDao2 {




/**
* 完结特征

* @param map
* @return
*/
// @Select(value = { "\tselect \n" + "\tseller_id,\n" + "\tthedate,\n"
// + "\t convert(decimal(18,4),succ_trade_amt) AS '已收货金额' ,\n" + "\t succ_trade_num AS '交易成功笔数' ,\n"
// + "\t succ_auction_num AS '已收货商品数' ,\n" + "\t\tsucc_refund_trade_amt AS '退款成功金额' ,\n"
// + "\t 1-(case when (alipay_order_num+succ_refund_order_num)=0 then 0 else convert(decimal(18,4),convert(decimal(18,4), succ_refund_order_num/convert(decimal(18,4),(alipay_order_num+succ_refund_order_num))))    end) '七天完结率' from ysf_ShopTrade  "
// + "where seller_id=#{sellerid} and thedate between #{begintime} and #{endtime}" })
@SelectProvider(type=ordersmapper.class,method="findFeature")
List> findFeature(String sellerid, String begintime, String endtime, String platform,String before);
/**

* 支付特征
* @param sellerid 卖家ID
* @param begintime 开始时间
* @param endtime 结束时间
* @param platform 平台ID
* @return
*/
@SelectProvider(type = ordersmapper.class, method = "showpay")
List> showPay(String sellerid, String begintime, String endtime, String platform,String before);


/**
* 下单特征 接口

* @param sellerid
*            卖家ID

* @param begintime
*            开始时间
* @param endtime
*            结束时间
* @param platform
*            平台ID
* @return
*/
@SelectProvider(type = ordersmapper.class, method = "showorders")
List> showorders(String sellerid, String begintime, String endtime, String platform,String before);



/**
* 访客特征
* @param sellerid
* @param begintime
* @param endtime
* @param platform
* @return
*/
@SelectProvider(type=ordersmapper.class,method="showvisitor")
List>  showvisitor(String sellerid, String begintime, String endtime, String platform,String before);





class ordersmapper {

//完结特征
public static String findFeature(String sellerid, String begintime, String endtime, String platform,String before){
StringBuilder sdf=new StringBuilder();
String sql="select sum(e.已收货金额) as Succ_Auction_amt ,  sum(e.交易成功笔数) as Succ_Trade_num, sum(e.已收货商品数) as Succ_Auction_num, sum(e.退款成功金额)as Succ_refund_trade_amt, avg(e.七天完结率)as Order_Over_Rate  from ("+
   " select  seller_id, thedate, convert(decimal(18,4), succ_trade_amt)  AS '已收货金额' , succ_trade_num AS '交易成功笔数 ' , succ_auction_num AS '已收货商品数' , convert(decimal(18,4), succ_refund_trade_amt) AS '退款成功金额' , 1-(case when (alipay_order_num+succ_refund_order_num)=0"+ 
"then 0 else convert(decimal(18,4),convert(decimal(18,4), succ_refund_order_num/convert(decimal(18,4),(alipay_order_num+succ_refund_order_num)))) end) '七天完结率'"+
"from  ysf_ShopTrade ";
sdf.append(sql);
sdf.append("where seller_id="+sellerid+" and thedate between "+begintime+"  and "+endtime+" ) e ");
sdf.append(" union all ");
sdf.append(sql);
sdf.append("where seller_id="+sellerid+" and thedate between "+before+"  and "+begintime+" ) e");

return sdf.toString();
}



//访客特征 (四个指标)
public static String showvisitor(String sellerid, String begintime, String endtime, String platform,String before){
StringBuilder sdf=new StringBuilder();
if("0".equals(platform)){
 
 String sql = "select avg(e.页面到达率) as PageTo_Rate ,avg(e.平均访问深度) as AVGVisit_Depth,avg(e.宝贝收藏率) as Page_Collect_Rate,avg(e.买家加购率) as Add_Cart_Rate from (select a.seller_id,a.thedate,"
+ "case when sum(b.uv)=0 then 0  else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), sum(c.iuv))/ CONVERT(DECIMAL(18, 4), sum(b.uv))) end  AS '页面到达率' ,"
+ " case when sum(b.uv)=0 then 0 else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), sum(c.pv))/ CONVERT(DECIMAL(18, 4), sum(b.uv))) end  AS '平均访问深度',"
+ " case when sum(b.uv)=0 then 0 else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), sum(d.auction_collect_num))/ CONVERT(DECIMAL(18, 4), sum(b.uv))) end  AS '宝贝收藏率',"
+ " case when sum(b.uv)=0 then 0  else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), sum(a.add_cart_user_num))/ CONVERT(DECIMAL(18, 4), sum(b.uv))) end  AS '买家加购率' "
+ "from ysf_AuctionTrade a left join ysf_ShopTraffic b   on a.seller_id=b.seller_id and a.thedate=b.thedate "
+ "left join ysf_ShopPlatformRegionView c on a.seller_id=c.seller_id and a.thedate=c.thedate left join  ysf_AuctionCollect d on a.seller_id=d.seller_id and a.thedate=d.thedate";
  sdf.append(sql);
  sdf.append(" where a.seller_id="+sellerid+" and a.thedate between "+begintime+" and "+endtime+" and c.visit_platform in (1,2)    group by a.seller_id,a.thedate ) e");
  sdf.append(" union all ");
  sdf.append(sql);
  sdf.append(" where a.seller_id="+sellerid+" and a.thedate between "+before+" and "+begintime+" and c.visit_platform in (1,2)    group by a.seller_id,a.thedate ) e");
}
else {
String sql = "select avg(e.页面到达率) as PageTo_Rate,avg(e.平均访问深度) as AVGVisit_Depth,avg(e.宝贝收藏率) as Page_Collect_Rate,avg(e.买家加购率) as Add_Cart_Rate  from (select a.seller_id,a.thedate,"
+ "case when sum(b.uv)=0 then 0  else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), sum(c.iuv))/ CONVERT(DECIMAL(18, 4), sum(b.uv))) end  AS '页面到达率' ,"
+ " case when sum(b.uv)=0 then 0 else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), sum(c.pv))/ CONVERT(DECIMAL(18, 4), sum(b.uv))) end  AS '平均访问深度',"
+ " case when sum(b.uv)=0 then 0 else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), sum(d.auction_collect_num))/ CONVERT(DECIMAL(18, 4), sum(b.uv))) end  AS '宝贝收藏率',"
+ " case when sum(b.uv)=0 then 0  else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), sum(a.add_cart_user_num))/ CONVERT(DECIMAL(18, 4), sum(b.uv))) end  AS '买家加购率' "
+ "from ysf_AuctionTrade a left join ysf_ShopTraffic b   on a.seller_id=b.seller_id and a.thedate=b.thedate "
+ "left join ysf_ShopPlatformRegionView c on a.seller_id=c.seller_id and a.thedate=c.thedate left join  ysf_AuctionCollect d on a.seller_id=d.seller_id and a.thedate=d.thedate";
  sdf.append(sql);
sdf.append(" where a.seller_id="+sellerid+" and a.thedate between "+begintime+" and "+endtime+" and c.visit_platform="+platform+" group by a.seller_id,a.thedate ) e");
 sdf.append(" union all  ");
sdf.append(sql);
sdf.append(" where a.seller_id="+sellerid+" and a.thedate between "+before+" and "+begintime+" and c.visit_platform="+platform+" group by a.seller_id,a.thedate ) e");

}
return sdf.toString();
  }
            
// 支付特征
public static String showpay(String sellerid, String begintime, String endtime, String platform,String before) {

StringBuilder sdf = new StringBuilder();
if("0".equals(platform)){

String sql = "select sum(a.店铺成交金额) as Pay_ord_amt, avg(a.订单支付率) as Gmv_pay_Rate, avg(a.拍下支付率) as Pay_ord_Rate, avg(a.支付客单价) as Payord_Auction_amt, avg(a.支付客单件) as Payord_Auction_num "+
" from (select  seller_id,thedate,sum(convert(decimal(18,4),alipay_trade_amt)) as 店铺成交金额 ," +


"  case when sum(gmv_trade_amt)=0 then 0 else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), sum(alipay_trade_amt))/ CONVERT(DECIMAL(18, 4), sum(gmv_trade_amt))) end  AS 拍下支付率,"
+


"case when sum(gmv_trade_num) =0 then 0  else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), sum(alipay_trade_num))/ CONVERT(DECIMAL(18, 4), sum(gmv_trade_num))) end  AS 订单支付率 ,"
+


"case when sum(alipay_winner_num )=0 then 0 else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), sum(alipay_auction_num))/ CONVERT(DECIMAL(18, 4), sum(alipay_winner_num ))) end  AS 支付客单件,"
+ "case when  sum(alipay_winner_num )=0 then 0  else CONVERT(DECIMAL(18, 2), CONVERT(DECIMAL(18, 2), sum(alipay_trade_amt))/ CONVERT(DECIMAL(18, 2), sum(alipay_winner_num ))) end  AS 支付客单价"
+
" from ysf_ShopPlatformRegionTrade ";
sdf.append(sql);
sdf.append(" where seller_id=" + sellerid + " and   thedate between " + begintime + "  and " + endtime + "");
sdf.append(" and gmv_platform in (1,2) group by seller_id, thedate ) a");

sdf.append(" union  all ");

sdf.append(sql);
sdf.append(" where seller_id=" + sellerid + " and   thedate between " + before + "  and " + begintime + "");
sdf.append(" and gmv_platform in (1,2) group by seller_id, thedate ) a");

}

else {
 
String sql = "select sum(a.店铺成交金额) as Pay_ord_amt , avg(a.订单支付率) as Gmv_pay_Rate, avg(a.拍下支付率) as Pay_ord_Rate, avg(a.支付客单价) as Payord_Auction_amt, avg(a.支付客单件) as Payord_Auction_num"+
" from (select  seller_id,thedate,sum(convert(decimal(18,4),alipay_trade_amt)) as 店铺成交金额 ," +


"  case when sum(gmv_trade_amt)=0 then 0 else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), sum(alipay_trade_amt))/ CONVERT(DECIMAL(18, 4), sum(gmv_trade_amt))) end  AS 拍下支付率,"
+


"case when sum(gmv_trade_num) =0 then 0  else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), sum(alipay_trade_num))/ CONVERT(DECIMAL(18, 4), sum(gmv_trade_num))) end  AS 订单支付率 ,"
+


"case when sum(alipay_winner_num )=0 then 0 else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), sum(alipay_auction_num))/ CONVERT(DECIMAL(18, 4), sum(alipay_winner_num ))) end  AS 支付客单件,"
+ "case when  sum(alipay_winner_num )=0 then 0  else CONVERT(DECIMAL(18, 2), CONVERT(DECIMAL(18, 2), sum(alipay_trade_amt))/ CONVERT(DECIMAL(18, 2), sum(alipay_winner_num ))) end  AS 支付客单价"
+
" from ysf_ShopPlatformRegionTrade ";
sdf.append(sql);
sdf.append(" where seller_id=" + sellerid + " and   thedate between " + begintime + "  and " + endtime + "");
  sdf.append(" and gmv_platform = " + platform + " group by seller_id, thedate ) a");
  
  sdf.append(" union  all ");

sdf.append(sql);
sdf.append(" where seller_id=" + sellerid + " and   thedate between " + before + "  and " + begintime + "");
 sdf.append(" and gmv_platform = " + platform + " group by seller_id, thedate ) a");
}


return sdf.toString();
}


// 下单特征
public static String showorders(String sellerid, String begintime, String endtime, String platform,String before) {


String sql = "";
StringBuilder sdf = new StringBuilder();
if ("0".equals(platform)) {
String sqls="select  sum(c.店铺拍下笔数) as  Gmv_Trade_num,sum(c.店铺拍下金额) as Gmv_Trade_amt, avg(下单客单件)as Crtord_Auction_num,avg(下单客单价)as Crtord_Auction_amt,avg(店铺下单率)as Crtord_Rate  from (";
sdf.append(sqls);
sql = "select a.seller_id,a.thedate," + "sum(CONVERT(DECIMAL(18, 4),a.alipay_trade_num)) as  店铺拍下笔数,"
+ "sum(CONVERT(DECIMAL(18, 4),a.gmv_trade_amt)) as 店铺拍下金额,"
+ "sum(case when   b.uv = 0  then 0 else  CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), a.gmv_order_num)/ CONVERT(DECIMAL(18, 4), b.uv)) end ) AS 店铺下单率,"
+ "sum(case when a.gmv_winner_num=0 then 0 else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), a.gmv_auction_num)/ CONVERT(DECIMAL(18, 4), a.gmv_winner_num)) end ) AS 下单客单件 ,"
+ "sum(case when a.gmv_winner_num=0 then 0  else CONVERT(DECIMAL(18, 2), CONVERT(DECIMAL(18, 2), a.gmv_trade_amt)/ CONVERT(DECIMAL(18, 2), a.gmv_winner_num)) end ) AS 下单客单价";


sdf.append(sql);
sdf.append(
"  from ysf_ShopPlatformTrade a left join ysf_ShopTraffic b on a.seller_id=b.seller_id and a.thedate=b.thedate where a.seller_id="
+ sellerid + " and a.thedate between " + begintime + "  and " + endtime + " ");
sdf.append("   and a.gmv_platform in (1,2)   group by  a.seller_id ,a. thedate ) c");

sdf.append(" union all ");

sdf.append(sqls);
sql = "select a.seller_id,a.thedate," + "sum(CONVERT(DECIMAL(18, 4),a.alipay_trade_num)) as  店铺拍下笔数,"
+ "sum(CONVERT(DECIMAL(18, 4),a.gmv_trade_amt)) as 店铺拍下金额,"
+ "sum(case when   b.uv = 0  then 0 else  CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), a.gmv_order_num)/ CONVERT(DECIMAL(18, 4), b.uv)) end ) AS 店铺下单率,"
+ "sum(case when a.gmv_winner_num=0 then 0 else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), a.gmv_auction_num)/ CONVERT(DECIMAL(18, 4), a.gmv_winner_num)) end ) AS 下单客单件 ,"
+ "sum(case when a.gmv_winner_num=0 then 0  else CONVERT(DECIMAL(18, 2), CONVERT(DECIMAL(18, 2), a.gmv_trade_amt)/ CONVERT(DECIMAL(18, 2), a.gmv_winner_num)) end ) AS 下单客单价";


sdf.append(sql);
sdf.append(
"  from ysf_ShopPlatformTrade a left join ysf_ShopTraffic b on a.seller_id=b.seller_id and a.thedate=b.thedate where a.seller_id="
+ sellerid + " and a.thedate between " + before + "  and " + begintime + " ");
sdf.append("   and a.gmv_platform in (1,2)   group by  a.seller_id ,a. thedate ) c");


} else {
// String sqls="select  sum(c.店铺拍下笔数) as  Gmv_Trade_num,sum(c.店铺拍下金额) as Gmv_Trade_amt, avg(下单客单件)as Crtord_Auction_num,avg(下单客单价)as Crtord_Auction_amt,avg(店铺下单率)as Crtord_Rate  from (";
String sqls="select  sum(c.店铺拍下笔数) as  Gmv_Trade_num,sum(c.店铺拍下金额) as Gmv_Trade_amt, avg(下单客单件)as Crtord_Auction_num,avg(下单客单价)as  Crtord_Auction_amt,avg(店铺下单率)as Crtord_Rate from (";
sdf.append(sqls);
sql = "select a.seller_id,a.thedate," + "sum(CONVERT(DECIMAL(18, 4),a.alipay_trade_num)) as  店铺拍下笔数,"
+ "sum(CONVERT(DECIMAL(18, 4),a.gmv_trade_amt)) as 店铺拍下金额,"
+ "sum(case when   b.uv = 0  then 0 else  CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), a.gmv_order_num)/ CONVERT(DECIMAL(18, 4), b.uv)) end ) AS 店铺下单率,"
+ "sum(case when a.gmv_winner_num=0 then 0 else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), a.gmv_auction_num)/ CONVERT(DECIMAL(18, 4), a.gmv_winner_num)) end ) AS 下单客单件 ,"
+ "sum(case when a.gmv_winner_num=0 then 0  else CONVERT(DECIMAL(18, 2), CONVERT(DECIMAL(18, 2), a.gmv_trade_amt)/ CONVERT(DECIMAL(18, 2), a.gmv_winner_num)) end ) AS 下单客单价";


sdf.append(sql);
sdf.append(
"  from ysf_ShopPlatformTrade a left join ysf_ShopTraffic b on a.seller_id=b.seller_id and a.thedate=b.thedate where a.seller_id="
+ sellerid + " and a.thedate between " + begintime + "  and " + endtime + " ");
sdf.append("   and a.gmv_platform = "+platform+"  group by  a.seller_id ,a. thedate ) c");


sdf.append(" union all ");

sdf.append(sqls);
sql = "select a.seller_id,a.thedate," + "sum(CONVERT(DECIMAL(18, 4),a.alipay_trade_num)) as  店铺拍下笔数,"
+ "sum(CONVERT(DECIMAL(18, 4),a.gmv_trade_amt)) as 店铺拍下金额,"
+ "sum(case when   b.uv = 0  then 0 else  CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), a.gmv_order_num)/ CONVERT(DECIMAL(18, 4), b.uv)) end ) AS 店铺下单率,"
+ "sum(case when a.gmv_winner_num=0 then 0 else CONVERT(DECIMAL(18, 4), CONVERT(DECIMAL(18, 4), a.gmv_auction_num)/ CONVERT(DECIMAL(18, 4), a.gmv_winner_num)) end ) AS 下单客单件 ,"
+ "sum(case when a.gmv_winner_num=0 then 0  else CONVERT(DECIMAL(18, 2), CONVERT(DECIMAL(18, 2), a.gmv_trade_amt)/ CONVERT(DECIMAL(18, 2), a.gmv_winner_num)) end ) AS 下单客单价";


sdf.append(sql);
sdf.append(
"  from ysf_ShopPlatformTrade a left join ysf_ShopTraffic b on a.seller_id=b.seller_id and a.thedate=b.thedate where a.seller_id="
+ sellerid + " and a.thedate between " + before + "  and " + begintime + " ");
sdf.append("   and a.gmv_platform ="+platform+"   group by  a.seller_id ,a. thedate ) c");



}
return sdf.toString();
}
}


public static void main(String[] args) {


String showorders = ordersmapper.findFeature("1036319921", "20161213", "20161220", "0","20161206");


System.out.println("showorders=" + showorders);


}


}

你可能感兴趣的:(springboot)