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 75a3949d..9c764ae6 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 @@ -2024,34 +2024,130 @@ public class ResourceServiceImpl extends CrudServiceImpl> typeCountListByApplyDept = resourceDao.selectApplyDeptDetailTypeCountList(params); - Map>> typeCountListMap = typeCountListByApplyDept.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(item.get("type").toString(), Integer.parseInt(item.get("count").toString())); - } + if (params.containsKey("deptId") && org.apache.commons.lang3.StringUtils.isNotEmpty(params.get("deptId").toString())) { + List> typeCountListByApplyDept = resourceDao.selectApplyDeptDetailTypeCountList(params); + Map>> typeCountListMap = typeCountListByApplyDept.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(item.get("type").toString(), Integer.parseInt(item.get("count").toString())); + } + }); + resultList.add(map); }); - resultList.add(map); - }); - Integer total = 0; - for (Integer count : countMap.values()) { - total += count; + 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; + } else { + List> typeCountListByApplyDept = resourceDao.selectApplyDeptDetailTypeCountList(params); + List> resultList = getDeptTemp1(); + resultList.addAll(getDeptTemp2()); + Map countMap = new HashMap<>(); + + Map>> typeCountListMap = // 市级部门 + typeCountListByApplyDept.stream().filter(index -> index.get("deptType").toString().equals("2")).collect(Collectors.groupingBy(m -> m.get("dept_id").toString())); + 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 = // 区级部门 + typeCountListByApplyDept.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()); + + Map>> typeCountListMap2 = // 会议室 + typeCountListByApplyDept.stream().filter(index -> index.get("deptType").toString().equals("99")).collect(Collectors.groupingBy(m -> m.get("deptName").toString())); + resultList = resultList.stream().map(index -> { + if (typeCountListMap2.keySet().contains(index.get("name").toString())) { // 该部门存在上架信息 + index.put("count", Integer.parseInt(index.get("count").toString()) + typeCountListMap2.get(index.get("name").toString()).stream().mapToInt(it -> Integer.parseInt(it.get("count").toString())).sum()); + typeCountListMap2.get(index.get("name").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())); + } + }); + typeCountListMap2.remove(typeCountListMap2.get(index.get("deptName").toString()));// 去除 + } + return index; + }).collect(Collectors.toList()); + + if (!typeCountListMap2.isEmpty()) { // 仍然有会议室信息 + List> temp = typeCountListMap2.keySet().stream().map(index_ -> { + HashMap map = new HashMap<>(); + typeCountListMap2.get(index_).stream().forEach(count -> { + map.put(count.get("type").toString(), Integer.parseInt(count.get("type").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())); + } + }); + map.put("name", index_); + map.put("dept_id", null); + map.put("yyzy", "0"); + map.put("znsf", "0"); + map.put("tcfw", "0"); + map.put("kfzj", "0"); + map.put("ywzj", "0"); + map.put("jcss", "0"); + map.put("zsk", "0"); + map.put("sjzy", "0"); + map.put("hys", "0"); + return map; + }).collect(Collectors.toList()); // 会议室的 + resultList.addAll(temp); + } + + 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; } @Override diff --git a/renren-admin/src/main/resources/mapper/resource/ResourceDao.xml b/renren-admin/src/main/resources/mapper/resource/ResourceDao.xml index 1ead14f4..4083759c 100644 --- a/renren-admin/src/main/resources/mapper/resource/ResourceDao.xml +++ b/renren-admin/src/main/resources/mapper/resource/ResourceDao.xml @@ -1719,6 +1719,9 @@ SELECT COUNT( taa.resource_id ) AS "count", sd.NAME AS "deptName", + sd.id AS "dept_id", + sd.type AS "deptType", + sd.district AS "district", ( CASE tdr.type @@ -1777,9 +1780,11 @@ UNION SELECT - - COUNT( id ) AS 'count' , + COUNT( id ) AS 'count', dept AS 'deptName', + NULL AS "dept_id", + 99 AS "deptType", + NULL AS "district", 'hys' AS 'type' FROM t_meetingroom_book tmb