package com.fdkankan.ucenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fdkankan.ucenter.entity.CameraDetail;
import com.fdkankan.ucenter.entity.CameraType;
import com.fdkankan.ucenter.entity.ScenePlus;
import com.fdkankan.ucenter.entity.ScenePro;
import com.fdkankan.ucenter.mapper.ICameraTypeMapper;
import com.fdkankan.ucenter.service.ICameraDetailService;
import com.fdkankan.ucenter.service.ICameraTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fdkankan.ucenter.service.IScenePlusService;
import com.fdkankan.ucenter.service.ISceneProService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2023-04-12
 */
@Service
public class CameraTypeServiceImpl extends ServiceImpl<ICameraTypeMapper, CameraType> implements ICameraTypeService {

    @Autowired
    ISceneProService sceneProService;
    @Autowired
    IScenePlusService scenePlusService;
    @Autowired
    ICameraDetailService cameraDetailService;
    @Override
    public CameraType getByCameraType(Integer cameraType) {
        LambdaQueryWrapper<CameraType> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CameraType::getCameraType,cameraType);
        return this.getOne(wrapper);
    }

    @Override
    public CameraType getByCameraId(Long cameraId) {
        CameraDetail cameraDetail = cameraDetailService.getByCameraId(cameraId);
        if(cameraDetail!= null){
            return this.getByCameraType(cameraDetail.getType());
        }
        return null;
    }

    @Override
    public CameraType getByNum(String sceneNum) {
        ScenePro scenePro = sceneProService.getByNum(sceneNum);

        Long cameraId = null;
        if(scenePro != null){
            cameraId = scenePro.getCameraId();
        }else {
            ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
            if(scenePlus!= null){
                cameraId = scenePlus.getCameraId();
            }
        }
        if(cameraId != null){
           return this.getByCameraId(cameraId);
        }
        return null;
    }
}
