<?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.yida.data.system.mapper.EduSchoolInquireCommonQuestionMapper">

    <select id="findQuestionPage"
            resultType="com.yida.data.common.core.entity.system.EduSchoolInquireCommonQuestion">
        SELECT
        a.*,
        GROUP_CONCAT( c.label ) AS label
        FROM
        `edu_school_inquire_common_question` a
        LEFT JOIN edu_school_inquire_common_question_label b ON a.id = b.question_id
        LEFT JOIN edu_label c ON b.label_id = c.id
        WHERE
        a.dept_id = #{deptId}
        AND a.del_flag = 0
        <if test="labelId != null">
            AND b.label_id = #{labelId}
        </if>
        <if test="question != null and question != ''">
            and a.question like concat ('%',#{question},'%')
        </if>
		GROUP BY
		a.id
		ORDER BY a.create_date DESC
    </select>
    <select id="findPhonePage" resultType="com.yida.data.system.vo.FindPhonePageVO">
        SELECT
        a.id,
        a.`name`,
        a.phone,
        c.school_name,
        GROUP_CONCAT(DISTINCT f.nature) as school_type,
        GROUP_CONCAT(e.label) as label
        FROM
        `edu_school_inquire_phone` a
        LEFT JOIN edu_school_inquire_phone_label b ON a.id = b.phone_id
        LEFT JOIN edu_label e ON b.label_id = e.id
        LEFT JOIN t_dept d ON a.dept_id = d.DEPT_ID
        LEFT JOIN t_dept_school_information c ON d.DEPT_ID = c.school_id
        left join t_dept_school_information_nature f on c.id = f.information_id
        WHERE
        a.dept_id = #{deptId}
        AND a.del_flag = 0
        <if test="labelId != null">
            AND b.label_id = #{labelId}
        </if>
        <if test="schoolName != null and schoolName != ''">
            and d.DEPT_NAME like concat ('%',#{schoolName},'%')
        </if>
        GROUP BY a.id,
        a.`name`,
        a.phone,
        c.id
        ORDER BY
        a.create_date DESC
    </select>
</mapper>
