package com.fdkankan.ucenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fdkankan.ucenter.entity.CameraVersion;
import com.fdkankan.ucenter.mapper.ICameraVersionMapper;
import com.fdkankan.ucenter.service.ICameraVersionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 相机版本表 服务实现类
 * </p>
 *
 * @author 
 * @since 2022-10-13
 */
@Service
public class CameraVersionServiceImpl extends ServiceImpl<ICameraVersionMapper, CameraVersion> implements ICameraVersionService {

    @Override
    public CameraVersion findByStatus(String type) {
        LambdaQueryWrapper<CameraVersion> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CameraVersion::getStatus,"A");
        if(StringUtils.isNotBlank(type)){
            wrapper.eq(CameraVersion::getType,type);
        }else {
            wrapper.eq(CameraVersion::getType,1);
        }
        wrapper.orderByDesc(CameraVersion::getCreateTime);
        List<CameraVersion> list = this.list(wrapper);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
