|
|
@@ -378,10 +378,8 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
if (Objects.nonNull(pageReqVO.getDeptId())) {
|
|
|
ids = deptService.getChildDeptIdListFromCache(pageReqVO.getDeptId());
|
|
|
// 找到所有子部门对象集合
|
|
|
-
|
|
|
ids.add(pageReqVO.getDeptId());
|
|
|
pageReqVO.setDeptIds(ids);
|
|
|
-
|
|
|
}
|
|
|
// 检查contractName不为空但projectIds为空的情况
|
|
|
if (StrUtil.isNotBlank(pageReqVO.getContractName()) && (CollUtil.isEmpty(pageReqVO.getProjectIds()))) {
|
|
|
@@ -408,93 +406,175 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
// 点击项目部 显示 下属队伍的数据
|
|
|
// 首先判断点击的部门是属于 公司 还是 队伍 如果没有点击任何部门 默认查询所有项目部数据
|
|
|
if (ObjUtil.isEmpty(pageReqVO.getDeptId())) {
|
|
|
- Set<Long> projectDeptIds = new HashSet<>();
|
|
|
- // key项目部id value项目部名称
|
|
|
- Map<Long, DeptDO> projectDeptPair = new HashMap<>();
|
|
|
- // key部门id value部门parentId
|
|
|
- Map<Long, Long> teamProjectIdPair = new HashMap<>();
|
|
|
-
|
|
|
- // 以项目部为维度统计数据 所有项目部
|
|
|
- // 找到所有项目部 与 队伍 的对应关系
|
|
|
- // 查询所有瑞恒的项目部
|
|
|
- Set<Long> allRhChildDeptIds = deptService.getChildDeptIdListFromCache(157l);
|
|
|
- DeptListReqVO reqVO = new DeptListReqVO();
|
|
|
- reqVO.setDeptIds(allRhChildDeptIds);
|
|
|
- List<DeptDO> depts = deptService.getDeptList(reqVO);
|
|
|
- depts.forEach(dept -> {
|
|
|
- if ("2".equals(dept.getType())) {
|
|
|
- projectDeptIds.add(dept.getId());
|
|
|
- projectDeptPair.put(dept.getId(), dept);
|
|
|
- }
|
|
|
- teamProjectIdPair.put(dept.getId(), dept.getParentId());
|
|
|
- });
|
|
|
- if (CollUtil.isNotEmpty(dailyReports)) {
|
|
|
- dailyReports.forEach(report -> {
|
|
|
- if (ObjUtil.isNotEmpty(report.getDeptId()) && teamProjectIdPair.containsKey(report.getDeptId())) {
|
|
|
- Long projectDeptId = teamProjectIdPair.get(report.getDeptId());
|
|
|
- if (ObjUtil.isNotEmpty(projectDeptId) && projectDeptPair.containsKey(projectDeptId)) {
|
|
|
- DeptDO tempDept = projectDeptPair.get(projectDeptId);
|
|
|
- // 累计注气量
|
|
|
- if (cumulativeGasInjectionPair.containsKey(projectDeptId)) {
|
|
|
- BigDecimal tempGasInjection = cumulativeGasInjectionPair.get(projectDeptId);
|
|
|
- cumulativeGasInjectionPair.put(projectDeptId, report.getDailyGasInjection().add(tempGasInjection));
|
|
|
- } else {
|
|
|
- cumulativeGasInjectionPair.put(projectDeptId, report.getDailyGasInjection());
|
|
|
- }
|
|
|
- // 累计注水量
|
|
|
- if (cumulativeWaterInjectionPair.containsKey(projectDeptId)) {
|
|
|
- BigDecimal tempWaterInjection = cumulativeWaterInjectionPair.get(projectDeptId);
|
|
|
- cumulativeWaterInjectionPair.put(projectDeptId, report.getDailyWaterInjection().add(tempWaterInjection));
|
|
|
- } else {
|
|
|
- cumulativeWaterInjectionPair.put(projectDeptId, report.getDailyWaterInjection());
|
|
|
- }
|
|
|
- // 累计用电量
|
|
|
- if (cumulativePowerConsumptionPair.containsKey(projectDeptId)) {
|
|
|
- BigDecimal tempPower = cumulativePowerConsumptionPair.get(projectDeptId);
|
|
|
- cumulativePowerConsumptionPair.put(projectDeptId, report.getDailyPowerUsage().add(tempPower));
|
|
|
- } else {
|
|
|
- cumulativePowerConsumptionPair.put(projectDeptId, report.getDailyPowerUsage());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- // 生成返回的数据列表集合
|
|
|
- projectDeptPair.forEach((deptId, dept) -> {
|
|
|
- IotRhDailyReportStatisticsRespVO statistics = new IotRhDailyReportStatisticsRespVO();
|
|
|
- statistics.setProjectDeptId(deptId);
|
|
|
- statistics.setProjectDeptName(dept.getName());
|
|
|
- statistics.setSort(dept.getSort());
|
|
|
- if (cumulativeGasInjectionPair.containsKey(deptId)) {
|
|
|
- statistics.setCumulativeGasInjection(cumulativeGasInjectionPair.get(deptId));
|
|
|
- }
|
|
|
- if (cumulativeWaterInjectionPair.containsKey(deptId)) {
|
|
|
- statistics.setCumulativeWaterInjection(cumulativeWaterInjectionPair.get(deptId));
|
|
|
- }
|
|
|
- if (cumulativePowerConsumptionPair.containsKey(deptId)) {
|
|
|
- statistics.setCumulativePowerConsumption(cumulativePowerConsumptionPair.get(deptId));
|
|
|
- }
|
|
|
- result.add(statistics);
|
|
|
- });
|
|
|
+ result = statisticsByProjectDept(dailyReports, 157L);
|
|
|
} else {
|
|
|
// 判断点击的组织树中的部门类型 类型(公司级1 项目部2 队伍3)
|
|
|
DeptDO selectedDept = deptService.getDept(pageReqVO.getDeptId());
|
|
|
if ("1".equals(selectedDept.getType())) {
|
|
|
// 以项目部为维度汇总数据
|
|
|
-
|
|
|
+ result = statisticsByProjectDept(dailyReports, pageReqVO.getDeptId());
|
|
|
} else if ("2".equals(selectedDept.getType())) {
|
|
|
// 以队伍为维度汇总数据
|
|
|
-
|
|
|
+ result = statisticsByProjectDepartment(dailyReports, pageReqVO.getDeptId());
|
|
|
} else if ("3".equals(selectedDept.getType())) {
|
|
|
// 显示单个队伍的汇总数据
|
|
|
-
|
|
|
+ result = statisticsByProjectDepartment(dailyReports, pageReqVO.getDeptId());
|
|
|
} else {
|
|
|
// 点击的部门没有类型 判断部门下的是否包含 项目部类型部门 新疆分公司
|
|
|
// 以项目部为维度汇总数据
|
|
|
-
|
|
|
+ result = statisticsByProjectDept(dailyReports, pageReqVO.getDeptId());
|
|
|
}
|
|
|
}
|
|
|
// 根据result集合内对象的 sort 属性正序排列 sort 类型为 integer 类型
|
|
|
+ if (CollUtil.isNotEmpty(result)) {
|
|
|
+ result.sort(Comparator.comparing(
|
|
|
+ IotRhDailyReportStatisticsRespVO::getSort,
|
|
|
+ Comparator.nullsLast(Comparator.naturalOrder())
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按项目部维度统计数据
|
|
|
+ * @param dailyReports 日报数据列表
|
|
|
+ * @param rootDeptId 根部门ID(如157L为瑞恒根部门,或其他公司级部门ID)
|
|
|
+ * @return 项目部维度统计结果列表
|
|
|
+ */
|
|
|
+ private List<IotRhDailyReportStatisticsRespVO> statisticsByProjectDept(List<IotRhDailyReportDO> dailyReports, Long rootDeptId) {
|
|
|
+ List<IotRhDailyReportStatisticsRespVO> result = new ArrayList<>();
|
|
|
+
|
|
|
+ Set<Long> projectDeptIds = new HashSet<>();
|
|
|
+ // key项目部id value项目部名称
|
|
|
+ Map<Long, DeptDO> projectDeptPair = new HashMap<>();
|
|
|
+ // key部门id value部门parentId
|
|
|
+ Map<Long, Long> teamProjectIdPair = new HashMap<>();
|
|
|
+
|
|
|
+ // key队伍id/项目部id value累计注气量
|
|
|
+ Map<Long, BigDecimal> cumulativeGasInjectionPair = new HashMap<>();
|
|
|
+ // key队伍id/项目部id value累计注水量
|
|
|
+ Map<Long, BigDecimal> cumulativeWaterInjectionPair = new HashMap<>();
|
|
|
+ // key队伍id/项目部id value累计用电
|
|
|
+ Map<Long, BigDecimal> cumulativePowerConsumptionPair = new HashMap<>();
|
|
|
+
|
|
|
+ // 以项目部为维度统计数据
|
|
|
+ // 找到所有项目部与队伍的对应关系
|
|
|
+ // 查询指定根部门下的所有子部门
|
|
|
+ Set<Long> allRhChildDeptIds = deptService.getChildDeptIdListFromCache(rootDeptId);
|
|
|
+ DeptListReqVO reqVO = new DeptListReqVO();
|
|
|
+ reqVO.setDeptIds(allRhChildDeptIds);
|
|
|
+ List<DeptDO> depts = deptService.getDeptList(reqVO);
|
|
|
+
|
|
|
+ // 构建项目部映射和父子部门关系
|
|
|
+ depts.forEach(dept -> {
|
|
|
+ if ("2".equals(dept.getType())) {
|
|
|
+ projectDeptIds.add(dept.getId());
|
|
|
+ projectDeptPair.put(dept.getId(), dept);
|
|
|
+ }
|
|
|
+ teamProjectIdPair.put(dept.getId(), dept.getParentId());
|
|
|
+ });
|
|
|
+
|
|
|
+ // 累计计算各项指标
|
|
|
+ if (CollUtil.isNotEmpty(dailyReports)) {
|
|
|
+ dailyReports.forEach(report -> {
|
|
|
+ if (ObjUtil.isNotEmpty(report.getDeptId()) && teamProjectIdPair.containsKey(report.getDeptId())) {
|
|
|
+ Long projectDeptId = teamProjectIdPair.get(report.getDeptId());
|
|
|
+ if (ObjUtil.isNotEmpty(projectDeptId) && projectDeptPair.containsKey(projectDeptId)) {
|
|
|
+ // 累计注气量
|
|
|
+ cumulativeGasInjectionPair.merge(projectDeptId, report.getDailyGasInjection(), BigDecimal::add);
|
|
|
+ // 累计注水量
|
|
|
+ cumulativeWaterInjectionPair.merge(projectDeptId, report.getDailyWaterInjection(), BigDecimal::add);
|
|
|
+ // 累计用电量
|
|
|
+ cumulativePowerConsumptionPair.merge(projectDeptId, report.getDailyPowerUsage(), BigDecimal::add);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成返回的数据列表集合
|
|
|
+ projectDeptPair.forEach((deptId, dept) -> {
|
|
|
+ IotRhDailyReportStatisticsRespVO statistics = new IotRhDailyReportStatisticsRespVO();
|
|
|
+ statistics.setProjectDeptId(deptId);
|
|
|
+ statistics.setProjectDeptName(dept.getName());
|
|
|
+ statistics.setSort(dept.getSort());
|
|
|
+ statistics.setType("2");
|
|
|
+ statistics.setCumulativeGasInjection(cumulativeGasInjectionPair.get(deptId));
|
|
|
+ statistics.setCumulativeWaterInjection(cumulativeWaterInjectionPair.get(deptId));
|
|
|
+ statistics.setCumulativePowerConsumption(cumulativePowerConsumptionPair.get(deptId));
|
|
|
+ result.add(statistics);
|
|
|
+ });
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按 队伍 维度统计数据
|
|
|
+ * @param dailyReports 日报数据列表
|
|
|
+ * @param deptId 项目部ID 或 队伍id(塔河项目部 HY-A1)
|
|
|
+ * @return 队伍 维度统计结果列表
|
|
|
+ */
|
|
|
+ private List<IotRhDailyReportStatisticsRespVO> statisticsByProjectDepartment(List<IotRhDailyReportDO> dailyReports, Long deptId) {
|
|
|
+ List<IotRhDailyReportStatisticsRespVO> result = new ArrayList<>();
|
|
|
+
|
|
|
+ Set<Long> projectDeptIds = new HashSet<>();
|
|
|
+ // key项目部id value项目部名称
|
|
|
+ Map<Long, DeptDO> projectDeptPair = new HashMap<>();
|
|
|
+ // key队伍id value队伍名称
|
|
|
+ Map<Long, DeptDO> teamDeptPair = new HashMap<>();
|
|
|
+ // key部门id value部门parentId
|
|
|
+ Map<Long, Long> teamProjectIdPair = new HashMap<>();
|
|
|
+
|
|
|
+ // key队伍id value累计注气量
|
|
|
+ Map<Long, BigDecimal> cumulativeGasInjectionPair = new HashMap<>();
|
|
|
+ // key队伍id value累计注水量
|
|
|
+ Map<Long, BigDecimal> cumulativeWaterInjectionPair = new HashMap<>();
|
|
|
+ // key队伍id value累计用电
|
|
|
+ Map<Long, BigDecimal> cumulativePowerConsumptionPair = new HashMap<>();
|
|
|
+
|
|
|
+ // 以 队伍 为维度统计数据
|
|
|
+ // 找到所有项目部与队伍的对应关系
|
|
|
+ // 查询指定根部门下的所有子部门
|
|
|
+ Set<Long> allRhChildDeptIds = deptService.getChildDeptIdListFromCache(deptId);
|
|
|
+ DeptListReqVO reqVO = new DeptListReqVO();
|
|
|
+ allRhChildDeptIds.add(deptId); // 查询某支队伍
|
|
|
+ reqVO.setDeptIds(allRhChildDeptIds);
|
|
|
+ List<DeptDO> depts = deptService.getDeptList(reqVO);
|
|
|
+
|
|
|
+ // 构建项目部映射和父子部门关系
|
|
|
+ depts.forEach(dept -> {
|
|
|
+ if ("3".equals(dept.getType())) {
|
|
|
+ projectDeptIds.add(dept.getId());
|
|
|
+ teamDeptPair.put(dept.getId(), dept);
|
|
|
+ }
|
|
|
+ teamProjectIdPair.put(dept.getId(), dept.getParentId());
|
|
|
+ });
|
|
|
+
|
|
|
+ // 累计计算各项指标
|
|
|
+ if (CollUtil.isNotEmpty(dailyReports)) {
|
|
|
+ dailyReports.forEach(report -> {
|
|
|
+ if (ObjUtil.isNotEmpty(report.getDeptId())) {
|
|
|
+ // 累计注气量
|
|
|
+ cumulativeGasInjectionPair.merge(report.getDeptId(), report.getDailyGasInjection(), BigDecimal::add);
|
|
|
+ // 累计注水量
|
|
|
+ cumulativeWaterInjectionPair.merge(report.getDeptId(), report.getDailyWaterInjection(), BigDecimal::add);
|
|
|
+ // 累计用电量
|
|
|
+ cumulativePowerConsumptionPair.merge(report.getDeptId(), report.getDailyPowerUsage(), BigDecimal::add);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成返回的数据列表集合
|
|
|
+ teamDeptPair.forEach((teamDeptId, dept) -> {
|
|
|
+ IotRhDailyReportStatisticsRespVO statistics = new IotRhDailyReportStatisticsRespVO();
|
|
|
+ statistics.setTeamId(teamDeptId);
|
|
|
+ statistics.setTeamName(dept.getName());
|
|
|
+ statistics.setSort(dept.getSort());
|
|
|
+ statistics.setType("3");
|
|
|
+ statistics.setCumulativeGasInjection(cumulativeGasInjectionPair.get(teamDeptId));
|
|
|
+ statistics.setCumulativeWaterInjection(cumulativeWaterInjectionPair.get(teamDeptId));
|
|
|
+ statistics.setCumulativePowerConsumption(cumulativePowerConsumptionPair.get(teamDeptId));
|
|
|
+ result.add(statistics);
|
|
|
+ });
|
|
|
|
|
|
return result;
|
|
|
}
|