<?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.schoolinout.api.mapper.ApiParentMapper">

    <select id="selectOnlyOne" resultType="com.schoolinout.system.domain.Parent">
        SELECT
        p.id,
        p.parent_name,
        p.parent_phone,
        p.relation,
        p.del_flag,
        p.create_by,
        p.create_time,
        p.update_by,
        p.update_time,
        GROUP_CONCAT(sp.student_id SEPARATOR ',') AS student_ids
        from tb_school_parent p
        LEFT JOIN tb_school_student_parent_relation sp ON p.id = sp.parent_id
        <where>
            <if test="id != null">
                AND p.id = #{id}
            </if>
            <if test="parentPhone != null">
                AND p.parent_phone = #{parentPhone}
            </if>
            <if test="parentName != null">
                AND p.parent_name LIKE '%' #{parentName} '%'
            </if>
        </where>
    </select>
</mapper>