<?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.ximai.mes.md.mapper.MdClientMapper">
    <resultMap type="MdClient" id="MdClientResult">
        <result property="clientId" column="client_id"/>
        <result property="clientCode" column="client_code"/>
        <result property="sapClientCode" column="sap_client_code"/>
        <result property="clientName" column="client_name"/>
        <result property="clientNick" column="client_nick"/>
        <result property="clientEn" column="client_en"/>
        <result property="clientEnAbbr" column="client_en_abbr"/>
        <result property="clientLevel" column="client_level"/>
        <result property="billLevel" column="bill_level"/>
        <result property="invoiceAddr" column="invoice_addr"/>
        <result property="address" column="address"/>
        <result property="region" column="region"/>
        <result property="country" column="country"/>
        <result property="city" column="city"/>
        <result property="area" column="area"/>
        <result property="lang" column="lang"/>
        <result property="postcode" column="postcode"/>
        <result property="tel" column="tel"/>
        <result property="phone" column="phone"/>
        <result property="email" column="email"/>
        <result property="isClientWaybill" column="is_client_waybill"/>
        <result property="stampMode" column="stamp_mode"/>
        <result property="requisition" column="requisition"/>
        <result property="clientForm" column="client_form"/>
        <result property="orderRequest" column="order_request"/>
        <result property="receiptRequest" column="receipt_request"/>
        <result property="clientCheckRequest" column="client_check_request"/>
        <result property="requestSignReceipt" column="request_sign_receipt"/>
        <result property="isPrintDate" column="is_print_date"/>
        <result property="noInvoice" column="is_no_invoice"/>
        <result property="paymentRequest" column="payment_request"/>
        <result property="clientWorkTime" column="client_work_time"/>
        <result property="signRequest" column="sign_request"/>
        <result property="billPrintRequest" column="bill_print_request"/>
        <result property="membershipGroup" column="membership_group"/>
        <result property="qcReportType" column="qc_report_type"/>
        <result property="receiptSigningMethod" column="receipt_signing_method"/>
        <result property="shippingMethod" column="shipping_method"/>
        <result property="path" column="path"/>
        <result property="billPrintSetting" column="bill_print_setting"/>
        <result property="billExceptionDeadline" column="bill_exception_deadline"/>
        <result property="sendMode" column="send_mode"/>
        <result property="settleMode" column="settle_mode"/>
        <result property="paymentDeadline" column="payment_deadline"/>
        <result property="accountingDeadline" column="accounting_deadline"/>
        <result property="collectionDeadline" column="collection_deadline"/>
        <result property="orderExceptionDeadline" column="order_exception_deadline"/>
        <result property="deductionPercent" column="deduction_percentage"/>
        <result property="amountDecimal" column="amount_decimal"/>
        <result property="legalPerson" column="legal_person"/>
        <result property="licenseNo" column="license_no"/>
        <result property="taxNo" column="tax_no"/>
        <result property="orderKind" column="order_kind"/>
        <result property="remark" column="remark"/>
        <result property="enableFlag" column="enable_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectMdClientVo">
        select client_id, client_code, sap_client_code, client_name, client_nick, client_en, client_en_abbr, client_level, bill_level, invoice_addr, address, region, country, city, area, lang, postcode, tel, phone, email, is_client_waybill, stamp_mode, requisition, client_form, order_request, receipt_request, client_check_request, request_sign_receipt, is_print_date, is_no_invoice, payment_request, client_work_time, sign_request, bill_print_request, membership_group, qc_report_type, receipt_signing_method, shipping_method, path, bill_print_setting, bill_exception_deadline, send_mode, settle_mode, payment_deadline, accounting_deadline, collection_deadline, order_exception_deadline, deduction_percentage, amount_decimal, legal_person, license_no, tax_no, order_kind, remark, enable_flag, create_by, create_time, update_by, update_time
        from md_client
    </sql>

    <select id="selectMdClientList" parameterType="MdClient" resultMap="MdClientResult">
        <include refid="selectMdClientVo"/>
        <where>
            <if test="clientCode != null  and clientCode != ''"> and client_code = #{clientCode}</if>
            <if test="sapClientCode != null  and sapClientCode != ''"> and sap_client_code = #{sapClientCode}</if>
            <if test="clientName != null  and clientName != ''"> and client_name like concat('%', #{clientName}, '%')</if>
            <if test="clientNick != null  and clientNick != ''"> and client_nick = #{clientNick}</if>
            <if test="clientEn != null  and clientEn != ''"> and client_en = #{clientEn}</if>
            <if test="clientEnAbbr != null  and clientEnAbbr != ''"> and client_en_abbr = #{clientEnAbbr}</if>
            <if test="clientLevel != null "> and client_level = #{clientLevel}</if>
            <if test="billLevel != null "> and bill_level = #{billLevel}</if>
            <if test="invoiceAddr != null  and invoiceAddr != ''"> and invoice_addr = #{invoiceAddr}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="region != null  and region != ''"> and region = #{region}</if>
            <if test="country != null  and country != ''"> and country = #{country}</if>
            <if test="city != null  and city != ''"> and city = #{city}</if>
            <if test="area != null  and area != ''"> and area = #{area}</if>
            <if test="lang != null  and lang != ''"> and lang = #{lang}</if>
            <if test="postcode != null  and postcode != ''"> and postcode = #{postcode}</if>
            <if test="tel != null  and tel != ''"> and tel = #{tel}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="isClientWaybill != null  and isClientWaybill != ''"> and is_client_waybill = #{isClientWaybill}</if>
            <if test="stampMode != null  and stampMode != ''"> and stamp_mode = #{stampMode}</if>
            <if test="requisition != null  and requisition != ''"> and requisition = #{requisition}</if>
            <if test="clientForm != null  and clientForm != ''"> and client_form = #{clientForm}</if>
            <if test="orderRequest != null  and orderRequest != ''"> and order_request = #{orderRequest}</if>
            <if test="receiptRequest != null  and receiptRequest != ''"> and receipt_request = #{receiptRequest}</if>
            <if test="clientCheckRequest != null  and clientCheckRequest != ''"> and client_check_request = #{clientCheckRequest}</if>
            <if test="requestSignReceipt != null  and requestSignReceipt != ''"> and request_sign_receipt = #{requestSignReceipt}</if>
            <if test="isPrintDate != null  and isPrintDate != ''"> and is_print_date = #{isPrintDate}</if>
            <if test="noInvoice != null  and noInvoice != ''"> and is_no_invoice = #{noInvoice}</if>
            <if test="paymentRequest != null  and paymentRequest != ''"> and payment_request = #{paymentRequest}</if>
            <if test="clientWorkTime != null "> and client_work_time = #{clientWorkTime}</if>
            <if test="signRequest != null  and signRequest != ''"> and sign_request = #{signRequest}</if>
            <if test="billPrintRequest != null  and billPrintRequest != ''"> and bill_print_request = #{billPrintRequest}</if>
            <if test="membershipGroup != null  and membershipGroup != ''"> and membership_group = #{membershipGroup}</if>
            <if test="qcReportType != null  and qcReportType != ''"> and qc_report_type = #{qcReportType}</if>
            <if test="receiptSigningMethod != null  and receiptSigningMethod != ''"> and receipt_signing_method = #{receiptSigningMethod}</if>
            <if test="shippingMethod != null  and shippingMethod != ''"> and shipping_method = #{shippingMethod}</if>
            <if test="path != null  and path != ''"> and path = #{path}</if>
            <if test="billPrintSetting != null  and billPrintSetting != ''"> and bill_print_setting = #{billPrintSetting}</if>
            <if test="billExceptionDeadline != null  and billExceptionDeadline != ''"> and bill_exception_deadline = #{billExceptionDeadline}</if>
            <if test="sendMode != null  and sendMode != ''"> and send_mode = #{sendMode}</if>
            <if test="settleMode != null  and settleMode != ''"> and settle_mode = #{settleMode}</if>
            <if test="paymentDeadline != null  and paymentDeadline != ''"> and payment_deadline = #{paymentDeadline}</if>
            <if test="accountingDeadline != null  and accountingDeadline != ''"> and accounting_deadline = #{accountingDeadline}</if>
            <if test="collectionDeadline != null  and collectionDeadline != ''"> and collection_deadline = #{collectionDeadline}</if>
            <if test="orderExceptionDeadline != null  and orderExceptionDeadline != ''"> and order_exception_deadline = #{orderExceptionDeadline}</if>
            <if test="deductionPercent != null  and deductionPercent != ''"> and deduction_percentage = #{deductionPercent}</if>
            <if test="amountDecimal != null  and amountDecimal != ''"> and amount_decimal = #{amountDecimal}</if>
            <if test="legalPerson != null  and legalPerson != ''"> and legal_person = #{legalPerson}</if>
            <if test="licenseNo != null  and licenseNo != ''"> and license_no = #{licenseNo}</if>
            <if test="taxNo != null  and taxNo != ''"> and tax_no = #{taxNo}</if>
            <if test="orderKind != null  and orderKind != ''"> and order_kind = #{orderKind}</if>
            <if test="enableFlag != null  and enableFlag != ''"> and enable_flag = #{enableFlag}</if>
        </where>
    </select>

    <select id="selectMdClientByClientId" parameterType="Long" resultMap="MdClientResult">
        <include refid="selectMdClientVo"/>
        where client_id = #{clientId}
    </select>

    <select id="checkClientCodeUnique" parameterType="MdClient" resultMap="MdClientResult">
        <include refid="selectMdClientVo"/>
        where client_code = #{clientCode} limit 1
    </select>

    <select id="checkClientNameUnique" parameterType="MdClient" resultMap="MdClientResult">
        <include refid="selectMdClientVo"/>
        where client_name = #{clientName} limit 1
    </select>

    <select id="checkClientNickUnique" parameterType="MdClient" resultMap="MdClientResult">
        <include refid="selectMdClientVo"/>
        where client_nick = #{clientNick} limit 1
    </select>


    <insert id="insertMdClient" parameterType="MdClient" useGeneratedKeys="true" keyProperty="clientId">
        insert into md_client
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="clientCode != null">client_code,</if>
            <if test="sapClientCode != null">sap_client_code,</if>
            <if test="clientName != null">client_name,</if>
            <if test="clientNick != null">client_nick,</if>
            <if test="clientEn != null">client_en,</if>
            <if test="clientEnAbbr != null">client_en_abbr,</if>
            <if test="clientLevel != null">client_level,</if>
            <if test="billLevel != null">bill_level,</if>
            <if test="invoiceAddr != null">invoice_addr,</if>
            <if test="address != null">address,</if>
            <if test="region != null">region,</if>
            <if test="country != null">country,</if>
            <if test="city != null">city,</if>
            <if test="area != null">area,</if>
            <if test="lang != null">lang,</if>
            <if test="postcode != null">postcode,</if>
            <if test="tel != null">tel,</if>
            <if test="phone != null">phone,</if>
            <if test="email != null">email,</if>
            <if test="isClientWaybill != null">is_client_waybill,</if>
            <if test="stampMode != null">stamp_mode,</if>
            <if test="requisition != null">requisition,</if>
            <if test="clientForm != null">client_form,</if>
            <if test="orderRequest != null">order_request,</if>
            <if test="receiptRequest != null">receipt_request,</if>
            <if test="clientCheckRequest != null">client_check_request,</if>
            <if test="requestSignReceipt != null">request_sign_receipt,</if>
            <if test="isPrintDate != null">is_print_date,</if>
            <if test="noInvoice != null">noInvoice,</if>
            <if test="paymentRequest != null">payment_request,</if>
            <if test="clientWorkTime != null">client_work_time,</if>
            <if test="signRequest != null">sign_request,</if>
            <if test="billPrintRequest != null">bill_print_request,</if>
            <if test="membershipGroup != null">membership_group,</if>
            <if test="qcReportType != null">qc_report_type,</if>
            <if test="receiptSigningMethod != null">receipt_signing_method,</if>
            <if test="shippingMethod != null">shipping_method,</if>
            <if test="path != null">path,</if>
            <if test="billPrintSetting != null">bill_print_setting,</if>
            <if test="billExceptionDeadline != null">bill_exception_deadline,</if>
            <if test="sendMode != null">send_mode,</if>
            <if test="settleMode != null">settle_mode,</if>
            <if test="paymentDeadline != null">payment_deadline,</if>
            <if test="accountingDeadline != null">accounting_deadline,</if>
            <if test="collectionDeadline != null">collection_deadline,</if>
            <if test="orderExceptionDeadline != null">order_exception_deadline,</if>
            <if test="deductionPercent != null">deduction_percentage,</if>
            <if test="amountDecimal != null">amount_decimal,</if>
            <if test="legalPerson != null">legal_person,</if>
            <if test="licenseNo != null">license_no,</if>
            <if test="taxNo != null">tax_no,</if>
            <if test="orderKind != null">order_kind,</if>
            <if test="remark != null">remark,</if>
            <if test="enableFlag != null">enable_flag,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="clientCode != null">#{clientCode},</if>
            <if test="sapClientCode != null">#{sapClientCode},</if>
            <if test="clientName != null">#{clientName},</if>
            <if test="clientNick != null">#{clientNick},</if>
            <if test="clientEn != null">#{clientEn},</if>
            <if test="clientEnAbbr != null">#{clientEnAbbr},</if>
            <if test="clientLevel != null">#{clientLevel},</if>
            <if test="billLevel != null">#{billLevel},</if>
            <if test="invoiceAddr != null">#{invoiceAddr},</if>
            <if test="address != null">#{address},</if>
            <if test="region != null">#{region},</if>
            <if test="country != null">#{country},</if>
            <if test="city != null">#{city},</if>
            <if test="area != null">#{area},</if>
            <if test="lang != null">#{lang},</if>
            <if test="postcode != null">#{postcode},</if>
            <if test="tel != null">#{tel},</if>
            <if test="phone != null">#{phone},</if>
            <if test="email != null">#{email},</if>
            <if test="isClientWaybill != null">#{isClientWaybill},</if>
            <if test="stampMode != null">#{stampMode},</if>
            <if test="requisition != null">#{requisition},</if>
            <if test="clientForm != null">#{clientForm},</if>
            <if test="orderRequest != null">#{orderRequest},</if>
            <if test="receiptRequest != null">#{receiptRequest},</if>
            <if test="clientCheckRequest != null">#{clientCheckRequest},</if>
            <if test="requestSignReceipt != null">#{requestSignReceipt},</if>
            <if test="isPrintDate != null">#{isPrintDate},</if>
            <if test="noInvoice != null">#{noInvoice},</if>
            <if test="paymentRequest != null">#{paymentRequest},</if>
            <if test="clientWorkTime != null">#{clientWorkTime},</if>
            <if test="signRequest != null">#{signRequest},</if>
            <if test="billPrintRequest != null">#{billPrintRequest},</if>
            <if test="membershipGroup != null">#{membershipGroup},</if>
            <if test="qcReportType != null">#{qcReportType},</if>
            <if test="receiptSigningMethod != null">#{receiptSigningMethod},</if>
            <if test="shippingMethod != null">#{shippingMethod},</if>
            <if test="path != null">#{path},</if>
            <if test="billPrintSetting != null">#{billPrintSetting},</if>
            <if test="billExceptionDeadline != null">#{billExceptionDeadline},</if>
            <if test="sendMode != null">#{sendMode},</if>
            <if test="settleMode != null">#{settleMode},</if>
            <if test="paymentDeadline != null">#{paymentDeadline},</if>
            <if test="accountingDeadline != null">#{accountingDeadline},</if>
            <if test="collectionDeadline != null">#{collectionDeadline},</if>
            <if test="orderExceptionDeadline != null">#{orderExceptionDeadline},</if>
            <if test="deductionPercent != null">#{deductionPercent},</if>
            <if test="amountDecimal != null">#{amountDecimal},</if>
            <if test="legalPerson != null">#{legalPerson},</if>
            <if test="licenseNo != null">#{licenseNo},</if>
            <if test="taxNo != null">#{taxNo},</if>
            <if test="orderKind != null">#{orderKind},</if>
            <if test="remark != null">#{remark},</if>
            <if test="enableFlag != null">#{enableFlag},</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>
        </trim>
    </insert>

    <update id="updateMdClient" parameterType="MdClient">
        update md_client
        <trim prefix="SET" suffixOverrides=",">
            <if test="clientCode != null">client_code = #{clientCode},</if>
            <if test="sapClientCode != null">sap_client_code = #{sapClientCode},</if>
            <if test="clientName != null">client_name = #{clientName},</if>
            <if test="clientNick != null">client_nick = #{clientNick},</if>
            <if test="clientEn != null">client_en = #{clientEn},</if>
            <if test="clientEnAbbr != null">client_en_abbr = #{clientEnAbbr},</if>
            <if test="clientLevel != null">client_level = #{clientLevel},</if>
            <if test="billLevel != null">bill_level = #{billLevel},</if>
            <if test="invoiceAddr != null">invoice_addr = #{invoiceAddr},</if>
            <if test="address != null">address = #{address},</if>
            <if test="region != null">region = #{region},</if>
            <if test="country != null">country = #{country},</if>
            <if test="city != null">city = #{city},</if>
            <if test="area != null">area = #{area},</if>
            <if test="lang != null">lang = #{lang},</if>
            <if test="postcode != null">postcode = #{postcode},</if>
            <if test="tel != null">tel = #{tel},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="email != null">email = #{email},</if>
            <if test="isClientWaybill != null">is_client_waybill = #{isClientWaybill},</if>
            <if test="stampMode != null">stamp_mode = #{stampMode},</if>
            <if test="requisition != null">requisition = #{requisition},</if>
            <if test="clientForm != null">client_form = #{clientForm},</if>
            <if test="orderRequest != null">order_request = #{orderRequest},</if>
            <if test="receiptRequest != null">receipt_request = #{receiptRequest},</if>
            <if test="clientCheckRequest != null">client_check_request = #{clientCheckRequest},</if>
            <if test="requestSignReceipt != null">request_sign_receipt = #{requestSignReceipt},</if>
            <if test="isPrintDate != null">is_print_date = #{isPrintDate},</if>
            <if test="noInvoice != null">is_no_invoice = #{noInvoice},</if>
            <if test="paymentRequest != null">payment_request = #{paymentRequest},</if>
            <if test="clientWorkTime != null">client_work_time = #{clientWorkTime},</if>
            <if test="signRequest != null">sign_request = #{signRequest},</if>
            <if test="billPrintRequest != null">bill_print_request = #{billPrintRequest},</if>
            <if test="membershipGroup != null">membership_group = #{membershipGroup},</if>
            <if test="qcReportType != null">qc_report_type = #{qcReportType},</if>
            <if test="receiptSigningMethod != null">receipt_signing_method = #{receiptSigningMethod},</if>
            <if test="shippingMethod != null">shipping_method = #{shippingMethod},</if>
            <if test="path != null">path = #{path},</if>
            <if test="billPrintSetting != null">bill_print_setting = #{billPrintSetting},</if>
            <if test="billExceptionDeadline != null">bill_exception_deadline = #{billExceptionDeadline},</if>
            <if test="sendMode != null">send_mode = #{sendMode},</if>
            <if test="settleMode != null">settle_mode = #{settleMode},</if>
            <if test="paymentDeadline != null">payment_deadline = #{paymentDeadline},</if>
            <if test="accountingDeadline != null">accounting_deadline = #{accountingDeadline},</if>
            <if test="collectionDeadline != null">collection_deadline = #{collectionDeadline},</if>
            <if test="orderExceptionDeadline != null">order_exception_deadline = #{orderExceptionDeadline},</if>
            <if test="deductionPercent != null">deduction_percentage = #{deductionPercent},</if>
            <if test="amountDecimal != null">amount_decimal = #{amountDecimal},</if>
            <if test="legalPerson != null">legal_person = #{legalPerson},</if>
            <if test="licenseNo != null">license_no = #{licenseNo},</if>
            <if test="taxNo != null">tax_no = #{taxNo},</if>
            <if test="orderKind != null">order_kind = #{orderKind},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="enableFlag != null">enable_flag = #{enableFlag},</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>
        </trim>
        where client_id = #{clientId}
    </update>

    <delete id="deleteMdClientByClientId" parameterType="Long">
        delete from md_client where client_id = #{clientId}
    </delete>

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