Explorar el Código

睿选首页 添加roi查询,和分时数据

zhaoxian hace 9 meses
padre
commit
650aeb3d38

+ 61 - 1
ruixuan-common/src/main/java/com/ruixuan/common/utils/DateUtils.java

@@ -302,6 +302,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
         date.setTime(timestamp);
         return DateFormatUtils.format(date, YYYYMMDD);
     }
+
     /**
      * 时间戳转换为字符串
      *
@@ -334,6 +335,26 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
         String nowTime = sdf.format(rightNowTime);
         return nowTime;
     }
+    /**
+     * 返回 日期-天数 的string 日期
+     *
+     * @param time        时间
+     * @param daysBetween 天数
+     * @return
+     */
+    public static String getSubtractTime2(Date time, Integer daysBetween) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar rightNow = Calendar.getInstance();
+        rightNow.setTime(time);
+        if (daysBetween.intValue() > 0) {
+            rightNow.add(Calendar.DAY_OF_YEAR, -daysBetween.intValue() - 1);
+        } else {
+            rightNow.add(Calendar.DAY_OF_YEAR, -1);//日期 -1
+        }
+        Date rightNowTime = rightNow.getTime();
+        String nowTime = sdf.format(rightNowTime);
+        return nowTime;
+    }
 
 
     /**
@@ -529,7 +550,46 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
         return null;
     }
 
+    /**
+     * 根据本阶段日期 获取上阶段 开始 和 截至 日期
+     *
+     * @param startTime 本阶段开始时间
+     * @param endTime   本阶段截至时间
+     * @return
+     * @throws ParseException
+     */
+    public static Map<String, String> getStartEndTime(String startTime, String endTime) {
+        Map<String, String> timeMap = new HashMap();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Date start = null;
+        Date end = null;
+        try {
+            start = sdf.parse(startTime);
+            end = sdf.parse(endTime);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        //相差天数
+        Long daysBetween = (end.getTime() - start.getTime()) / (60 * 60 * 24 * 1000);
+        String lastTimeStart = getSubtractTime2(start, daysBetween.intValue());
+        String lastTimeEnd = getSubtractTime2(end, daysBetween.intValue());
+        timeMap.put("lastTimeStart", lastTimeStart);
+        timeMap.put("lastTimeEnd", lastTimeEnd);
+        timeMap.put("daysBetween", daysBetween.toString());
+        return timeMap;
+    }
+
     public static void main(String[] args) {
-        System.out.println(timestamptoMinutesAndSecondsStr(1661851245589L));
+
+        Map<String, String> map = getStartEndTime("2024-09-12", "2024-09-18");
+        //下个周期的开始时间
+        String lastTimeStart = map.get("lastTimeStart");
+        //下个周期的结束时间
+        String lastTimeEnd = map.get("lastTimeEnd");
+        System.out.println(map);
+        System.out.println(lastTimeStart);
+        System.out.println(lastTimeEnd);
+
+
     }
 }

+ 12 - 4
ruixuan-live/src/main/java/com/ruixuan/isc/mapper/SupplyChainMapper.java

@@ -78,9 +78,9 @@ public interface SupplyChainMapper {
 
     String getCookie(Long regId);
 
-    JSONObject selectOrderInfo(@Param("promoterIds") List<String> promoterIds, @Param("startDate") Long startDate, @Param("endDate") Long endDate);
+    JSONObject selectOrderInfo(Map<String, Object> requestMap);
 
-    JSONObject selectOrderInfoBytedance(@Param("promoterIds") List<String> promoterIds, @Param("startDate") Long startDate, @Param("endDate") Long endDate);
+    JSONObject selectOrderInfoBytedance(Map<String, Object> parMap);
 
     JSONObject selectOrderRate(@Param("promoterIds") List<String> promoterIds, @Param("itemIds") List<Long> itemIds, @Param("statDate") Long statDate, @Param("endDate") Long endDate,@Param("hour") int hour);
 
@@ -92,9 +92,9 @@ public interface SupplyChainMapper {
 
     JSONObject getMonthOrderAmountTotal(Map<String, Object> map);
 
-    JSONObject selectOrderInfoByItemIds(@Param("itemIds") List<Long> itemIds, @Param("startDate") Long startDate, @Param("endDate") Long endDate);
+    JSONObject selectOrderInfoByItemIds(Map<String, Object> requestMap);
 
-    JSONObject selectOrderInfoByItemIdsBytedance(@Param("itemIds") List<Long> itemIds, @Param("startDate") Long startDate, @Param("endDate") Long endDate);
+    JSONObject selectOrderInfoByItemIdsBytedance(Map<String, Object> requestMap);
 
     List<JSONObject> getMonthOrderAmountByItems(Map<String, Object> map);
 
@@ -232,4 +232,12 @@ public interface SupplyChainMapper {
     List<Long> getItemIdsByUserId(@Param("userId") Long userId);
 
     List<Long> getItemIdsByDeptId(@Param("deptId") Long deptId);
+
+    List<JSONObject> getKsChannelGmvHourByDateRoi(@Param("userList") List<Long> userList, @Param("date") Integer date);
+
+    List<JSONObject> getKsCourtshipGmvHourByDateRoi(@Param("userList") List<Long> userList, @Param("date") Integer date);
+
+    List<JSONObject> getBytedanceChannelGmvHourByDateRoi(@Param("userList") List<Long> userList, @Param("date") Long date);
+
+    List<JSONObject> getBytedanceCourtshipGmvHourByDateRoi(@Param("userList") List<Long> userList, @Param("date") Long date);
 }

+ 12 - 4
ruixuan-live/src/main/java/com/ruixuan/isc/service/ISupplyChainService.java

@@ -98,7 +98,7 @@ public interface ISupplyChainService {
     //认领列表导出
     List<JSONObject> exportUserItemDetail(Map<String, Object> requestMap);
 
-    JSONObject selectOrderInfo(List<String> promoterIds, Long startDate, Long endDate);
+    JSONObject selectOrderInfo(Map<String, Object> requestMap);
 
     JSONObject selectOrderRate(List<String> promoterIds, List<Long> itemIds, Long statDate, Long endDate,int hour);
 
@@ -108,7 +108,7 @@ public interface ISupplyChainService {
 
     JSONObject getMonthOrderAmountTotal(Map<String, Object> map);
 
-    JSONObject selectOrderInfoByItemIds(List<Long> itemIds, Long startDate, Long endDate);
+    JSONObject selectOrderInfoByItemIds(Map<String, Object> requestMap);
 
     List<JSONObject> getMonthOrderAmountByItems(Map<String, Object> map);
 
@@ -142,7 +142,7 @@ public interface ISupplyChainService {
 
     List<JSONObject> bdDetailListV2(Map<String, Object> requestMap);
 
-    JSONObject selectOrderInfoByItemIdsBytedance(List<Long> itemIds, Long startDate, Long endDate);
+    JSONObject selectOrderInfoByItemIdsBytedance(Map<String, Object> requestMap);
 
     List<JSONObject> getMonthOrderAmountBytedance(Map<String, Object> map);
 
@@ -160,7 +160,7 @@ public interface ISupplyChainService {
 
     List<JSONObject> getPromoterRatioListBytedance(Map<String, Object> requestMap);
 
-    JSONObject selectOrderInfoBytedance(List<String> promoterIds, Long startDate, Long endDate);
+    JSONObject selectOrderInfoBytedance(Map<String, Object> parMap);
 
     List<JSONObject> bdReportListV2ByBind(Map<String, Object> requestMap);
 
@@ -210,4 +210,12 @@ public interface ISupplyChainService {
     List<Long> getItemIdsByUserId(Long userId);
 
     List<Long> getItemIdsByDeptId(Long deptId);
+
+    List<JSONObject> getKsChannelGmvHourByDateRoi(List<Long> userList, Integer nowDate);
+
+    List<JSONObject> getKsCourtshipGmvHourByDateRoi(List<Long> userList, Integer nowDate);
+
+    List<JSONObject> getBytedanceChannelGmvHourByDateRoi(List<Long> userList, Long dataNow);
+
+    List<JSONObject> getBytedanceCourtshipGmvHourByDateRoi(List<Long> userList, Long dataNow);
 }

+ 62 - 10
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/KuaishouItemCollectSamplesServiceImpl.java

@@ -462,22 +462,45 @@ public class KuaishouItemCollectSamplesServiceImpl implements IKuaishouItemColle
         data.put("completeRate", sample.getString("completeRate"));//合格作业率
         JSONObject order = new JSONObject();
 
+        //当前小时
+        Integer hour2 = DateUtils.getNowHour() - 1;
+        //根据本阶段日期 获取上阶段 开始 和 截至 日期
+        Map<String, String> map = DateUtils.getStartEndTime(startDate, endDate);
+        String daysBetween = map.get("daysBetween");
+        Map<String, Object> parMap = new HashMap<>();
+        if (!"0".equals(daysBetween)) {
+            hour2 = 23;
+        }
+        //下个周期的开始时间
+        String lastTimeStart = map.get("lastTimeStart");
+        //下个周期的结束时间
+        String lastTimeEnd = map.get("lastTimeEnd");
+        parMap.put("promoterIds", promoterIds);
+        parMap.put("startDate", DateUtils.strDateToInt(startDate));
+        parMap.put("endDate", DateUtils.strDateToInt(endDate));
+        parMap.put("lastTimeStart", DateUtils.strDateToInt(lastTimeStart));
+        parMap.put("lastTimeEnd", DateUtils.strDateToInt(lastTimeEnd));
+        parMap.put("hour", hour2);
+
         if ("1".equals(mediaId)) {
-            order = supplyChainService.selectOrderInfoBytedance(promoterIds, DateUtils.strDateToInt(startDate), DateUtils.strDateToInt(endDate));
+            order = supplyChainService.selectOrderInfoBytedance(parMap);
         } else {
-            order = supplyChainService.selectOrderInfo(promoterIds, DateUtils.strDateToInt(startDate), DateUtils.strDateToInt(endDate));
+            order = supplyChainService.selectOrderInfo(parMap);
         }
         data.put("allNumber", order.getLong("allNumber"));//订单总数
         data.put("promoterCount", order.getLong("promoterCount"));//达人总数
         data.put("itemCount", order.getLong("itemCount"));//商品数
+        data.put("orderAmount", order.getLong("orderAmount"));//订单金额
         data.put("validOrderNUm", order.getLong("validOrderNUm"));//有效订单数
+        data.put("validOrderNUmRoi", order.getBigDecimal("validOrderNUmRoi"));//有效订单数ROI
         data.put("inValidOrderNUm", order.getLong("allNumber") - order.getLong("validOrderNUm"));//失效订单数
-        data.put("orderAmount", order.getLong("orderAmount"));//订单金额
+        data.put("inValidOrderNUmRoi", order.getBigDecimal("inValidOrderNUmRoi"));//失效订单数ROI
+        data.put("baseAmount", order.getLong("baseAmount"));//有效订单金额
+        data.put("baseAmountRoi", order.getBigDecimal("baseAmountRoi"));//有效订单金额ROI
         data.put("regimentalPromotionAmount", order.getLong("regimentalPromotionAmount"));//预估服务费
-        data.put("baseAmount", order.getLong("baseAmount"));//累计货贷基数
+        data.put("regimentalPromotionAmountRoi", order.getBigDecimal("regimentalPromotionAmountRoi"));//预估服务费ROI
         if ("1".equals(mediaId)) {
             data.put("secondEstimatedCommission", order.getLong("secondEstimatedCommission"));// 预估服务费支出
-
         }
 
         Date date = new Date();
@@ -582,12 +605,29 @@ public class KuaishouItemCollectSamplesServiceImpl implements IKuaishouItemColle
         List<Long> itemIds = kuaishouItemCollectSamplesMapper.getItemIdsByCreateId(userList, mediaId);
         if (Check.isNotNull(itemIds)) {
             JSONObject order = null;
+            //当前小时
+            Integer hour2 = DateUtils.getNowHour() - 1;
+            //根据本阶段日期 获取上阶段 开始 和 截至 日期
+            Map<String, String> map = DateUtils.getStartEndTime(startDate, endDate);
+            String daysBetween = map.get("daysBetween");
+            Map<String, Object> parMap = new HashMap<>();
+            if (!"0".equals(daysBetween)) {
+                hour2 = 23;
+            }
+            //下个周期的开始时间
+            String lastTimeStart = map.get("lastTimeStart");
+            //下个周期的结束时间
+            String lastTimeEnd = map.get("lastTimeEnd");
+            parMap.put("itemIds", itemIds);
+            parMap.put("startDate", DateUtils.strDateToInt(startDate));
+            parMap.put("endDate", DateUtils.strDateToInt(endDate));
+            parMap.put("lastTimeStart", DateUtils.strDateToInt(lastTimeStart));
+            parMap.put("lastTimeEnd", DateUtils.strDateToInt(lastTimeEnd));
+            parMap.put("hour", hour2);
             if ("1".equals(mediaId)) {
-                Long startHourTemp = DateUtils.strDateToInt(startDate);
-                Long endHourTemp = DateUtils.strDateToInt(endDate);
-                order = supplyChainService.selectOrderInfoByItemIdsBytedance(itemIds, startHourTemp, endHourTemp);
+                order = supplyChainService.selectOrderInfoByItemIdsBytedance(parMap);
             } else {
-                order = supplyChainService.selectOrderInfoByItemIds(itemIds, DateUtils.strDateToInt(startDate), DateUtils.strDateToInt(endDate));
+                order = supplyChainService.selectOrderInfoByItemIds(parMap);
             }
             data.put("sendCount", order.getLong("sendCount"));//发货数
             data.put("sendRate", order.getString("sendRate"));//订单发货率
@@ -595,10 +635,14 @@ public class KuaishouItemCollectSamplesServiceImpl implements IKuaishouItemColle
             data.put("promoterCount", order.getLong("promoterCount"));//达人总数
             data.put("itemCount", order.getLong("itemCount"));//达人总数
             data.put("validOrderNUm", order.getLong("validOrderNUm"));//有效订单数
+            data.put("validOrderNUmRoi", order.getBigDecimal("validOrderNUmRoi"));//有效订单数Roi
             data.put("inValidOrderNUm", order.getLong("allNumber") - order.getLong("validOrderNUm"));//失效订单数
+            data.put("inValidOrderNUmRoi", order.getBigDecimal("inValidOrderNUmRoi"));//失效订单数Roi
             data.put("orderAmount", order.getLong("orderAmount"));//订单金额
             data.put("regimentalPromotionAmount", order.getLong("regimentalPromotionAmount"));//预估服务费
+            data.put("regimentalPromotionAmountRoi", order.getBigDecimal("regimentalPromotionAmountRoi"));//预估服务费Roi
             data.put("baseAmount", order.getLong("baseAmount"));//累计货贷基数
+            data.put("baseAmountRoi", order.getBigDecimal("baseAmountRoi"));//累计货贷基数Roi
 
             Date date = new Date();
             //当前小时
@@ -793,18 +837,23 @@ public class KuaishouItemCollectSamplesServiceImpl implements IKuaishouItemColle
         }
         List<JSONObject> today = new ArrayList<>();
         List<JSONObject> yesterday = new ArrayList<>();
+        List<JSONObject> roi = new ArrayList<>();
         if ("1".equals(type)) { // 渠道
             today = supplyChainService.getKsChannelGmvHourByDate(userList, DateUtils.getIntegerTime(nowDate));
             yesterday = supplyChainService.getKsChannelGmvHourByDate(userList, DateUtils.getIntegerTime(lastDate));
+            roi = supplyChainService.getKsChannelGmvHourByDateRoi(userList, DateUtils.getIntegerTime(nowDate));
         } else if ("2".equals(type)) {
             today = supplyChainService.getKsCourtshipGmvHourByDate(userList, DateUtils.getIntegerTime(nowDate));
             yesterday = supplyChainService.getKsCourtshipGmvHourByDate(userList, DateUtils.getIntegerTime(lastDate));
+            roi = supplyChainService.getKsCourtshipGmvHourByDateRoi(userList, DateUtils.getIntegerTime(nowDate));
         }
         completionTime(today, nowDate);
         completionTime(yesterday, lastDate);
+        completionTime(roi, nowDate);
         JSONObject result = new JSONObject();
         result.put("today", today);
         result.put("yesterday", yesterday);
+        result.put("roi", roi);
         returnJson.put("result", result);
         returnJson.put("success", true);
         returnJson.put("message", "操作成功");
@@ -880,17 +929,20 @@ public class KuaishouItemCollectSamplesServiceImpl implements IKuaishouItemColle
         }
         List<JSONObject> today = new ArrayList<>();
         List<JSONObject> yesterday = new ArrayList<>();
+        List<JSONObject> roi = new ArrayList<>();
         if ("1".equals(type)) { // 渠道
-
             today = supplyChainService.getBytedanceChannelGmvHourByDate(userList, dataNow);
             yesterday = supplyChainService.getBytedanceChannelGmvHourByDate(userList, lastDateNow);
+            roi = supplyChainService.getBytedanceChannelGmvHourByDateRoi(userList, dataNow);
         } else if ("2".equals(type)) {
             today = supplyChainService.getBytedanceCourtshipGmvHourByDate(userList, dataNow);
             yesterday = supplyChainService.getBytedanceCourtshipGmvHourByDate(userList, lastDateNow);
+            roi = supplyChainService.getBytedanceCourtshipGmvHourByDateRoi(userList, dataNow);
         }
         JSONObject result = new JSONObject();
         result.put("today", today);
         result.put("yesterday", yesterday);
+        result.put("roi", roi);
         returnJson.put("result", result);
         returnJson.put("success", true);
         returnJson.put("message", "操作成功");

+ 28 - 8
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/SupplyChainServiceImpl.java

@@ -229,8 +229,8 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
     }
 
     @Override
-    public JSONObject selectOrderInfo(List<String> promoterIds, Long startDate, Long endDate) {
-        return supplyChainMapper.selectOrderInfo(promoterIds, startDate, endDate);
+    public JSONObject selectOrderInfo(Map<String, Object> requestMap) {
+        return supplyChainMapper.selectOrderInfo(requestMap);
     }
 
     @Override
@@ -289,8 +289,8 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
     }
 
     @Override
-    public JSONObject selectOrderInfoBytedance(List<String> promoterIds, Long startDate, Long endDate) {
-        return supplyChainMapper.selectOrderInfoBytedance(promoterIds, startDate, endDate);
+    public JSONObject selectOrderInfoBytedance(Map<String, Object> parMap) {
+        return supplyChainMapper.selectOrderInfoBytedance(parMap);
     }
 
     @Override
@@ -309,8 +309,8 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
     }
 
     @Override
-    public JSONObject selectOrderInfoByItemIds(List<Long> itemIds, Long startDate, Long endDate) {
-        return supplyChainMapper.selectOrderInfoByItemIds(itemIds, startDate, endDate);
+    public JSONObject selectOrderInfoByItemIds(Map<String, Object> requestMap) {
+        return supplyChainMapper.selectOrderInfoByItemIds(requestMap);
     }
 
     @Override
@@ -400,8 +400,8 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
     }
 
     @Override
-    public JSONObject selectOrderInfoByItemIdsBytedance(List<Long> itemIds, Long startDate, Long endDate) {
-        return supplyChainMapper.selectOrderInfoByItemIdsBytedance(itemIds, startDate, endDate);
+    public JSONObject selectOrderInfoByItemIdsBytedance(Map<String, Object> requestMap) {
+        return supplyChainMapper.selectOrderInfoByItemIdsBytedance(requestMap);
     }
 
     @Override
@@ -1206,6 +1206,26 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
         return supplyChainMapper.getItemIdsByDeptId(deptId);
     }
 
+    @Override
+    public List<JSONObject> getKsChannelGmvHourByDateRoi(List<Long> userList, Integer nowDate) {
+        return supplyChainMapper.getKsChannelGmvHourByDateRoi(userList, nowDate);
+    }
+
+    @Override
+    public List<JSONObject> getKsCourtshipGmvHourByDateRoi(List<Long> userList, Integer nowDate) {
+        return supplyChainMapper.getKsCourtshipGmvHourByDateRoi(userList, nowDate);
+    }
+
+    @Override
+    public List<JSONObject> getBytedanceChannelGmvHourByDateRoi(List<Long> userList, Long dataNow) {
+        return supplyChainMapper.getBytedanceChannelGmvHourByDateRoi(userList, dataNow);
+    }
+
+    @Override
+    public List<JSONObject> getBytedanceCourtshipGmvHourByDateRoi(List<Long> userList, Long dataNow) {
+        return supplyChainMapper.getBytedanceCourtshipGmvHourByDateRoi(userList, dataNow);
+    }
+
     private void getInfoKuaishouActivityInfo(KuaishouAccessToken accessToken, String url) {
         List<KuaiShouActivityInfo> list = new ArrayList<>();
         String appKey = accessToken.getAppKey();

+ 302 - 9
ruixuan-live/src/main/resources/mapper/isc/SupplyChainMapper.xml

@@ -1447,6 +1447,12 @@
     </select>
 
     <select id="selectOrderInfo" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t1.*,
+        ROUND(((t1.validOrderNUm-t2.validOrderNUm)/t2.validOrderNUm)*100,2) as 'validOrderNUmRoi',
+        ROUND(((t1.allNumber-t1.validOrderNUm-t2.inValidOrderNUm)/t2.inValidOrderNUm)*100,2) as 'inValidOrderNUmRoi',
+        ROUND(((t1.baseAmount-t2.baseAmount)/t2.baseAmount)*100,2) as 'baseAmountRoi',
+        ROUND(((t1.regimentalPromotionAmount-t2.regimentalPromotionAmount)/t2.regimentalPromotionAmount)*100,2) as 'regimentalPromotionAmountRoi'
+        FROM(
         SELECT
         COUNT(DISTINCT promoter_id) as 'promoterCount',
         COUNT(DISTINCT item_id) as 'itemCount',
@@ -1459,16 +1465,41 @@
         FROM kuaishou_supply_chain
         WHERE stat_date >= #{startDate}
         AND stat_date &lt;= #{endDate}
+        AND stat_hour &lt;= #{hour}
         <if test='promoterIds != null and promoterIds.size() > 0'>
             AND promoter_id in
             <foreach collection="promoterIds" item="item" separator=","
                      open="(" close=")">
                 #{item}
             </foreach>
-        </if>
+        </if>)t1
+        LEFT JOIN (
+        SELECT
+        IFNULL(SUM(CASE WHEN order_status != 80 THEN 1 ELSE 0 END), 0) AS 'validOrderNUm',
+        COUNT(oid)-IFNULL(SUM(CASE WHEN order_status != 80 THEN 1 ELSE 0 END), 0) as 'inValidOrderNUm',
+        IFNULL(SUM(CASE WHEN order_status != 80 THEN order_amount ELSE 0 END),0) as 'baseAmount',
+               IFNULL(SUM(CASE WHEN order_status != 80 THEN regimental_promotion_amount ELSE 0 END),0) AS
+        'regimentalPromotionAmount'
+        FROM kuaishou_supply_chain
+        WHERE stat_date >= #{lastTimeStart}
+        AND stat_date &lt;= #{lastTimeEnd}
+        AND stat_hour &lt;= #{hour}
+        <if test='promoterIds != null and promoterIds.size() > 0'>
+            AND promoter_id in
+            <foreach collection="promoterIds" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>)t2 on 1=1
     </select>
 
     <select id="selectOrderInfoBytedance" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t1.*,
+        ROUND(((t1.validOrderNUm-t2.validOrderNUm)/t2.validOrderNUm)*100,2) as 'validOrderNUmRoi',
+        ROUND(((t1.allNumber-t1.validOrderNUm-t2.inValidOrderNUm)/t2.inValidOrderNUm)*100,2) as 'inValidOrderNUmRoi',
+        ROUND(((t1.baseAmount-t2.baseAmount)/t2.baseAmount)*100,2) as 'baseAmountRoi',
+        ROUND(((t1.regimentalPromotionAmount-t2.regimentalPromotionAmount)/t2.regimentalPromotionAmount)*100,2) as 'regimentalPromotionAmountRoi'
+        FROM (
         SELECT
         COUNT(DISTINCT author_short_id) as 'promoterCount',
         COUNT(DISTINCT product_id) as 'itemCount',
@@ -1488,8 +1519,33 @@
         THEN second_estimated_commission
         ELSE 0 END) ,0) AS 'secondEstimatedCommission'
         FROM bytedance_order_list
-        WHERE pay_success_time >= #{startDate}
-        AND pay_success_time &lt;= #{endDate}
+        WHERE pay_success_time >=#{startDate}
+        AND pay_success_time &lt;=#{endDate}
+        AND pay_success_time_hour &lt;=#{hour}
+        <if test='promoterIds != null and promoterIds.size() > 0'>
+            AND author_short_id in
+            <foreach collection="promoterIds" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        )t1
+        LEFT JOIN (
+        SELECT
+        IFNULL(SUM(CASE WHEN flow_point != 'REFUND' THEN 1 ELSE 0 END), 0) AS 'validOrderNUm',
+        COUNT(order_id)-IFNULL(SUM(CASE WHEN flow_point != 'REFUND' THEN 1 ELSE 0 END), 0) as 'inValidOrderNUm',
+        IFNULL(SUM(CASE WHEN flow_point != 'REFUND' THEN total_pay_amount ELSE 0 END), 0) AS 'baseAmount',
+        IFNULL( sum(CASE
+        WHEN flow_point != 'REFUND' and colonel_type != 2
+        THEN colonel_estimated_commission
+        WHEN flow_point != 'REFUND' and colonel_type = 2
+        then second_estimated_commission
+        ELSE 0 END) * 0.9,0) AS
+        'regimentalPromotionAmount'
+        FROM bytedance_order_list
+        WHERE pay_success_time >=#{lastTimeStart}
+        AND pay_success_time &lt;=#{lastTimeEnd}
+        AND pay_success_time_hour &lt;=#{hour}
         <if test='promoterIds != null and promoterIds.size() > 0'>
             AND author_short_id in
             <foreach collection="promoterIds" item="item" separator=","
@@ -1497,12 +1553,17 @@
                 #{item}
             </foreach>
         </if>
+        )t2 on 1 = 1
     </select>
 
     <select id="selectOrderInfoByItemIds" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT t.*,
-        CONCAT(IFNULL(ROUND(sendCount / allNumber * 100, 2),0), '%') as 'sendRate'
-        FROM (
+        SELECT t1.*,
+        CONCAT(IFNULL(ROUND(t1.sendCount / t1.allNumber * 100, 2),0), '%') as 'sendRate',
+        ROUND(((t1.validOrderNUm-t2.validOrderNUm)/t2.validOrderNUm)*100,2) as 'validOrderNUmRoi',
+        ROUND(((t1.allNumber-t1.validOrderNUm-t2.inValidOrderNUm)/t2.inValidOrderNUm)*100,2) as 'inValidOrderNUmRoi',
+        ROUND(((t1.baseAmount-t2.baseAmount)/t2.baseAmount)*100,2) as 'baseAmountRoi',
+        ROUND(((t1.regimentalPromotionAmount-t2.regimentalPromotionAmount)/t2.regimentalPromotionAmount)*100,2) as 'regimentalPromotionAmountRoi'
+        FROM(
         SELECT
         COUNT(DISTINCT promoter_id) as 'promoterCount',
         COUNT(DISTINCT item_id) as 'itemCount',
@@ -1516,6 +1577,7 @@
         FROM kuaishou_supply_chain
         WHERE stat_date >= #{startDate}
         AND stat_date &lt;= #{endDate}
+        AND stat_hour &lt;= #{hour}
         <if test='itemIds != null and itemIds.size() > 0'>
             AND item_id in
             <foreach collection="itemIds" item="item" separator=","
@@ -1523,28 +1585,72 @@
                 #{item}
             </foreach>
         </if>
-        ) t
+        )t1
+        LEFT JOIN (
+        SELECT
+        IFNULL(SUM(CASE WHEN order_status != 80 THEN 1 ELSE 0 END), 0) AS 'validOrderNUm',
+        COUNT(oid)-IFNULL(SUM(CASE WHEN order_status != 80 THEN 1 ELSE 0 END), 0) as 'inValidOrderNUm',
+        IFNULL(sum(base_amount), 0) as 'baseAmount',
+        IFNULL(SUM(CASE WHEN order_status != 80 THEN regimental_promotion_amount ELSE 0 END),0) AS
+        'regimentalPromotionAmount'
+        FROM kuaishou_supply_chain
+        WHERE stat_date >= #{lastTimeStart}
+        AND stat_date &lt;= #{lastTimeEnd}
+        AND stat_hour &lt;= #{hour}
+        <if test='itemIds != null and itemIds.size() > 0'>
+            AND item_id in
+            <foreach collection="itemIds" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        )t2 on 1=1
     </select>
 
     <select id="selectOrderInfoByItemIdsBytedance" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t1.*,
+        ROUND(((t1.validOrderNUm-t2.validOrderNUm)/t2.validOrderNUm)*100,2) as 'validOrderNUmRoi',
+        ROUND(((t1.allNumber-t1.validOrderNUm-t2.inValidOrderNUm)/t2.inValidOrderNUm)*100,2) as 'inValidOrderNUmRoi',
+        ROUND(((t1.baseAmount-t2.baseAmount)/t2.baseAmount)*100,2) as 'baseAmountRoi',
+        ROUND(((t1.regimentalPromotionAmount-t2.regimentalPromotionAmount)/t2.regimentalPromotionAmount)*100,2) as 'regimentalPromotionAmountRoi'
+        from (
         SELECT
         COUNT(DISTINCT author_short_id) as 'promoterCount',
         COUNT(DISTINCT product_id) as 'itemCount',
         COUNT(order_id) as 'allNumber',
         IFNULL(SUM(CASE WHEN flow_point != 'REFUND' THEN 1 ELSE 0 END), 0) AS 'validOrderNUm',
-        IFNULL(SUM(CASE WHEN flow_point != 'REFUND' THEN total_pay_amount ELSE 0 END)/100, 0) AS 'orderAmount',
+        IFNULL(SUM(CASE WHEN flow_point != 'REFUND' THEN total_pay_amount ELSE 0 END)/100, 0) AS 'baseAmount',
         IFNULL(SUM(CASE WHEN flow_point != 'REFUND' THEN colonel_estimated_commission ELSE 0 END) * 0.9 /100,0) AS
         'regimentalPromotionAmount'
         FROM bytedance_order_list
         WHERE pay_success_time >= #{startDate}
         AND pay_success_time &lt;= #{endDate}
+        AND pay_success_time_hour &lt;=#{hour}
         <if test='itemIds != null and itemIds.size() > 0'>
             AND product_id in
             <foreach collection="itemIds" item="item" separator=","
                      open="(" close=")">
                 #{item}
             </foreach>
-        </if>
+        </if>)t1
+        LEFT JOIN (
+        SELECT
+        IFNULL(SUM(CASE WHEN flow_point != 'REFUND' THEN 1 ELSE 0 END), 0) AS 'validOrderNUm',
+        COUNT(order_id)-IFNULL(SUM(CASE WHEN flow_point != 'REFUND' THEN 1 ELSE 0 END), 0) as 'inValidOrderNUm',
+        IFNULL(SUM(CASE WHEN flow_point != 'REFUND' THEN total_pay_amount ELSE 0 END)/100, 0) AS 'baseAmount',
+        IFNULL(SUM(CASE WHEN flow_point != 'REFUND' THEN colonel_estimated_commission ELSE 0 END) * 0.9 /100,0) AS
+        'regimentalPromotionAmount'
+        FROM bytedance_order_list
+        WHERE pay_success_time >= #{lastTimeStart}
+        AND pay_success_time &lt;= #{lastTimeEnd}
+        AND pay_success_time_hour &lt;=#{hour}
+        <if test='itemIds != null and itemIds.size() > 0'>
+            AND product_id in
+            <foreach collection="itemIds" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>)t2 on 1=1
     </select>
 
     <select id="selectOrderRate" resultType="com.alibaba.fastjson.JSONObject">
@@ -2953,6 +3059,51 @@
         order by stat_hour asc;
     </select>
 
+    <select id="getKsChannelGmvHourByDateRoi" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t1.time,
+        ROUND(((t1.charge-t2.charge)/t2.charge)*100,2) as 'roi'
+        FROM
+        (select stat_hour as 'time',
+        round(sum(pay_amount) / 100, 2) as 'charge' from kuaishou_supply_chain
+        where stat_date = #{date}
+        <if test='userList != null and userList.size() > 0'>
+            and promoter_id in (
+            select promoter_id
+            from kuaishou_promoter where
+            1 = 1
+            and user_id in
+            <foreach collection="userList" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+            group by promoter_id
+            )
+        </if>
+        group by stat_hour
+        ) t1
+        LEFT JOIN
+        (select stat_hour as 'time',
+        round(sum(pay_amount) / 100, 2) as 'charge' from kuaishou_supply_chain
+        where stat_date = DATE_FORMAT(DATE_SUB(#{date},INTERVAL 1 day),'%Y%m%d')
+        <if test='userList != null and userList.size() > 0'>
+            and promoter_id in (
+            select promoter_id
+            from kuaishou_promoter where
+            1 = 1
+            and user_id in
+            <foreach collection="userList" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+            group by promoter_id
+            )
+        </if>
+        group by stat_hour
+        ) t2 ON t1.time =t2.time
+        ORDER BY `time`
+    </select>
+
 
     <select id="getKsCourtshipGmvHourByDate" resultType="com.alibaba.fastjson.JSONObject">
         select stat_hour as 'time',
@@ -2976,6 +3127,54 @@
         order by stat_hour asc;
 
     </select>
+
+    <select id="getKsCourtshipGmvHourByDateRoi" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t1.time,
+        ROUND(((t1.charge-t2.charge)/t2.charge)*100,2) as 'roi'
+        FROM
+        ( select stat_hour as 'time',
+        round(sum(pay_amount) / 100, 2) as 'charge'
+        from kuaishou_supply_chain
+        where stat_date = #{date}
+        <if test='userList != null and userList.size() > 0'>
+            and item_id in (
+            select item_id
+            from kuaishou_item_list where
+            1 = 1
+            and user_id in
+            <foreach collection="userList" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+            group by item_id
+            )
+        </if>
+        group by stat_hour
+        ) t1
+        LEFT JOIN
+        (
+        select stat_hour as 'time',
+        round(sum(pay_amount) / 100, 2) as 'charge'
+        from kuaishou_supply_chain
+        where stat_date = DATE_FORMAT(DATE_SUB(#{date},INTERVAL 1 day),'%Y%m%d')
+        <if test='userList != null and userList.size() > 0'>
+            and item_id in (
+            select item_id
+            from kuaishou_item_list where
+            1 = 1
+            and user_id in
+            <foreach collection="userList" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+            group by item_id
+            )
+        </if>
+        group by stat_hour
+        ) t2 ON t1.time =t2.time
+        ORDER BY `time`
+    </select>
     <select id="getBytedanceChannelGmvHourByDate" resultType="com.alibaba.fastjson.JSONObject">
         select pay_success_time_hour as 'time',
         round(sum(total_pay_amount) / 100, 2) as 'charge' from bytedance_order_list where pay_success_time = #{date}
@@ -2996,6 +3195,53 @@
         order by pay_success_time_hour asc;
 
     </select>
+
+    <select id="getBytedanceChannelGmvHourByDateRoi" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t1.time,
+        ROUND(((t1.charge-t2.charge)/t2.charge)*100,2) as 'roi'
+        FROM
+        (
+        select pay_success_time_hour as 'time',
+        round(sum(total_pay_amount) / 100, 2) as 'charge' from bytedance_order_list where pay_success_time = #{date}
+        <if test='userList != null and userList.size() > 0'>
+            and author_short_id in(
+            select promoter_id
+            from kuaishou_promoter where
+            1 = 1
+            and user_id in
+            <foreach collection="userList" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+            group by promoter_id
+            )
+        </if>
+        group by pay_success_time_hour
+        ) t1
+        LEFT JOIN
+        (
+        select pay_success_time_hour as 'time',
+        round(sum(total_pay_amount) / 100, 2) as 'charge' from bytedance_order_list
+        where pay_success_time = DATE_FORMAT(DATE_SUB(#{date},INTERVAL 1 day),'%Y%m%d')
+        <if test='userList != null and userList.size() > 0'>
+            and author_short_id in(
+            select promoter_id
+            from kuaishou_promoter where
+            1 = 1
+            and user_id in
+            <foreach collection="userList" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+            group by promoter_id
+            )
+        </if>
+        group by pay_success_time_hour
+        ) t2 ON t1.time =t2.time
+        ORDER BY `time`
+    </select>
+
     <select id="getBytedanceCourtshipGmvHourByDate" resultType="com.alibaba.fastjson.JSONObject">
         select pay_success_time_hour as 'time',
         round(sum(total_pay_amount) / 100, 2) as 'charge' from bytedance_order_list where pay_success_time = #{date}
@@ -3016,6 +3262,53 @@
         order by pay_success_time_hour asc;
     </select>
 
+
+    <select id="getBytedanceCourtshipGmvHourByDateRoi" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t1.time,
+        ROUND(((t1.charge-t2.charge)/t2.charge)*100,2) as 'roi'
+        FROM
+        (
+        select pay_success_time_hour as 'time',
+        round(sum(total_pay_amount) / 100, 2) as 'charge' from bytedance_order_list where pay_success_time = #{date}
+        <if test='userList != null and userList.size() > 0'>
+            and product_id in(
+            select item_id
+            from kuaishou_item_list where
+            1 = 1
+            and user_id in
+            <foreach collection="userList" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+            group by item_id
+            )
+        </if>
+        group by pay_success_time_hour
+        ) t1
+        LEFT JOIN
+        (
+        select pay_success_time_hour as 'time',
+        round(sum(total_pay_amount) / 100, 2) as 'charge' from bytedance_order_list
+        where pay_success_time = DATE_FORMAT(DATE_SUB(#{date},INTERVAL 1 day),'%Y%m%d')
+        <if test='userList != null and userList.size() > 0'>
+            and product_id in(
+            select item_id
+            from kuaishou_item_list where
+            1 = 1
+            and user_id in
+            <foreach collection="userList" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+            group by item_id
+            )
+        </if>
+        group by pay_success_time_hour
+        ) t2 ON t1.time =t2.time
+        ORDER BY `time`
+    </select>
+
     <insert id="replaceKuaiShouActivityOpenItemList">
         replace into kuaishou_activity_open_item_list(
         item_id,