Przeglądaj źródła

数据补全+排序

zhaoxian 4 lat temu
rodzic
commit
c129a28c7c

+ 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);