<?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="io.dataease.base.mapper.ext.ExtSysMsgMapper">

    <resultMap id="msgGridDto" type="io.dataease.controller.message.dto.MsgGridDto" extends="io.dataease.base.mapper.SysMsgMapper.BaseResultMap">
        <result column="router" property="router"></result>
        <result column="callback" property="callback"></result>
    </resultMap>
    <sql id="Example_Where_Clause">
        <where>
            <foreach collection="oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>





    <select id="queryGrid" parameterType="io.dataease.base.domain.SysMsgExample" resultMap="msgGridDto">
        select sm.*, smt.router, smt.callback
        from sys_msg sm
        left join sys_msg_type smt on smt.msg_type_id = sm.type_id

        <if test="_parameter != null">
            <include refid="Example_Where_Clause" />
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
        <if test="orderByClause == null">
            order by sm.create_time desc
        </if>
    </select>


    <insert id="batchInsert" parameterType="io.dataease.base.domain.SysMsgSetting">
        INSERT INTO sys_msg_setting (user_id,type_id,channel_id,enable)
        VALUES
        <foreach collection="settings" item="setting" separator=",">
            (#{setting.userId}, #{setting.typeId}, #{setting.channelId}, #{setting.enable})
        </foreach>
    </insert>


</mapper>
