<?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.SchoolStypeMapper">
    <!--通过域名获取学校样式列表-->
    <select id="findAll" resultType="com.xhkjedu.sapi.model.system.TSchoolStype">
        select stid, s.schooldomain, st.schoolid, schooltype, stypeaddr, createid, createtime
        ,s.schoolname
        from (select schoolid,schoolname,schooldomain from t_school where schooldomain=#{stype.schooldomain}
        limit 1)s left join t_school_stype st on s.schoolid=st.schoolid
    </select>
    <!--通过学校id获取学校样式列表-->
    <select id="findAll2" resultType="com.xhkjedu.sapi.model.system.TSchoolStype">
        select st.stid, s.schooldomain, st.schoolid, st.schooltype, st.stypeaddr, st.createid,
               st.createtime,s.schoolname
        from t_school s left join t_school_stype st on s.schoolid=st.schoolid where s.schoolid=#{stype.schoolid}
        UNION  all
        select st2.stid,st2.schooldomain, st2.schoolid, st2.schooltype, st2.stypeaddr, st2.createid,
               st2.createtime,'' as schoolname
        from t_school_stype st2 where st2.schooldomain='default'
    </select>

    <!--批量添加-->
    <insert id="batchSave" parameterType="com.xhkjedu.sapi.model.system.TSchoolStype">
        <foreach collection ="list" item="s" index= "index" separator =";">
            INSERT INTO t_school_stype (schooldomain, schoolid, schooltype, stypeaddr, createid, createtime)
            VALUES (#{s.schooldomain},#{s.schoolid},#{s.schooltype},#{s.stypeaddr},#{s.createid},#{s.createtime})
            ON DUPLICATE KEY UPDATE schooldomain=#{s.schooldomain},stypeaddr=#{s.stypeaddr},createid=#{s.createid}
        </foreach>
    </insert>
</mapper>
