From 55a4112533c958492078a5a94c90667e6cf5969c Mon Sep 17 00:00:00 2001 From: ‘liusuyi’ <1951119284@qq.com> Date: 星期六, 13 四月 2024 10:39:22 +0800 Subject: [PATCH] 修改获取附近车辆bug 修改默认所有相机启动引导队列 --- ard-work/src/main/java/com/ruoyi/device/uav/controller/ArdUavController.java | 193 +++++++++++++++++++++++------------------------ 1 files changed, 94 insertions(+), 99 deletions(-) diff --git a/ard-work/src/main/java/com/ruoyi/device/uav/controller/ArdUavController.java b/ard-work/src/main/java/com/ruoyi/device/uav/controller/ArdUavController.java index cf246b5..579a9ed 100644 --- a/ard-work/src/main/java/com/ruoyi/device/uav/controller/ArdUavController.java +++ b/ard-work/src/main/java/com/ruoyi/device/uav/controller/ArdUavController.java @@ -1,32 +1,21 @@ package com.ruoyi.device.uav.controller; -import com.dtflys.forest.exceptions.ForestNetworkException; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.pagehelper.util.StringUtil; +import com.alibaba.fastjson.JSON; import com.ruoyi.common.core.controller.BaseController; -import com.ruoyi.utils.forest.UavClient; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.device.uav.service.UavService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.codec.binary.StringUtils; -import org.jetbrains.annotations.Nullable; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpMethod; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import javax.annotation.PostConstruct; -import javax.crypto.Cipher; -import javax.crypto.spec.SecretKeySpec; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.*; -import org.apache.commons.codec.binary.Base64; -import static org.springframework.http.HttpMethod.GET; -import static org.springframework.http.HttpMethod.POST; +import static org.springframework.http.HttpMethod.*; /** * 鐩告満璁惧Controller @@ -39,108 +28,114 @@ @RequestMapping("/device/uav") @Api(tags = "鏃犱汉鏈哄閮ㄦ帴鍙�") public class ArdUavController extends BaseController { - public static final String USERNAME = "ardbailu"; - public static final String PASSWORD = "ardkj12345"; - public static final String SALT = "0123456789012345"; - - //token 鐧婚檰鍚庢瘡娆¤姹�,鍦╤eader涓惡甯� - private String token;//鐧诲綍鎴愬姛杩斿洖鐨則oken - private ObjectMapper om = new ObjectMapper(); @Autowired - private UavClient uavClient; + private UavService uavService; + + @Value("${uav.enabled}") + private Boolean uavEnabled; @PostConstruct public void created() { - this.uavLogin(); + if(!uavEnabled){//鏃犱汉鏈哄姞鍏ュ紑鍏� + return; + } + this.uavService.login(); } - public void uavLogin() { - String codedPassword = this.Encrypt(PASSWORD, SALT); - String body = "{\"username\":\"" + USERNAME + "\",\"password\":\"" + codedPassword + "\"}"; - try { - String res = uavClient.POST("login", null, body); - Map resMap = om.readValue(res, Map.class); - Map data = (Map) resMap.get("data"); - if (data != null) { - this.token = (String) data.get("access_token"); - } - } catch (ForestNetworkException e) { - e.printStackTrace(); - } catch (JsonMappingException e) { - throw new RuntimeException(e); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } @GetMapping("/") @ApiOperation("鏃犱汉鏈篻et鎺ュ彛") - public Object get(@RequestParam String url, @RequestParam String data) { - return doUavRequest(GET, url, data); + public Object get(@RequestParam String url) { + return this.uavService.doUavRequest(GET, url, "{}"); - } - - @Nullable - private String doUavRequest(HttpMethod method, String url, String data) { - String res = null; - Method requestMethod = null; - //鑾峰彇method - try { - requestMethod = UavClient.class.getMethod(method.name(), String.class, String.class, String.class); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } - //鎵цmethod - try { - res = (String) requestMethod.invoke(this.uavClient, url, this.token, data); - } catch (InvocationTargetException e) { - ForestNetworkException fe = (ForestNetworkException) e.getCause(); - if (fe.getStatusCode() == 401) {//token澶辨晥,閲嶆柊鐧诲綍 - this.uavLogin(); - } - try {//鍐嶆璋冪敤鎺ュ彛 - res = (String) requestMethod.invoke(this.uavClient, url, this.token, data); - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); - } catch (InvocationTargetException ex) { - throw new RuntimeException(ex); - } - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - - return res; } @PostMapping("/") @ApiOperation("鏃犱汉鏈簆ost鎺ュ彛") - public Object post(@RequestParam String url, @RequestParam String data) { - return doUavRequest(POST, url, data); + public Object post(@RequestBody Map<String, String> param) { + String url = param.get("url"); + String data = param.get("data"); + return this.uavService.doUavRequest(POST, url, data); } - public String Encrypt(String sSrc, String sKey) { - if (sKey == null) { - System.out.print("Key涓虹┖null"); - return null; - } - // 鍒ゆ柇Key鏄惁涓�16浣� - if (sKey.length() != 16) { - System.out.print("Key闀垮害涓嶆槸16浣�"); - return null; - } - byte[] encrypted = null; - try { - byte[] raw = sKey.getBytes("utf-8"); - SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); - Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");//"绠楁硶/妯″紡/琛ョ爜鏂瑰紡" - cipher.init(Cipher.ENCRYPT_MODE, skeySpec); - encrypted = cipher.doFinal(sSrc.getBytes("utf-8")); - } catch (Exception e) { + @DeleteMapping("/") + @ApiOperation("鏃犱汉鏈篸elete鎺ュ彛") + public Object delete(@RequestBody Map<String, String> param) { + String url = param.get("url"); + String data = param.get("data"); + return this.uavService.doUavRequest(DELETE, url, data); + } + + @GetMapping("/getToken") + @ApiOperation("鏃犱汉鏈篸elete鎺ュ彛") + public Object getToken() { + + return this.uavService.getToken(); + } + + @PostMapping("/checkPointValid") + @ApiOperation("鏃犱汉鏈烘娴嬭埅鐐规湁鏁堟�ф帴鍙�") + public Object checkPointValid(@RequestBody Map<String,Map<String,Object>> param) { + String url = "wayline/api/v1/waylines/planning/check_point_valid"; + return this.uavService.checkPointValid(url, param); + } + + @PostMapping("/checkLineValid") + @ApiOperation("鏃犱汉鏈烘娴嬬嚎璺湁鏁堟�ф帴鍙�") + public Object checkLineValid(@RequestBody Map<String,List<Map<String,String>>> param) { + String url = "wayline/api/v1/waylines/planning/check_line_valid"; + return this.uavService.checkLineValid(url, param); + } + + @GetMapping("/getWorkspaceId") + @ApiOperation("鑾峰彇宸ヤ綔绌洪棿涓婚敭") + public AjaxResult getWorkspaceId() { + try{ + String workspaceId = this.uavService.getWorkspaceId(); + if(workspaceId != null){ + return AjaxResult.success(workspaceId); + }else{ + return AjaxResult.success(""); + } + }catch(Exception e){ e.printStackTrace(); - ; + return AjaxResult.error(); } - return new Base64().encodeToString(encrypted);//姝ゅ浣跨敤BASE64鍋氳浆鐮佸姛鑳斤紝鍚屾椂鑳借捣鍒�2娆″姞瀵嗙殑浣滅敤銆� } + @PostMapping("/addWaylinesPlanning") + @ApiOperation("鏂板鑸嚎") + public Object addWaylinesPlanning(@RequestBody Map<String,Object> param) { + String url = "wayline/api/v1/waylines/planning"; + return this.uavService.addWaylinesPlanning(url, param); + } + + @PostMapping("/deleteWaylinesPlanning") + @ApiOperation("鍒犻櫎鑸嚎") + public Object deleteWaylinesPlanning(@RequestBody Map<String,String> param) { + String url = "wayline/api/v1/waylines/delete/"; + return this.uavService.deleteWaylinesPlanning(url, param); + } + + @PutMapping("/updateWaylinesPlanning") + @ApiOperation("淇敼鑸嚎") + public Object updateWaylinesPlanning(@RequestBody Map<String,Object> param) { + String url = "wayline/api/v1/waylines/update"; + return this.uavService.updateWaylinesPlanning(url, param); + } + + @PostMapping("/addAlarm") + @ApiOperation("鍗曠偣浠诲姟") + public Object addAlarm(@RequestBody Map<String,Object> param) { + String url = "manage/api/v1/alarms/add"; + return this.uavService.addAlarm(url, param); + } + + @PostMapping("/saveCurrentGroup") + @ApiOperation("鍚屾") + public Object saveCurrentGroup(@RequestBody Map<String,Object> param) { + String url = "wayline/api/v1/waylines/planning/save_current_group"; + return this.uavService.saveCurrentGroup(url, param); + } } -- Gitblit v1.9.3