<?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.fs.qw.mapper.QwWelcomeMapper">

    <resultMap type="QwWelcome" id="QwWelcomeResult">
        <result property="welcomeId"    column="welcome_id"    />
        <result property="templateId"    column="template_id"    />
        <result property="welcomeType"    column="welcome_type"    />
        <result property="textContent"    column="text_content"    />
        <result property="imageMediaId"    column="image_media_id"    />
        <result property="imagePicUrl"    column="image_pic_url"    />
        <result property="linkTitle"    column="link_title"    />
        <result property="linkPicurl"    column="link_picurl"    />
        <result property="linkDesc"    column="link_desc"    />
        <result property="linkUrl"    column="link_url"    />
        <result property="miniprogramTitle"    column="miniprogram_title"    />
        <result property="miniprogramPicMediaId"    column="miniprogram_pic_media_id"    />
        <result property="miniprogramPicUrl"    column="miniprogram_pic_url"    />
        <result property="miniprogramAppid"    column="miniprogram_appid"    />
        <result property="miniprogramPage"    column="miniprogram_page"    />
        <result property="fileMediaId"    column="file_media_id"    />
        <result property="videoMediaId"    column="video_media_id"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="notify"    column="notify"    />
        <result property="corpId"    column="corp_id"    />
        <result property="videoUrl"    column="video_url"    />
        <result property="companyId"    column="company_id"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="createName"    column="create_name"    />
        <result property="createdAt"    column="created_at"    />
    </resultMap>

    <sql id="selectQwWelcomeVo">
        select welcome_id, template_id, welcome_type, text_content, image_media_id, image_pic_url, link_title, link_picurl, link_desc, link_url, miniprogram_title, miniprogram_pic_media_id, miniprogram_pic_url, miniprogram_appid, miniprogram_page, file_media_id, video_media_id, file_url, notify, corp_id, video_url, company_id, update_time, create_time, create_name, created_at from qw_welcome
    </sql>

    <select id="selectQwWelcomeList" parameterType="QwWelcome" resultMap="QwWelcomeResult">
        <include refid="selectQwWelcomeVo"/>
        <where>
            <if test="templateId != null  and templateId != ''"> and template_id = #{templateId}</if>
            <if test="welcomeType != null "> and welcome_type = #{welcomeType}</if>
            <if test="textContent != null  and textContent != ''"> and text_content like  concat('%', #{textContent}, '%') </if>
            <if test="imageMediaId != null  and imageMediaId != ''"> and image_media_id = #{imageMediaId}</if>
            <if test="imagePicUrl != null  and imagePicUrl != ''"> and image_pic_url = #{imagePicUrl}</if>
            <if test="linkTitle != null  and linkTitle != ''"> and link_title = #{linkTitle}</if>
            <if test="linkPicurl != null  and linkPicurl != ''"> and link_picurl = #{linkPicurl}</if>
            <if test="linkDesc != null  and linkDesc != ''"> and link_desc = #{linkDesc}</if>
            <if test="linkUrl != null  and linkUrl != ''"> and link_url = #{linkUrl}</if>
            <if test="miniprogramTitle != null  and miniprogramTitle != ''"> and miniprogram_title = #{miniprogramTitle}</if>
            <if test="miniprogramPicMediaId != null  and miniprogramPicMediaId != ''"> and miniprogram_pic_media_id = #{miniprogramPicMediaId}</if>
            <if test="miniprogramPicUrl != null  and miniprogramPicUrl != ''"> and miniprogram_pic_url = #{miniprogramPicUrl}</if>
            <if test="miniprogramAppid != null  and miniprogramAppid != ''"> and miniprogram_appid = #{miniprogramAppid}</if>
            <if test="miniprogramPage != null  and miniprogramPage != ''"> and miniprogram_page = #{miniprogramPage}</if>
            <if test="fileMediaId != null  and fileMediaId != ''"> and file_media_id = #{fileMediaId}</if>
            <if test="videoMediaId != null  and videoMediaId != ''"> and video_media_id = #{videoMediaId}</if>
            <if test="fileUrl != null  and fileUrl != ''"> and file_url = #{fileUrl}</if>
            <if test="notify != null "> and notify = #{notify}</if>
            <if test="corpId != null  and corpId != ''"> and corp_id = #{corpId}</if>
            <if test="videoUrl != null  and videoUrl != ''"> and video_url = #{videoUrl}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="createName != null  and createName != ''"> and create_name like concat('%', #{createName}, '%')</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectQwWelcomeByWelcomeId" parameterType="Long" resultMap="QwWelcomeResult">
        <include refid="selectQwWelcomeVo"/>
        where welcome_id = #{welcomeId}
    </select>

    <insert id="insertQwWelcome" parameterType="QwWelcome" useGeneratedKeys="true" keyProperty="welcomeId">
        insert into qw_welcome
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="templateId != null">template_id,</if>
            <if test="welcomeType != null">welcome_type,</if>
            <if test="textContent != null">text_content,</if>
            <if test="imageMediaId != null">image_media_id,</if>
            <if test="imagePicUrl != null">image_pic_url,</if>
            <if test="linkTitle != null">link_title,</if>
            <if test="linkPicurl != null">link_picurl,</if>
            <if test="linkDesc != null">link_desc,</if>
            <if test="linkUrl != null">link_url,</if>
            <if test="miniprogramTitle != null">miniprogram_title,</if>
            <if test="miniprogramPicMediaId != null">miniprogram_pic_media_id,</if>
            <if test="miniprogramPicUrl != null">miniprogram_pic_url,</if>
            <if test="miniprogramAppid != null">miniprogram_appid,</if>
            <if test="miniprogramPage != null">miniprogram_page,</if>
            <if test="fileMediaId != null">file_media_id,</if>
            <if test="videoMediaId != null">video_media_id,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="notify != null">notify,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="videoUrl != null">video_url,</if>
            <if test="companyId != null">company_id,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createName != null">create_name,</if>
            <if test="createdAt != null">created_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="templateId != null">#{templateId},</if>
            <if test="welcomeType != null">#{welcomeType},</if>
            <if test="textContent != null">#{textContent},</if>
            <if test="imageMediaId != null">#{imageMediaId},</if>
            <if test="imagePicUrl != null">#{imagePicUrl},</if>
            <if test="linkTitle != null">#{linkTitle},</if>
            <if test="linkPicurl != null">#{linkPicurl},</if>
            <if test="linkDesc != null">#{linkDesc},</if>
            <if test="linkUrl != null">#{linkUrl},</if>
            <if test="miniprogramTitle != null">#{miniprogramTitle},</if>
            <if test="miniprogramPicMediaId != null">#{miniprogramPicMediaId},</if>
            <if test="miniprogramPicUrl != null">#{miniprogramPicUrl},</if>
            <if test="miniprogramAppid != null">#{miniprogramAppid},</if>
            <if test="miniprogramPage != null">#{miniprogramPage},</if>
            <if test="fileMediaId != null">#{fileMediaId},</if>
            <if test="videoMediaId != null">#{videoMediaId},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="notify != null">#{notify},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="videoUrl != null">#{videoUrl},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createName != null">#{createName},</if>
            <if test="createdAt != null">#{createName},</if>
         </trim>
    </insert>

    <update id="updateQwWelcome" parameterType="QwWelcome">
        update qw_welcome
        <trim prefix="SET" suffixOverrides=",">
            <if test="templateId != null">template_id = #{templateId},</if>
            <if test="welcomeType != null">welcome_type = #{welcomeType},</if>
            <if test="textContent != null">text_content = #{textContent},</if>
            <if test="imageMediaId != null">image_media_id = #{imageMediaId},</if>
            <if test="imagePicUrl != null">image_pic_url = #{imagePicUrl},</if>
            <if test="linkTitle != null">link_title = #{linkTitle},</if>
            <if test="linkPicurl != null">link_picurl = #{linkPicurl},</if>
            <if test="linkDesc != null">link_desc = #{linkDesc},</if>
            <if test="linkUrl != null">link_url = #{linkUrl},</if>
            <if test="miniprogramTitle != null">miniprogram_title = #{miniprogramTitle},</if>
            <if test="miniprogramPicMediaId != null">miniprogram_pic_media_id = #{miniprogramPicMediaId},</if>
            <if test="miniprogramPicUrl != null">miniprogram_pic_url = #{miniprogramPicUrl},</if>
            <if test="miniprogramAppid != null">miniprogram_appid = #{miniprogramAppid},</if>
            <if test="miniprogramPage != null">miniprogram_page = #{miniprogramPage},</if>
            <if test="fileMediaId != null">file_media_id = #{fileMediaId},</if>
            <if test="videoMediaId != null">video_media_id = #{videoMediaId},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="notify != null">notify = #{notify},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="videoUrl != null">video_url = #{videoUrl},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createName != null">create_name = #{createName},</if>
            <if test="createdAt != null">createAt = #{createdAt},</if>
        </trim>
        where welcome_id = #{welcomeId}
    </update>

    <delete id="deleteQwWelcomeByWelcomeId" parameterType="Long">
        delete from qw_welcome where welcome_id = #{welcomeId}
    </delete>

    <delete id="deleteQwWelcomeByWelcomeIds" parameterType="String">
        delete from qw_welcome where welcome_id in
        <foreach item="welcomeId" collection="array" open="(" separator="," close=")">
            #{welcomeId}
        </foreach>
    </delete>
</mapper>
