| | |
| | | import com.ruoyi.basic.pojo.StorageAttachment; |
| | | import com.ruoyi.basic.pojo.StorageBlob; |
| | | import com.ruoyi.basic.service.StorageAttachmentService; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | | import com.ruoyi.common.utils.MinioUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | |
| | | import com.ruoyi.inspectiontask.service.InspectionTaskService; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.sales.mapper.CommonFileMapper; |
| | | import com.ruoyi.sales.pojo.CommonFile; |
| | | import com.ruoyi.sales.service.impl.CommonFileServiceImpl; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.IOException; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Autowired |
| | | private CommonFileServiceImpl commonFileService; |
| | | |
| | | @Autowired |
| | | private CommonFileMapper commonFileMapper; |
| | | |
| | | @Override |
| | | public IPage<InspectionTaskDto> selectInspectionTaskList(Page<InspectionTask> page, InspectionTaskDto inspectionTaskDto) { |
| | | LambdaQueryWrapper<InspectionTask> queryWrapper = new LambdaQueryWrapper<>(); |
| | |
| | | } else { |
| | | sysUserMap = new HashMap<>(); |
| | | } |
| | | //巡检人ids |
| | | List<String> inspectorIds = entityPage.getRecords().stream().map(InspectionTask::getInspectorId).collect(Collectors.toList()); |
| | | |
| | | //获取所有不重复的用户ID |
| | | Set<Long> allUserIds = entityPage.getRecords().stream() |
| | | .map(InspectionTask::getInspectorId) // 获取"2,3"这样的字符串 |
| | |
| | | (existing, replacement) -> existing)); |
| | | |
| | | //处理附件 |
| | | Map<Long, List<StorageAttachment>> attachmentsMap = storageAttachmentMapper.selectList(new LambdaQueryWrapper<StorageAttachment>().in(StorageAttachment::getRecordId, ids) |
| | | .eq(StorageAttachment::getRecordType, InspectionTasks.ordinal())) |
| | | .stream() |
| | | .collect(Collectors.groupingBy(StorageAttachment::getRecordId)); |
| | | // 批量查询所有需要的文件数据 |
| | | Set<Long> blobIds = attachmentsMap.values() |
| | | .stream() |
| | | .flatMap(List::stream) |
| | | .map(StorageAttachment::getStorageBlobId) |
| | | .collect(Collectors.toSet()); |
| | | Map<Long, StorageBlob> blobMap = blobIds.isEmpty() |
| | | ? Collections.emptyMap() |
| | | : storageBlobMapper.selectList(new LambdaQueryWrapper<StorageBlob>().in(StorageBlob::getId, blobIds)) |
| | | .stream() |
| | | .collect(Collectors.toMap(StorageBlob::getId, Function.identity())); |
| | | |
| | | List<CommonFile> commonFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>() |
| | | .in(CommonFile::getCommonId, ids) |
| | | .in(CommonFile::getType, Arrays.asList(FileNameType.INSPECTION.getValue(), FileNameType.INSPECTION_PRODUCTION_BEFORE.getValue(), FileNameType.INSPECTION_PRODUCTION_AFTER.getValue()))); |
| | | if(commonFiles == null){ |
| | | commonFiles = new ArrayList<>(); |
| | | } |
| | | List<CommonFile> finalCommonFiles = commonFiles; |
| | | List<InspectionTaskDto> dtoList = entityPage.getRecords().stream().map(inspectionTask -> { |
| | | InspectionTaskDto dto = new InspectionTaskDto(); |
| | | BeanUtils.copyProperties(inspectionTask, dto); // 复制主对象属性 |
| | |
| | | dto.setInspector(inspectorNames); |
| | | } |
| | | |
| | | // 初始化三个附件列表 |
| | | dto.setBeforeProduction(new ArrayList<>()); |
| | | dto.setAfterProduction(new ArrayList<>()); |
| | | dto.setProductionIssues(new ArrayList<>()); |
| | | dto.setDateStr(inspectionTask.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
| | | |
| | | // 处理附件分类 |
| | | Optional.ofNullable(attachmentsMap.get(inspectionTask.getId())) |
| | | .orElse(Collections.emptyList()) |
| | | .forEach(attachment -> { |
| | | StorageBlob blob = blobMap.get(attachment.getStorageBlobId()); |
| | | if (blob != null) { |
| | | // 创建附件DTO |
| | | StorageBlobDTO blobDto = createBlobDto(blob); |
| | | |
| | | // 根据type分类 |
| | | switch ((int) blob.getType().longValue()) { |
| | | case 0: |
| | | dto.getBeforeProduction().add(blobDto); |
| | | break; |
| | | case 1: |
| | | dto.getAfterProduction().add(blobDto); |
| | | break; |
| | | case 2: |
| | | dto.getProductionIssues().add(blobDto); |
| | | break; |
| | | default: |
| | | // 可选:记录未分类类型 |
| | | break; |
| | | } |
| | | } |
| | | }); |
| | | 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())); |
| | | |
| | | return dto; |
| | | }).collect(Collectors.toList()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int addOrEditInspectionTask(InspectionTaskDto inspectionTaskDto) { |
| | | public int addOrEditInspectionTask(InspectionTaskDto inspectionTaskDto) throws IOException { |
| | | InspectionTask inspectionTask = new InspectionTask(); |
| | | BeanUtils.copyProperties(inspectionTaskDto, inspectionTask); |
| | | inspectionTask.setRegistrantId(SecurityUtils.getLoginUser().getUserId()); |
| | |
| | | i = inspectionTaskMapper.updateById(inspectionTask); |
| | | } |
| | | |
| | | if (inspectionTaskDto.getStorageBlobDTO() != null && !inspectionTaskDto.getStorageBlobDTO().isEmpty()) { |
| | | List<StorageAttachment> attachments = new ArrayList<>(); |
| | | |
| | | for (StorageBlobDTO storageBlobDTO : inspectionTaskDto.getStorageBlobDTO()) { |
| | | StorageAttachment storageAttachment = new StorageAttachment( |
| | | StorageAttachmentFile, |
| | | (long) InspectionTasks.ordinal(), |
| | | inspectionTask.getId() |
| | | ); |
| | | storageAttachment.setStorageBlobDTO(storageBlobDTO); |
| | | attachments.add(storageAttachment); |
| | | } |
| | | storageAttachmentService.saveStorageAttachment(attachments, inspectionTask.getId(), InspectionTasks, StorageAttachmentFile); |
| | | } |
| | | // if (inspectionTaskDto.getStorageBlobDTO() != null && !inspectionTaskDto.getStorageBlobDTO().isEmpty()) { |
| | | // List<StorageAttachment> attachments = new ArrayList<>(); |
| | | // |
| | | // for (StorageBlobDTO storageBlobDTO : inspectionTaskDto.getStorageBlobDTO()) { |
| | | // StorageAttachment storageAttachment = new StorageAttachment( |
| | | // StorageAttachmentFile, |
| | | // (long) InspectionTasks.ordinal(), |
| | | // inspectionTask.getId() |
| | | // ); |
| | | // storageAttachment.setStorageBlobDTO(storageBlobDTO); |
| | | // attachments.add(storageAttachment); |
| | | // } |
| | | // storageAttachmentService.saveStorageAttachment(attachments, inspectionTask.getId(), InspectionTasks, StorageAttachmentFile); |
| | | // } |
| | | commonFileService.migrateTempFilesToFormal(inspectionTask.getId(),inspectionTaskDto.getTempFileIds()); |
| | | return i; |
| | | } |
| | | |
| | |
| | | if (ids == null || ids.length == 0) { |
| | | return 0; |
| | | } |
| | | commonFileService.deleteByBusinessIds(Arrays.asList(ids),FileNameType.INSPECTION.getValue()); |
| | | commonFileService.deleteByBusinessIds(Arrays.asList(ids),FileNameType.INSPECTION_PRODUCTION_BEFORE.getValue()); |
| | | commonFileService.deleteByBusinessIds(Arrays.asList(ids),FileNameType.INSPECTION_PRODUCTION_AFTER.getValue()); |
| | | return inspectionTaskMapper.deleteBatchIds(Arrays.asList(ids)); |
| | | } |
| | | |