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

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.employeeyearleaderoutput.vo.EmployeeYearLeaderOutputPageReqVO;
import cn.iocoder.lyzsys.module.tjt.dal.dataobject.employeeyearleaderoutput.EmployeeYearLeaderOutputDO;
import org.apache.ibatis.annotations.Mapper;

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

@Mapper
public interface EmployeeYearLeaderOutputMapper extends BaseMapperX<EmployeeYearLeaderOutputDO> {

    default PageResult<EmployeeYearLeaderOutputDO> selectPage(EmployeeYearLeaderOutputPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<EmployeeYearLeaderOutputDO>()
                .eqIfPresent(EmployeeYearLeaderOutputDO::getEmployeeId, reqVO.getEmployeeId())
                .likeIfPresent(EmployeeYearLeaderOutputDO::getEmployeeName, reqVO.getEmployeeName())
                .eqIfPresent(EmployeeYearLeaderOutputDO::getOutputYear, reqVO.getOutputYear())
                .eqIfPresent(EmployeeYearLeaderOutputDO::getEnabledFlag, reqVO.getEnabledFlag())
                .orderByDesc(EmployeeYearLeaderOutputDO::getOutputYear)
                .orderByAsc(EmployeeYearLeaderOutputDO::getSortNo)
                .orderByAsc(EmployeeYearLeaderOutputDO::getId));
    }

    default EmployeeYearLeaderOutputDO selectByEmployeeIdAndOutputYear(Long employeeId, Integer outputYear) {
        return selectOne(new LambdaQueryWrapperX<EmployeeYearLeaderOutputDO>()
                .eq(EmployeeYearLeaderOutputDO::getEmployeeId, employeeId)
                .eq(EmployeeYearLeaderOutputDO::getOutputYear, outputYear));
    }

    default List<EmployeeYearLeaderOutputDO> selectListByOutputYear(Integer outputYear) {
        return selectList(new LambdaQueryWrapperX<EmployeeYearLeaderOutputDO>()
                .eq(EmployeeYearLeaderOutputDO::getOutputYear, outputYear));
    }

    default List<EmployeeYearLeaderOutputDO> selectEnabledListByOutputYear(Integer outputYear,
                                                                          Collection<Long> employeeIds) {
        return selectList(new LambdaQueryWrapperX<EmployeeYearLeaderOutputDO>()
                .eq(EmployeeYearLeaderOutputDO::getOutputYear, outputYear)
                .eq(EmployeeYearLeaderOutputDO::getEnabledFlag, Boolean.TRUE)
                .inIfPresent(EmployeeYearLeaderOutputDO::getEmployeeId, employeeIds)
                .orderByAsc(EmployeeYearLeaderOutputDO::getSortNo)
                .orderByAsc(EmployeeYearLeaderOutputDO::getId));
    }

    default Long selectCountByEmployeeId(Long employeeId) {
        return selectCount(new LambdaQueryWrapperX<EmployeeYearLeaderOutputDO>()
                .eq(EmployeeYearLeaderOutputDO::getEmployeeId, employeeId));
    }

}
