吉安感知网项目-后端
xiebin
2026-01-06 d207a86cdf1ab52ef8cb7cd83bad8fceab8038cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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);
 
    }
 
 
}