<?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.hw.mes.mapper.MesBaseSupplierInfoMapper">
    
    <resultMap type="MesBaseSupplierInfo" id="MesBaseSupplierInfoResult">
        <result property="supplierId"    column="supplier_id"    />
        <result property="supplierCode"    column="supplier_code"    />
        <result property="supplierName"    column="supplier_name"    />
        <result property="erpId"    column="erp_id"    />
        <result property="supplierStatus"    column="supplier_status"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="auditDate"    column="audit_date"    />
    </resultMap>

    <sql id="selectMesBaseSupplierInfoVo">
        select supplier_id, supplier_code, supplier_name, erp_id, supplier_status, remark, create_by, create_time, update_by, update_time, audit_date from mes_base_supplier_info
    </sql>

    <select id="selectMesBaseSupplierInfoList" parameterType="MesBaseSupplierInfo" resultMap="MesBaseSupplierInfoResult">
        <include refid="selectMesBaseSupplierInfoVo"/>
        <where>  
            <if test="supplierCode != null  and supplierCode != ''"> and supplier_code = #{supplierCode}</if>
            <if test="supplierName != null  and supplierName != ''"> and supplier_name like concat('%', #{supplierName}, '%')</if>
            <if test="erpId != null "> and erp_id = #{erpId}</if>
            <if test="supplierStatus != null  and supplierStatus != ''"> and supplier_status = #{supplierStatus}</if>
            <if test="params.beginAuditDate != null and params.beginAuditDate != '' and params.endAuditDate != null and params.endAuditDate != ''"> and audit_date between #{params.beginAuditDate} and #{params.endAuditDate}</if>
        </where>
    </select>
    
    <select id="selectMesBaseSupplierInfoBySupplierId" parameterType="Long" resultMap="MesBaseSupplierInfoResult">
        <include refid="selectMesBaseSupplierInfoVo"/>
        where supplier_id = #{supplierId}
    </select>
        
    <insert id="insertMesBaseSupplierInfo" parameterType="MesBaseSupplierInfo" useGeneratedKeys="true" keyProperty="supplierId">
        insert into mes_base_supplier_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="supplierCode != null">supplier_code,</if>
            <if test="supplierName != null and supplierName != ''">supplier_name,</if>
            <if test="erpId != null">erp_id,</if>
            <if test="supplierStatus != null and supplierStatus != ''">supplier_status,</if>
            <if test="remark != null">remark,</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>
            <if test="auditDate != null">audit_date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="supplierCode != null">#{supplierCode},</if>
            <if test="supplierName != null and supplierName != ''">#{supplierName},</if>
            <if test="erpId != null">#{erpId},</if>
            <if test="supplierStatus != null and supplierStatus != ''">#{supplierStatus},</if>
            <if test="remark != null">#{remark},</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>
            <if test="auditDate != null">#{auditDate},</if>
         </trim>
    </insert>

    <update id="updateMesBaseSupplierInfo" parameterType="MesBaseSupplierInfo">
        update mes_base_supplier_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="supplierCode != null">supplier_code = #{supplierCode},</if>
            <if test="supplierName != null and supplierName != ''">supplier_name = #{supplierName},</if>
            <if test="erpId != null">erp_id = #{erpId},</if>
            <if test="supplierStatus != null and supplierStatus != ''">supplier_status = #{supplierStatus},</if>
            <if test="remark != null">remark = #{remark},</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>
            <if test="auditDate != null">audit_date = #{auditDate},</if>
        </trim>
        where supplier_id = #{supplierId}
    </update>

    <delete id="deleteMesBaseSupplierInfoBySupplierId" parameterType="Long">
        delete from mes_base_supplier_info where supplier_id = #{supplierId}
    </delete>

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