diff --git a/renren-admin/src/main/java/io/renren/common/controller/CensusController.java b/renren-admin/src/main/java/io/renren/common/controller/CensusController.java index b9be86de..203125c1 100644 --- a/renren-admin/src/main/java/io/renren/common/controller/CensusController.java +++ b/renren-admin/src/main/java/io/renren/common/controller/CensusController.java @@ -59,35 +59,28 @@ public class CensusController { @ApiOperation("各类资源数目") public Result>> resourceAmount() { List> dbAmount = resourceService.getAmountGroupByType(); - List temp = dbAmount.stream().map(index -> index.get("type").toString()).collect(Collectors.toList()); + dbAmount = dbAmount.stream().filter(index -> Arrays.asList(censusTypes).contains(index.get("type").toString())).collect(Collectors.toList()); + List> finalDbAmount = dbAmount; + + List temp = finalDbAmount.stream().map(index -> index.get("type").toString()).collect(Collectors.toList()); Arrays.stream(censusTypes).filter(index -> !temp.contains(index)).forEach(index -> { // 数据库内不存在的资源类型 - if (index.equals("数据资源")) { - Map nullMap = new HashMap() { - { - put("amount", 10413); - put("type", "数据资源"); - } - }; - dbAmount.add(nullMap); - } else { - Map nullMap = new HashMap() { - { - put("amount", 0); - put("type", index); - } - }; - dbAmount.add(nullMap); - } + Map nullMap = new HashMap() { + { + put("amount", 0); + put("type", index); + } + }; + finalDbAmount.add(nullMap); }); - Long sum = dbAmount.stream().mapToLong(index -> Long.valueOf(index.get("amount").toString())).sum(); + Long sum = finalDbAmount.stream().mapToLong(index -> Long.valueOf(index.get("amount").toString())).sum(); Map sumMap = new HashMap() { { put("amount", sum); put("type", "资源汇聚总量"); } }; - dbAmount.add(sumMap); - return new Result>>().ok(dbAmount); + finalDbAmount.add(sumMap); + return new Result>>().ok(finalDbAmount); } @GetMapping(value = "/whole_amount")