<?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.dbcapp.mapper.record.AccessUnioMapper">


    <select id="getUnio" resultType="com.nantian.cloud.dbcapp.vo.AccessUnionVo">
        SELECT
            info.id AS id,
            info.enterprise_code AS enterprise_code,
            info.register_address AS register_address,
            info.register_date AS register_date,
            energy.record_date AS record_date,
	        info.cmp_name AS cmp_name,
	        dict.tname
        FROM
            access_enterprise_info AS info
            INNER JOIN access_energys_tructure AS energy ON info.enterprise_code = energy.enterprise_code
            AND info.state = 2
            AND info.del_flag = 1
            AND energy.del_flag = 1
            <if test="year != null and year != ''">
                AND LEFT ( energy.record_date ,4) = #{year}
            </if>
            <if test="dictid != null and dictid != ''">
                AND LEFT ( RIGHT ( info.region_code, 6 ), 4 ) =LEFT ( #{dictid},4 )
            </if>
            LEFT JOIN dict_region AS dict ON LEFT(RIGHT ( info.region_code, 6 ),4) = LEFT(dict.id,4)
        GROUP BY info.enterprise_code,energy.record_date
    </select>
    <select id="getAllInfo" resultType="com.nantian.cloud.dbcapp.vo.AccessUnionVo">
        SELECT
            info.id AS id,
            info.enterprise_code AS enterprise_code,
            info.register_address AS register_address,
            info.register_date AS register_date,
            info.cmp_name AS cmp_name,
            dict.tname
        FROM
            `access_enterprise_info` AS info
                INNER JOIN dict_region AS dict ON LEFT ( RIGHT ( info.region_code, 6 ), 4 ) = LEFT ( dict.id, 4 )  AND info.state = 2
        GROUP BY
            info.enterprise_code
    </select>
</mapper>