<?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.xingxi.web.controller.master.product.mapper.VendorMapper">
    <resultMap type="Vendor" id="VendorResult">
        <result property="vendorId"    column="vendorId"    />
        <result property="vendorName"    column="vendorName"    />
        <result property="contact"    column="contact"    />
        <result property="mobile"    column="mobile"    />
        <result property="mail"    column="mail"    />
        <result property="address"    column="address"    />
        <result property="refundContact"    column="refundContact"    />
        <result property="refundMobile"    column="refundMobile"    />
        <result property="refundAddress"    column="refundAddress"    />
        <result property="delFlag"    column="delFlag"    />
        <result property="createUser"    column="createUser"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateUser"    column="updateUser"    />
        <result property="updateTime"    column="updateTime"    />
    </resultMap>

    <sql id="selectVendor">
        select vendorId, vendorName, contact, mobile, mail, address, refundContact, refundMobile, refundAddress, delFlag, createUser, createTime, updateUser, updateTime from m_vendor
    </sql>

    <select id="selectVendorList" parameterType="Vendor" resultMap="VendorResult">
        <include refid="selectVendor"/>
        <where>  
            <if test="vendorName != null  and vendorName != ''"> and vendorName like concat('%', #{vendorName}, '%')</if>
            <if test="contact != null  and contact != ''"> and contact = #{contact}</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
            <if test="mail != null  and mail != ''"> and mail = #{mail}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="refundContact != null  and refundContact != ''"> and refundContact = #{refundContact}</if>
            <if test="refundMobile != null  and refundMobile != ''"> and refundMobile = #{refundMobile}</if>
            <if test="refundAddress != null  and refundAddress != ''"> and refundAddress = #{refundAddress}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </select>
    
    <select id="selectVendorByVendorId" parameterType="Long" resultMap="VendorResult">
        <include refid="selectVendor"/>
        where vendorId = #{vendorId}
    </select>
        
    <insert id="insertVendor" parameterType="Vendor" useGeneratedKeys="true" keyProperty="vendorId">
        insert into m_vendor
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="vendorName != null">vendorName,</if>
            <if test="contact != null">contact,</if>
            <if test="mobile != null">mobile,</if>
            <if test="mail != null">mail,</if>
            <if test="address != null">address,</if>
            <if test="refundContact != null">refundContact,</if>
            <if test="refundMobile != null">refundMobile,</if>
            <if test="refundAddress != null">refundAddress,</if>
            <if test="delFlag != null">delFlag,</if>
            <if test="createUser != null">createUser,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateUser != null">updateUser,</if>
            <if test="updateTime != null">updateTime,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="vendorName != null">#{vendorName},</if>
            <if test="contact != null">#{contact},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="mail != null">#{mail},</if>
            <if test="address != null">#{address},</if>
            <if test="refundContact != null">#{refundContact},</if>
            <if test="refundMobile != null">#{refundMobile},</if>
            <if test="refundAddress != null">#{refundAddress},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <insert id="batchInsertVendor">
        insert into m_vendor( vendorName, contact, mobile, mail, address, refundContact, refundMobile, refundAddress, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.vendorName}, #{item.contact}, #{item.mobile}, #{item.mail}, #{item.address}, #{item.refundContact}, #{item.refundMobile}, #{item.refundAddress}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateVendor" parameterType="Vendor">
        update m_vendor
        <trim prefix="SET" suffixOverrides=",">
            <if test="vendorName != null">vendorName = #{vendorName},</if>
            <if test="contact != null">contact = #{contact},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="mail != null">mail = #{mail},</if>
            <if test="address != null">address = #{address},</if>
            <if test="refundContact != null">refundContact = #{refundContact},</if>
            <if test="refundMobile != null">refundMobile = #{refundMobile},</if>
            <if test="refundAddress != null">refundAddress = #{refundAddress},</if>
            <if test="delFlag != null">delFlag = #{delFlag},</if>
            <if test="createUser != null">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where vendorId = #{vendorId}
    </update>

    <delete id="deleteVendorByVendorId" parameterType="Long">
        delete from m_vendor where vendorId = #{vendorId}
    </delete>

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

    <update id="logicDeleteVendorByVendorId" parameterType="Long">
        update m_vendor
            set delFlag = '1'
        where vendorId = #{vendorId}
    </update>

    <update id="logicDeleteVendorByVendorIds" parameterType="String">
        update m_vendor
        set delFlag = '1'
        where vendorId in
        <foreach item="vendorId" collection="array" open="(" separator="," close=")">
            #{vendorId}
        </foreach>
    </update>

    <update id="logicDeleteVendorByCondition" parameterType="Vendor">
        update m_vendor
        set delFlag = '1'
        <where>
            <if test="vendorName != null  and vendorName != ''"> and vendorName like concat('%', #{vendorName}, '%')</if>
            <if test="contact != null  and contact != ''"> and contact = #{contact}</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
            <if test="mail != null  and mail != ''"> and mail = #{mail}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="refundContact != null  and refundContact != ''"> and refundContact = #{refundContact}</if>
            <if test="refundMobile != null  and refundMobile != ''"> and refundMobile = #{refundMobile}</if>
            <if test="refundAddress != null  and refundAddress != ''"> and refundAddress = #{refundAddress}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </update>
</mapper>