| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | |
| | | @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; |
| | | |
| | |
| | | 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)); |
| | | //登记人ids |
| | | 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()) { |
| | |
| | | // 使用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()); |
| | |
| | | |
| | | 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()); |
| | |
| | | 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(); |
| | |
| | | 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) { |
| | |
| | | |
| | | 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) { |
| | |
| | | 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)); |