zhangnaisong
2024-03-02 0771b90c0e49714e1682dc133d1bebafb545dd5a
app无人机航线管理提交
已修改2个文件
244 ■■■■■ 文件已修改
ard-work/src/main/java/com/ruoyi/device/uav/controller/ArdUavController.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ard-work/src/main/java/com/ruoyi/device/uav/service/UavService.java 192 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ard-work/src/main/java/com/ruoyi/device/uav/controller/ArdUavController.java
@@ -1,6 +1,8 @@
package com.ruoyi.device.uav.controller;
import com.alibaba.fastjson.JSON;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.device.uav.service.UavService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -65,5 +67,55 @@
        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();
        }
    }
    @PostMapping("/addWaylinesPlanning")
    @ApiOperation("新增航线")
    public Object addWaylinesPlanning(@RequestBody Map<String,Object> param) {
        String url = "wayline/api/v1/waylines/planning";
        return this.uavService.addWaylinesPlanning(url, param);
    }
    @DeleteMapping("/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);
    }
}
ard-work/src/main/java/com/ruoyi/device/uav/service/UavService.java
@@ -13,6 +13,7 @@
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;
@@ -58,6 +59,8 @@
    private String token;
    private String workspaceId;
    @Autowired
    private UavClient uavClient;
    @Autowired
@@ -77,6 +80,10 @@
        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("无人机参数配置缺失:");
        }
@@ -128,6 +135,7 @@
            //token赋值
            this.token = token;
            this.workspaceId = (String) uavUser.get("workspace_id");
        } catch (ForestNetworkException fe) {
            if (fe.getStatusCode() == 401) {//token失效,重新登录
                this.login();
@@ -136,6 +144,7 @@
                token = (String) uavUser.get("access_token");
                //token赋值
                this.token = token;
                this.workspaceId = (String) uavUser.get("workspace_id");
                return token;
            }
        }
@@ -546,4 +555,187 @@
        }
        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();
        }
    }
}