| | |
| | | package com.dji.sample.droneairport.controller; |
| | | |
| | | import com.dji.sample.common.model.CustomClaim; |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.droneairport.model.param.AddDeviceParam; |
| | | import com.dji.sample.droneairport.model.param.RegistParam; |
| | | import com.dji.sample.droneairport.dao.DeviceExpanSionMapper; |
| | | import com.dji.sample.droneairport.model.param.ReturnTaskParam; |
| | | import com.dji.sample.droneairport.service.RegistService; |
| | | import com.dji.sample.droneairport.utils.SM2.Utils; |
| | | import com.dji.sample.droneairport.utils.SM4Util; |
| | | import com.dji.sample.manage.service.impl.DeviceRedisServiceImpl; |
| | | import org.bouncycastle.crypto.InvalidCipherTextException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | |
| | | import static com.dji.sample.component.AuthInterceptor.TOKEN_CLAIM; |
| | | |
| | | @RequestMapping("/droneAirport") |
| | | @RestController |
| | | public class RegistController { |
| | | @Autowired |
| | | private RegistService registService; |
| | | @Autowired |
| | | private DeviceExpanSionMapper expanSionDao; |
| | | |
| | | @PostMapping("/RegistService") |
| | | public ResponseResult resgitePort(@RequestBody RegistParam param) { |
| | | return ResponseResult.success(registService.registPort(param)); |
| | | @Autowired |
| | | private DeviceRedisServiceImpl deviceRedisService; |
| | | |
| | | // @PostMapping("/RegistService") |
| | | // public ResponseResult resgitePort(@RequestBody RegistDto param) { |
| | | // return ResponseResult.success(registService.registPort(param)); |
| | | // } |
| | | // @PostMapping("/authorization") |
| | | // public ResponseResult checkDeviceOnline(@RequestBody String body, HttpServletRequest request) throws Exception { |
| | | // String headerValue = request.getHeader("x-lc-secret"); |
| | | // return registService.authorization(body, headerValue); |
| | | // |
| | | // } |
| | | |
| | | @PostMapping("/addDevice/{workspace_id}") |
| | | public ResponseResult registeDrone(@PathVariable(name = "workspace_id") String workspaceId) { |
| | | return ResponseResult.success(registService.addDrone(workspaceId)); |
| | | } |
| | | |
| | | @PostMapping("/addDevice") |
| | | public ResponseResult registeDrone(@RequestBody AddDeviceParam param) { |
| | | param.setBrand("大疆"); |
| | | param.setDeviceid("1581F6QAD241500BDZ3J"); |
| | | param.setModel("M3D"); |
| | | param.setHeight(15); |
| | | param.setLatitude(25.8917271933111); |
| | | param.setLongitude(116.02094292569765); |
| | | param.setRadius(7000); |
| | | param.setRegioncode("360781"); |
| | | return ResponseResult.success(registService.addDrone(param)); |
| | | @GetMapping("/getDroneStatus") |
| | | public ResponseResult droneStatus(@RequestParam String deviceid, HttpServletResponse response) throws Exception { |
| | | Map<String, String> info=registService.getDroneState(deviceid); |
| | | response.setHeader("x-lc-secret", info.get("serect")); |
| | | return ResponseResult.success(200,"获取无人机机场状态成功!",info.get("text"),UUID.randomUUID().toString()); |
| | | } |
| | | |
| | | @PostMapping("/AddTask") |
| | | public ResponseResult AddTask(HttpServletRequest request, @RequestBody String body,HttpServletResponse response) throws Exception { |
| | | String headerValue = request.getHeader("x-lc-secret"); |
| | | CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM); |
| | | String creator = customClaim.getUsername(); |
| | | Map<String, String> info = registService.AddTask(body, headerValue, creator); |
| | | response.setHeader("x-lc-secret", info.get("serect")); |
| | | return ResponseResult.success(200, "无人机机场任务添加成功", info.get("taskid"),info.get("traceId")); |
| | | } |
| | | |
| | | @PostMapping("/updateTask") |
| | | public ResponseResult updateTask(HttpServletRequest request, @RequestBody String body,HttpServletResponse response) throws Exception { |
| | | String headerValue = request.getHeader("x-lc-secret"); |
| | | CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM); |
| | | String creator = customClaim.getUsername(); |
| | | Map<String, String> info = registService.updateTask(body, headerValue, creator); |
| | | response.setHeader("x-lc-secret", info.get("serect")); |
| | | return ResponseResult.success(200, "无人机机场任务更新成功",info.get("taskid"), info.get("traceId")); |
| | | } |
| | | |
| | | @GetMapping("/cancelTask") |
| | | public ResponseResult cancelTask(@RequestParam String taskid,HttpServletResponse response) throws InvalidCipherTextException, IOException { |
| | | Map<String, String> info=registService.cancelTask(taskid); |
| | | response.setHeader("x-lc-secret", info.get("serect")); |
| | | return ResponseResult.success(200,"无人机任务取消成功",info.get("taskid"), UUID.randomUUID().toString()); |
| | | } |
| | | @PostMapping("/queryTaskStatus") |
| | | public ResponseResult queryTaskStatus(HttpServletRequest request, @RequestParam String taskid) throws Exception { |
| | | return registService.queryTaskStatus(taskid); |
| | | } |
| | | @GetMapping("/getResult") |
| | | public ResponseResult getResult(@RequestParam String taskid,HttpServletResponse response) throws InvalidCipherTextException, IOException { |
| | | Map<String, String> info = registService.findDbFilesByTaskId(taskid); |
| | | response.setHeader("x-lc-secret", info.get("serect")); |
| | | return ResponseResult.success(200, "无人机成果获取成功!",info.get("data"), info.get("traceId")); |
| | | } |
| | | @PostMapping("/test") |
| | | public ResponseResult test(@RequestBody AddDeviceParam param) { |
| | | return ResponseResult.success(param); |
| | | } |
| | | @GetMapping("/getDroneStatus") |
| | | public ResponseResult droneStatus(@RequestParam String deviceid){ |
| | | return ResponseResult.success(registService.getDroneState(deviceid)); |
| | | public ResponseResult test(HttpServletRequest request,@RequestBody String param,HttpServletResponse response) throws Exception { |
| | | String headerValue = request.getHeader("x-lc-secret"); |
| | | headerValue=Utils.convertBase64ToHex(headerValue); |
| | | headerValue=Utils.decrypt(headerValue, "00D631FD5615416EAB63D33A9E66E801F95DE840567504210080006081DE877AE3"); |
| | | System.out.println(headerValue); |
| | | String value=SM4Util.decrypt(headerValue,param); |
| | | System.out.println(value); |
| | | String sm= SM4Util.generateSM4Key(); |
| | | String values=SM4Util.encrypt(sm,value); |
| | | String pub=Utils.encrypt(sm,"04225AACF606D800EA3C2C31FCF8FB161B15F7A8D0460DEB91013D4F228C455E76A2ED8D71BC6525B5DC5CC015C155479D8839950344AEE438A3A6305C90F8269F"); |
| | | pub=Utils.hexToBase64(pub); |
| | | response.setHeader("x-lc-secret", pub); |
| | | return ResponseResult.success(values); |
| | | } |
| | | } |