<?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.parentStudentInfo.ParentStudentInfoMapper">

    <resultMap type="ParentStudentInfo" id="ParentStudentInfoResult">
        <result property="id" column="id"/>
        <result property="parentId" column="parent_id"/>
        <result property="studentId" column="student_id"/>
        <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="selectParentStudentInfoVo">
        select id, parent_id, student_id, del_flag, create_by, create_time, update_by, update_time from parent_student_info
    </sql>

    <select id="selectParentStudentInfoList" parameterType="ParentStudentInfo" resultMap="ParentStudentInfoResult">
        <include refid="selectParentStudentInfoVo"/>
        <where>
            <if test="parentId != null ">
                and parent_id = #{parentId}
            </if>
            <if test="studentId != null ">
                and student_id = #{studentId}
            </if>
        </where>
    </select>

    <select id="selectParentStudentInfoById" parameterType="Long"
            resultMap="ParentStudentInfoResult">
        <include refid="selectParentStudentInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertParentStudentInfo" parameterType="ParentStudentInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into parent_student_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">parent_id,
            </if>
            <if test="studentId != null">student_id,
            </if>
            <if test="delFlag != null">del_flag,
            </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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parentId != null">#{parentId},
            </if>
            <if test="studentId != null">#{studentId},
            </if>
            <if test="delFlag != null">#{delFlag},
            </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>
        </trim>
    </insert>

    <update id="updateParentStudentInfo" parameterType="ParentStudentInfo">
        update parent_student_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id =
                #{parentId},
            </if>
            <if test="studentId != null">student_id =
                #{studentId},
            </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="deleteParentStudentInfoById" parameterType="Long">
        delete from parent_student_info where student_id = #{id}
    </delete>

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

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

    <select id="getParentStudentInfoByStudentId" parameterType="long" resultType="int">
        select count(1) counts from parent_student_info where student_id = #{studentId}
    </select>
</mapper>