Browse Source

Merge remote-tracking branch 'origin/V1.1.5' into V1.1.5

syh 4 năm trước cách đây
mục cha
commit
3efb7c228d

+ 3 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/EtlKuaishouAudienceAccountDailyMapper.xml

@@ -121,7 +121,7 @@
             </if>
         </if>
         IFNULL(ad_scene,'全部') as 'type'
-        FROM ctop_kuaishou_report_daily_account
+        FROM ctop_kuaishou_report_daily_account_ad_scene
         where stat_date = #{day}
         AND account_id = #{accountId}
         group by stat_date,ad_scene
@@ -130,7 +130,7 @@
 
     <select id="getSceneTypeList" resultType="java.lang.String">
         SELECT DISTINCT IFNULL(ad_scene, '全部')
-        FROM ctop_kuaishou_report_daily_account
+        FROM ctop_kuaishou_report_daily_account_ad_scene
         WHERE LENGTH(trim(ad_scene))>0
         ORDER BY ad_scene
     </select>
@@ -164,7 +164,7 @@
             </if>
         </if>
         IFNULL(ad_scene,'全部')as 'type'
-        FROM ctop_kuaishou_report_daily_account
+        FROM ctop_kuaishou_report_daily_account_ad_scene
         where stat_date &gt;= DATE_FORMAT(date_sub(now(), interval 8 day), '%Y-%m-%d')
         AND stat_date &lt;= DATE_FORMAT(date_sub(now(), interval 2 day), '%Y-%m-%d')
         AND account_id = #{accountId}

+ 47 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/EtlKuaishouReportAccountHourlyServiceImpl.java

@@ -131,6 +131,8 @@ public class EtlKuaishouReportAccountHourlyServiceImpl extends ServiceImpl<EtlKu
             todayList = etlHourlyAccountMapper.getOnedayEtlReportList(startTime, accountId, value, type);
             String lastDay = DateUtils.getLastDay(startTime, 1);
             yesterdayList = etlHourlyAccountMapper.getOnedayEtlReportList(lastDay, accountId, value, type);
+            completionTime(todayList);
+            completionTime(yesterdayList);
         } else {
             updateTime = etlDailyAccountMapper.getNewlyUpdateTime();
             todayList = etlDailyAccountMapper.getOnedayEtlReportList(startTime, endTime, accountId, value, type);
@@ -144,14 +146,14 @@ public class EtlKuaishouReportAccountHourlyServiceImpl extends ServiceImpl<EtlKu
             List<String> dayList = null;
             if (days > todayNum) {
                 dayList = DateUtils.getDays(startTime, endTime);
-                completionTime(todayList, dayList);
+                completionDate(todayList, dayList);
             }
             if (days > yesterdayNum) {
                 dayList = DateUtils.getDays(startTime2, endTime2);
-                completionTime(yesterdayList, dayList);
+                completionDate(yesterdayList, dayList);
             }
-            userRechargeListSort(todayList);
-            userRechargeListSort(yesterdayList);
+            statDateListSort(todayList);
+            statDateListSort(yesterdayList);
         }
         obj.put("today", todayList);
         obj.put("yesterday", yesterdayList);
@@ -162,7 +164,7 @@ public class EtlKuaishouReportAccountHourlyServiceImpl extends ServiceImpl<EtlKu
     /**
      * 补全日期
      */
-    private void completionTime(List<JSONObject> dataList, List<String> dayList) {
+    private void completionDate(List<JSONObject> dataList, List<String> dayList) {
         List<String> newDayList = new ArrayList<>();
         for (JSONObject data : dataList) {
             newDayList.add(data.getString("statDate"));
@@ -177,7 +179,30 @@ public class EtlKuaishouReportAccountHourlyServiceImpl extends ServiceImpl<EtlKu
         }
     }
 
-    private static void userRechargeListSort(List<JSONObject> list) {
+    /**
+     * 补全时辰
+     */
+    private void completionTime(List<JSONObject> dataList) {
+        List<Integer> newDayList = new ArrayList<>();
+        for (JSONObject data : dataList) {
+            newDayList.add(data.getInteger("statHour"));
+        }
+        List<Integer> dayList = new ArrayList<>();
+        for (int i = 0; i < 23; i++) {
+            dayList.add(i);
+        }
+        for (Integer hour : dayList) {
+            if (!newDayList.contains(hour)) {
+                JSONObject obj = new JSONObject();
+                obj.put("statHour", hour);
+                obj.put("value", 0);
+                dataList.add(obj);
+            }
+        }
+        statHourListSort(dataList);
+    }
+
+    private static void statDateListSort(List<JSONObject> list) {
         Collections.sort(list, new Comparator<JSONObject>() {
             @Override
             public int compare(JSONObject o1, JSONObject o2) {
@@ -194,6 +219,22 @@ public class EtlKuaishouReportAccountHourlyServiceImpl extends ServiceImpl<EtlKu
         });
     }
 
+    private static void statHourListSort(List<JSONObject> list) {
+        Collections.sort(list, new Comparator<JSONObject>() {
+            @Override
+            public int compare(JSONObject o1, JSONObject o2) {
+                try {
+                    Integer dt1 = o1.getInteger("statHour");
+                    Integer dt2 = o2.getInteger("statHour");
+                    return dt1.compareTo(dt2);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                return 0;
+            }
+        });
+    }
+
     @Override
     public Result<Object> getMaxChargeAccountIdByUser(String userId) {
         JSONObject obj = etlDailyAccountMapper.getMaxChargeAccountId(userId);