<?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.younike.system.mapper.MerchantLogMapper">
    
    <resultMap type="MerchantLog" id="MerchantLogResult">
        <result property="merchantId"    column="merchant_id"    />
        <result property="preState"    column="pre_state"    />
        <result property="nowState"    column="now_state"    />
        <result property="modifyInfo"    column="modify_info"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectMerchantLogVo">
        select merchant_id, pre_state, now_state, modify_info, create_by, create_time, update_by, update_time from merchant_log
    </sql>

    <select id="selectMerchantLogList" parameterType="MerchantLog" resultMap="MerchantLogResult">
        <include refid="selectMerchantLogVo"/>
        <where>  
            <if test="preState != null  and preState != ''"> and pre_state = #{preState}</if>
            <if test="nowState != null  and nowState != ''"> and now_state = #{nowState}</if>
            <if test="modifyInfo != null  and modifyInfo != ''"> and modify_info = #{modifyInfo}</if>
        </where>
    </select>
    
    <select id="selectMerchantLogByMerchantId" parameterType="Long" resultMap="MerchantLogResult">
        <include refid="selectMerchantLogVo"/>
        where merchant_id = #{merchantId}
    </select>
        
    <insert id="insertMerchantLog" parameterType="MerchantLog" useGeneratedKeys="true" keyProperty="merchantId">
        insert into merchant_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="preState != null">pre_state,</if>
            <if test="nowState != null">now_state,</if>
            <if test="modifyInfo != null">modify_info,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="preState != null">#{preState},</if>
            <if test="nowState != null">#{nowState},</if>
            <if test="modifyInfo != null">#{modifyInfo},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateMerchantLog" parameterType="MerchantLog">
        update merchant_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="preState != null">pre_state = #{preState},</if>
            <if test="nowState != null">now_state = #{nowState},</if>
            <if test="modifyInfo != null">modify_info = #{modifyInfo},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where merchant_id = #{merchantId}
    </update>

    <delete id="deleteMerchantLogByMerchantId" parameterType="Long">
        delete from merchant_log where merchant_id = #{merchantId}
    </delete>

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