| | |
| | | |
| | | dto.setDateStr(inspectionTask.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
| | | |
| | | // 初始化三个附件列表 |
| | | dto.setCommonFileList(finalCommonFiles.stream().filter(commonFile -> commonFile.getType().equals(FileNameType.INSPECTION.getValue())).collect(Collectors.toList())); |
| | | dto.setCommonFileListAfter(finalCommonFiles.stream().filter(commonFile -> commonFile.getType().equals(FileNameType.INSPECTION_PRODUCTION_AFTER.getValue())).collect(Collectors.toList())); |
| | | dto.setCommonFileListBefore(finalCommonFiles.stream().filter(commonFile -> commonFile.getType().equals(FileNameType.INSPECTION_PRODUCTION_BEFORE.getValue())).collect(Collectors.toList())); |
| | | // 初始化三个附件列表,按commonId和type过滤 |
| | | Long taskId = inspectionTask.getId(); |
| | | dto.setCommonFileList(finalCommonFiles.stream() |
| | | .filter(commonFile -> commonFile.getCommonId().equals(taskId) && commonFile.getType().equals(FileNameType.INSPECTION.getValue())) |
| | | .collect(Collectors.toList())); |
| | | dto.setCommonFileListAfter(finalCommonFiles.stream() |
| | | .filter(commonFile -> commonFile.getCommonId().equals(taskId) && commonFile.getType().equals(FileNameType.INSPECTION_PRODUCTION_AFTER.getValue())) |
| | | .collect(Collectors.toList())); |
| | | dto.setCommonFileListBefore(finalCommonFiles.stream() |
| | | .filter(commonFile -> commonFile.getCommonId().equals(taskId) && commonFile.getType().equals(FileNameType.INSPECTION_PRODUCTION_BEFORE.getValue())) |
| | | .collect(Collectors.toList())); |
| | | |
| | | |
| | | return dto; |
| | |
| | | i = inspectionTaskMapper.insert(inspectionTask); |
| | | } else { |
| | | i = inspectionTaskMapper.updateById(inspectionTask); |
| | | // 编辑时处理附件删除逻辑 |
| | | handleFileDeletion(inspectionTask.getId(), inspectionTaskDto); |
| | | } |
| | | |
| | | commonFileService.migrateTempFilesToFormal(inspectionTask.getId(),inspectionTaskDto.getTempFileIds()); |
| | | return i; |
| | | } |
| | | |
| | | /** |
| | | * 处理附件删除逻辑:对比原有附件和传入的附件,删除被移除的附件 |
| | | */ |
| | | private void handleFileDeletion(Long taskId, InspectionTaskDto inspectionTaskDto) { |
| | | // 查询原有的三种类型附件 |
| | | List<CommonFile> existingFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>() |
| | | .eq(CommonFile::getCommonId, taskId) |
| | | .in(CommonFile::getType, Arrays.asList( |
| | | FileNameType.INSPECTION.getValue(), |
| | | FileNameType.INSPECTION_PRODUCTION_BEFORE.getValue(), |
| | | FileNameType.INSPECTION_PRODUCTION_AFTER.getValue()))); |
| | | |
| | | if (CollectionUtils.isEmpty(existingFiles)) { |
| | | return; |
| | | } |
| | | |
| | | // 获取前端传入的附件ID集合 |
| | | Set<Long> submittedFileIds = new HashSet<>(); |
| | | if (inspectionTaskDto.getCommonFileList() != null) { |
| | | inspectionTaskDto.getCommonFileList().stream() |
| | | .map(CommonFile::getId) |
| | | .filter(Objects::nonNull) |
| | | .forEach(submittedFileIds::add); |
| | | } |
| | | if (inspectionTaskDto.getCommonFileListBefore() != null) { |
| | | inspectionTaskDto.getCommonFileListBefore().stream() |
| | | .map(CommonFile::getId) |
| | | .filter(Objects::nonNull) |
| | | .forEach(submittedFileIds::add); |
| | | } |
| | | if (inspectionTaskDto.getCommonFileListAfter() != null) { |
| | | inspectionTaskDto.getCommonFileListAfter().stream() |
| | | .map(CommonFile::getId) |
| | | .filter(Objects::nonNull) |
| | | .forEach(submittedFileIds::add); |
| | | } |
| | | |
| | | // 找出需要删除的附件ID(原有但前端没传的) |
| | | List<Long> toDeleteIds = existingFiles.stream() |
| | | .map(CommonFile::getId) |
| | | .filter(id -> !submittedFileIds.contains(id)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 删除附件 |
| | | if (!toDeleteIds.isEmpty()) { |
| | | commonFileService.delCommonFileByIds(toDeleteIds.toArray(new Long[0])); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int delByIds(Long[] ids) { |