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.query.InspectionFileQuery;
import com.tuoheng.admin.request.inspection.AddInspectionRequest;
import com.tuoheng.admin.request.inspection.EditInspectionRequest;
import com.tuoheng.admin.request.inspection.InspectionRequest;
import com.tuoheng.admin.request.inspection.QueryInspectionPageListRequest;
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.common.core.common.OperationEnum;
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 QueryFlightDataTrackService queryFlightDataTrackService;


    /**
     * 查询巡检任务分页分页列表
     *
     * @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();
    }

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

}
