<?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.TabHaobanWelcomeMapper">
    <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabWelcome">
        <id column="welcome_id" jdbcType="VARCHAR" property="welcomeId"/>
        <result column="wx_enterprise_id" jdbcType="VARCHAR" property="wxEnterpriseId"/>
        <result column="title" jdbcType="VARCHAR" property="title"/>
        <result column="welcome_content" jdbcType="VARCHAR" property="welcomeContent"/>
        <result column="welcome_img" jdbcType="VARCHAR" property="welcomeImg"/>
        <result column="status_flag" jdbcType="INTEGER" property="statusFlag"/>
        <result column="open_flag" jdbcType="INTEGER" property="openFlag"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="operator_id" jdbcType="VARCHAR" property="operatorId"/>
        <result column="operator_name" jdbcType="VARCHAR" property="operatorName"/>
        <result column="default_welcome_flag" jdbcType="INTEGER" property="defaultWelcomeFlag"/>
        <result column="creator_id" property="creatorId"/>
        <result column="creator_name" property="creatorName"/>
        <result column="modifier_id" property="modifierId"/>
        <result column="modifier_name" property="modifierName"/>
        <result column="type" property="type" jdbcType="INTEGER" />
    </resultMap>

    <sql id="Base_Column_List">
        welcome_id
        , wx_enterprise_id, title, welcome_content,welcome_img,open_flag, status_flag,
        create_time, update_time, operator_id, operator_name, default_welcome_flag , creator_id , creator_name , modifier_id , modifier_name, `type`
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_welcome
        where welcome_id = #{welcomeId,jdbcType=VARCHAR}
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
        delete
        from tab_haoban_welcome
        where welcome_id = #{welcomeId,jdbcType=VARCHAR}
    </delete>

    <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabWelcome">
        insert into tab_haoban_welcome (welcome_id, wx_enterprise_id, title,
                                        welcome_content, welcome_img, open_flag, status_flag, create_time,
                                        update_time, operator_id, operator_name, default_welcome_flag , creator_id , creator_name,modifier_id,modifier_name, `type`)
        values (#{welcomeId,jdbcType=VARCHAR},
                #{wxEnterpriseId,jdbcType=VARCHAR},
                #{title,jdbcType=VARCHAR},
                #{welcomeContent,jdbcType=VARCHAR},
                #{welcomeImg},
                #{openFlag},
                #{statusFlag,jdbcType=INTEGER},
                #{createTime,jdbcType=TIMESTAMP},
                #{updateTime,jdbcType=TIMESTAMP},
                #{operatorId,jdbcType=VARCHAR},
                #{operatorName,jdbcType=VARCHAR},
                #{defaultWelcomeFlag,jdbcType=INTEGER} , #{creatorId} , #{creatorName} , #{modifierId} , #{modifierName},
                #{type}
                )
    </insert>

    <update id="updateByPrimaryKeySelective" parameterType="com.gic.haoban.manage.service.entity.TabWelcome">
        update tab_haoban_welcome
        <set>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="title != null">
                title = #{title,jdbcType=VARCHAR},
            </if>
            <if test="welcomeContent != null">
                welcome_content = #{welcomeContent,jdbcType=VARCHAR},
            </if>
            <if test="welcomeImg != null">
                welcome_img = #{welcomeImg,jdbcType=VARCHAR},
            </if>
            <if test="openFlag != null">
                open_flag = #{openFlag,jdbcType=INTEGER},
            </if>
            <if test="statusFlag != null">
                status_flag = #{statusFlag,jdbcType=INTEGER},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="operatorId != null">
                operator_id = #{operatorId},
            </if>
            <if test="operatorName != null">
                operator_name = #{operatorName},
            </if>
            <if test="defaultWelcomeFlag != null">
                default_welcome_flag = #{defaultWelcomeFlag,jdbcType=INTEGER},
            </if>
             <if test="modifierId != null">
                modifier_id = #{modifierId},
            </if>
            <if test="modifierName != null">
                modifier_name = #{modifierName},
            </if>
            <if test="type != null">
                `type` = #{type}
            </if>
        </set>
        where welcome_id = #{welcomeId,jdbcType=VARCHAR}
    </update>

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

    <select id="listByWxEnterpriseId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_welcome
        where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
        <if test="title != null and title != ''">
            and title = #{title,jdbcType=VARCHAR}
        </if>
        <if test="defaultWelcomeFlag != null and defaultWelcomeFlag != ''">
            and default_welcome_flag = #{defaultWelcomeFlag,jdbcType=INTEGER}
        </if>
        and status_flag = 1
        order by update_time desc
    </select>

    <select id="countByWxEnterpriseId" resultType="java.lang.Long">
        select count(*)
        from tab_haoban_welcome
        where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
          and status_flag = 1
        <if test="type != null">
            and `type` = #{type}
        </if>
    </select>

    <select id="listAllWelcome" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_welcome where status_flag = 1
    </select>

    <select id="queryWelcomeList" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from tab_haoban_welcome
        <where>
            status_flag = 1
            <if test="wxEnterpriseId != null and wxEnterpriseId != '' ">
                and wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
            </if>
            <if test="title != null and title != ''">
                and title like concat('%', #{title}, '%')
            </if>
            <if test="defaultWelcomeFlag != null and defaultWelcomeFlag != ''">
                and default_welcome_flag = #{defaultWelcomeFlag,jdbcType=INTEGER}
            </if>
            <if test="type != null">
                and type = #{type}
            </if>
        </where>
        order by update_time desc
    </select>

</mapper>