package com.ltgk.video.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ltgk.common.utils.sql.MybatisUtil;
import com.ltgk.video.domain.entity.DsVideoPlan;
import com.ltgk.video.mapper.DsVideoPlanMapper;
import com.ltgk.video.service.IDsVideoPlanService;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 视频监控方案数据表 服务实现类
 * </p>
 *
 * @author zhouyaoyao
 * @since 2025-01-19
 */
@Service
public class DsVideoPlanServiceImpl extends ServiceImpl<DsVideoPlanMapper, DsVideoPlan> implements IDsVideoPlanService {

    /**
     * 分页查询
     * @param dsVideoPlan
     * @return
     */
    @Override
    public IPage<DsVideoPlan> selectByPage(DsVideoPlan dsVideoPlan) {
        int pageNum = Objects.isNull(dsVideoPlan.getPageNum()) ? 1 : dsVideoPlan.getPageNum();
        int pageSize = Objects.isNull(dsVideoPlan.getPageSize()) ? 10 : dsVideoPlan.getPageSize();
        IPage<DsVideoPlan> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<DsVideoPlan> queryWrapper = MybatisUtil.notNullField(dsVideoPlan).lambda();
        queryWrapper.orderByDesc(DsVideoPlan::getUpdateAt);
        return baseMapper.selectPage(page, queryWrapper);
    }
}
