<?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.qmth.jkserver.dao.ExamPlanDao">

    <select id="findById" resultType="com.qmth.jkserver.model.ExamPlan">
        select * from jk_exam_plan t
        <where>
            <if test="id != null and id != ''">
                and t.id = #{id}
            </if>
        </where>
    </select>

    <delete id="deleteById">
        delete t from jk_exam_plan t
        <where>
            <if test="id != null and id != ''">
                and t.id = #{id}
            </if>
        </where>
    </delete>

    <select id="findByExamCode" resultType="com.qmth.jkserver.model.ExamPlan">
        select * from jk_exam_plan t
        <where>
            <if test="examCode != null and examCode != ''">
                and t.exam_code = #{examCode}
            </if>
        </where>
    </select>

    <select id="findByName" resultType="com.qmth.jkserver.model.ExamPlan">
        select * from jk_exam_plan t
        <where>
            <if test="name != null and name != ''">
                and t.name = #{name}
            </if>
        </where>
    </select>

    <select id="findByExamCodeAndExamTask" resultType="com.qmth.jkserver.dto.result.ExamPlanAnaTaskResult">
        select jep.id,
               jep.name,
               jep.exam_code as examCode,
               jep.exam_type as examType,
               jet.*
        from jk_exam_plan jep
        left join jk_exam_task jet on jet.id = jep.exam_task_id
        <where>
            <if test="examCode != null and examCode != ''">
                and jep.exam_code = #{examCode}
            </if>
            <if test="status != null and status != ''">
                and jet.status = #{status}
            </if>
            <if test="result != null and result != ''">
                and jet.result = #{result}
            </if>
            <if test="examType != null and examType != ''">
                and jep.exam_type = #{examType}
            </if>
            <if test="examStatus != null and examStatus != ''">
                and jep.exam_status = #{examStatus}
            </if>
            <if test="enable != null and enable != '' or enable == 0">
                and jep.enable = #{enable}
            </if>
            <if test="schoolId != null and schoolId != ''">
                and jep.school_id = #{schoolId}
            </if>
            <if test="creatorId != null and creatorId != ''">
                and jep.creator_id = #{creatorId}
            </if>
        </where>
        order by jep.create_time desc
    </select>

    <select id="findByExamCodeAndExamTaskCount" resultType="java.lang.Long">
        select count(1) from jk_exam_plan jep
        left join jk_exam_task jet on jet.id = jep.exam_task_id
        <where>
            <if test="examCode != null and examCode != ''">
                and jep.exam_code = #{examCode}
            </if>
            <if test="status != null and status != ''">
                and jet.status = #{status}
            </if>
            <if test="result != null and result != ''">
                and jet.result = #{result}
            </if>
            <if test="examType != null and examType != ''">
                and jep.exam_type = #{examType}
            </if>
            <if test="examStatus != null and examStatus != ''">
                and jep.exam_status = #{examStatus}
            </if>
            <if test="enable != null and enable != '' or enable == 0">
                and jep.enable = #{enable}
            </if>
            <if test="schoolId != null and schoolId != ''">
                and jep.school_id = #{schoolId}
            </if>
            <if test="creatorId != null and creatorId != ''">
                and jep.creator_id = #{creatorId}
            </if>
        </where>
    </select>
</mapper>
