<?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.MobileMapper">

    <!-- 2020年以后查询数据-->
    <select id="getCompanyListByYear" resultType="java.lang.String">
        select enterpriseCode from enterprise_info where regionCode like CONCAT(#{code}, '%')
        <if test="inde!=null">
            and tid=#{inde}
        </if>
    </select>

   <!-- 2020年综合能耗-->
    <select id="getInfo1" resultType="com.nantian.cloud.dbcapp.vo.CoalVo">
        SELECT sum( guideline_val )/10000  as value ,
        record_circle as month
         from t_unitenergy2020 where enterprise_id in
        <foreach collection="companyList" item="items" separator="," open="(" close=")">
            #{items}
        </foreach>
        AND record_circle BETWEEN #{startTime} and #{endTime} and energyTypeCode = '0000' and code='00000000'
        and guideline_val &lt; 1000000 and guideline_val  >0and isRight = '1'
        GROUP BY record_circle
    </select>

    <!-- 2019年综合能耗-->
    <select id="getTce2019" resultType="com.nantian.cloud.dbcapp.vo.CoalVo">
           SELECT
            sum(T.guideline_val)/10000  as value,
            T.record_circle as month
        FROM
            t_unitenergy2019 t LEFT JOIN history_monitorpoint b on t.unitId=b.unitid and t.code =b.code
        WHERE
            T.record_circle BETWEEN  #{startTime} and #{endTime}  and T.unitId in
             <foreach collection="companyList" item="items" separator="," open="(" close=")">
                    #{items}
             </foreach>
            and b.Type ='ZHNH'
             GROUP BY T.record_circle
    </select>

    <!--2019年单位-->
    <select id="getAllCompanyList2019" resultType="java.lang.String">
        select enterprise_code from t_enterprise_old where 1=1
        <if test="code!=null">
            and region_code like CONCAT(#{code}, '%')
        </if>

        <if test="inde1!=null">
            and industryCode=#{inde1}
        </if>

        <if test="cmpName!=null">
            and enterprise_name like CONCAT('%',#{cmpName}, '%')
        </if>
    </select>

    <!--通过信用代码的到entID-->
    <select id="getentIdByEnterpriseCode" resultType="java.lang.String">
        SELECT
        entId
        FROM
        t_enterprise_old where 1=1
        <if test="companyList !=null">
            and enterprise_code in
            <foreach collection="companyList" item="items" separator="," open="(" close=")">
                #{items}
            </foreach>
        </if>

    </select>

<!--通过信用代码的到2020年企业-->
    <select id="getCompanyByCode" resultType="com.nantian.cloud.dbcapp.vo.MobileInfoVO">
        select  enterpriseCode as enterpriseCode,cmpName as name from enterprise_info
            where enterpriseCode =#{enterpriseCode}
    </select>

    <!--通过信用代码的到2020年企业综合能耗-->
    <select id="getTce2020" resultType="com.nantian.cloud.dbcapp.vo.CoalVo">
        SELECT sum(guideline_val)  as value ,
        record_circle as month
        from t_unitenergy2020 where enterprise_id =#{enterpriseCode}
        AND record_circle BETWEEN #{startTime} and #{endTime} and energyTypeCode = '0000' and code='00000000'
        and guideline_val &lt; 1000000 and guideline_val  >0 and isRight = "1"
        group by record_circle
    </select>
  <!--通过信用代码的到2020年企业联系人-->
    <select id="getNameAndPhone" resultType="com.nantian.cloud.dbcapp.vo.CoalVo">
        select manager as month,phone as value  from company_energy_manager where enterpriseCode =#{enterpriseCode}
    </select>

    <!--通过信用代码的到2020年企业采集点-->
    <select id="getCollectionByCode" resultType="java.lang.Integer">
        select count(datacode) from configure_data_collect where enterpriseCode =#{enterpriseCode}
    </select>


 <!--   得到老数据entId-->
    <select id="getEntId" resultType="java.lang.Integer">
        SELECT entId FROM t_enterprise_old where  enterprise_code =#{enterpriseCode}
    </select>

    <!--2019年-->
    <select id="getCompanyByCode2019" resultType="com.nantian.cloud.dbcapp.vo.MobileInfoVO">
       SELECT
            CompanyName as name,
            InchargeName as man1,
            InchargePhone as phone1,
            EMonitor as man2,
            EMonitorPhone as phone2,
            EManagementName as man3,
            EManagementPhone as phone3
        FROM
            energycconsumptionunit
        WHERE
            id = #{entID}
    </select>

    <!--通过信用代码的到2019年企业综合能耗-->
    <select id="getEnterpriceTce2019" resultType="com.nantian.cloud.dbcapp.vo.CoalVo">
        SELECT
        sum(T.guideline_val) as value,
        T.record_circle as month
        FROM
        t_unitenergy2019 t LEFT JOIN history_monitorpoint b on t.unitId=b.unitid and t.code =b.code
        WHERE
        T.record_circle BETWEEN  #{startTime} and #{endTime}  and T.unitId =#{entID}
        and b.Type ='ZHNH'
        GROUP BY T.record_circle
    </select>

    <!--通过信用代码的到2019年采集点-->
    <select id="getCollectionByCode2019" resultType="java.lang.Integer">
        select count(id) from history_monitorpoint
	        WHERE EntID  =#{entID}
    </select>

    <!--查询计量人员单位列表-->
    <select id="getComList" resultType="java.lang.String">
        select enterprise_code from enterprise_info_jly
        <where>
            <if test="substring!=null">
                region_code like #{substring}
            </if>
            <if test="industry!=null">
                and industry_code = #{industry}
            </if>
            <if test="cmpName!=null">
                and cmp_name like #{cmpName}
            </if>
        </where>
        order by region_code
    </select>

    <!--查询计量人员详细列表-->
    <select id="getMeasureList" resultType="com.nantian.cloud.dbcapp.vo.MobileMeasureVO">
        SELECT
                a.calculater_name as  name,
                b.cmp_name as cmpName,
                c.meaning as cmpNameArea,
                d.meaning as cmpNameIndustry,
                a.technical_post as  zc,
                a.certificate_name as jsmc,
                a.certificate_no as  nob,
                a.dept as  department,
                a.job as  post,
                a.phone as  phone,
                b.enterprise_code as epcCode,
                case when certificate is  null then 0 else 1 end   as isCz
                FROM
                    company_calculater  a  LEFT JOIN enterprise_info_jly b on a.enterprise_code =b.enterprise_code
                    LEFT JOIN dict_region c on b.region_code= c.id
                    LEFT JOIN dict_industry_code d on b.tid= d.code
                WHERE 1=1
                    <if test="compList !=null">
                       and  a.enterprise_code IN
                        <foreach collection="compList" item="items" separator="," open="(" close=")">
                            #{items}
                        </foreach>
                    </if>
                    AND a.del_flag =1
                    having epcCode is not null
                    order by b.region_code
    </select>


        <!--查询审查任务统计-->
    <select id="getSumTask" resultType="java.lang.Integer">
        SELECT count(*) from check_plan where del_flag =1 and dept_id like concat(#{areaCode},'%')
    </select>

    <!--查询审查任务列表-->
    <select id="getTaskList" resultType="com.nantian.cloud.dbcapp.vo.MobileTaskVO">
       SELECT
            id as id,
           name as name,
           num as No,
           year as year,
           check_type  as type,
           begin_time as starTime,
           end_time as endTime

        FROM
            check_plan
        WHERE
            del_flag =1
            <if test="name!=null">
                and name like #{name}
            </if>

            <if test="type!=null">
                and check_type = #{type}
            </if>

    </select>


    <!--通过任务id查询企业-->
    <select id="getCompListByPlanId" resultType="com.nantian.cloud.dbcapp.vo.MobileCompVO">
        select
         com_name as  name,
         epc as  enterpriseCode,
         check_status as  state
        from check_enterprice where check_plan_id=#{id}
    </select>


    <select id="selectInstrumentsNum" resultType="com.nantian.cloud.dbcapp.vo.InstrumentVO">
        select meterLevel from configure_gauge a left join enterprise_info_jly b on a.enterpriseCode = b.enterprise_code
        where b.region_code like concat(#{areaCode},'%')
    </select>


    <select id="getInstrumentsInfo" resultType="com.nantian.cloud.dbcapp.vo.InstrumentsInfo">
        SELECT
        b.manageNo AS instrumentsCode,
        b.enterpriseCode as enterpriseCode,
        a.cmp_name AS enterpriseName,
        c.meaning AS cmpNameArea,
        d.meaning AS industryName,
        b.meterLevel AS instrumentsLevel,
        b.meterName AS instrumentsLevelName,
        b.manufacturer AS ProductName,
        b.location AS location,
        b.precisionLevel as precisionLevel
        FROM
        configure_gauge b
        LEFT JOIN enterprise_info_jly a ON b.enterpriseCode = a.enterprise_code
        LEFT JOIN dict_region c ON a.region_code = c.code
        LEFT JOIN dict_industry_code d ON a.industry_code = d.CODE
        WHERE
        1 = 1
        <if test = "compList !=null" >
        AND a.enterprise_code IN
            <foreach collection="compList" item="items" separator="," open="(" close=")">
             #{items}
            </foreach >
        </if>
        <if test="level!=null">
            and meterLevel=#{level}
        </if>
        order by a.region_code
    </select>

    <select id="countAllLogs" resultType="com.nantian.cloud.dbcapp.vo.MobileUpdateInfoBo">
        select count(a.id) as dataValue, ${index} as analysisTime from enterprise_energy_data a where a.enterpriseCode in
        <foreach collection="list" open="(" separator="," close=")" item="item">
            #{item}
        </foreach>
        and a.statDate like #{s}
        group BY ${index}
    </select>

    <select id="sumAllElectricityValue" resultType="com.nantian.cloud.dbcapp.vo.MobileUpdateInfoBo">
        select count(a.id) as dataValue, ${electricityIndex} as analysisTime from company_data_detail a where a.enterpriseCode in
        <foreach collection="list" open="(" separator="," close=")" item="item">
            #{item}
        </foreach>
        and a.time like #{s} and a.statType = "1"
        group BY ${electricityIndex}
    </select>

    <select id="selectUpdateInfoCollect" resultType="com.nantian.cloud.dbcapp.vo.MobileUpdateInfoBo">
        select count(distinct a.id) as dataValue ,count(distinct a.enterpriseCode) as dataNum,${index} as analysisTime from enterprise_backup_data a
        left join enterprise_info b on a.enterpriseCode = b.enterpriseCode
        <where>
        <if test="areaName!=null">
            b.regionCode like #{areaName}
        </if>
        <if test="industryName!=null">
            and  b.tid = #{industryName}
        </if>
        <if test="s!=null">
            and  a.channelType = #{s}
        </if>
        <if test="o!=null">
            and  a.uploadCompleted = #{o}
        </if>
        and uploadDate like #{time}
       group by ${index}
        </where>
    </select>

    <select id="selectUpdateInfoElectricity" resultType="com.nantian.cloud.dbcapp.vo.MobileUpdateInfoBo">
        select count(distinct a.id) as dataValue ,count(distinct a.enterpriseCode) as dataNum,${index} as analysisTime from enterprise_backup_data a
        left join electric_enterprise_info b on a.enterpriseCode = b.enterpriseCode
        <where>
            <if test="areaName!=null">
                b.regionCode like #{areaName}
            </if>
            <if test="industryName!=null">
                and  b.industry_code = #{industryName}
            </if>
            <if test="s!=null">
                and  a.channelType = #{s}
            </if>
            <if test="o!=null">
                and  a.uploadCompleted = #{o}
            </if>
            and uploadDate like #{time}
            group by ${index}
        </where>
    </select>


    <select id="selectUpdateEnterpriseInfo" resultType="com.nantian.cloud.dbcapp.vo.MobileEnterpriseVo">
      select b.cmpName as enterpriseName,a.enterpriseCode,e.tname as areaName,f.`name` as industryName,count(c.id) as collectValue,
      count(d.id) as electricity,COUNT(a.id) as updateCountryNum,count(a.channelType="1") as updateCountryCollectNum
      count(a.channelType="1") as updateCountryCollectNum from enterprise_backup_data a left join enterprise_info   b on a.enterpriseCode = b.enterpriseCode
      left join enterprise_energy_data c on c.enterpriseCode = a.enterpriseCode
      left join company_data_detail d on d.enterpriseCode = a.enterpriseCode and d.ststType = "1"
      left join dict_region e on e.code = b.regionCode
      left join temp_dict_name f on f.code = b.tid
        <where>
            <if test="areaName!=null">
                b.regionCode like #{areaName}
            </if>
            <if test="industryName!=null">
             and    b.tid = #{industryName}
            </if>
            <if test="cmpName!=null">
             and    b.cmpName = #{cmpName}
            </if>
        </where>
        group by a.enterpriseCode
    </select>

    <select id="selectEnterpriseBaseInfo" resultType="com.nantian.cloud.dbcapp.vo.MobileEnterpriseVo">
        (select b.cmpName as enterpriseName,a.enterpriseCode,e.tname as areaName,f.`name` as industryName,a.uploadCompleted as state
        from enterprise_backup_data a left join upload_country_enterprise_info b on a.enterpriseCode = b.enterpriseCode
        left join dict_region e on e.code = b.regionCode
        left join temp_dict_name f on f.code = b.tid
        <where>
            <if test="areaName!=null">
                b.regionCode like #{areaName}
            </if>
            <if test="industryName!=null">
                and    b.tid = #{industryName}
            </if>
            <if test="cmpName!=null">
                and    b.cmpName like #{cmpName}
            </if>
            and  b.cmpName is not null
        </where>
        group by a.enterpriseCode)
    </select>

    <select id="selectEnterpriseCollectInfo" resultType="com.nantian.cloud.dbcapp.vo.MobileEnterpriseVo">
        select a.enterpriseCode,count(a.id) as collectValue

        from enterprise_energy_data a
        group by a.enterpriseCode order by a.enterpriseCode
    </select>


    <select id="selectEnterpriseElectricityInfo" resultType="com.nantian.cloud.dbcapp.vo.MobileEnterpriseVo">
        select a.enterpriseCode,count(a.id) as electricity
        from company_data_detail a
        group by a.enterpriseCode order by a.enterpriseCode
    </select>



    <select id="selectEnterpriseUpdateInfo" resultType="com.nantian.cloud.dbcapp.vo.MobileEnterpriseVo">
    select a.enterpriseCode,
       COUNT(a.id) as updateCountryNum from enterprise_backup_data a
        group by a.enterpriseCode order by a.enterpriseCode
         </select>

    <select id="selectEnterpriseUpdateInfo1" resultType="com.nantian.cloud.dbcapp.vo.MobileEnterpriseVo">
         select a.enterpriseCode,
       COUNT(a.id) as updateCountryNum from enterprise_backup_data a
       where a.channelType="1"
        group by a.enterpriseCode order by a.enterpriseCode
    </select>

    <select id="selectEnterpriseUpdateInfo2" resultType="com.nantian.cloud.dbcapp.vo.MobileEnterpriseVo">
         select a.enterpriseCode,
       COUNT(a.id) as updateCountryNum from enterprise_backup_data a
       where a.channelType="3"
        group by a.enterpriseCode order by a.enterpriseCode
    </select>
    <select id="selectUpdateInfo" resultType="com.nantian.cloud.dbcapp.vo.UpdateEnterpriseInfo">
       select enterpriseCode,dataCode, dataValue ,uploadDate as `update` , statDate ,b.meaning as inputType, statType as frequency,
       channelType ,uploadCompleted from enterprise_backup_data a left join dict_data_collect_origin b
       on a.inputType = b.code
       <where>
           <if test="time!=null">
               uploadDate like #{time}
           </if>
           <if test="list!=null">
            and enterpriseCode in
            <foreach collection="list" open="(" separator="," close=")" item="item">
                #{item}
            </foreach>
           </if>
       </where>
    </select>

    <select id="selectAllInfos" resultType="com.nantian.cloud.dbcapp.vo.MobileUpdateInfoBo">
        select count(*) as dataValue, ${index} as analysisTime,"1" as type from enterprise_energy_data a where
          a.enterpriseCode in (SELECT DISTINCT enterpriseCode FROM enterprise_info WHERE regionCode LIKE concat(#{area},'%')
         <if test="industry!=null">
            and tid = #{industry}
         </if>)
        and a.statDate like #{time}
        group BY ${index}
        UNION all
        select count(*) as dataValue, ${electricityIndex} as analysisTime,"2" as type from company_data_detail a where
         a.enterpriseCode in(SELECT DISTINCT enterpriseCode FROM electric_enterprise_info WHERE regionCode LIKE concat(#{area},'%')
        <if test="industry!=null">
            and industry_code = #{industry}
        </if>)
        and a.time like #{time}
        group BY ${electricityIndex}
    </select>


    <select id="selectUpdateAll" resultType="com.nantian.cloud.dbcapp.vo.MobileUpdateInfoBo">
        select count(distinct a.id) as dataValue ,count(distinct a.enterpriseCode) as dataNum,${index} as analysisTime ,"1" as type from enterprise_backup_data a
        left join enterprise_info b on a.enterpriseCode = b.enterpriseCode
        <where>
            <if test="areaName!=null">
                b.regionCode like #{areaName}
            </if>
            <if test="industryName!=null">
                and  b.tid = #{industryName}
            </if>

                and  a.channelType = "1"
            and uploadDate like #{time}
            group by ${index}
        </where>
        UNION all
        select count(distinct a.id) as dataValue ,count(distinct a.enterpriseCode) as dataNum,${index} as analysisTime ,"2" as type from enterprise_backup_data a
        left join enterprise_info b on a.enterpriseCode = b.enterpriseCode
        <where>
            <if test="areaName!=null">
                b.regionCode like #{areaName}
            </if>
            <if test="industryName!=null">
                and  b.tid = #{industryName}
            </if>
            and  a.channelType = "1" and  a.uploadCompleted = '成功'
            and uploadDate like #{time}
            group by ${index}
        </where>
        UNION all
        select count(distinct a.id) as dataValue ,count(distinct a.enterpriseCode) as dataNum,${index} as analysisTime,"3" as type from enterprise_backup_data a
        left join electric_enterprise_info b on a.enterpriseCode = b.enterpriseCode
        <where>
        <if test="areaName!=null">
            b.regionCode like #{areaName}
        </if>
        <if test="industryName!=null">
            and  b.industry_code = #{industryName}
        </if>

            and  a.channelType !="1"
        and uploadDate like #{time}
        group by ${index}
        </where>
        UNION all
        select count(distinct a.id) as dataValue ,count(distinct a.enterpriseCode) as dataNum,${index} as analysisTime,"4" as type from enterprise_backup_data a
        left join electric_enterprise_info b on a.enterpriseCode = b.enterpriseCode
        <where>
        <if test="areaName!=null">
            b.regionCode like #{areaName}
        </if>
        <if test="industryName!=null">
            and  b.industry_code = #{industryName}
        </if>

        and  a.channelType !="1"  and  a.uploadCompleted = '成功'
        and uploadDate like #{time}
        group by ${index}
        </where>
    </select>


    <select id="selectUpdateCountryByDay" resultType="int">
        select count(distinct a.enterpriseCode) as dataNum from enterprise_backup_data a
        left join enterprise_info b on a.enterpriseCode = b.enterpriseCode
        <where>
        <if test="areaName!=null">
            b.regionCode like #{areaName}
        </if>
        <if test="industryName!=null">
            and  b.tid = #{industryName}
        </if>
        and  a.channelType = '1'
        and uploadDate = #{time}
        </where>
        UNION all
        select count(distinct a.enterpriseCode) as dataNum from enterprise_backup_data a
        left join enterprise_info b on a.enterpriseCode = b.enterpriseCode
        <where>
            <if test="areaName!=null">
                b.regionCode like #{areaName}
            </if>
            <if test="industryName!=null">
                and  b.tid = #{industryName}
            </if>
            and  a.channelType = '1'  and  a.uploadCompleted = '成功'
            and uploadDate = #{time}
        </where>
        UNION all
        select count(distinct a.enterpriseCode) as dataNum from enterprise_backup_data a
        left join electric_enterprise_info b on a.enterpriseCode = b.enterpriseCode
        <where>
        <if test="areaName!=null">
            b.regionCode like #{areaName}
        </if>
        <if test="industryName!=null">
            and  b.industry_code = #{industryName}
        </if>
        and  a.channelType !='1'
        and uploadDate = #{time}
        </where>
        UNION all
        select count(distinct a.enterpriseCode) as dataNum from enterprise_backup_data a
        left join electric_enterprise_info b on a.enterpriseCode = b.enterpriseCode
        <where>
            <if test="areaName!=null">
                b.regionCode like #{areaName}
            </if>
            <if test="industryName!=null">
                and  b.industry_code = #{industryName}
            </if>
            and  a.channelType !='1'  and  a.uploadCompleted = '成功'
            and uploadDate = #{time}
        </where>
    </select>


    <select id="selectMaxTime" resultType="string">
        select max(uploadDate) from enterprise_backup_data
    </select>


    <select id="selectNameByCode" resultType="string">
        select meaning from dict_region where code = #{code}
    </select>

    <select id="selectExceptionByDay" resultType="com.nantian.cloud.dbcapp.vo.ExceptionByDay">
        select count(a.id) as collectValue ,substring(statDate,1,10) as statDate,GROUP_CONCAT(distinct a.enterpriseCode) as list from energy_exception_data_info a left join enterprise_info b
        on a.enterpriseCode = b.enterpriseCode
        where b.regionCode like concat(#{areaCode},"%") and a.statDate like concat(#{time},"%")
        group by substring(statDate,1,10)
    </select>

    <select id="selectExceptionInfos" resultType="com.nantian.cloud.dbcapp.vo.ExceptionInfoVo">
        select DISTINCT (a.enterpriseCode),a.dataCode ,a.convertRation,a.dataValue,a.exceptionType,substring(a.statDate,1,10) as statDate,a.collectItemName,c.qualityUnit as enterpriseUnit ,c.collectUnit  from
        energy_exception_data_info as a left join enterprise_info as b on a.enterpriseCode = b.enterpriseCode left join dict_energy_type_unit_collect c
        on substring(a.dataCode,11,4) = c.code
        where b.regionCode like concat(#{areaCode},'%') and a.statDate like concat(#{time},'%')
        ORDER BY statDate
    </select>

    <select id="selectIndustryByName" resultType="string">
        select id from temp_dict_name where name = #{industry}
    </select>

    <select id="selectExceptionByArea" resultType="com.nantian.cloud.dbcapp.dto.ExceptionByAreaBo">
SELECT
	COUNT( a.id ) AS num,
	count(case a.exceptionType when 1 then true else null end ) AS volatility,
    count(case a.exceptionType when 2 then true else null end ) AS convertRation,
	count(case a.exceptionType when 3 then true else null end ) AS collectValue,
	count(case a.exceptionType when 4 then true else null end ) AS transmission,
	count(case a.exceptionType when 5 then true else null end ) AS electricity,
	a.enterpriseCode,
	b.cmpName AS epcName
FROM
	energy_exception_data_info a
	LEFT JOIN enterprise_info b ON a.enterpriseCode = b.enterpriseCode
WHERE
	a.statDate BETWEEN #{pre}
	AND #{end}
	AND b.regionCode LIKE concat( #{areaCode}, '%' )
GROUP BY
	a.enterpriseCode
ORDER BY
	num DESC
    </select>

    <select id="selectCountByArea" resultType="com.nantian.cloud.dbcapp.vo.InstrumentsByArea">
         SELECT
             count(a.id) as num , ${sub} as areaCode,SUBSTR(c.meaning,1,2) as areaName
                FROM
                    company_calculater  a  LEFT JOIN enterprise_info_jly b on a.enterprise_code = b.enterprise_code
										left join dict_region c on b.region_code = c.id
                WHERE
                    b.region_code like concat(#{areaCode},'%') and
                    a.del_flag =1
                    group by areaCode
                    order by num desc
    </select>

    <select id="selectCountNumByArea" resultType="com.nantian.cloud.dbcapp.vo.InstrumentsByArea">
       SELECT
             count(a.id) as num , ${sub} as areaCode,SUBSTR(c.meaning,1,2) as areaName
                FROM
                    configure_gauge  a  LEFT JOIN enterprise_info_jly b on a.enterpriseCode = b.enterprise_code
										left join dict_region c on b.region_code = c.id
                WHERE
                    b.region_code like concat(#{areaCode},'%') and
                    a.del_flag =1
                    group by areaCode
                    order by num desc
    </select>


    <select id="selectEpcInfo" resultType="int">
        select count(*) from upload_country_enterprise_info
        <where>
            regionCode like concat(#{areaCode},'%')
            <if test="industryCode!=null">
              and  tid = #{industryCode}
            </if>
            and enterpriseType = '0'
        </where>
        union all
        select count(*) from upload_country_enterprise_info
        <where>
            regionCode like concat(#{areaCode},'%')
            <if test="industryCode!=null">
                and  tid = #{industryCode}
            </if>
            and enterpriseType = '1'
        </where>
    </select>

    <select id="selectExceptionInfosByarea" resultType="com.nantian.cloud.dbcapp.vo.ExceptionInfoVo">
             SELECT DISTINCT
	( a.enterpriseCode ),
	a.dataCode,
	a.convertRation,
	a.dataValue,
	a.exceptionType,
	substring( a.statDate, 1, 10 ) AS statDate,
	a.collectItemName ,
	c.qualityUnit AS enterpriseUnit,
	c.collectUnit
FROM
	energy_exception_data_info AS a
	LEFT JOIN enterprise_info AS b ON a.enterpriseCode = b.enterpriseCode
	LEFT JOIN dict_energy_type_unit_collect c ON c.CODE = substring(a.dataCode, 11, 4)
WHERE
	b.regionCode LIKE concat( #{areaCode}, '%' )
	AND a.statDate BETWEEN #{pre}
	AND #{end}
    </select>

    <select id="getEnterpriseNum" resultType="int">
        select count(distinct enterpriseCode) from enterprise_info
        <where>
            <if test="area!=null">
                regionCode like concat(#{area},"%")
            </if>
            <if test="industry!=null">
                and tid = #{industry}
            </if>
        </where>
        union all
        select  count(DISTINCT enterpriseCode )from (
        SELECT a.enterpriseCode  FROM electric_enterprise_info a
        where 1=1
        <if test="area !=null" >
            and a.regionCode LIKE concat(#{area},"%")
        </if>
        <if test="industry!=null">
            and a.industry_code = #{industry}
        </if>
        union all
        SELECT d.enterpriseCode  FROM enterprise_info d
        where 1=1
        <if test="area!=null" >
            and d.regionCode like concat(#{area},"%")
        </if>
        <if test="industry!=null">
            and d.tid =#{industry}
        </if>
        ) t
        union all
        select count(distinct enterpriseCode) from upload_country_enterprise_info
        <where>
            regionCode
            like concat(#{area},"%")
            <if test="industry!=null">
                and tid = #{industry}
            </if>
            and uploadCompleted = '1'
        </where>
    </select>
</mapper>
