<?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.enterprise.companyrelated.mapper.BizEntityRelatedMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.trade.service.enterprise.companyrelated.domain.BizEntityRelated">
        <result column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="gmt_create" property="gmtCreate" />
        <result column="gmt_modified" property="gmtModified" />
        <result column="user_id" property="userId" />
        <result column="relate_type" property="relateType" />
        <result column="country" property="country" />
        <result column="status" property="status" />
        <result column="entity_type" property="entityType" />
        <result column="entity_name" property="entityName" />
        <result column="cert_no" property="certNo" />
        <result column="establish_date" property="establishDate" />
        <result column="registered_capital" property="registeredCapital" />
        <result column="industry" property="industry" />
        <result column="registered_address" property="registeredAddress" />
        <result column="business_address" property="businessAddress" />
        <result column="business_category" property="businessCategory" />
        <result column="cooperate_from" property="cooperateFrom" />
        <result column="cooperate_length" property="cooperateLength" />
        <result column="cooperate_unit" property="cooperateUnit" />
        <result column="contact_name" property="contactName" />
        <result column="contact_id_no" property="contactIdNo" />
        <result column="contact_mobile" property="contactMobile" />
        <result column="contact_email" property="contactEmail" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        deleted,
        gmt_create,
        gmt_modified,
        user_id, relate_type, country, `status`, entity_type, entity_name, cert_no, establish_date, registered_capital, industry, registered_address, business_address, business_category, cooperate_from, cooperate_length, cooperate_unit, contact_name, contact_id_no, contact_mobile, contact_email
    </sql>

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

    <select id="queryListBySearch" resultType="com.trade.service.enterprise.companyrelated.domain.BizEntityRelated">
        SELECT
        <include refid="Base_Column_List" />
        FROM
        biz_entity_related
        WHERE
            deleted = 0
        <if test="userId!= null and userId!= ''">
            and user_id = #{userId}
        </if>
        <if test="relateType!= null and relateType!= ''">
            and relate_type = #{relateType}
        </if>
        <if test="country!= null and country!= ''">
            and country = #{country}
        </if>
        <if test="entityType!= null and entityType!= ''">
            and entity_type = #{entityType}
        </if>
        <if test="entityName!= null and entityName!= ''">
            and entity_name like CONCAT('%', #{entityName}, '%')
        </if>
        <if test="modifiedTimeStart!= null">
            and gmt_modified &gt;= #{modifiedTimeStart}
        </if>
        <if test="modifiedTimeEnd!= null">
            AND gmt_create &lt; DATE_FORMAT(DATE_ADD(#{modifiedTimeEnd},INTERVAL 1 DAY),'%Y-%m-%d')
        </if>
    </select>

</mapper>
