package com.keao.edu.user.dao;

import com.keao.edu.common.dal.BaseDAO;
import com.keao.edu.user.dto.ExamOrganStatisticsDto;
import com.keao.edu.user.dto.ExamOrganizationRelationExtraDto;
import com.keao.edu.user.entity.ExamOrganizationRelation;
import com.keao.edu.user.entity.Organization;
import com.keao.edu.user.enums.YesOrNoEnum;
import org.apache.ibatis.annotations.Param;

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

public interface ExamOrganizationRelationDao extends BaseDAO<Long, ExamOrganizationRelation> {

    List<ExamOrganizationRelationExtraDto> queryExamOrgans(Map<String, Object> params);
    int countExamOrgans(Map<String, Object> params);

    List<ExamOrganizationRelationExtraDto> getExamChildOrgans(@Param("examId") Long examId, @Param("organIds") List<Integer> organIds);

    /**
     * @param examOrganizationRelations:
     * @return int
     * @describe 批量插入考级项目与合作单位关联
     * @author Joburgess
     * @date 2020.06.18
     */
    int batchInsert(@Param("examOrganizationRelations") List<ExamOrganizationRelation> examOrganizationRelations);

    /**
     * @param examOrganizationRelations:
     * @return int
     * @describe 批量更新
     * @author Joburgess
     * @date 2020.06.29
     */
    int batchUpdate(@Param("examOrganizationRelations") List<ExamOrganizationRelation> examOrganizationRelations);

    /**
     * @describe 更新考级项目下指定合作单位的可排考状态
     * @author Joburgess
     * @date 2020.07.17
     * @param examId:
     * @param organIds:
     * @return int
     */
    int updateOrganAllowArrangeExamStatus(@Param("examId") Long examId,
                                          @Param("isAllowArrangeExam") Integer isAllowArrangeExam,
                                          @Param("organIds") List<Integer> organIds);

    /**
     * @param examId:      考级项目编号
     * @param organIds:    合作单位编号列表
     * @param sendUrlFlag: 链接发送状态
     * @return int
     * @describe 批量更新合作单位的链接发送状态
     * @author Joburgess
     * @date 2020.06.18
     */
    int batchUpdateSendUrlFlag(@Param("examId") Integer examId,
                               @Param("organIds") List<Integer> organIds,
                               @Param("sendUrlFlag") YesOrNoEnum sendUrlFlag);

    /**
     * @param examId:
     * @return com.keao.edu.user.entity.ExamOrganizationRelation
     * @describe 获取考级项目关联的合作单位
     * @author Joburgess
     * @date 2020.06.18
     */
    List<ExamOrganizationRelation> getWithExam(@Param("examId") Integer examId);

    List<ExamOrganizationRelation> getOrganInfoWithExam(@Param("examId") Integer examId);

    List<ExamOrganizationRelation> getWithExams(@Param("examIds") List<Long> examIds);

    List<ExamOrganizationRelation> getWithExamsAndOrgans(@Param("examIds") List<Long> examIds,
                                                         @Param("organIds") List<Integer> organs);

    /**
     * @param examId:
     * @return java.util.Set<java.lang.Integer>
     * @describe 获取考级项目关联的合作单位编号
     * @author Joburgess
     * @date 2020.06.18
     */
    Set<Integer> getOrganIdsWithExam(@Param("examId") Integer examId);

    /**
     * @param examId:
     * @param organIds:
     * @return java.util.List<com.keao.edu.user.entity.ExamOrganizationRelation>
     * @describe 统计指定考级项目与指定分布下的报名人数与累计收款
     * @author Joburgess
     * @date 2020.06.28
     */
    List<ExamOrganizationRelation> countExamOrganStudentAndPayment(@Param("examId") Integer examId,
                                                                   @Param("organIds") List<Integer> organIds);

    /**
     * 是否有考试项目
     *
     * @param organId
     * @return
     */
    Integer findByOrganId(@Param("organId") Integer organId);

    /**
     * @param params:
     * @return java.util.List<com.keao.edu.user.entity.Organization>
     * @describe 获取未关联到考级项目的合作单位
     * @author Joburgess
     * @date 2020.07.03
     */
    List<Organization> queryUnRelatedOrgans(Map<String, Object> params);

    int countUnRelatedOrgans(Map<String, Object> params);

    /**
     * 获取考级项目关联合作单位信息
     *
     * @param examId
     * @param OrganId
     * @return
     */
    ExamOrganStatisticsDto getExamOrganizationRelation(@Param("examId") Long examId, @Param("OrganId") Integer OrganId);

    int deleteExamOrgans(@Param("examId") Long examId, @Param("organIds") List<Integer> organIds);

    /**
     * 获取考级项目关联合作单位信息
     * @param examId
     * @param organIds
     * @return
     */
    List<ExamOrganizationRelation> getExamOrganizationRelations(@Param("examId") Long examId, @Param("organIds") List<Integer> organIds);

}
