From 46de17be4544de36ef40a6ace72390a5bfd6008b Mon Sep 17 00:00:00 2001 From: wangliwen Date: Sun, 19 Jun 2022 12:17:17 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=82=E3=80=82=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/controller/CensusControllerV2.java | 20 ++++++++++++++----- 1 file changed, 15 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 8c6ef76b..b667d4a6 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 @@ -136,24 +136,34 @@ public class CensusControllerV2 { return new Result().ok(result); } - @GetMapping("/applicationNum") + @GetMapping("/districtResourceRank") @ApiOperation("应用资源区县市排名") @LogOperation("应用资源数量统计") public Result>> districtResourceRank() { List> result = Collections.synchronizedList(new ArrayList<>()); List> district = jdbcTemplate.queryForList("SELECT * FROM sys_dept WHERE type = 2"); -// Map>> listMap -// = + List> 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); + String sql = String.format("SELECT COUNT(id) FROM tb_data_resource WHERE dept_id = %s AND type = '应用资源' AND del_flag = 0;", index.get("id").toString()); + logger.info(sql); + Long count = jdbcTemplate.queryForObject(sql, 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())); + }).distinct().collect(Collectors.toList()); + Map>> i = + listMap.stream().collect(Collectors.groupingBy(m -> m.keySet().stream().findFirst().toString())); + result = i.keySet().stream().map(index -> { + Map re = new LinkedHashMap<>(); + re.put("deptId", index); + re.put("count", i.get(index).stream().mapToLong(index_ -> index_.values().stream().mapToLong(count_ -> count_).sum()).sum()); + return re; + }).collect(Collectors.toList()); + return new Result().ok(result); }