<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "http://mybatis.org/dtd/mybatis-3-mapper.dtd" "mybatis-3-mapper.dtd" >
<mapper namespace="com.reyun.saas.mob.user.dao.AppMapper">

    <!--下拉框-主账号关联渠道查询app-->
    <select id="selectBySuperUser"  resultType="map" >
        select id,appkey,app_name appName from app where root_parent = #{rootParent} and del_flag is false and disable_flag is false
        and os = #{os}
        <if test="cid!=null">
            and appkey in (select appkey from channel where cid = #{cid})
        </if>
    </select>

    <!--下拉框-管理员关联渠道查询app-->
    <select id="findAppsBySubAppManager" resultType="map">
        select id,appkey,app_name appName from app where id in (${appIds}) and del_flag is false and disable_flag is false
        and os = #{os}
        <if test="cid!=null">
            and appkey in (select appkey from channel where cid = #{cid})
        </if>
    </select>

    <!-- 关联渠道查询app -->
    <select id="findAppByAppkeyLinkChannel" resultType="com.reyun.saas.mob.user.domain.App">
        SELECT DISTINCT t2.* FROM channel t1 INNER JOIN app t2 ON t1.appkey = t2.appkey WHERE t1.appkey IN
        <foreach collection="appkeys" item="appkey" open="(" close=")" separator=",">
            #{appkey}
        </foreach>
        AND (t1.del_flag is false AND t2.del_Flag is false )
        <if test="isActive != null ">
            AND t1.active is ${isActive}
        </if>
    </select>

    <!-- 关联工单查询app -->
    <select id="findAppByAppkeyLinkWorkOrder" resultType="com.reyun.saas.mob.user.domain.App">
        SELECT DISTINCT t2.* FROM work_order_export t1 INNER JOIN app t2 ON t1.appkey = t2.appkey WHERE t1.appkey IN
        <foreach collection="appkeys" item="appkey" open="(" close=")" separator=",">
            #{appkey}
        </foreach>
        AND t1.del_flag is false
    </select>


</mapper>