Browse Source

getInfo 重写hot.json

lyhzzz 3 years ago
parent
commit
570b9a0a61

+ 25 - 18
src/main/java/com/cdf/controller/api/PageDataApiController.java

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.naming.ldap.PagedResultsControl;
+import java.sql.Time;
 import java.util.Date;
 import java.util.List;
 
@@ -36,6 +37,8 @@ public class PageDataApiController {
         LambdaQueryWrapper<PageData> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(PageData::getCdfCookieId,cookieId);
         wrapper.eq(PageData::getDay,DateUtil.getDay(new Date()));
+        wrapper.isNull(PageData::getInPageTime);
+
         List<PageData> list = pageDataService.list(wrapper);
         PageData pageData;
         if(list.size() <=0){
@@ -49,26 +52,30 @@ public class PageDataApiController {
         }else {
             pageData = list.get(0);
         }
-        if(!pageData.getUrl().equals(whereUrl) && pageData.getIsJump() ==1){
-            pageData.setIsJump(0);
-        }
         pageData.setUrl(whereUrl);
-        if(type == 1){
-            long time = DateUtil.getDateTime(pageData.getCreateTime());
-            pageData.setStopTime(new Date().getTime() - time );
-        }
-        if(type == 2){
-            pageData.setIsClickGame(1);
-        }
-        if(type == 3){
-            pageData.setIsClickShop(1);
-        }
-        if(type == 4){
-            pageData.setStepNum( pageData.getStepNum() + 1);
-        }
-        if(type == 5){
-            pageData.setVideoNum( pageData.getVideoNum() + 1);
+        switch (type){
+            case 0:
+                pageData.setInPageTime(DateUtil.getDateTime(new Date()));
+                break;
+            case 1:
+                pageData.setOutPageTime(DateUtil.getDateTime(new Date()));
+                long time = DateUtil.getDateTime(pageData.getInPageTime());
+                pageData.setStopTime(new Date().getTime() - time );
+                break;
+            case 2:
+                pageData.setIsClickGame(1);
+                break;
+            case 3:
+                pageData.setIsClickShop(1);
+                break;
+            case 4:
+                pageData.setStepNum( pageData.getStepNum() + 1);
+                break;
+            case 5:
+                pageData.setVideoNum( pageData.getVideoNum() + 1);
+                break;
         }
+        pageData.setUpdateTime(null);
         pageDataService.saveOrUpdate(pageData);
         return ResultData.ok();
     }

+ 1 - 1
src/main/java/com/cdf/controller/back/TestController.java

@@ -38,7 +38,7 @@ public class TestController {
     }
 
     @RequestMapping("/test/task")
-    public ResultData statisticsH5Data(@RequestParam(required = false) String day){
+    public ResultData statisticsH5Data(@RequestParam(required = false) String day) throws Exception {
         if(StringUtils.isNotBlank(day)){
             ScheduleTask.day = day;
         }

+ 6 - 3
src/main/java/com/cdf/entity/PageData.java

@@ -46,9 +46,6 @@ public class PageData implements Serializable {
     @TableField("is_click_shop")
     private Integer isClickShop;
 
-    @TableField("is_jump")
-    private Integer isJump;
-
     @TableField("stop_time")
     private Long stopTime;
 
@@ -74,5 +71,11 @@ public class PageData implements Serializable {
     @TableField("update_time")
     private String updateTime;
 
+    @TableField("in_page_time")
+    private String InPageTime;
+
+    @TableField("out_page_time")
+    private String outPageTime;
+
 
 }

+ 13 - 1
src/main/java/com/cdf/entity/TotalData.java

@@ -28,7 +28,7 @@ public class TotalData implements Serializable {
     private String id;
 
     /**
-     * 平均停留时间
+     * 平均停留时间 /秒
      */
     @TableField("avg_stop_time")
     private Long avgStopTime;
@@ -50,6 +50,16 @@ public class TotalData implements Serializable {
      */
     @TableField("avg_click_shop")
     private BigDecimal avgClickShop;
+    /**
+     * 平均步数
+     */
+    @TableField("avg_step_num")
+    private Long avgStepNum;
+    /**
+     * 视频点击次数
+     */
+    @TableField("video_num")
+    private Long videoNum;
 
     @TableField("create_time")
     private String createTime;
@@ -66,6 +76,8 @@ public class TotalData implements Serializable {
                 ", avgJump=" + avgJump +
                 ", avgClickGame=" + avgClickGame +
                 ", avgClickShop=" + avgClickShop +
+                ", avgStepNum=" + avgStepNum +
+                ", videoNum=" + videoNum +
                 ", createTime='" + createTime + '\'' +
                 ", updateTime='" + updateTime + '\'' +
                 '}';

+ 18 - 4
src/main/java/com/cdf/schedule/ScheduleTask.java

@@ -30,7 +30,7 @@ public class ScheduleTask {
 
     @Scheduled(cron = "0 0 0 * * ?")
     //@Scheduled(cron = "30 * * * * ?")
-    public void statisticsH5Data() {
+    public void statisticsH5Data() throws Exception {
         if(day == null){
             day = DateUtil.getDay(new Date(), -1);
         }
@@ -42,9 +42,10 @@ public class ScheduleTask {
         BigDecimal jumpCount = BigDecimal.ZERO;
         BigDecimal clickGameCount = BigDecimal.ZERO;
         BigDecimal clickShopCount = BigDecimal.ZERO;
+        Long totalVideoNum = 0L;
+        Long totalStepNum = 0L;
         for (PageData pageData : list) {
-            stopTimeCount += pageData.getStopTime();
-            if(pageData.getIsJump() == 1){
+            if(pageData.getStepNum() == 0){
                 jumpCount = jumpCount.add(new BigDecimal(1));
             }
             if(pageData.getIsClickGame() == 1){
@@ -53,16 +54,27 @@ public class ScheduleTask {
             if(pageData.getIsClickShop() == 1){
                 clickShopCount = clickShopCount.add(new BigDecimal(1));
             }
+            if(pageData.getStopTime() == 0){
+                String inPageTime = pageData.getInPageTime();
+                String outPageTime = pageData.getOutPageTime() == null ? day+ " 23:59:59" :pageData.getOutPageTime();
+                long time = DateUtil.getDateTime(outPageTime) - DateUtil.getDateTime(inPageTime);
+                pageData.setStopTime(time);
+            }
+            stopTimeCount += pageData.getStopTime();
+            totalVideoNum += pageData.getVideoNum();
+            totalStepNum += pageData.getStepNum();
         }
-        Long avgStopTime = 0L;
+        long avgStopTime = 0L;
         BigDecimal avgJump = BigDecimal.ZERO;
         BigDecimal avgClickGame = BigDecimal.ZERO;
         BigDecimal avgClickShop = BigDecimal.ZERO;
+        Long avgStepNum = 0L;
         if(list.size()>0){
             avgStopTime = (stopTimeCount / list.size())/1000;
             avgJump = jumpCount.divide(new BigDecimal(list.size()),4,BigDecimal.ROUND_HALF_UP);
             avgClickGame = clickGameCount.divide(new BigDecimal(list.size()),4,BigDecimal.ROUND_HALF_UP);
             avgClickShop = clickShopCount.divide(new BigDecimal(list.size()),4,BigDecimal.ROUND_HALF_UP);
+            avgStepNum = totalStepNum / list.size();
         }
         TotalData totalData = new TotalData();
         totalData.setId(day);
@@ -70,6 +82,8 @@ public class ScheduleTask {
         totalData.setAvgJump(avgJump);
         totalData.setAvgClickGame(avgClickGame);
         totalData.setAvgClickShop(avgClickShop);
+        totalData.setVideoNum(totalVideoNum);
+        totalData.setAvgStepNum(avgStepNum);
         totalDataService.saveOrUpdate(totalData);
 
         log.info("{发送{}的统计结果{}给海鲲,{}",day,totalData,DateUtil.getDateTime(new Date()));