| | |
| | | package com.dji.sample.media.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.dji.sample.common.model.Pagination; |
| | | import com.dji.sample.common.model.PaginationData; |
| | |
| | | import com.dji.sample.media.model.FileUploadDTO; |
| | | import com.dji.sample.media.model.MediaFileDTO; |
| | | import com.dji.sample.media.model.MediaFileEntity; |
| | | import com.dji.sample.media.model.MediaFileQueryParam; |
| | | import com.dji.sample.media.service.IFileService; |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | import com.dji.sample.wayline.model.entity.WaylineJobEntity; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PaginationData<MediaFileDTO> getMediaFilesPaginationByWorkspaceId(String workspaceId, long page, long pageSize) { |
| | | Page<MediaFileEntity> pageData = mapper.selectPage( |
| | | new Page<MediaFileEntity>(page, pageSize), |
| | | new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId) |
| | | .orderByDesc(MediaFileEntity::getId)); |
| | | List<MediaFileDTO> records = pageData.getRecords() |
| | | .stream() |
| | | .map(this::entityConvertToDto) |
| | | .collect(Collectors.toList()); |
| | | |
| | | return new PaginationData<MediaFileDTO>(records, new Pagination(pageData)); |
| | | public List<MediaFileEntity> listMediaFileEntity(String workspaceId, String jobId) { |
| | | return mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId).eq(MediaFileEntity::getJobId,jobId)); |
| | | } |
| | | |
| | | @Override |
| | | public PaginationData<MediaFileEntity> getMediaFilesPaginationByWorkspaceId(String workspaceId, long page, long pageSize, MediaFileQueryParam mediaFileQueryParam) { |
| | | // Page<MediaFileEntity> pageData = mapper.selectPage( |
| | | // new Page<MediaFileEntity>(page, pageSize), |
| | | // new LambdaQueryWrapper<MediaFileEntity>() |
| | | // .eq(MediaFileEntity::getWorkspaceId, workspaceId) |
| | | // .orderByDesc(MediaFileEntity::getId)); |
| | | Page<MediaFileEntity> pageData = mapper.selectPage(new Page<MediaFileEntity>(page, pageSize), new LambdaQueryWrapper<MediaFileEntity>() |
| | | .eq(MediaFileEntity::getWorkspaceId,workspaceId) |
| | | .orderByDesc(MediaFileEntity::getCreateTime)); |
| | | |
| | | List<MediaFileEntity> records = pageData.getRecords() |
| | | .stream() |
| | | .collect(Collectors.toList()); |
| | | return new PaginationData<MediaFileEntity>(records, new Pagination(pageData)); |
| | | } |
| | | |
| | | public int deleteMedia(String workspaceId, String fileId) { |
| | | int count=mapper.delete(new LambdaUpdateWrapper<MediaFileEntity>().eq(MediaFileEntity::getFileId, fileId) |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId)); |
| | | return count; |
| | | } |
| | | @Override |
| | | public URL getObjectUrl(String workspaceId, String fileId) { |
| | | Optional<MediaFileEntity> mediaFileOpt = getMediaByFileId(workspaceId, fileId); |
| | | if (mediaFileOpt.isEmpty()) { |
| | | throw new IllegalArgumentException("{} doesn't exist."); |
| | | throw new IllegalArgumentException("{} 不存在"); |
| | | } |
| | | |
| | | return ossService.getObjectUrl(OssConfiguration.bucket, mediaFileOpt.get().getObjectKey()); |
| | |
| | | .map(this::entityConvertToDto).collect(Collectors.toList()); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean updateMediaFile(String workspaceId, MediaFileEntity mediaFileEntity) { |
| | | |
| | | /*MediaFileEntity params = new MediaFileEntity(); |
| | | params.setFileId(mediaFileEntity.getFileId()); |
| | | params.setWorkspaceId(mediaFileEntity.getWorkspaceId());*/ |
| | | boolean update1 = new LambdaUpdateChainWrapper<>(mapper).eq(MediaFileEntity::getFileId, mediaFileEntity.getFileId()) |
| | | .set(MediaFileEntity::getFileName, mediaFileEntity.getFileName()) |
| | | .set(MediaFileEntity::getCollectStatus,mediaFileEntity.getCollectStatus()) |
| | | .set(MediaFileEntity::getUserId,mediaFileEntity.getUserId()) |
| | | .update(); |
| | | // int update = mapper.update(mediaFileEntity, Wrappers.update(params)); |
| | | return update1; |
| | | } |
| | | |
| | | /** |
| | | * Convert the received file object into a database entity object. |
| | | * @param file |
| | |
| | | if (file != null) { |
| | | builder.fileName(file.getName()) |
| | | .filePath(file.getPath()) |
| | | .isadd(0) |
| | | .fingerprint(file.getFingerprint()) |
| | | .objectKey(file.getObjectKey()) |
| | | .subFileType(file.getSubFileType()) |
| | | .isOriginal(file.getExt().getIsOriginal()) |
| | | .jobId(file.getExt().getFlightId()) |
| | | .drone(file.getExt().getSn()) |
| | | .drone(file.getExt().getSn()).metadata(file.getMetadata()) |
| | | .tinnyFingerprint(file.getExt().getTinnyFingerprint()); |
| | | |
| | | // domain-type-subType |
| | |
| | | .objectKey(entity.getObjectKey()) |
| | | .tinnyFingerprint(entity.getTinnyFingerprint()) |
| | | .payload(entity.getPayload()) |
| | | .metadata(entity.getMetadata()) |
| | | .createTime(LocalDateTime.ofInstant( |
| | | Instant.ofEpochMilli(entity.getCreateTime()), ZoneId.systemDefault())) |
| | | .drone(entity.getDrone()) |