From 2c99eb5590b22483d6b7cf9a52f6461e73c31eef Mon Sep 17 00:00:00 2001 From: wangliwen Date: Sun, 19 Jun 2022 09:56:16 +0800 Subject: [PATCH] ... --- renren-admin/pom.xml | 2 +- .../common/controller/CensusControllerV2.java | 82 +++++++++++++++++++ .../modules/security/config/ShiroConfig.java | 5 +- 3 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 renren-admin/src/main/java/io/renren/common/controller/CensusControllerV2.java diff --git a/renren-admin/pom.xml b/renren-admin/pom.xml index 140fa1bc..b44b8cb6 100644 --- a/renren-admin/pom.xml +++ b/renren-admin/pom.xml @@ -304,7 +304,7 @@ application-prod.yml - db/*.sql + diff --git a/renren-admin/src/main/java/io/renren/common/controller/CensusControllerV2.java b/renren-admin/src/main/java/io/renren/common/controller/CensusControllerV2.java new file mode 100644 index 00000000..ae4ddda4 --- /dev/null +++ b/renren-admin/src/main/java/io/renren/common/controller/CensusControllerV2.java @@ -0,0 +1,82 @@ +package io.renren.common.controller; + + +import io.renren.common.utils.Result; +import io.renren.modules.processForm.service.TAbilityApplicationService; +import io.renren.modules.resource.service.ResourceService; +import io.renren.modules.resourceBrowse.service.ResourceBrowseService; +import io.renren.modules.sys.service.SysDeptService; +import io.renren.modules.sys.service.SysUserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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.RestController; + +import java.util.*; +import java.util.concurrent.CompletableFuture; + + +/** + * 2022.6.19 版本 + */ +@Api(tags = "全局统计中心v2") +@RestController +@RequestMapping("/census/center/v2") +public class CensusControllerV2 { + private static Logger logger = LoggerFactory.getLogger(CensusControllerV2.class); + + @Autowired + private ResourceService resourceService; + @Autowired + private SysUserService sysUserService; + @Autowired + private TAbilityApplicationService tAbilityApplicationService; + @Autowired + private ResourceBrowseService resourceBrowseService; + @Autowired + private SysDeptService sysDeptService; + + @Value("${census.type}") + private String[] censusTypes; // 需要进行统计的资源类型 + + @GetMapping(value = "/whole_amount") + @ApiOperation("平台概览") + public Result>> wholeAmount() { + List> result = Collections.synchronizedList(new ArrayList<>()); + + CompletableFuture userAmount = CompletableFuture.supplyAsync(() -> { // 获取平台用户总数 + return sysUserService.countAllUser(); + }).thenAccept(sum -> { + result.add(new HashMap() { + { + put("amount", sum); + put("type", "用户量"); + } + }); + }); + + CompletableFuture pvAmount = CompletableFuture.supplyAsync(() -> { // 平台访问量 + return resourceService.countAllVisits(); + }).thenAccept(sum -> { + result.add(new HashMap() { + { + put("amount", sum); + put("type", "平台访问量"); + } + }); + }); + CompletableFuture all = CompletableFuture.allOf(userAmount, pvAmount); + all.join(); + result.sort(Comparator.comparing(x -> x.get("type").toString())); + return new Result>>().ok(result); + } + + public Result>> visitTrend() { + return null; + } +} diff --git a/renren-admin/src/main/java/io/renren/modules/security/config/ShiroConfig.java b/renren-admin/src/main/java/io/renren/modules/security/config/ShiroConfig.java index 9359ce5f..923c2a3b 100644 --- a/renren-admin/src/main/java/io/renren/modules/security/config/ShiroConfig.java +++ b/renren-admin/src/main/java/io/renren/modules/security/config/ShiroConfig.java @@ -9,10 +9,8 @@ import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSource import org.apache.shiro.spring.web.ShiroFilterFactoryBean; import org.apache.shiro.web.mgt.DefaultWebSecurityManager; import org.apache.shiro.web.session.mgt.DefaultWebSessionManager; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.stereotype.Component; import javax.servlet.Filter; import java.util.HashMap; @@ -83,8 +81,7 @@ public class ShiroConfig { */ filterMap.put("/upload", "anon"); filterMap.put("/upload/**", "anon"); - filterMap.put("/census/center/**", "anon"); // 全局各类统计 - + filterMap.put("/census/center/**", "anon"); // 全局各类统计 包含 /census/center/v2 filterMap.put("/**", "oauth2"); shiroFilter.setFilterChainDefinitionMap(filterMap);