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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jljc.entity.TReportEnergysTructure">
        <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="start_inventory" property="startInventory"/>
        <result column="object" property="object"/>
        <result column="money" property="money"/>
        <result column="consume_sum" property="consumeSum"/>
        <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="production_sum" property="productionSum"/>
        <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"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, report_id, energy_code, energy_code_name, unit, start_inventory, object, money, consume_sum, consume_industry,
        consume_material, consume_noindustry, consume_transport, end_inventory, production_sum, modulus, ref_modulus, userid, update_time, del_flag, dept_id
    </sql>

    <select id="getTructureByReportId" resultType="com.nantian.cloud.jljc.entity.TReportEnergysTructure">
        select
        <include refid="Base_Column_List"></include>
        from t_report_energys_tructure
        where report_id = #{reportId} and del_flag = "1"
    </select>

    <select id="getAllTructureByReportId" resultType="com.nantian.cloud.jljc.entity.TReportEnergysTructure">
        SELECT  e.id as energyCode, e.energy_name as energyCodeName, e.unit,
				t.start_inventory, t.object, t.money, t.consume_sum, t.consume_industry,
                t.consume_material, t.consume_noindustry, t.consume_transport, t.end_inventory, t.production_sum, t.modulus,
				e.equal_modulus as equalModulus, e.ref_modulus as refModulus
        FROM energy_info e left join  `t_report_energys_tructure` 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="getTructureByReportIdAndName" resultType="com.nantian.cloud.jljc.entity.TReportEnergysTructure">
        select a.energy_code, a.energy_code_name, a.unit, a.start_inventory, a.object, a.money, a.consume_sum,
        a.consume_industry, a.consume_material, a.consume_noindustry, a.consume_transport, a.end_inventory, a.production_sum
        from (
            select <include refid="Base_Column_List"></include>
            from t_report_energys_tructure
            where del_flag = "1"
            <if test="reportId !=null and reportId!=''">
                and report_id =#{reportId}
            </if>
        ) a
        <trim prefix="where" prefixOverrides="and">
            <if test=" list!=null and list!='' ">
                and
                <foreach collection="list" index="index" item="i" separator="or">
                    a.energy_code_name like concat("%",#{i},"%")
                </foreach>
            </if>
        </trim>
    </select>

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

    <select id="selByPage" resultType="com.nantian.cloud.jljc.entity.TReportEnergysTructure">
        select <include refid="Base_Column_List"></include>
        from t_report_energys_tructure
        <trim prefix="where" prefixOverrides="and">
            <if test="query.reportId !=null and query.reportId!=''">
                and report_id =#{query.reportId}
            </if>
            <if test="query.delFlag !=null and query.delFlag!=''">
                and del_flag = #{query.delFlag}
            </if>
        </trim>
    </select>

    <select id="getEnergyName" resultType="java.lang.String">
        select energy_code_name from `t_report_energys_tructure`
        where del_flag = "1" and energy_code is not null and report_id = #{reportId}
    </select>

</mapper>
