<?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.CompanyInfoMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.CompanyInfo">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="company_name" jdbcType="VARCHAR" property="companyName"/>
        <result column="address" jdbcType="VARCHAR" property="address"/>
        <result column="establish_date" jdbcType="DATE" property="establishDate"/>
        <result column="telephone" jdbcType="VARCHAR" property="telephone"/>
        <result column="website" jdbcType="VARCHAR" property="website"/>
        <result column="company_type" jdbcType="TINYINT" property="companyType"/>
        <result column="email" jdbcType="VARCHAR" property="email"/>
        <result column="company_url" jdbcType="VARCHAR" property="companyUrl"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_user_Id" jdbcType="BIGINT" property="updateUserId"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="data_state" jdbcType="TINYINT" property="dataState"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_company_info
            (id,
            company_name,
            address,
            establish_date,
            telephone,
            website,
            company_type,
            email,
            company_url,
            create_user_id,
            create_time,
            update_user_Id,
            update_time,
            data_state)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.companyName},
            #{item.address},
            #{item.establishDate},
            #{item.telephone},
            #{item.website},
            #{item.companyType},
            #{item.email},
            #{item.companyUrl},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.dataState})
        </foreach>
    </insert>

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

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="companyInfoFilter != null">
            <if test="companyInfoFilter.companyType != null and companyInfoFilter.companyType != ''">
                AND company_type = #{companyInfoFilter.companyType}
            </if>
            <if test="companyInfoFilter.companyName != null and companyInfoFilter.companyName != ''">
                <bind name = "safeCompanyInfoCompanyName" value = "'%' + companyInfoFilter.companyName + '%'" />
                AND tour_company_info.company_name LIKE #{safeCompanyInfoCompanyName}
            </if>
            <if test="companyInfoFilter.searchString != null and companyInfoFilter.searchString != ''">
                <bind name = "safeCompanyInfoSearchString" value = "'%' + companyInfoFilter.searchString + '%'" />
                AND IFNULL(tour_company_info.company_name,'') LIKE #{safeCompanyInfoSearchString}
            </if>
        </if>
    </sql>

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