瀏覽代碼

首页分时数据,补全时辰

zhaoxian 1 年之前
父節點
當前提交
456e7357e0

+ 45 - 3
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/KuaishouItemCollectSamplesServiceImpl.java

@@ -779,7 +779,7 @@ public class KuaishouItemCollectSamplesServiceImpl implements IKuaishouItemColle
     }
 
     @Override
-    public JSONObject getKsGmvHour(Long userId, String type, String mediaId,String nowDate,String lastDate){
+    public JSONObject getKsGmvHour(Long userId, String type, String mediaId, String nowDate, String lastDate) {
         JSONObject returnJson = new JSONObject();
         String roleKey = userService.getRoleKeyByUserId(userId);
         List<Long> userList = null;
@@ -800,6 +800,8 @@ public class KuaishouItemCollectSamplesServiceImpl implements IKuaishouItemColle
             today = supplyChainService.getKsCourtshipGmvHourByDate(userList, nowDate);
             yesterday = supplyChainService.getKsCourtshipGmvHourByDate(userList, lastDate);
         }
+        completionTime(today);
+        completionTime(yesterday);
         JSONObject result = new JSONObject();
         result.put("today", today);
         result.put("yesterday", yesterday);
@@ -810,8 +812,48 @@ public class KuaishouItemCollectSamplesServiceImpl implements IKuaishouItemColle
         return returnJson;
     }
 
+    /**
+     * 补全时辰
+     */
+    private void completionTime(List<JSONObject> dataList) {
+        List<Integer> newDayList = new ArrayList<>();
+        for (JSONObject data : dataList) {
+            newDayList.add(data.getInteger("time"));
+        }
+        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("time", hour);
+                obj.put("charge", 0.00);
+                dataList.add(obj);
+            }
+        }
+        statHourListSort(dataList);
+    }
+
+    //排序
+    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("time");
+                    Integer dt2 = o2.getInteger("time");
+                    return dt1.compareTo(dt2);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                return 0;
+            }
+        });
+    }
+
     @Override
-    public JSONObject getBytedanceGmvHour(Long userId, String type, String mediaId,String nowDate,String lastDate) {
+    public JSONObject getBytedanceGmvHour(Long userId, String type, String mediaId, String nowDate, String lastDate) {
         JSONObject returnJson = new JSONObject();
 
         Long dataNow = Long.valueOf(nowDate.replace("-", ""));
@@ -831,7 +873,7 @@ public class KuaishouItemCollectSamplesServiceImpl implements IKuaishouItemColle
         List<JSONObject> yesterday = new ArrayList<>();
         if ("1".equals(type)) { // 渠道
 
-            today = supplyChainService.getBytedanceChannelGmvHourByDate(userList,dataNow);
+            today = supplyChainService.getBytedanceChannelGmvHourByDate(userList, dataNow);
             yesterday = supplyChainService.getBytedanceChannelGmvHourByDate(userList, lastDateNow);
         } else if ("2".equals(type)) {
             today = supplyChainService.getBytedanceCourtshipGmvHourByDate(userList, dataNow);