소스 검색

pms 瑞鹰日报汇总统计 卡片 折线 列表 逻辑优化

zhangcl 1 주 전
부모
커밋
465a739c96

+ 12 - 4
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotrydailyreport/IotRyDailyReportController.java

@@ -186,7 +186,7 @@ public class IotRyDailyReportController {
 
         PageResult<IotRyDailyReportDO> pageResult = iotRyDailyReportService.getIotRyDailyReportPage(pageReqVO);
 
-        return success(new PageResult<>(buildRyDailyReports(pageResult.getList()), pageResult.getTotal()));
+        return success(new PageResult<>(buildRyDailyReports(pageResult.getList(), pageReqVO), pageResult.getTotal()));
     }
 
     @GetMapping("/statistics")
@@ -232,7 +232,7 @@ public class IotRyDailyReportController {
      * @param reports
      * @return
      */
-    private List<IotRyDailyReportRespVO> buildRyDailyReports(List<IotRyDailyReportDO> reports) {
+    private List<IotRyDailyReportRespVO> buildRyDailyReports(List<IotRyDailyReportDO> reports, IotRyDailyReportPageReqVO pageReqVO) {
         if (CollUtil.isEmpty(reports)) {
             return Collections.emptyList();
         }
@@ -322,7 +322,7 @@ public class IotRyDailyReportController {
             // 按施工队伍统计 钻井日报 施工井数 完工井数
             List<IotRyDailyReportTaskCountVO> deptTasks = iotRyDailyReportService.countTasksByDept();
             // 修井日报 不存在既填写钻井日报 又填写修井日报的队伍
-            List<IotRyDailyReportTaskCountVO> repairDeptTasks = iotRyDailyReportService.countRepairTasksByDept();
+            List<IotRyDailyReportTaskCountVO> repairDeptTasks = iotRyDailyReportService.countRepairTasksByDept(pageReqVO);
             if (CollUtil.isNotEmpty(deptTasks)) {
                 deptTasks.forEach(task -> {
                     totalTasksPair.put(task.getDeptId(), task.getTotalTaskCount());
@@ -450,7 +450,15 @@ public class IotRyDailyReportController {
         Map<Long, Integer> totalTasksPair = new HashMap<>();
         // key施工队伍id    value完工井数量
         Map<Long, Integer> completedTasksPair = new HashMap<>();
-        List<IotRyDailyReportTaskCountVO> repairDeptTasks = iotRyDailyReportService.countRepairTasksByDept();
+        // 瑞鹰修井 施工井数 完工井数 统计
+        Set<Long> ids = new HashSet<>();
+        if (Objects.nonNull(pageReqVO.getDeptId())) {
+            ids = deptService.getChildDeptIdListFromCache(pageReqVO.getDeptId());
+            ids.add(pageReqVO.getDeptId());
+            pageReqVO.setDeptIds(ids);
+        }
+        List<IotRyDailyReportTaskCountVO> repairDeptTasks = iotRyDailyReportService.countRepairTasksByDept(pageReqVO);
+
         if (CollUtil.isNotEmpty(repairDeptTasks)) {
             repairDeptTasks.forEach(task -> {
                 totalTasksPair.put(task.getDeptId(), task.getTotalTaskCount());

+ 25 - 9
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotrydailyreport/IotRyDailyReportMapper.java

@@ -329,15 +329,31 @@ public interface IotRyDailyReportMapper extends BaseMapperX<IotRyDailyReportDO>
      * 按部门统计 修井 任务数量 完工任务数量
      * @return 部门任务统计列表
      */
-    @Select("SELECT " +
-            "dept_id as deptId, " +
-            "COUNT(DISTINCT CASE WHEN task_id IS NOT NULL THEN task_id END) as totalTaskCount, " +
-            "COUNT(DISTINCT CASE WHEN repair_status = 'wg' AND task_id IS NOT NULL THEN task_id END) as completedTaskCount " +
-            "FROM rq_iot_ry_daily_report " +
-            "WHERE deleted = 0 " +
-            "AND project_classification = 2 " +
-            "GROUP BY dept_id")
-    List<IotRyDailyReportTaskCountVO> countRepairTasksByDept();
+    @Select({
+            "<script>",
+            "SELECT ",
+            "dept_id as deptId, ",
+            "COUNT(DISTINCT CASE WHEN task_id IS NOT NULL THEN task_id END) as totalTaskCount, ",
+            "COUNT(DISTINCT CASE WHEN repair_status = 'wg' AND task_id IS NOT NULL THEN task_id END) as completedTaskCount ",
+            "FROM rq_iot_ry_daily_report ",
+            "WHERE deleted = 0 ",
+            "AND project_classification = 2 ",
+            "<if test='reqVO.deptIds != null and !reqVO.deptIds.isEmpty()'>",
+            "AND dept_id IN ",
+            "<foreach collection='reqVO.deptIds' item='deptId' open='(' separator=',' close=')'>",
+            "#{deptId}",
+            "</foreach>",
+            "</if>",
+            "<if test='reqVO.createTime != null and reqVO.createTime[0] != null'>",
+            "AND create_time &gt;= #{reqVO.createTime[0]} ",
+            "</if>",
+            "<if test='reqVO.createTime != null and reqVO.createTime[1] != null'>",
+            "AND create_time &lt;= #{reqVO.createTime[1]} ",
+            "</if>",
+            "GROUP BY dept_id",
+            "</script>"
+    })
+    List<IotRyDailyReportTaskCountVO> countRepairTasksByDept(@Param("reqVO") IotRyDailyReportPageReqVO reqVO);
 
     /**
      * 按部门统计 修井 任务数量 完工任务数量 当前日期所属的月 年

+ 1 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrydailyreport/IotRyDailyReportService.java

@@ -81,7 +81,7 @@ public interface IotRyDailyReportService {
      *
      * @return 按部门统计任务数量
      */
-    List<IotRyDailyReportTaskCountVO> countRepairTasksByDept();
+    List<IotRyDailyReportTaskCountVO> countRepairTasksByDept(IotRyDailyReportPageReqVO pageReqVO);
 
     /**
      * 按部门统计 修井 月累计 年累计 任务数量

+ 97 - 38
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrydailyreport/IotRyDailyReportServiceImpl.java

@@ -404,8 +404,8 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
     }
 
     @Override
-    public List<IotRyDailyReportTaskCountVO> countRepairTasksByDept() {
-        return iotRyDailyReportMapper.countRepairTasksByDept();
+    public List<IotRyDailyReportTaskCountVO> countRepairTasksByDept(IotRyDailyReportPageReqVO pageReqVO) {
+        return iotRyDailyReportMapper.countRepairTasksByDept(pageReqVO);
     }
 
     @Override
@@ -797,7 +797,7 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         if (ObjUtil.isEmpty(pageReqVO.getDeptId())) {
             result = polylineStatisticsByProjectDept(pageReqVO, dailyReports, 158L, pageReqVO.getCreateTime());
         } else {
-            // 判断点击的组织树中的部门类型 类型(公司级1 项目部2 队伍3)
+            // 判断点击的组织树中的部门类型 (公司级1 项目部2 队伍3)
             DeptDO selectedDept = deptService.getDept(pageReqVO.getDeptId());
             if ("1".equals(selectedDept.getType())) {
                 // 以项目部为维度汇总数据
@@ -910,9 +910,14 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         Map<Long, BigDecimal> cumulativeProductTimePair = new HashMap<>();
         // key队伍id/项目部id   value额定生产时间(H)
         Map<Long, BigDecimal> cumulativeRatedTimePair = new HashMap<>();
-        // key队伍id/项目部id   value累计运行时效   累计注气量/累计产能
+        // key队伍id/项目部id   value累计运行时效
         Map<Long, BigDecimal> cumulativeTransitTimePair = new HashMap<>();
 
+        // key部门id-任务id
+        Set<String> deptTaskConstrcts = new HashSet<>();
+        // key部门id-任务id
+        Set<String> deptTaskFinishes = new HashSet<>();
+
         // 以项目部为维度统计数据
         // 找到所有项目部与队伍的对应关系
         // 查询指定根部门下的所有子部门
@@ -939,7 +944,7 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         Map<Long, BigDecimal> taskRatedProductionTimePair = new HashMap<>();
         if ("2".equals(pageReqVO.getProjectClassification())) {
             // 查询修井 累计施工井数 累计完工井数
-            List<IotRyDailyReportTaskCountVO> repairDeptTasks = iotRyDailyReportMapper.countRepairTasksByDept();
+            List<IotRyDailyReportTaskCountVO> repairDeptTasks = iotRyDailyReportMapper.countRepairTasksByDept(pageReqVO);
             if (CollUtil.isNotEmpty(repairDeptTasks)) {
                 repairDeptTasks.forEach(task -> {
                     totalTasksPair.put(task.getDeptId(), task.getTotalTaskCount());
@@ -1091,6 +1096,11 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         // key日期yyyy-MM-dd   value额定生产时间(H)
         Map<String, BigDecimal> dateRatedTimePair = new HashMap<>();
 
+        // key部门id-任务id    value施工井对应的日期
+        Map<String, String> deptTaskConstructPair = new HashMap<>();
+        // key部门id-任务id    value完工井对应的日期
+        Map<String, String> deptTaskFinishPair = new HashMap<>();
+
         // 以项目部为维度统计数据
         // 找到所有项目部与队伍的对应关系
         // 查询指定根部门下的所有子部门
@@ -1116,30 +1126,47 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         // key任务id   value额定生产时间
         Map<Long, BigDecimal> taskRatedProductionTimePair = new HashMap<>();
         if ("2".equals(pageReqVO.getProjectClassification())) {
+            // 计算累计施工井数 累计完工井数 时 过滤掉 taskId 为空的数据
+            dailyReports.forEach(report -> {
+                if (ObjUtil.isNotEmpty(report.getTaskId()) && allRhChildDeptIds.contains(report.getDeptId())) {
+                    String uniqueKey = StrUtil.join("-", report.getDeptId(), report.getTaskId());
+                    String dateStr = LocalDateTimeUtil.format(report.getCreateTime(), DatePattern.NORM_DATE_PATTERN);
+                    deptTaskConstructPair.put(uniqueKey, dateStr);
+                    deptTaskFinishPair.put(uniqueKey, dateStr);
+                }
+            });
             // 查询 指定时间范围内的 修井 累计施工井数 累计完工井数
             // 每天的任务数量 taskId 去重后的数量
-            // 每天完工任务数量 taskId 去重后 状态为 wg 的数量
+            // 每天完工任务数量 deptId+taskId 去重后 状态为 wg 的数量
             dailyReports.forEach(report -> {
+                String uniqueKey = StrUtil.join("-", report.getDeptId(), report.getTaskId());
                 String dateStr = LocalDateTimeUtil.format(report.getCreateTime(), DatePattern.NORM_DATE_PATTERN);
-                if (dateConstructTaskPair.containsKey(dateStr)) {
-                    Set<Long> tempUniqueTaskIds = dateConstructTaskPair.get(dateStr);
-                    tempUniqueTaskIds.add(report.getTaskId());
-                    dateConstructTaskPair.put(dateStr, tempUniqueTaskIds);
-                } else {
-                    Set<Long> tempUniqueTaskIds = new HashSet<>();
-                    tempUniqueTaskIds.add(report.getTaskId());
-                    dateConstructTaskPair.put(dateStr, tempUniqueTaskIds);
-                }
-                // 组装完工任务集合
-                if ("wg".equals(report.getRepairStatus())) {
-                    if (dateFinishTaskPair.containsKey(dateStr)) {
-                        Set<Long> tempUniqueTaskIds = dateFinishTaskPair.get(dateStr);
+                if (deptTaskConstructPair.containsKey(uniqueKey)) {
+                    String tempDateStr = deptTaskFinishPair.get(uniqueKey);
+
+                    if (dateConstructTaskPair.containsKey(tempDateStr)) {
+                        Set<Long> tempUniqueTaskIds = dateConstructTaskPair.get(tempDateStr);
                         tempUniqueTaskIds.add(report.getTaskId());
-                        dateFinishTaskPair.put(dateStr, tempUniqueTaskIds);
+                        dateConstructTaskPair.put(tempDateStr, tempUniqueTaskIds);
                     } else {
                         Set<Long> tempUniqueTaskIds = new HashSet<>();
                         tempUniqueTaskIds.add(report.getTaskId());
-                        dateFinishTaskPair.put(dateStr, tempUniqueTaskIds);
+                        dateConstructTaskPair.put(tempDateStr, tempUniqueTaskIds);
+                    }
+                }
+                // 组装完工任务集合
+                if ("wg".equals(report.getRepairStatus())) {
+                    if (deptTaskFinishPair.containsKey(uniqueKey)) {
+                        String tempDateStr = deptTaskFinishPair.get(uniqueKey);
+                        if (dateFinishTaskPair.containsKey(tempDateStr)) {
+                            Set<Long> tempUniqueTaskIds = dateFinishTaskPair.get(tempDateStr);
+                            tempUniqueTaskIds.add(report.getTaskId());
+                            dateFinishTaskPair.put(tempDateStr, tempUniqueTaskIds);
+                        } else {
+                            Set<Long> tempUniqueTaskIds = new HashSet<>();
+                            tempUniqueTaskIds.add(report.getTaskId());
+                            dateFinishTaskPair.put(tempDateStr, tempUniqueTaskIds);
+                        }
                     }
                 }
             });
@@ -1269,7 +1296,7 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         Map<Long, BigDecimal> cumulativeProductTimePair = new HashMap<>();
         // key队伍id/项目部id   value额定生产时间(H)
         Map<Long, BigDecimal> cumulativeRatedTimePair = new HashMap<>();
-        // key队伍id   value累计运行时效   累计注气量/累计产能
+        // key队伍id   value累计运行时效
         Map<Long, BigDecimal> cumulativeTransitTimePair = new HashMap<>();
 
         // 以 队伍 为维度统计数据
@@ -1298,7 +1325,7 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         Map<Long, BigDecimal> taskRatedProductionTimePair = new HashMap<>();
         if ("2".equals(pageReqVO.getProjectClassification())) {
             // 查询修井 累计施工井数 累计完工井数
-            List<IotRyDailyReportTaskCountVO> repairDeptTasks = iotRyDailyReportMapper.countRepairTasksByDept();
+            List<IotRyDailyReportTaskCountVO> repairDeptTasks = iotRyDailyReportMapper.countRepairTasksByDept(pageReqVO);
             if (CollUtil.isNotEmpty(repairDeptTasks)) {
                 repairDeptTasks.forEach(task -> {
                     totalTasksPair.put(task.getDeptId(), task.getTotalTaskCount());
@@ -1425,6 +1452,10 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         // key日期yyyy-MM-dd   value额定生产时间(H)
         Map<String, BigDecimal> dateRatedTimePair = new HashMap<>();
 
+        // key部门id-任务id    value施工井对应的日期
+        Map<String, String> deptTaskConstructPair = new HashMap<>();
+        // key部门id-任务id    value完工井对应的日期
+        Map<String, String> deptTaskFinishPair = new HashMap<>();
 
         // 以 队伍 为维度统计数据
         // 找到所有项目部与队伍的对应关系
@@ -1451,30 +1482,58 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         // key任务id   value额定生产时间
         Map<Long, BigDecimal> taskRatedProductionTimePair = new HashMap<>();
         if ("2".equals(pageReqVO.getProjectClassification())) {
+
+            // 1. 先校验时间区间数组有效性
+            boolean isCreateTimesValid = createTimes != null && createTimes.length >= 2
+                    && createTimes[0] != null && createTimes[1] != null;
+
+            // 计算累计施工井数 累计完工井数 时 过滤掉 taskId 为空的数据
+            dailyReports.forEach(report -> {
+                // 2. 获取日报创建时间并校验非空
+                LocalDateTime reportCreateTime = report.getCreateTime();
+                if (ObjUtil.isNotEmpty(report.getTaskId()) && allRhChildDeptIds.contains(report.getDeptId())
+                        && ObjUtil.isNotEmpty(reportCreateTime) && isCreateTimesValid
+                        && !reportCreateTime.isBefore(createTimes[0]) && !reportCreateTime.isAfter(createTimes[1])) {
+                    String uniqueKey = StrUtil.join("-", report.getDeptId(), report.getTaskId());
+                    String dateStr = LocalDateTimeUtil.format(report.getCreateTime(), DatePattern.NORM_DATE_PATTERN);
+                    deptTaskConstructPair.put(uniqueKey, dateStr);
+                    deptTaskFinishPair.put(uniqueKey, dateStr);
+                }
+            });
+
             // 查询 指定时间范围内的 修井 累计施工井数 累计完工井数
             // 每天的任务数量 taskId 去重后的数量
             // 每天完工任务数量 taskId 去重后 状态为 wg 的数量
             dailyReports.forEach(report -> {
+                String uniqueKey = StrUtil.join("-", report.getDeptId(), report.getTaskId());
                 String dateStr = LocalDateTimeUtil.format(report.getCreateTime(), DatePattern.NORM_DATE_PATTERN);
-                if (dateConstructTaskPair.containsKey(dateStr)) {
-                    Set<Long> tempUniqueTaskIds = dateConstructTaskPair.get(dateStr);
-                    tempUniqueTaskIds.add(report.getTaskId());
-                    dateConstructTaskPair.put(dateStr, tempUniqueTaskIds);
-                } else {
-                    Set<Long> tempUniqueTaskIds = new HashSet<>();
-                    tempUniqueTaskIds.add(report.getTaskId());
-                    dateConstructTaskPair.put(dateStr, tempUniqueTaskIds);
-                }
-                // 组装完工任务集合
-                if ("wg".equals(report.getRepairStatus())) {
-                    if (dateFinishTaskPair.containsKey(dateStr)) {
-                        Set<Long> tempUniqueTaskIds = dateFinishTaskPair.get(dateStr);
+                if (deptTaskConstructPair.containsKey(uniqueKey)) {
+                    String tempDateStr = deptTaskFinishPair.get(uniqueKey);
+
+                    if (dateConstructTaskPair.containsKey(tempDateStr)) {
+                        Set<Long> tempUniqueTaskIds = dateConstructTaskPair.get(tempDateStr);
                         tempUniqueTaskIds.add(report.getTaskId());
-                        dateFinishTaskPair.put(dateStr, tempUniqueTaskIds);
+                        dateConstructTaskPair.put(tempDateStr, tempUniqueTaskIds);
                     } else {
                         Set<Long> tempUniqueTaskIds = new HashSet<>();
                         tempUniqueTaskIds.add(report.getTaskId());
-                        dateFinishTaskPair.put(dateStr, tempUniqueTaskIds);
+                        dateConstructTaskPair.put(tempDateStr, tempUniqueTaskIds);
+                    }
+                }
+                // 组装完工任务集合
+                if ("wg".equals(report.getRepairStatus())) {
+                    if (deptTaskFinishPair.containsKey(uniqueKey)) {
+                        String tempDateStr = deptTaskFinishPair.get(uniqueKey);
+
+                        if (dateFinishTaskPair.containsKey(tempDateStr)) {
+                            Set<Long> tempUniqueTaskIds = dateFinishTaskPair.get(tempDateStr);
+                            tempUniqueTaskIds.add(report.getTaskId());
+                            dateFinishTaskPair.put(tempDateStr, tempUniqueTaskIds);
+                        } else {
+                            Set<Long> tempUniqueTaskIds = new HashSet<>();
+                            tempUniqueTaskIds.add(report.getTaskId());
+                            dateFinishTaskPair.put(tempDateStr, tempUniqueTaskIds);
+                        }
                     }
                 }
             });