|
|
@@ -944,10 +944,10 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
result = statisticsByProjectDept(dailyReports, pageReqVO.getDeptId(), pageReqVO);
|
|
|
} else if ("2".equals(selectedDept.getType())) {
|
|
|
// 以队伍为维度汇总数据
|
|
|
- result = statisticsByProjectDepartment(dailyReports, pageReqVO.getDeptId());
|
|
|
+ result = statisticsByProjectDepartment(dailyReports, pageReqVO);
|
|
|
} else if ("3".equals(selectedDept.getType())) {
|
|
|
// 显示单个队伍的汇总数据
|
|
|
- result = statisticsByProjectDepartment(dailyReports, pageReqVO.getDeptId());
|
|
|
+ result = statisticsByProjectDepartment(dailyReports, pageReqVO);
|
|
|
} else {
|
|
|
// 点击的部门没有类型 判断部门下的是否包含 项目部类型部门 新疆分公司
|
|
|
// 以项目部为维度汇总数据
|
|
|
@@ -1006,6 +1006,8 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
Map<Long, List<BigDecimal>> cumulativeNonProductionTimePair = new HashMap<>();
|
|
|
// key队伍id/项目部id value非生产时效
|
|
|
Map<Long, BigDecimal> cumulativeNonProductionPair = new HashMap<>();
|
|
|
+ // key队伍id/项目部id value设备利用率
|
|
|
+ Map<Long, BigDecimal> deviceUtilizationPair = new HashMap<>();
|
|
|
|
|
|
// 以项目部为维度统计数据
|
|
|
// 找到所有项目部与队伍的对应关系
|
|
|
@@ -1015,11 +1017,23 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
reqVO.setDeptIds(allRhChildDeptIds);
|
|
|
List<DeptDO> depts = deptService.getDeptList(reqVO);
|
|
|
|
|
|
+ // 包含设备的部门id集合
|
|
|
+ Set<Long> haveDeviceDeptIds = new HashSet<>();
|
|
|
+ IotDevicePageReqVO deviceReqVO = new IotDevicePageReqVO();
|
|
|
+ deviceReqVO.setDeptIds(new ArrayList<>(allRhChildDeptIds));
|
|
|
+ List<IotDeviceDO> devices = iotDeviceMapper.selectListAlone(deviceReqVO);
|
|
|
+ if (CollUtil.isNotEmpty(devices)) {
|
|
|
+ // 筛选出包含设备的队伍部门集合
|
|
|
+ devices.forEach(device -> {
|
|
|
+ haveDeviceDeptIds.add(device.getDeptId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
// 构建项目部映射和父子部门关系
|
|
|
depts.forEach(dept -> {
|
|
|
// 暂时过滤掉 欧洲项目部 克拉玛依项目部
|
|
|
- if ("2".equals(dept.getType()) && dept.getId() != 352 && dept.getId() != 166) {
|
|
|
- // 项目部
|
|
|
+ if ("2".equals(dept.getType()) && "LY".equals(dept.getEmail())) {
|
|
|
+ // 状态为LY的项目部 才统计设备利用率
|
|
|
projectDeptIds.add(dept.getId());
|
|
|
projectDeptPair.put(dept.getId(), dept);
|
|
|
}
|
|
|
@@ -1029,22 +1043,51 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
}
|
|
|
teamProjectIdPair.put(dept.getId(), dept.getParentId());
|
|
|
});
|
|
|
+ // key项目部id value项目部包含的队伍id集合
|
|
|
+ Map<Long, Set<Long>> projectTeamPair = new HashMap<>();
|
|
|
+ // 筛选项目部下包含的队伍
|
|
|
+ depts.forEach(dept -> {
|
|
|
+ Long deptId = dept.getId();
|
|
|
+ Long parentId = dept.getParentId();
|
|
|
+ if (projectDeptIds.contains(parentId)) {
|
|
|
+ // 获得当前部门的上级项目部
|
|
|
+ projectDeptIds.forEach(projectDeptId -> {
|
|
|
+ if (projectDeptId.equals(parentId) && haveDeviceDeptIds.contains(deptId)) {
|
|
|
+ if (projectTeamPair.containsKey(projectDeptId)) {
|
|
|
+ Set<Long> tempTeamIds = projectTeamPair.get(projectDeptId);
|
|
|
+ tempTeamIds.add(deptId);
|
|
|
+ projectTeamPair.put(projectDeptId, tempTeamIds);
|
|
|
+ } else {
|
|
|
+ Set<Long> tempTeamIds = new HashSet<>();
|
|
|
+ tempTeamIds.add(deptId);
|
|
|
+ projectTeamPair.put(projectDeptId, tempTeamIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
LocalDateTime[] createTime = pageReqVO.getCreateTime();
|
|
|
+ List<Long> daysCounts = new ArrayList<>();
|
|
|
// 如果 createTime 包含的时间是 1天则查询 这1天时间内的 队伍总数 施工队伍数量 施工准备队伍数量 驻地待命队伍数量
|
|
|
if (ObjUtil.isNotEmpty(createTime)) {
|
|
|
LocalDateTime startTime = createTime[0];
|
|
|
LocalDateTime endTime = createTime[1];
|
|
|
- if (ObjUtil.isNotEmpty(startTime) && ObjUtil.isNotEmpty(endTime)) {
|
|
|
+ if (ObjUtil.isNotEmpty(startTime) && ObjUtil.isNotEmpty(endTime) && !endTime.isBefore(startTime)) {
|
|
|
+ // 查询时间区间包含的天数
|
|
|
+ // 使用ChronoUnit.DAYS.between计算天数差,并+1包含首尾两天
|
|
|
+ long daysCount = ChronoUnit.DAYS.between(
|
|
|
+ startTime.toLocalDate(),
|
|
|
+ endTime.toLocalDate()
|
|
|
+ ) + 1;
|
|
|
+ daysCounts.add(daysCount);
|
|
|
+
|
|
|
LocalDate startLocalDate = startTime.toLocalDate();
|
|
|
LocalDate endLocalDate = endTime.toLocalDate();
|
|
|
if (startLocalDate.isEqual(endLocalDate)) {
|
|
|
// 查询日期区间是 同一天
|
|
|
// 设置每个项目部下的队伍数量 只筛选 包含设备的队伍数量
|
|
|
Set<Long> deviceDeptIds = new HashSet<>();
|
|
|
- IotDevicePageReqVO deviceReqVO = new IotDevicePageReqVO();
|
|
|
- deviceReqVO.setDeptIds(new ArrayList<>(allRhChildDeptIds));
|
|
|
- List<IotDeviceDO> devices = iotDeviceMapper.selectListAlone(deviceReqVO);
|
|
|
if (CollUtil.isNotEmpty(devices)) {
|
|
|
devices.forEach(device -> {
|
|
|
deviceDeptIds.add(device.getDeptId());
|
|
|
@@ -1101,6 +1144,9 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 统计各项目部的设备利用率
|
|
|
+ // key项目部id value项目部包含的队伍指定时间区域内日报数量
|
|
|
+ Map<Long, Integer> projectReportPair = new HashMap<>();
|
|
|
// 查询指定部门下相关设备的产能
|
|
|
// key队伍id value队伍下相关设备产能
|
|
|
Map<Long, BigDecimal> teamCapacityPair = queryCapacities(new ArrayList<>(allRhChildDeptIds));
|
|
|
@@ -1108,6 +1154,21 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
// 累计计算各项指标
|
|
|
if (CollUtil.isNotEmpty(dailyReports)) {
|
|
|
dailyReports.forEach(report -> {
|
|
|
+ // 统计各项目部的日报数量
|
|
|
+ if (CollUtil.isNotEmpty(projectTeamPair)) {
|
|
|
+ projectTeamPair.forEach((projectDeptId, teamDeptIds) -> {
|
|
|
+ if (teamDeptIds.contains(report.getDeptId())) {
|
|
|
+ // 项目部日报数量
|
|
|
+ if (projectReportPair.containsKey(projectDeptId)) {
|
|
|
+ Integer tempCount = projectReportPair.get(projectDeptId);
|
|
|
+ projectReportPair.put(projectDeptId, ++tempCount);
|
|
|
+ } else {
|
|
|
+ projectReportPair.put(projectDeptId, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
if (ObjUtil.isNotEmpty(report.getDeptId()) && teamProjectIdPair.containsKey(report.getDeptId())) {
|
|
|
Long projectDeptId = teamProjectIdPair.get(report.getDeptId());
|
|
|
if (ObjUtil.isNotEmpty(projectDeptId) && projectDeptPair.containsKey(projectDeptId)) {
|
|
|
@@ -1156,6 +1217,26 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 计算各项目部的平均设备利用率
|
|
|
+ if (CollUtil.isNotEmpty(projectTeamPair)) {
|
|
|
+ projectTeamPair.forEach((projectDeptId, resultTeamIds) -> {
|
|
|
+ double rate = 0.0;
|
|
|
+ Integer currentTeamNum = resultTeamIds.size();
|
|
|
+ if (projectReportPair.containsKey(projectDeptId)) {
|
|
|
+ Integer reportCount = projectReportPair.getOrDefault(projectDeptId, 0);
|
|
|
+ // 当前项目部 设备利用率 公式 reportCount/(currentTeamNum * daysCount)
|
|
|
+ // 计算设备利用率(处理除数为0的情况)
|
|
|
+ if (currentTeamNum > 0 && CollUtil.isNotEmpty(daysCounts)) {
|
|
|
+ long daysCount = daysCounts.get(0);
|
|
|
+ rate = new BigDecimal((double) reportCount / (currentTeamNum * daysCount))
|
|
|
+ .setScale(4, RoundingMode.HALF_UP) // 保留4位小数,四舍五入
|
|
|
+ .doubleValue();
|
|
|
+ deviceUtilizationPair.put(projectDeptId, BigDecimal.valueOf(rate));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
if (CollUtil.isNotEmpty(cumulativeNonProductionTimePair)) {
|
|
|
// 计算各项目部的平均时效
|
|
|
cumulativeNonProductionTimePair.forEach((projectDeptId, nonProductTimes) -> {
|
|
|
@@ -1176,6 +1257,7 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
statistics.setProjectDeptName(dept.getName());
|
|
|
statistics.setSort(dept.getSort());
|
|
|
statistics.setType("2");
|
|
|
+ statistics.setUtilizationRate(deviceUtilizationPair.get(deptId));
|
|
|
statistics.setCumulativeGasInjection(cumulativeGasInjectionPair.get(deptId));
|
|
|
statistics.setCumulativeWaterInjection(cumulativeWaterInjectionPair.get(deptId));
|
|
|
statistics.setCumulativePowerConsumption(cumulativePowerConsumptionPair.get(deptId));
|
|
|
@@ -1323,10 +1405,11 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
/**
|
|
|
* 按 队伍 维度统计数据
|
|
|
* @param dailyReports 日报数据列表
|
|
|
- * @param deptId 项目部ID 或 队伍id(塔河项目部 HY-A1)
|
|
|
+ * @param pageReqVO.deptId 项目部ID 或 队伍id(塔河项目部 HY-A1)
|
|
|
* @return 队伍 维度统计结果列表
|
|
|
*/
|
|
|
- private List<IotRhDailyReportStatisticsRespVO> statisticsByProjectDepartment(List<IotRhDailyReportDO> dailyReports, Long deptId) {
|
|
|
+ private List<IotRhDailyReportStatisticsRespVO> statisticsByProjectDepartment(List<IotRhDailyReportDO> dailyReports,
|
|
|
+ IotRhDailyReportPageReqVO pageReqVO) {
|
|
|
List<IotRhDailyReportStatisticsRespVO> result = new ArrayList<>();
|
|
|
|
|
|
Set<Long> projectDeptIds = new HashSet<>();
|
|
|
@@ -1353,33 +1436,83 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
Map<Long, List<BigDecimal>> cumulativeNonProductionTimePair = new HashMap<>();
|
|
|
// key队伍id/项目部id value非生产时效
|
|
|
Map<Long, BigDecimal> cumulativeNonProductionPair = new HashMap<>();
|
|
|
+ // key队伍id/项目部id value设备利用率
|
|
|
+ Map<Long, BigDecimal> deviceUtilizationPair = new HashMap<>();
|
|
|
|
|
|
// 以 队伍 为维度统计数据
|
|
|
// 找到所有项目部与队伍的对应关系
|
|
|
// 查询指定根部门下的所有子部门
|
|
|
- Set<Long> allRhChildDeptIds = deptService.getChildDeptIdListFromCache(deptId);
|
|
|
+ Set<Long> allRhChildDeptIds = deptService.getChildDeptIdListFromCache(pageReqVO.getDeptId());
|
|
|
DeptListReqVO reqVO = new DeptListReqVO();
|
|
|
- allRhChildDeptIds.add(deptId); // 查询某支队伍
|
|
|
+ allRhChildDeptIds.add(pageReqVO.getDeptId()); // 查询某支队伍
|
|
|
reqVO.setDeptIds(allRhChildDeptIds);
|
|
|
List<DeptDO> depts = deptService.getDeptList(reqVO);
|
|
|
|
|
|
+ // 筛选出状态为 LY 的项目部
|
|
|
+ depts.forEach(dept -> {
|
|
|
+ // 暂时过滤掉 欧洲项目部 克拉玛依项目部
|
|
|
+ if ("2".equals(dept.getType()) && "LY".equals(dept.getEmail())) {
|
|
|
+ // 状态为LY的项目部 才统计设备利用率
|
|
|
+ projectDeptIds.add(dept.getId());
|
|
|
+ projectDeptPair.put(dept.getId(), dept);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
// 构建项目部映射和父子部门关系
|
|
|
depts.forEach(dept -> {
|
|
|
if ("3".equals(dept.getType())) {
|
|
|
- projectDeptIds.add(dept.getId());
|
|
|
teamDeptPair.put(dept.getId(), dept);
|
|
|
}
|
|
|
teamProjectIdPair.put(dept.getId(), dept.getParentId());
|
|
|
});
|
|
|
|
|
|
+ // 包含设备的部门id集合
|
|
|
+ Set<Long> haveDeviceDeptIds = new HashSet<>();
|
|
|
+ IotDevicePageReqVO deviceReqVO = new IotDevicePageReqVO();
|
|
|
+ deviceReqVO.setDeptIds(new ArrayList<>(allRhChildDeptIds));
|
|
|
+ List<IotDeviceDO> devices = iotDeviceMapper.selectListAlone(deviceReqVO);
|
|
|
+ if (CollUtil.isNotEmpty(devices)) {
|
|
|
+ // 筛选出包含设备的队伍部门集合
|
|
|
+ devices.forEach(device -> {
|
|
|
+ haveDeviceDeptIds.add(device.getDeptId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ LocalDateTime[] createTime = pageReqVO.getCreateTime();
|
|
|
+ List<Long> daysCounts = new ArrayList<>();
|
|
|
+ // 如果 createTime 包含的时间是 1天则查询 这1天时间内的 队伍总数 施工队伍数量 施工准备队伍数量 驻地待命队伍数量
|
|
|
+ if (ObjUtil.isNotEmpty(createTime)) {
|
|
|
+ LocalDateTime startTime = createTime[0];
|
|
|
+ LocalDateTime endTime = createTime[1];
|
|
|
+ if (ObjUtil.isNotEmpty(startTime) && ObjUtil.isNotEmpty(endTime) && !endTime.isBefore(startTime)) {
|
|
|
+ // 查询时间区间包含的天数
|
|
|
+ // 使用ChronoUnit.DAYS.between计算天数差,并+1包含首尾两天
|
|
|
+ long daysCount = ChronoUnit.DAYS.between(
|
|
|
+ startTime.toLocalDate(),
|
|
|
+ endTime.toLocalDate()
|
|
|
+ ) + 1;
|
|
|
+ daysCounts.add(daysCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 查询指定部门下相关设备的产能
|
|
|
// key队伍id value队伍下相关设备产能
|
|
|
Map<Long, BigDecimal> teamCapacityPair = queryCapacities(new ArrayList<>(allRhChildDeptIds));
|
|
|
-
|
|
|
+ // 统计各队伍的设备利用率
|
|
|
+ // key队伍id value队伍指定时间区域内日报数量
|
|
|
+ Map<Long, Integer> teamReportPair = new HashMap<>();
|
|
|
// 累计计算各项指标
|
|
|
if (CollUtil.isNotEmpty(dailyReports)) {
|
|
|
dailyReports.forEach(report -> {
|
|
|
if (ObjUtil.isNotEmpty(report.getDeptId())) {
|
|
|
+ // 统计各个队伍的日报数量
|
|
|
+ if (teamReportPair.containsKey(report.getDeptId())) {
|
|
|
+ Integer tempCount = teamReportPair.get(report.getDeptId());
|
|
|
+ teamReportPair.put(report.getDeptId(), ++tempCount);
|
|
|
+ } else {
|
|
|
+ teamReportPair.put(report.getDeptId(), 1);
|
|
|
+ }
|
|
|
+
|
|
|
// 累计注气量
|
|
|
cumulativeGasInjectionPair.merge(report.getDeptId(), report.getDailyGasInjection(), BigDecimal::add);
|
|
|
// 累计注水量
|
|
|
@@ -1432,6 +1565,23 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
cumulativeNonProductionPair.put(teamId, nonProductionEfficiency);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ // 计算各队伍的平均设备利用率
|
|
|
+ if (CollUtil.isNotEmpty(teamReportPair)) {
|
|
|
+ teamReportPair.forEach((teamDeptId, reportCount) -> {
|
|
|
+ double rate = 0.0;
|
|
|
+ Integer currentTeamNum = 1;
|
|
|
+ // 当前项目部 设备利用率 公式 reportCount/(currentTeamNum * daysCount)
|
|
|
+ // 计算设备利用率(处理除数为0的情况)
|
|
|
+ if (currentTeamNum > 0 && CollUtil.isNotEmpty(daysCounts)) {
|
|
|
+ long daysCount = daysCounts.get(0);
|
|
|
+ rate = new BigDecimal((double) reportCount / (currentTeamNum * daysCount))
|
|
|
+ .setScale(4, RoundingMode.HALF_UP) // 保留4位小数,四舍五入
|
|
|
+ .doubleValue();
|
|
|
+ deviceUtilizationPair.put(teamDeptId, BigDecimal.valueOf(rate));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 生成返回的数据列表集合
|
|
|
@@ -1441,6 +1591,7 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
statistics.setTeamName(dept.getName());
|
|
|
statistics.setSort(dept.getSort());
|
|
|
statistics.setType("3");
|
|
|
+ statistics.setUtilizationRate(deviceUtilizationPair.get(teamDeptId));
|
|
|
statistics.setCumulativeGasInjection(cumulativeGasInjectionPair.get(teamDeptId));
|
|
|
statistics.setCumulativeWaterInjection(cumulativeWaterInjectionPair.get(teamDeptId));
|
|
|
statistics.setCumulativePowerConsumption(cumulativePowerConsumptionPair.get(teamDeptId));
|