aix
2024-08-13 128183e176aab3003a04b517b56162ba2ef780b0
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package com.dji.sample.media.controller;
 
import com.dji.sample.common.model.CustomClaim;
import com.dji.sample.common.model.PaginationData;
import com.dji.sample.common.model.ResponseResult;
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.media.util.ImageDownloaderAndCompressor;
import com.dji.sample.media.util.MinioFileDownloader;
import com.drew.imaging.ImageProcessingException;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
 
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
import static com.dji.sample.component.AuthInterceptor.TOKEN_CLAIM;
import static com.dji.sample.media.util.ImageDownloaderAndCompressor.*;
 
/**
 * @author sean
 * @version 0.2
 * @date 2021/12/9
 */
@RestController
@RequestMapping("${url.media.prefix}${url.media.version}/files")
public class FileController {
 
    @Autowired
    private IFileService fileService;
 
    /**
     * Get information about all the media files in this workspace based on the workspace id.
     * 根据工作空间id获取有关此工作空间中所有媒体文件的信息。
     *
     * @param workspaceId
     * @return
     */
    @GetMapping("/{workspace_id}/files")
    public ResponseResult<PaginationData<MediaFileEntity>> getFilesList(@RequestParam(defaultValue = "1") Long page,
                                                                        @RequestParam(name = "page_size", defaultValue = "10") Long pageSize,
                                                                        @PathVariable(name = "workspace_id") String workspaceId,
                                                                        MediaFileQueryParam mediaFileQueryParam) {
        PaginationData<MediaFileEntity> filesList = fileService.getMediaFilesPaginationByWorkspaceId(workspaceId, page, pageSize, mediaFileQueryParam);
        return ResponseResult.success(filesList);
    }
 
    @GetMapping("/{workspace_id}/listAdded")
    public ResponseResult listIsadd(@RequestParam String dkbh,
                                    @PathVariable(name = "workspace_id") String workspaceId) {
        List<MediaFileEntity> entityList = fileService.listByIsadd(dkbh, workspaceId);
        return ResponseResult.success(entityList);
    }
 
    @GetMapping("/{workspace_id}/getPhotoByJobId")
    public ResponseResult getPhotoByJobId(@RequestParam String jobId,
                                          @RequestParam(defaultValue = "1") int page,
                                          @RequestParam(name = "page_size", defaultValue = "10") int pageSize,
                                          @PathVariable(name = "workspace_id") String workspaceId
    ) {
        return ResponseResult.success(fileService.getPhotoByJobId(page, pageSize, workspaceId, jobId));
    }
 
    @GetMapping("/{workspace_id}/getJobIds")
    public ResponseResult getJobIds(@PathVariable(name = "workspace_id") String workspaceId,
                                    @RequestParam(defaultValue = "1") int page,
                                    @RequestParam(name = "page_size", defaultValue = "10") int pageSize
    ) {
        return ResponseResult.success(fileService.mediaQuerys(page, pageSize, workspaceId));
    }
 
    @PutMapping("/examine")
    public ResponseResult examineData(@RequestParam String fileId) {
        return fileService.updateExamByFileId(fileId);
    }
 
    @GetMapping("/getMediaInfo")
    public ResponseResult mediaInfo(@RequestParam String fileName) {
 
        Object info = fileService.mediaInfo(fileName);
        if (info != null) {
            return ResponseResult.success(info);
        }
        return ResponseResult.error("图片正在加载");
    }
 
    @GetMapping("/{workspace_id}/files/{job_id}")
    public ResponseResult findFilesList(@PathVariable(name = "workspace_id") String workspaceId, @PathVariable(name = "job_id") String jobId) {
        return ResponseResult.success(fileService.listMediaFileEntity(workspaceId, jobId));
    }
 
    @GetMapping("dataShow/{workspace_id}")
    public ResponseResult getMeidaData(@PathVariable(name = "workspace_id") String workspaceId,
                                       @RequestParam Integer page,
                                       @RequestParam(name = "page_size", defaultValue = "10") Integer pageSize,
                                       @RequestParam(name = "photoStart", required = false) Long updateStart,
                                       @RequestParam(name = "photoEnd", required = false) Long updateEnd,
                                       @RequestParam(name = "updateStart", required = false) Long photoStart,
                                       @RequestParam(name = "updateEnd", required = false) Long photoEnd,
                                       @RequestParam(name = "jobName", required = false) String jobName,
                                       @RequestParam(name = "jobId", required = false) String jobId,
                                       @RequestParam(required = false) String type
    ) {
 
        return ResponseResult.success(fileService.mediaQuery(page, pageSize, updateStart, updateEnd, photoStart, photoEnd, jobName, workspaceId, type,jobId));
 
    }
 
    @GetMapping("nailDataShow/{workspace_id}")
    public ResponseResult getNailMeidaData(@PathVariable(name = "workspace_id") String workspaceId,
                                           @RequestParam Integer page,
                                           @RequestParam(name = "page_size", defaultValue = "10") Integer pageSize,
                                           @RequestParam(name = "photoStart", required = false) Long updateStart,
                                           @RequestParam(name = "photoEnd", required = false) Long updateEnd,
                                           @RequestParam(name = "updateStart", required = false) Long photoStart,
                                           @RequestParam(name = "updateEnd", required = false) Long photoEnd,
                                           @RequestParam(name = "jobName", required = false) String jobName,
                                           @RequestParam(required = false) String type
    ) {
 
        return ResponseResult.success(fileService.mediaNailQuery(page, pageSize, updateStart, updateEnd, photoStart, photoEnd, jobName, workspaceId, type));
 
    }
 
    @PostMapping("/{workspace_id}/updateFile")
    public ResponseResult updateFile(HttpServletRequest request, @PathVariable(name = "workspace_id") String workspaceId, @RequestBody MediaFileEntity mediaFileEntity) {
        CustomClaim claims = (CustomClaim) request.getAttribute(TOKEN_CLAIM);
        mediaFileEntity.setUserId(claims.getId());
        return ResponseResult.success(fileService.updateMediaFile(workspaceId, mediaFileEntity));
    }
 
    @DeleteMapping("/{workspace_id}/deleteFile")
    public ResponseResult deleteFile(@PathVariable(name = "workspace_id") String workspaceId, @RequestParam String fileId) {
        //根据fileId删除图片
        int count = fileService.deleteMedia(workspaceId, fileId);
        if (count == 0) {
            return ResponseResult.error("删除失败");
        }
        return ResponseResult.success();
    }
 
 
    /**
     * Query the download address of the file according to the media file id,
     * and redirect to this address directly for download.
     *
     * @param workspaceId
     * @param fileId
     * @param response
     */
    @GetMapping("/{workspace_id}/file/{file_id}/url")
    public void getFileUrl(@PathVariable(name = "workspace_id") String workspaceId,
                           @PathVariable(name = "file_id") String fileId, HttpServletResponse response) {
 
        try {
            URL url = fileService.getObjectUrl(workspaceId, fileId);
            response.sendRedirect(url.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    @PostMapping("/download-images")
    public ResponseResult downloadImages(@RequestBody List<String> jobIds) {
        return fileService.downloadImages(jobIds);
    }
 
    @GetMapping("/refreshPhoto")
    public void refreshPhoto(){
        fileService.getNoaddFile();
    }
}