feature (数据监控):查询teemlink库中的异常数据比率
This commit is contained in:
@ -183,7 +183,13 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>3.8.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- swagger2-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
|
@ -0,0 +1,113 @@
|
||||
package com.ruoyi.project.monitor.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.framework.redis.RedisCache;
|
||||
import com.ruoyi.framework.web.controller.BaseController;
|
||||
import com.ruoyi.framework.web.domain.AjaxResult;
|
||||
import com.ruoyi.framework.web.page.TableDataInfo;
|
||||
import com.ruoyi.project.monitor.domain.TeemLinkExt;
|
||||
import com.ruoyi.project.monitor.domain.TeemLinkMonitorQueryModel;
|
||||
import com.ruoyi.project.monitor.domain.TeemLinkTable;
|
||||
import com.ruoyi.project.monitor.service.ITeemLinkMonitorService;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
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 java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* teemlink数据监控
|
||||
*
|
||||
* @author lihe
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/monitor/teemlink")
|
||||
public class TeemLinkMonitorController extends BaseController {
|
||||
|
||||
@Value("${uv.formMonitor}")
|
||||
private String teemLinkPath;
|
||||
@Autowired
|
||||
private ITeemLinkMonitorService teemLinkMonitorService;
|
||||
// @Autowired
|
||||
// private RestTemplate restTemplate;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
/**
|
||||
* teemlink表单查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(TeemLinkMonitorQueryModel monitorQueryModel) {
|
||||
|
||||
List<TeemLinkExt> list = redisCache.getCacheList("teemlink_form");
|
||||
if (null == list || 0 == list.size()) {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Request request = new Request.Builder()
|
||||
.url(teemLinkPath)
|
||||
.build();
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
|
||||
TeemLinkTable[] arr = JSON.parseObject(response.body().string(), TeemLinkTable[].class);
|
||||
list = buildTeemLinkExt(Arrays.asList(arr));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<TeemLinkExt> selectList =
|
||||
list.stream()
|
||||
.filter(sp -> (StringUtils.isNotEmpty(monitorQueryModel.getTableName())
|
||||
&& ((sp.getTableChineseName().contains(monitorQueryModel.getTableName())) ||
|
||||
(sp.getTableDbName().contains(monitorQueryModel.getTableName()))) || (StringUtils.isEmpty(monitorQueryModel.getTableName())))
|
||||
).collect(Collectors.toList());
|
||||
int total = selectList.size();
|
||||
selectList = selectList.stream().skip((monitorQueryModel.getPageIndex() - 1) * monitorQueryModel.getPageSize())
|
||||
.limit(monitorQueryModel.getPageSize()).collect(Collectors.toList());
|
||||
|
||||
return getDataTable(selectList, total);
|
||||
}
|
||||
|
||||
private List<TeemLinkExt> buildTeemLinkExt(List<TeemLinkTable> teemLinkTables) {
|
||||
List<TeemLinkExt> linkExts = new LinkedList<>();
|
||||
|
||||
teemLinkTables.forEach(tableLinkTable -> {
|
||||
tableLinkTable.getColumns().forEach(teemLinkColumn -> {
|
||||
TeemLinkExt teemLinkExt = new TeemLinkExt();
|
||||
teemLinkExt.setTableChineseName(tableLinkTable.getChineseName());
|
||||
teemLinkExt.setTableDbName(tableLinkTable.getDbName());
|
||||
teemLinkExt.setColumnChineseName(teemLinkColumn.getChineseName());
|
||||
teemLinkExt.setColumnDbName(teemLinkColumn.getDbName());
|
||||
teemLinkExt.setFieldType(teemLinkColumn.getFieldType());
|
||||
teemLinkExt.setDictType(teemLinkColumn.getDictType());
|
||||
linkExts.add(teemLinkExt);
|
||||
});
|
||||
});
|
||||
|
||||
return linkExts;
|
||||
}
|
||||
|
||||
/**
|
||||
* teemlink表单数据统计
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/stat")
|
||||
public AjaxResult stat(@RequestParam("tableName") String tableName, @RequestParam("columnName") String columnName) {
|
||||
return AjaxResult.success(teemLinkMonitorService.stat(tableName, columnName));
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.ruoyi.project.monitor.domain;
|
||||
|
||||
/**
|
||||
* teemlink配置的表单列
|
||||
*/
|
||||
public class TeemLinkColumn {
|
||||
/**
|
||||
* 中文名称
|
||||
*/
|
||||
private String chineseName;
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
private String dbName;
|
||||
/**
|
||||
* 字段类型
|
||||
* 字符、日期、数值、字典
|
||||
*/
|
||||
private String fieldType;
|
||||
/**
|
||||
* 字典类型
|
||||
*/
|
||||
private String dictType;
|
||||
|
||||
public String getChineseName() {
|
||||
return chineseName;
|
||||
}
|
||||
|
||||
public void setChineseName(String chineseName) {
|
||||
this.chineseName = chineseName;
|
||||
}
|
||||
|
||||
public String getDbName() {
|
||||
return dbName;
|
||||
}
|
||||
|
||||
public void setDbName(String dbName) {
|
||||
this.dbName = dbName;
|
||||
}
|
||||
|
||||
public String getFieldType() {
|
||||
return fieldType;
|
||||
}
|
||||
|
||||
public void setFieldType(String fieldType) {
|
||||
this.fieldType = fieldType;
|
||||
}
|
||||
|
||||
public String getDictType() {
|
||||
return dictType;
|
||||
}
|
||||
|
||||
public void setDictType(String dictType) {
|
||||
this.dictType = dictType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TeemLinkColumn{" +
|
||||
"chineseName='" + chineseName + '\'' +
|
||||
", dbName='" + dbName + '\'' +
|
||||
", fieldType='" + fieldType + '\'' +
|
||||
", dictType='" + dictType + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.ruoyi.project.monitor.domain;
|
||||
|
||||
/**
|
||||
* 展示用的model
|
||||
* @author lihe
|
||||
*/
|
||||
public class TeemLinkExt {
|
||||
private String tableChineseName;
|
||||
private String tableDbName;
|
||||
private String columnChineseName;
|
||||
private String columnDbName;
|
||||
private String fieldType;
|
||||
private String dictType;
|
||||
private Float stat;
|
||||
|
||||
public String getTableChineseName() {
|
||||
return tableChineseName;
|
||||
}
|
||||
|
||||
public void setTableChineseName(String tableChineseName) {
|
||||
this.tableChineseName = tableChineseName;
|
||||
}
|
||||
|
||||
public String getTableDbName() {
|
||||
return tableDbName;
|
||||
}
|
||||
|
||||
public void setTableDbName(String tableDbName) {
|
||||
this.tableDbName = tableDbName;
|
||||
}
|
||||
|
||||
public String getColumnChineseName() {
|
||||
return columnChineseName;
|
||||
}
|
||||
|
||||
public void setColumnChineseName(String columnChineseName) {
|
||||
this.columnChineseName = columnChineseName;
|
||||
}
|
||||
|
||||
public String getColumnDbName() {
|
||||
return columnDbName;
|
||||
}
|
||||
|
||||
public void setColumnDbName(String columnDbName) {
|
||||
this.columnDbName = columnDbName;
|
||||
}
|
||||
|
||||
public String getFieldType() {
|
||||
return fieldType;
|
||||
}
|
||||
|
||||
public void setFieldType(String fieldType) {
|
||||
this.fieldType = fieldType;
|
||||
}
|
||||
|
||||
public String getDictType() {
|
||||
return dictType;
|
||||
}
|
||||
|
||||
public void setDictType(String dictType) {
|
||||
this.dictType = dictType;
|
||||
}
|
||||
|
||||
public Float getStat() {
|
||||
return stat;
|
||||
}
|
||||
|
||||
public void setStat(Float stat) {
|
||||
this.stat = stat;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.ruoyi.project.monitor.domain;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TeemLinkMonitorQueryModel {
|
||||
private Integer pageIndex;
|
||||
private Integer pageSize;
|
||||
private String tableName;
|
||||
private String columnName;
|
||||
|
||||
public Integer getPageIndex() {
|
||||
return pageIndex;
|
||||
}
|
||||
|
||||
public void setPageIndex(Integer pageIndex) {
|
||||
this.pageIndex = pageIndex;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getColumnName() {
|
||||
return columnName;
|
||||
}
|
||||
|
||||
public void setColumnName(String columnName) {
|
||||
this.columnName = columnName;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.ruoyi.project.monitor.domain;
|
||||
|
||||
/**
|
||||
* teemlink数据统计
|
||||
*
|
||||
* @author lihe
|
||||
*/
|
||||
public class TeemLinkStat {
|
||||
private Integer count;
|
||||
private Integer validCount;
|
||||
|
||||
public Integer getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(Integer count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public Integer getValidCount() {
|
||||
return validCount;
|
||||
}
|
||||
|
||||
public void setValidCount(Integer validCount) {
|
||||
this.validCount = validCount;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.ruoyi.project.monitor.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* teemlink配置的表单
|
||||
*
|
||||
* @author lihe
|
||||
*/
|
||||
public class TeemLinkTable {
|
||||
private String chineseName;
|
||||
private String dbName;
|
||||
private List<TeemLinkColumn> columns;
|
||||
|
||||
public String getChineseName() {
|
||||
return chineseName;
|
||||
}
|
||||
|
||||
public void setChineseName(String chineseName) {
|
||||
this.chineseName = chineseName;
|
||||
}
|
||||
|
||||
public String getDbName() {
|
||||
return dbName;
|
||||
}
|
||||
|
||||
public void setDbName(String dbName) {
|
||||
this.dbName = dbName;
|
||||
}
|
||||
|
||||
public List<TeemLinkColumn> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void setColumns(List<TeemLinkColumn> columns) {
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TeemLinkTable{" +
|
||||
"chineseName='" + chineseName + '\'' +
|
||||
", dbName='" + dbName + '\'' +
|
||||
", columns=" + columns +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package com.ruoyi.project.monitor.mapper;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.ruoyi.project.monitor.domain.TeemLinkStat;
|
||||
import com.ruoyi.project.monitor.domain.TeemLinkTable;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* teemlink数据监控
|
||||
*
|
||||
* @author lihe
|
||||
*/
|
||||
@DS("teemlink")
|
||||
public interface TeemLinkMonitorMapper {
|
||||
|
||||
/**
|
||||
* 查看某表的字段数据统计
|
||||
*
|
||||
* @param tableName
|
||||
* @param columnName
|
||||
* @return
|
||||
*/
|
||||
TeemLinkStat getColumnStat(@Param("tableName") String tableName, @Param("columnName") String columnName);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.ruoyi.project.monitor.service;
|
||||
|
||||
import com.ruoyi.project.monitor.domain.SysOperLog;
|
||||
import com.ruoyi.project.monitor.domain.TeemLinkStat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* teemlink 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ITeemLinkMonitorService {
|
||||
/**
|
||||
* 数据统计
|
||||
*
|
||||
* @param tableName
|
||||
* @param columnName
|
||||
* @return
|
||||
*/
|
||||
TeemLinkStat stat(String tableName, String columnName);
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.ruoyi.project.monitor.service.impl;
|
||||
|
||||
import com.ruoyi.project.monitor.domain.TeemLinkStat;
|
||||
import com.ruoyi.project.monitor.mapper.TeemLinkMonitorMapper;
|
||||
import com.ruoyi.project.monitor.service.ITeemLinkMonitorService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 服务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class TeemLinkMonitorServiceImpl implements ITeemLinkMonitorService {
|
||||
@Autowired
|
||||
private TeemLinkMonitorMapper teemLinkMonitorMapper;
|
||||
|
||||
@Override
|
||||
public TeemLinkStat stat(String tableName, String columnName) {
|
||||
return teemLinkMonitorMapper.getColumnStat(tableName, columnName);
|
||||
}
|
||||
}
|
@ -13,8 +13,9 @@ ruoyi:
|
||||
# 获取ip地址开关
|
||||
addressEnabled: false
|
||||
uv:
|
||||
dataUrl: http://172.16.30.74:9500/api
|
||||
aitificialOfficeBasePriceUrl: /price/office/artificial?yearMonth=%d&lastYearMonth=%d
|
||||
dataUrl: http://172.16.30.74:9500/api/
|
||||
aitificialOfficeBasePriceUrl: price/office/artificial?yearMonth=%d&lastYearMonth=%d
|
||||
formMonitor: http://172.16.30.247:9800/tables
|
||||
|
||||
# 开发环境配置
|
||||
server:
|
||||
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.project.monitor.mapper.TeemLinkMonitorMapper">
|
||||
<select id="getColumnStat" resultType="com.ruoyi.project.monitor.domain.TeemLinkStat">
|
||||
select count(1) as count,
|
||||
(select count(1) from ${tableName} where ${columnName} is not null and #{columnName}
|
||||
<![CDATA[ <> ]]> '') as validCount
|
||||
from ${tableName}
|
||||
</select>
|
||||
</mapper>
|
Reference in New Issue
Block a user