<?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.ImporterEntityMapper">


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id
        ,
        deleted,
        gmt_create,
        gmt_modified,
        customer_user_id, entity_no, region, country, `status`, entity_name, cert_type, cert_no, business_province, business_city, business_address, business_post_code, contact_direct_ind,
        contact_name, contact_mobile, contact_email, vat_no
    </sql>

    <!-- 根据证件号查询企业相关信息 -->
    <select id="getByUserIdAndCertNo" resultType="com.trade.service.companyrelated.domain.ImporterEntity">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        importer_entity
        WHERE
        customer_user_id = #{customerUserId}
        and cert_no = #{certNo}
        and deleted = 0
    </select>

    <select id="queryListBySearch" parameterType="com.trade.service.companyrelated.domain.vo.ImporterEntitySearch"
            resultType="com.trade.service.companyrelated.domain.ImporterEntity">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        importer_entity
        WHERE
        deleted = 0
        <if test="customerUserId!= null and customerUserId!= ''">
            and customer_user_id = #{customerUserId}
        </if>
        <if test="region!= null and region!= ''">
            and region = #{region}
        </if>
        <if test="country!= null and country!= ''">
            and country = #{country}
        </if>
        <if test="status!= null and status!= ''">
            and status = #{status}
        </if>
        <if test="entityName!= null and entityName!= ''">
            and entity_name like CONCAT('%', #{entityName}, '%')
        </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>
