mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 10:57:13 +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 | ||||
|   | ||||
| @@ -31,11 +31,15 @@ import org.springframework.web.bind.annotation.PathVariable; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | ||||
| import top.continew.admin.common.constant.CacheConstants; | ||||
| 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 top.continew.admin.system.service.DashboardService; | ||||
| import top.continew.starter.core.util.validate.ValidationUtils; | ||||
| import top.continew.starter.log.core.annotation.Log; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
| @@ -72,6 +76,15 @@ public class DashboardController { | ||||
|         return dashboardService.getOverviewIp(); | ||||
|     } | ||||
|  | ||||
|     @Operation(summary = "查询地域分析", description = "查询地域分析") | ||||
|     @GetMapping("/analysis/geo") | ||||
|     @CachePenetrationProtect | ||||
|     @CacheRefresh(refresh = 7200) | ||||
|     @Cached(key = "'GEO'", name = CacheConstants.DASHBOARD_KEY_PREFIX, cacheType = CacheType.BOTH, syncLocal = true) | ||||
|     public List<DashboardChartCommonResp> getAnalysisGeo() throws IOException { | ||||
|         return dashboardService.getAnalysisGeo(); | ||||
|     } | ||||
|  | ||||
|     @Operation(summary = "查询访问趋势信息", description = "查询访问趋势信息") | ||||
|     @Parameter(name = "days", description = "日期数", example = "30", in = ParameterIn.PATH) | ||||
|     @GetMapping("/access/trend/{days}") | ||||
| @@ -92,15 +105,6 @@ public class DashboardController { | ||||
|         return dashboardService.getAnalysisTimeslot(); | ||||
|     } | ||||
|  | ||||
|     @Operation(summary = "查询地域分析", description = "查询地域分析") | ||||
|     @GetMapping("/analysis/geo") | ||||
|     @CachePenetrationProtect | ||||
|     @CacheRefresh(refresh = 7200) | ||||
|     @Cached(key = "'GEO'", name = CacheConstants.DASHBOARD_KEY_PREFIX, cacheType = CacheType.BOTH, syncLocal = true) | ||||
|     public List<DashboardChartCommonResp> getAnalysisGeo() { | ||||
|         return dashboardService.getAnalysisGeo(); | ||||
|     } | ||||
|  | ||||
|     @Operation(summary = "查询模块分析", description = "查询模块分析") | ||||
|     @GetMapping("/analysis/module") | ||||
|     @CachePenetrationProtect | ||||
|   | ||||
							
								
								
									
										1
									
								
								continew-webapi/src/main/resources/china.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								continew-webapi/src/main/resources/china.json
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Reference in New Issue
	
	Block a user