package com.tuoheng.admin.service.flightdata.query;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.entity.domain.FlightData;
import com.tuoheng.admin.entity.domain.Inspection;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.enums.code.inspection.QueryInspectionInfoByIdCodeEnum;
import com.tuoheng.admin.mapper.FlightDataMapper;
import com.tuoheng.admin.mapper.InspectionMapper;
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;

import java.util.List;

/**
 * 获取飞行轨迹 业务处理层
 *
 * @Author ChengWang
 * @Date 2022/12/1
 */
@Service
@Slf4j
public class QueryFindFlightDataService {

    @Autowired
    private InspectionMapper inspectionMapper;

    @Autowired
    private FlightDataMapper flightDataMapper;

    public JsonResult findFlightData(String id) {
        if (StringUtils.isEmpty(id)) {
            return JsonResult.error(QueryInspectionInfoByIdCodeEnum.INSPECTION_ID_IS_NULL.getCode(), QueryInspectionInfoByIdCodeEnum.INSPECTION_ID_IS_NULL.getMsg());
        }
        Inspection inspection = inspectionMapper.selectOne(new LambdaQueryWrapper<Inspection>()
                .eq(Inspection::getId, id)
                .eq(Inspection::getMark, MarkEnum.VALID.getCode()));
        //根据任务id查询对应的云盒遥测数据
        List<FlightData> listData = flightDataMapper.selectListByInspectionId(id);
        return JsonResult.success(listData);
    }
}
