<?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.ruoyi.info.collection.mapper.CcdiEnterpriseBaseInfoMapper">

    <resultMap id="CcdiEnterpriseBaseInfoVoResultMap" type="com.ruoyi.info.collection.domain.vo.CcdiEnterpriseBaseInfoVO">
        <id property="socialCreditCode" column="social_credit_code"/>
        <result property="enterpriseName" column="enterprise_name"/>
        <result property="enterpriseType" column="enterprise_type"/>
        <result property="enterpriseNature" column="enterprise_nature"/>
        <result property="industryClass" column="industry_class"/>
        <result property="industryName" column="industry_name"/>
        <result property="establishDate" column="establish_date"/>
        <result property="registerAddress" column="register_address"/>
        <result property="legalRepresentative" column="legal_representative"/>
        <result property="legalCertType" column="legal_cert_type"/>
        <result property="legalCertNo" column="legal_cert_no"/>
        <result property="shareholder1" column="shareholder1"/>
        <result property="shareholder2" column="shareholder2"/>
        <result property="shareholder3" column="shareholder3"/>
        <result property="shareholder4" column="shareholder4"/>
        <result property="shareholder5" column="shareholder5"/>
        <result property="status" column="status"/>
        <result property="riskLevel" column="risk_level"/>
        <result property="entSource" column="ent_source"/>
        <result property="dataSource" column="data_source"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

    <select id="selectEnterpriseBaseInfoPage" resultMap="CcdiEnterpriseBaseInfoVoResultMap">
        SELECT
            social_credit_code,
            enterprise_name,
            enterprise_type,
            enterprise_nature,
            industry_class,
            industry_name,
            establish_date,
            register_address,
            legal_representative,
            legal_cert_type,
            legal_cert_no,
            shareholder1,
            shareholder2,
            shareholder3,
            shareholder4,
            shareholder5,
            status,
            risk_level,
            ent_source,
            data_source,
            create_time
        FROM ccdi_enterprise_base_info
        <where>
            <if test="queryDTO != null and queryDTO.enterpriseName != null and queryDTO.enterpriseName != ''">
                AND enterprise_name LIKE CONCAT('%', #{queryDTO.enterpriseName}, '%')
            </if>
            <if test="queryDTO != null and queryDTO.socialCreditCode != null and queryDTO.socialCreditCode != ''">
                AND social_credit_code = #{queryDTO.socialCreditCode}
            </if>
            <if test="queryDTO != null and queryDTO.enterpriseType != null and queryDTO.enterpriseType != ''">
                AND enterprise_type = #{queryDTO.enterpriseType}
            </if>
            <if test="queryDTO != null and queryDTO.enterpriseNature != null and queryDTO.enterpriseNature != ''">
                AND enterprise_nature = #{queryDTO.enterpriseNature}
            </if>
            <if test="queryDTO != null and queryDTO.industryClass != null and queryDTO.industryClass != ''">
                AND industry_class LIKE CONCAT('%', #{queryDTO.industryClass}, '%')
            </if>
            <if test="queryDTO != null and queryDTO.status != null and queryDTO.status != ''">
                AND status = #{queryDTO.status}
            </if>
            <if test="queryDTO != null and queryDTO.riskLevel != null and queryDTO.riskLevel != ''">
                AND risk_level = #{queryDTO.riskLevel}
            </if>
            <if test="queryDTO != null and queryDTO.entSource != null and queryDTO.entSource != ''">
                AND ent_source = #{queryDTO.entSource}
            </if>
        </where>
        ORDER BY create_time DESC
    </select>

    <!-- 批量插入实体中介 -->
    <insert id="insertBatch" parameterType="java.util.List">
        INSERT INTO ccdi_enterprise_base_info (
            social_credit_code, enterprise_name, enterprise_type, enterprise_nature,
            industry_class, industry_name, establish_date, register_address,
            legal_representative, legal_cert_type, legal_cert_no,
            shareholder1, shareholder2, shareholder3, shareholder4, shareholder5,
            status, risk_level, ent_source, data_source,
            created_by, updated_by, create_time, update_time
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
                #{item.socialCreditCode}, #{item.enterpriseName}, #{item.enterpriseType}, #{item.enterpriseNature},
                #{item.industryClass}, #{item.industryName}, #{item.establishDate}, #{item.registerAddress},
                #{item.legalRepresentative}, #{item.legalCertType}, #{item.legalCertNo},
                #{item.shareholder1}, #{item.shareholder2}, #{item.shareholder3}, #{item.shareholder4}, #{item.shareholder5},
                #{item.status}, #{item.riskLevel}, #{item.entSource}, #{item.dataSource},
                #{item.createdBy}, #{item.updatedBy}, NOW(), NOW()
            )
        </foreach>
    </insert>

    <!-- 批量导入实体中介数据(存在则更新,不存在则插入) -->
    <insert id="importEntityBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO ccdi_enterprise_base_info (
            social_credit_code, enterprise_name, enterprise_type, enterprise_nature,
            industry_class, industry_name, establish_date, register_address,
            legal_representative, legal_cert_type, legal_cert_no,
            shareholder1, shareholder2, shareholder3, shareholder4, shareholder5,
            status, risk_level, ent_source, data_source,
            created_by, updated_by, create_time, update_time
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
                #{item.socialCreditCode}, #{item.enterpriseName}, #{item.enterpriseType}, #{item.enterpriseNature},
                #{item.industryClass}, #{item.industryName}, #{item.establishDate}, #{item.registerAddress},
                #{item.legalRepresentative}, #{item.legalCertType}, #{item.legalCertNo},
                #{item.shareholder1}, #{item.shareholder2}, #{item.shareholder3}, #{item.shareholder4}, #{item.shareholder5},
                #{item.status}, #{item.riskLevel}, #{item.entSource}, #{item.dataSource},
                #{item.createdBy}, #{item.updatedBy}, NOW(), NOW()
            )
        </foreach>
        ON DUPLICATE KEY UPDATE
            enterprise_name = VALUES(enterprise_name),
            enterprise_type = VALUES(enterprise_type),
            enterprise_nature = VALUES(enterprise_nature),
            industry_class = VALUES(industry_class),
            industry_name = VALUES(industry_name),
            establish_date = VALUES(establish_date),
            register_address = VALUES(register_address),
            legal_representative = VALUES(legal_representative),
            legal_cert_type = VALUES(legal_cert_type),
            legal_cert_no = VALUES(legal_cert_no),
            shareholder1 = VALUES(shareholder1),
            shareholder2 = VALUES(shareholder2),
            shareholder3 = VALUES(shareholder3),
            shareholder4 = VALUES(shareholder4),
            shareholder5 = VALUES(shareholder5),
            status = VALUES(status),
            risk_level = VALUES(risk_level),
            ent_source = VALUES(ent_source),
            data_source = VALUES(data_source),
            updated_by = VALUES(updated_by),
            update_time = NOW()
    </insert>

    <!-- 批量更新实体中介 -->
    <update id="updateBatch" parameterType="java.util.List">
        <foreach collection="list" item="item" separator=";">
            UPDATE ccdi_enterprise_base_info
            <set>
                <if test="item.enterpriseName != null and item.enterpriseName != ''">enterprise_name = #{item.enterpriseName},</if>
                <if test="item.enterpriseType != null">enterprise_type = #{item.enterpriseType},</if>
                <if test="item.enterpriseNature != null">enterprise_nature = #{item.enterpriseNature},</if>
                <if test="item.industryClass != null">industry_class = #{item.industryClass},</if>
                <if test="item.industryName != null">industry_name = #{item.industryName},</if>
                <if test="item.establishDate != null">establish_date = #{item.establishDate},</if>
                <if test="item.registerAddress != null">register_address = #{item.registerAddress},</if>
                <if test="item.legalRepresentative != null">legal_representative = #{item.legalRepresentative},</if>
                <if test="item.legalCertType != null">legal_cert_type = #{item.legalCertType},</if>
                <if test="item.legalCertNo != null">legal_cert_no = #{item.legalCertNo},</if>
                <if test="item.shareholder1 != null">shareholder1 = #{item.shareholder1},</if>
                <if test="item.shareholder2 != null">shareholder2 = #{item.shareholder2},</if>
                <if test="item.shareholder3 != null">shareholder3 = #{item.shareholder3},</if>
                <if test="item.shareholder4 != null">shareholder4 = #{item.shareholder4},</if>
                <if test="item.shareholder5 != null">shareholder5 = #{item.shareholder5},</if>
                <if test="item.status != null">status = #{item.status},</if>
                <if test="item.riskLevel != null">risk_level = #{item.riskLevel},</if>
                <if test="item.entSource != null">ent_source = #{item.entSource},</if>
                <if test="item.dataSource != null">data_source = #{item.dataSource},</if>
                <if test="item.updatedBy != null">updated_by = #{item.updatedBy},</if>
                update_time = NOW()
            </set>
            WHERE social_credit_code = #{item.socialCreditCode}
        </foreach>
    </update>

</mapper>
