<?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.tradingPlatform.mapper.TradingPlatformMapper">

    <resultMap type="com.trade.service.tradingPlatform.domain.TradingPlatform" id="TradingPlatformMap">
        <result property="id" column="id"/>
        <result property="platformName" column="platform_name"/>
        <result property="platformCode" column="platform_code"/>
        <result property="districtCode" column="district_code"/>
        <result property="establishDate" column="establish_date"/>
        <result property="certNo" column="cert_no"/>
        <result property="legalName" column="legal_name"/>
        <result property="registerAddress" column="register_address"/>
        <result property="businessAddress" column="business_address"/>
        <result property="contactName" column="contact_name"/>
        <result property="contactEmail" column="contact_email"/>
        <result property="contactMobile" column="contact_mobile"/>
        <result property="taxNum" column="tax_num"/>
        <result property="bankName" column="bank_name"/>
        <result property="bankNum" column="bank_num"/>
        <result property="hasSinosureInsurance" column="has_sinosure_insurance"/>
        <result property="remark" column="remark"/>
        <result property="deleted" column="deleted"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
        <result property="gmtCreate" column="gmt_create"/>
        <result property="gmtModified" column="gmt_modified"/>
    </resultMap>

    <sql id="Base_Column_List">
        `id`, `platform_name`, `platform_code`, `district_code`, `establish_date`, `cert_no`,
        `legal_name`, `register_address`, `business_address`, `contact_name`, `contact_email`,
        `contact_mobile`, `tax_num`, `bank_name`, `bank_num`, `has_sinosure_insurance`, `remark`,
        `deleted`, `create_by`, `update_by`, `gmt_create`, `gmt_modified`
    </sql>

    <resultMap type="com.trade.service.tradingPlatform.dto.TradingPlatformBaseInfo"
               id="tradingPlatformBaseInfoResultMap">
        <result property="platformId" column="platform_id"/>
        <result property="platformName" column="platform_name"/>
        <result property="platformCode" column="platform_code"/>
        <result property="districtCode" column="district_code"/>
        <result property="establishDate" column="establish_date"/>
        <result property="hasSinosureInsurance" column="has_sinosure_insurance"/>
        <result property="hasImportExportQualification" column="has_import_export_qualification"/>
        <result property="hasExportAgentQualify" column="has_export_agent_qualify"/>
        <result property="gmtModified" column="gmt_modified"/>
    </resultMap>

    <select id="findBySearch" resultMap="tradingPlatformBaseInfoResultMap">
        SELECT platform.id AS platform_id, platform.platform_name, platform.platform_code, platform.district_code,
        platform.establish_date , platform.has_sinosure_insurance,qualification.has_import_export_qualification,
        qualification.has_export_agent_qualify ,qualification.gmt_modified
        FROM trading_platform platform
        LEFT JOIN trading_platform_qualification qualification ON qualification.platform_id = platform.id
        WHERE platform.deleted = 0
        <if test="platformName!= null and platformName!= ''">
            AND platform.platform_name LIKE CONCAT('%', #{platformName}, '%')
        </if>
        <if test="platformCode!= null and platformCode!= ''">
            AND platform.platform_code = #{platformCode}
        </if>
        <if test="districtCode!= null and districtCode!= ''">
            AND platform.district_code = #{districtCode}
        </if>
        <if test="hasSinosureInsurance!= null and hasSinosureInsurance!= ''">
            AND qualification.has_sinosure_insurance = #{hasSinosureInsurance}
        </if>
        <if test="hasImportExportQualification!= null and hasImportExportQualification!= ''">
            AND qualification.has_import_export_qualification = #{hasImportExportQualification}
        </if>
        <if test="hasExportAgentQualify!= null and hasExportAgentQualify!= ''">
            AND qualification.has_export_agent_qualify = #{hasExportAgentQualify}
        </if>
        <if test="updateStartDate != null">
            <![CDATA[ AND DATE_FORMAT(platform.gmt_modified, '%Y-%m-%d')>=  DATE_FORMAT(#{updateStartDate}, '%Y-%m-%d') ]]>
        </if>
        <if test="updateEndDate != null">
            <![CDATA[ AND DATE_FORMAT(platform.gmt_modified, '%Y-%m-%d')<=  DATE_FORMAT(#{updateEndDate}, '%Y-%m-%d') ]]>
        </if>
        ORDER BY platform.gmt_modified DESC
    </select>


</mapper>

