package com.tuoheng.admin.controller;

import com.tuoheng.admin.dto.InspectionDto;
import com.tuoheng.admin.entity.FlightData;
import com.tuoheng.admin.request.inspection.*;
import com.tuoheng.admin.service.inspection.IInspectionService;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 巡检任务前端控制器
 *
 * @author wanjing
 * @team tuoheng
 * @date 2022-11-16
 */
@Slf4j
@RestController
@RequestMapping("/inspection")
public class InspectionController {

    @Autowired
    private IInspectionService iInspectionService;

    /**
     * 工作台巡检任务列表
     */
    @GetMapping("/list")
    public JsonResult inspectionCardList(){
//        log.info("进入查询巡检任务列表接口");
        return iInspectionService.inspectionCardList();
    }

    /**
     *根据任务id获取无人机信息
     * @param inspectionId
     * @return
     */
    @GetMapping("/airportMsg/{inspectionId}")
    public JsonResult getAirportMsg(@PathVariable("inspectionId") String inspectionId){
        return iInspectionService.airportMsg(inspectionId);
    }

    /**
     * 根据任务id获取回放视频及任务详情
     * @param inspectionId
     * @return
     */
    @GetMapping("/detailsById/{inspectionId}")
    public JsonResult detailsById(@PathVariable("inspectionId") String inspectionId){
        return iInspectionService.detailsById(inspectionId);
    }


    /**
     * 查询巡检任务分页列表
     */
    @GetMapping("/page/list")
    public JsonResult list(QueryInspectionPageListRequest request) {
//        log.info("进入查询巡检任务分页列表接口");
        return iInspectionService.selectPageList(request);
    }

    /**
     * 获取巡检任务信息信息
     */
    @GetMapping(value = "/info/{id}")
    public JsonResult getInfo(@PathVariable("id") String id) {
//        log.info("进入查询任务详情接口, id={}", id);
        return iInspectionService.getInspectionInfo(id);
    }

    /**
     * 获取巡检任务详情信息
     */
    @GetMapping(value = "/details/{id}")
    public JsonResult getDetails(@PathVariable("id") String id) {
//        log.info("进入查询任务详情接口, id={}", id);
        return iInspectionService.getInspectionDetails(id);
    }

    /**
     * 新增巡检任务
     */
    @PostMapping("/add")
    public JsonResult add(@RequestBody AddInspectionRequest addInspectionRequest) {
//        log.info("进入添加任务接口");
        return iInspectionService.insert(addInspectionRequest);
    }

    /**
     * 修改巡检任务
     */
    @PutMapping("/edit")
    public JsonResult edit(@RequestBody EditInspectionRequest editInspectionRequest) {
//        log.info("进入修改任务接口, id={}", editInspectionRequest.getId());
        return iInspectionService.update(editInspectionRequest);
    }

    /**
     * 删除巡检任务
     */
    @DeleteMapping("/delete/{id}")
    public JsonResult delete(@PathVariable("id") String id) {
//        log.info("进入删除任务接口, id={}", id);
        return iInspectionService.deleteById(id);
    }

    /**
     * 根据机场id查询任务
     *
     * @param dto
     * @return
     */
    @GetMapping("/listByAirportId")
    public JsonResult getListByAirportId(InspectionDto dto) {
        return iInspectionService.getListByAirportId(dto);
    }

    /**
     * 根据id获取任务视频回放和直播
     *
     * @param id
     * @return
     */
    @GetMapping("/videoById/{id}")
    public JsonResult videoById(@PathVariable("id") String id) {
        return iInspectionService.getVideoById(id);
    }


    /**
     * 获取飞行轨迹
     *
     * @param id
     * @return
     */
    @GetMapping("/findFlightData/{id}")
    public JsonResult finFlightData(@PathVariable("id") String id) {
        return iInspectionService.findFlightData(id);
    }

    /**
     * 根据巡检id查询最新一条遥测数据
     *
     * @param inspectionId
     * @return
     */
    @GetMapping("/getFlightDataByInspectionId")
    public FlightData getFlightDataByInspectionId(@RequestParam("inspectionId") String inspectionId) {
        return iInspectionService.getFlightDataByInspectionId(inspectionId);
    }

    /**
     * 重新提交巡检任务
     */
    @PutMapping("/resubmit")
    public JsonResult resubmit(@RequestBody EditInspectionRequest editInspectionRequest) {
        log.info("进入重新提交任务接口, id={}", editInspectionRequest.getId());
        return iInspectionService.resubmit(editInspectionRequest);
    }

    /**
     * 立即执行
     *
     * @param id
     * @return
     */
    @PostMapping("/execute/{id}")
    public JsonResult execute(@PathVariable("id") String id) {
        log.info("进入立即执行任务接口, id={}", id);
        return iInspectionService.execute(id);
    }

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

    /**
     * 上传离线视频
     *
     * @param request
     * @return
     */
    @PostMapping("/uploadFlightUrl")
    public JsonResult uploadFlightUrl(@RequestBody UploadFlightUrlRequest request) {
        log.info("进入上传离线视频回调接口");
        return iInspectionService.uploadFlightUrl(request);
    }

    /**
     * 修改巡检任务
     *
     * @param request
     * @return
     */
    @PostMapping("/updateTaskByCode")
    public JsonResult updateTaskByCode(@RequestBody UpdateTaskByCodeRequest request) {
        log.info("进入修改巡检任务回调接口");
        return iInspectionService.updateTaskByCode(request);
    }

}
