Browse Source

统计信息添加时间段统计

lyhzzz 3 years ago
parent
commit
fca152e63a

+ 4 - 2
src/main/java/com/cdf/controller/api/PageDataApiController.java

@@ -91,8 +91,10 @@ public class PageDataApiController {
 
 
     @GetMapping("/pageData")
     @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) throws Exception {
-        return ResultData.ok(totalDataService.getByType(type,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));
     }
     }
 }
 }
 
 

+ 1 - 1
src/main/java/com/cdf/service/ITotalDataService.java

@@ -13,5 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
  */
 public interface ITotalDataService extends IService<TotalData> {
 public interface ITotalDataService extends IService<TotalData> {
 
 
-    TotalData getByType(Integer type, String day) throws Exception;
+    TotalData getByType(Integer type, String day,String startDay,String endDay) throws Exception;
 }
 }

+ 14 - 1
src/main/java/com/cdf/service/impl/TotalDataServiceImpl.java

@@ -25,7 +25,7 @@ import java.util.List;
 public class TotalDataServiceImpl extends ServiceImpl<ITotalDataMapper, TotalData> implements ITotalDataService {
 public class TotalDataServiceImpl extends ServiceImpl<ITotalDataMapper, TotalData> implements ITotalDataService {
 
 
     @Override
     @Override
-    public TotalData getByType(Integer type, String time) throws Exception {
+    public TotalData getByType(Integer type, String time,String startDay,String endDay) throws Exception {
         switch (type){
         switch (type){
             case 0:     //日
             case 0:     //日
                 if(StringUtils.isEmpty(time)){
                 if(StringUtils.isEmpty(time)){
@@ -59,6 +59,19 @@ public class TotalDataServiceImpl extends ServiceImpl<ITotalDataMapper, TotalDat
                 }
                 }
                 month.setId(time);
                 month.setId(time);
                 return month;
                 return month;
+            case 3:     //时间段
+                if(StringUtils.isNotBlank(startDay) && StringUtils.isNotBlank(endDay)){
+                    TotalData totalData = this.getBaseMapper().getWeek(startDay, endDay);
+                    if(totalData == null){
+                        totalData = newTotalData(startDay +"-"+endDay);
+                    }
+                    totalData.setId(startDay +"-"+ endDay);
+                    return totalData;
+                }
+                if(StringUtils.isEmpty(time)){
+                    time = DateUtil.getDay(new Date(),-1);
+                }
+                return  this.getById(time) == null ? newTotalData(time) : this.getById(time);
             default:
             default:
                 throw new IllegalStateException("Unexpected value: " + type);
                 throw new IllegalStateException("Unexpected value: " + type);
         }
         }

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

@@ -18,7 +18,9 @@
  | 参数名称      | 参数说明      | 是否必须 | 数据类型     | 示例     |
  | 参数名称      | 参数说明      | 是否必须 | 数据类型     | 示例     |
  | ------------ | -----------   | -------- | -------     | -----    |
  | ------------ | -----------   | -------- | -------     | -----    |
  | day          | 具体日期(默认昨天,type为1时返回日期所在周的数据,不传默认上周。type为2时返回日期所在月份的数据,不传默认上个月)      |  false   |   String   |2022-06-18 |
  | day          | 具体日期(默认昨天,type为1时返回日期所在周的数据,不传默认上周。type为2时返回日期所在月份的数据,不传默认上个月)      |  false   |   String   |2022-06-18 |
- | type          | 类型(0:日,1:周,2:月)默认0    |  false   |   int      |0    |
+ | type          | 类型(0:日,1:周,2:月,3:自定义时间段)默认0    |  false   |   int      |0    |
+ | startDay          | 开始天数 (当type 为3时,不为空)   |  false   |   string      |2022-06-18   |
+ | endDay          | 结束天数 (当type 为3时,不为空)    |  false   |   string      |2022-06-30  |