<?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.QuestionPointMapper">
    <!--删除试题关联知识点信息-->
    <delete id="deleteByQuestionId">
        delete from t_question_point where questionid=#{questionid}
    </delete>
    <!--批量添加-->
    <insert id="batchSave" parameterType="com.xhkjedu.sstudy.model.question.TQuestionPoint">
        INSERT INTO t_question_point (qpid,questionid,pointid,createid,createtime)
        VALUES
        <foreach collection ="list" item="p" index= "index" separator =",">
            (#{p.qpid},#{p.questionid},#{p.pointid},#{p.createid},#{p.createtime})
        </foreach>
    </insert>

    <!--试题关联知识点-->
    <select id="listPointsByQuestionid" resultType="java.util.Map">
        select qp.pointid,p.pointname from t_question_point qp
        left join t_point p on qp.pointid=p.pointid
        where qp.questionid=#{questionid} order by p.pointorder
    </select>

    <!--试题关联知识点-->
    <resultMap id="questionPoints" type="java.util.Map">
        <result property="questionid" column="questionid" />
        <collection property="pointList" javaType="java.util.List" ofType="java.util.Map">
            <result property="pointid" column="pointid" />
            <result property="pointname" column="pointname" />
        </collection>
    </resultMap>
    <select id="listQuestionPoints" resultMap="questionPoints">
        select qp.questionid,qp.pointid,p.pointname from t_question_point qp
        left join t_point p on qp.pointid=p.pointid
        where qp.questionid in
        <foreach collection="questionids" item="q" separator="," open="(" close=")">
            #{q}
        </foreach>
        order by p.pointorder
    </select>
</mapper>
