yumeng 1 Minggu lalu
induk
melakukan
0b15d15cbd

+ 4 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/AdqAdvertiserReportMapper.java

@@ -61,6 +61,10 @@ public interface AdqAdvertiserReportMapper {
 
     List<JSONObject> getOperateGroupPreviousByUsers(@Param("startDate") Long startDate, @Param("endDate") Long endDate, @Param("userIds") List<String> userIds);
 
+    List<JSONObject> getOperateGroupHourlyMetricsByUsers(@Param("hour") Integer hour, @Param("currentStartDate") Long currentStartDate, @Param("currentEndDate") Long currentEndDate, @Param("previousStartDate") Long previousStartDate, @Param("previousEndDate") Long previousEndDate, @Param("userIds") List<String> userIds);
+
+    List<JSONObject> getOperateGroupDailyMetricsByUsers(@Param("currentStartDate") Long currentStartDate, @Param("currentEndDate") Long currentEndDate, @Param("previousStartDate") Long previousStartDate, @Param("previousEndDate") Long previousEndDate, @Param("userIds") List<String> userIds);
+
     List<JSONObject> getAdqOperateGroupInfoHourlyBatch(@Param("managerIds") List<String> managerIds, @Param("hour") Integer hour, @Param("startDate") Long startDate, @Param("endDate") Long endDate, @Param("lastTimeEnd") Long lastTimeEnd, @Param("lastTimeStart") Long lastTimeStart);
 
     List<JSONObject> getAdqOperateGroupInfoBatch(@Param("managerIds") List<String> managerIds, @Param("startDate") Long startDate, @Param("endDate") Long endDate, @Param("lastTimeEnd") Long lastTimeEnd, @Param("lastTimeStart") Long lastTimeStart);

+ 164 - 70
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/xml/AdqAdvertiserReportMapper.xml

@@ -33,7 +33,7 @@
     </select>
 
     <select id="getTotalChargeHourly" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT /*+ READ_FROM_STORAGE(TIKV[report]) */
+        SELECT 
                IFNULL(SUM(CASE WHEN report.stat_date = #{today} THEN report.cost END), 0.00) AS 'todayCost',
                IFNULL(SUM(CASE WHEN report.stat_date = #{yesterday} AND report.stat_hour &lt;= #{hour} THEN report.cost END), 0.00) AS 'yesterdayCost',
                IFNULL(SUM(CASE WHEN report.stat_date = #{today} THEN report.cost END), 0.00) AS 'thisWeekTodayCost',
@@ -70,7 +70,7 @@
     </select>
 
     <select id="getHourCost" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT /*+ READ_FROM_STORAGE(TIKV[report]) */ report.stat_hour AS 'time',
+        SELECT report.stat_hour AS 'time',
                IFNULL(SUM(report.cost), 0.00) AS 'cost'
         FROM application.adq_advertiser_report_hourly report
         WHERE report.stat_date = #{startTime}
@@ -82,7 +82,7 @@
     </select>
 
     <select id="getDataCost" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT /*+ READ_FROM_STORAGE(TIKV[report]) */ DATE_FORMAT(report.stat_date, '%Y-%m-%d') AS 'time',
+        SELECT DATE_FORMAT(report.stat_date, '%Y-%m-%d') AS 'time',
                IFNULL(SUM(report.cost), 0.00) AS 'cost'
         FROM application.adq_advertiser_report_hourly report
         WHERE report.stat_date >= #{startTime}
@@ -95,7 +95,7 @@
     </select>
 
     <select id="getProjectTodayBase" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT /*+ READ_FROM_STORAGE(TIKV[report]) */ report.project_id AS 'projectId',
+        SELECT report.project_id AS 'projectId',
                MAX(report.advertiser_name) AS 'companyName',
                SUM(report.cost) AS 'cost',
                SUM(report.view_count) AS 'aclick',
@@ -139,7 +139,7 @@
     </select>
 
     <select id="getProjectPrevHourlyCostByDayAndIds" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT /*+ READ_FROM_STORAGE(TIKV[report]) */ report.project_id AS 'projectId',
+        SELECT report.project_id AS 'projectId',
                SUM(report.cost) AS 'cost'
         FROM application.adq_advertiser_report_hourly report
         WHERE report.stat_date = #{statDate}
@@ -166,7 +166,7 @@
     </select>
 
     <select id="getProjectAccountOperatorCountByCurrentHourlyAndIds" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT /*+ READ_FROM_STORAGE(TIKV[report]) */ report.project_id AS 'projectId',
+        SELECT report.project_id AS 'projectId',
                COUNT(DISTINCT report.account_id) AS 'accountNum',
                COUNT(DISTINCT report.user_id) AS 'operaterNum'
         FROM application.adq_advertiser_report_hourly report
@@ -182,7 +182,7 @@
 
     <select id="getProjectToDayReport" resultType="com.alibaba.fastjson.JSONObject">
         WITH active_projects AS (
-            SELECT /*+ READ_FROM_STORAGE(TIKV[t1]) */ t1.project_id AS projectId,
+            SELECT t1.project_id AS projectId,
                    MAX(t1.advertiser_name) AS companyName,
                    SUM(t1.cost) AS cost,
                    SUM(t1.view_count) AS aclick,
@@ -229,7 +229,7 @@
                           LEFT JOIN `jeecg-boot`.sys_user t4 ON t3.responsible_id = t4.id
                           LEFT JOIN `jeecg-boot`.sys_user t5 ON t3.sale_id = t5.id
                           LEFT JOIN (
-                     SELECT /*+ READ_FROM_STORAGE(TIKV[report]) */ report.project_id,
+                     SELECT report.project_id,
                             SUM(report.cost) AS 'costs'
                      FROM application.adq_advertiser_report_hourly report
                               INNER JOIN active_projects active ON active.projectId = report.project_id
@@ -238,7 +238,7 @@
                      GROUP BY report.project_id
                  ) t7 ON ap.projectId = t7.project_id
                           LEFT JOIN (
-                     SELECT /*+ READ_FROM_STORAGE(TIKV[report]) */ report.project_id,
+                     SELECT report.project_id,
                             COUNT(DISTINCT report.account_id) AS 'accountNum',
                             COUNT(DISTINCT report.user_id) AS 'operaterNum'
                      FROM application.adq_advertiser_report_hourly report
@@ -379,7 +379,7 @@
     </select>
 
     <select id="getAdqOperateInfoHourly" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT /*+ READ_FROM_STORAGE(TIKV[t]) */ COUNT(DISTINCT t.account_id) AS 'accountNum',
+        SELECT COUNT(DISTINCT t.account_id) AS 'accountNum',
                COUNT(DISTINCT t.project_id) AS 'projectNums',
                SUM(t.cost) AS 'totalCost',
                t.user_id AS 'userId',
@@ -391,7 +391,7 @@
         FROM application.adq_advertiser_report_hourly t
                  LEFT JOIN `jeecg-boot`.sys_user t2 ON t.user_id = t2.id
                  LEFT JOIN (
-            SELECT /*+ READ_FROM_STORAGE(TIKV[d]) */ SUM(d.cost) AS 'lastCost', d.user_id
+            SELECT SUM(d.cost) AS 'lastCost', d.user_id
             FROM application.adq_advertiser_report_hourly d
             WHERE d.cost > 0
               AND d.stat_hour &lt;= #{hour}
@@ -468,7 +468,7 @@
                NULL AS 'unitNum',
                NULL AS 'projectNum'
         FROM (
-                 SELECT /*+ READ_FROM_STORAGE(TIKV[d]) */ COUNT(DISTINCT d.account_id) AS 'accountNum',
+                 SELECT COUNT(DISTINCT d.account_id) AS 'accountNum',
                         COUNT(DISTINCT d.project_id) AS 'projectNum',
                         SUM(d.cost) AS 'totalCost',
                         d.user_id
@@ -486,7 +486,7 @@
                  GROUP BY d.user_id
              ) t1
                  LEFT JOIN (
-            SELECT /*+ READ_FROM_STORAGE(TIKV[d]) */ SUM(d.cost) AS 'lastCost'
+            SELECT SUM(d.cost) AS 'lastCost'
             FROM application.adq_advertiser_report_hourly d
             WHERE d.cost > 0
               AND d.stat_hour &lt;= #{hour}
@@ -551,7 +551,7 @@
                           LEFT JOIN `jeecg-boot`.sys_user_role ur ON u.id = ur.user_id
                           LEFT JOIN `jeecg-boot`.sys_role r ON ur.role_id = r.id
                           INNER JOIN (
-                     SELECT /*+ READ_FROM_STORAGE(TIKV[report]) */ DISTINCT report.user_id
+                     SELECT DISTINCT report.user_id
                      FROM application.adq_advertiser_report_hourly report
                      WHERE report.stat_date >= #{startDate}
                        AND report.stat_date &lt;= #{endDate}
@@ -566,7 +566,7 @@
                    AND u.del_flag = 0
                  GROUP BY m.manage_id, u.id
                  UNION ALL
-                 SELECT /*+ READ_FROM_STORAGE(TIKV[report]) */ report.user_id AS managerId, report.user_id AS userId
+                 SELECT report.user_id AS managerId, report.user_id AS userId
                  FROM application.adq_advertiser_report_hourly report
                  WHERE report.user_id IN
                        <foreach collection="managerIds" item="item" separator="," open="(" close=")">
@@ -588,7 +588,7 @@
     </sql>
 
     <select id="getOperateGroupCurrentHourlyByUsers" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT /*+ READ_FROM_STORAGE(TIKV[d]) */ d.user_id AS 'userId',
+        SELECT d.user_id AS 'userId',
                COUNT(DISTINCT d.account_id) AS 'accountNum',
                COUNT(DISTINCT d.project_id) AS 'projectNum',
                SUM(d.cost) AS 'totalCost'
@@ -621,7 +621,7 @@
     </select>
 
     <select id="getOperateGroupPreviousHourlyByUsers" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT /*+ READ_FROM_STORAGE(TIKV[d]) */ d.user_id AS 'userId',
+        SELECT d.user_id AS 'userId',
                SUM(d.cost) AS 'lastCost'
         FROM application.adq_advertiser_report_hourly d
         WHERE d.cost > 0
@@ -649,16 +649,92 @@
         GROUP BY d.user_id
     </select>
 
+    <select id="getOperateGroupHourlyMetricsByUsers" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT d.user_id AS 'userId',
+               COUNT(DISTINCT CASE
+                                  WHEN d.stat_date >= #{currentStartDate}
+                                      AND d.stat_date &lt;= #{currentEndDate}
+                                      AND d.stat_hour &lt;= #{hour}
+                                      AND d.cost > 0
+                                      THEN d.account_id
+                   END) AS 'accountNum',
+               COUNT(DISTINCT CASE
+                                  WHEN d.stat_date >= #{currentStartDate}
+                                      AND d.stat_date &lt;= #{currentEndDate}
+                                      AND d.stat_hour &lt;= #{hour}
+                                      AND d.cost > 0
+                                      THEN d.project_id
+                   END) AS 'projectNum',
+               IFNULL(SUM(CASE
+                              WHEN d.stat_date >= #{currentStartDate}
+                                  AND d.stat_date &lt;= #{currentEndDate}
+                                  AND d.stat_hour &lt;= #{hour}
+                                  AND d.cost > 0
+                                  THEN d.cost
+                          END), 0) AS 'totalCost',
+               IFNULL(SUM(CASE
+                              WHEN d.stat_date >= #{previousStartDate}
+                                  AND d.stat_date &lt;= #{previousEndDate}
+                                  AND d.stat_hour &lt;= #{hour}
+                                  AND d.cost > 0
+                                  THEN d.cost
+                          END), 0) AS 'lastCost'
+        FROM application.adq_advertiser_report_hourly d
+        WHERE d.user_id IN
+        <foreach collection="userIds" item="item" separator="," open="(" close=")">
+            #{item}
+        </foreach>
+          AND d.stat_date >= #{previousStartDate}
+          AND d.stat_date &lt;= #{currentEndDate}
+        GROUP BY d.user_id
+    </select>
+
+    <select id="getOperateGroupDailyMetricsByUsers" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT d.user_id AS 'userId',
+               COUNT(DISTINCT CASE
+                                  WHEN d.stat_date >= #{currentStartDate}
+                                      AND d.stat_date &lt;= #{currentEndDate}
+                                      AND d.cost > 0
+                                      THEN d.account_id
+                   END) AS 'accountNum',
+               COUNT(DISTINCT CASE
+                                  WHEN d.stat_date >= #{currentStartDate}
+                                      AND d.stat_date &lt;= #{currentEndDate}
+                                      AND d.cost > 0
+                                      THEN d.project_id
+                   END) AS 'projectNum',
+               IFNULL(SUM(CASE
+                              WHEN d.stat_date >= #{currentStartDate}
+                                  AND d.stat_date &lt;= #{currentEndDate}
+                                  AND d.cost > 0
+                                  THEN d.cost
+                          END), 0) AS 'totalCost',
+               IFNULL(SUM(CASE
+                              WHEN d.stat_date >= #{previousStartDate}
+                                  AND d.stat_date &lt;= #{previousEndDate}
+                                  AND d.cost > 0
+                                  THEN d.cost
+                          END), 0) AS 'lastCost'
+        FROM application.adq_advertiser_report_daily d
+        WHERE d.user_id IN
+        <foreach collection="userIds" item="item" separator="," open="(" close=")">
+            #{item}
+        </foreach>
+          AND d.stat_date >= #{previousStartDate}
+          AND d.stat_date &lt;= #{currentEndDate}
+        GROUP BY d.user_id
+    </select>
+
     <select id="getAdqOperateGroupInfoHourlyBatch" resultType="com.alibaba.fastjson.JSONObject">
         SELECT rel.managerId AS 'userId',
                COUNT(DISTINCT rel.userId) AS 'operationNum',
-               IFNULL(SUM(cur.accountNum), 0) AS 'accountNum',
-               IFNULL(SUM(cur.projectNum), 0) AS 'projectNums',
-               IFNULL(SUM(cur.totalCost), 0) AS 'totalCost',
-               IFNULL(SUM(prev.lastCost), 0) AS 'lastCost',
+               IFNULL(SUM(metrics.accountNum), 0) AS 'accountNum',
+               IFNULL(SUM(metrics.projectNum), 0) AS 'projectNums',
+               IFNULL(SUM(metrics.totalCost), 0) AS 'totalCost',
+               IFNULL(SUM(metrics.lastCost), 0) AS 'lastCost',
                CASE
-                   WHEN IFNULL(SUM(prev.lastCost), 0) = 0 THEN '0%'
-                   ELSE CONCAT(CAST(ROUND((IFNULL(SUM(cur.totalCost), 0) - SUM(prev.lastCost)) / SUM(prev.lastCost) * 100, 2) AS CHAR), '%')
+                   WHEN IFNULL(SUM(metrics.lastCost), 0) = 0 THEN '0%'
+                   ELSE CONCAT(CAST(ROUND((IFNULL(SUM(metrics.totalCost), 0) - SUM(metrics.lastCost)) / SUM(metrics.lastCost) * 100, 2) AS CHAR), '%')
                    END AS 'yearOnYearCost',
                NULL AS 'unitNum',
                NULL AS 'projectNum'
@@ -666,47 +742,57 @@
                  <include refid="adqOperateGroupRelationTable"/>
              ) rel
                  LEFT JOIN (
-            SELECT /*+ READ_FROM_STORAGE(TIKV[d]) */ d.user_id,
-                   COUNT(DISTINCT d.account_id) AS 'accountNum',
-                   COUNT(DISTINCT d.project_id) AS 'projectNum',
-                   SUM(d.cost) AS 'totalCost'
+            SELECT d.user_id,
+                   COUNT(DISTINCT CASE
+                                      WHEN d.stat_date >= #{startDate}
+                                          AND d.stat_date &lt;= #{endDate}
+                                          AND d.stat_hour &lt;= #{hour}
+                                          AND d.cost > 0
+                                          THEN d.account_id
+                       END) AS 'accountNum',
+                   COUNT(DISTINCT CASE
+                                      WHEN d.stat_date >= #{startDate}
+                                          AND d.stat_date &lt;= #{endDate}
+                                          AND d.stat_hour &lt;= #{hour}
+                                          AND d.cost > 0
+                                          THEN d.project_id
+                       END) AS 'projectNum',
+                   IFNULL(SUM(CASE
+                                  WHEN d.stat_date >= #{startDate}
+                                      AND d.stat_date &lt;= #{endDate}
+                                      AND d.stat_hour &lt;= #{hour}
+                                      AND d.cost > 0
+                                      THEN d.cost
+                              END), 0) AS 'totalCost',
+                   IFNULL(SUM(CASE
+                                  WHEN d.stat_date >= #{lastTimeStart}
+                                      AND d.stat_date &lt;= #{lastTimeEnd}
+                                      AND d.stat_hour &lt;= #{hour}
+                                      AND d.cost > 0
+                                      THEN d.cost
+                              END), 0) AS 'lastCost'
             FROM application.adq_advertiser_report_hourly d
                      INNER JOIN (
                 <include refid="adqOperateGroupUsersTable"/>
             ) users ON users.userId = d.user_id
-            WHERE d.cost > 0
-              AND d.stat_hour &lt;= #{hour}
-              AND d.stat_date >= #{startDate}
+            WHERE d.stat_date >= #{lastTimeStart}
               AND d.stat_date &lt;= #{endDate}
             GROUP BY d.user_id
-        ) cur ON rel.userId = cur.user_id
-                 LEFT JOIN (
-            SELECT /*+ READ_FROM_STORAGE(TIKV[d]) */ d.user_id,
-                   SUM(d.cost) AS 'lastCost'
-            FROM application.adq_advertiser_report_hourly d
-                     INNER JOIN (
-                <include refid="adqOperateGroupUsersTable"/>
-            ) users ON users.userId = d.user_id
-            WHERE d.cost > 0
-              AND d.stat_hour &lt;= #{hour}
-              AND d.stat_date >= #{lastTimeStart}
-              AND d.stat_date &lt;= #{lastTimeEnd}
-            GROUP BY d.user_id
-        ) prev ON rel.userId = prev.user_id
+        ) metrics ON rel.userId = metrics.user_id
         GROUP BY rel.managerId
-        ORDER BY IFNULL(SUM(cur.totalCost), 0) DESC
+        ORDER BY IFNULL(SUM(metrics.totalCost), 0) DESC
     </select>
 
     <select id="getAdqOperateGroupInfoBatch" resultType="com.alibaba.fastjson.JSONObject">
         SELECT rel.managerId AS 'userId',
                COUNT(DISTINCT rel.userId) AS 'operationNum',
-               IFNULL(SUM(cur.accountNum), 0) AS 'accountNum',
-               IFNULL(SUM(cur.projectNum), 0) AS 'projectNums',
-               IFNULL(SUM(cur.totalCost), 0) AS 'totalCost',
-               IFNULL(SUM(prev.lastCost), 0) AS 'lastCost',
+               IFNULL(SUM(metrics.accountNum), 0) AS 'accountNum',
+               IFNULL(SUM(metrics.projectNum), 0) AS 'projectNums',
+               IFNULL(SUM(metrics.totalCost), 0) AS 'totalCost',
+               IFNULL(SUM(metrics.lastCost), 0) AS 'lastCost',
                CASE
-                   WHEN IFNULL(SUM(prev.lastCost), 0) = 0 THEN '0%'
-                   ELSE CONCAT(CAST(ROUND((IFNULL(SUM(cur.totalCost), 0) - SUM(prev.lastCost)) / SUM(prev.lastCost) * 100, 2) AS CHAR), '%')
+                   WHEN IFNULL(SUM(metrics.lastCost), 0) = 0 THEN '0%'
+                   ELSE CONCAT(CAST(ROUND((IFNULL(SUM(metrics.totalCost), 0) - SUM(metrics.lastCost)) / SUM(metrics.lastCost) * 100, 2) AS CHAR), '%')
                    END AS 'yearOnYearCost',
                NULL AS 'unitNum',
                NULL AS 'projectNum'
@@ -715,32 +801,40 @@
              ) rel
                  LEFT JOIN (
             SELECT d.user_id,
-                   COUNT(DISTINCT d.account_id) AS 'accountNum',
-                   COUNT(DISTINCT d.project_id) AS 'projectNum',
-                   SUM(d.cost) AS 'totalCost'
+                   COUNT(DISTINCT CASE
+                                      WHEN d.stat_date >= #{startDate}
+                                          AND d.stat_date &lt;= #{endDate}
+                                          AND d.cost > 0
+                                          THEN d.account_id
+                       END) AS 'accountNum',
+                   COUNT(DISTINCT CASE
+                                      WHEN d.stat_date >= #{startDate}
+                                          AND d.stat_date &lt;= #{endDate}
+                                          AND d.cost > 0
+                                          THEN d.project_id
+                       END) AS 'projectNum',
+                   IFNULL(SUM(CASE
+                                  WHEN d.stat_date >= #{startDate}
+                                      AND d.stat_date &lt;= #{endDate}
+                                      AND d.cost > 0
+                                      THEN d.cost
+                              END), 0) AS 'totalCost',
+                   IFNULL(SUM(CASE
+                                  WHEN d.stat_date >= #{lastTimeStart}
+                                      AND d.stat_date &lt;= #{lastTimeEnd}
+                                      AND d.cost > 0
+                                      THEN d.cost
+                              END), 0) AS 'lastCost'
             FROM application.adq_advertiser_report_daily d
                      INNER JOIN (
                 <include refid="adqOperateGroupUsersTable"/>
             ) users ON users.userId = d.user_id
-            WHERE d.cost > 0
-              AND d.stat_date >= #{startDate}
+            WHERE d.stat_date >= #{lastTimeStart}
               AND d.stat_date &lt;= #{endDate}
             GROUP BY d.user_id
-        ) cur ON rel.userId = cur.user_id
-                 LEFT JOIN (
-            SELECT d.user_id,
-                   SUM(d.cost) AS 'lastCost'
-            FROM application.adq_advertiser_report_daily d
-                     INNER JOIN (
-                <include refid="adqOperateGroupUsersTable"/>
-            ) users ON users.userId = d.user_id
-            WHERE d.cost > 0
-              AND d.stat_date >= #{lastTimeStart}
-              AND d.stat_date &lt;= #{lastTimeEnd}
-            GROUP BY d.user_id
-        ) prev ON rel.userId = prev.user_id
+        ) metrics ON rel.userId = metrics.user_id
         GROUP BY rel.managerId
-        ORDER BY IFNULL(SUM(cur.totalCost), 0) DESC
+        ORDER BY IFNULL(SUM(metrics.totalCost), 0) DESC
     </select>
 
 </mapper>

+ 21 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/xml/MaterialStareMapper.xml

@@ -1980,6 +1980,13 @@
                           INNER JOIN `application`.app_user_manage m ON u.id = m.user_id
                           INNER JOIN `jeecg-boot`.sys_user_role ur ON u.id = ur.user_id
                           INNER JOIN `jeecg-boot`.sys_role r ON ur.role_id = r.id
+                          INNER JOIN (
+                     SELECT DISTINCT report.user_id
+                     FROM application.kuaishou_account_report_hourly_dw report
+                     WHERE report.stat_date >= #{startDate}
+                       AND report.stat_date &lt;= #{endDate}
+                       AND report.charge > 0
+                 ) active_users ON active_users.user_id = u.id
                  WHERE m.manage_id IN
                        <foreach collection="managerIds" item="item" separator="," open="(" close=")">
                            #{item}
@@ -2003,6 +2010,13 @@
                           INNER JOIN `application`.app_user_manage m ON u.id = m.user_id
                           INNER JOIN `jeecg-boot`.sys_user_role ur ON u.id = ur.user_id
                           INNER JOIN `jeecg-boot`.sys_role r ON ur.role_id = r.id
+                          INNER JOIN (
+                     SELECT DISTINCT report.user_id
+                     FROM application.bytedance_advertiser_report_hourly_dw report
+                     WHERE report.stat_datetime >= #{startDate}
+                       AND report.stat_datetime &lt;= #{endDate}
+                       AND report.cost > 0
+                 ) active_users ON active_users.user_id = u.id
                  WHERE m.manage_id IN
                        <foreach collection="managerIds" item="item" separator="," open="(" close=")">
                            #{item}
@@ -2026,6 +2040,13 @@
                           INNER JOIN `application`.app_user_manage m ON u.id = m.user_id
                           INNER JOIN `jeecg-boot`.sys_user_role ur ON u.id = ur.user_id
                           INNER JOIN `jeecg-boot`.sys_role r ON ur.role_id = r.id
+                          INNER JOIN (
+                     SELECT DISTINCT report.user_id
+                     FROM application.adq_advertiser_report_hourly report
+                     WHERE report.stat_date >= #{startDate}
+                       AND report.stat_date &lt;= #{endDate}
+                       AND report.cost > 0
+                 ) active_users ON active_users.user_id = u.id
                  WHERE m.manage_id IN
                        <foreach collection="managerIds" item="item" separator="," open="(" close=")">
                            #{item}

+ 8 - 56
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/impl/AdqAdvertiserReportServiceImpl.java

@@ -198,69 +198,21 @@ public class AdqAdvertiserReportServiceImpl implements IAdqAdvertiserReportServi
             if (managerIds.isEmpty()) {
                 return Result.successMsg("查询成功。", new PageInfo<>(list));
             }
-            Map<String, Set<String>> teamMembers = dashboardQuerySupport.getOperateTeamMembers("16", managerIds, startDate, entDate);
-            List<String> allUserIds = teamMembers.values().stream().flatMap(Set::stream).distinct().collect(Collectors.toList());
-            if (allUserIds.isEmpty()) {
-                return Result.successMsg("查询成功。", new PageInfo<>(list));
-            }
-            CompletableFuture<Map<String, JSONObject>> currentFuture;
-            CompletableFuture<Map<String, JSONObject>> previousFuture;
             if (startTime.equals(endTime) && startTime.equals(nowDateStr)) {
-                currentFuture = CompletableFuture.supplyAsync(() -> toMetricMap(adqAdvertiserReportMapper.getOperateGroupCurrentHourlyByUsers(hour, startDate, entDate, allUserIds)));
-                previousFuture = CompletableFuture.supplyAsync(() -> toMetricMap(adqAdvertiserReportMapper.getOperateGroupPreviousHourlyByUsers(hour, lastTimeStart, lastTimeEnd, allUserIds)));
+                list = adqAdvertiserReportMapper.getAdqOperateGroupInfoHourlyBatch(managerIds, hour, startDate, entDate, lastTimeEnd, lastTimeStart);
             } else {
-                currentFuture = CompletableFuture.supplyAsync(() -> toMetricMap(adqAdvertiserReportMapper.getOperateGroupCurrentByUsers(startDate, entDate, allUserIds)));
-                previousFuture = CompletableFuture.supplyAsync(() -> toMetricMap(adqAdvertiserReportMapper.getOperateGroupPreviousByUsers(lastTimeStart, lastTimeEnd, allUserIds)));
+                list = adqAdvertiserReportMapper.getAdqOperateGroupInfoBatch(managerIds, startDate, entDate, lastTimeEnd, lastTimeStart);
             }
-            Map<String, JSONObject> currentMap = currentFuture.join();
-            Map<String, JSONObject> previousMap = previousFuture.join();
-            for (KuaiShouOperateGroupVo groupVo : operationManagerList) {
-                Set<String> memberIds = teamMembers.get(groupVo.getUserId());
-                if (memberIds == null || memberIds.isEmpty()) {
-                    continue;
-                }
-                List<String> activeMemberIds = memberIds.stream().filter(currentMap::containsKey).collect(Collectors.toList());
-                if (activeMemberIds.isEmpty()) {
-                    continue;
-                }
-                JSONObject row = new JSONObject();
-                row.put("userId", groupVo.getUserId());
-                row.put("realname", managerNameMap.get(groupVo.getUserId()));
-                row.put("operationNum", activeMemberIds.size());
-                long accountNum = 0L;
-                long projectNums = 0L;
-                double totalCost = 0D;
-                double lastCost = 0D;
-                for (String memberId : activeMemberIds) {
-                    JSONObject current = currentMap.get(memberId);
-                    if (current != null) {
-                        accountNum += getLong(current, "accountNum");
-                        projectNums += getLong(current, "projectNum");
-                        totalCost += getDouble(current, "totalCost");
-                    }
-                    JSONObject previous = previousMap.get(memberId);
-                    if (previous != null) {
-                        lastCost += getDouble(previous, "lastCost");
-                    }
-                }
-                int operationNum = activeMemberIds.size();
-                row.put("accountNum", accountNum);
-                row.put("projectNums", projectNums);
-                row.put("totalCost", totalCost);
-                row.put("lastCost", lastCost);
+            for (JSONObject row : list) {
+                row.put("realname", managerNameMap.get(row.getString("userId")));
+                double totalCost = getDouble(row, "totalCost");
+                double lastCost = getDouble(row, "lastCost");
+                int operationNum = row.getInteger("operationNum") == null ? 0 : row.getInteger("operationNum");
+                long accountNum = getLong(row, "accountNum");
                 row.put("yearOnYearCost", lastCost == 0D ? "0%" : new BigDecimal((totalCost - lastCost) / lastCost * 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "%");
                 row.put("averageDayCost", new BigDecimal(totalCost / (days + 1)).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                 row.put("averagePeopleCost", new BigDecimal(operationNum == 0 ? 0D : totalCost / operationNum).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
                 row.put("averageAccountCost", new BigDecimal(accountNum == 0 ? 0D : totalCost / accountNum).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
-                list.add(row);
-            }
-            if (!Check.isNull(list)) {
-                Collections.sort(list, new Comparator<JSONObject>() {
-                    @Override
-                    public int compare(JSONObject o1, JSONObject o2) {
-                        return o2.getDouble("totalCost").compareTo(o1.getDouble("totalCost"));
-                    }
-                });
             }
             PageInfo<JSONObject> pageInfo = new PageInfo<>(list);
             return Result.successMsg("查询成功。", pageInfo);

+ 1 - 6
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/impl/SafeTiFlashInterceptor.java

@@ -19,7 +19,7 @@ import java.util.Properties;
 
 /**
  * 按 mapper 维度切换 TiDB 读引擎。
- * 腾讯报表只能走 tikv,快手/头条原有报表在 tiflash 下明显更快
+ * 当前报表查询统一走 tiflash,tidb
  */
 @Intercepts({
         @Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})
@@ -30,8 +30,6 @@ public class SafeTiFlashInterceptor implements Interceptor {
     private static final Logger log = LoggerFactory.getLogger(SafeTiFlashInterceptor.class);
 
     private static final String MATERIAL_MAPPER_PREFIX = "org.jeecg.ctop.material.mapper.";
-    private static final String ADQ_MAPPER_PREFIX = MATERIAL_MAPPER_PREFIX + "AdqAdvertiserReportMapper";
-    private static final String TIKV_ENGINE = "tikv";
     private static final String TIFLASH_ENGINE = "tiflash,tidb";
 
     @Override
@@ -64,9 +62,6 @@ public class SafeTiFlashInterceptor implements Interceptor {
         if (statementId == null || !statementId.startsWith(MATERIAL_MAPPER_PREFIX)) {
             return null;
         }
-        if (statementId.startsWith(ADQ_MAPPER_PREFIX)) {
-            return TIKV_ENGINE;
-        }
         return TIFLASH_ENGINE;
     }
 

+ 1 - 1
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/support/DashboardQuerySupport.java

@@ -53,7 +53,7 @@ public class DashboardQuerySupport {
             return Collections.emptyMap();
         }
         String managerKey = managerIds.stream().sorted().collect(Collectors.joining(","));
-        String cacheKey = "dashboard:team:" + managerKey;
+        String cacheKey = "dashboard:team:" + mediaId + ":" + managerKey + ":" + startDate + ":" + endDate;
         List<JSONObject> rows = dashboardLocalCacheService.get(cacheKey, TEAM_MEMBER_CACHE_TTL, () -> loadOperateTeamMembers(mediaId, managerIds, startDate, endDate));
         Map<String, Set<String>> result = new HashMap<>();
         if (rows == null) {