<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.artfess.examine.dao.ExamPaperBaseDao">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.artfess.examine.model.ExamPaperBase">
        <id column="id_" property="id" />
        <result column="way_type_" property="wayType" />
        <result column="subject_id_" property="subjectId" />
        <result column="name_" property="name" />
        <result column="type_" property="type" />
        <result column="time_length_" property="timeLength" />
        <result column="total_score_" property="totalScore" />
        <result column="pass_score" property="passScore" />
        <result column="total_person_" property="totalPerson" />
        <result column="memo_" property="memo" />
        <result column="is_dele_" property="isDele" />
        <result column="create_by_" property="createBy" />
        <result column="create_org_id_" property="createOrgId" />
        <result column="create_time_" property="createTime" />
        <result column="update_by_" property="updateBy" />
        <result column="update_time_" property="updateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id_, way_type_, subject_id_, name_, type_, time_length_, total_score_, pass_score, total_person_, memo_, is_dele_, create_by_, create_org_id_, create_time_, update_by_, update_time_
    </sql>
    <select id="findByPage" resultType="com.artfess.examine.model.ExamPaperBase">
        SELECT b.*,s.status_,s.time_length_,s.plan_start_time_,s.pass_score_,s.plan_end_time_,s.train_model_,r.name_ as roomName
        FROM exam_paper_base b
        LEFT JOIN exam_paper_setting s on b.id_ = s.paper_id_
        LEFT JOIN exam_room_info r on r.id_ = s.room_id_
        <if test="ew.customSqlSegment!=null">
            ${ew.customSqlSegment}
        </if>

    </select>
    <select id="getAllUser" resultType="com.artfess.examine.vo.UserInfoVo">
        SELECT
            id_ as userId,account_ as account,fullname_ as userName
        FROM
            uc_user
        WHERE
            is_dele_ = '0'
            AND USER_TYPE_ = '2'
    </select>
    <select id="getYearPaperCount" resultType="java.lang.Long">
        SELECT
            count(b.*)
        FROM
            exam_paper_base b
        WHERE
            b.is_dele_ = '0'
            AND b.paper_type_ = '2'
            AND b.create_time_ > date_trunc( 'year', now() )
            AND date_trunc( 'year', now() ) + INTERVAL '1 year' > b.create_time_
            and b.subject_id_ = #{vo.subjectId}
            and b.end_status_ = '1'
            <if test="vo.id!=null">
                and id_ != #{vo.id}
            </if>
    </select>

</mapper>
