package org.sxkj.resource.controller;
|
|
|
import com.aliyuncs.utils.StringUtils;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springblade.core.tool.utils.StringUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.util.CollectionUtils;
|
import org.springframework.web.bind.annotation.*;
|
import org.sxkj.common.func.Streams;
|
import org.sxkj.common.model.PaginationData;
|
import org.sxkj.common.model.ResponseResult;
|
import org.sxkj.common.utils.FileTypeUtils;
|
import org.sxkj.common.utils.HeaderUtils;
|
import org.sxkj.resource.entity.MediaFileEntity;
|
import org.sxkj.resource.model.FileUploadDTO;
|
import org.sxkj.resource.model.MapKeyConst;
|
import org.sxkj.resource.model.MediaJobDTO;
|
import org.sxkj.resource.model.SearchMediaParam;
|
import org.sxkj.resource.service.IFileService;
|
import org.sxkj.resource.vo.MediaFileCountVO;
|
import org.sxkj.resource.vo.MediaFileVO;
|
import org.sxkj.resource.vo.MediaTimeFileVO;
|
import springfox.documentation.annotations.ApiIgnore;
|
|
import java.awt.*;
|
import java.io.IOException;
|
import java.util.Collections;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.concurrent.ConcurrentHashMap;
|
|
/**
|
* @author sean
|
* @version 0.2
|
* @date 2021/12/7
|
*/
|
@Slf4j
|
@RestController
|
@RequestMapping("/media/api/v1/workspaces")
|
@Api(tags = {"媒体资源相关"})
|
public class MediaController {
|
|
@Autowired
|
private IFileService fileService;
|
|
/**
|
* Check if the file has been uploaded by the fingerprint.
|
* 检查文件是否已通过指纹上传。
|
*
|
* @param workspaceId
|
* @param file
|
* @return
|
*/
|
@PostMapping("/{workspace_id}/fast-upload")
|
@ApiIgnore
|
public ResponseResult fastUpload(@PathVariable(name = "workspace_id") String workspaceId, @RequestBody FileUploadDTO file) {
|
|
boolean isExist = fileService.checkExist(workspaceId, file.getFingerprint());
|
|
return isExist ? ResponseResult.success() : ResponseResult.error(file.getFingerprint() + "不存在");
|
}
|
|
|
/**
|
* Query the files that already exist in this workspace based on the workspace id and the collection of tiny fingerprints.
|
*
|
* @param workspaceId
|
* @param tinyFingerprints There is only one tiny_fingerprint parameter in the body.
|
* But it is not recommended to use Map to receive the parameter.
|
* @return
|
*/
|
@PostMapping("/{workspace_id}/files/tiny-fingerprints")
|
@ApiIgnore
|
public ResponseResult<Map<String, List<String>>> uploadCallback(
|
@PathVariable(name = "workspace_id") String workspaceId,
|
@RequestBody Map<String, List<String>> tinyFingerprints) throws JsonProcessingException {
|
|
List<String> existingList = fileService.getExistTinyFingerprints(workspaceId, tinyFingerprints.get(MapKeyConst.TINY_FINGERPRINTS));
|
return ResponseResult.success(new ConcurrentHashMap<>(Map.of(MapKeyConst.TINY_FINGERPRINTS, existingList)));
|
}
|
|
@GetMapping("/{workspace_id}/files/media_page")
|
@ApiIgnore
|
public ResponseResult<PaginationData<MediaJobDTO>> mediaPage(
|
@PathVariable(name = "workspace_id") String workspaceId, @RequestBody SearchMediaParam param) {
|
|
PaginationData<MediaJobDTO> data = fileService.mediaPage(workspaceId, param);
|
return ResponseResult.success(data);
|
}
|
|
|
@GetMapping("/files/detail/{job_id}")
|
@ApiIgnore
|
public ResponseResult<PaginationData<MediaJobDTO>> mediaDetail(
|
@PathVariable(name = "job_id") String jobId, @RequestParam Long page, @RequestParam Long pageSize) {
|
PaginationData<MediaJobDTO> data = fileService.mediaDetail(jobId, page, pageSize);
|
return ResponseResult.success(data);
|
}
|
|
@GetMapping("/files/getMediaFileCountBy")
|
@ApiOperation(value = "首页-任务成果 ", position = 1)
|
public ResponseResult<MediaFileCountVO> getMediaFileCountByResultType(Integer resultType, String areaCode) {
|
return ResponseResult.success(fileService.getMediaFileCountByResultType(resultType, HeaderUtils.formatAreaCode(areaCode)));
|
}
|
|
/**
|
* 任务id
|
*
|
* @param jobIds 任务id
|
* @return
|
*/
|
@ApiModelProperty(name = "jobIds")
|
@GetMapping("/files/getJobsAllFiles")
|
@ApiOperation(value = "航线上事件点的数据", position = 1)
|
public ResponseResult<List<MediaFileEntity>> getJobsAllFiles(@RequestParam("jobIds") List<String> jobIds) {
|
if(CollectionUtils.isEmpty(jobIds)){
|
return ResponseResult.data(Collections.emptyList());
|
}
|
List<MediaFileEntity> list = fileService.getJobsAllFiles(jobIds);
|
list = Streams.filter(list, entity -> {
|
String objectKey = entity.getObjectKey();
|
if (!StringUtils.isEmpty(objectKey)) {
|
return FileTypeUtils.isImageFile(objectKey) || FileTypeUtils.isVideoFile(objectKey);
|
}
|
return false;
|
});
|
return ResponseResult.success(list);
|
|
}
|
|
|
}
|