<?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.trade.service.companyrelated.mapper.VendorEntityMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.trade.service.companyrelated.domain.VendorEntity">
        <result column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="customer_user_id" property="customerUserId" />
        <result column="entity_no" property="entityNo" />
        <result column="entity_name" property="entityName" />
        <result column="contact_name" property="contactName" />
        <result column="contact_cert_no" property="contactCertNo" />
        <result column="contact_mobile" property="contactMobile" />
        <result column="contact_email" property="contactEmail" />
        <result column="acct_name" property="acctName" />
        <result column="acct_no" property="acctNo" />
        <result column="acct_open_bank" property="acctOpenBank" />
        <result column="gmt_create" property="gmtCreate" />
        <result column="gmt_modified" property="gmtModified" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        deleted,
        customer_user_id, entity_no, entity_name, contact_name, contact_cert_no, contact_mobile, contact_email, acct_name, acct_no, acct_open_bank, gmt_create, gmt_modified
    </sql>

    <select id="getByUserIdAndEntityName" resultType="com.trade.service.companyrelated.domain.VendorEntity">
    SELECT
    <include refid="Base_Column_List"/>
    FROM
        vendor_entity
    WHERE
        customer_user_id = #{customerUserId}
    and entity_name = #{entityName}
    and deleted = 0
</select>


    <select id="queryListBySearch" parameterType="com.trade.service.companyrelated.domain.vo.VendorEntitySearch"
            resultType="com.trade.service.companyrelated.domain.VendorEntity">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        vendor_entity
        WHERE
        deleted = 0
        <if test="userId!= null and userId!= ''">
            and user_id = #{userId}
        </if>
        <if test="entityName!= null and entityName!= ''">
            and entity_name like CONCAT('%', #{entityName}, '%')
        </if>
        <if test="entityNo!= null and entityNo!= ''">
            and entity_no = #{entityNo}
        </if>
        <if test="createdTimeStart!= null">
            and gmt_create &gt;= #{createdTimeStart}
        </if>
        <if test="createdTimeEnd!= null">
            AND gmt_create &lt; DATE_FORMAT(DATE_ADD(#{createdTimeEnd},INTERVAL 1 DAY),'%Y-%m-%d')
        </if>
    </select>

</mapper>
