package com.qmth.sop.business.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qmth.sop.business.bean.dto.DataPermissionDto;
import com.qmth.sop.business.bean.dto.SopCrmInfo;
import com.qmth.sop.business.bean.result.*;
import com.qmth.sop.business.entity.TBDing;
import com.qmth.sop.business.entity.TFFlowApprove;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 * 考勤打卡表 Mapper 接口.
 *
 * @author: shudonghui
 * @date: 2023-08-10 14:23:07
 * @version: 1.0
 * @email: shudonghui@qmth.com.cn
 * @Company: www.qmth.com.cn
 */
public interface TBDingMapper extends BaseMapper<TBDing> {

    /**
     * 查询列表
     *
     * @param iPage
     * @return
     */

    IPage<TBDingSubmitQueryResult> query(IPage<Map> iPage, @Param("serviceId") Long serviceId, @Param("status") String status, @Param("createId") Long createId, @Param("userName") String userName, @Param("supplierId") Long supplierId, @Param("custom") String custom, @Param("sopNo") String sopNo, @Param("days") Long days, @Param("dpr") DataPermissionDto dpr);

    List<TBDingSubmitQueryResult> query(@Param("serviceId") Long serviceId, @Param("status") String status, @Param("createId") Long createId, @Param("userName") String userName, @Param("supplierId") Long supplierId, @Param("custom") String custom, @Param("sopNo") String sopNo, @Param("days") Long days, @Param("dpr") DataPermissionDto dpr);

    TBDingCountResult count(@Param("serviceId") Long serviceId, @Param("createId") Long createId, @Param("userName") String userName, @Param("supplierId") Long supplierId, @Param("custom") String custom, @Param("sopNo") String sopNo, @Param("dpr") DataPermissionDto dpr);

    IPage<TBDingAttendanceResult> attendanceQuery(IPage<Map> iPage, @Param("serviceId") Long serviceId, @Param("userName") String userName, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("supplierId") Long supplierId, @Param("custom") String custom, @Param("sopNo") String sopNo, @Param("type") String type, @Param("status") String status, @Param("dpr")DataPermissionDto dpr,@Param("abnormal")Long abnormal);

    TBDingAttendanceCountResult attendanceCount(@Param("serviceId") Long serviceId, @Param("userName") String userName, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("supplierId") Long supplierId, @Param("custom") String custom, @Param("sopNo") String sopNo, @Param("dpr")DataPermissionDto dpr);

    List<TBDingAttendanceResult> attendanceQuery(@Param("serviceId") Long serviceId, @Param("userName") String userName, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("supplierId") Long supplierId, @Param("custom") String custom, @Param("sopNo") String sopNo, @Param("type") String type, @Param("status") String status,@Param("abnormal")Long abnormal);

    /**
     * 根据用户id查询打卡信息
     *
     * @param userId        用户id
     * @param serviceUnitId 服务单元id
     * @return 打卡信息
     */
    List<DingElementResult> findDingResultByUserId(@Param("userId") Long userId, @Param("serviceUnitId") Long serviceUnitId);

    /**
     * 根据sopNo查询sop的状态和日期
     *
     * @param sopNo sopNo
     * @return 状态 开始时间 更新时间
     */
    List<TFFlowApprove> findDateAndStatusBySopNo(@Param("sopNo") String sopNo);

    /**
     * 查询打卡异常提交次数
     *
     * @param userId 用户id
     * @param sopNo  sopNo
     * @return 暂用的打卡次数
     */
    int findDingExceptionApplyCount(@Param("userId") Long userId,
                                    @Param("sopNo") String sopNo);
}