<?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.xhkjedu.sapi.mapper.system.ModuledefaultMapper">
    <!-- 根据归属获取所有模块 -->
    <select id="listModulesByBelong" resultType="com.xhkjedu.sapi.model.system.TModule">
        SELECT m.moduleid,m.modulename,m.moduleurl,m.moduleico,m.modulepid,m.morder,m.minout
        ,m.comm,m.mclass,m.level,m.mabbrevname,m.mdefault,m.belong,m.belongcode,m.display
        FROM t_moduledefault m where m.belong=#{belong}
        <if test="belongcode!=null and belongcode==1">and m.belongcode in (1,3)</if>
        <if test="belongcode!=null and belongcode==2">and m.belongcode in (2,3)</if>

        <if test="display!=null">and m.display=#{display}</if>
        group by m.moduleid ORDER BY m.level,m.morder,m.moduleid
    </select>

    <!--获取所有模块-->
    <select id="listAllModules" resultType="com.xhkjedu.sapi.model.system.TModule">
        SELECT m.moduleid,m.modulename,m.moduleurl,m.moduleico,m.modulepid,m.morder,m.minout
        ,m.comm,m.mclass,m.level,m.mabbrevname,m.mdefault,m.belong,m.belongcode,m.display
        FROM t_moduledefault m ORDER BY m.level,m.morder,m.moduleid
    </select>
    <!-- 获取供第一层模块 -->
    <select id="listLevelModule" resultType="com.xhkjedu.sapi.vo.system.ModuleSelVo">
        SELECT moduleid,modulename,LEVEL FROM t_moduledefault WHERE LEVEL=1 and display=1
        and belong=#{belong} order by level,morder,moduleid
    </select>
    <!--获取学校id集合-->
    <select id="listSchoolId" resultType="java.lang.Integer">
        select schoolid from t_school where schoolstate=1
    </select>
    <!--模块地址对应模块数量-->
    <select id="countByUrl" resultType="java.lang.Integer">
        select count(*) from t_moduledefault where moduleurl=#{moduleurl} and belong=#{belong}
    </select>

    <!--模块地址对应模块数量-->
    <select id="countByMabbrevname" resultType="java.lang.Integer">
        select count(*) from t_moduledefault where mabbrevname=#{mabbrevname} and belong=#{belong}
    </select>

    <!--获取系统模块id-->
    <select id="getModuleIdByDefaultId" resultType="com.xhkjedu.sapi.model.system.TModule">
        select schoolid,moduleid from t_module where level=1 and belong=#{belong} and
        defaultid=#{moduleid} and schoolid in
        <foreach collection="schoolids" item="schoolid" index="index" open="(" separator="," close=")">
            ${schoolid}
        </foreach>
        group by schoolid
    </select>

    <!--修改显示状态-->
    <update id="updateModuleDisplay">
        update t_moduledefault set display=#{display} where moduleid=#{moduleid}
    </update>

    <!--修改分组下应用状态-->
    <update id="updateModuleDisplayForLevel">
        update t_moduledefault set display=#{display} where modulepid=#{moduleid} or moduleid=#{moduleid}
    </update>

</mapper>
