<?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.nantian.cloud.jljc.mapper.TReportEnterpriseMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jljc.entity.TReportEnterprise">
        <id column="id" property="id"/>
        <result column="enterprise_code" property="enterpriseCode"/>
        <result column="year" property="year"/>
        <result column="enterprise_name" property="enterpriseName"/>
        <result column="password" property="password"/>
        <result column="field" property="field"/>
        <result column="parea" property="parea"/>
        <result column="area" property="area"/>
        <result column="ptrade" property="ptrade"/>
        <result column="trade" property="trade"/>
        <result column="enterprise_type" property="enterpriseType"/>
        <result column="corporation_name" property="corporationName"/>
        <result column="corporation_unit_code" property="corporationUnitCode"/>
        <result column="register_date" property="registerDate"/>
        <result column="register_principal" property="registerPrincipal"/>
        <result column="telephone" property="telephone"/>
        <result column="center" property="center"/>
        <result column="center_name" property="centerName"/>
        <result column="address" property="address"/>
        <result column="geographical_coordinates" property="geographicalCoordinates"/>
        <result column="website" property="website"/>
        <result column="zip_code" property="zipCode"/>
        <result column="region_code" property="regionCode"/>
        <result column="email" property="email"/>
        <result column="energy_control_name" property="energyControlName"/>
        <result column="fax" property="fax"/>
        <result column="leader" property="leader"/>
        <result column="leader_tel" property="leaderTel"/>
        <result column="leader_job" property="leaderJob"/>
        <result column="icsem" property="icsem"/>
        <result column="icsem_tel" property="icsemTel"/>
        <result column="icsem_train_num" property="icsemTrainNum"/>
        <result column="icsem_certificate" property="icsemCertificate"/>
        <result column="staff" property="staff"/>
        <result column="staff_tel" property="staffTel"/>
        <result column="staff_train_num" property="staffTrainNum"/>
        <result column="certificate" property="certificate"/>
        <result column="processing_link" property="processingLink"/>
        <result column="processing_link_json" property="processingLinkJson"/>
        <result column="certificate_date" property="certificateDate"/>
        <result column="certificate_organ" property="certificateOrgan"/>
        <result column="epc_type" property="epcType"/>
        <result column="del_flag" property="delFlag"/>
        <result column="userid" property="userid"/>
        <result column="update_time" property="updateTime"/>
        <result column="dept_id" property="deptId"/>
        <result column="productinfos" property="productinfos"/>
        <result column="indicators" property="indicators"/>
        <result column="energy_types" property="energyTypes"/>
        <result column="report_id" property="reportId"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, enterprise_code, year, enterprise_name, password, field, parea, area, ptrade, trade, enterprise_type,
         corporation_name, corporation_unit_code, register_date, register_principal, telephone, center, center_name,
         address, geographical_coordinates, website, zip_code, region_code, email, energy_control_name, fax, leader,
         leader_tel, leader_job, icsem, icsem_tel, icsem_train_num, icsem_certificate, staff, staff_tel, staff_train_num,
         certificate, processing_link, processing_link_json, certificate_date, certificate_organ, epc_type, del_flag, userid, update_time,
         dept_id, productinfos, indicators, energy_types, report_id
    </sql>

    <insert id="saveOrUpdateByUniqueKey">
        insert into t_report_enterprise
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test='enterpriseCode != null'>enterprise_code,</if>
            <if test='year != null'>year,</if>
            <if test='enterpriseName != null'>enterprise_name,</if>
            <if test='password != null'>password,</if>
            <if test='field != null'>field,</if>
            <if test='parea != null'>parea,</if>
            <if test='area != null'>area,</if>
            <if test='ptrade != null'>ptrade,</if>
            <if test='trade != null'>trade,</if>
            <if test='enterpriseType != null'>enterprise_type,</if>
            <if test='corporationName != null'>corporation_name,</if>
            <if test='corporationUnitCode != null'>corporation_unit_code,</if>
            <if test='registerDate != null'>register_date,</if>
            <if test='registerPrincipal != null'>register_principal,</if>
            <if test='telephone != null'>telephone,</if>
            <if test='center != null'>center,</if>
            <if test='centerName != null'>center_name,</if>
            <if test='address != null'>address,</if>
            <if test='geographicalCoordinates != null'>geographical_coordinates,</if>
            <if test='website != null'>website,</if>
            <if test='zipCode != null'>zip_code,</if>
            <if test='regionCode != null'>region_code,</if>
            <if test='email != null'>email,</if>
            <if test='energyControlName != null'>energy_control_name,</if>
            <if test='fax != null'>fax,</if>
            <if test='leader != null'>leader,</if>
            <if test='leaderTel != null'>leader_tel,</if>
            <if test='leaderJob != null'>leader_job,</if>
            <if test='icsem != null'>icsem,</if>
            <if test='icsemTel != null'>icsem_tel,</if>
            <if test='icsemTrainNum != null'>icsem_train_num,</if>
            <if test='icsemCertificate != null'>icsem_certificate,</if>
            <if test='staff != null'>staff,</if>
            <if test='staffTel != null'>staff_tel,</if>
            <if test='staffTrainNum != null'>staff_train_num,</if>
            <if test='certificate != null'>certificate,</if>
            <if test='processingLink != null'>processing_link,</if>
            <if test='processingLinkJson != null'>processing_link_json,</if>
            <if test='certificateDate != null'>certificate_date,</if>
            <if test='certificateOrgan != null'>certificate_organ,</if>
            <if test='epcType != null'>epc_type,</if>
            <if test='delFlag != null'>del_flag,</if>
            <if test='userid != null'>userid,</if>
            <if test='updateTime != null'>update_time,</if>
            <if test='deptId != null'>dept_id,</if>
            <if test='productinfos != null'>productinfos,</if>
            <if test='indicators != null'>indicators,</if>
            <if test='energyTypes != null'>energy_types,</if>
            <if test='reportId != null'>report_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test='enterpriseCode != null'>#{enterpriseCode},</if>
            <if test='year != null'>#{year},</if>
            <if test='enterpriseName != null'>#{enterpriseName},</if>
            <if test='password != null'>#{password},</if>
            <if test='field != null'>#{field},</if>
            <if test='parea != null'>#{parea},</if>
            <if test='area != null'>#{area},</if>
            <if test='ptrade != null'>#{ptrade},</if>
            <if test='trade != null'>#{trade},</if>
            <if test='enterpriseType != null'>#{enterpriseType},</if>
            <if test='corporationName != null'>#{corporationName},</if>
            <if test='corporationUnitCode != null'>#{corporationUnitCode},</if>
            <if test='registerDate != null'>#{registerDate},</if>
            <if test='registerPrincipal != null'>#{registerPrincipal},</if>
            <if test='telephone != null'>#{telephone},</if>
            <if test='center != null'>#{center},</if>
            <if test='centerName != null'>#{centerName},</if>
            <if test='address != null'>#{address},</if>
            <if test='geographicalCoordinates != null'>#{geographicalCoordinates},</if>
            <if test='website != null'>#{website},</if>
            <if test='zipCode != null'>#{zipCode},</if>
            <if test='regionCode != null'>#{regionCode},</if>
            <if test='email != null'>#{email},</if>
            <if test='energyControlName != null'>#{energyControlName},</if>
            <if test='fax != null'>#{fax},</if>
            <if test='leader != null'>#{leader},</if>
            <if test='leaderTel != null'>#{leaderTel},</if>
            <if test='leaderJob != null'>#{leaderJob},</if>
            <if test='icsem != null'>#{icsem},</if>
            <if test='icsemTel != null'>#{icsemTel},</if>
            <if test='icsemTrainNum != null'>#{icsemTrainNum},</if>
            <if test='icsemCertificate != null'>#{icsemCertificate},</if>
            <if test='staff != null'>#{staff},</if>
            <if test='staffTel != null'>#{staffTel},</if>
            <if test='staffTrainNum != null'>#{staffTrainNum},</if>
            <if test='certificate != null'>#{certificate},</if>
            <if test='processingLink != null'>#{processingLink},</if>
            <if test='processingLinkJson != null'>#{processingLinkJson},</if>
            <if test='certificateDate != null'>#{certificateDate},</if>
            <if test='certificateOrgan != null'>#{certificateOrgan},</if>
            <if test='epcType != null'>#{epcType},</if>
            <if test='delFlag != null'>#{delFlag},</if>
            <if test='userid != null'>#{userid},</if>
            <if test='updateTime != null'>#{updateTime},</if>
            <if test='deptId != null'>#{deptId},</if>
            <if test='productinfos != null'>#{productinfos},</if>
            <if test='indicators != null'>#{indicators},</if>
            <if test='energyTypes != null'>#{energyTypes},</if>
            <if test='reportId != null'>#{reportId},</if>
        </trim>
        ON duplicate KEY UPDATE
        <trim suffixOverrides=",">
            <if test='enterpriseCode != null'>enterprise_code=#{enterpriseCode},</if>
            <if test='year != null'>year=#{year},</if>
            <if test='enterpriseName != null'>enterprise_name=#{enterpriseName},</if>
            <if test='password != null'>password=#{password},</if>
            <if test='field != null'>field=#{field},</if>
            <if test='parea != null'>parea=#{parea},</if>
            <if test='area != null'>area=#{area},</if>
            <if test='ptrade != null'>ptrade=#{ptrade},</if>
            <if test='trade != null'>trade=#{trade},</if>
            <if test='enterpriseType != null'>enterprise_type=#{enterpriseType},</if>
            <if test='corporationName != null'>corporation_name=#{corporationName},</if>
            <if test='corporationUnitCode != null'>corporation_unit_code=#{corporationUnitCode},</if>
            <if test='registerDate != null'>register_date=#{registerDate},</if>
            <if test='registerPrincipal != null'>register_principal=#{registerPrincipal},</if>
            <if test='telephone != null'>telephone=#{telephone},</if>
            <if test='center != null'>center=#{center},</if>
            <if test='centerName != null'>center_name=#{centerName},</if>
            <if test='address != null'>address=#{address},</if>
            <if test='geographicalCoordinates != null'>geographical_coordinates=#{geographicalCoordinates},</if>
            <if test='website != null'>website=#{website},</if>
            <if test='zipCode != null'>zip_code=#{zipCode},</if>
            <if test='regionCode != null'>region_code=#{regionCode},</if>
            <if test='email != null'>email=#{email},</if>
            <if test='energyControlName != null'>energy_control_name=#{energyControlName},</if>
            <if test='fax != null'>fax=#{fax},</if>
            <if test='leader != null'>leader=#{leader},</if>
            <if test='leaderTel != null'>leader_tel=#{leaderTel},</if>
            <if test='leaderJob != null'>leader_job=#{leaderJob},</if>
            <if test='icsem != null'>icsem=#{icsem},</if>
            <if test='icsemTel != null'>icsem_tel=#{icsemTel},</if>
            <if test='icsemTrainNum != null'>icsem_train_num=#{icsemTrainNum},</if>
            <if test='icsemCertificate != null'>icsem_certificate=#{icsemCertificate},</if>
            <if test='staff != null'>staff=#{staff},</if>
            <if test='staffTel != null'>staff_tel=#{staffTel},</if>
            <if test='staffTrainNum != null'>staff_train_num=#{staffTrainNum},</if>
            <if test='certificate != null'>certificate=#{certificate},</if>
            <if test='processingLink != null'>processing_link=#{processingLink},</if>
            <if test='processingLinkJson != null'>processing_link_json=#{processingLinkJson},</if>
            <if test='certificateDate != null'>certificate_date=#{certificateDate},</if>
            <if test='certificateOrgan != null'>certificate_organ=#{certificateOrgan},</if>
            <if test='epcType != null'>epc_type=#{epcType},</if>
            <if test='delFlag != null'>del_flag=#{delFlag},</if>
            <if test='userid != null'>userid=#{userid},</if>
            <if test='updateTime != null'>update_time=#{updateTime},</if>
            <if test='deptId != null'>dept_id=#{deptId},</if>
            <if test='productinfos != null'>productinfos=#{productinfos},</if>
            <if test='indicators != null'>indicators=#{indicators},</if>
            <if test='energyTypes != null'>energy_types=#{energyTypes},</if>
            <if test='reportId != null'>report_id=#{reportId},</if>
        </trim>
    </insert>

    <select id="getEnterpriseInfo" resultType="com.nantian.cloud.jljc.entity.TReportEnterprise">
        select
        <include refid="Base_Column_List"></include>
        from t_report_enterprise
        where enterprise_code = #{epc} and year = #{year} and del_flag = "1"
    </select>

    <select id="getProductInfo" resultType="java.lang.String">
        select productinfos
        from t_report_enterprise
        where enterprise_code = #{epc} and year = #{year}  and del_flag = "1"
    </select>

    <select id="getEnergyIndex" resultType="java.lang.String">
        select indicators
        from t_report_enterprise
        where enterprise_code = #{epc} and year = #{year}  and del_flag = "1"
    </select>

    <select id="getEnergyInfo" resultType="java.lang.String">
        select energy_types
        from t_report_enterprise
        where enterprise_code = #{epc} and year = #{year}  and del_flag = "1"
    </select>

    <select id="getEnterpriseByReportId" resultType="com.nantian.cloud.jljc.entity.TReportEnterprise">
        select <include refid="Base_Column_List"></include>
        from t_report_enterprise
        where report_id = #{reportId} and del_flag = "1"
    </select>

    <select id="queryCustomEnterprise" resultType="com.nantian.cloud.jljc.entity.TReportEnterprise">
        select IFNULL(e.enterprise_code,#{epc}) enterprise_code, IFNULL(t.year,#{year}) year, IFNULL(t.enterprise_name,e.cmp_name) enterprise_name,
        IFNULL(t.corporation_name,e.corporation_name) corporation_name,IFNULL(t.telephone,e.phone) telephone, IFNULL(t.address, e.address) address,
        IFNULL(t.geographical_coordinates,'') geographical_coordinates, IFNULL(t.website,e.url) website, IFNULL(t.zip_code,e.zip_code) zip_code,
        IFNULL(t.region_code,e.region_code) region_code, IFNULL(t.email,e.email) email, IFNULL(t.fax,e.fax) fax,
        t.leader, t.leader_tel, t.leader_job, t.icsem, t.icsem_tel, t.staff, t.staff_tel
        from enterprise_info e left join t_report_enterprise t
        on t.enterprise_code = e.enterprise_code  and t.year = #{year} and t.del_flag = "1"
        where e.enterprise_code = #{epc}
    </select>

</mapper>
