<?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.TabHaobanWelcomeMediaMapper">

    <resultMap type="com.gic.haoban.manage.service.entity.TabHaobanWelcomeMedia" id="TabHaobanWelcomeMediaMap">
        <result property="welcomeMediaId" column="welcome_media_id" jdbcType="BIGINT"/>
        <result property="wxEnterpriseId" column="wx_enterprise_id" jdbcType="VARCHAR"/>
        <result property="welcomeId" column="welcome_id" jdbcType="VARCHAR"/>
        <result property="mediaTitle" column="media_title" jdbcType="VARCHAR"/>
        <result property="mediaType" column="media_type" jdbcType="INTEGER"/>
        <result property="mediaUrl" column="media_url" jdbcType="VARCHAR"/>
        <result property="miniProgramPage" column="mini_program_page" jdbcType="VARCHAR"/>
        <result property="mediaSize" column="media_size" jdbcType="VARCHAR"/>
        <result property="miniProgramId" column="mini_program_id" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="deleteFlag" column="delete_flag" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="TabHaobanWelcomeMediaMap">
        select welcome_media_id,
               wx_enterprise_id,
               welcome_id,
               media_title,
               media_type,
               media_url,
               mini_program_page,
               media_size,
               mini_program_id,
               create_time,
               update_time,
               delete_flag
        from tab_haoban_welcome_media
        where welcome_media_id = #{welcomeMediaId}
    </select>

    <select id="listByWelcomeId" resultMap="TabHaobanWelcomeMediaMap">
        select welcome_media_id,
               wx_enterprise_id,
               welcome_id,
               media_title,
               media_type,
               media_url,
               mini_program_page,
               media_size,
               mini_program_id,
               create_time,
               update_time,
               delete_flag
        from tab_haoban_welcome_media
            where welcome_id = #{welcomeId} and delete_flag = 0
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="welcomeSuitRangId" useGeneratedKeys="false">
        insert into tab_haoban_welcome_media(
                                             welcome_media_id,
                                             wx_enterprise_id,
                                             welcome_id,
                                             media_title,
                                             media_type,
                                             media_url,
                                             mini_program_page,
                                             media_size,
                                             mini_program_id,
                                             create_time,
                                             update_time,
                                             delete_flag)
        values (#{welcomeMediaId},
                #{wxEnterpriseId},
                #{welcomeId},
                #{mediaTitle},
                #{mediaType},
                #{mediaUrl},
                #{miniProgramPage},
                #{mediaSize},
                #{miniProgramId},
                #{createTime},
                #{updateTime},
                #{deleteFlag})
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update tab_haoban_welcome_media
        <set>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                wx_enterprise_id = #{wxEnterpriseId},
            </if>
            <if test="welcomeId != null and welcomeId != ''">
                welcome_id = #{welcomeId},
            </if>
            <if test="mediaTitle != null">
                media_title = #{mediaTitle},
            </if>
            <if test="mediaType != null">
                media_type = #{mediaType},
            </if>
            <if test="mediaUrl != null and mediaUrl != ''">
                media_url = #{mediaUrl},
            </if>
            <if test="miniProgramPage != null and miniProgramPage != ''">
                mini_program_page = #{miniProgramPage},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="deleteFlag != null">
                delete_flag = #{deleteFlag},
            </if>
        </set>
        where welcome_media_id = #{welcomeMediaId}
    </update>

    <update id="removeByWelcomeId">
        update tab_haoban_welcome_media
        set delete_flag = 1
        where welcome_id = #{welcomeId}
    </update>

</mapper>
