package com.tuoheng.admin.service.third.airport;

import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.constant.SystemConstant;
import com.tuoheng.admin.mapper.TenantMapper;
import com.tuoheng.common.core.config.common.CommonConfig;
import com.tuoheng.common.core.exception.ServiceException;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class DroneControlService {

    @Autowired
    private TenantMapper tenantMapper;

    public JsonResult execute(JSONObject jsonObject) {
        log.info("进入调用机场平台，操作无人机, jsonObject={}", jsonObject);
        String url = CommonConfig.airportURL + SystemConstant.API_AIRPORT_DRONE_CONTROL;

        log.info("调用机场平台，操作无人机: url:{}", url);
        log.info("调用机场平台，操作无人机: jsonObject:{}", jsonObject);

        String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST");
        log.info("调用机场平台，操作无人机: airPortStr:{}", airPortStr);
        if (StringUtils.isEmpty(airPortStr)) {
            log.info("调用机场平台，操作无人机：返回数据为空");
            return JsonResult.error(-1, "机场平台返回数据为空");
        }
        JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class);
        if (0 != jsonResult.getCode()) {
            log.info("调用机场平台，操作无人机：返回失败，jsonResult：{}", jsonResult.getMsg());
            return JsonResult.error(-1, "机场平台返回失败");
        }
        log.info("调用机场平台方法: 操作无人机结束");
        return JsonResult.success();
    }

}