<?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.ruoyi.system.mapper.RegisterParentsStudentMapper">
    
    <resultMap type="RegisterParentsStudent" id="RegisterParentsStudentResult">
        <result property="id"    column="id"    />
        <result property="parentsId"    column="parents_id"    />

        <result property="parentsName"    column="parents_name"    />
        <result property="parentsPhone"    column="parents_phone"    />

        <result property="schoolId"    column="school_id"    />
        <result property="schoolName"    column="school_name"    />
        <result property="classId"    column="class_id"    />
        <result property="className"    column="class_name"    />
        <result property="studentName"    column="student_name"    />
        <result property="studentNumber"    column="student_number"    />
        <result property="isPass"    column="is_pass"    />
        <result property="auditId"    column="audit_id"    />
        <result property="auditUser"    column="audit_user"    />
        <result property="opinion"    column="opinion"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectRegisterParentsStudentVo">
        select id, parents_id,parents_name,parents_phone, school_id, school_name, class_id, class_name, student_name, student_number, is_pass,audit_id,audit_user,opinion, create_by, create_time, update_by, update_time, remark from register_parents_student
    </sql>

    <select id="selectRegisterParentsStudentList" parameterType="RegisterParentsStudent" resultMap="RegisterParentsStudentResult">
        <include refid="selectRegisterParentsStudentVo"/>
        <where>  
            <if test="parentsId != null  and parentsId != ''"> and parents_id = #{parentsId}</if>
            <if test="parentsName != null  and parentsName != ''"> and parents_name = #{parentsName}</if>
            <if test="parentsPhone != null  and parentsPhone != ''"> and parents_phone = #{parentsPhone}</if>
            <if test="schoolId != null  and schoolId != ''"> and school_id = #{schoolId}</if>
            <if test="schoolName != null  and schoolName != ''"> and school_name like concat('%', #{schoolName}, '%')</if>
            <if test="classId != null  and classId != ''"> and class_id = #{classId}</if>
            <if test="className != null  and className != ''"> and class_name like concat('%', #{className}, '%')</if>
            <if test="studentName != null  and studentName != ''"> and student_name like concat('%', #{studentName}, '%')</if>
            <if test="studentNumber != null  and studentNumber != ''"> and student_number = #{studentNumber}</if>
            <if test="isPass != null  and isPass != ''"> and is_pass = #{isPass}</if>
            <if test="auditId != null "> and audit_id = #{auditId}</if>
            <if test="auditUser != null  and auditUser != ''"> and audit_user = #{auditUser}</if>
            <if test="classIds != null  and classIds.size()>0">
                and class_id in
                <foreach collection="classIds" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>

        </where>
    </select>
    
    <select id="selectRegisterParentsStudentById" parameterType="Long" resultMap="RegisterParentsStudentResult">
        <include refid="selectRegisterParentsStudentVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertRegisterParentsStudent" parameterType="RegisterParentsStudent" useGeneratedKeys="true" keyProperty="id">
        insert into register_parents_student
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentsId != null">parents_id,</if>
            <if test="parentsName != null "> parents_name ,</if>
            <if test="parentsPhone != null "> parents_phone,</if>
            <if test="schoolId != null">school_id,</if>
            <if test="schoolName != null">school_name,</if>
            <if test="classId != null">class_id,</if>
            <if test="className != null">class_name,</if>
            <if test="studentName != null">student_name,</if>
            <if test="studentNumber != null">student_number,</if>
            <if test="isPass != null">is_pass,</if>
            <if test="auditId != null">audit_id,</if>
            <if test="auditUser != null">audit_user,</if>
            <if test="opinion != null">opinion,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parentsId != null">#{parentsId},</if>
            <if test="parentsName != null "> #{parentsName},</if>
            <if test="parentsPhone != null "> #{parentsPhone},</if>
            <if test="schoolId != null">#{schoolId},</if>
            <if test="schoolName != null">#{schoolName},</if>
            <if test="classId != null">#{classId},</if>
            <if test="className != null">#{className},</if>
            <if test="studentName != null">#{studentName},</if>
            <if test="studentNumber != null">#{studentNumber},</if>
            <if test="isPass != null">#{isPass},</if>
            <if test="auditId != null">#{auditId},</if>
            <if test="auditUser != null">#{auditUser},</if>
            <if test="opinion != null">#{opinion},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateRegisterParentsStudent" parameterType="RegisterParentsStudent">
        update register_parents_student
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentsId != null">parents_id = #{parentsId},</if>
            <if test="parentsName != null "> parents_name = #{parentsName},</if>
            <if test="parentsPhone != null "> parents_phone = #{parentsPhone},</if>
            <if test="schoolId != null">school_id = #{schoolId},</if>
            <if test="schoolName != null">school_name = #{schoolName},</if>
            <if test="classId != null">class_id = #{classId},</if>
            <if test="className != null">class_name = #{className},</if>
            <if test="studentName != null">student_name = #{studentName},</if>
            <if test="studentNumber != null">student_number = #{studentNumber},</if>
            <if test="isPass != null">is_pass = #{isPass},</if>
            <if test="auditId != null">audit_id= #{auditId},</if>
            <if test="auditUser != null">audit_user= #{auditUser},</if>
            <if test="opinion != null">opinion= #{opinion},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRegisterParentsStudentById" parameterType="Long">
        delete from register_parents_student where id = #{id}
    </delete>

    <delete id="deleteRegisterParentsStudentByIds" parameterType="String">
        delete from register_parents_student where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deleteRegisterParentsStudentByParentsId" parameterType="java.lang.Long">
        delete from register_parents_student where parents_id = #{parentsId} and isPass = '3';
    </delete>
</mapper>