<?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.zbf.system.mapper.TBaseProviderMapper">

    <resultMap type="TBaseProvider" id="TBaseProviderResult">
            <result property="id"    column="id"    />
            <result property="providerId"    column="provider_id"    />
            <result property="proTypeId"    column="pro_type_id"    />
            <result property="providerName"    column="provider_name"    />
            <result property="pyName"    column="py_name"    />
            <result property="address"    column="address"    />
            <result property="contact"    column="contact"    />
            <result property="phone"    column="phone"    />
            <result property="mobile"    column="mobile"    />
            <result property="fax"    column="fax"    />
            <result property="email"    column="email"    />
            <result property="postCode"    column="post_code"    />
            <result property="bank"    column="bank"    />
            <result property="accountName"    column="account_name"    />
            <result property="account"    column="account"    />
            <result property="arrDays"    column="arr_days"    />
            <result property="providerLevel"    column="provider_level"    />
            <result property="percent"    column="percent"    />
            <result property="remark"    column="remark"    />
            <result property="nature"    column="nature"    />
            <result property="website"    column="website"    />
            <result property="legalMan"    column="legal_man"    />
            <result property="areaId"    column="area_id"    />
            <result property="regAddress"    column="reg_address"    />
            <result property="invoiceTitle"    column="invoice_title"    />
            <result property="taxNumber"    column="tax_number"    />
            <result property="payTypeId"    column="pay_type_id"    />
            <result property="invoiceAddress"    column="invoice_address"    />
            <result property="recipient"    column="recipient"    />
            <result property="recPhone"    column="rec_phone"    />
            <result property="recFax"    column="rec_fax"    />
            <result property="recEmail"    column="rec_email"    />
            <result property="version"    column="version"    />
            <result property="createTime"    column="create_time"    />
            <result property="createBy"    column="create_by"    />
            <result property="updateTime"    column="update_time"    />
            <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectTBaseProviderVo">
        select id, provider_id, pro_type_id, provider_name, py_name, address, contact, phone, mobile, fax, email, post_code, bank, account_name, account, arr_days, provider_level, percent, remark, nature, website, legal_man, area_id, reg_address, invoice_title, tax_number, pay_type_id, invoice_address, recipient, rec_phone, rec_fax, rec_email, version, create_time, create_by, update_time, update_by from t_base_provider
    </sql>

    <select id="selectTBaseProviderList" parameterType="TBaseProvider" resultMap="TBaseProviderResult">
        <include refid="selectTBaseProviderVo"/>
        <where>
                        <if test="providerId != null  and providerId != ''"> and provider_id = #{providerId}</if>
                        <if test="proTypeId != null  and proTypeId != ''"> and pro_type_id = #{proTypeId}</if>
                        <if test="providerName != null  and providerName != ''"> and provider_name like concat('%', #{providerName}, '%')</if>
                        <if test="pyName != null  and pyName != ''"> and py_name like concat('%', #{pyName}, '%')</if>
                        <if test="address != null  and address != ''"> and address = #{address}</if>
                        <if test="contact != null  and contact != ''"> and contact = #{contact}</if>
                        <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
                        <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
                        <if test="fax != null  and fax != ''"> and fax = #{fax}</if>
                        <if test="email != null  and email != ''"> and email = #{email}</if>
                        <if test="postCode != null  and postCode != ''"> and post_code = #{postCode}</if>
                        <if test="bank != null  and bank != ''"> and bank = #{bank}</if>
                        <if test="accountName != null  and accountName != ''"> and account_name like concat('%', #{accountName}, '%')</if>
                        <if test="account != null  and account != ''"> and account = #{account}</if>
                        <if test="arrDays != null "> and arr_days = #{arrDays}</if>
                        <if test="providerLevel != null  and providerLevel != ''"> and provider_level = #{providerLevel}</if>
                        <if test="percent != null "> and percent = #{percent}</if>
                        <if test="nature != null  and nature != ''"> and nature = #{nature}</if>
                        <if test="website != null  and website != ''"> and website = #{website}</if>
                        <if test="legalMan != null  and legalMan != ''"> and legal_man = #{legalMan}</if>
                        <if test="areaId != null  and areaId != ''"> and area_id = #{areaId}</if>
                        <if test="regAddress != null  and regAddress != ''"> and reg_address = #{regAddress}</if>
                        <if test="invoiceTitle != null  and invoiceTitle != ''"> and invoice_title = #{invoiceTitle}</if>
                        <if test="taxNumber != null  and taxNumber != ''"> and tax_number = #{taxNumber}</if>
                        <if test="payTypeId != null  and payTypeId != ''"> and pay_type_id = #{payTypeId}</if>
                        <if test="invoiceAddress != null  and invoiceAddress != ''"> and invoice_address = #{invoiceAddress}</if>
                        <if test="recipient != null  and recipient != ''"> and recipient = #{recipient}</if>
                        <if test="recPhone != null  and recPhone != ''"> and rec_phone = #{recPhone}</if>
                        <if test="recFax != null  and recFax != ''"> and rec_fax = #{recFax}</if>
                        <if test="recEmail != null  and recEmail != ''"> and rec_email = #{recEmail}</if>

                        <if test="selectIds !=null and selectIds.length>0">
                            and id in
                            <foreach collection="selectIds" item="itemId" open="(" close=")" separator=",">
                              #{itemId}
                            </foreach>
                        </if>
        </where>
        order by id asc
    </select>

    <select id="selectTBaseProviderById" parameterType="Long" resultMap="TBaseProviderResult">
            <include refid="selectTBaseProviderVo"/>
            where id = #{id}
    </select>

    <insert id="insertTBaseProvider" parameterType="TBaseProvider" useGeneratedKeys="true" keyProperty="id">
        insert into t_base_provider
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="providerId != null and providerId != ''">provider_id,</if>
                    <if test="proTypeId != null">pro_type_id,</if>
                    <if test="providerName != null and providerName != ''">provider_name,</if>
                    <if test="pyName != null">py_name,</if>
                    <if test="address != null">address,</if>
                    <if test="contact != null">contact,</if>
                    <if test="phone != null">phone,</if>
                    <if test="mobile != null">mobile,</if>
                    <if test="fax != null">fax,</if>
                    <if test="email != null">email,</if>
                    <if test="postCode != null">post_code,</if>
                    <if test="bank != null">bank,</if>
                    <if test="accountName != null">account_name,</if>
                    <if test="account != null">account,</if>
                    <if test="arrDays != null">arr_days,</if>
                    <if test="providerLevel != null">provider_level,</if>
                    <if test="percent != null">percent,</if>
                    <if test="remark != null">remark,</if>
                    <if test="nature != null">nature,</if>
                    <if test="website != null">website,</if>
                    <if test="legalMan != null">legal_man,</if>
                    <if test="areaId != null">area_id,</if>
                    <if test="regAddress != null">reg_address,</if>
                    <if test="invoiceTitle != null">invoice_title,</if>
                    <if test="taxNumber != null">tax_number,</if>
                    <if test="payTypeId != null">pay_type_id,</if>
                    <if test="invoiceAddress != null">invoice_address,</if>
                    <if test="recipient != null">recipient,</if>
                    <if test="recPhone != null">rec_phone,</if>
                    <if test="recFax != null">rec_fax,</if>
                    <if test="recEmail != null">rec_email,</if>
                    <if test="version != null">version,</if>
                    <if test="createTime != null">create_time,</if>
                    <if test="createBy != null">create_by,</if>
                    <if test="updateTime != null">update_time,</if>
                    <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="providerId != null and providerId != ''">#{providerId},</if>
                    <if test="proTypeId != null">#{proTypeId},</if>
                    <if test="providerName != null and providerName != ''">#{providerName},</if>
                    <if test="pyName != null">#{pyName},</if>
                    <if test="address != null">#{address},</if>
                    <if test="contact != null">#{contact},</if>
                    <if test="phone != null">#{phone},</if>
                    <if test="mobile != null">#{mobile},</if>
                    <if test="fax != null">#{fax},</if>
                    <if test="email != null">#{email},</if>
                    <if test="postCode != null">#{postCode},</if>
                    <if test="bank != null">#{bank},</if>
                    <if test="accountName != null">#{accountName},</if>
                    <if test="account != null">#{account},</if>
                    <if test="arrDays != null">#{arrDays},</if>
                    <if test="providerLevel != null">#{providerLevel},</if>
                    <if test="percent != null">#{percent},</if>
                    <if test="remark != null">#{remark},</if>
                    <if test="nature != null">#{nature},</if>
                    <if test="website != null">#{website},</if>
                    <if test="legalMan != null">#{legalMan},</if>
                    <if test="areaId != null">#{areaId},</if>
                    <if test="regAddress != null">#{regAddress},</if>
                    <if test="invoiceTitle != null">#{invoiceTitle},</if>
                    <if test="taxNumber != null">#{taxNumber},</if>
                    <if test="payTypeId != null">#{payTypeId},</if>
                    <if test="invoiceAddress != null">#{invoiceAddress},</if>
                    <if test="recipient != null">#{recipient},</if>
                    <if test="recPhone != null">#{recPhone},</if>
                    <if test="recFax != null">#{recFax},</if>
                    <if test="recEmail != null">#{recEmail},</if>
                    <if test="version != null">#{version},</if>
                    <if test="createTime != null">#{createTime},</if>
                    <if test="createBy != null">#{createBy},</if>
                    <if test="updateTime != null">#{updateTime},</if>
                    <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateTBaseProvider" parameterType="TBaseProvider">
        update t_base_provider
        <trim prefix="SET" suffixOverrides=",">
                    <if test="providerId != null and providerId != ''">provider_id = #{providerId},</if>
                    <if test="proTypeId != null">pro_type_id = #{proTypeId},</if>
                    <if test="providerName != null and providerName != ''">provider_name = #{providerName},</if>
                    <if test="pyName != null">py_name = #{pyName},</if>
                    <if test="address != null">address = #{address},</if>
                    <if test="contact != null">contact = #{contact},</if>
                    <if test="phone != null">phone = #{phone},</if>
                    <if test="mobile != null">mobile = #{mobile},</if>
                    <if test="fax != null">fax = #{fax},</if>
                    <if test="email != null">email = #{email},</if>
                    <if test="postCode != null">post_code = #{postCode},</if>
                    <if test="bank != null">bank = #{bank},</if>
                    <if test="accountName != null">account_name = #{accountName},</if>
                    <if test="account != null">account = #{account},</if>
                    <if test="arrDays != null">arr_days = #{arrDays},</if>
                    <if test="providerLevel != null">provider_level = #{providerLevel},</if>
                    <if test="percent != null">percent = #{percent},</if>
                    <if test="remark != null">remark = #{remark},</if>
                    <if test="nature != null">nature = #{nature},</if>
                    <if test="website != null">website = #{website},</if>
                    <if test="legalMan != null">legal_man = #{legalMan},</if>
                    <if test="areaId != null">area_id = #{areaId},</if>
                    <if test="regAddress != null">reg_address = #{regAddress},</if>
                    <if test="invoiceTitle != null">invoice_title = #{invoiceTitle},</if>
                    <if test="taxNumber != null">tax_number = #{taxNumber},</if>
                    <if test="payTypeId != null">pay_type_id = #{payTypeId},</if>
                    <if test="invoiceAddress != null">invoice_address = #{invoiceAddress},</if>
                    <if test="recipient != null">recipient = #{recipient},</if>
                    <if test="recPhone != null">rec_phone = #{recPhone},</if>
                    <if test="recFax != null">rec_fax = #{recFax},</if>
                    <if test="recEmail != null">rec_email = #{recEmail},</if>
                    <if test="version != null">version = #{version},</if>
                    <if test="createTime != null">create_time = #{createTime},</if>
                    <if test="createBy != null">create_by = #{createBy},</if>
                    <if test="updateTime != null">update_time = #{updateTime},</if>
                    <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="enableTBaseProviderByIds" parameterType="String">
        update t_base_provider set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledTBaseProviderByIds" parameterType="String">
        update t_base_provider set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteTBaseProviderById" parameterType="Long">
        delete from t_base_provider  where id = #{id}
    </delete>

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