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

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.api.attendance.dto.AttendancePunchRecordDTO;
import cn.iocoder.yudao.module.system.api.attendance.vo.AttendancePunchRecordVO;
import cn.iocoder.yudao.module.system.controller.admin.punchrecord.vo.AttendancePunchRecordPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.punchrecord.AttendancePunchRecordDO;
import cn.iocoder.yudao.module.system.service.attendance.punch.dto.AttendanceOnTheDayDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 用户打卡记录 Mapper
 *
 * @author 艾楷
 */
@Mapper
public interface AttendancePunchRecordMapper extends BaseMapperX<AttendancePunchRecordDO> {
//
    default PageResult<AttendancePunchRecordDO> selectPage(AttendancePunchRecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AttendancePunchRecordDO>()
                .eqIfPresent(AttendancePunchRecordDO::getUserId, reqVO.getUserId())
                .eqIfPresent(AttendancePunchRecordDO::getAttendanceGroupId, reqVO.getAttendanceGroupId())
                .eqIfPresent(AttendancePunchRecordDO::getAttendanceGroupShiftId, reqVO.getAttendanceGroupShiftId())
                .eqIfPresent(AttendancePunchRecordDO::getType, reqVO.getType())
                .eqIfPresent(AttendancePunchRecordDO::getPunchType, reqVO.getPunchType())
                .eqIfPresent(AttendancePunchRecordDO::getStatus, reqVO.getStatus())
                .eqIfPresent(AttendancePunchRecordDO::getWorkType, reqVO.getWorkType())
                .neIfPresent(AttendancePunchRecordDO::getStatus, AttendanceOnTheDayDTO.PUNCH_STATUS_UN_PUNCH)
                .eqIfPresent(AttendancePunchRecordDO::getFieldServiceFlag, reqVO.getFieldServiceFlag())
                .betweenIfPresent(AttendancePunchRecordDO::getDayTime, reqVO.getDayTime())
                .betweenIfPresent(AttendancePunchRecordDO::getPunchTime, reqVO.getPunchTime())
                .eqIfPresent(AttendancePunchRecordDO::getRemark, reqVO.getRemark())
                .eqIfPresent(AttendancePunchRecordDO::getImage, reqVO.getImage())
                .betweenIfPresent(AttendancePunchRecordDO::getShouldPunchTime, reqVO.getCreateTime())
                .orderByDesc(AttendancePunchRecordDO::getId));
    }

    /**
     * 统计
     *
     * @param userList
     * @param dateList
     * @return
     */
    List<AttendancePunchRecordDO> statistics(@Param("userList") List<Long> userList, @Param("dateList") List<String> dateList);
}
