<?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.gxwebsoft.credit.mapper.CreditNearbyCompanyMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*, b.match_name AS companyName, u.real_name AS realName
        FROM credit_nearby_company a
        LEFT JOIN credit_company b ON a.company_id = b.id
        LEFT JOIN gxwebsoft_core.sys_user u ON a.user_id = u.user_id
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.name != null">
                AND a.name LIKE CONCAT('%', #{param.name}, '%')
            </if>
            <if test="param.companyId != null">
              AND a.company_id = #{param.companyId}
            </if>
            <if test="param.registrationStatus != null">
                AND a.registration_status LIKE CONCAT('%', #{param.registrationStatus}, '%')
            </if>
            <if test="param.legalPerson != null">
                AND a.legal_person LIKE CONCAT('%', #{param.legalPerson}, '%')
            </if>
            <if test="param.registeredCapital != null">
                AND a.registered_capital LIKE CONCAT('%', #{param.registeredCapital}, '%')
            </if>
            <if test="param.establishDate != null">
                AND a.establish_date LIKE CONCAT('%', #{param.establishDate}, '%')
            </if>
            <if test="param.code != null">
                AND a.code LIKE CONCAT('%', #{param.code}, '%')
            </if>
            <if test="param.address != null">
                AND a.address LIKE CONCAT('%', #{param.address}, '%')
            </if>
            <if test="param.postalCode != null">
                AND a.postal_code LIKE CONCAT('%', #{param.postalCode}, '%')
            </if>
            <if test="param.phone != null">
                AND a.phone LIKE CONCAT('%', #{param.phone}, '%')
            </if>
            <if test="param.moreTel != null">
                AND a.more_tel LIKE CONCAT('%', #{param.moreTel}, '%')
            </if>
            <if test="param.email != null">
                AND a.email LIKE CONCAT('%', #{param.email}, '%')
            </if>
            <if test="param.moreEmail != null">
                AND a.more_email LIKE CONCAT('%', #{param.moreEmail}, '%')
            </if>
            <if test="param.country != null">
                AND a.country LIKE CONCAT('%', #{param.country}, '%')
            </if>
            <if test="param.province != null">
                AND a.province LIKE CONCAT('%', #{param.province}, '%')
            </if>
            <if test="param.city != null">
                AND a.city LIKE CONCAT('%', #{param.city}, '%')
            </if>
            <if test="param.region != null">
                AND a.region LIKE CONCAT('%', #{param.region}, '%')
            </if>
<!--            <if test="param.taxpayerCode != null">-->
<!--                AND a.taxpayer_code LIKE CONCAT('%', #{param.taxpayerCode}, '%')-->
<!--            </if>-->
            <if test="param.registrationNumber != null">
                AND a.registration_number LIKE CONCAT('%', #{param.registrationNumber}, '%')
            </if>
            <if test="param.organizationalCode != null">
                AND a.organizational_code LIKE CONCAT('%', #{param.organizationalCode}, '%')
            </if>
            <if test="param.numberOfInsuredPersons != null">
                AND a.number_of_insured_persons LIKE CONCAT('%', #{param.numberOfInsuredPersons}, '%')
            </if>
            <if test="param.annualReport != null">
                AND a.annual_report LIKE CONCAT('%', #{param.annualReport}, '%')
            </if>
            <if test="param.institutionType != null">
                AND a.institution_type LIKE CONCAT('%', #{param.institutionType}, '%')
            </if>
            <if test="param.companySize != null">
                AND a.company_size LIKE CONCAT('%', #{param.companySize}, '%')
            </if>
            <if test="param.businessTerm != null">
                AND a.business_term LIKE CONCAT('%', #{param.businessTerm}, '%')
            </if>
            <if test="param.nationalStandardIndustryCategories != null">
                AND a.national_standard_industry_categories LIKE CONCAT('%', #{param.nationalStandardIndustryCategories}, '%')
            </if>
            <if test="param.nationalStandardIndustryCategories2 != null">
                AND a.national_standard_industry_categories2 LIKE CONCAT('%', #{param.nationalStandardIndustryCategories2}, '%')
            </if>
            <if test="param.nationalStandardIndustryCategories3 != null">
                AND a.national_standard_industry_categories3 LIKE CONCAT('%', #{param.nationalStandardIndustryCategories3}, '%')
            </if>
            <if test="param.nationalStandardIndustryCategories4 != null">
                AND a.national_standard_industry_categories4 LIKE CONCAT('%', #{param.nationalStandardIndustryCategories4}, '%')
            </if>
            <if test="param.formerName != null">
                AND a.former_name LIKE CONCAT('%', #{param.formerName}, '%')
            </if>
            <if test="param.englishName != null">
                AND a.english_name LIKE CONCAT('%', #{param.englishName}, '%')
            </if>
            <if test="param.domain != null">
                AND a.domain LIKE CONCAT('%', #{param.domain}, '%')
            </if>
            <if test="param.mailingAddress != null">
                AND a.mailing_address LIKE CONCAT('%', #{param.mailingAddress}, '%')
            </if>
            <if test="param.mailingEmail != null">
                AND a.mailing_email LIKE CONCAT('%', #{param.mailingEmail}, '%')
            </if>
            <if test="param.companyProfile != null">
                AND a.company_profile LIKE CONCAT('%', #{param.companyProfile}, '%')
            </if>
            <if test="param.natureOfBusiness != null">
                AND a.nature_of_business LIKE CONCAT('%', #{param.natureOfBusiness}, '%')
            </if>
            <if test="param.tel != null">
                AND a.tel LIKE CONCAT('%', #{param.tel}, '%')
            </if>
            <if test="param.nationalStandardIndustryCategories5 != null">
                AND a.national_standard_industry_categories5 LIKE CONCAT('%', #{param.nationalStandardIndustryCategories5}, '%')
            </if>
            <if test="param.nationalStandardIndustryCategories6 != null">
                AND a.national_standard_industry_categories6 LIKE CONCAT('%', #{param.nationalStandardIndustryCategories6}, '%')
            </if>
            <if test="param.nationalStandardIndustryCategories7 != null">
                AND a.national_standard_industry_categories7 LIKE CONCAT('%', #{param.nationalStandardIndustryCategories7}, '%')
            </if>
            <if test="param.nationalStandardIndustryCategories8 != null">
                AND a.national_standard_industry_categories8 LIKE CONCAT('%', #{param.nationalStandardIndustryCategories8}, '%')
            </if>
            <if test="param.url != null">
                AND a.url LIKE CONCAT('%', #{param.url}, '%')
            </if>
            <if test="param.type != null">
                AND a.type = #{param.type}
            </if>
            <if test="param.parentId != null">
                AND a.parent_id = #{param.parentId}
            </if>
            <if test="param.paidinCapital != null">
                AND a.paidin_capital LIKE CONCAT('%', #{param.paidinCapital}, '%')
            </if>
            <if test="param.registrationAuthority != null">
                AND a.registration_authority LIKE CONCAT('%', #{param.registrationAuthority}, '%')
            </if>
            <if test="param.taxpayerQualification != null">
                AND a.taxpayer_qualification LIKE CONCAT('%', #{param.taxpayerQualification}, '%')
            </if>
            <if test="param.latestAnnualReportYear != null">
                AND a.latest_annual_report_year LIKE CONCAT('%', #{param.latestAnnualReportYear}, '%')
            </if>
            <if test="param.latestAnnualReportOnOperatingRevenue != null">
                AND a.latest_annual_report_on_operating_revenue LIKE CONCAT('%', #{param.latestAnnualReportOnOperatingRevenue}, '%')
            </if>
            <if test="param.enterpriseScoreCheck != null">
                AND a.enterprise_score_check LIKE CONCAT('%', #{param.enterpriseScoreCheck}, '%')
            </if>
            <if test="param.creditRating != null">
                AND a.credit_rating LIKE CONCAT('%', #{param.creditRating}, '%')
            </if>
            <if test="param.cechnologyScore != null">
                AND a.cechnology_score LIKE CONCAT('%', #{param.cechnologyScore}, '%')
            </if>
            <if test="param.cechnologyLevel != null">
                AND a.cechnology_level LIKE CONCAT('%', #{param.cechnologyLevel}, '%')
            </if>
            <if test="param.smallEnterprise != null">
                AND a.small_enterprise LIKE CONCAT('%', #{param.smallEnterprise}, '%')
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.recommend != null">
                AND a.recommend = #{param.recommend}
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
            <if test="param.keywords != null">
                AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
                  OR a.name = #{param.keywords}
                  OR b.name LIKE CONCAT('%', #{param.keywords}, '%')
                )
              </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.credit.entity.CreditNearbyCompany">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.credit.entity.CreditNearbyCompany">
        <include refid="selectSql"></include>
    </select>

</mapper>
