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())
                .eqIfPresent(EmployeeDO::getOfficeLeaderFlag, reqVO.getOfficeLeaderFlag())
                .orderByAsc(EmployeeDO::getSortNo)
                .orderByAsc(EmployeeDO::getId));
    }

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

    default List<EmployeeDO> selectEnabledList() {
        return selectList(new LambdaQueryWrapperX<EmployeeDO>()
                .eq(EmployeeDO::getEnabledFlag, Boolean.TRUE)
                .orderByAsc(EmployeeDO::getSortNo)
                .orderByAsc(EmployeeDO::getId));
    }

    default List<EmployeeDO> selectEnabledLeaderList() {
        return selectList(new LambdaQueryWrapperX<EmployeeDO>()
                .eq(EmployeeDO::getEnabledFlag, Boolean.TRUE)
                .eq(EmployeeDO::getOfficeLeaderFlag, Boolean.TRUE)
                .orderByAsc(EmployeeDO::getSortNo)
                .orderByAsc(EmployeeDO::getId));
    }

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

}
