package cn.iocoder.yudao.module.system.dal.mysql.worklog;

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.worklog.dto.statistics.NeedWriteHistoryDTO;
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.statistics.LogStatisticsDetailsVO;
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.statistics.LogStatisticsModelVO;
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.statistics.LogStatisticsPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.dal.dataobject.worklog.LogStatisticsDO;
import cn.iocoder.yudao.module.system.service.worklog.dto.LogUseVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 工作日志统计 Mapper
 *
 * @author 艾楷
 */
@Mapper
public interface LogStatisticsMapper extends BaseMapperX<LogStatisticsDO> {

    default PageResult<LogStatisticsDO> selectPage(LogStatisticsPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<LogStatisticsDO>()
                .eqIfPresent(LogStatisticsDO::getFormId, reqVO.getFormId())
                .eqIfPresent(LogStatisticsDO::getRuleId, reqVO.getRuleId())
                .eqIfPresent(LogStatisticsDO::getUserId, reqVO.getUserId())
                .eqIfPresent(LogStatisticsDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(LogStatisticsDO::getLogInstanceExtId, reqVO.getLogInstanceExtId())
                .eqIfPresent(LogStatisticsDO::getType, reqVO.getType())
                .eqIfPresent(LogStatisticsDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(LogStatisticsDO::getTime, reqVO.getTime())
                .betweenIfPresent(LogStatisticsDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(LogStatisticsDO::getId));
    }

    /**
     * 获取为提交用户列表
     *
     * @param formId
     * @param thisTime
     * @return
     */
    List<AdminUserDO> getUnSubmittedUser(@Param("formId") Long formId, @Param("thisTime") String thisTime);

    /**
     * 获取统计
     *
     * @param dateList
     * @param formId
     * @return
     */
    List<LogStatisticsDetailsVO> getStatistics(@Param("formId") Long formId, @Param("userId") Long userId, @Param("deptId") Long deptId, @Param("dateList") List<String> dateList);

    /**
     * 获取当天/本周的统计
     *
     * @param formId
     * @param dateList
     * @return
     */
    List<LogStatisticsDetailsVO> getCurrentStatistics(@Param("formId") Long formId, @Param("dateList") List<String> dateList);

    /**
     * 获取我的当天/本周的统计
     *
     * @param userId
     * @param formId
     * @param dateList
     * @return
     */
    List<LogUseVO> getMyCurrentStatistics(@Param("userId") Long userId, @Param("deptId") Long deptId, @Param("formId") Long formId, @Param("dateList") List<String> dateList);

    /**
     * 获取我的日志历史记录
     *
     * @param dto
     * @param dateList
     * @return
     */
    List<LogStatisticsModelVO> getNeedWriteHistory(@Param("dto") NeedWriteHistoryDTO dto, @Param("dateList") List<String> dateList);
}