| | |
| | | import com.ruoyi.sy.controller.ArdSyCarController; |
| | | import com.ruoyi.utils.forest.UavClient; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import okhttp3.*; |
| | | import org.apache.commons.codec.binary.Base64; |
| | | import org.apache.commons.collections4.map.HashedMap; |
| | | import org.java_websocket.WebSocket; |
| | |
| | | |
| | | private String token; |
| | | |
| | | private String workspaceId; |
| | | |
| | | @Autowired |
| | | private UavClient uavClient; |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | @Value("${uav.enabled}") |
| | | private Boolean uavEnabled; |
| | | |
| | | @PostConstruct |
| | | public void created() { |
| | | if(!uavEnabled){//无人机加入开关 |
| | | return; |
| | | } |
| | | |
| | | getUavConfig(); |
| | | this.login(); |
| | |
| | | this.username = ConfigUtils.getConfigValue("uav_username"); |
| | | this.password = ConfigUtils.getConfigValue("uav_password"); |
| | | this.salt = ConfigUtils.getConfigValue("uav_salt"); |
| | | /*this.host = "http://112.98.126.2:6100/"; |
| | | this.username = "znstest"; |
| | | this.password = "znstest"; |
| | | this.salt = "0123456789012345";*/ |
| | | if (StringUtils.isEmpty(this.host) || StringUtils.isEmpty(this.username) || StringUtils.isEmpty(this.password) || StringUtils.isEmpty(this.salt)) { |
| | | throw new RuntimeException("无人机参数配置缺失:"); |
| | | } |
| | |
| | | |
| | | //token赋值 |
| | | this.token = token; |
| | | this.workspaceId = (String) uavUser.get("workspace_id"); |
| | | } catch (ForestNetworkException fe) { |
| | | if (fe.getStatusCode() == 401) {//token失效,重新登录 |
| | | this.login(); |
| | |
| | | token = (String) uavUser.get("access_token"); |
| | | //token赋值 |
| | | this.token = token; |
| | | this.workspaceId = (String) uavUser.get("workspace_id"); |
| | | return token; |
| | | } |
| | | } |
| | |
| | | } |
| | | return new Base64().encodeToString(encrypted);//此处使用BASE64做转码功能,同时能起到2次加密的作用。 |
| | | } |
| | | |
| | | public Object checkPointValid(String url, Map<String,Map<String,Object>> data) { |
| | | String token = this.getToken(); |
| | | url = this.host + url; |
| | | Map<String,Object> resultMap = checkPointValid(url,token, data); |
| | | return resultMap; |
| | | } |
| | | |
| | | public Map<String,Object> checkPointValid(String url,String access_token,Map<String,Map<String,Object>> map){ |
| | | MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); |
| | | OkHttpClient okHttpClient = new OkHttpClient(); |
| | | |
| | | RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map)); |
| | | |
| | | Request request = new Request.Builder().url(url).post(body).addHeader("x-auth-token",access_token).build(); |
| | | |
| | | Response response = null; |
| | | try { |
| | | response = okHttpClient.newCall(request).execute(); |
| | | } catch (IOException e1) { |
| | | // TODO Auto-generated catch block |
| | | e1.printStackTrace(); |
| | | } |
| | | |
| | | ResponseBody responseBody = response.body(); |
| | | |
| | | try { |
| | | String message = responseBody.string();// 响应体 |
| | | Map<String,Object> map0 = (Map<String, Object>) JSON.parse(message); |
| | | return map0; |
| | | } catch (IOException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | return new HashMap(); |
| | | } |
| | | } |
| | | |
| | | public Object checkLineValid(String url, Map<String,List<Map<String,String>>> data) { |
| | | String token = this.getToken(); |
| | | url = this.host + url; |
| | | Map<String,Object> resultMap = checkLineValid(url,token, data); |
| | | return resultMap; |
| | | } |
| | | |
| | | public Map<String,Object> checkLineValid(String url,String access_token,Map<String,List<Map<String,String>>> map){ |
| | | MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); |
| | | OkHttpClient okHttpClient = new OkHttpClient(); |
| | | |
| | | RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map)); |
| | | |
| | | Request request = new Request.Builder().url(url).post(body).addHeader("x-auth-token",access_token).build(); |
| | | |
| | | Response response = null; |
| | | try { |
| | | response = okHttpClient.newCall(request).execute(); |
| | | } catch (IOException e1) { |
| | | // TODO Auto-generated catch block |
| | | e1.printStackTrace(); |
| | | } |
| | | |
| | | ResponseBody responseBody = response.body(); |
| | | |
| | | try { |
| | | String message = responseBody.string();// 响应体 |
| | | Map<String,Object> map0 = (Map<String, Object>) JSON.parse(message); |
| | | return map0; |
| | | } catch (IOException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | return new HashMap(); |
| | | } |
| | | } |
| | | |
| | | public String getWorkspaceId(){ |
| | | String token = this.getToken(); |
| | | return this.workspaceId; |
| | | } |
| | | |
| | | public Object addWaylinesPlanning(String url, Map<String,Object> data) { |
| | | String token = this.getToken(); |
| | | url = this.host + url; |
| | | Map<String,Object> resultMap = addWaylinesPlanning(url,token, data); |
| | | return resultMap; |
| | | } |
| | | |
| | | public Map<String,Object> addWaylinesPlanning(String url,String access_token,Map<String,Object> map){ |
| | | MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); |
| | | OkHttpClient okHttpClient = new OkHttpClient(); |
| | | |
| | | RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map)); |
| | | |
| | | Request request = new Request.Builder().url(url).post(body).addHeader("x-auth-token",access_token).build(); |
| | | |
| | | Response response = null; |
| | | try { |
| | | response = okHttpClient.newCall(request).execute(); |
| | | } catch (IOException e1) { |
| | | // TODO Auto-generated catch block |
| | | e1.printStackTrace(); |
| | | } |
| | | |
| | | ResponseBody responseBody = response.body(); |
| | | |
| | | try { |
| | | String message = responseBody.string();// 响应体 |
| | | Map<String,Object> map0 = (Map<String, Object>) JSON.parse(message); |
| | | return map0; |
| | | } catch (IOException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | return new HashMap(); |
| | | } |
| | | } |
| | | |
| | | public Object deleteWaylinesPlanning(String url, Map<String,String> data) { |
| | | String token = this.getToken(); |
| | | String waylineId = data.get("waylineId"); |
| | | url = this.host + url + waylineId; |
| | | Map<String,Object> resultMap = deleteWaylinesPlanning(url,token); |
| | | return resultMap; |
| | | } |
| | | |
| | | public static Map<String,Object> deleteWaylinesPlanning(String url,String access_token){ |
| | | OkHttpClient okHttpClient = new OkHttpClient(); |
| | | |
| | | Request request = new Request.Builder().url(url).delete().addHeader("x-auth-token",access_token).build(); |
| | | |
| | | Response response = null; |
| | | try { |
| | | response = okHttpClient.newCall(request).execute(); |
| | | } catch (IOException e1) { |
| | | // TODO Auto-generated catch block |
| | | e1.printStackTrace(); |
| | | } |
| | | |
| | | ResponseBody responseBody = response.body(); |
| | | |
| | | try { |
| | | String message = responseBody.string();// 响应体 |
| | | Map<String,Object> map0 = (Map<String, Object>) JSON.parse(message); |
| | | return map0; |
| | | } catch (IOException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | return new HashMap(); |
| | | } |
| | | } |
| | | |
| | | public Object updateWaylinesPlanning(String url, Map<String,Object> data) { |
| | | String token = this.getToken(); |
| | | url = this.host + url; |
| | | Map<String,Object> resultMap = updateWaylinesPlanning(url,token, data); |
| | | return resultMap; |
| | | } |
| | | |
| | | public Map<String,Object> updateWaylinesPlanning(String url,String access_token,Map<String,Object> map){ |
| | | MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); |
| | | OkHttpClient okHttpClient = new OkHttpClient(); |
| | | |
| | | RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map)); |
| | | |
| | | Request request = new Request.Builder().url(url).post(body).addHeader("x-auth-token",access_token).build(); |
| | | |
| | | Response response = null; |
| | | try { |
| | | response = okHttpClient.newCall(request).execute(); |
| | | } catch (IOException e1) { |
| | | // TODO Auto-generated catch block |
| | | e1.printStackTrace(); |
| | | } |
| | | |
| | | ResponseBody responseBody = response.body(); |
| | | |
| | | try { |
| | | String message = responseBody.string();// 响应体 |
| | | Map<String,Object> map0 = (Map<String, Object>) JSON.parse(message); |
| | | return map0; |
| | | } catch (IOException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | return new HashMap(); |
| | | } |
| | | } |
| | | |
| | | public Object addAlarm(String url, Map<String,Object> data) { |
| | | String token = this.getToken(); |
| | | url = this.host + url; |
| | | data.put("userName",this.username); |
| | | Map<String,Object> resultMap = addAlarm(url,token, data); |
| | | return resultMap; |
| | | } |
| | | |
| | | public Map<String,Object> addAlarm(String url,String access_token,Map<String,Object> map){ |
| | | MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); |
| | | OkHttpClient okHttpClient = new OkHttpClient(); |
| | | |
| | | RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map)); |
| | | |
| | | Request request = new Request.Builder().url(url).post(body).addHeader("x-auth-token",access_token).build(); |
| | | |
| | | Response response = null; |
| | | try { |
| | | response = okHttpClient.newCall(request).execute(); |
| | | } catch (IOException e1) { |
| | | // TODO Auto-generated catch block |
| | | e1.printStackTrace(); |
| | | } |
| | | |
| | | ResponseBody responseBody = response.body(); |
| | | |
| | | try { |
| | | String message = responseBody.string();// 响应体 |
| | | Map<String,Object> map0 = (Map<String, Object>) JSON.parse(message); |
| | | return map0; |
| | | } catch (IOException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | return new HashMap(); |
| | | } |
| | | } |
| | | |
| | | public Object saveCurrentGroup(String url, Map<String,Object> data) { |
| | | String token = this.getToken(); |
| | | url = this.host + url; |
| | | Map<String,Object> resultMap = addWaylinesPlanning(url,token, data); |
| | | return resultMap; |
| | | } |
| | | |
| | | public Map<String,Object> saveCurrentGroup(String url,String access_token,Map<String,Object> map){ |
| | | MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); |
| | | OkHttpClient okHttpClient = new OkHttpClient(); |
| | | |
| | | RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map)); |
| | | |
| | | Request request = new Request.Builder().url(url).post(body).addHeader("x-auth-token",access_token).build(); |
| | | |
| | | Response response = null; |
| | | try { |
| | | response = okHttpClient.newCall(request).execute(); |
| | | } catch (IOException e1) { |
| | | // TODO Auto-generated catch block |
| | | e1.printStackTrace(); |
| | | } |
| | | |
| | | ResponseBody responseBody = response.body(); |
| | | |
| | | try { |
| | | String message = responseBody.string();// 响应体 |
| | | Map<String,Object> map0 = (Map<String, Object>) JSON.parse(message); |
| | | return map0; |
| | | } catch (IOException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | return new HashMap(); |
| | | } |
| | | } |
| | | } |