package jnpf.cultivate.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jnpf.model.cultivate.dto.position.FtbCultivatePersonStatisticesDTO;
import jnpf.model.cultivate.dto.position.FtbCultivatePositionOrgStatisticesDTO;
import jnpf.model.cultivate.dto.position.FtbCultivatePositionPersonStatisticesDTO;
import jnpf.model.cultivate.v2.position.vo.CultivatePositionCourseVo;
import jnpf.model.cultivate.v2.position.vo.PersonForLeaderVo;
import jnpf.model.cultivate.v2.position.vo.V2StudyCountVo;
import jnpf.model.cultivate.v2.statistics.V2UserCourseStudyVo;
import jnpf.model.cultivate.vo.course.web.UserCourseStudyVo;
import jnpf.model.cultivate.vo.position.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface FtbCultivatePositionStatisticesMapper {

    /**
     * 个人维度统计
     */
    Page<FtbCultivatePositionPersonStatisticesVO> personListStatistics(@Param("page") Page<FtbCultivatePositionPersonStatisticesVO> page, @Param("params") FtbCultivatePositionPersonStatisticesDTO params);

    /**
     * 下属参与学习人数
     */
    Integer numberOfPeopleParticipatingInTheStudy1(@Param("userIds") List<String> userIds, @Param("innerCourseIds") List<String> innerCourseIds);

    /**
     * 查询课程id
     */
    List<CultivatePositionCourseVo> queryCourseIds();

    /**
     * 下属人均学习时长
     */
    Integer averageStudyHoursPerSubordinate1(@Param("userIds") List<String> userIds, @Param("innerCourseIds") List<String> innerCourseIds);

    /**
     * 统计课程数
     *
     * @param userId 用户id
     * @param type   0学习课程数，1 课程完成数
     */
    Integer numberOfStudyCourses(@Param("userId") String userId, @Param("type") Integer type);

    /**
     * 统计课程数
     *
     * @param userIds        用户id
     * @param type           0学习课程数，1 课程完成数
     * @param innerCourseIds
     */
    List<PersonStatisticesDto> batchNumberOfStudyCourses2(@Param("userIds") List<String> userIds, @Param("type") Integer type, @Param("innerCourseIds") List<String> innerCourseIds);

    /**
     * 岗位维度统计
     */
    Page<FtbCultivatePersonStatisticesVO> positionListStatistics(@Param("page") Page<FtbCultivatePersonStatisticesVO> page,
                                                                 @Param("params") FtbCultivatePersonStatisticesDTO params);

    /**
     * 岗位学习课程总数
     */
    List<FtbCultivatePersonStatisticesVO.TotalNumberOfOnTheJobLearningCourses> totalNumberOfOnTheJobLearningCourses(@Param("postLearnIds") List<String> postLearnIds);

    /**
     * 已学习课程数
     */
    List<FtbCultivatePersonStatisticesVO.NumberOfCoursesTaken> numberOfCoursesTaken(@Param("postLearnIds") List<String> postLearnIds);

    /**
     * 已学习课程数
     */
    Long numberOfCoursesTakenStoreIndex(@Param("postLearnIds") List<String> postLearnIds, @Param("userId") String userId);

    /**
     * 岗位学习人数
     */
    List<String> numberOfPeopleStudyingOnTheJob(@Param("userIds") List<String> userIds);

    /**
     * 学习时长
     */
    Long studyDuration(@Param("userIds") List<String> userIds);

    /**
     * 参与学习人数
     */
    List<String> numberOfPeopleParticipatingInTheStudyOrg(@Param("params") FtbCultivatePositionOrgStatisticesDTO params, @Param("userIds") List<String> userIds, @Param("positionIds") String positionIds);

    /**
     * 学习总时长
     */
    Integer totalStudyTime(@Param("params") FtbCultivatePositionOrgStatisticesDTO statisticDTO, @Param("userIds") List<String> userIds, @Param("postionIds") String postionIds);

    /**
     * 已学课程数
     */
    Integer numberOfCoursesTakens(@Param("params") FtbCultivatePositionOrgStatisticesDTO statisticDTO, @Param("userIds") List<String> userIds, @Param("postionIds") String postionIds);

    /**
     * 课程总数
     */
    Integer totalNumberOfCourses();

    /**
     * 组织课程信息
     */
    List<OrganizeCourseDetails> organizeCourseDetails(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("postionIds") String postionIds,
                                                      @Param("userIds") List<String> userIds);

    /**
     * 已参与学习人数
     */
    List<CourseStudyCountVO> numberOfPeopleParticipatingInTheFinishStudy(@Param("courseIds") List<String> courseIds, @Param("postionIds") String postionIds, @Param("states") List<Integer> states, @Param("userIds") Set<String> userIds);

    /**
     * 个人维度-课程详情
     */
    List<PersonalDimensionCourseDetails> personalDimensionCourseDetails(@Param("startDate") String startDate, @Param("endDate") String endDate,
                                                                        @Param("userId") String userId);

    /**
     * 课程学习进度
     */
    Integer courseLearningProgress(@Param("courseId") String courseId, @Param("userId") String userId, @Param("type") Integer type);

    /**
     * 岗位学习总数
     */
    Integer jobLearningProgress(@Param("postId") String postId, @Param("userId") String userId, @Param("type") Integer type);

    /**
     * 学习地图课程总数
     */
    Integer totalNumberOfLearningMapCourses1(@Param("postIds") List<String> postIds, @Param("innerCourseIds") List<String> innerCourseIds);

    /**
     * 员工姓名和员工ID
     */
    List<Map<String, String>> fuzzySearchForRosterKeywords(@Param("keyWords") String keyWords);

    /**
     * 岗位学习人数
     */
    Integer numberOfPeopleWhoCompletedTheStudy(@Param("userIds") List<String> userIds);

    /**
     * 获取岗位名称
     */
    List<String> getPostIds(@Param("postIds") List<String> postIds);

    /**
     * 根据查询岗位查询对应的岗位考试合格分
     */
    @Select("SELECT ex.F_PassMark FROM  ftb_cultivate_position_exam as po INNER JOIN ftb_cultivate_exam as ex ON po.F_ExamId = ex.F_Id where po.F_PostRankId =#{positionId} AND po.F_EnabledMark = 0 ")
    BigDecimal qualifyingPointsForJobRelatedExaminations(@Param("positionId") String positionId);

    /**
     * 根据查询岗位查询对应的岗位实操合格分
     */
    @Select("SELECT fy.F_PassScore FROM   ftb_cultivate_position_exam_identify as po INNER JOIN ftb_cultivate_identify_table as fy ON po.F_IdentifyId = fy.F_Id where po.F_PostRankId =#{positionId} AND po.F_EnabledMark = 0")
    BigDecimal qualifyingPointsForJobRelatedAppraisal(@Param("positionId") String positionId);

    /**
     * 查询岗位下课程完成情况
     */
    List<PersonStatisticesDto> queryCourseCompletionStatusOfThePosition(@Param("positionId") String positionId,
                                                                        @Param("idsByGradesId") List<String> idsByGradesId,
                                                                        @Param("type") Integer type);

    /**
     * 岗位考试合格率
     */
    List<FtbCultivatePersonStatisticesVO.PassedTheExam> checkJobQualificationRate(@Param("postIds") List<String> postIds);

    /**
     * 根据岗位查询课程总数
     *
     * @param positionIds 岗位id集合
     * @return
     */
    Long courseTotleNum(@Param("positionIds") List<String> positionIds);

    /**
     * 查询岗位下已学课程列表
     *
     * @param postLearnIds 岗位学习id
     * @param userId       用户id
     * @return
     */
    List<String> queryComplateCourseLists(@Param("postLearnIds") List<String> postLearnIds, @Param("userId") String userId);

    /**
     * 查询岗位下已学和学习中的课程列表
     *
     * @param postLearnIds 岗位学习id
     * @param userId       用户id
     * @return
     */
    List<String> queryComplateAndStudyingCourseLists(@Param("postLearnIds") List<String> postLearnIds, @Param("userId") String userId);


    /**
     * 查询岗位下所有需要学习的课程
     *
     * @param positionIds 岗位id
     * @return
     */
    List<String> queryAllNeedStudyCourseForPost(@Param("positionIds") List<String> positionIds);

    List<V2UserCourseStudyVo> batchQueryAllCourseStudyV2(@Param("userIds") List<String> userIds);

    List<PersonForLeaderVo> queryAllNextUser(@Param("leaderUserIds") List<String> leaderUserIds);

    V2StudyCountVo numberOfPeopleParticipatingInTheStudy(@Param("userIds") List<String> userIds, @Param("innerCourseIds") List<String> innerCourseIds);

    List<UserCourseStudyVo> batchQueryAllCourseStudy(@Param("userIds") List<String> userIds);
}
