<?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="cn.ezhizao.project.business.mapper.BizSupplierMapper">

    <resultMap type="cn.ezhizao.project.business.domain.BizSupplier" id="BizSupplierResult">
        <id column="id" property="id"/>
    </resultMap>

    <select id="getList" resultMap="BizSupplierResult" parameterType="cn.ezhizao.project.business.domain.BizSupplier">
        SELECT t1.*,
        ( SELECT biz_supplier_contacts.name
        FROM biz_supplier_contacts
        WHERE t1.id = biz_supplier_contacts.supplier_id
        AND biz_supplier_contacts.is_default = 1
        AND biz_supplier_contacts.deleted = 0
        LIMIT 1
        ) AS contact_name,
        ( SELECT biz_supplier_contacts.phone_number
        FROM biz_supplier_contacts
        WHERE t1.id = biz_supplier_contacts.supplier_id
        AND biz_supplier_contacts.is_default = 1
        AND biz_supplier_contacts.deleted = 0
        LIMIT 1
        ) AS contact_phone_number
        FROM biz_supplier t1
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            t1.deleted = 0
            <if test="tenantId != null and tenantId != 0"> AND t1.tenant_id = #{tenantId}</if>
            <if test="name != null and name != ''"> AND t1.name LIKE CONCAT('%', #{name}, '%')</if>
            <if test="mnemonicCode != null and mnemonicCode != ''"> AND t1.mnemonic_code LIKE CONCAT('%', #{mnemonicCode}, '%')</if>
            <if test="code != null and code != ''"> AND t1.code LIKE CONCAT('%', #{code}, '%')</if>

        </trim>

    </select>

    <delete id="physicalDelete">
        DELETE FROM biz_supplier
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
       <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>
</mapper>
