Browse Source

批量查询天数

lyhzzz 2 years ago
parent
commit
560e1dd3b6

+ 7 - 6
src/main/java/com/cdf/controller/api/PageDataApiController.java

@@ -12,11 +12,7 @@ import com.cdf.service.ITotalDataService;
 import com.cdf.util.DateUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import javax.naming.ldap.PagedResultsControl;
@@ -113,11 +109,16 @@ public class PageDataApiController {
 
 
     @GetMapping("/pageData")
-    public ResultData getPageData(@RequestParam (required = false) String day,
+    public ResultData getPageData(@RequestParam(required = false) String day,
                                   @RequestParam(required = false,defaultValue = "0") Integer type,
                                   @RequestParam(required = false) String startDay,
                                   @RequestParam(required = false) String endDay) throws Exception {
         return ResultData.ok(totalDataService.getByType(type,day,startDay,endDay));
     }
+
+    @PostMapping("/pageDataList")
+    public ResultData pageDataList(@RequestParam(required = false) List<String> days) throws Exception {
+        return ResultData.ok(totalDataService.getListByType(days));
+    }
 }
 

+ 4 - 0
src/main/java/com/cdf/service/ITotalDataService.java

@@ -3,6 +3,8 @@ package com.cdf.service;
 import com.cdf.entity.TotalData;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -14,4 +16,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
 public interface ITotalDataService extends IService<TotalData> {
 
     TotalData getByType(Integer type, String day,String startDay,String endDay) throws Exception;
+
+    List<TotalData> getListByType( List<String> days) throws Exception;
 }

+ 23 - 0
src/main/java/com/cdf/service/impl/TotalDataServiceImpl.java

@@ -10,7 +10,9 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -77,6 +79,27 @@ public class TotalDataServiceImpl extends ServiceImpl<ITotalDataMapper, TotalDat
         }
     }
 
+    @Override
+    public List<TotalData> getListByType(List<String> days) throws Exception {
+        LambdaQueryWrapper<TotalData> wrapper = new LambdaQueryWrapper<>();
+        wrapper.in(TotalData::getId,days);
+        List<TotalData> list = this.list(wrapper);
+
+        List<TotalData> voList = new ArrayList<>();
+        HashMap<String,TotalData> map = new HashMap<>();
+        for (TotalData totalData : list) {
+            map.put(totalData.getId(),totalData);
+        }
+        for (String day : days) {
+            TotalData totalData = map.get(day);
+            if(totalData == null){
+                totalData = newTotalData(day);
+            }
+            voList.add(totalData);
+        }
+        return voList;
+    }
+
     private TotalData newTotalData(String id ){
         TotalData totalData = new TotalData();
         totalData.setId(id);

+ 43 - 1
vr场景统计结果接口文档.md

@@ -4,7 +4,7 @@
  
  **HOST**: http://vr-admin.cdfmembers.com
  
- **Version**:1.0.0
+ **Version**:1.0.3
  
  ## 1、获取前一天统计结果
  
@@ -47,3 +47,45 @@
   "timestamp": 1655707020322
 }
  ```
+
+
+ ## 2、批量获取统计结果
+ 
+ **接口地址** `/api/pageDataList`
+ 
+ **请求方式** `POST`
+ 
+ 
+ **请求参数**
+ 
+ | 参数名称      | 参数说明      | 是否必须 | 数据类型     | 示例     |
+ | ------------ | -----------   | -------- | -------     | -----    |
+ | days          |日期数组 |  false   |   String[]   |[2022-06-18,2022-06-19,2022-09-14] |
+
+ 
+ 
+ 
+ **响应示例**
+ 
+ 
+ ```json
+{
+  "code": 0,             
+  "message": "操作成功",
+  "data": [
+       {
+          "id": "2022-06-18",   //日期 ,type为1时日期所在周的第一天,type为2时返回月份
+          "avgStopTime": 2,     //平均停留时间 /秒
+          "avgJump": 0,         //跳出率  保留4位小数
+          "avgClickGame": 0,    //寻宝游戏点击率  保留4位小数
+          "avgClickShop": 0,    //商品详情点击率  保留4位小数
+          "avgStepNum": 4,      //平均步数
+          "videoNum": 1,        //视频点击次数
+          "createTime": "2022-06-19 00:00:00",
+          "updateTime": "2022-06-19 00:00:00"
+        }
+  ],
+  "success": true,
+  "timestamp": 1655707020322
+}
+ ```