吉安感知网项目-后端
linwei
2026-02-05 08d4bb2bf4bfadc9ab5fcf6b0a2bfb543d22b2a0
drone-service/drone-gd/src/main/java/org/sxkj/gd/xingtu/JianXingtuApiService.java
@@ -1,6 +1,7 @@
package org.sxkj.gd.xingtu;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.StringUtil;
@@ -23,6 +24,7 @@
 * @Date 2026/1/26 15:22
 * @Version 1.0
 */
@Slf4j
@Service
public class JianXingtuApiService {
@@ -38,7 +40,8 @@
   /**
    * 获取星图登录token
    * @return  token
    *
    * @return token
    */
   @SneakyThrows
   public String getToken() {
@@ -80,6 +83,7 @@
   /**
    * 设备列表-无人机
    *
    * @param name 名称
    * @return 接口响应
    */
@@ -90,6 +94,7 @@
   /**
    * 设备列表-机巢
    *
    * @param name 名称
    * @return 接口响应
    */
@@ -100,6 +105,7 @@
   /**
    * 新增飞行任务
    *
    * @param param 请求参数
    * @return 接口响应
    */
@@ -121,23 +127,30 @@
      if (StringUtil.isBlank(token) || "获取token失败".equals(token)) {
         return R.fail("获取token失败");
      }
      HttpHeaders headers = new HttpHeaders();
      headers.set("authorization", token);
      HttpEntity<Object> entity = new HttpEntity<>(body, headers);
      ResponseEntity<R> response = restTemplate.exchange(url, HttpMethod.POST, entity, R.class);
      if (response.getStatusCode().is2xxSuccessful()) {
         R responseBody = response.getBody();
         if (responseBody != null) {
            return responseBody;
      try {
         HttpHeaders headers = new HttpHeaders();
         headers.set("authorization", token);
         log.info("请求外部接口: {} {}", url, body);
         HttpEntity<Object> entity = new HttpEntity<>(body, headers);
         ResponseEntity<R> response = restTemplate.exchange(url, HttpMethod.POST, entity, R.class);
         log.info("响应外部接口: {}", response);
         if (response.getStatusCode().is2xxSuccessful()) {
            R responseBody = response.getBody();
            if (responseBody != null) {
               return responseBody;
            }
            return R.fail("接口返回为空");
         }
         return R.fail("接口返回为空");
         return R.fail("请求外部接口失败");
      } catch (Exception e) {
         log.error("请求外部接口异常: ", e);
         return R.fail("请求外部接口异常: " + e.getMessage());
      }
      return R.fail("请求外部接口失败");
   }
   /**
    * 解析JSON字符串为Map
    *
    * @param input JSON字符串
    * @return 解析后的Map
    */