<?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.tourism.webadmin.back.dao.TourImGroupTypeMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourImGroupType">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="parent_id" jdbcType="BIGINT" property="parentId"/>
        <result column="type_name" jdbcType="VARCHAR" property="typeName"/>
        <result column="type_icon" jdbcType="VARCHAR" property="typeIcon"/>
        <result column="enable" jdbcType="TINYINT" property="enable"/>
        <result column="data_state" jdbcType="TINYINT" property="dataState"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_im_group_type
            (id,
            parent_id,
            type_name,
            type_icon,
            enable,
            data_state,
            create_user_id,
            create_time,
            update_time,
            update_user_id)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.parentId},
            #{item.typeName},
            #{item.typeIcon},
            #{item.enable},
            #{item.dataState},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateTime},
            #{item.updateUserId})
        </foreach>
    </insert>

    <!-- 如果有逻辑删除字段过滤，请写到这里 -->
    <sql id="filterRef">
        <!-- 这里必须加上全包名，否则当filterRef被其他Mapper.xml包含引用的时候，就会调用Mapper.xml中的该SQL片段 -->
        <include refid="com.tourism.webadmin.back.dao.TourImGroupTypeMapper.inputFilterRef"/>
        AND tour_im_group_type.data_state = ${@com.tourism.common.core.constant.GlobalDeletedFlag@NORMAL}
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourImGroupTypeFilter != null">
            <if test="tourImGroupTypeFilter.id != null">
                AND tour_im_group_type.id = #{tourImGroupTypeFilter.id}
            </if>
            <if test="tourImGroupTypeFilter.parentId != null">
                AND tour_im_group_type.parent_id = #{tourImGroupTypeFilter.parentId}
            </if>
            <if test="tourImGroupTypeFilter.typeName != null and tourImGroupTypeFilter.typeName != ''">
                <bind name = "safeTourImGroupTypeTypeName" value = "'%' + tourImGroupTypeFilter.typeName + '%'" />
                AND tour_im_group_type.type_name LIKE #{safeTourImGroupTypeTypeName}
            </if>
            <if test="tourImGroupTypeFilter.enable != null">
                AND tour_im_group_type.enable = #{tourImGroupTypeFilter.enable}
            </if>
            <if test="tourImGroupTypeFilter.searchString != null and tourImGroupTypeFilter.searchString != ''">
                <bind name = "safeTourImGroupTypeSearchString" value = "'%' + tourImGroupTypeFilter.searchString + '%'" />
                AND IFNULL(tour_im_group_type.type_name,'') LIKE #{safeTourImGroupTypeSearchString}
            </if>
        </if>
    </sql>

    <select id="getTourImGroupTypeList" resultMap="BaseResultMap" parameterType="com.tourism.webadmin.back.model.TourImGroupType">
        SELECT * FROM tour_im_group_type
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
</mapper>
