mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-11 06:57:12 +08:00
refactor: 重构仪表盘查询地域分析接口
This commit is contained in:
@@ -99,6 +99,13 @@ public interface LogMapper extends BaseMapper<LogDO> {
|
||||
@Cached(key = "#months[0]", name = CacheConstants.DASHBOARD_KEY_PREFIX + "IP:")
|
||||
List<DashboardChartCommonResp> selectListDashboardAnalysisIp(@Param("months") List<String> months);
|
||||
|
||||
/**
|
||||
* 查询仪表盘地域分析信息
|
||||
*
|
||||
* @return 仪表盘地域分析信息
|
||||
*/
|
||||
List<DashboardChartCommonResp> selectListDashboardAnalysisGeo();
|
||||
|
||||
/**
|
||||
* 查询仪表盘访问趋势信息
|
||||
*
|
||||
@@ -116,14 +123,6 @@ public interface LogMapper extends BaseMapper<LogDO> {
|
||||
*/
|
||||
List<DashboardChartCommonResp> selectListDashboardAnalysisTimeslot();
|
||||
|
||||
/**
|
||||
* 查询仪表盘地域分析信息
|
||||
*
|
||||
* @param top 显示数量
|
||||
* @return 仪表盘地域分析信息
|
||||
*/
|
||||
List<DashboardChartCommonResp> selectListDashboardAnalysisGeo(@Param("top") Integer top);
|
||||
|
||||
/**
|
||||
* 查询仪表盘模块分析信息
|
||||
*
|
||||
|
@@ -16,8 +16,12 @@
|
||||
|
||||
package top.continew.admin.system.service;
|
||||
|
||||
import top.continew.admin.system.model.resp.dashboard.*;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardAccessTrendResp;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardOverviewCommonResp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -49,6 +53,14 @@ public interface DashboardService {
|
||||
*/
|
||||
DashboardOverviewCommonResp getOverviewIp();
|
||||
|
||||
/**
|
||||
* 查询地域分析信息
|
||||
*
|
||||
* @return 地域分析信息
|
||||
* @throws IOException /
|
||||
*/
|
||||
List<DashboardChartCommonResp> getAnalysisGeo() throws IOException;
|
||||
|
||||
/**
|
||||
* 查询访问趋势信息
|
||||
*
|
||||
@@ -64,13 +76,6 @@ public interface DashboardService {
|
||||
*/
|
||||
List<DashboardChartCommonResp> getAnalysisTimeslot();
|
||||
|
||||
/**
|
||||
* 查询地域分析信息
|
||||
*
|
||||
* @return 地域分析信息
|
||||
*/
|
||||
List<DashboardChartCommonResp> getAnalysisGeo();
|
||||
|
||||
/**
|
||||
* 查询模块分析信息
|
||||
*
|
||||
|
@@ -17,9 +17,17 @@
|
||||
package top.continew.admin.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.*;
|
||||
import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.continew.admin.system.mapper.LogMapper;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardAccessTrendResp;
|
||||
@@ -28,7 +36,9 @@ import top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardOverviewCommonResp;
|
||||
import top.continew.admin.system.service.DashboardService;
|
||||
import top.continew.admin.system.service.NoticeService;
|
||||
import top.continew.starter.core.constant.StringConstants;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
@@ -78,6 +88,31 @@ public class DashboardServiceImpl implements DashboardService {
|
||||
return resp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardChartCommonResp> getAnalysisGeo() throws IOException {
|
||||
List<DashboardChartCommonResp> originList = logMapper.selectListDashboardAnalysisGeo();
|
||||
List<DashboardChartCommonResp> list = new ArrayList<>(34);
|
||||
// 获取省份数据
|
||||
String chinaJson = IoUtil.readUtf8(new ClassPathResource("china.json").getInputStream());
|
||||
JSONArray jsonArr = JSONUtil.parseObj(chinaJson).getJSONArray("children");
|
||||
List<String> provinceList = jsonArr.stream().map(item -> {
|
||||
JSONObject itemJsonObj = JSONUtil.parseObj(item);
|
||||
return "%s:%s".formatted(itemJsonObj.getStr("name"), itemJsonObj.getStr("fullname"));
|
||||
}).toList();
|
||||
// 汇总各省份访问数据
|
||||
for (String province : provinceList) {
|
||||
String[] split = province.split(StringConstants.COLON);
|
||||
String name = split[0];
|
||||
String fullName = split[1];
|
||||
long sum = originList.stream()
|
||||
.filter(item -> item.getName().contains(name))
|
||||
.mapToLong(DashboardChartCommonResp::getValue)
|
||||
.sum();
|
||||
list.add(new DashboardChartCommonResp(fullName, sum));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardAccessTrendResp> listAccessTrend(Integer days) {
|
||||
DateTime currentDate = DateUtil.date();
|
||||
@@ -113,12 +148,6 @@ public class DashboardServiceImpl implements DashboardService {
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardChartCommonResp> getAnalysisGeo() {
|
||||
List<DashboardChartCommonResp> list = logMapper.selectListDashboardAnalysisGeo(9);
|
||||
return this.buildOtherPieChartData(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardChartCommonResp> getAnalysisModule() {
|
||||
return logMapper.selectListDashboardAnalysisModule(10);
|
||||
|
@@ -83,6 +83,18 @@
|
||||
ORDER BY name
|
||||
</select>
|
||||
|
||||
<select id="selectListDashboardAnalysisGeo" resultType="top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp">
|
||||
SELECT
|
||||
CASE
|
||||
WHEN POSITION(' ' IN address) > 0 THEN SUBSTRING(address FROM 1 FOR POSITION(' ' IN address) - 1)
|
||||
ELSE address
|
||||
END AS name,
|
||||
COUNT(*) AS value
|
||||
FROM sys_log
|
||||
WHERE address LIKE '中国%'
|
||||
GROUP BY name
|
||||
</select>
|
||||
|
||||
<select id="selectListDashboardAccessTrend"
|
||||
resultType="top.continew.admin.system.model.resp.dashboard.DashboardAccessTrendResp">
|
||||
SELECT
|
||||
@@ -105,19 +117,6 @@
|
||||
ORDER BY name
|
||||
</select>
|
||||
|
||||
<select id="selectListDashboardAnalysisGeo" resultType="top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp">
|
||||
SELECT
|
||||
CASE
|
||||
WHEN POSITION(' ' IN address) > 0 THEN SUBSTRING(address FROM 1 FOR POSITION(' ' IN address) - 1)
|
||||
ELSE address
|
||||
END AS name,
|
||||
COUNT(DISTINCT ip) AS value
|
||||
FROM sys_log
|
||||
GROUP BY name
|
||||
ORDER BY value DESC
|
||||
LIMIT #{top}
|
||||
</select>
|
||||
|
||||
<select id="selectListDashboardAnalysisModule"
|
||||
resultType="top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp">
|
||||
SELECT
|
||||
|
Reference in New Issue
Block a user