| | |
| | | import com.dji.sample.component.websocket.service.ISendMessageService; |
| | | import com.dji.sample.manage.model.dto.DeviceDTO; |
| | | import com.dji.sample.manage.model.enums.UserTypeEnum; |
| | | import com.dji.sample.manage.model.receiver.OsdSubDeviceReceiver; |
| | | import com.dji.sample.manage.service.IDeviceRedisService; |
| | | import com.dji.sample.manage.service.IDeviceService; |
| | | import com.dji.sample.media.dao.IFileMapper; |
| | |
| | | import com.dji.sample.media.service.IMediaService; |
| | | import com.dji.sample.wayline.model.dto.WaylineJobDTO; |
| | | import com.dji.sample.wayline.service.IWaylineJobService; |
| | | import com.drew.imaging.ImageProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | |
| | | import java.awt.*; |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Optional; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private String fileAddress; |
| | | @Value("${oss.bucket}") |
| | | private String bucket; |
| | | |
| | | @Override |
| | | public Boolean fastUpload(String workspaceId, String fingerprint) { |
| | | return fileService.checkExist(workspaceId, fingerprint); |
| | | } |
| | | |
| | | @Override |
| | | public Integer saveMediaFile(String workspaceId, FileUploadDTO file) { |
| | | public Integer saveMediaFile(String workspaceId, FileUploadDTO file){ |
| | | return fileService.saveFile(workspaceId, file); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public PaginationData<MediaJobDTO> mediaPage(String workspaceId, SearchMediaParam param) { |
| | | param.setFileAddress(fileAddress+"/"+bucket); |
| | | param.setFileAddress(fileAddress + "/" + bucket); |
| | | Page<MediaJobDTO> waylineJobDTOPage = mapper.mediaPage(new Page<MediaJobDTO>(param.getPage(), param.getPageSize()), workspaceId, param); |
| | | return new PaginationData<MediaJobDTO>(waylineJobDTOPage.getRecords(), new Pagination(waylineJobDTOPage)); |
| | | } |
| | | |
| | | @Override |
| | | public PaginationData<MediaJobDTO> mediaDetail( String jobId,Long page, Long pageSize) { |
| | | Page<MediaJobDTO> waylineJobDTOPage = mapper.mediaDetail(new Page<MediaJobDTO>(page, pageSize), jobId,fileAddress+"/"+bucket); |
| | | public PaginationData<MediaJobDTO> mediaDetail(String jobId, Long page, Long pageSize) { |
| | | Page<MediaJobDTO> waylineJobDTOPage = mapper.mediaDetail(new Page<MediaJobDTO>(page, pageSize), jobId, fileAddress + "/" + bucket); |
| | | return new PaginationData<MediaJobDTO>(waylineJobDTOPage.getRecords(), new Pagination(waylineJobDTOPage)); |
| | | } |
| | | |
| | | /** |
| | | * Handle media files messages reported by dock. |
| | | * 处理由dock报告的媒体文件消息。 |
| | | * |
| | | * @param receiver |
| | | * @return |
| | | */ |
| | | @ServiceActivator(inputChannel = ChannelName.INBOUND_EVENTS_FILE_UPLOAD_CALLBACK, outputChannel = ChannelName.OUTBOUND_EVENTS) |
| | | public CommonTopicReceiver handleFileUploadCallBack(CommonTopicReceiver receiver) { |
| | | public CommonTopicReceiver handleFileUploadCallBack(CommonTopicReceiver receiver) throws IOException, FontFormatException, ImageProcessingException { |
| | | FileUploadCallback callback = objectMapper.convertValue(receiver.getData(), FileUploadCallback.class); |
| | | |
| | | if (callback.getResult() != ResponseResult.CODE_SUCCESS) { |
| | | log.error("媒体文件上传失败;Media file upload failed!"); |
| | | return null; |
| | |
| | | log.error("保存文件到数据库失败,请手动检查数据;Failed to save the file to the database, please check the data manually."); |
| | | return null; |
| | | } |
| | | } else if (!StringUtils.isEmpty(jobId)) { //一键起飞操作需要上传文件 |
| | | } else if (!StringUtils.isEmpty(jobId)) { //一键起飞操作需要 |
| | | WaylineJobDTO waylineJobDTO = new WaylineJobDTO(); |
| | | waylineJobDTO.setWorkspaceId(device.getWorkspaceId()); |
| | | waylineJobDTO.setDockSn(device.getDeviceSn()); |
| | |
| | | /** |
| | | * update the uploaded count and notify web side |
| | | * 更新上传的计数并通知web端 |
| | | * |
| | | * @param mediaFileCount |
| | | * @param receiver |
| | | * @param jobId |
| | |
| | | |
| | | //通过websocket把数据发送给web |
| | | sendMessageService.sendBatch(dock.getWorkspaceId(), UserTypeEnum.WEB.getVal(), |
| | | BizCodeEnum.FILE_UPLOAD_CALLBACK.getCode(), mediaFileCount); |
| | | BizCodeEnum.FILE_UPLOAD_CALLBACK.getCode(), mediaFileCount); |
| | | } |
| | | |
| | | private Boolean parseMediaFile(FileUploadCallback callback, WaylineJobDTO job) { |
| | | private Boolean parseMediaFile(FileUploadCallback callback, WaylineJobDTO job) { |
| | | // Set the drone sn that shoots the media |
| | | Optional<DeviceDTO> dockDTO = deviceService.getDeviceBySn(job.getDockSn()); |
| | | dockDTO.ifPresent(dock -> callback.getFile().getExt().setSn(dock.getChildDeviceSn())); |
| | |
| | | // set path |
| | | String objectKey = callback.getFile().getObjectKey(); |
| | | callback.getFile().setPath(objectKey.substring(objectKey.indexOf("/") + 1, objectKey.lastIndexOf("/"))); |
| | | |
| | | return fileService.saveFile(job.getWorkspaceId(), callback.getFile()) > 0; |
| | | int count =fileService.saveFile(job.getWorkspaceId(), callback.getFile()); |
| | | try { |
| | | fileService.saveMarkFile(job.getWorkspaceId(), callback.getFile()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return count > 0; |
| | | } |
| | | |
| | | /** |
| | | * Handles the highest priority message about media uploads. |
| | | * |
| | | * @param receiver |
| | | * @param headers |
| | | * @return |
| | |
| | | return null; |
| | | } |
| | | sendMessageService.sendBatch(deviceOpt.get().getWorkspaceId(), UserTypeEnum.WEB.getVal(), |
| | | BizCodeEnum.HIGHEST_PRIORITY_UPLOAD_FLIGHT_TASK_MEDIA.getCode(), countDTO); |
| | | BizCodeEnum.HIGHEST_PRIORITY_UPLOAD_FLIGHT_TASK_MEDIA.getCode(), countDTO); |
| | | |
| | | return receiver; |
| | | } |