<?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.collectmaster.CollectMasterDataMapper">

    <insert id="insertData">
        insert into ${tableName} (id,enterpriseCode,dataCode,dataValue,convertRation,valid,scope,inputType,statType,statDate,uploadDate,addDate,digest) values
        (#{data.id},#{data.enterpriseCode},#{data.dataCode},#{data.dataValue},#{data.convertRation},#{data.valid},#{data.scope},#{data.inputType},
        #{data.statType},#{data.statDate},#{data.uploadDate},#{data.addDate},#{data.digest})
    </insert>

    <insert id="saveCollectDataBackup">
        <foreach collection="tanleNames" item="tableName">
            insert into data_bf select * from ${tableName};
        </foreach>
        insert into data_bf_log
        select now() date, (select count(*) FROM `data_bf` where addDate like concat(date_format(now(),'%Y-%m-%d'),'%')) count, concat(date_format(now(),'%Y-%m-%d'),'采集库数据备份');
    </insert>

    <select id="getTableNameList" resultType="java.lang.String">
        select table_name from information_schema.tables
        where table_schema='ynenergy_collect'
        and table_name like 'enterprise_energy_data_%';
    </select>

    <select id="getDataByTable" statementType="STATEMENT" resultType="com.nantian.cloud.dbcapp.vo.EnterpriseEnergyDataVo">
        <if test=" tanleNames!=null and tanleNames!='' ">
            <foreach collection="tanleNames" item="tableName" separator="union">
                select * from ${tableName}
            </foreach>
        </if>
    </select>
    <select id="getDataBySataDate" resultType="java.lang.String">
		select id from ${tableName} where enterpriseCode =#{data.enterpriseCode} and dataCode = #{data.dataCode} and statDate like concat(#{data.statDate},'%')
    </select>
</mapper>
