<?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="cn.reghao.tnb.content.app.exam.db.mapper.PaperMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into exam_paper
        (`subject_id`,`name`,`description`,`duration`,`total_score`,`pass_score`,`start_time`,`end_time`,`passcode`,`status`,`create_at`,`create_by`)
        values 
        (#{subjectId},#{name},#{description},#{duration},#{totalScore},#{passScore},#{endTime},#{startTime},#{passcode},#{status},#{createAt},#{createBy})
    </insert>

    <delete id="deleteById">
        delete from exam_paper
        where id=#{paperId}
    </delete>

    <select id="findAll" resultType="cn.reghao.tnb.content.app.exam.model.po.Paper">
        select *
        from exam_paper
    </select>
    <select id="findById" resultType="cn.reghao.tnb.content.app.exam.model.po.Paper">
        select *
        from exam_paper
        where id=#{id}
    </select>

    <select id="countByCriteria" resultType="java.lang.Integer">
        select count(*)
        from exam_paper
        where 1=1
        <if test="subjectId != null">
            and subject_id=#{subjectId}
        </if>
    </select>
    <select id="findPaperByPage" resultType="cn.reghao.tnb.content.app.exam.model.po.Paper">
        select *
        from exam_paper
        where 1=1
        <if test="paperQuery.subjectId != null">
            and subject_id=#{paperQuery.subjectId}
        </if>
    </select>
</mapper>