| | |
| | | import lombok.SneakyThrows; |
| | | import org.springblade.core.redis.cache.BladeRedis; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.sxkj.common.jaxt.JianXingTuApiClient; |
| | | import org.sxkj.gd.workorder.dto.GdXingtuFlyTaskSaveDTO; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 设备列表-无人机 |
| | | * @param name 名称 |
| | | * @return 接口响应 |
| | | */ |
| | | public R getDevicePilotList(String name) { |
| | | String url = JianXingTuApiClient.getDevicePilotListUrl(); |
| | | return postWithAuthHeader(url, buildListParams(name)); |
| | | } |
| | | |
| | | /** |
| | | * 设备列表-机巢 |
| | | * @param name 名称 |
| | | * @return 接口响应 |
| | | */ |
| | | public R getDeviceAirportList(String name) { |
| | | String url = JianXingTuApiClient.getDeviceAirportListUrl(); |
| | | return postWithAuthHeader(url, buildListParams(name)); |
| | | } |
| | | |
| | | /** |
| | | * 新增飞行任务 |
| | | * @param param 请求参数 |
| | | * @return 接口响应 |
| | | */ |
| | | public R saveFlyTask(GdXingtuFlyTaskSaveDTO param) { |
| | | String url = JianXingTuApiClient.getFlyTaskSaveUrl(); |
| | | return postWithAuthHeader(url, param); |
| | | } |
| | | |
| | | private Map<String, Object> buildListParams(String name) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | if (StringUtil.isNotBlank(name)) { |
| | | params.put("name", name); |
| | | } |
| | | return params; |
| | | } |
| | | |
| | | private R postWithAuthHeader(String url, Object body) { |
| | | String token = getToken(); |
| | | 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; |
| | | } |
| | | return R.fail("接口返回为空"); |
| | | } |
| | | return R.fail("请求外部接口失败"); |
| | | } |
| | | |
| | | /** |
| | | * 解析JSON字符串为Map |
| | | * @param input JSON字符串 |
| | | * @return 解析后的Map |