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

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.smartfactory.controller.admin.attendance.vo.StaffAttendanceRecordReqVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.attendance.vo.StaffAttendanceRecordSaveReqVO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.attendance.StaffAttendanceRecordDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.util.List;
import java.util.Objects;

/**
 * 厂区员工考勤记录 Mapper
 *
 * @author 符溶馨
 */
@Mapper
public interface StaffAttendanceRecordMapper extends BaseMapperX<StaffAttendanceRecordDO> {

    void deleteRecord(@Param("reqVO") StaffAttendanceRecordSaveReqVO staffAttendanceRecordSaveReqVO);

    default List<StaffAttendanceRecordDO> selectRecordList(StaffAttendanceRecordReqVO reqVO, LocalDate[] date) {

        return selectList(new LambdaQueryWrapperX<StaffAttendanceRecordDO>()
                .eqIfPresent(StaffAttendanceRecordDO::getStaffId, reqVO.getStaffId())
                .neIfPresent(StaffAttendanceRecordDO::getFactoryId, reqVO.getFactoryId())
                .betweenIfPresent(StaffAttendanceRecordDO::getPunchTime, date)
                .like(Objects.isNull(date) && Objects.nonNull(reqVO.getMonth()), StaffAttendanceRecordDO::getPunchTime, reqVO.getMonth()));
    }
}