package cn.iocoder.yudao.module.attendance.dal.mysql.business;

import java.time.LocalDate;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.attendance.dal.dataobject.business.AttendanceBusinessDO;
import cn.iocoder.yudao.module.system.enums.common.DeletedEnum;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.attendance.controller.admin.business.vo.*;

/**
 * 出差信息 Mapper
 *
 * @author zhaopq
 */
@Mapper
public interface AttendanceBusinessMapper extends BaseMapperX<AttendanceBusinessDO> {

    default PageResult<AttendanceBusinessDO> selectPage(AttendanceBusinessPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AttendanceBusinessDO>()
                .eqIfPresent(AttendanceBusinessDO::getBusinessId, reqVO.getBusinessId())
                .eqIfPresent(AttendanceBusinessDO::getEmployeeId, reqVO.getEmployeeId())
                .eqIfPresent(AttendanceBusinessDO::getEmployeeUuid, reqVO.getEmployeeUuid())
                .likeIfPresent(AttendanceBusinessDO::getEmployeeName, reqVO.getEmployeeName())
                .eqIfPresent(AttendanceBusinessDO::getEmployeePhone, reqVO.getEmployeePhone())
                .eqIfPresent(AttendanceBusinessDO::getUserId, reqVO.getUserId())
                .eqIfPresent(AttendanceBusinessDO::getUserUuid, reqVO.getUserUuid())
                .eqIfPresent(AttendanceBusinessDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(AttendanceBusinessDO::getDeptUuid, reqVO.getDeptUuid())
                .eqIfPresent(AttendanceBusinessDO::getPostId, reqVO.getPostId())
                .eqIfPresent(AttendanceBusinessDO::getPosition, reqVO.getPosition())
                .eqIfPresent(AttendanceBusinessDO::getReason, reqVO.getReason())
                .eqIfPresent(AttendanceBusinessDO::getDestination, reqVO.getDestination())
                .betweenIfPresent(AttendanceBusinessDO::getStartDate, reqVO.getStartDate())
                .betweenIfPresent(AttendanceBusinessDO::getEndDate, reqVO.getEndDate())
                .eqIfPresent(AttendanceBusinessDO::getDay, reqVO.getDay())
                .eqIfPresent(AttendanceBusinessDO::getEstimatedCost, reqVO.getEstimatedCost())
                .eqIfPresent(AttendanceBusinessDO::getRemarks, reqVO.getRemarks())
                .eqIfPresent(AttendanceBusinessDO::getStatus, reqVO.getStatus())
                .eqIfPresent(AttendanceBusinessDO::getInfoSource, reqVO.getInfoSource())
                .eqIfPresent(AttendanceBusinessDO::getCreatorEmployeeId, reqVO.getCreatorEmployeeId())
                .likeIfPresent(AttendanceBusinessDO::getCreatorEmployeeName, reqVO.getCreatorEmployeeName())
                .betweenIfPresent(AttendanceBusinessDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(AttendanceBusinessDO::getTenantId, reqVO.getTenantId())
                .eq(AttendanceBusinessDO::getDeleted, DeletedEnum.FALSE)
                .orderByDesc(AttendanceBusinessDO::getId));
    }

    default AttendanceBusinessDO selectByDateAndEmployeeId(LocalDate date, Long employeeId) {
        return selectOne(new LambdaQueryWrapperX<AttendanceBusinessDO>()
                .eqIfPresent(AttendanceBusinessDO::getEmployeeId, employeeId)
                .geIfPresent(AttendanceBusinessDO::getStartDate, date)
                .leIfPresent(AttendanceBusinessDO::getEndDate, date)
                .orderByDesc(AttendanceBusinessDO::getId));
    }

}