配置文件内不需统计的资源 排除接口出数据

This commit is contained in:
wangliwen 2022-06-23 10:29:07 +08:00
parent e43cc1bfdb
commit b140d7f4d6
1 changed files with 14 additions and 21 deletions

View File

@ -59,35 +59,28 @@ public class CensusController {
@ApiOperation("各类资源数目") @ApiOperation("各类资源数目")
public Result<List<Map<String, Object>>> resourceAmount() { public Result<List<Map<String, Object>>> resourceAmount() {
List<Map<String, Object>> dbAmount = resourceService.getAmountGroupByType(); List<Map<String, Object>> dbAmount = resourceService.getAmountGroupByType();
List<String> 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<Map<String, Object>> finalDbAmount = dbAmount;
List<String> temp = finalDbAmount.stream().map(index -> index.get("type").toString()).collect(Collectors.toList());
Arrays.stream(censusTypes).filter(index -> !temp.contains(index)).forEach(index -> { // 数据库内不存在的资源类型 Arrays.stream(censusTypes).filter(index -> !temp.contains(index)).forEach(index -> { // 数据库内不存在的资源类型
if (index.equals("数据资源")) { Map<String, Object> nullMap = new HashMap<String, Object>() {
Map<String, Object> nullMap = new HashMap<String, Object>() { {
{ put("amount", 0);
put("amount", 10413); put("type", index);
put("type", "数据资源"); }
} };
}; finalDbAmount.add(nullMap);
dbAmount.add(nullMap);
} else {
Map<String, Object> nullMap = new HashMap<String, Object>() {
{
put("amount", 0);
put("type", index);
}
};
dbAmount.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<String, Object> sumMap = new HashMap<String, Object>() { Map<String, Object> sumMap = new HashMap<String, Object>() {
{ {
put("amount", sum); put("amount", sum);
put("type", "资源汇聚总量"); put("type", "资源汇聚总量");
} }
}; };
dbAmount.add(sumMap); finalDbAmount.add(sumMap);
return new Result<List<Map<String, Object>>>().ok(dbAmount); return new Result<List<Map<String, Object>>>().ok(finalDbAmount);
} }
@GetMapping(value = "/whole_amount") @GetMapping(value = "/whole_amount")