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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jljc.entity.TReportEnergyOut">
        <id column="id" property="id" />
        <result column="report_id" property="reportId" />
        <result column="energy_code" property="energyCode" />
        <result column="energy_code_name" property="energyCodeName" />
        <result column="unit" property="unit" />
        <result column="modulus" property="modulus" />
        <result column="ref_modulus" property="refModulus" />
        <result column="userid" property="userid" />
        <result column="update_time" property="updateTime" />
        <result column="del_flag" property="delFlag" />
        <result column="dept_id" property="deptId" />
        <result column="production_consumption" property="productionConsumption" />
        <result column="pro_con_total" property="proConTotal" />
        <result column="thermal_power" property="thermalPower" />
        <result column="heating" property="heating" />
        <result column="coal_washing" property="coalWashing" />
        <result column="coking" property="coking" />
        <result column="oil" property="oil" />
        <result column="gasification" property="gasification" />
        <result column="gas_liquefaction" property="gasLiquefaction" />
        <result column="coal_products" property="coalProducts" />
        <result column="conversion_output" property="conversionOutput" />
        <result column="conversion_output_ref" property="conversionOutputRef" />
        <result column="waste_power" property="wastePower" />
        <result column="gas_power" property="gasPower" />
        <result column="recycling" property="recycling" />
        <result column="remark" property="remark" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, report_id, energy_code, energy_code_name, unit, modulus, ref_modulus, userid, update_time, del_flag, dept_id,
        production_consumption, pro_con_total, thermal_power, heating, coal_washing, coking, oil, gasification,
        gas_liquefaction, coal_products, conversion_output, conversion_output_ref, recycling, remark, waste_power, gas_power
    </sql>

    <select id="getOutByReportIdAndName" resultType="com.nantian.cloud.jljc.entity.TReportEnergyOut">
        select <include refid="Base_Column_List"></include>
        from t_report_energy_out
        where energy_code_name = #{name} and report_id = #{reportId} and del_flag = "1"
    </select>

    <select id="getAllOutByReportId" resultType="com.nantian.cloud.jljc.entity.TReportEnergyOut">
        SELECT  e.id as energyCode, e.energy_name as energyCodeName, e.unit, t.modulus, e.ref_modulus as refModulus,
                t.production_consumption, t.pro_con_total, t.thermal_power, t.heating, t.coal_washing, t.coking, t.oil,
                t.gasification,t.gas_liquefaction, t.coal_products, t.conversion_output, t.conversion_output_ref, t.recycling, t.remark,t.waste_power, t.gas_power
        FROM energy_info e left join  `t_report_energy_out` t
        on t.energy_code = e.code and t.report_id = #{reportId} and t.del_flag = "1"
        where e.del_flag = "1" ORDER BY e.id
    </select>

    <select id="comparison" resultType="com.nantian.cloud.jljc.entity.TReportEnergyOut">
        SELECT
            e1.start_inventory,
            e1.object,
            e1.energy_code_name ename,
            e2.id,
            e2.report_id,
            e2.energy_code,
            e2.energy_code_name,
            e2.unit,
            IFNULL(e2.modulus,e1.modulus) modulus,
            IFNULL(e2.ref_modulus,e1.ref_modulus) ref_modulus,
            e2.userid,
            e2.update_time,
            e2.del_flag,
            e2.dept_id,
            e2.production_consumption,
            e2.pro_con_total,
            e2.thermal_power,
            e2.heating,
            e2.coal_washing,
            e2.coking,
            e2.oil,
            e2.gasification,
            e2.gas_liquefaction,
            e2.coal_products,
            e2.conversion_output,
            e2.conversion_output_ref,
            e2.recycling,
            e2.remark,
            e2.waste_power,
            e2.gas_power
        FROM
            t_report t1
            LEFT JOIN t_report t2 ON t2.YEAR = t1.YEAR
            AND t2.enterprise_code = t1.enterprise_code
            AND t2.type = '2-1'
            AND t2.del_flag = '1'
            LEFT JOIN t_report_energys_tructure e1 ON e1.report_id = t1.id
            AND e1.del_flag = '1'
            LEFT JOIN t_report_energy_out e2 ON e2.report_id = t2.id
            AND e2.del_flag = '1'
            AND e2.energy_code_name = e1.energy_code_name
        WHERE
            t1.YEAR = #{year}
            AND t1.enterprise_code = #{enterpriseCode}
            AND t1.type = '2'
            AND t1.del_flag = '1'
            AND e1.energy_code_name NOT LIKE '合计%'
            AND e1.energy_code_name NOT LIKE '原煤%'
    </select>


</mapper>
