<?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.gic.haoban.manage.service.dao.mapper.TabHaobanWelcomeTemplateRelationMapper">
    <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.hm.TabHaobanWelcomeTemplateRelation">
        <id column="relation_id" property="relationId" jdbcType="BIGINT"/>
        <result column="enterprise_id" property="enterpriseId" jdbcType="VARCHAR"/>
        <result column="wx_enterprise_id" property="wxEnterpriseId" jdbcType="VARCHAR"/>
        <result column="welcome_id" property="welcomeId" jdbcType="VARCHAR"/>
        <result column="refer_id" property="referId" jdbcType="VARCHAR"/>
        <result column="refer_code" property="referCode" jdbcType="VARCHAR"/>
        <result column="refer_name" property="referName" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="type" property="type" jdbcType="INTEGER"/>
        <result column="status" property="status" jdbcType="INTEGER"/>
    </resultMap>
    <sql id="Base_Column_List">
        relation_id
        , enterprise_id, wx_enterprise_id, welcome_id, refer_id, refer_name, create_time,
    update_time, type, status, refer_code
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_welcome_template_relation
        where relation_id = #{relationId,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete
        from tab_haoban_welcome_template_relation
        where relation_id = #{relationId,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.hm.TabHaobanWelcomeTemplateRelation">
        insert into tab_haoban_welcome_template_relation (relation_id, enterprise_id, wx_enterprise_id,
                                                          welcome_id, refer_id, refer_name,
                                                          create_time, update_time, type,
                                                          status, refer_code)
        values (#{relationId,jdbcType=BIGINT}, #{enterpriseId,jdbcType=VARCHAR}, #{wxEnterpriseId,jdbcType=VARCHAR},
                #{welcomeId,jdbcType=VARCHAR}, #{referId,jdbcType=VARCHAR}, #{referName,jdbcType=VARCHAR},
                #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{type,jdbcType=INTEGER},
                #{status,jdbcType=INTEGER}, #{referCode,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective"
            parameterType="com.gic.haoban.manage.service.entity.hm.TabHaobanWelcomeTemplateRelation">
        insert into tab_haoban_welcome_template_relation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="relationId != null">
                relation_id,
            </if>
            <if test="enterpriseId != null">
                enterprise_id,
            </if>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id,
            </if>
            <if test="welcomeId != null">
                welcome_id,
            </if>
            <if test="referId != null">
                refer_id,
            </if>
            <if test="referCode != null">
                refer_code,
            </if>
            <if test="referName != null">
                refer_name,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="type != null">
                type,
            </if>
            <if test="status != null">
                status,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="relationId != null">
                #{relationId,jdbcType=BIGINT},
            </if>
            <if test="enterpriseId != null">
                #{enterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="wxEnterpriseId != null">
                #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="welcomeId != null">
                #{welcomeId,jdbcType=VARCHAR},
            </if>
            <if test="referId != null">
                #{referId,jdbcType=VARCHAR},
            </if>
            <if test="referCode != null">
                #{referCode,jdbcType=VARCHAR},
            </if>
            <if test="referName != null">
                #{referName,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="type != null">
                #{type,jdbcType=INTEGER},
            </if>
            <if test="status != null">
                #{status,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective"
            parameterType="com.gic.haoban.manage.service.entity.hm.TabHaobanWelcomeTemplateRelation">
        update tab_haoban_welcome_template_relation
        <set>
            <if test="enterpriseId != null">
                enterprise_id = #{enterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="welcomeId != null">
                welcome_id = #{welcomeId,jdbcType=VARCHAR},
            </if>
            <if test="referId != null">
                refer_id = #{referId,jdbcType=VARCHAR},
            </if>
            <if test="referCode != null">
                refer_code = #{referCode,jdbcType=VARCHAR},
            </if>
            <if test="referName != null">
                refer_name = #{referName,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="type != null">
                type = #{type,jdbcType=INTEGER},
            </if>
            <if test="status != null">
                status = #{status,jdbcType=INTEGER},
            </if>
        </set>
        where relation_id = #{relationId,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey"
            parameterType="com.gic.haoban.manage.service.entity.hm.TabHaobanWelcomeTemplateRelation">
        update tab_haoban_welcome_template_relation
        set enterprise_id    = #{enterpriseId,jdbcType=VARCHAR},
            wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
            welcome_id       = #{welcomeId,jdbcType=VARCHAR},
            refer_id         = #{referId,jdbcType=VARCHAR},
            refer_code       = #{referCode,jdbcType=VARCHAR},
            refer_name       = #{referName,jdbcType=VARCHAR},
            create_time      = #{createTime,jdbcType=TIMESTAMP},
            update_time      = #{updateTime,jdbcType=TIMESTAMP},
            type             = #{type,jdbcType=INTEGER},
            status           = #{status,jdbcType=INTEGER}
        where relation_id = #{relationId,jdbcType=BIGINT}
    </update>

    <select id="queryWelcomeTemplate" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from tab_haoban_welcome_template_relation
        <where>
            <if test="welcomeId != null">
                and welcome_id = #{welcomeId}
            </if>
            <if test="status != null">
                and `status` = #{status}
            </if>
            <if test="searchContent != null and searchContent != ''">
                and (refer_code = #{searchContent} or refer_name like CONCAT('%', #{searchContent}, '%') )
            </if>
            <if test="statusList != null and statusList.size > 0">
                and `status` in
                <foreach collection="statusList" item="status" open="(" close=")" separator=",">
                    #{status}
                </foreach>
            </if>
        </where>
    </select>

    <select id="queryWelTemplateRelation" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from tab_haoban_welcome_template_relation
        where refer_id = #{referId}
        <if test="welcomeId != null">
            and welcome_id = #{welcomeId}
        </if>
        <if test="status != null">
            and `status` = #{status}
        </if>
    </select>
</mapper>