<?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.yiqi.crm.mapper.WxReplyMapper">

    <resultMap type="com.yiqi.crm.domain.WxReply" id="WxReplyResult">
        <result property="replyId" column="reply_id"/>
        <result property="keyWords" column="key_words"/>
        <result property="keyWordsType" column="key_words_type"/>
        <result property="isUseKeyWords" column="is_use_key_words"/>
        <result property="title" column="title"/>
        <result property="author" column="author"/>
        <result property="synopsis" column="synopsis"/>
        <result property="pictureUrl" column="picture_url"/>
        <result property="picTextDetailContent" column="pic_text_detail_content"/>
        <result property="picTextUrl" column="pic_text_url"/>
        <result property="replyType" column="reply_type"/>
        <result property="contentType" column="content_type"/>
        <result property="lookNumber" column="look_number"/>
        <result property="mediaId" column="media_id"/>
        <result property="relationReplyId" column="relation_reply_id"/>
        <result property="sort" column="sort"/>
        <result property="status" column="status"/>
        <result property="createById" column="create_by_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateById" column="update_by_id"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectWxReplyVo">
        select reply_id, key_words, key_words_type, is_use_key_words,
         title, author, synopsis, picture_url, pic_text_detail_content,
          pic_text_url, reply_type, content_type, look_number, media_id, sort, status, relation_reply_id,
           create_by_id, create_by, create_time, update_by_id, update_by, update_time, remark
        from wx_reply
    </sql>

    <select id="selectWxReplyList"  resultMap="WxReplyResult">
        <include refid="selectWxReplyVo"/>
        <where>
            <if test="keyWords != null  and keyWords != ''">
                and key_words like concat('%', #{keyWords}, '%')
            </if>
            <if test="keyWordsType != null  and keyWordsType != ''">
                and key_words_type = #{keyWordsType}
            </if>
            <if test="isUseKeyWords != null  and isUseKeyWords != ''">
                and is_use_key_words = #{isUseKeyWords}
            </if>
            <if test="title != null  and title != ''">
                and title = #{title}
            </if>
            <if test="author != null  and author != ''">
                and author = #{author}
            </if>
            <if test="synopsis != null  and synopsis != ''">
                and synopsis = #{synopsis}
            </if>
            <if test="pictureUrl != null  and pictureUrl != ''">
                and picture_url = #{pictureUrl}
            </if>
            <if test="picTextDetailContent != null  and picTextDetailContent != ''">
                and pic_text_detail_content = #{picTextDetailContent}
            </if>
            <if test="picTextUrl != null  and picTextUrl != ''">
                and pic_text_url = #{picTextUrl}
            </if>
            <if test="replyType != null  and replyType != ''">
                and reply_type = #{replyType}
            </if>
            <if test="contentType != null  and contentType != ''">
                and content_type = #{contentType}
            </if>
            <if test="lookNumber != null  and lookNumber != ''">
                and look_number = #{lookNumber}
            </if>
            <if test="createById != null  and createById != ''">
                and create_by_id = #{createById}
            </if>
            <if test="updateById != null  and updateById != ''">
                and update_by_id = #{updateById}
            </if>
        </where>
    </select>

    <select id="selectWxReplyByReplyId" parameterType="Long"
            resultMap="WxReplyResult">
        <include refid="selectWxReplyVo"/>
        where reply_id = #{replyId}
    </select>

    <select id="getKeyWordsReplyList" resultMap="WxReplyResult">
        <include refid="selectWxReplyVo"/>
        where 1=1
        <if test="keyWords != null and keyWords != '' and keyWordsType == '10510'">
            and key_words like concat('%', #{keyWords}, '%')
        </if>
        <if test="keyWords != null and keyWords != '' and keyWordsType == '10520'">
            and key_words = #{keyWords}
        </if>
        <if test="replyId != null and replyId != ''">
            and reply_id = #{replyId}
        </if>
        <if test="replyType != null and replyType != ''">
            and reply_type = #{replyType}
        </if>
        <if test="keyWordsType != null and keyWordsType != '' and keyWordsType == '10510'">
            and key_words_type != "10520"
        </if>
        <if test="keyWordsType != null and keyWordsType != '' and keyWordsType == '10520'">
            and key_words_type = #{keyWordsType}
        </if>
        <if test="contentType != null  and contentType != ''">
            and content_type = #{contentType}
        </if>
        <if test="status != null and status != ''">
            and status = #{status}
        </if>
    </select>

    <select id="selectWxReplyByReplyType" resultMap="WxReplyResult">
        <include refid="selectWxReplyVo"/>
        where reply_type = #{replyType}
    </select>
    <select id="countLookNumber" resultType="java.lang.Integer">
        update wx_reply set look_number = look_number+1 where reply_id = #{replyId};
    </select>

    <insert id="insertWxReply"  useGeneratedKeys="true"
            keyProperty="replyId">
        insert into wx_reply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="keyWords != null and keyWords != ''">key_words,
            </if>
            <if test="keyWordsType != null and keyWordsType != ''">key_words_type,
            </if>
            <if test="isUseKeyWords != null and isUseKeyWords != ''">is_use_key_words,
            </if>
            <if test="title != null">title,
            </if>
            <if test="author != null">author,
            </if>
            <if test="synopsis != null">synopsis,
            </if>
            <if test="pictureUrl != null">picture_url,
            </if>
            <if test="picTextDetailContent != null">pic_text_detail_content,
            </if>
            <if test="picTextUrl != null">pic_text_url,
            </if>
            <if test="replyType != null and replyType != ''">reply_type,
            </if>
            <if test="contentType != null and contentType != ''">content_type,
            </if>
            <if test="lookNumber != null">look_number,
            </if>
            <if test="createById != null">create_by_id,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateById != null">update_by_id,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
            <if test="remark != null">remark,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="keyWords != null and keyWords != ''">#{keyWords},
            </if>
            <if test="keyWordsType != null and keyWordsType != ''">#{keyWordsType},
            </if>
            <if test="isUseKeyWords != null and isUseKeyWords != ''">#{isUseKeyWords},
            </if>
            <if test="title != null">#{title},
            </if>
            <if test="author != null">#{author},
            </if>
            <if test="synopsis != null">#{synopsis},
            </if>
            <if test="pictureUrl != null">#{pictureUrl},
            </if>
            <if test="picTextDetailContent != null">#{picTextDetailContent},
            </if>
            <if test="picTextUrl != null">#{picTextUrl},
            </if>
            <if test="replyType != null and replyType != ''">#{replyType},
            </if>
            <if test="contentType != null and contentType != ''">#{contentType},
            </if>
            <if test="lookNumber != null">#{lookNumber},
            </if>
            <if test="createById != null">#{createById},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateById != null">#{updateById},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
            <if test="remark != null">#{remark},
            </if>
        </trim>
    </insert>

    <update id="updateWxReply">
        update wx_reply
        <trim prefix="SET" suffixOverrides=",">
            <if test="keyWords != null and keyWords != ''">key_words =
                #{keyWords},
            </if>
            <if test="keyWordsType != null and keyWordsType != ''">key_words_type =
                #{keyWordsType},
            </if>
            <if test="isUseKeyWords != null and isUseKeyWords != ''">is_use_key_words =
                #{isUseKeyWords},
            </if>
            <if test="title != null">title =
                #{title},
            </if>
            <if test="author != null">author =
                #{author},
            </if>
            <if test="synopsis != null">synopsis =
                #{synopsis},
            </if>
            <if test="pictureUrl != null">picture_url =
                #{pictureUrl},
            </if>
            <if test="picTextDetailContent != null">pic_text_detail_content =
                #{picTextDetailContent},
            </if>
            <if test="picTextUrl != null">pic_text_url =
                #{picTextUrl},
            </if>
            <if test="replyType != null and replyType != ''">reply_type =
                #{replyType},
            </if>
            <if test="contentType != null and contentType != ''">content_type =
                #{contentType},
            </if>
            <if test="lookNumber != null">look_number =
                #{lookNumber},
            </if>
            <if test="createById != null">create_by_id =
                #{createById},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateById != null">update_by_id =
                #{updateById},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
            <if test="remark != null">remark =
                #{remark},
            </if>
        </trim>
        where reply_id = #{replyId}
    </update>

    <delete id="deleteWxReplyByReplyId" parameterType="Long">
        delete from wx_reply where reply_id = #{replyId}
    </delete>

    <delete id="deleteWxReplyByReplyIds" parameterType="String">
        delete from wx_reply where reply_id in
        <foreach item="replyId" collection="array" open="(" separator="," close=")">
            #{replyId}
        </foreach>
    </delete>
</mapper>