From b871e526e794c09708de431899ef6de75886bbc4 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 20 十月 2026 15:22:32 +0800
Subject: [PATCH] feat: 设备巡检优化,巡检项目拆分
---
src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java | 101 +++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 79 insertions(+), 22 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 5826fa7..03bcbc2 100644
--- a/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
+++ b/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
@@ -17,8 +17,10 @@
import com.ruoyi.device.pojo.DeviceLedger;
import com.ruoyi.device.pojo.DeviceRepair;
import com.ruoyi.inspectiontask.dto.InspectionTaskDto;
+import com.ruoyi.inspectiontask.mapper.InspectionTaskItemMapper;
import com.ruoyi.inspectiontask.mapper.InspectionTaskMapper;
import com.ruoyi.inspectiontask.pojo.InspectionTask;
+import com.ruoyi.inspectiontask.pojo.InspectionTaskItem;
import com.ruoyi.inspectiontask.service.InspectionTaskService;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysUserMapper;
@@ -27,9 +29,18 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.Date;
-import java.util.*;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -40,10 +51,12 @@
@Service
@Slf4j
@RequiredArgsConstructor
-public class InspectionTaskServiceImpl extends ServiceImpl<InspectionTaskMapper, InspectionTask> implements InspectionTaskService {
-
+public class InspectionTaskServiceImpl
+ extends ServiceImpl<InspectionTaskMapper, InspectionTask>
+ implements InspectionTaskService {
private final InspectionTaskMapper inspectionTaskMapper;
+ private final InspectionTaskItemMapper inspectionTaskItemMapper;
private final SysUserMapper sysUserMapper;
@@ -64,17 +77,22 @@
if (StringUtils.isNotBlank(inspectionTaskDto.getTaskName())) {
queryWrapper.like(InspectionTask::getTaskName, inspectionTaskDto.getTaskName());
}
- if (StringUtils.isNotBlank(inspectionTaskDto.getInspectionProject())) {
- queryWrapper.like(InspectionTask::getInspectionProject, inspectionTaskDto.getInspectionProject());
- }
IPage<InspectionTask> entityPage = inspectionTaskMapper.selectPage(page, queryWrapper);
// 鏃犳暟鎹彁鍓嶈繑鍥�
if (CollectionUtils.isEmpty(entityPage.getRecords())) {
return new Page<>(entityPage.getCurrent(), entityPage.getSize(), entityPage.getTotal());
}
+ List<Long> inspectionTaskIds = entityPage.getRecords().stream().map(InspectionTask::getId).toList();
+ Map<Long, List<InspectionTaskItem>> recordItemsByTask = inspectionTaskItemMapper.selectList(
+ new LambdaQueryWrapper<InspectionTaskItem>()
+ .in(InspectionTaskItem::getInspectionTaskId, inspectionTaskIds)
+ .orderByAsc(InspectionTaskItem::getSortNum))
+ .stream().collect(Collectors.groupingBy(InspectionTaskItem::getInspectionTaskId));
//鐧昏浜篿ds
- List<Long> registrantIds = entityPage.getRecords().stream().map(InspectionTask::getRegistrantId).collect(Collectors.toList());
+ List<Long> registrantIds = entityPage.getRecords().stream()
+ .map(InspectionTask::getRegistrantId)
+ .collect(Collectors.toList());
// 鎵归噺鏌ヨ鐧昏浜�
Map<Long, SysUser> sysUserMap;
if (!registrantIds.isEmpty()) {
@@ -101,15 +119,15 @@
// 浣跨敤SQL鎵归噺鏌ヨ鐢ㄦ埛淇℃伅
Map<Long, String> userIdToNameMap = allUserIds.isEmpty()
? Collections.emptyMap()
- : sysUserMapper.selectUsersByIds(new ArrayList<>(allUserIds))
- .stream()
- .collect(Collectors.toMap(
- SysUser::getUserId,
- SysUser::getNickName,
- (existing, replacement) -> existing));
+ : sysUserMapper.selectUsersByIds(new ArrayList<>(allUserIds)).stream()
+ .collect(Collectors.toMap(
+ SysUser::getUserId,
+ SysUser::getNickName,
+ (existing, replacement) -> existing));
List<InspectionTaskDto> dtoList = entityPage.getRecords().stream().map(inspectionTask -> {
InspectionTaskDto dto = new InspectionTaskDto();
BeanUtils.copyProperties(inspectionTask, dto); // 澶嶅埗涓诲璞″睘鎬�
+ dto.setInspectionItems(recordItemsByTask.getOrDefault(inspectionTask.getId(), Collections.emptyList()));
// 璁剧疆鐧昏浜�
SysUser sysUser = sysUserMap.get(inspectionTask.getRegistrantId());
@@ -134,10 +152,12 @@
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()));
-
+ 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()));
return dto;
}).collect(Collectors.toList());
@@ -175,6 +195,9 @@
if (i <= 0) {
return i;
}
+ if (inspectionTaskDto.getInspectionItems() != null) {
+ updateInspectionItemStatuses(inspectionTask.getId(), inspectionTaskDto);
+ }
Long linkedRepairId = syncRepairOrderIfAbnormal(inspectionTask, oldInspectionTask);
if (linkedRepairId != null && !Objects.equals(linkedRepairId, inspectionTask.getDeviceRepairId())) {
InspectionTask relationUpdate = new InspectionTask();
@@ -187,6 +210,33 @@
saveInspectionAttachments(inspectionTask.getId(), inspectionTaskDto);
return i;
+ }
+
+ private void updateInspectionItemStatuses(Long inspectionTaskId, InspectionTaskDto request) {
+ List<InspectionTaskItem> requestedItems = request.getInspectionItems();
+ List<InspectionTaskItem> currentItems = inspectionTaskItemMapper.selectList(
+ new LambdaQueryWrapper<InspectionTaskItem>()
+ .eq(InspectionTaskItem::getInspectionTaskId, inspectionTaskId));
+ Map<Long, InspectionTaskItem> currentById = currentItems.stream()
+ .collect(Collectors.toMap(InspectionTaskItem::getId, Function.identity()));
+ Set<Long> seenIds = new HashSet<>();
+ for (InspectionTaskItem requested : requestedItems) {
+ if (requested == null || requested.getId() == null
+ || requested.getItemStatus() == null
+ || (requested.getItemStatus() != 0 && requested.getItemStatus() != 1)
+ || !seenIds.add(requested.getId())) {
+ throw new IllegalArgumentException("宸℃鍐呭鐘舵�佹棤鏁�");
+ }
+ InspectionTaskItem current = currentById.get(requested.getId());
+ if (current == null) {
+ throw new IllegalArgumentException("宸℃鍐呭娓呭崟宸插彉鍖栵紝璇峰埛鏂板悗閲嶈瘯");
+ }
+ current.setItemStatus(requested.getItemStatus());
+ current.setRemarks(requested.getRemarks());
+ current.setCompletedBy(requested.getItemStatus() == 1 ? SecurityUtils.getUserId() : null);
+ current.setCompletedTime(requested.getItemStatus() == 1 ? LocalDateTime.now() : null);
+ inspectionTaskItemMapper.updateById(current);
+ }
}
private void validateInspectionInput(InspectionTaskDto inspectionTaskDto, InspectionTask oldInspectionTask) {
@@ -222,19 +272,24 @@
private boolean hasAnyInspectionPhotoAfterSave(InspectionTaskDto inspectionTaskDto, InspectionTask oldInspectionTask) {
Long recordId = oldInspectionTask == null ? null : oldInspectionTask.getId();
- return hasApplicationPhotoAfterSave(inspectionTaskDto.getCommonFileListDTO(), ApplicationTypeEnum.FILE, recordId)
- || hasApplicationPhotoAfterSave(inspectionTaskDto.getCommonFileListAfterDTO(), ApplicationTypeEnum.AFTER_FILE, recordId)
- || hasApplicationPhotoAfterSave(inspectionTaskDto.getCommonFileListBeforeDTO(), ApplicationTypeEnum.BEFORE_FILE, recordId);
+ return hasApplicationPhotoAfterSave(
+ inspectionTaskDto.getCommonFileListDTO(), ApplicationTypeEnum.FILE, recordId)
+ || hasApplicationPhotoAfterSave(
+ inspectionTaskDto.getCommonFileListAfterDTO(), ApplicationTypeEnum.AFTER_FILE, recordId)
+ || hasApplicationPhotoAfterSave(
+ inspectionTaskDto.getCommonFileListBeforeDTO(), ApplicationTypeEnum.BEFORE_FILE, recordId);
}
- private boolean hasApplicationPhotoAfterSave(List<StorageBlobDTO> requestPhotos, ApplicationTypeEnum applicationType, Long recordId) {
+ private boolean hasApplicationPhotoAfterSave(
+ List<StorageBlobDTO> requestPhotos, ApplicationTypeEnum applicationType, Long recordId) {
if (requestPhotos != null) {
return !requestPhotos.isEmpty();
}
if (recordId == null) {
return false;
}
- return CollectionUtils.isNotEmpty(fileUtil.getStorageAttachmentsByApplicationAndRecordTypeAndRecordId(applicationType, RecordTypeEnum.INSPECTION_TASK, recordId));
+ return CollectionUtils.isNotEmpty(fileUtil.getStorageAttachmentsByApplicationAndRecordTypeAndRecordId(
+ applicationType, RecordTypeEnum.INSPECTION_TASK, recordId));
}
private void fillAcceptanceInfo(InspectionTask inspectionTask, InspectionTask oldInspectionTask) {
@@ -383,6 +438,8 @@
if (ids == null || ids.length == 0) {
return 0;
}
+ inspectionTaskItemMapper.delete(new LambdaQueryWrapper<InspectionTaskItem>()
+ .in(InspectionTaskItem::getInspectionTaskId, Arrays.asList(ids)));
// 鍒犻櫎鏂囦欢
fileUtil.deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordIds(ApplicationTypeEnum.FILE, RecordTypeEnum.INSPECTION_TASK, Arrays.asList(ids));
fileUtil.deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordIds(ApplicationTypeEnum.AFTER_FILE, RecordTypeEnum.INSPECTION_TASK, Arrays.asList(ids));
--
Gitblit v1.9.3