From 4f55d3cb4bc644e4534106336f2047af1a4db5df Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期五, 29 五月 2026 18:09:46 +0800
Subject: [PATCH] feat(config): 添加新环境配置并扩展设备台账功能

---
 src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java |  185 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 138 insertions(+), 47 deletions(-)

diff --git a/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java b/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
index 9729b40..f21e386 100644
--- a/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
+++ b/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
@@ -12,7 +12,9 @@
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.device.mapper.DeviceAreaMapper;
 import com.ruoyi.device.mapper.DeviceLedgerMapper;
+import com.ruoyi.device.pojo.DeviceArea;
 import com.ruoyi.device.mapper.DeviceRepairMapper;
 import com.ruoyi.device.pojo.DeviceLedger;
 import com.ruoyi.device.pojo.DeviceRepair;
@@ -28,6 +30,8 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import java.time.format.DateTimeFormatter;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.util.Date;
 import java.util.*;
 import java.util.function.Function;
@@ -53,30 +57,21 @@
 
     private final DeviceLedgerMapper deviceLedgerMapper;
 
+    private final DeviceAreaMapper deviceAreaMapper;
+
     private static final String INSPECTION_RESULT_ABNORMAL = "0";
     private static final String INSPECTION_RESULT_NORMAL = "1";
     private static final int REPAIR_STATUS_PENDING = 0;
 
     @Override
     public IPage<InspectionTaskDto> selectInspectionTaskList(Page<InspectionTask> page, InspectionTaskDto inspectionTaskDto) {
-        LambdaQueryWrapper<InspectionTask> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.orderByDesc(InspectionTask::getCreateTime);
-        if (StringUtils.isNotBlank(inspectionTaskDto.getTaskName())) {
-            queryWrapper.like(InspectionTask::getTaskName, inspectionTaskDto.getTaskName());
-        }
-        if (StringUtils.isNotBlank(inspectionTaskDto.getInspectionProject())) {
-            queryWrapper.like(InspectionTask::getInspectionProject, inspectionTaskDto.getInspectionProject());
-        }
-        queryWrapper.orderByDesc(InspectionTask::getCreateTime);
-        IPage<InspectionTask> entityPage = inspectionTaskMapper.selectPage(page, queryWrapper);
+        IPage<InspectionTask> entityPage = inspectionTaskMapper.selectInspectionTaskAggregatePage(page, inspectionTaskDto);
 
-        //  鏃犳暟鎹彁鍓嶈繑鍥�
         if (CollectionUtils.isEmpty(entityPage.getRecords())) {
             return new Page<>(entityPage.getCurrent(), entityPage.getSize(), entityPage.getTotal());
         }
-        //鐧昏浜篿ds
+
         List<Long> registrantIds = entityPage.getRecords().stream().map(InspectionTask::getRegistrantId).collect(Collectors.toList());
-        // 鎵归噺鏌ヨ鐧昏浜�
         Map<Long, SysUser> sysUserMap;
         if (!registrantIds.isEmpty()) {
             List<SysUser> sysUsers = sysUserMapper.selectUsersByIds(registrantIds);
@@ -84,9 +79,9 @@
         } else {
             sysUserMap = new HashMap<>();
         }
-        //鑾峰彇鎵�鏈変笉閲嶅鐨勭敤鎴稩D
+
         Set<Long> allUserIds = entityPage.getRecords().stream()
-                .map(InspectionTask::getInspectorId) // 鑾峰彇"2,3"杩欐牱鐨勫瓧绗︿覆
+                .map(InspectionTask::getInspectorId)
                 .filter(StringUtils::isNotBlank)
                 .flatMap(idsStr -> Arrays.stream(idsStr.split(",")))
                 .map(idStr -> {
@@ -99,7 +94,6 @@
                 .filter(Objects::nonNull)
                 .collect(Collectors.toSet());
 
-        // 浣跨敤SQL鎵归噺鏌ヨ鐢ㄦ埛淇℃伅
         Map<Long, String> userIdToNameMap = allUserIds.isEmpty()
                 ? Collections.emptyMap()
                 : sysUserMapper.selectUsersByIds(new ArrayList<>(allUserIds))
@@ -108,42 +102,138 @@
                         SysUser::getUserId,
                         SysUser::getNickName,
                         (existing, replacement) -> existing));
-        List<InspectionTaskDto> dtoList = entityPage.getRecords().stream().map(inspectionTask -> {
-            InspectionTaskDto dto = new InspectionTaskDto();
-            BeanUtils.copyProperties(inspectionTask, dto);  // 澶嶅埗涓诲璞″睘鎬�
 
-            // 璁剧疆鐧昏浜�
-            SysUser sysUser = sysUserMap.get(inspectionTask.getRegistrantId());
-            if (sysUser != null) {
-                dto.setRegistrant(sysUser.getNickName());
-            }
-            // 澶勭悊宸℃浜哄悕绉�
-            if (StringUtils.isNotBlank(inspectionTask.getInspectorId())) {
-                String inspectorNames = Arrays.stream(inspectionTask.getInspectorId().split(","))
-                        .map(String::trim)
-                        .map(idStr -> {
-                            try {
-                                Long userId = Long.parseLong(idStr);
-                                return userIdToNameMap.getOrDefault(userId, "鏈煡鐢ㄦ埛(" + idStr + ")");
-                            } catch (NumberFormatException e) {
-                                return "鏃犳晥ID(" + idStr + ")";
-                            }
-                        })
-                        .collect(Collectors.joining(","));
-                dto.setInspector(inspectorNames);
-            }
+        Set<Long> areaIds = entityPage.getRecords().stream()
+                .map(InspectionTask::getAreaId)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+        Map<Long, String> areaNameMap = new HashMap<>();
+        if (!areaIds.isEmpty()) {
+            List<DeviceArea> areas = deviceAreaMapper.selectBatchIds(new ArrayList<>(areaIds));
+            areas.forEach(area -> areaNameMap.put(area.getId(), area.getAreaName()));
+        }
 
-            dto.setDateStr(inspectionTask.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
-            // 鍒濆鍖栦笁涓檮浠跺垪琛�
-            dto.setCommonFileListVO(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.FILE, RecordTypeEnum.INSPECTION_TASK, inspectionTask.getId()));
-            dto.setCommonFileListAfterVO(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.AFTER_FILE, RecordTypeEnum.INSPECTION_TASK, inspectionTask.getId()));
-            dto.setCommonFileListBeforeVO(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.BEFORE_FILE, RecordTypeEnum.INSPECTION_TASK, inspectionTask.getId()));
+        List<InspectionTaskDto> dtoList = buildInspectionTaskDtoList(
+                entityPage.getRecords(),
+                sysUserMap,
+                userIdToNameMap,
+                areaNameMap
+        );
 
+        IPage<InspectionTaskDto> resultPage = new Page<>();
+        BeanUtils.copyProperties(entityPage, resultPage);
+        resultPage.setRecords(dtoList);
+        return resultPage;
+    }
 
-            return dto;
-        }).collect(Collectors.toList());
+    private List<InspectionTaskDto> buildInspectionTaskDtoList(List<InspectionTask> records,
+                                                               Map<Long, SysUser> sysUserMap,
+                                                               Map<Long, String> userIdToNameMap,
+                                                               Map<Long, String> areaNameMap) {
+        if (CollectionUtils.isEmpty(records)) {
+            return Collections.emptyList();
+        }
+        return records.stream()
+                .map(record -> buildInspectionTaskDto(record, sysUserMap, userIdToNameMap, areaNameMap))
+                .collect(Collectors.toList());
+    }
 
-        // 7. 鏋勫缓杩斿洖鍒嗛〉瀵硅薄
+    private InspectionTaskDto buildInspectionTaskDto(InspectionTask baseTask,
+                                                     Map<Long, SysUser> sysUserMap,
+                                                     Map<Long, String> userIdToNameMap,
+                                                     Map<Long, String> areaNameMap) {
+        InspectionTaskDto dto = new InspectionTaskDto();
+        BeanUtils.copyProperties(baseTask, dto);
+
+        SysUser sysUser = sysUserMap.get(baseTask.getRegistrantId());
+        if (sysUser != null) {
+            dto.setRegistrant(sysUser.getNickName());
+        }
+        if (StringUtils.isNotBlank(baseTask.getInspectorId())) {
+            String inspectorNames = Arrays.stream(baseTask.getInspectorId().split(","))
+                    .map(String::trim)
+                    .map(idStr -> {
+                        try {
+                            Long userId = Long.parseLong(idStr);
+                            return userIdToNameMap.getOrDefault(userId, "鏈煡鐢ㄦ埛(" + idStr + ")");
+                        } catch (NumberFormatException e) {
+                            return "鏃犳晥ID(" + idStr + ")";
+                        }
+                    })
+                    .collect(Collectors.joining(","));
+            dto.setInspector(inspectorNames);
+        }
+
+        if (baseTask.getCreateTime() != null) {
+            dto.setDateStr(baseTask.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+        }
+        if (baseTask.getAreaId() != null) {
+            dto.setAreaName(areaNameMap.getOrDefault(baseTask.getAreaId(), ""));
+        }
+        dto.setCommonFileListVO(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.FILE, RecordTypeEnum.INSPECTION_TASK, baseTask.getId()));
+        dto.setCommonFileListAfterVO(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.AFTER_FILE, RecordTypeEnum.INSPECTION_TASK, baseTask.getId()));
+        dto.setCommonFileListBeforeVO(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.BEFORE_FILE, RecordTypeEnum.INSPECTION_TASK, baseTask.getId()));
+        return dto;
+    }
+
+    @Override
+    public IPage<InspectionTaskDto> selectInspectionTaskRecordList(Page<InspectionTask> page, Long timingId) {
+        InspectionTaskDto queryDto = new InspectionTaskDto();
+        queryDto.setTimingId(timingId);
+        queryDto.setCreateTimeStart(LocalDate.now().atStartOfDay());
+        queryDto.setCreateTimeEnd(queryDto.getCreateTimeStart().plusDays(1));
+
+        IPage<InspectionTask> entityPage = inspectionTaskMapper.selectInspectionTaskAggregatePage(page, queryDto);
+        if (CollectionUtils.isEmpty(entityPage.getRecords())) {
+            return new Page<>(entityPage.getCurrent(), entityPage.getSize(), entityPage.getTotal());
+        }
+
+        List<Long> registrantIds = entityPage.getRecords().stream().map(InspectionTask::getRegistrantId).collect(Collectors.toList());
+        Map<Long, SysUser> sysUserMap;
+        if (!registrantIds.isEmpty()) {
+            List<SysUser> sysUsers = sysUserMapper.selectUsersByIds(registrantIds);
+            sysUserMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, Function.identity()));
+        } else {
+            sysUserMap = new HashMap<>();
+        }
+
+        Set<Long> allUserIds = entityPage.getRecords().stream()
+                .map(InspectionTask::getInspectorId)
+                .filter(StringUtils::isNotBlank)
+                .flatMap(idsStr -> Arrays.stream(idsStr.split(",")))
+                .map(idStr -> {
+                    try {
+                        return Long.parseLong(idStr.trim());
+                    } catch (NumberFormatException e) {
+                        return null;
+                    }
+                })
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+
+        Map<Long, String> userIdToNameMap = allUserIds.isEmpty()
+                ? Collections.emptyMap()
+                : sysUserMapper.selectUsersByIds(new ArrayList<>(allUserIds))
+                .stream()
+                .collect(Collectors.toMap(
+                        SysUser::getUserId,
+                        SysUser::getNickName,
+                        (existing, replacement) -> existing));
+
+        Set<Long> areaIds = entityPage.getRecords().stream()
+                .map(InspectionTask::getAreaId)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+        Map<Long, String> areaNameMap = new HashMap<>();
+        if (!areaIds.isEmpty()) {
+            List<DeviceArea> areas = deviceAreaMapper.selectBatchIds(new ArrayList<>(areaIds));
+            areas.forEach(area -> areaNameMap.put(area.getId(), area.getAreaName()));
+        }
+
+        List<InspectionTaskDto> dtoList = entityPage.getRecords().stream()
+                .map(task -> buildInspectionTaskDto(task, sysUserMap, userIdToNameMap, areaNameMap))
+                .collect(Collectors.toList());
+
         IPage<InspectionTaskDto> resultPage = new Page<>();
         BeanUtils.copyProperties(entityPage, resultPage);
         resultPage.setRecords(dtoList);
@@ -166,6 +256,7 @@
         BeanUtils.copyProperties(inspectionTaskDto, inspectionTask);
         inspectionTask.setRegistrantId(SecurityUtils.getLoginUser().getUserId());
         inspectionTask.setRegistrant(SecurityUtils.getLoginUser().getUsername());
+        inspectionTask.setInspectionStatus(2);
         fillAcceptanceInfo(inspectionTask, oldInspectionTask);
         int i;
         if (Objects.isNull(inspectionTaskDto.getId())) {

--
Gitblit v1.9.3