diff --git a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java index 3050c8e8..30ebf700 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java @@ -2056,67 +2056,84 @@ public class ResourceServiceImpl extends CrudServiceImpl> typeCountListByDept = resourceDao.selectDeptDetailTypeCountList(params); - Map>> typeCountListMap = // 市级部门 - typeCountListByDept.stream().filter(index -> index.get("deptType").toString().equals("2")).collect(Collectors.groupingBy(m -> m.get("dept_id").toString())); - List> resultList = getDeptTemp1(); - resultList.addAll(getDeptTemp2()); - Map countMap = new HashMap<>(); - resultList = resultList.stream().map(index -> { - if (typeCountListMap.keySet().contains(index.get("dept_id").toString())) { // 该部门存在上架信息 - index.put("count", typeCountListMap.get(index.get("dept_id").toString()).stream().mapToInt(it -> Integer.parseInt(it.get("count").toString())).sum()); - typeCountListMap.get(index.get("dept_id").toString()).stream().forEach(count -> { - index.put(count.get("type").toString(), count.get("count")); - if (countMap.containsKey(count.get("type"))) { - countMap.replace(count.get("type").toString(), Integer.parseInt(count.get("count").toString()) + countMap.get(count.get("type"))); + if (params.containsKey("deptId") && params.get("deptId") != null) { + List> typeCountListByDept = resourceDao.selectDeptDetailTypeCountList(params); + Map>> typeCountListMap = typeCountListByDept.stream().collect(Collectors.groupingBy(m -> m.get("deptName").toString())); + ArrayList resultList = new ArrayList<>(); + Map countMap = new HashMap<>(); + typeCountListMap.forEach((k, v) -> { + HashMap map = new HashMap<>(); + map.put("count", v.stream().mapToInt(it -> Integer.parseInt(it.get("count").toString())).sum()); + map.put("name", k); + v.forEach(item -> { + map.put(item.get("type").toString(), item.get("count")); + if (countMap.containsKey(item.get("type"))) { + countMap.replace(item.get("type").toString(), Integer.parseInt(item.get("count").toString()) + countMap.get(item.get("type"))); } else { - countMap.put(count.get("type").toString(), Integer.parseInt(count.get("count").toString())); + countMap.put(item.get("type").toString(), Integer.parseInt(item.get("count").toString())); } }); + resultList.add(map); + }); + Integer total = 0; + for (Integer count : countMap.values()) { + total += count; } - return index; - }).collect(Collectors.toList()); - Map>> typeCountListMap1 = // 区级部门 - typeCountListByDept.stream().filter(index -> index.get("deptType").toString().equals("3")).collect(Collectors.groupingBy(m -> m.get("district").toString())); - resultList = resultList.stream().map(index -> { - if (typeCountListMap1.keySet().contains(index.get("dept_id").toString())) { // 该部门存在上架信息 - index.put("count", typeCountListMap1.get(index.get("dept_id").toString()).stream().mapToInt(it -> Integer.parseInt(it.get("count").toString())).sum()); - typeCountListMap1.get(index.get("dept_id").toString()).stream().forEach(count -> { - index.put(count.get("type").toString(), Integer.parseInt(count.get("count").toString()) + Integer.parseInt(index.getOrDefault(count.get("type").toString(), "0").toString())); - if (countMap.containsKey(count.get("type"))) { - countMap.replace(count.get("type").toString(), Integer.parseInt(count.get("count").toString()) + countMap.get(count.get("type"))); - } else { - countMap.put(count.get("type").toString(), Integer.parseInt(count.get("count").toString())); - } - }); + countMap.put("count", total); + HashMap count = new HashMap<>(); + count.put("name", "总计"); + count.putAll(countMap); + resultList.add(count); + return resultList; + } else { // 全部部门 + List> typeCountListByDept = resourceDao.selectDeptDetailTypeCountList(params); + Map>> typeCountListMap = // 市级部门 + typeCountListByDept.stream().filter(index -> index.get("deptType").toString().equals("2")).collect(Collectors.groupingBy(m -> m.get("dept_id").toString())); + List> resultList = getDeptTemp1(); + resultList.addAll(getDeptTemp2()); + Map countMap = new HashMap<>(); + resultList = resultList.stream().map(index -> { + if (typeCountListMap.keySet().contains(index.get("dept_id").toString())) { // 该部门存在上架信息 + index.put("count", typeCountListMap.get(index.get("dept_id").toString()).stream().mapToInt(it -> Integer.parseInt(it.get("count").toString())).sum()); + typeCountListMap.get(index.get("dept_id").toString()).stream().forEach(count -> { + index.put(count.get("type").toString(), count.get("count")); + if (countMap.containsKey(count.get("type"))) { + countMap.replace(count.get("type").toString(), Integer.parseInt(count.get("count").toString()) + countMap.get(count.get("type"))); + } else { + countMap.put(count.get("type").toString(), Integer.parseInt(count.get("count").toString())); + } + }); + } + return index; + }).collect(Collectors.toList()); + Map>> typeCountListMap1 = // 区级部门 + typeCountListByDept.stream().filter(index -> index.get("deptType").toString().equals("3")).collect(Collectors.groupingBy(m -> m.get("district").toString())); + resultList = resultList.stream().map(index -> { + if (typeCountListMap1.keySet().contains(index.get("dept_id").toString())) { // 该部门存在上架信息 + index.put("count", typeCountListMap1.get(index.get("dept_id").toString()).stream().mapToInt(it -> Integer.parseInt(it.get("count").toString())).sum()); + typeCountListMap1.get(index.get("dept_id").toString()).stream().forEach(count -> { + index.put(count.get("type").toString(), Integer.parseInt(count.get("count").toString()) + Integer.parseInt(index.getOrDefault(count.get("type").toString(), "0").toString())); + if (countMap.containsKey(count.get("type"))) { + countMap.replace(count.get("type").toString(), Integer.parseInt(count.get("count").toString()) + countMap.get(count.get("type"))); + } else { + countMap.put(count.get("type").toString(), Integer.parseInt(count.get("count").toString())); + } + }); + } + return index; + }).collect(Collectors.toList()); + Integer total = 0; + for (Integer count : countMap.values()) { + total += count; } - return index; - }).collect(Collectors.toList()); -// typeCountListMap.forEach((k, v) -> { -// HashMap map = new HashMap<>(); -// map.put("count", v.stream().mapToInt(it -> Integer.parseInt(it.get("count").toString())).sum()); -// map.put("name", k); -// v.forEach(item -> { -// map.put(item.get("type").toString(), item.get("count")); -// if (countMap.containsKey(item.get("type"))) { -// countMap.replace(item.get("type").toString(), Integer.parseInt(item.get("count").toString()) + countMap.get(item.get("type"))); -// } else { -// countMap.put(item.get("type").toString(), Integer.parseInt(item.get("count").toString())); -// } -// }); -// resultList.add(map); -// }); - - Integer total = 0; - for (Integer count : countMap.values()) { - total += count; + countMap.put("count", total); + HashMap count = new HashMap<>(); + count.put("name", "总计"); + count.putAll(countMap); + resultList.add(count); + return resultList; } - countMap.put("count", total); - HashMap count = new HashMap<>(); - count.put("name", "总计"); - count.putAll(countMap); - resultList.add(count); - return resultList; + } /**