package com.qmth.sop.business.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.qmth.sop.business.bean.dto.DateFormDto;
import com.qmth.sop.business.bean.params.DingSaveParam;
import com.qmth.sop.business.bean.result.*;
import com.qmth.sop.business.entity.SysUser;
import com.qmth.sop.business.entity.TBDing;
import com.qmth.sop.common.enums.DingResultEnum;
import com.qmth.sop.common.enums.InOutTypeEnum;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 考勤打卡表 服务类
 *
 * @author: shudonghui
 * @date: 2023-08-10 14:23:08
 * @version: 1.0
 * @email: shudonghui@qmth.com.cn
 * @Company: www.qmth.com.cn
 */
public interface TBDingService extends IService<TBDing> {
    // -- 考勤打卡部分

    /**
     * 根据sop查询打卡界面元素
     *
     * @param sopNo  sop编号
     * @param userId 用户id
     * @return 打卡元素
     */
    DingElementResult findDingElements(String sopNo, Long userId);

    /**
     * 考勤结果统计
     *
     * @param sopNo  sop单号
     * @param userId 用户id
     * @return 考勤结果统计
     */
    DingStatisticResult findDingStatistic(String sopNo, Long userId);

    /**
     * 保存打卡记录
     *
     * @param dingSaveParam 打卡记录保存参数
     * @param userId        当前请求用户id
     */
    void dingSave(DingSaveParam dingSaveParam, Long userId) throws IOException;


    /**
     * 查询列表
     *
     * @param iPage
     * @return
     */
    IPage<TBDingSubmitQueryResult> query(IPage<Map> iPage, Long serviceId, String status, Long createId, String userName, Long supplierId, String custom, String sopNo, Long days);

    List<TBDingSubmitQueryResult> query(SysUser requestUser, Long serviceId, String status, Long createId, String userName, Long supplierId, String custom, String sopNo, Long days);

    TBDingCountResult count(Long serviceId, Long createId, String userName, Long supplierId, String custom, String sopNo);

    IPage<TBDingAttendanceResult> attendanceQuery(IPage<Map> iPage, Long serviceId, String userName, Long startTime, Long endTime, Long supplierId, String custom, String sopNo, InOutTypeEnum type, DingResultEnum status, Long abnormal);

    TBDingAttendanceCountResult attendanceCount(Long serviceId, String userName, Long startTime, Long endTime, Long supplierId, String custom, String sopNo);

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

    /**
     * 根据sop单号构建打卡日期表单
     *
     * @param sopNo sop单号
     * @return 应签到日期
     */
    DateFormDto buildSignDateFormBySop(String sopNo);

    /**
     * 查询考勤组规则
     *
     * @param userId        用户id
     * @param serviceUnitId 服务单元id
     * @return 规则
     */
    DingElementResult findDingRule(Long userId, Long serviceUnitId);

    /**
     * 查询剩余补卡天数
     *
     * @param userId 用户id
     * @param sopNo  流水号
     * @return 剩余补卡天数
     */
    int findRemainCount(Long userId, String sopNo);

    /**
     * 每天晚上自动为没有打卡（签到签退都没打）的人生成打卡记录
     *
     * @param signYear 签到年
     * @param signDay  签到月日
     */
    void autoAddDingRecord(String signYear, String signDay);
}