StatisticsQueryController.java
4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.skua.modules.statisticsquery.controller;
import cn.hutool.core.util.PinyinUtil;
import com.google.common.base.CaseFormat;
import com.skua.aop.annotation.CustomExceptionAnno;
import com.skua.core.api.vo.Result;
import com.skua.core.context.SpringContextUtils;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.base.service.IBaseService;
import com.skua.modules.statisticsquery.constant.SQConstant;
import com.skua.modules.statisticsquery.dto.StatisticsQueryDTO;
import com.skua.modules.statisticsquery.enums.SQEnum;
import com.skua.modules.statisticsquery.service.IStatisticsQueryService;
import com.skua.modules.statisticsquery.service.IStatisticsSubService;
import com.skua.modules.statisticsquery.vo.StatisticsQueryVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.stream.Collectors;
/**
* <pre>
* 统计查询
* </pre>
*
* @author sonin
* @version 1.0 2023/9/22 14:13
*/
@Slf4j
@RestController
@RequestMapping("/statisticsQuery")
public class StatisticsQueryController {
@Autowired
private IStatisticsQueryService statisticsQueryService;
@Autowired
private IBaseService baseService;
@PostMapping(value = "/insertAlias")
@CustomExceptionAnno(description = "插入别名")
public Result<Object> insertAliasCtrl(@RequestBody List<Map<String, Object>> paramsMapList) {
Result<Object> result = new Result<>();
Date nowDate = new Date();
List<Map<String, Object>> resMapList = new ArrayList<>();
for (Map<String, Object> paramsMap : paramsMapList) {
String aliasName = ConvertUtils.getString(paramsMap.get("aliasName"));
String id = PinyinUtil.getPinYin(aliasName);
String nm = ConvertUtils.getString(paramsMap.get("nm"));
String remark = ConvertUtils.getString(paramsMap.get("remark"));
Map<String, Object> entityMap = new HashMap<String, Object>() {{
put("id", id);
put("nm", nm);
put("alias_name", aliasName);
put("alias_desc", aliasName);
put("remark", remark);
put("create_time", nowDate);
put("del_flag", "0");
}};
try {
baseService.insert(SQConstant.aliasTable, entityMap);
} catch (Exception e) {
e.printStackTrace();
}
resMapList.add(entityMap.keySet().stream().collect(Collectors.toMap(key -> CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, key), entityMap::get)));
}
result.setResult(resMapList);
return result;
}
/**
* <pre>
* 查询 xsinsert || xxx_count || realtimedata || f_report_itemv 表数据
* </pre>
*
* @param name
* @param asyncFlag 是否启用异步查询,默认false
* @param statisticsQueryDTOList
* @author sonin
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@PostMapping(value = "/multiDataSource/{name}")
@CustomExceptionAnno(description = "多重数据源数据")
public Result<Object> multiDataSourceCtrl(@PathVariable String name, @RequestParam(defaultValue = "0") String asyncFlag, @RequestParam(defaultValue = "0") String dataSourceFlag, @RequestBody List<StatisticsQueryDTO> statisticsQueryDTOList) {
Result<Object> result = new Result<>();
List<StatisticsQueryVO> statisticsQueryVOList;
// 判断查询哪种数据源
if ("0".equals(dataSourceFlag)) {
// 查询报表report
statisticsQueryVOList = statisticsQueryService.handleHistoryFunc(asyncFlag, statisticsQueryDTOList, SQEnum.REPORT);
} else if ("1".equals(dataSourceFlag)) {
// 查询history(xsinsert || xxx_count)
statisticsQueryVOList = statisticsQueryService.handleHistoryFunc(asyncFlag, statisticsQueryDTOList, SQEnum.HISTORY);
} else if ("2".equals(dataSourceFlag)) {
// 查询realtimedata
statisticsQueryVOList = statisticsQueryService.handleRealtimeFunc(statisticsQueryDTOList);
} else {
// 默认
statisticsQueryVOList = new ArrayList<>();
}
IStatisticsSubService statisticsSubService = (IStatisticsSubService) SpringContextUtils.getBean(name);
if (statisticsSubService != null) {
result.setResult(statisticsSubService.execute(statisticsQueryVOList));
} else {
result.setResult(statisticsQueryVOList);
}
return result;
}
}