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

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.entity.domain.Camera;
import com.tuoheng.admin.entity.domain.ThMission;
import com.tuoheng.admin.entity.request.camera.QueryCameraListRequest;
import com.tuoheng.admin.entity.request.emergency.QueryEmergencyListRequest;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.enums.MissionEnum;
import com.tuoheng.admin.enums.TaskStatusEnum;
import com.tuoheng.admin.mapper.CameraMapper;
import com.tuoheng.admin.mapper.ThMissionMapper;
import com.tuoheng.common.utils.JsonResult;
import com.tuoheng.system.entity.User;
import com.tuoheng.system.utils.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 查询应急任务列表业务层处理
 *
 * @author wanjing
 * @team tuoheng
 * @date 2023-02-13
 */
@Slf4j
@Service
public class QueryEmergencyListService {

    @Autowired
    private ThMissionMapper thMissionMapper;

    public JsonResult getList(QueryEmergencyListRequest request) {
//        log.info("进入查询应急任务列表业务");
        User user = ShiroUtils.getUserInfo();
        Integer tenantId = user.getTenantId();
        request.setTenantId(tenantId);
        JsonResult result = this.check(tenantId, request);
        if (0 != result.getCode()) {
            log.info("进入查询应急任务列表业务：校验失败：{}", result.getMsg());
            return result;
        }

        List<ThMission> missionList = thMissionMapper.selectList(new LambdaQueryWrapper<ThMission>()
                        .eq(ThMission::getMark, MarkEnum.VALID.getCode())
                        .eq(ThMission::getTenantId, tenantId)
                        .eq(ObjectUtil.isNotEmpty(request.getAirportFlyType()), ThMission::getAirportFlyType, request.getAirportFlyType())
                        .in(CollectionUtil.isNotEmpty(request.getStatusList()), ThMission::getStatus, request.getStatusList()));

        if (CollectionUtil.isEmpty(missionList)) {
            log.info("应急任务列表数据为空");
        }
        return JsonResult.success(missionList);
    }

    /**
     * 检查参数
     *
     * @param tenantId
     * @param request
     * @return
     */
    private JsonResult check(Integer tenantId, QueryEmergencyListRequest request) {
        return JsonResult.success();
    }

}
