<?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.ozs.base.mapper.BaseSupplierMapper">
    <resultMap type="com.ozs.base.domain.BaseSupplier" id="BaseSupplierResult">
        <id property="id" column="id"/>
        <result property="supplierName" column="supplier_name"/>
        <result property="supplierResponsiblePerson" column="supplier_responsible_person"/>
        <result property="supplierAddress" column="supplier_address"/>
        <result property="supplierType" column="supplier_type"/>
        <result property="supplierState" column="supplier_state"/>
        <result property="supplierAdvancePurchase" column="supplier_advance_purchase"/>
    </resultMap>

    <insert id="insertBaseSupplier" parameterType="com.ozs.base.domain.BaseSupplier">
        insert into base_supplier (
        <if test="supplierName != null and supplierName != '' ">
            supplier_name,
        </if>
        <if test="supplierResponsiblePerson != null and supplierResponsiblePerson != '' ">
            supplier_responsible_person,
        </if>
        <if test="supplierAddress != null and supplierAddress != '' ">
            supplier_address,
        </if>
        <if test="supplierType != null and supplierType != '' ">
            supplier_type,
        </if>
        <if test="supplierState != null and supplierState != ''">
            supplier_state,
        </if>
        <if test="supplierAdvancePurchase != null and supplierAdvancePurchase != ''">
            supplier_advance_purchase
        </if>
        ) values (
        <if test="supplierName != null and supplierName != ''">
            #{supplierName},
        </if>
        <if test="supplierResponsiblePerson != null and supplierResponsiblePerson != ''">
            #{supplierResponsiblePerson},
        </if>
        <if test="supplierAddress != null and supplierAddress != ''">
            #{supplierAddress},
        </if>
        <if test="supplierType != null and supplierType != ''">
            #{supplierType},
        </if>
        <if test="supplierState != null and supplierState != ''">
            #{supplierState},
        </if>
        <if test="supplierAdvancePurchase != null and supplierAdvancePurchase != ''">
            #{supplierAdvancePurchase}
        </if>
        )
    </insert>

    <delete id="deleteBaseSupplier" parameterType="java.lang.Integer">
        delete from base_supplier where id = #{id}
    </delete>

    <update id="updateBaseSupplier" parameterType="com.ozs.base.domain.BaseSupplier">
        update base_supplier
        <set>
            <if test="supplierName != null and supplierName != ''">
                supplier_name = #{supplierName},
            </if>
            <if test="supplierResponsiblePerson != null and supplierResponsiblePerson != ''">
                supplier_responsible_person = #{supplierResponsiblePerson},
            </if>
            <if test="supplierAddress != null and supplierAddress != ''">
                supplier_address = #{supplierAddress},
            </if>
            <if test="supplierType != null and supplierType != ''">
                supplier_type = #{supplierType},
            </if>
            <if test="supplierState != null and supplierState != ''">
                supplier_state = #{supplierState},
            </if>
            <if test="supplierAdvancePurchase != null and supplierAdvancePurchase != '' ">
                supplier_advance_purchase = #{supplierAdvancePurchase},
            </if>
        </set>
        where id = #{id}
    </update>

    <select id="selectBaseSupplier" parameterType="com.ozs.base.domain.BaseSupplier" resultMap="BaseSupplierResult">
        select * from base_supplier
        <where>
            <if test="id != null and id != ''">
                id = #{id},
            </if>
            <if test="supplierName != null and supplierName != ''">
                supplier_name like '% +' #{supplierName} '+ %',
            </if>
            <if test="supplierResponsiblePerson != null and supplierResponsiblePerson != ''">
                supplier_responsible_person like '% +' #{supplierResponsiblePerson} '+ %',
            </if>
            <if test="supplierAddress != null and supplierAddress != ''">
                supplier_address like '% +' #{supplierAddress} '+ %',
            </if>
            <if test="supplierType != null and supplierType != ''">
                supplier_type = #{supplierType},
            </if>
            <if test="supplierState != null and supplierState != ''">
                supplier_state = #{supplierState},
            </if>
            <if test="supplierAdvancePurchase != null and supplierAdvancePurchase != '' ">
                supplier_advance_purchase = #{supplierAdvancePurchase}
            </if>
        </where>
    </select>
</mapper>