<?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.xhkjedu.sstudy.mapper.question.ZQuestionUpdateMapper">

    <!--试题知识点列表-->
    <resultMap id="questionResult" type="com.xhkjedu.sstudy.vo.question.QuestionVo">
        <result property="questionid" column="questionid"></result>
        <result property="qstem" column="qstem"></result>
        <result property="qstemtxt" column="qstemtxt"></result>
        <result property="qoption" column="qoption"></result>
        <result property="qanswer" column="qanswer"></result>
        <result property="qanalyze" column="qanalyze"></result>
        <result property="score" column="score"></result>
        <result property="complexity" column="complexity"></result>
        <result property="ctype" column="ctype"></result>
        <result property="hearfile" column="hearfile"></result>
        <result property="qtypeid" column="qtypeid"></result>
        <result property="qtypename" column="qtypename"></result>
        <result property="subjectid" column="subjectid"></result>
        <result property="count" column="count"></result>
        <result property="qlevel" column="qlevel"></result>
        <result property="qstate" column="qstate"></result>
        <result property="questionpid" column="questionpid"></result>
        <result property="source" column="source"></result>
        <result property="year" column="year"></result>
        <result property="region" column="region"></result>
        <result property="schoolname" column="schoolname"></result>
        <result property="schoolid" column="schoolid"></result>
        <result property="belong" column="belong"></result>
        <result property="createtime" column="createtime"></result>

        <collection property="points" ofType="com.xhkjedu.sstudy.vo.subjectbook.PointVo" javaType="java.util.List"
                    select="listPoint" column="{questionid=questionid}">
        </collection>
        <collection property="directors" ofType="com.xhkjedu.sstudy.vo.subjectbook.DirectorVo" javaType="java.util.List">
            <result property="lsbid" column="lsbid"></result>
            <result property="directorid" column="directorid"></result>
        </collection>
    </resultMap>
    <resultMap id="pointResult" type="com.xhkjedu.sstudy.vo.subjectbook.PointVo">
        <result property="pointid" column="pointid"></result>
        <result property="pointname" column="pointname"></result>
    </resultMap>
    <select id="listPoint" resultMap="pointResult">
        select qp.pointid,p.pointname from t_question_point qp left join t_point p on qp.pointid = p.pointid
        where qp.questionid=#{questionid}
    </select>
    <select id="listQuestions" resultMap="questionResult">
        select q.questionid,q.qstem,q.qstemtxt,q.qoption,q.qanswer,q.qanalyze,q.score,q.complexity,q.ctype,q.belong
        ,q.qtypeid,q.qtypename,q.createtime,q.hearfile,q.subjectid,q.count,q.qlevel,q.qstate,q.source,q.year,q.region,q.schoolname,
        q.createid,q.schoolid ,qd.directorid,qd.lsbid
        from t_question q
        left join t_question_director qd on q.questionid=qd.questionid
        left join t_subject s on q.subjectid=s.subjectid
        where s.level=#{level} and q.belong=1 and q.qstate=1 and s.subjectid=#{subjectid} and q.ctype in (7,8,10)
    </select>

    <!--获取指定学段的ctype为1,16，17的值-->
    <select id="listSubjectQtype" resultType="com.xhkjedu.sstudy.model.subjectbook.TSubjectQuestiontype">
        select q.qtypeid,q.qtypename,q.ctype from t_subject_questiontype q
        left join t_subject s on q.subjectid=s.subjectid
        where s.level=#{level} and q.belong=1 and s.subjectid=#{subjectid} and q.ctype in (1,16,17)
    </select>

    <!--需要处理的科目的题型-->
    <select id="listSubjects" resultType="com.xhkjedu.sstudy.model.subjectbook.TSubject">
        select s.subjectid,s.subjectname,s.level from t_question q
         left join t_subject s on q.subjectid=s.subjectid
        where q.qstate=1 and q.ctype in (7,8,10) group by s.subjectid
    </select>

    <!--更改原试题状态为已删除 正式环境处理1686996000-->
    <update id="updateBatchQuestionState">
        update t_question set qstate=10,timeunix=1686996000 where questionid in
        <foreach collection="questionids" item="questionid" index="index" open="(" close=")" separator=",">
            #{questionid}
        </foreach>
    </update>

</mapper>
