package com.tuoheng.admin.service.inspection;

import com.tuoheng.admin.dto.InspectionDto;
import com.tuoheng.admin.entity.FlightData;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.request.inspection.*;
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.resubmit.ResubmitInspectionService;
import com.tuoheng.admin.service.inspection.delete.DeleteInspectionService;
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 DeleteInspectionService deleteInspectionService;

    @Autowired
    private QueryInspectionListService queryInspectionListService;

    @Autowired
    private QueryVideoService queryVideoService;

    @Autowired
    private ResubmitInspectionService resubmitInspectionService;

    @Autowired
    private QueryFindFlightDataService queryFindFlightDataService;

    @Autowired
    private QueryFindFlightDataByInspectionIdService queryFindFlightDataByInspectionIdService;

    @Autowired
    private ExecuteInspectionService executeInspectionService;

    @Autowired
    private QueryNewInspectionListService queryNewInspectionListService;

    @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;

    /**
     * 查询巡任务
     * @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);
    }

    /**
     * 删除巡检任务信息
     * 
     * @param id 巡检任务主键
     * @return 结果
     */
    @Override
    public JsonResult deleteById(String id) {
        return deleteInspectionService.deleteById(id);
    }

    /**
     * 根据机场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 editInspectionRequest 修改任务请求参数
     * @return 结果
     */
    @Override
    public JsonResult resubmit(EditInspectionRequest editInspectionRequest) {
        return resubmitInspectionService.resubmit(editInspectionRequest);
    }

    /**
     * 获取飞行轨迹
     * @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);
    }

    /**
     * 根据用户id获取最新的五条任务信息
     * @param
     * @return
     */
    @Override
    public JsonResult getNewInspectionList() {
        return queryNewInspectionListService.getList();
    }

    /**
     * 被硬件调用，执行任务后，回调执行状态
     */
    @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);
    }

    /**
     * 根据任务id获取任务回放视频和任务详情
     * @param inspectionId
     * @return
     */
    @Override
    public JsonResult detailsById(String inspectionId) {
        return queryInspectionDetailsService.detailsById(inspectionId);
    }

}
