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 + + - -