<?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.company.mapper.CompanyWxChatMapper">
    
    <resultMap type="CompanyWxChat" id="CompanyWxChatResult">
        <result property="id"    column="id"    />
        <result property="wxUserId"    column="wx_user_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="msgJson"    column="msg_json"    />
        <result property="content"    column="content"    />
        <result property="msgType"    column="msg_type"    />
        <result property="sendType"    column="send_type"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCompanyWxChatVo">
        select id, wx_user_id, company_id, company_user_id, msg_json, content, msg_type, send_type, create_time, create_by, update_by, update_time, remark from company_wx_chat
    </sql>

    <select id="selectCompanyWxChatList" parameterType="CompanyWxChat" resultMap="CompanyWxChatResult">
        <include refid="selectCompanyWxChatVo"/>
        <where>  
            <if test="wxUserId != null "> and wx_user_id = #{wxUserId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="msgJson != null  and msgJson != ''"> and msg_json = #{msgJson}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="msgType != null "> and msg_type = #{msgType}</if>
            <if test="sendType != null "> and send_type = #{sendType}</if>
        </where>
    </select>
    
    <select id="selectCompanyWxChatById" parameterType="Long" resultMap="CompanyWxChatResult">
        <include refid="selectCompanyWxChatVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCompanyWxChat" parameterType="CompanyWxChat" useGeneratedKeys="true" keyProperty="id">
        insert into company_wx_chat
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wxUserId != null">wx_user_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="msgJson != null">msg_json,</if>
            <if test="content != null">content,</if>
            <if test="msgType != null">msg_type,</if>
            <if test="sendType != null">send_type,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</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="wxUserId != null">#{wxUserId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="msgJson != null">#{msgJson},</if>
            <if test="content != null">#{content},</if>
            <if test="msgType != null">#{msgType},</if>
            <if test="sendType != null">#{sendType},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCompanyWxChat" parameterType="CompanyWxChat">
        update company_wx_chat
        <trim prefix="SET" suffixOverrides=",">
            <if test="wxUserId != null">wx_user_id = #{wxUserId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="msgJson != null">msg_json = #{msgJson},</if>
            <if test="content != null">content = #{content},</if>
            <if test="msgType != null">msg_type = #{msgType},</if>
            <if test="sendType != null">send_type = #{sendType},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</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 id = #{id}
    </update>

    <delete id="deleteCompanyWxChatById" parameterType="Long">
        delete from company_wx_chat where id = #{id}
    </delete>

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