From e0e157f0e5b23ff6e27ec7ae0ee028af6f2facd1 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Mon, 4 Nov 2024 20:59:47 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E4=BB=AA?= =?UTF-8?q?=E8=A1=A8=E7=9B=98=E6=9F=A5=E8=AF=A2=E5=9C=B0=E5=9F=9F=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/system/mapper/LogMapper.java | 15 +++---- .../system/service/DashboardService.java | 21 +++++---- .../service/impl/DashboardServiceImpl.java | 43 ++++++++++++++++--- .../src/main/resources/mapper/LogMapper.xml | 25 ++++++----- .../common/DashboardController.java | 24 ++++++----- continew-webapi/src/main/resources/china.json | 1 + 6 files changed, 83 insertions(+), 46 deletions(-) create mode 100644 continew-webapi/src/main/resources/china.json diff --git a/continew-module-system/src/main/java/top/continew/admin/system/mapper/LogMapper.java b/continew-module-system/src/main/java/top/continew/admin/system/mapper/LogMapper.java index 4f8edb9f..56045c17 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/mapper/LogMapper.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/mapper/LogMapper.java @@ -99,6 +99,13 @@ public interface LogMapper extends BaseMapper { @Cached(key = "#months[0]", name = CacheConstants.DASHBOARD_KEY_PREFIX + "IP:") List selectListDashboardAnalysisIp(@Param("months") List months); + /** + * 查询仪表盘地域分析信息 + * + * @return 仪表盘地域分析信息 + */ + List selectListDashboardAnalysisGeo(); + /** * 查询仪表盘访问趋势信息 * @@ -116,14 +123,6 @@ public interface LogMapper extends BaseMapper { */ List selectListDashboardAnalysisTimeslot(); - /** - * 查询仪表盘地域分析信息 - * - * @param top 显示数量 - * @return 仪表盘地域分析信息 - */ - List selectListDashboardAnalysisGeo(@Param("top") Integer top); - /** * 查询仪表盘模块分析信息 * diff --git a/continew-module-system/src/main/java/top/continew/admin/system/service/DashboardService.java b/continew-module-system/src/main/java/top/continew/admin/system/service/DashboardService.java index f4ea349c..8744cf84 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/service/DashboardService.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/service/DashboardService.java @@ -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 getAnalysisGeo() throws IOException; + /** * 查询访问趋势信息 * @@ -64,13 +76,6 @@ public interface DashboardService { */ List getAnalysisTimeslot(); - /** - * 查询地域分析信息 - * - * @return 地域分析信息 - */ - List getAnalysisGeo(); - /** * 查询模块分析信息 * diff --git a/continew-module-system/src/main/java/top/continew/admin/system/service/impl/DashboardServiceImpl.java b/continew-module-system/src/main/java/top/continew/admin/system/service/impl/DashboardServiceImpl.java index af3aa8ca..1c01b748 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/service/impl/DashboardServiceImpl.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/service/impl/DashboardServiceImpl.java @@ -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 getAnalysisGeo() throws IOException { + List originList = logMapper.selectListDashboardAnalysisGeo(); + List list = new ArrayList<>(34); + // 获取省份数据 + String chinaJson = IoUtil.readUtf8(new ClassPathResource("china.json").getInputStream()); + JSONArray jsonArr = JSONUtil.parseObj(chinaJson).getJSONArray("children"); + List 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 listAccessTrend(Integer days) { DateTime currentDate = DateUtil.date(); @@ -113,12 +148,6 @@ public class DashboardServiceImpl implements DashboardService { return list; } - @Override - public List getAnalysisGeo() { - List list = logMapper.selectListDashboardAnalysisGeo(9); - return this.buildOtherPieChartData(list); - } - @Override public List getAnalysisModule() { return logMapper.selectListDashboardAnalysisModule(10); diff --git a/continew-module-system/src/main/resources/mapper/LogMapper.xml b/continew-module-system/src/main/resources/mapper/LogMapper.xml index 27d4a334..64f322b7 100644 --- a/continew-module-system/src/main/resources/mapper/LogMapper.xml +++ b/continew-module-system/src/main/resources/mapper/LogMapper.xml @@ -83,6 +83,18 @@ ORDER BY name + + - -