<?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.xinyilu.system.mapper.checkReportFailInfo.CheckReportFailInfoMapper">

    <resultMap type="CheckReportFailInfo" id="CheckReportFailInfoResult">
        <result property="id" column="id"/>
        <result property="kindergartenId" column="kindergarten_id"/>
        <result property="classId" column="class_id"/>
        <result property="studentId" column="student_id"/>
        <result property="studentName" column="student_name"/>
        <result property="batchCode" column="batch_code"/>
        <result property="batchName" column="batch_name"/>
        <result property="checkReportType" column="check_report_type"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectCheckReportFailInfoVo">
        select id,
               kindergarten_id,
               class_id,
               student_id,
               student_name,
               batch_code,
               batch_name,
               check_report_type,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time
        from check_report_fail_info
    </sql>

    <select id="selectCheckReportFailInfoList" parameterType="CheckReportFailInfo"
            resultType="com.xinyilu.system.domain.dto.CheckReportFailInfoDTO">
        select
        crf.id,
        crf.kindergarten_id,
        ki.kindergarten_name,
        crf.class_id,
        crf.student_id,
        crf.student_name,
        crf.batch_code,
        crf.batch_name,
        crf.check_report_type,
        crf.del_flag,
        crf.create_by,
        crf.create_time,
        crf.update_by,
        crf.update_time
        from check_report_fail_info crf
        left join kindergarten_info ki on ki.id=crf.kindergarten_id
        <where>
            crf.del_flag=0
            <if test="kindergartenId != null ">
                and crf.kindergarten_id = #{kindergartenId}
            </if>
            <if test="classId != null ">
                and crf.class_id = #{classId}
            </if>
            <if test="studentId != null ">
                and crf.student_id = #{studentId}
            </if>
            <if test="studentName != null  and studentName != ''">
                and crf.student_name like concat('%', #{studentName}, '%')
            </if>
            <if test="batchCode != null  and batchCode != ''">
                and crf.batch_code = #{batchCode}
            </if>
            <if test="batchName != null  and batchName != ''">
                and crf.batch_name like concat('%', #{batchName}, '%')
            </if>
            <if test="checkReportType != null  and checkReportType != ''">
                and crf.check_report_type = #{checkReportType}
            </if>
        </where>
    </select>

    <select id="selectCheckReportFailInfoById" parameterType="Long"
            resultMap="CheckReportFailInfoResult">
        <include refid="selectCheckReportFailInfoVo"/>
        where id = #{id}
    </select>
    <insert id="insertBatchTestCategoryInfo" parameterType="list">
        insert into test_category_item(
        item_category_id,
        item_id,
        del_flag,
        create_by,
        create_time
        ) values
        <foreach item="categoryItem" index="index" collection="categoryItemList" separator=",">
            (
            #{categoryItem.itemCategoryId},
            #{categoryItem.itemId},
            0,
            #{categoryItem.createBy},
            #{categoryItem.createTime}
            )
        </foreach>
    </insert>

    <insert id="insertCheckReportFailInfo" parameterType="CheckReportFailInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into check_report_fail_info(
        kindergarten_id,
        class_id,
        student_id,
        student_name,
        batch_code,
        batch_name,
        check_report_type,
        del_flag,
        create_by,
        create_time
        ) values
        <foreach item="failInfo" index="index" collection="checkReportFailInfo" separator=",">
            (
            #{failInfo.kindergartenId},
            #{failInfo.classId},
            #{failInfo.studentId},
            #{failInfo.studentName},
            #{failInfo.batchCode},
            #{failInfo.batchName},
            #{failInfo.checkReportType},
            0,
            #{failInfo.createBy},
            #{failInfo.createTime}
            )
        </foreach>
    </insert>

    <update id="updateCheckReportFailInfoStatus" parameterType="String">
        update check_report_fail_info set del_flag = 1, update_time = now() where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>


    <update id="updateCheckReportFailInfo" parameterType="CheckReportFailInfo">
        update check_report_fail_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="kindergartenId != null">kindergarten_id =
                #{kindergartenId},
            </if>
            <if test="classId != null">class_id =
                #{classId},
            </if>
            <if test="studentId != null">student_id =
                #{studentId},
            </if>
            <if test="studentName != null">student_name =
                #{studentName},
            </if>
            <if test="batchCode != null and batchCode != ''">batch_code =
                #{batchCode},
            </if>
            <if test="batchName != null">batch_name =
                #{batchName},
            </if>
            <if test="checkReportType != null">check_report_type =
                #{checkReportType},
            </if>
            <if test="delFlag != null">del_flag =
                #{delFlag},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCheckReportFailInfoById" parameterType="Long">
        delete
        from check_report_fail_info
        where id = #{id}
    </delete>

    <delete id="deleteCheckReportFailInfoByIds" parameterType="String">
        delete from check_report_fail_info where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
