<?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.miaxis.question.mapper.QuestionInfoMapper">

    <resultMap type="QuestionInfo" id="QuestionInfoResult">
        <result property="id"    column="id"    />
        <result property="number"    column="number"    />
        <result property="answer"    column="answer"    />
        <result property="answerkeyword"    column="answerkeyword"    />
        <result property="explainGif"    column="explain_gif"    />
        <result property="explainJq"    column="explain_jq"    />
        <result property="explainJs"    column="explain_js"    />
        <result property="explainMp3"    column="explain_mp3"    />
        <result property="image"    column="image"    />
        <result property="imageYdt"    column="image_ydt"    />
        <result property="issue"    column="issue"    />
        <result property="opts"    column="opts"    />
        <result property="skillkeyword"    column="skillkeyword"    />
        <result property="titlekeyword"    column="titlekeyword"    />
        <result property="issuemp3"    column="issuemp3"    />
        <result property="answermp3"    column="answermp3"    />
        <result property="explainjsmp3"    column="explainjsmp3"    />
        <result property="liceCar"    column="lice_car"    />
        <result property="liceBus"    column="lice_bus"    />
        <result property="liceTruck"    column="lice_truck"    />
        <result property="liceMoto"    column="lice_moto"    />
        <result property="sequeIssue"    column="seque_issue"    />
        <result property="classIssue"    column="class_issue"    />
        <result property="placeIssue"    column="place_issue"    />
        <result property="excellIssue"    column="excell_issue"    />
        <result property="sequeIssueName"    column="seque_issue_name"    />
        <result property="placeIssueName"    column="place_issue_name"    />
        <result property="excellIssueName"    column="excell_issue_name"    />
        <result property="classIssueName"    column="class_issue_name"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="subject"    column="subject"    />
        <result property="classSort"    column="class_sort"    />
        <result property="excellSort"    column="excell_sort"    />
        <result property="sequeSort"    column="seque_sort"    />
        <result property="placeSort"    column="place_sort"    />
        <result property="sequeSort"    column="seque_sort"    />
        <result property="placeSort"    column="place_sort"    />
        <result property="chapterId"    column="chapter_id"    />
        <result property="diffDegree"    column="diff_degree"    />
        <result property="isNew"    column="is_new"    />


    </resultMap>

    <sql id="selectQuestionInfoVo">
        select * from question_info
    </sql>

    <select id="selectQuestionInfoList" parameterType="com.miaxis.question.dto.QuestionInfoDTO" resultMap="QuestionInfoResult">
        <include refid="selectQuestionInfoVo"/>
        <where>
            <if test="number != null "> and number = #{number}</if>
            <if test="answer != null  and answer != ''"> and answer = #{answer}</if>
            <if test="answerkeyword != null  and answerkeyword != ''"> and answerkeyword = #{answerkeyword}</if>
            <if test="explainGif != null  and explainGif != ''"> and explain_gif = #{explainGif}</if>
            <if test="explainJq != null  and explainJq != ''"> and explain_jq = #{explainJq}</if>
            <if test="explainJs != null  and explainJs != ''"> and explain_js = #{explainJs}</if>
            <if test="explainMp3 != null  and explainMp3 != ''"> and explain_mp3 = #{explainMp3}</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="imageYdt != null  and imageYdt != ''"> and image_ydt = #{imageYdt}</if>
            <if test="issue != null  and issue != ''"> and issue = #{issue}</if>
            <if test="opts != null  and opts != ''"> and opts = #{opts}</if>
            <if test="skillkeyword != null  and skillkeyword != ''"> and skillkeyword = #{skillkeyword}</if>
            <if test="titlekeyword != null  and titlekeyword != ''"> and titlekeyword = #{titlekeyword}</if>
            <if test="issuemp3 != null  and issuemp3 != ''"> and issuemp3 = #{issuemp3}</if>
            <if test="answermp3 != null  and answermp3 != ''"> and answermp3 = #{answermp3}</if>
            <if test="explainjsmp3 != null  and explainjsmp3 != ''"> and explainjsmp3 = #{explainjsmp3}</if>
            <if test="liceCar != null  and liceCar != ''"> and lice_car = #{liceCar}</if>
            <if test="liceBus != null  and liceBus != ''"> and lice_bus = #{liceBus}</if>
            <if test="liceTruck != null  and liceTruck != ''"> and lice_truck = #{liceTruck}</if>
            <if test="liceMoto != null  and liceMoto != ''"> and lice_moto = #{liceMoto}</if>
            <if test="sequeIssue != null  and sequeIssue != ''"> and seque_issue = #{sequeIssue}</if>
            <if test="classIssue != null  and classIssue != ''"> and class_issue = #{classIssue}</if>
            <if test="placeIssue != null  and placeIssue != ''"> and place_issue = #{placeIssue}</if>
            <if test="excellIssue != null  and excellIssue != ''"> and excell_issue = #{excellIssue}</if>
            <if test="sequeIssueName != null  and sequeIssueName != ''"> and seque_issue_name like concat('%', #{sequeIssueName}, '%')</if>
            <if test="placeIssueName != null  and placeIssueName != ''"> and place_issue_name like concat('%', #{placeIssueName}, '%')</if>
            <if test="excellIssueName != null  and excellIssueName != ''"> and excell_issue_name like concat('%', #{excellIssueName}, '%')</if>
            <if test="questionType != null "> and question_type = #{questionType}</if>
            <if test="subject != null  and subject != ''"> and subject = #{subject}</if>
            <if test="chapterId != null  and chapterId != ''"> and chapter_id = #{chapterId}</if>
            <if test="diffDegree != null  and diffDegree != ''"> and diff_degree = #{diffDegree}</if>
            <if test="isNew != null  and isNew != ''"> and is_new = #{isNew}</if>
        </where>

   <!--     <if test="isRand!=null and isRand!=''"> order by rand() </if>-->
        <if test="sort!=null and sort!='' "> order by IFNULL(${sortName},10000) </if>
    </select>


    <select id="selectNormalQuestionInfoList" parameterType="com.miaxis.question.dto.QuestionInfoDTO" resultMap="QuestionInfoResult">
        <include refid="selectQuestionInfoVo"/>
        <where>
            <if test="number != null "> and number = #{number}</if>
            <if test="answer != null  and answer != ''"> and answer = #{answer}</if>
            <if test="answerkeyword != null  and answerkeyword != ''"> and answerkeyword = #{answerkeyword}</if>
            <if test="explainGif != null  and explainGif != ''"> and explain_gif = #{explainGif}</if>
            <if test="explainJq != null  and explainJq != ''"> and explain_jq = #{explainJq}</if>
            <if test="explainJs != null  and explainJs != ''"> and explain_js = #{explainJs}</if>
            <if test="explainMp3 != null  and explainMp3 != ''"> and explain_mp3 = #{explainMp3}</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="imageYdt != null  and imageYdt != ''"> and image_ydt = #{imageYdt}</if>
            <if test="issue != null  and issue != ''"> and issue = #{issue}</if>
            <if test="opts != null  and opts != ''"> and opts = #{opts}</if>
            <if test="skillkeyword != null  and skillkeyword != ''"> and skillkeyword = #{skillkeyword}</if>
            <if test="titlekeyword != null  and titlekeyword != ''"> and titlekeyword = #{titlekeyword}</if>
            <if test="issuemp3 != null  and issuemp3 != ''"> and issuemp3 = #{issuemp3}</if>
            <if test="answermp3 != null  and answermp3 != ''"> and answermp3 = #{answermp3}</if>
            <if test="explainjsmp3 != null  and explainjsmp3 != ''"> and explainjsmp3 = #{explainjsmp3}</if>
            <if test="liceCar != null  and liceCar != ''"> and lice_car = #{liceCar}</if>
            <if test="liceBus != null  and liceBus != ''"> and lice_bus = #{liceBus}</if>
            <if test="liceTruck != null  and liceTruck != ''"> and lice_truck = #{liceTruck}</if>
            <if test="liceMoto != null  and liceMoto != ''"> and lice_moto = #{liceMoto}</if>
            <if test="sequeIssue != null  and sequeIssue != ''"> and seque_issue = #{sequeIssue}</if>
            <if test="classIssue != null  and classIssue != ''"> and class_issue = #{classIssue}</if>
            <if test="placeIssue != null  and placeIssue != ''"> and place_issue = #{placeIssue}</if>
            <if test="excellIssue != null  and excellIssue != ''"> and excell_issue = #{excellIssue}</if>
            <if test="sequeIssueName != null  and sequeIssueName != ''"> and seque_issue_name like concat('%', #{sequeIssueName}, '%')</if>
            <if test="placeIssueName != null  and placeIssueName != ''"> and place_issue_name like concat('%', #{placeIssueName}, '%')</if>
            <if test="excellIssueName != null  and excellIssueName != ''"> and excell_issue_name like concat('%', #{excellIssueName}, '%')</if>
            <if test="classIssueName != null  and classIssueName != ''"> and class_issue_name like concat('%', #{classIssueName}, '%')</if>
            <if test="questionType != null "> and question_type = #{questionType}</if>
            <if test="chapterId != null  and chapterId != ''"> and chapter_id = #{chapterId}</if>
            <if test="diffDegree != null  and diffDegree != ''"> and diff_degree = #{diffDegree}</if>
            <if test="isNew != null  and isNew != ''"> and is_new = #{isNew}</if>

        </where>
        limit 0,50
    </select>




    <select id="selectQuestionInfoListIds" parameterType="Long" resultMap="QuestionInfoResult">
        <include refid="selectQuestionInfoVo"/>
        <where>
            and id in
             <foreach collection="array" item="id" index="index" open="(" close=")" separator=",">
                 #{id}
             </foreach>
        </where>
        order by FIELD(id,
        <foreach collection="array" item="id" index="index" open="" close="" separator=",">
            #{id}
        </foreach>
        )
    </select>

    <select id="selectJxQuestionInfo"  resultType="com.miaxis.question.vo.QuestionInfoJxVO">
        SELECT
            DISTINCT case WHEN excell_issue_name is null then '地方专题' else excell_issue_name end as "excell_issue_name",
            excell_issue
        FROM question_info
        <where>
            <if test="excellIssueName != null  and excellIssueName != ''"> and excell_issue_name like concat('%',#{excellIssueName},'%')</if>
            <if test="subject != null  and subject != ''"> and subject = #{subject}</if>
            <if test="liceCar != null  and liceCar != ''"> and lice_car = #{liceCar} </if>
            <if test="liceBus != null  and liceBus != ''"> and lice_bus = #{liceBus}</if>
            <if test="liceTruck != null  and liceTruck != ''"> and lice_truck = #{liceTruck}</if>
            <if test="liceMoto != null  and liceMoto != ''"> and lice_moto = #{liceMoto}</if>
        </where>
        ORDER BY
            excell_issue + 0 ASC
    </select>


    <select id="selectDfQuestionInfo"  resultType="com.miaxis.question.vo.QuestionInfoDfVO">
        SELECT
            DISTINCT
            case WHEN place_issue_name is null then '地方专题' else place_issue_name end as "place_issue_name",
            place_issue
        FROM question_info
        <where>
            <if test="subject != null  and subject != ''"> and subject = #{subject}</if>
            <if test="liceCar != null  and liceCar != ''"> and lice_car = #{liceCar} </if>
            <if test="liceBus != null  and liceBus != ''"> and lice_bus = #{liceBus}</if>
            <if test="liceTruck != null  and liceTruck != ''"> and lice_truck = #{liceTruck}</if>
            <if test="liceMoto != null  and liceMoto != ''"> and lice_moto = #{liceMoto}</if>
        </where>
        ORDER BY
            place_issue + 0 ASC
    </select>


    <select id="selectFlQuestionInfo"  resultType="com.miaxis.question.vo.QuestionInfoFlVO">
        SELECT
        DISTINCT
        case WHEN class_issue_name is null then '地方专题' else class_issue_name end as "class_issue_name",
        class_issue
        FROM question_info
        <where>
            <if test="subject != null  and subject != ''"> and subject = #{subject}</if>
            <if test="liceCar != null  and liceCar != ''"> and lice_car = #{liceCar} </if>
            <if test="liceBus != null  and liceBus != ''"> and lice_bus = #{liceBus}</if>
            <if test="liceTruck != null  and liceTruck != ''"> and lice_truck = #{liceTruck}</if>
            <if test="liceMoto != null  and liceMoto != ''"> and lice_moto = #{liceMoto}</if>
        </where>
        ORDER BY
        class_issue + 0 ASC
    </select>


    <select id="selectSxQuestionInfo"  resultType="com.miaxis.question.vo.QuestionInfoSxVO">
        SELECT
        DISTINCT
        case WHEN seque_issue_name is null then '地方专题' else seque_issue_name end as "seque_issue_name",
        seque_issue
        FROM question_info
        <where>
            <if test="subject != null  and subject != ''"> and subject = #{subject}</if>
            <if test="liceCar != null  and liceCar != ''"> and lice_car = #{liceCar} </if>
            <if test="liceBus != null  and liceBus != ''"> and lice_bus = #{liceBus}</if>
            <if test="liceTruck != null  and liceTruck != ''"> and lice_truck = #{liceTruck}</if>
            <if test="liceMoto != null  and liceMoto != ''"> and lice_moto = #{liceMoto}</if>
        </where>
        ORDER BY
        seque_issue + 0 ASC
    </select>

    <select id="selectIssueType1"  resultType="com.miaxis.question.vo.QuestionInfoExcelTypeVo">
        		SELECT
                    DISTINCT case WHEN class_issue_name is null then '地方专题' else class_issue_name end as title,
                     class_issue  as type_id
                    FROM
                     question_info
                    WHERE
                    subject = #{subject}
                     AND lice_car = 1 and
                     class_issue_name is not null
                    ORDER BY
                     class_issue + 0 ASC
    </select>


    <select id="selecQuestionInfoExcel1"  resultType="com.miaxis.question.vo.QuestionInfoExcelVo">
        SELECT id,
             number,
             issue,
             image,
             excell_issue_name,
             class_issue_name,
              place_issue_name,
              seque_issue_name,
             question_type  FROM question_info WHERE class_issue = #{typeId} and subject_1 =1 and lice_car = 1
    </select>

    <select id="selectIssueType2"  resultType="com.miaxis.question.vo.QuestionInfoExcelTypeVo">
        		SELECT
                    DISTINCT case WHEN excell_issue_name is null then '地方专题' else excell_issue_name end as title,
                     excell_issue as type_id
                    FROM
                     question_info
                    WHERE
                    subject = #{subject}
                     AND lice_car = 1 and
                     excell_issue_name is not null
                    ORDER BY
                     excell_issue + 0 ASC
    </select>


    <select id="selecQuestionInfoExcel2"  resultType="com.miaxis.question.vo.QuestionInfoExcelVo">
        SELECT id,
             number,
             issue,
             image,
             excell_issue_name,
             class_issue_name,
              place_issue_name,
               seque_issue_name,
             question_type  FROM question_info WHERE excell_issue = #{typeId} and subject_1 =1 and lice_car = 1
    </select>


    <select id="selectIssueType3"  resultType="com.miaxis.question.vo.QuestionInfoExcelTypeVo">
        		SELECT
                    DISTINCT case WHEN place_issue_name is null then '地方专题' else place_issue_name end as title,
                     place_issue as type_id
                    FROM
                     question_info
                    WHERE
                     subject = #{subject}
                     AND lice_car = 1 and
                     place_issue_name is not null
                    ORDER BY
                     place_issue + 0 ASC
    </select>


    <select id="selecQuestionInfoExcel3"  resultType="com.miaxis.question.vo.QuestionInfoExcelVo">
        SELECT id,
             number,
             issue,
             image,
             excell_issue_name,
             class_issue_name,
              place_issue_name,
              seque_issue_name,
             question_type  FROM question_info WHERE  place_issue  = #{typeId} and subject_1 =1 and lice_car = 1
    </select>


    <select id="selectIssueType4"  resultType="com.miaxis.question.vo.QuestionInfoExcelTypeVo">
        		SELECT
                    DISTINCT case WHEN seque_issue_name is null then '地方专题' else seque_issue_name end as title,
                     seque_issue as type_id
                    FROM
                     question_info
                    WHERE
                     subject = #{subject}
                     AND lice_car = 1 and
                     seque_issue_name is not null
                    ORDER BY
                     seque_issue + 0 ASC
    </select>


    <select id="selecQuestionInfoExcel4"  resultType="com.miaxis.question.vo.QuestionInfoExcelVo">
        SELECT id,
             id_ydt,
             number,
             issue,
             image,
             excell_issue_name,
             class_issue_name,
              place_issue_name,
              seque_issue_name,
             question_type  FROM question_info WHERE  seque_issue  = #{typeId} and subject_1 =1 and lice_car = 1
    </select>


    <select id="selectIssueType5"  resultType="com.miaxis.question.vo.QuestionInfoExcelTypeVo">
        SELECT
            DISTINCT case WHEN seque_issue_name is null then '地方专题' else seque_issue_name end as title,
                     seque_issue as type_id
        FROM
            question_info
        WHERE
            subject = #{subject}
          AND lice_car = 1 and
            seque_issue_name is not null
        ORDER BY
            seque_issue + 0 ASC
    </select>


    <select id="selecQuestionInfoExcel5"  resultType="com.miaxis.question.vo.QuestionInfoExcelVo">
        SELECT id,
               id_ydt,
            number,
            issue,
            image,
            excell_issue_name,
            class_issue_name,
            place_issue_name,
            seque_issue_name,
            question_type  FROM question_info WHERE  seque_issue  = #{typeId} and subject_1 =1 and lice_car = 1
    </select>


    <select id="selectQuestionInfoSortList"  resultType="com.miaxis.question.vo.QuestionInfoExcelVo">
        SELECT id,
             id_ydt,
             number,
             issue,
             image,
             excell_issue_name,
             class_issue_name,
              place_issue_name,
              seque_issue_name,
              ${sortName} as sort,
             question_type  FROM question_info WHERE  ${issueTypeParmName}  = #{issueValue} and subject =#{subject} and lice_car = 1
             <if test="issue != null  and issue != ''"> and issue like concat('%', #{issue}, '%')</if>
             order by  IFNULL(${sortName},100000)
    </select>

    <select id="updateSortById"  >
        update question_info set ${sortName} = #{sort} WHERE  id = #{id}
    </select>


    <select id="selectTestQuestionInfoList"   resultMap="QuestionInfoResult">
        select * from question_info
        <where>
            <if test="subject != null"> and subject = #{subject}</if>
            <if test="questionType != null"> and question_type = #{questionType}</if>
            <if test="liceCar != null  and liceCar != ''"> and lice_car = #{liceCar} </if>
            <if test="liceBus != null  and liceBus != ''"> and lice_bus = #{liceBus}</if>
            <if test="liceTruck != null  and liceTruck != ''"> and lice_truck = #{liceTruck}</if>
            <if test="liceMoto != null  and liceMoto != ''"> and lice_moto = #{liceMoto}</if>
            <if test="chapterId != null "> and chapter_id = #{chapterId}</if>
            <if test="diffDegree != null "> and diff_degree in
                <foreach item="degree" index="index" collection="diffDegree"
                         open="(" separator="," close=")">
                    #{degree}
                </foreach>
            </if>
        </where>
        ORDER BY rand() limit 0,${num}
    </select>
    <select id="selectQuestionInfoCount"   resultType="int">
        select count(1) from question_info
        <where>
            <if test="subject != null"> and subject = #{subject}</if>
            <if test="questionType != null"> and question_type = #{questionType}</if>
            <if test="liceCar != null  and liceCar != ''"> and lice_car = #{liceCar} </if>
            <if test="liceBus != null  and liceBus != ''"> and lice_bus = #{liceBus}</if>
            <if test="liceTruck != null  and liceTruck != ''"> and lice_truck = #{liceTruck}</if>
            <if test="liceMoto != null  and liceMoto != ''"> and lice_moto = #{liceMoto}</if>
            <if test="chapterId != null "> and chapter_id = #{chapterId}</if>
            <if test="diffDegree != null "> and diff_degree in
                <foreach item="degree" index="index" collection="diffDegree"
                         open="(" separator="," close=")">
                    #{degree}
                </foreach>
            </if>
        </where>
    </select>




    <select id="selectFreeQuestionInfoList"   resultMap="QuestionInfoResult">
        select q1.* from question_info q1 join question_free q2 on q1.id = q2.id
        <where>
            <if test="subject != null"> and q2.subject = #{subject}</if>
        </where>
         order by q2.free_sort
    </select>


    <select id="selectQuestionInfoListByYdtIds" parameterType="Long" resultMap="QuestionInfoResult">
        <include refid="selectQuestionInfoVo"/>
        <where>
            and id_ydt in
            <foreach collection="array" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>

        </where>
    </select>


    <select id="selectMiQuestionInfoList" parameterType="QuestionInfoMiDTO" resultMap="QuestionInfoResult">
        select * from
            (select * from question_info t2 join
                           (SELECT substring_index(group_concat(t.id order by t.id desc ),',',1) maxid FROM question_info t GROUP BY t.id_ydt) t1 on t2.id = t1.maxid) t3
                JOIN t_app_question_category tt ON t3.id_ydt = tt.question_id where tt.gs = #{gs} AND tt.kemu = #{kemu} and tt.category = #{category}

    </select>

    <select id="selectTestK14QuestionInfoList" resultType="com.miaxis.question.domain.QuestionInfo">
        ${sql}
    </select>



</mapper>
