<?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.yunfeiyun.agmp.fms.mapper.WmsSupplierMapper">
    
    <resultMap type="WmsSupplier" id="WmsSupplierResult">
        <result property="supplierId"    column="supplierId"    />
        <result property="supplierName"    column="supplierName"    />
        <result property="supplierLinkman"    column="supplierLinkman"    />
        <result property="supplierLinktel"    column="supplierLinktel"    />
        <result property="supplierLinkaddress"    column="supplierLinkaddress"    />
        <result property="supplierRemark"    column="supplierRemark"    />
        <result property="supplierCreator"    column="supplierCreator"    />
        <result property="supplierCreateddate"    column="supplierCreateddate"    />
        <result property="supplierType" column="supplierType"/>
    </resultMap>

    <sql id="selectWmsSupplierVo">
        select supplierId, supplierName, supplierLinkman, supplierLinktel, supplierLinkaddress, supplierRemark, supplierCreator, supplierCreateddate,supplierType from WmsSupplier
    </sql>

    <select id="selectWmsSupplierList" parameterType="WmsSupplier" resultMap="WmsSupplierResult">
        select supplierId, supplierName, supplierLinkman, supplierLinktel, supplierLinkaddress, supplierRemark, supplierCreator, supplierCreateddate,supplierType, b.resUrl as supplierPreview, b.resId as supplierQualificationResId from WmsSupplier a
        LEFT JOIN SysRes b on b.resBusId = a.supplierId
        <where>  
            <if test="supplierName != null  and supplierName != ''"> and supplierName like concat('%', #{supplierName}, '%')</if>
            <if test="supplierLinkman != null  and supplierLinkman != ''"> and supplierLinkman = #{supplierLinkman}</if>
            <if test="supplierLinktel != null  and supplierLinktel != ''"> and supplierLinktel = #{supplierLinktel}</if>
            <if test="supplierLinkaddress != null  and supplierLinkaddress != ''"> and supplierLinkaddress = #{supplierLinkaddress}</if>
            <if test="supplierRemark != null  and supplierRemark != ''"> and supplierRemark = #{supplierRemark}</if>
            <if test="supplierCreator != null  and supplierCreator != ''"> and supplierCreator = #{supplierCreator}</if>
            <if test="supplierCreateddate != null  and supplierCreateddate != ''"> and supplierCreateddate = #{supplierCreateddate}</if>
            <if test="supplierType != null  and supplierType != ''"> and supplierType = #{supplierType}</if>
        </where>
    </select>
    
    <select id="selectWmsSupplierBySupplierId" parameterType="String" resultMap="WmsSupplierResult">
        <include refid="selectWmsSupplierVo"/>
        where supplierId = #{supplierId}
    </select>
        
    <insert id="insertWmsSupplier" parameterType="WmsSupplier">
        insert into WmsSupplier
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="supplierId != null">supplierId,</if>
            <if test="supplierName != null">supplierName,</if>
            <if test="supplierLinkman != null">supplierLinkman,</if>
            <if test="supplierLinktel != null">supplierLinktel,</if>
            <if test="supplierLinkaddress != null">supplierLinkaddress,</if>
            <if test="supplierRemark != null">supplierRemark,</if>
            <if test="supplierCreator != null">supplierCreator,</if>
            <if test="supplierCreateddate != null">supplierCreateddate,</if>
            <if test="supplierType != null">supplierType,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="supplierId != null">#{supplierId},</if>
            <if test="supplierName != null">#{supplierName},</if>
            <if test="supplierLinkman != null">#{supplierLinkman},</if>
            <if test="supplierLinktel != null">#{supplierLinktel},</if>
            <if test="supplierLinkaddress != null">#{supplierLinkaddress},</if>
            <if test="supplierRemark != null">#{supplierRemark},</if>
            <if test="supplierCreator != null">#{supplierCreator},</if>
            <if test="supplierCreateddate != null">#{supplierCreateddate},</if>
            <if test="supplierType != null">#{supplierType},</if>
         </trim>
    </insert>

    <update id="updateWmsSupplier" parameterType="WmsSupplier">
        update WmsSupplier
        <trim prefix="SET" suffixOverrides=",">
            <if test="supplierName != null">supplierName = #{supplierName},</if>
            <if test="supplierLinkman != null">supplierLinkman = #{supplierLinkman},</if>
            <if test="supplierLinktel != null">supplierLinktel = #{supplierLinktel},</if>
            <if test="supplierLinkaddress != null">supplierLinkaddress = #{supplierLinkaddress},</if>
            <if test="supplierRemark != null">supplierRemark = #{supplierRemark},</if>
            <if test="supplierCreator != null">supplierCreator = #{supplierCreator},</if>
            <if test="supplierCreateddate != null">supplierCreateddate = #{supplierCreateddate},</if>
            <if test="supplierType != null">supplierType = #{supplierType}</if>
        </trim>
        where supplierId = #{supplierId}
    </update>

    <delete id="deleteWmsSupplierBySupplierId" parameterType="String">
        delete from WmsSupplier where supplierId = #{supplierId}
    </delete>

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