package com.tuoheng.admin.service.inspection;

import com.tuoheng.admin.entity.dto.InspectionDto;
import com.tuoheng.admin.entity.domain.FlightData;
import com.tuoheng.admin.entity.request.inspection.*;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.service.flightdata.query.QueryFindFlightDataByInspectionIdService;
import com.tuoheng.admin.service.flightdata.query.QueryFindFlightDataService;
import com.tuoheng.admin.service.flightdata.query.QueryFlightDataTrackService;
import com.tuoheng.admin.service.inspection.add.AddInspectionService;
import com.tuoheng.admin.service.inspection.execute.ExecuteInspectionService;
import com.tuoheng.admin.service.inspection.query.*;
import com.tuoheng.admin.service.inspection.update.UpdateInspectionService;
import com.tuoheng.admin.service.inspection.update.flyer.UpdateFlyerService;
import com.tuoheng.admin.service.inspection.update.status.UpdateExecuteTaskStatusService;
import com.tuoheng.admin.service.inspection.update.status.UpdateInspectionStatusService;
import com.tuoheng.admin.service.inspection.upload.UploadFlightUrlService;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 巡检任务Service业务层处理
 *
 * @team tuoheng
 * @author wanjing
 * @date 2022-11-16
 */
@Slf4j
@Service
public class InspectionServiceImpl implements IInspectionService {

    @Autowired
    private InspectionMapper inspectionMapper;

    @Autowired
    private QueryInspectionPageListService queryInspectionPageListService;

    @Autowired
    private QueryInspectionByIdService queryInspectionByIdService;

    @Autowired
    private QueryInspectionDetailsByIdService queryInspectionDetailsByIdService;

    @Autowired
    private AddInspectionService addinspectionService;

    @Autowired
    private UpdateInspectionService updateInspectionService;

    @Autowired
    private QueryInspectionListService queryInspectionListService;

    @Autowired
    private QueryVideoService queryVideoService;

    @Autowired
    private QueryFindFlightDataService queryFindFlightDataService;

    @Autowired
    private QueryFindFlightDataByInspectionIdService queryFindFlightDataByInspectionIdService;

    @Autowired
    private ExecuteInspectionService executeInspectionService;

    @Autowired
    private UpdateInspectionStatusService updateInspectionStatusService;

    @Autowired
    private QueryFlightDataTrackService queryFlightDataTrackService;

    @Autowired
    private UploadFlightUrlService uploadFlightUrlService;

    @Autowired
    private UpdateFlyerService updateFlyerService;

    @Autowired
    private UpdateExecuteTaskStatusService updateExecuteTaskStatusService;

    @Autowired
    private QueryInspectionCardListService queryInspectionCardListService;

    @Autowired
    private QueryAirportMsgByIdService queryAirportMsgByIdService;

    @Autowired
    private  QueryInspectionDetailsService queryInspectionDetailsService;

    @Autowired
    private QueryInspectionAndAirportStatusService queryInspectionAndAirportStatusService;

    @Autowired
    private QueryInspectionListDataService queryInspectionListDataService;

    /**
     * 查询巡任务
     * @return
     */
    @Override
    public JsonResult inspectionCardList() {
        return queryInspectionCardListService.getInspectionCardList();
    }

    /**
     * 查询巡检任务分页分页列表
     *
     * @param queryInspectionRequest 巡检任务查询实体
     * @return
     */
    @Override
    public JsonResult selectPageList(QueryInspectionPageListRequest queryInspectionRequest) {
        return queryInspectionPageListService.getPageList(queryInspectionRequest);
    }

    /**
     * 查询巡检任务信息
     * 
     * @param id 巡检任务id
     * @return 巡检任务
     */
    @Override
    public JsonResult getInspectionInfo(String id) {
        return queryInspectionByIdService.getInspectionInfo(id);
    }

    /**
     * 查询巡检任务详情
     *
     * @param id 巡检任务id
     * @return 巡检任务
     */
    @Override
    public JsonResult getInspectionDetails(String id) {
        return queryInspectionDetailsByIdService.getInspectionDetails(id);
    }

    /**
     * 查询巡检任务列表
     * 
     * @param request 巡检任务查询实体
     * @return 巡检任务
     */
    @Override
    public JsonResult selectList(QueryInspectionPageListRequest request) {
        log.info("进入查询巡检任务列表业务");
//        Page<Inspection> page = new Page<>(request.getPage(), request.getLimit());
//        request.setUserId(ShiroUtils.getUserId());
//        request.setTenantId(ShiroUtils.getTenantId());

//        List<Inspection> list = inspectionMapper.selectList(page, request);

        return JsonResult.success();
    }

    /**
     * 新增巡检任务
     * 
     * @param addInspectionRequest 新增任务请求参数
     * @return 结果
     */
    @Override
    public JsonResult insert(AddInspectionRequest addInspectionRequest) {
        return addinspectionService.add(addInspectionRequest);
    }

    /**
     * 修改巡检任务
     * 
     * @param editInspectionRequest 修改任务请求参数
     * @return 结果
     */
    @Override
    public JsonResult update(EditInspectionRequest editInspectionRequest) {
        return updateInspectionService.update(editInspectionRequest);
    }

    /**
     * 根据机场id获取当前登录人部门的巡检任务列表
     * @param dto
     * @return
     */
    @Override
    public JsonResult getListByAirportId(InspectionDto dto) {
        return queryInspectionListService.getListByAirportId(dto);
    }

    @Override
    public JsonResult getVideoById(String id) {
        return queryVideoService.getVideoById(id);
    }

    /**
     * 获取飞行轨迹
     * @param id
     * @return
     */
    @Override
    public JsonResult findFlightData(String id) {
        return queryFindFlightDataService.findFlightData(id);
    }

    /**
     * 根据巡检ID查询最新一条遥测数据
     * @param inspectionId
     * @return
     */
    @Override
    public FlightData getFlightDataByInspectionId(String inspectionId) {
        return queryFindFlightDataByInspectionIdService.getFlightData(inspectionId);
    }

    /**
     *立即执行
     * @param id 任务id
     * @return 结果
     */
    @Override
    public JsonResult execute(String id) {
        return executeInspectionService.execute(id);
    }

    /**
     * 被硬件调用，执行任务后，回调执行状态
     */
    @Override
    public JsonResult updateExecuteTaskStatus(ExecuteTaskStatusRequest executeTaskStatusRequest) {
        return updateExecuteTaskStatusService.updateStatus(executeTaskStatusRequest);
    }

    /**
     * 被硬件调用，存任务飞行开始/结束状态
     */
    @Override
    public JsonResult updateStatus(MissionStatusRequest missionStatusRequest) {
        return updateInspectionStatusService.updateStatus(missionStatusRequest);
    }

    /**
     * 被硬件调用，存飞行轨迹
     * @param inspectionRequest
     * @return
     */
    @Override
    public JsonResult track(InspectionRequest inspectionRequest) {
        return queryFlightDataTrackService.track(inspectionRequest);
    }

    /**
     * 上传离线视频
     *
     * @param request
     * @return
     */
    @Override
    public JsonResult uploadFlightUrl(UploadFlightUrlRequest request) {
        return uploadFlightUrlService.uploadFlightUrl(request);
    }

    /**
     * 修改任务(修改任务状态和飞手信息)
     *
     * @param request
     * @return
     */
    @Override
    public JsonResult updateTaskByCode(UpdateTaskByCodeRequest request) {
        return updateFlyerService.update(request);
    }

    /**
     * 根据任务id获取直播和无人机信息
     * @param inspectionId
     * @return
     */
    @Override
    public JsonResult airportMsg(String inspectionId) {
        return queryAirportMsgByIdService.airportMsg(inspectionId);
    }

    /**
     * 获取最新的五条
     * @return
     */
    @Override
    public JsonResult inspectionList() {
        return queryInspectionListDataService.inspectionList();
    }

    /**
     * 页面滑动条展示
     * @return
     */
    @Override
    public JsonResult getList() {
        return queryInspectionAndAirportStatusService.getList();
    }

    /**
     * 根据任务id和无人机id获取直播和机场内外部视频
     * @param inspectionId
     * @param droneId
     * @return
     */
    @Override
    public JsonResult getVideoUrl(String inspectionId, Integer droneId) {
        return queryVideoService.getVideoUrl(inspectionId,droneId);
    }

}
