<?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.TabHaobanTemplateEnterpriseRelationMapper">
    <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabHaobanTemplateEnterpriseRelation">
        <id column="template_enterprise_relation_id" property="templateEnterpriseRelationId" jdbcType="VARCHAR"/>
        <result column="wx_enterprise_id" property="wxEnterpriseId" jdbcType="VARCHAR"/>
        <result column="wx_enterprise_name" property="wxEnterpriseName" jdbcType="VARCHAR"/>
        <result column="application_template_id" property="applicationTemplateId" jdbcType="VARCHAR"/>
        <result column="status_flag" property="statusFlag" jdbcType="INTEGER"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>
    <sql id="Base_Column_List">
        template_enterprise_relation_id, wx_enterprise_id, application_template_id, status_flag,wx_enterprise_name,
    create_time, update_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_template_enterprise_relation
        where template_enterprise_relation_id = #{templateEnterpriseRelationId,jdbcType=VARCHAR}
    </select>
    
    <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabHaobanTemplateEnterpriseRelation">
        insert into tab_haoban_template_enterprise_relation (template_enterprise_relation_id, wx_enterprise_id,
                                                             application_template_id, status_flag, create_time,
                                                             update_time, wx_enterprise_name)
        values (#{templateEnterpriseRelationId,jdbcType=VARCHAR}, #{wxEnterpriseId,jdbcType=VARCHAR},
                #{applicationTemplateId,jdbcType=VARCHAR}, #{statusFlag,jdbcType=INTEGER},
                #{createTime,jdbcType=TIMESTAMP},
                #{updateTime,jdbcType=TIMESTAMP}, #{wxEnterpriseName,jdbcType=VARCHAR})
    </insert>
    
    <update id="updateByPrimaryKeySelective"
            parameterType="com.gic.haoban.manage.service.entity.TabHaobanTemplateEnterpriseRelation">
        update tab_haoban_template_enterprise_relation
        <set>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="wxEnterpriseName != null">
                wx_enterprise_name = #{wxEnterpriseName,jdbcType=VARCHAR},
            </if>
            <if test="applicationTemplateId != null">
                application_template_id = #{applicationTemplateId,jdbcType=VARCHAR},
            </if>
            <if test="statusFlag != null">
                status_flag = #{statusFlag,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where template_enterprise_relation_id = #{templateEnterpriseRelationId,jdbcType=VARCHAR}
    </update>
    <update id="updateByPrimaryKey"
            parameterType="com.gic.haoban.manage.service.entity.TabHaobanTemplateEnterpriseRelation">
        update tab_haoban_template_enterprise_relation
        set wx_enterprise_id        = #{wxEnterpriseId,jdbcType=VARCHAR},
            wx_enterprise_name      = #{wxEnterpriseName,jdbcType=VARCHAR},
            application_template_id = #{applicationTemplateId,jdbcType=VARCHAR},
            status_flag             = #{statusFlag,jdbcType=INTEGER},
            create_time             = #{createTime,jdbcType=TIMESTAMP},
            update_time             = #{updateTime,jdbcType=TIMESTAMP}
        where template_enterprise_relation_id = #{templateEnterpriseRelationId,jdbcType=VARCHAR}
    </update>

    <select id="listEnterpriseByTemplateId" resultMap="BaseResultMap" parameterType="java.lang.String">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_template_enterprise_relation
        where application_template_id = #{templateId,jdbcType=VARCHAR}
        and status_flag = 1
    </select>

    <select id="selectByWxEnterpriseId" resultMap="BaseResultMap" parameterType="java.lang.String">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_template_enterprise_relation
        where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
        and status_flag = 1
    </select>

    <select id="listEnterpriseByParams" resultMap="BaseResultMap" parameterType="java.lang.String">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_template_enterprise_relation
        where application_template_id = #{applicationTemplateId,jdbcType=VARCHAR}
        and status_flag = 1
        <if test="wxEnterpriseName != null and wxEnterpriseName != ''">
            and wx_enterprise_name like CONCAT('%',#{wxEnterpriseName},'%')
        </if>
        <if test="wxEnterpriseIds != null and wxEnterpriseIds.size() > 0">
            and wx_enterprise_id IN
            <foreach collection="wxEnterpriseIds" item="id" index="index" open="(" close=")" separator=",">
                #{id,jdbcType=VARCHAR}
            </foreach>
        </if>
    </select>
</mapper>