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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jljc.entity.EnergyInfo">
        <id column="id" property="id" />
        <result column="energy_name" property="energyName" />
        <result column="code" property="code" />
        <result column="unit" property="unit" />
        <result column="ref_modulus" property="refModulus" />
        <result column="equal_modulus" property="equalModulus" />
        <result column="unit_modulus" property="unitModulus" />
        <result column="co2" property="co2" />
        <result column="ch4" property="ch4" />
        <result column="no2" property="no2" />
        <result column="pid" property="pid" />
        <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="start_inventory" property="startInventory"/>
        <result column="object" property="object"/>
        <result column="money" property="money"/>
        <result column="consume_industry" property="consumeIndustry"/>
        <result column="consume_material" property="consumeMaterial"/>
        <result column="consume_noindustry" property="consumeNoindustry"/>
        <result column="consume_transport" property="consumeTransport"/>
        <result column="end_inventory" property="endInventory"/>
        <result column="consume_sum" property="consumeSum"/>
        <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="recycling" property="recycling" />
        <result column="nowrefModulus" property="nowrefModulus" />
        <result column="equivalentMarks" property="equivalentMarks" />
        <result column="compBuyEnergy" property="compBuyEnergy" />
        <result column="processEnergy" property="processEnergy" />
        <result column="craftEnergy" property="craftEnergy" />
    </resultMap>

    <resultMap id="EnergyInfoTreeVo" type="com.nantian.cloud.jljc.vo.EnergyInfoTreeVo">
        <id column="value" property="value" />
        <result column="pvalue" property="pvalue" />
        <result column="label" property="label" />
        <result column="code" property="code" />
        <result column="unit" property="unit" />
        <result column="ref_modulus" property="refModulus" />
        <result column="equal_modulus" property="equalModulus" />
        <result column="unit_modulus" property="unitModulus" />
        <result column="start_inventory" property="startInventory"/>
        <result column="object" property="object"/>
        <result column="money" property="money"/>
        <result column="consume_industry" property="consumeIndustry"/>
        <result column="consume_material" property="consumeMaterial"/>
        <result column="consume_noindustry" property="consumeNoindustry"/>
        <result column="consume_transport" property="consumeTransport"/>
        <result column="end_inventory" property="endInventory"/>
        <result column="consume_sum" property="consumeSum"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, energy_name, code, unit, ref_modulus, equal_modulus, unit_modulus, co2, ch4, no2, pid, userid, update_time, del_flag, dept_id,
        start_inventory, object, money, consume_industry, consume_material, consume_noindustry, consume_transport, end_inventory, consume_sum,
        production_consumption, pro_con_total, thermal_power, heating, coal_washing, coking, oil, gasification, gas_liquefaction,
        coal_products, conversion_output, conversion_output_ref, recycling
    </sql>

    <sql id="base_tree">
        id as value, pid as pvalue, energy_name as label, code,
        unit, ref_modulus, equal_modulus, unit_modulus,
        start_inventory, object, money, consume_industry, consume_material, consume_noindustry, consume_transport, end_inventory, consume_sum
    </sql>

    <select id="getInfoByStr" resultType="com.nantian.cloud.jljc.entity.EnergyInfo">
        select <include refid="Base_Column_List"></include>
        from energy_info
        where id in
        <foreach collection="list" index="index" item="i" separator=","  open="("  close=")">
            #{i}
        </foreach>
    </select>

    <select id="getEnergyInfoTree" resultType="com.nantian.cloud.jljc.vo.EnergyInfoTreeVo">
        select <include refid="base_tree"></include>
        from energy_info
    </select>

    <select id="getPageScope" resultType="com.nantian.cloud.jljc.entity.EnergyInfo">
        select <include refid="Base_Column_List"></include>
        from energy_info
        <trim prefix="where" prefixOverrides="and">
            <if test="query.energyName != null  and query.energyName != ''">
                and energy_name like concat("%",#{query.energyName},"%")
            </if>
            <if test="query.delFlag != null  and query.delFlag != ''">
                and del_flag = #{query.delFlag}
            </if>
        </trim>
    </select>

    <select id="getCodeByPid" resultType="java.lang.String">
        select DISTINCT e2.code
        from energy_info e1
        inner join energy_info e2 on e1.pid = e2.id and e1.del_flag = "1"
    </select>

    <select id="energyListAndChild" resultType="com.nantian.cloud.jljc.entity.EnergyInfo">
        select e1.*, GROUP_CONCAT(e2.id) childs
        from energy_info e1
        left join energy_info e2 on e1.id = e2.pid
        where e1.pid = '0' and e1.del_flag ="1"  group by e1.id
    </select>

    <select id="energyCodeList" resultType="com.nantian.cloud.jljc.entity.EnergyInfo">
        select code
        from energy_info
        where del_flag ="1"
    </select>
    <select id="getEnergyInfoList" resultType="java.util.Map">
        select code as value, energy_name as label
        from energy_info
        where del_flag = "1"
    </select>
    <select id="getEnergyInfoByReportSetting" resultType="com.nantian.cloud.jljc.entity.EnergyInfo">
        select id, energy_name, t1.code, unit, ref_modulus, equal_modulus, unit_modulus, co2, ch4, no2, pid, userid, update_time, del_flag, dept_id,
        start_inventory, object, money, consume_industry, consume_material, consume_noindustry, consume_transport, end_inventory, consume_sum,
        production_consumption, pro_con_total, thermal_power, heating, coal_washing, coking, oil, gasification, gas_liquefaction,
        coal_products, conversion_output, conversion_output_ref, recycling, IFNULL(t2.nowrefModulus,ref_modulus) nowrefModulus, IFNULL(t2.equivalentMarks,equal_modulus) equivalentMarks,
        IFNULL(t2.compBuyEnergy,'false') compBuyEnergy, IFNULL(t2.processEnergy,'false') processEnergy, IFNULL(t2.craftEnergy,'false') craftEnergy
        from energy_info t1
        <foreach collection="list" item="item" index="i" separator="union" open=" left join (" close=") t2">
            select #{item.code} code, #{item.nowrefModulus} nowrefModulus, #{item.equivalentMarks} equivalentMarks, #{item.compBuyEnergy} compBuyEnergy, #{item.processEnergy} processEnergy, #{item.craftEnergy} craftEnergy
        </foreach> on t1.code = t2.code
        where t1.del_flag = "1"
    </select>
</mapper>
