package cn.iocoder.yudao.module.system.dal.mysql.attendance.group;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.group.vo.AttendanceGroupPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.group.AttendanceGroupDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 考勤组 Mapper
 *
 * @author 艾楷
 */
@Mapper
public interface AttendanceGroupMapper extends BaseMapperX<AttendanceGroupDO> {

    default PageResult<AttendanceGroupDO> selectPage(AttendanceGroupPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AttendanceGroupDO>()
                .eqIfPresent(AttendanceGroupDO::getUserId, reqVO.getUserId())
                .likeIfPresent(AttendanceGroupDO::getGroupName, reqVO.getGroupName())
                .eqIfPresent(AttendanceGroupDO::getType, reqVO.getType())
                .eqIfPresent(AttendanceGroupDO::getPunchType, reqVO.getPunchType())
                .eqIfPresent(AttendanceGroupDO::getLongitude, reqVO.getLongitude())
                .eqIfPresent(AttendanceGroupDO::getLatitude, reqVO.getLatitude())
                .eqIfPresent(AttendanceGroupDO::getScope, reqVO.getScope())
                .eqIfPresent(AttendanceGroupDO::getAutoHolidaysFlag, reqVO.getAutoHolidaysFlag())
                .betweenIfPresent(AttendanceGroupDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(AttendanceGroupDO::getId));
    }

    /**
     * 通过当前登录用户获取用户所在群组
     *
     * @param userId
     * @return
     */
    List<AttendanceGroupDO> getByUserId(@Param("userId") Long userId);
}