@@ -0,0 +1,47 @@ | |||
package com.tuoheng.miniprogram.controller; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.miniprogram.service.AirportService; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.GetMapping; | |||
import org.springframework.web.bind.annotation.PathVariable; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2022/11/30 | |||
*/ | |||
@Slf4j | |||
@RestController | |||
@RequestMapping("/airport") | |||
public class AirPortController { | |||
@Autowired | |||
private AirportService airportService; | |||
/** | |||
* 获取巡检机场 | |||
*/ | |||
@GetMapping("/list") | |||
public JsonResult getList() { | |||
return airportService.getAirportList(); | |||
} | |||
/** | |||
* 获取巡检线路 | |||
* | |||
* @param droneId 机场列表里面的droneId | |||
* @return | |||
*/ | |||
@GetMapping("/line/list/{droneId}") | |||
public JsonResult getAirLineList(@PathVariable("droneId") Integer droneId) { | |||
return airportService.getAirLineList(droneId); | |||
} | |||
} |
@@ -36,24 +36,6 @@ public class InspectionController { | |||
return iInspectionService.index(query); | |||
} | |||
/** | |||
* | |||
* 获取巡检路线 | |||
* @param droneId | |||
* @return | |||
*/ | |||
@GetMapping("/airport/line/{droneId}") | |||
public List<AirLineVO> airLine(@PathVariable("droneId") Integer droneId){ | |||
return iInspectionService.airLine(droneId); | |||
} | |||
/** | |||
* 获取巡检机场 | |||
*/ | |||
@GetMapping("/airport") | |||
public List<AirPortVO> airport() { | |||
return iInspectionService.airport(); | |||
} | |||
/** | |||
* 回放 |
@@ -0,0 +1,39 @@ | |||
package com.tuoheng.miniprogram.enums; | |||
public enum AriportCodeEnum { | |||
GET_NO_TENANT(1000, "获取租户信息失败!"), | |||
BAD_REQUEST(1000, "获取机场信息失败,请重试!"); | |||
/** | |||
* 错误码 | |||
*/ | |||
private Integer code; | |||
/** | |||
* 错误信息 | |||
*/ | |||
private String msg; | |||
AriportCodeEnum(Integer code, String msg){ | |||
this.code = code; | |||
this.msg = msg; | |||
} | |||
public Integer getCode() { | |||
return code; | |||
} | |||
public void setCode(Integer code) { | |||
this.code = code; | |||
} | |||
public String getMsg() { | |||
return msg; | |||
} | |||
public void setMsg(String msg) { | |||
this.msg = msg; | |||
} | |||
} |
@@ -0,0 +1,11 @@ | |||
package com.tuoheng.miniprogram.service; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
public interface AirportService { | |||
JsonResult getAirportList(); | |||
JsonResult getAirLineList(Integer droneId); | |||
} |
@@ -14,9 +14,6 @@ import java.util.List; | |||
public interface IInspectionService { | |||
JsonResult index(InspectionQuery query); | |||
List<AirLineVO> airLine(Integer droneId); | |||
List<AirPortVO> airport(); | |||
JsonResult playback(String id); | |||
@@ -0,0 +1,74 @@ | |||
package com.tuoheng.miniprogram.service.impl; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.utils.JacksonUtil; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import com.tuoheng.miniprogram.dao.TenantMapper; | |||
import com.tuoheng.miniprogram.entity.Tenant; | |||
import com.tuoheng.miniprogram.enums.AriportCodeEnum; | |||
import com.tuoheng.miniprogram.service.AirportService; | |||
import com.tuoheng.miniprogram.utils.ShiroUtils; | |||
import com.tuoheng.miniprogram.vo.AirLineVO; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.Objects; | |||
@Service | |||
public class AirportServiceImpl implements AirportService { | |||
private final static String API_AIRPORT_LIST = "/api/airportInterface/airportList"; | |||
private final static String API_AIRPORT_LINE_LIST = "/api/airportInterface/taskByDroneId"; | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Override | |||
public JsonResult getAirportList() { | |||
//读取不同租户的机场平台url | |||
Tenant tenant = tenantMapper.selectById(ShiroUtils.getTenantId()); | |||
if (ObjectUtil.isEmpty(tenant)) { | |||
return JsonResult.error(AriportCodeEnum.GET_NO_TENANT.getCode(), AriportCodeEnum.GET_NO_TENANT.getMsg()); | |||
} | |||
if (StringUtils.isEmpty(tenant.getAirportUrl())) { | |||
return JsonResult.error(AriportCodeEnum.GET_NO_TENANT.getCode(), AriportCodeEnum.GET_NO_TENANT.getMsg()); | |||
} | |||
String url = tenant.getAirportUrl() + API_AIRPORT_LIST; | |||
String param = "page=1&limit=10"; | |||
String airPortStr = HttpUtils.sendGet(url, param); | |||
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(jsonResult.getData()) && jsonResult.getCode() != 0)) { | |||
return JsonResult.error(AriportCodeEnum.BAD_REQUEST.getCode(), AriportCodeEnum.BAD_REQUEST.getMsg()); | |||
} | |||
return jsonResult; | |||
} | |||
@Override | |||
public JsonResult getAirLineList(Integer droneId) { | |||
//读取不同租户的机场平台url | |||
Tenant tenant = tenantMapper.selectById(ShiroUtils.getTenantId()); | |||
if (ObjectUtil.isEmpty(tenant)) { | |||
return JsonResult.error(AriportCodeEnum.GET_NO_TENANT.getCode(), AriportCodeEnum.GET_NO_TENANT.getMsg()); | |||
} | |||
if (StringUtils.isEmpty(tenant.getAirportUrl())) { | |||
return JsonResult.error(AriportCodeEnum.GET_NO_TENANT.getCode(), AriportCodeEnum.GET_NO_TENANT.getMsg()); | |||
} | |||
String url = tenant.getAirportUrl() + API_AIRPORT_LINE_LIST; | |||
String param = "page=1&limit=100&droneId=" + droneId; | |||
String airPortStr = HttpUtils.sendGet(url, param); | |||
JsonResult<AirLineVO> jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(Objects.requireNonNull(jsonResult).getData()) && jsonResult.getCode() != 0)) { | |||
return JsonResult.error(AriportCodeEnum.BAD_REQUEST.getCode(), AriportCodeEnum.BAD_REQUEST.getMsg()); | |||
} | |||
return jsonResult; | |||
} | |||
} |
@@ -144,46 +144,6 @@ public class InspectionServiceImpl implements IInspectionService { | |||
return JsonResult.success(pageDataVo); | |||
} | |||
@Override | |||
public List<AirLineVO> airLine(Integer droneId) { | |||
//读取不同租户的机场平台url | |||
Tenant tenant = tenantMapper.selectById(ShiroUtils.getTenantId()); | |||
if (ObjectUtil.isEmpty(tenant)) { | |||
throw new ServiceException(ServiceExceptionEnum.GET_NO_TENANT); | |||
} | |||
if (StringUtils.isEmpty(tenant.getAirportUrl())) { | |||
throw new ServiceException(ServiceExceptionEnum.GET_NO_TENANT); | |||
} | |||
String url = tenant.getAirportUrl() + "/api/airportInterface/taskByDroneId"; | |||
String param = "page=1&limit=100&droneId=" + droneId; | |||
String airPortStr = HttpUtils.sendGet(url, param); | |||
JsonResult<AirLineVO> jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(Objects.requireNonNull(jsonResult).getData()) && jsonResult.getCode() != 0)) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取航线信息失败,请重试"); | |||
} | |||
return JSONObject.parseArray(JSONObject.parseObject(JSONObject.toJSONString(jsonResult.getData())).get("records").toString(), AirLineVO.class); | |||
} | |||
@Override | |||
public List<AirPortVO> airport() { | |||
//读取不同租户的机场平台url | |||
Tenant tenant = tenantMapper.selectById(ShiroUtils.getTenantId()); | |||
if (ObjectUtil.isEmpty(tenant)) { | |||
throw new ServiceException(ServiceExceptionEnum.GET_NO_TENANT); | |||
} | |||
if (StringUtils.isEmpty(tenant.getAirportUrl())) { | |||
throw new ServiceException(ServiceExceptionEnum.GET_NO_TENANT); | |||
} | |||
String url = tenant.getAirportUrl() + "/api/airportInterface/airportList"; | |||
String param = "page=1&limit=10"; | |||
String airPortStr = HttpUtils.sendGet(url, param); | |||
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(jsonResult.getData()) && jsonResult.getCode() != 0)) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取机场信息失败,请重试"); | |||
} | |||
return JSONObject.parseArray(JSONObject.parseObject(JSONObject.toJSONString(jsonResult.getData())).get("records").toString(), AirPortVO.class); | |||
} | |||
@Override | |||
public JsonResult playback(String id) { |