<?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.appversion.AppthirdManagerMapper">
    <!--学生监控详情-->
    <select id="listAll" resultType="com.xhkjedu.sapi.model.appversion.TAppthirdManager">
        select m.mid,m.mname,m.mpackage,m.mptype,m.msystem,m.mcomm,m.createid,m.createtime,m.belong
        <if test="manager.schoolid==null">
        ,(case when m.belong=3 then (select s.schoolname from t_school s where s.schoolid=m.schoolid) else '区平台' end)belongname
        </if>
        from t_appthird_manager m
        <where>
        <if test="manager.schoolid!=null">
            and (m.belong=2 or m.schoolid=#{manager.schoolid})
        </if>
        <if test="manager.mptype!=null">
            and m.mptype=#{manager.mptype}
        </if>
        <choose>
            <when test="manager.msystem!=null and manager.msystem==1"> and m.msystem=1</when>
            <otherwise> and m.msystem=2</otherwise>
        </choose>
        </where>
        order by m.createtime desc
    </select>
    <!--详情-->
    <select id="getByPackage" resultType="com.xhkjedu.sapi.model.appversion.TAppthirdManager">
        select m.mid,m.mname,m.mpackage,m.mptype,m.msystem,m.mcomm,m.createid,m.createtime,m.belong,m.schoolid
        from t_appthird_manager m
        where m.mpackage=#{mpackage}
        <if test="schoolid!=null">
            and (m.belong=2 or m.schoolid=#{schoolid})
        </if>
         limit 1
    </select>
    <!--添加-->
    <insert id="save">
        insert into t_appthird_manager (mid,mname,mpackage,mptype,msystem,mcomm,createid,createtime,belong,schoolid)
        values (#{manager.mid},#{manager.mname},#{manager.mpackage},#{manager.mptype},#{manager.msystem},#{manager.mcomm}
        ,#{manager.createid},#{manager.createtime},#{manager.belong},#{manager.schoolid})
        on duplicate key update mptype=#{manager.mptype}
    </insert>
    <!--删除-->
    <delete id="deleteByPackageAndSid">
        delete from t_appthird_manager where mpackage=#{mpackage}
        <if test="schoolid==null"> and schoolid is null</if>
        <if test="schoolid!=null"> and schoolid=#{schoolid}</if>
    </delete>
</mapper>
