Bläddra i källkod

账户报表 加入总和进行计算

yumeng 5 år sedan
förälder
incheckning
ee47953cb1

+ 21 - 2
module-report/src/main/java/cn/com/ctop/bytedance/mapper/AccountReportMapper.java

@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Param;
 
 import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author jeecg-boot
@@ -26,7 +27,7 @@ public interface AccountReportMapper {
     /**
      * 今日消耗
      *
-     * @param date 日期
+     * @param date       日期
      * @param accountIds
      * @return 今日消耗
      */
@@ -36,7 +37,7 @@ public interface AccountReportMapper {
     /**
      * 查询明细
      *
-     * @param date 日期
+     * @param date       日期
      * @param accountIds
      * @return 查询明细
      */
@@ -54,6 +55,7 @@ public interface AccountReportMapper {
 
     /**
      * 查询全部消耗 包括今日消耗
+     *
      * @param accountIds
      * @return
      */
@@ -94,6 +96,7 @@ public interface AccountReportMapper {
 
     /**
      * 查询所有按月统计数据
+     *
      * @param accountIds
      * @return
      */
@@ -124,6 +127,7 @@ public interface AccountReportMapper {
 
     /**
      * 用户报表信息
+     *
      * @param accountIds
      * @param discount
      * @return
@@ -145,10 +149,25 @@ public interface AccountReportMapper {
 
     /**
      * 按月统计
+     *
      * @param startDate
      * @param endDate
      * @param accountIds
      * @return
      */
     List<JSONObject> selectDayDetailByMonth(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("accountIds") JSONArray accountIds);
+
+
+    /**
+     * 查询分天汇总
+     *
+     * @param queryMap
+     * @return
+     */
+
+    JSONObject selectSummaryByMap(Map<String, Object> queryMap);
+
+    List<JSONObject> selectReportDetailGroupAccountIdByDate(@Param("statDate") String anotherDay,@Param("accountIds") JSONArray accountIds);
+
+    JSONObject selectHourSummaryByMap(Map<String, Object> queryMap);
 }

+ 213 - 0
module-report/src/main/java/cn/com/ctop/bytedance/mapper/xml/AccountReportMapper.xml

@@ -120,6 +120,34 @@
     </select>
 
 
+    <select id="selectReportDetailGroupAccountIdByDate" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        sum(charge) cost, -- 消耗
+        sum(photo_show) photoShow, -- 封面展示
+        sum(photo_click) photoClick, -- 封面点击
+        sum(aclick) aclick, -- 素材曝光数
+        (sum(photo_click) / sum(photo_show)) photoClickRatio, -- 封面点击率
+        (sum(form_count) / sum(bclick)) cvr,
+        ((sum(charge) / (sum(photo_show)) * 1000)) cpm,
+        sum(bclick) bClick,-- 行为数
+        sum(form_count) formCount,
+        (sum(charge) / sum(form_count)) formPrice, -- 表单提交单价
+        sum(activation) activationCount, -- 激活数
+        (sum(charge) / sum(activation)) activationPrice, -- 激活单价
+        account_id accountId,
+        (select auth_name from ctop_user_allocation where account_id = accountId limit 1) accountName
+        from
+        ctop_kuaishou_report_daily_account
+        where stat_date = #{statDate}
+        and account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        group by account_id;
+    </select>
+
+
     <select id="selectMaxHourByDate" resultType="java.lang.Integer">
         select
         max(stat_hour)
@@ -298,4 +326,189 @@
     </select>
 
 
+    <select id="selectSummaryByMap" parameterType="Map" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        sum(charge) cost, -- 消耗
+        (case
+        when sum(charge) != 0
+        then (sum(charge) / #{discount})
+        else 0
+        end
+        ) discountCost, -- 封面点击率
+
+        sum(photo_show) photoShow, -- 封面展示
+        sum(photo_click) photoClick, -- 封面点击
+        sum(aclick) aclick, -- 素材曝光数
+
+        (case
+        when sum(photo_show) != 0
+        then (sum(photo_click) / sum(photo_show))
+        else 0
+        end
+        ) photoClickRatio, -- 封面点击率
+
+        (case
+        when sum(bclick) != 0
+        then (sum(form_count) / sum(bclick))
+        else 0
+        end
+        ) cvr,
+
+        (case
+        when sum(photo_show) != 0
+        then ((sum(charge) / (sum(photo_show)) * 1000))
+        else 0
+        end
+        ) cpm,
+
+        sum(bclick) bClick,-- 行为数
+        (
+        CASE
+        WHEN sum(form_count) != 0 THEN
+        sum(form_count)
+        WHEN sum(activation) != 0 THEN
+        sum(activation)
+        ELSE
+        0
+        END
+        ) conversions, -- 转化数
+        (
+        CASE
+        WHEN sum(form_count) != 0 THEN
+        sum(charge) / sum(form_count)
+        WHEN sum(activation) != 0 THEN
+        sum(charge) / sum(activation)
+        ELSE
+        0
+        END
+        ) conversionPrice, -- 转化单价
+        (
+        CASE
+        WHEN sum(form_count) != 0 THEN
+        (sum(charge) / sum(form_count)) / #{discount}
+        WHEN sum(activation) != 0 THEN
+        (sum(charge) / sum(activation)) / #{discount}
+        ELSE
+        0
+        END
+        ) discountConversionPrice
+
+        from
+        ctop_kuaishou_report_daily_account
+
+        <where>
+            <if test="statDate != null">
+                and stat_date = #{statDate}
+            </if>
+            <if test="startDate != null">
+                and stat_date &gt;= #{startDate}
+            </if>
+            <if test="endDate != null">
+                and stat_date &lt;= #{endDate}
+            </if>
+
+            <if test="accountIds != null">
+                and account_id in
+                <foreach collection="accountIds" item="item" separator=","
+                         open="(" close=")">
+                    #{item}
+                </foreach>
+
+            </if>
+        </where>
+    </select>
+
+
+    <select id="selectHourSummaryByMap" parameterType="Map" resultType="com.alibaba.fastjson.JSONObject">
+
+        select
+        sum(charge) cost, -- 消耗
+        (case
+        when sum(charge) != 0
+        then (sum(charge) / #{discount})
+        else 0
+        end
+        ) discountCost, -- 封面点击率
+
+        sum(photo_show) photoShow, -- 封面展示
+        sum(photo_click) photoClick, -- 封面点击
+        sum(aclick) aclick, -- 素材曝光数
+
+        (case
+        when sum(photo_show) != 0
+        then (sum(photo_click) / sum(photo_show))
+        else 0
+        end
+        ) photoClickRatio, -- 封面点击率
+
+        (case
+        when sum(bclick) != 0
+        then (sum(form_count) / sum(bclick))
+        else 0
+        end
+        ) cvr,
+
+        (case
+        when sum(photo_show) != 0
+        then ((sum(charge) / (sum(photo_show)) * 1000))
+        else 0
+        end
+        ) cpm,
+
+        sum(bclick) bClick,-- 行为数
+        (
+        CASE
+        WHEN sum(form_count) != 0 THEN
+        sum(form_count)
+        WHEN sum(activation) != 0 THEN
+        sum(activation)
+        ELSE
+        0
+        END
+        ) conversions, -- 转化数
+        (
+        CASE
+        WHEN sum(form_count) != 0 THEN
+        sum(charge) / sum(form_count)
+        WHEN sum(activation) != 0 THEN
+        sum(charge) / sum(activation)
+        ELSE
+        0
+        END
+        ) conversionPrice, -- 转化单价
+        (
+        CASE
+        WHEN sum(form_count) != 0 THEN
+        (sum(charge) / sum(form_count)) / #{discount}
+        WHEN sum(activation) != 0 THEN
+        (sum(charge) / sum(activation)) / #{discount}
+        ELSE
+        0
+        END
+        ) discountConversionPrice
+
+        from
+        ctop_kuaishou_report_hourly_account
+
+        <where>
+            <if test="statDate != null">
+                and stat_date = #{statDate}
+            </if>
+            <if test="statHour != null">
+                and stat_hour &lt;= #{statHour}
+            </if>
+
+            <if test="accountIds != null">
+                and account_id in
+                <foreach collection="accountIds" item="item" separator=","
+                         open="(" close=")">
+                    #{item}
+                </foreach>
+
+            </if>
+        </where>
+
+
+    </select>
+
 </mapper>

+ 45 - 2
module-report/src/main/java/cn/com/ctop/bytedance/service/impl/AccountReportServiceImpl.java

@@ -12,7 +12,9 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author yumeng
@@ -257,6 +259,8 @@ public class AccountReportServiceImpl implements IAccountReportService {
                 return null;
             }
 
+            Map<String, Object> queryMap = new HashMap<>();
+            queryMap.put("discount", discount);
             String statDate = "";
             List<JSONObject> accountDetail = new ArrayList<>();
             Integer statHour = json.getInteger("statHour");
@@ -495,42 +499,81 @@ public class AccountReportServiceImpl implements IAccountReportService {
                     }
                 }
             } else if (type == 2) {
+                queryMap.put("statDate", anotherDay);
+                queryMap.put("accountIds", accountIds);
+                JSONObject ratioJson;
                 if (Check.isNull(statHour)) {
-                    accountDetail = accountReportMapper.selectReportDetailGroupAccountId(anotherDay, accountIds, 23);
+                    accountDetail = accountReportMapper.selectReportDetailGroupAccountIdByDate(anotherDay, accountIds);
                     statDate = anotherDay;
+                    ratioJson = accountReportMapper.selectSummaryByMap(queryMap);
+
                 } else {
                     accountDetail = accountReportMapper.selectReportDetailGroupAccountId(anotherDay, accountIds, statHour);
+                    queryMap.put("statHour", statHour);
                     statDate = anotherDay;
+                    ratioJson = accountReportMapper.selectHourSummaryByMap(queryMap);
                 }
+
+                returnJson.put("ratioJson", ratioJson);
             } else if (type == 3) {
                 String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -7);
                 accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds, discount);
                 statDate = endDate + " ~ " + anotherDay;
+
+
+                queryMap.put("startDate", endDate);
+                queryMap.put("endDate", anotherDay);
+                queryMap.put("accountIds", accountIds);
+
+
             } else if (type == 4) {
                 String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -15);
                 accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds, discount);
                 statDate = endDate + " ~ " + anotherDay;
+                queryMap.put("startDate", endDate);
+                queryMap.put("endDate", anotherDay);
+                queryMap.put("accountIds", accountIds);
+
             } else if (type == 5) {
                 String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -1);
                 accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds, discount);
                 statDate = endDate + " ~ " + anotherDay;
+                queryMap.put("startDate", endDate);
+                queryMap.put("endDate", anotherDay);
+                queryMap.put("accountIds", accountIds);
             } else if (type == 6) {
                 String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -3);
                 accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds, discount);
                 statDate = endDate + " ~ " + anotherDay;
+                queryMap.put("startDate", endDate);
+                queryMap.put("endDate", anotherDay);
+                queryMap.put("accountIds", accountIds);
             } else if (type == 7) {
                 String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -6);
                 accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds, discount);
                 statDate = endDate + " ~ " + anotherDay;
+                queryMap.put("startDate", endDate);
+                queryMap.put("endDate", anotherDay);
+                queryMap.put("accountIds", accountIds);
             } else if (type == 8) {
                 accountDetail = accountReportMapper.selectAccountReport(accountIds, discount);
                 statDate = "合计";
+                queryMap.put("accountIds", accountIds);
             } else if (type == 9) {
                 String startDate = json.getString("startDate");
                 String endDate = json.getString("endDate");
                 accountDetail = accountReportMapper.selectAccountReportByDate(startDate, endDate, accountIds, discount);
-                statDate = statDate + " ~ " + endDate;
+                statDate = endDate + " ~ " + startDate;
+                queryMap.put("startDate", endDate);
+                queryMap.put("endDate", startDate);
+                queryMap.put("accountIds", accountIds);
             }
+
+            if ((type != 1 && type != 2) && type != null) {
+                JSONObject ratioJson = accountReportMapper.selectSummaryByMap(queryMap);
+                returnJson.put("ratioJson", ratioJson);
+            }
+
             returnJson.put("statDate", statDate);
             returnJson.put("accountDetail", accountDetail);
         } catch (Exception e) {