From 8138361207a4fd2c2b1809e8e4c804b5056bc3db Mon Sep 17 00:00:00 2001 From: wangliwen Date: Sun, 19 Jun 2022 11:46:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=8A=A0=E4=B8=80=E4=B8=AA=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=8E=A7=E5=88=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/controller/CensusControllerV2.java | 88 +++++++++++++++++-- 1 file changed, 83 insertions(+), 5 deletions(-) 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 index ae4ddda4..8c6ef76b 100644 --- a/renren-admin/src/main/java/io/renren/common/controller/CensusControllerV2.java +++ b/renren-admin/src/main/java/io/renren/common/controller/CensusControllerV2.java @@ -1,6 +1,8 @@ package io.renren.common.controller; +import com.alibaba.fastjson.JSONObject; +import io.renren.common.annotation.LogOperation; import io.renren.common.utils.Result; import io.renren.modules.processForm.service.TAbilityApplicationService; import io.renren.modules.resource.service.ResourceService; @@ -13,12 +15,12 @@ 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 org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.web.bind.annotation.*; import java.util.*; import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; /** @@ -41,6 +43,9 @@ public class CensusControllerV2 { @Autowired private SysDeptService sysDeptService; + @Autowired + private JdbcTemplate jdbcTemplate; + @Value("${census.type}") private String[] censusTypes; // 需要进行统计的资源类型 @@ -76,7 +81,80 @@ public class CensusControllerV2 { return new Result>>().ok(result); } - public Result>> visitTrend() { - return null; + @PostMapping("/trafficStatistics") + @ApiOperation("浏览量统计") + @LogOperation("浏览量统计") + public Result trafficStatistics(@RequestBody JSONObject jsonObject) { + HashMap resultMap = new HashMap<>(); + String startDate = jsonObject.getString("startDate"); + String endDate = jsonObject.getString("endDate"); + resultMap.put("browseAvg", resourceBrowseService.selectDayAvg()); + resultMap.put("browseMax", resourceBrowseService.selectDayMax()); + resultMap.put("browseDayList", resourceBrowseService.selectDayList(startDate, endDate)); + return new Result().ok(resultMap); } + + + @GetMapping("/applicationNum") + @ApiOperation("应用资源数量统计") + @LogOperation("应用资源数量统计") + public Result>> applicationNum() { + List> result = Collections.synchronizedList(new ArrayList<>()); + + CompletableFuture allApplicationAmount = CompletableFuture.supplyAsync(() -> { // 获取平台总应用数目 + return jdbcTemplate.queryForObject("SELECT COUNT(id) FROM tb_data_resource WHERE type ='应用资源';", Long.class); + }).thenAccept(sum -> { + result.add(new HashMap() { + { + put("amount", sum); + put("type", "总应用数"); + } + }); + }); + CompletableFuture buildingApplicationAmount = CompletableFuture.supplyAsync(() -> { // 获取平台建设中数目 + return jdbcTemplate.queryForObject("SELECT COUNT(DISTINCT data_resource_id) FROM tb_data_attr WHERE attr_type = '应用状态' AND attr_value = '建设中';", Long.class); + }).thenAccept(sum -> { + result.add(new HashMap() { + { + put("amount", sum); + put("type", "建设中应用数"); + } + }); + }); + CompletableFuture endApplicationAmount = CompletableFuture.supplyAsync(() -> { // 获取平台建设中数目 + return jdbcTemplate.queryForObject("SELECT COUNT(DISTINCT data_resource_id) FROM tb_data_attr WHERE attr_type = '应用状态' AND attr_value = '停用';", Long.class); + }).thenAccept(sum -> { + result.add(new HashMap() { + { + put("amount", sum); + put("type", "停用应用数"); + } + }); + }); + CompletableFuture all = CompletableFuture.allOf(allApplicationAmount, buildingApplicationAmount, endApplicationAmount); + all.join(); + return new Result().ok(result); + } + + @GetMapping("/applicationNum") + @ApiOperation("应用资源区县市排名") + @LogOperation("应用资源数量统计") + public Result>> districtResourceRank() { + List> result = Collections.synchronizedList(new ArrayList<>()); + List> district = jdbcTemplate.queryForList("SELECT * FROM sys_dept WHERE type = 2"); +// Map>> listMap +// = + district.stream().map(index -> { + Map re = new LinkedHashMap<>(); + Long count = jdbcTemplate.queryForObject(String.format("SELECT COUNT(id) FROM tb_data_resource WHERE dept_id = %s AND type = '应用资源' AND del_flag = 0;", index.get("id").toString()), Long.class); + if (!"0".equals(index.get("pid").toString())) { // 有上级部门 + re.put(index.get("pid").toString(), count); + } else { + re.put(index.get("id").toString(), count); + } + return re; + }).distinct().collect(Collectors.groupingBy(m -> m.keySet().stream().findFirst().get())); + return new Result().ok(result); + } + }