package com.tuoheng.admin.service.cycle.query.one;

import cn.hutool.core.util.ObjectUtil;
import com.tuoheng.admin.conver.InspectionCycleConverMapper;
import com.tuoheng.admin.entity.InspectionCycle;
import com.tuoheng.admin.mapper.DeptMapper;
import com.tuoheng.admin.mapper.InspectionCycleMapper;
import com.tuoheng.admin.service.third.airport.AirportService;
import com.tuoheng.admin.vo.cycle.InspectionCycleVo;
import com.tuoheng.common.core.exception.ServiceException;
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;

/**
 * 查询周期任务业务层处理
 *
 * @author wanjing
 * @team tuoheng
 * @date 2023-08-25
 */
@Slf4j
@Service
public class QueryInspectionCycleService {

    @Autowired
    private DeptMapper deptMapper;

    @Autowired
    private InspectionCycleMapper inspectionCycleMapper;

    @Autowired
    private AirportService airportService;

    public JsonResult get(String id) {
//        log.info("进入查询周期任务业务");
//        User user = CurrentUserUtil.getUserInfo();
        JsonResult result = this.check(id);
        if (0 != result.getCode()) {
            log.info("进入查询周期任务分页列表业务：校验失败：{}", result.getMsg());
            return result;
        }
        InspectionCycle inspectionCycle = (InspectionCycle) result.getData();
        InspectionCycleVo inspectionCycleVo = InspectionCycleConverMapper.INSTANCE.fromInspectionCycleToInspectionCycleVo(inspectionCycle);
        return JsonResult.success(inspectionCycleVo);
    }

    /**
     * 检查参数
     *
     * @param id
     * @return
     */
    private JsonResult check(String id) {
        if (StringUtils.isEmpty(id)) {
            throw new ServiceException("周期任务ID为空");
        }
        InspectionCycle inspectionCycle = inspectionCycleMapper.selectById(id);
        if (ObjectUtil.isEmpty(inspectionCycle)) {
            throw new ServiceException("周期任务不存在");
        }
        return JsonResult.success(inspectionCycle);
    }

}
