package cn.iocoder.lyzsys.module.tjt.dal.mysql.yearkvalue;

import cn.iocoder.lyzsys.framework.common.pojo.PageResult;
import cn.iocoder.lyzsys.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.lyzsys.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.lyzsys.module.tjt.controller.admin.yearkvalue.vo.YearKValuePageReqVO;
import cn.iocoder.lyzsys.module.tjt.dal.dataobject.yearkvalue.YearKValueDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

@Mapper
public interface YearKValueMapper extends BaseMapperX<YearKValueDO> {

    default PageResult<YearKValueDO> selectPage(YearKValuePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<YearKValueDO>()
                .eqIfPresent(YearKValueDO::getKYear, reqVO.getKYear())
                .eqIfPresent(YearKValueDO::getEnabledFlag, reqVO.getEnabledFlag())
                .orderByAsc(YearKValueDO::getKYear));
    }

    default YearKValueDO selectByKYear(Integer kYear) {
        return selectOne(new LambdaQueryWrapperX<YearKValueDO>()
                .eq(YearKValueDO::getKYear, kYear));
    }

    default YearKValueDO selectEnabledByKYear(Integer kYear) {
        return selectOne(new LambdaQueryWrapperX<YearKValueDO>()
                .eq(YearKValueDO::getKYear, kYear)
                .eq(YearKValueDO::getEnabledFlag, Boolean.TRUE));
    }

    default List<YearKValueDO> selectEnabledListByYears(Collection<Integer> years) {
        if (years == null || years.isEmpty()) {
            return Collections.emptyList();
        }
        return selectList(new LambdaQueryWrapperX<YearKValueDO>()
                .in(YearKValueDO::getKYear, years)
                .eq(YearKValueDO::getEnabledFlag, Boolean.TRUE));
    }

}
