。。。

This commit is contained in:
wangliwen 2022-06-19 12:17:17 +08:00
parent 8138361207
commit 46de17be45
1 changed files with 15 additions and 5 deletions

View File

@ -136,24 +136,34 @@ public class CensusControllerV2 {
return new Result().ok(result);
}
@GetMapping("/applicationNum")
@GetMapping("/districtResourceRank")
@ApiOperation("应用资源区县市排名")
@LogOperation("应用资源数量统计")
public Result<List<Map<String, Object>>> districtResourceRank() {
List<Map<String, Object>> result = Collections.synchronizedList(new ArrayList<>());
List<Map<String, Object>> district = jdbcTemplate.queryForList("SELECT * FROM sys_dept WHERE type = 2");
// Map<String, List<Map<String, Object>>> listMap
// =
List<Map<String, Long>> listMap =
district.stream().map(index -> {
Map<String, Long> 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<String, List<Map<String, Long>>> i =
listMap.stream().collect(Collectors.groupingBy(m -> m.keySet().stream().findFirst().toString()));
result = i.keySet().stream().map(index -> {
Map<String, Object> 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);
}