rain
2024-07-16 94a6e4e4bc39153e64f8599e626475c4ce5bdb88
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package com.dji.sample.patches.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.common.util.MinioUrlUtils;
import com.dji.sample.media.model.MediaFileEntity;
import com.dji.sample.media.service.impl.FileServiceImpl;
import com.dji.sample.patches.model.Param.PatchesParam;
import com.dji.sample.patches.model.entity.LotInfo;
import com.dji.sample.patches.service.GetPatchesService;
import com.dji.sample.patches.service.ShpToDataSourceService;
import com.dji.sample.patches.utils.DistrictCodeUtils;
import com.dji.sample.patches.utils.GeoToolsUtil;
import com.dji.sample.patches.utils.PointPO;
import com.dji.sample.patches.utils.TimerUtil;
import com.dji.sample.territory.service.impl.TbDkjbxxServiceImpl;
import com.dji.sample.wayline.model.entity.WaylineFileEntity;
import com.dji.sample.wayline.service.IWaylineFileService;
import com.dji.sample.wayline.service.IWaylineJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.URL;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
 
import static com.dji.sample.component.AuthInterceptor.TOKEN_CLAIM;
 
@RequestMapping("${url.patches.prefix}${url.patches.version}/Patches")
@RestController
public class PatchesController {
    @Autowired
    private GetPatchesService getPatchesService;
    @Autowired
    private ShpToDataSourceService shpToDataSourceService;
    @Autowired
    private IWaylineFileService waylineFileService;
    @Autowired
    private IWaylineJobService waylineJobService;
    @Autowired
    private TbDkjbxxServiceImpl tbDkjbxxService;
    @Autowired
    private FileServiceImpl fileService;
    @Autowired
    private TimerUtil timerUtil;
 
    /**
     * 根据workspaceId获取图斑列表信息
     *
     * @param page
     * @param pageSize
     * @param workspaceId
     * @return
     */
    @GetMapping("/listPatches")
    public ResponseResult<PaginationData<LotInfo>> page(@RequestParam Integer page,
                                                        @RequestParam(name = "page_size", defaultValue = "10") Integer pageSize,
                                                        @RequestParam String workspaceId,
                                                        @RequestParam(name = "dkbh", required = false) String dkbh,
                                                        @RequestParam(name = "xzqdm", required = false) String xzqdm,
                                                        @RequestParam(name = "bsm", required = false) String bsm,
                                                        @RequestParam(name = "xmc", required = false) String xmc,
                                                        @RequestParam(name = "investigate", required = false) Integer investigate
    ) {
        fileService.getNoaddFile();
        //调用service分页查询
        PatchesParam param = PatchesParam.builder()
                .page(page)
                .workspaceId(workspaceId)
                .pageSize(pageSize)
                .dkbh(dkbh)
                .xzqdm(xzqdm)
                .bsm(bsm)
                .xmc(xmc)
                .investigate(investigate)
                .build();
        PaginationData<LotInfo> data = getPatchesService.limitGet(param);
        return ResponseResult.success(data);
    }
 
    /**
     * 删除图斑信息
     * 本接口不需要接收任何参数,调用成功后会删除相应的补丁信息。
     *
     * @return 返回操作结果,如果操作成功,则返回一个成功的响应结果。
     */
    @DeleteMapping("/deletePatches")
    public ResponseResult del(String workspaceId) {
        int count = getPatchesService.delPatches(workspaceId);
        return ResponseResult.success("删除的图斑数量是" + count);
    }
 
    @DeleteMapping("/deleteOne")
    public ResponseResult deleteOne(int id) {
        int count = getPatchesService.deleteOne(id);
        if (count != 0) {
            return ResponseResult.success("图斑删除成功id为" + id);
        }
        return ResponseResult.error("图斑删除失败");
    }
 
    @GetMapping("/getXzq")
    public ResponseResult xzq(@RequestParam String code) {
        String xzq = DistrictCodeUtils.nameToCode(code);
        return ResponseResult.success(xzq);
    }
 
    @GetMapping("/getInfoById")
    public ResponseResult<LotInfo> wayAndPatchesId(@RequestParam String patchesId) {
        return ResponseResult.success(getPatchesService.getPatchesFromId(patchesId));
    }
 
    @GetMapping("/getWayline")
    public ResponseResult getWayline(@RequestParam String waylineName, @RequestBody List<LotInfo> list) {
        try {
            MultipartFile file = timerUtil.getFile(waylineName, list, 25.8917266, 116.020940643);
            return ResponseResult.success(file);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
 
    @GetMapping("/getPoint")
    public List<PointPO> getPoint(@RequestParam List<Integer> list,
                                  @RequestParam Double airportLat,
                                  @RequestParam Double airportLon) {
        List<LotInfo> lotInfos = getPatchesService.getLotInfosByIds(list);
        return GeoToolsUtil.getRoutePointOrder(lotInfos, airportLat, airportLon);
    }
 
    @PostMapping("/patchesToWayline")
    public ResponseResult patchesToWayline(@RequestBody List<LotInfo> lotInfos,
                                           @RequestParam String waylineName,
                                           @RequestParam String spotInFreckle,
                                           @RequestParam String workspaceId,
                                           @RequestParam String patchesId,
                                           @RequestParam double lat,
                                           @RequestParam double lon,
                                           HttpServletRequest request) throws IOException {
        CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM);
        String creator = customClaim.getUsername();
        MultipartFile file = timerUtil.getFile(waylineName, lotInfos, lat, lon);
        waylineFileService.importKmzFile(file, workspaceId, creator, patchesId, spotInFreckle);
        WaylineFileEntity entity = waylineFileService.selectByName(waylineName);
        Map<String, String> infoMap = new HashMap<>();
        URL url = null;
        try {
            url = waylineFileService.getObjectUrl(workspaceId, entity.getWaylineId());
            infoMap.put("url", String.valueOf(MinioUrlUtils.getUrl(url)));
            infoMap.put("waylineId", entity.getWaylineId());
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return ResponseResult.success(infoMap);
    }
 
    @GetMapping("/useMyTask")
    public ResponseResult useMyTask() throws Exception {
        try {
            timerUtil.myTask();
//            timerUtil.myTask2();
//            timerUtil.myTask3();
//            timerUtil.mytask4();
//            timerUtil.mytask5();
//            timerUtil.mytask6();
//            timerUtil.mytask7();
 
        } catch (Exception e) {
            throw new RuntimeException("db存储发送出现异常" + e);
        }
        return ResponseResult.success();
    }
 
    @GetMapping("/tests")
    public ResponseResult use() {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        executor.execute(() -> {
            try {
                timerUtil.sendPostWithFileAndParameter("DB/result_db.db",
                        "635148ea-0ddb-4b23-945c-8a67abd813c9");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
        executor.shutdown();
        return ResponseResult.success();
    }
 
    @PostMapping("/way")
    public void getway(@RequestParam("file") MultipartFile file,
                       @RequestParam String workspaceId,
                       @RequestParam String waylineName,
                       @RequestParam String username) {
        waylineFileService.importKmzFileBack(file, workspaceId, username);
    }
 
    /**
     * 根据图斑的地块编号获取相对应音视频
     *
     * @param page
     * @param pageSize
     * @param workspaceId
     * @param dkbh
     * @return
     */
    @GetMapping("/listPhoto")
    public ResponseResult<PaginationData<MediaFileEntity>> GetPatchesPhoto(@RequestParam(name = "page", defaultValue = "1") Integer page,
                                                                           @RequestParam(name = "page_size", defaultValue = "10") Integer pageSize,
                                                                           @RequestParam String workspaceId,
                                                                           @RequestParam String dkbh) {
 
        try {
            PatchesParam param = PatchesParam.builder()
                    .page(page)
                    .workspaceId(workspaceId)
                    .pageSize(pageSize).build();
            PaginationData<MediaFileEntity> paginationData = getPatchesService.getPhoto(param, dkbh);
            return ResponseResult.success(paginationData);
        } catch (Exception e) {
            e.printStackTrace(); // 记录异常信息到控制台
            return ResponseResult.error("未匹配到相关图片"); // 返回错误信息,可以根据实际情况自定义
        }
    }
 
    /**
     * 上传图斑文件,解析文件并入库,再生成航线并返回
     *
     * @param file
     * @param workspaceId
     * @param waylineName
     * @param airportLat
     * @param airportLon
     * @param request
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadLot")
    public ResponseResult getGeo(@RequestParam("file") MultipartFile file,
                                 @RequestParam String workspaceId,
                                 @RequestParam String waylineName,
                                 @RequestParam double airportLat,
                                 @RequestParam double airportLon,
                                 HttpServletRequest request) throws Exception {
        MultipartFile multipartFile = shpToDataSourceService.insertGeo(file, workspaceId, waylineName, airportLat, airportLon);
        CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM);
        String creator = customClaim.getUsername();
        waylineFileService.importKmzFileBack(multipartFile, workspaceId, creator);
        WaylineFileEntity entity = waylineFileService.selectByName(waylineName);
        Map<String, String> infoMap = new HashMap<>();
        URL url = null;
        try {
            url = waylineFileService.getObjectUrl(workspaceId, entity.getWaylineId());
            infoMap.put("url", String.valueOf(MinioUrlUtils.getUrl(url)));
            infoMap.put("waylineId", entity.getWaylineId());
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return ResponseResult.success(infoMap);
    }
}