提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.report.controller.admin.goview; |
H |
2 |
|
|
3 |
import cn.hutool.core.map.MapUtil; |
|
4 |
import cn.hutool.core.util.RandomUtil; |
|
5 |
import com.iailab.framework.common.pojo.CommonResult; |
|
6 |
import com.iailab.module.report.controller.admin.goview.vo.data.GoViewDataGetBySqlReqVO; |
|
7 |
import com.iailab.module.report.controller.admin.goview.vo.data.GoViewDataRespVO; |
|
8 |
import com.iailab.module.report.service.goview.GoViewDataService; |
|
9 |
import io.swagger.v3.oas.annotations.Operation; |
|
10 |
import io.swagger.v3.oas.annotations.tags.Tag; |
|
11 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
12 |
import org.springframework.validation.annotation.Validated; |
|
13 |
import org.springframework.web.bind.annotation.RequestBody; |
|
14 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
15 |
import org.springframework.web.bind.annotation.RequestParam; |
|
16 |
import org.springframework.web.bind.annotation.RestController; |
|
17 |
|
|
18 |
import javax.annotation.Resource; |
|
19 |
import javax.validation.Valid; |
|
20 |
|
|
21 |
import java.util.*; |
|
22 |
|
|
23 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
24 |
|
|
25 |
@Tag(name = "管理后台 - GoView 数据", description = "提供 SQL、HTTP 等数据查询的能力") |
|
26 |
@RestController |
|
27 |
@RequestMapping("/report/go-view/data") |
|
28 |
@Validated |
|
29 |
public class GoViewDataController { |
|
30 |
|
|
31 |
@Resource |
|
32 |
private GoViewDataService goViewDataService; |
|
33 |
|
|
34 |
@RequestMapping("/get-by-sql") |
|
35 |
@Operation(summary = "使用 SQL 查询数据") |
|
36 |
@PreAuthorize("@ss.hasPermission('report:go-view-data:get-by-sql')") |
|
37 |
public CommonResult<GoViewDataRespVO> getDataBySQL(@Valid @RequestBody GoViewDataGetBySqlReqVO reqVO) { |
|
38 |
return success(goViewDataService.getDataBySQL(reqVO.getSql())); |
|
39 |
} |
|
40 |
|
|
41 |
@RequestMapping("/get-by-http") |
|
42 |
@Operation(summary = "使用 HTTP 查询数据", description = "这个只是示例接口,实际应该每个查询,都要写一个接口") |
|
43 |
@PreAuthorize("@ss.hasPermission('report:go-view-data:get-by-http')") |
|
44 |
public CommonResult<GoViewDataRespVO> getDataByHttp( |
|
45 |
@RequestParam(required = false) Map<String, String> params, |
|
46 |
@RequestBody(required = false) String body) { // params、body 按照需要去接收,这里仅仅是示例 |
|
47 |
GoViewDataRespVO respVO = new GoViewDataRespVO(); |
|
48 |
// 1. 数据维度 |
|
49 |
respVO.setDimensions(Arrays.asList("日期", "PV", "UV")); // PV 是每天访问次数;UV 是每天访问人数 |
|
50 |
// 2. 明细数据列表 |
|
51 |
// 目前通过随机的方式生成。一般来说,这里你可以写逻辑来实现数据的返回 |
|
52 |
respVO.setSource(new LinkedList<>()); |
|
53 |
for (int i = 1; i <= 12; i++) { |
|
54 |
String date = "2021-" + (i < 10 ? "0" + i : i); |
|
55 |
Integer pv = RandomUtil.randomInt(1000, 10000); |
|
56 |
Integer uv = RandomUtil.randomInt(100, 1000); |
|
57 |
respVO.getSource().add(MapUtil.<String, Object>builder().put("日期", date) |
|
58 |
.put("PV", pv).put("UV", uv).build()); |
|
59 |
} |
|
60 |
return success(respVO); |
|
61 |
} |
|
62 |
|
|
63 |
} |