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

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

import java.util.List;

@Mapper
public interface EmployeeMapper extends BaseMapperX<EmployeeDO> {

    default PageResult<EmployeeDO> selectPage(EmployeePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<EmployeeDO>()
                .likeIfPresent(EmployeeDO::getEmployeeName, reqVO.getEmployeeName())
                .eqIfPresent(EmployeeDO::getOfficeId, reqVO.getOfficeId())
                .eqIfPresent(EmployeeDO::getEmployeeStatus, reqVO.getEmployeeStatus())
                .eqIfPresent(EmployeeDO::getEnabledFlag, reqVO.getEnabledFlag())
                .orderByAsc(EmployeeDO::getSortNo)
                .orderByAsc(EmployeeDO::getId));
    }

    default List<EmployeeDO> selectSimpleList(String keyword, Long officeId, String status, Boolean enabledFlag) {
        return selectList(new LambdaQueryWrapperX<EmployeeDO>()
                .likeIfPresent(EmployeeDO::getEmployeeName, keyword)
                .eqIfPresent(EmployeeDO::getOfficeId, officeId)
                .eqIfPresent(EmployeeDO::getEmployeeStatus, status)
                .eqIfPresent(EmployeeDO::getEnabledFlag, enabledFlag)
                .orderByAsc(EmployeeDO::getSortNo)
                .orderByAsc(EmployeeDO::getId));
    }

    default Long selectCountByOfficeId(Long officeId) {
        return selectCount(new LambdaQueryWrapperX<EmployeeDO>()
                .eq(EmployeeDO::getOfficeId, officeId));
    }

}
