<?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.FormalParentsStudentMapper">
    
    <resultMap type="FormalParentsStudent" id="FormalParentsStudentResult">
        <result property="id"    column="id"    />
        <result property="parentsId"    column="parents_id"    />
        <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="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="selectFormalParentsStudentVo">
        select id, parents_id, school_id, school_name, class_id, class_name, student_name, student_number, create_by, create_time, update_by, update_time, remark from formal_parents_student
    </sql>

    <select id="selectFormalParentsStudentList" parameterType="FormalParentsStudent" resultMap="FormalParentsStudentResult">
        <include refid="selectFormalParentsStudentVo"/>
        <where>  
            <if test="parentsId != null  and parentsId != ''"> and parents_id = #{parentsId}</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>
        </where>
    </select>
    
    <select id="selectFormalParentsStudentById" parameterType="Long" resultMap="FormalParentsStudentResult">
        <include refid="selectFormalParentsStudentVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFormalParentsStudent" parameterType="FormalParentsStudent" useGeneratedKeys="true" keyProperty="id">
        insert into formal_parents_student
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentsId != null">parents_id,</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="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="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="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="updateFormalParentsStudent" parameterType="FormalParentsStudent">
        update formal_parents_student
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentsId != null">parents_id = #{parentsId},</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="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="deleteFormalParentsStudentById" parameterType="Long">
        delete from formal_parents_student where id = #{id}
    </delete>

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