<?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.school.index.mapper.EduSchoolHomeAppMapper">
    <resultMap id="baseMap" type="com.yida.data.common.core.entity.school.EduSchoolHomeApp">
        <id property="id" column="id"/>
        <result property="type" column="type"/>
        <result property="sort" column="sort"/>
        <result property="name" column="name"/>
        <result property="url" column="url"/>
        <result property="schoolId" column="school_id"/>
        <result property="logo" column="logo"/>
        <result property="originId" column="origin_id"/>
        <result property="originName" column="origin_name"/>
        <collection property="showList" ofType="com.yida.data.common.core.entity.school.EduSchoolHomeAppShow">
            <result column="staff_id" property="staffId"/>
            <result column="staff_name" property="staffName"/>
            <result column="dept_id" property="deptId"/>
            <result column="dept_name" property="deptName"/>
        </collection>
    </resultMap>

    <select id="listApp" resultMap="baseMap">
        select a.id,a.sort,a.name,a.origin_id,a.origin_name,a.url,a.type,a.school_id,a.logo,
        b.staff_id,b.staff_name,b.dept_id,b.dept_name
        from edu_school_home_app a
        left join (select * from edu_school_home_app_show where del_flag=0) b on a.id=b.app_id
        where a.del_flag=0
        and a.school_id=#{schoolId} and a.type=#{type}
        <if test="identityId != null">
            and( b.staff_id=#{identityId}
            <if test="deptIds != null and deptIds.size() != 0">
                or b.dept_id in
                <foreach collection="deptIds" item="item" close=")" open="(" separator=",">
                    #{item}
                </foreach>
            </if>
            )
        </if>
        order by a.sort
    </select>
</mapper>
