From 593516266a2588cd38ffa6a66da0af8f034600a0 Mon Sep 17 00:00:00 2001 From: wangliwen Date: Sun, 19 Jun 2022 12:52:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BA=E5=B8=82=E3=80=81=E5=A7=94=E5=8A=9E?= =?UTF-8?q?=E5=B1=80=20=E4=B8=A4=E7=B1=BB=E5=BA=94=E7=94=A8=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=8E=92=E5=90=8D=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/controller/CensusControllerV2.java | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 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 b667d4a6..aba43f78 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 @@ -2,11 +2,14 @@ package io.renren.common.controller; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; 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; import io.renren.modules.resourceBrowse.service.ResourceBrowseService; +import io.renren.modules.sys.dto.SysDeptDTO; import io.renren.modules.sys.service.SysDeptService; import io.renren.modules.sys.service.SysUserService; import io.swagger.annotations.Api; @@ -138,10 +141,23 @@ public class CensusControllerV2 { @GetMapping("/districtResourceRank") @ApiOperation("应用资源区县市排名") - @LogOperation("应用资源数量统计") + @LogOperation("应用资源区县市排名") public Result>> districtResourceRank() { + List> result = resourceRank(3); + return new Result().ok(result); + } + + @GetMapping("/cityResourceRank") + @ApiOperation("应用资源委办局排名") + @LogOperation("应用资源委办局排名") + public Result>> cityResourceRank() { + List> result = resourceRank(2); + return new Result().ok(result); + } + + private List> resourceRank(Integer type) { List> result = Collections.synchronizedList(new ArrayList<>()); - List> district = jdbcTemplate.queryForList("SELECT * FROM sys_dept WHERE type = 2"); + List> district = jdbcTemplate.queryForList("SELECT * FROM sys_dept WHERE type = " + type); List> listMap = district.stream().map(index -> { Map re = new LinkedHashMap<>(); @@ -149,22 +165,37 @@ public class CensusControllerV2 { logger.info(sql); Long count = jdbcTemplate.queryForObject(sql, Long.class); if (!"0".equals(index.get("pid").toString())) { // 有上级部门 - re.put(index.get("pid").toString(), count); + Optional sysDeptDTO = + Optional.ofNullable(sysDeptService.get(Long.valueOf(index.get("pid").toString()))); + if (sysDeptDTO.isPresent() && sysDeptDTO.get().getType() != null && sysDeptDTO.get().getType() >= 2) { + re.put(index.get("id").toString(), count); + } else { + re.put(index.get("pid").toString(), count); + } } else { re.put(index.get("id").toString(), count); } return re; - }).distinct().collect(Collectors.toList()); + }).collect(Collectors.toList()); Map>> i = - listMap.stream().collect(Collectors.groupingBy(m -> m.keySet().stream().findFirst().toString())); + listMap.stream().collect(Collectors.groupingBy(m -> m.keySet().stream().findFirst().get())); result = i.keySet().stream().map(index -> { Map re = new LinkedHashMap<>(); - re.put("deptId", index); + re.put("deptName", sysDeptService.get(Long.valueOf(index)).getName()); 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); + result.sort(Comparator.comparing(x -> { + ObjectMapper mapper = new ObjectMapper(); + try { + Map m = mapper.readValue(mapper.writeValueAsString(x), Map.class); + return Long.valueOf(m.get("count").toString()); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + ).reversed()); + return result; } }