<?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.DischargeEnergyConstructionMapper">
    <sql id="tableName">
        t_discharge_energy_construction
    </sql>

    <sql id="baseColumn">
        id,industry_type_name,industry_type_code,industry_subclass_name,industry_subclass_code,item_name,item_location,enterprise_name,enterprise_code,item_state,start_time,production_time,energy_design,energy_new,energy_new_plan,remark,state,userid,update_time,del_flag,dept_id
    </sql>
    <select id="getPageData" resultType="com.nantian.cloud.jljc.entity.DischargeEnergyConstruction">
        select *
        from t_discharge_energy_construction
        <trim prefix="where"  prefixOverrides="and">
            <if test="query.industryTypeCode != null">
                and industry_type_code = #{query.industryTypeCode}
            </if>
            <if test="query.industrySubclassCode != null">
                and industry_subclass_code = #{query.industrySubclassCode}
            </if>
            <if test="query.itemName != null">
                and item_name = #{query.itemName}
            </if>
            <if test="query.delFlag != null">
                and del_flag = #{query.delFlag}
            </if>
            <if test="query.itemLocation != null">
                and item_location = #{query.itemLocation}
            </if>
            <if test="query.enterpriseName != null">
                and enterprise_name = #{query.enterpriseName}
            </if>
            <if test="query.enterpriseCode != null">
                and enterprise_code = #{query.enterpriseCode}
            </if>
            <if test="query.year != null">
                and year = #{query.year}
            </if>
            <if test="query.quarter != null">
                and quarter = #{query.quarter}
            </if>
            <if test="query.id != null">
                and id = #{query.id}
            </if>
            <if test="query.state != null">
                and state = #{query.state}
            </if>
        </trim>
    </select>
    <select id="getCityData"
            resultType="com.nantian.cloud.jljc.vo.dischargeEnergy.DischargeEnergyConstructionVo">

        select d.meaning2, t2.rawSum,t2.energyDesignDlSum,t2.energyDesignDjSum,t2.energyNewPlanDlSum,t2.energyNewPlanDjSum,
         t1.*
        from t_discharge_energy_construction t1
        left join dict_region d on concat(left(t1.item_location,4),'00') = d.id
        left join (
        select left(t.item_location,4) loation,
        sum(t.energy_raw_value) rawSum,
        sum(t.energy_design_dl) energyDesignDlSum,
        sum(t.energy_design_dj) energyDesignDjSum,
        sum(t.energy_new_plan_dl) energyNewPlanDlSum,
        sum(t.energy_new_plan_dj) energyNewPlanDjSum
        from t_discharge_energy_construction t
        <trim prefix="where" prefixOverrides="and">
            <if test="query.industryTypeCode != null and query.industryTypeCode != 'null'">
                and t.industry_type_code = #{query.industryTypeCode}
            </if>
            <if test="query.industrySubclassCode != null and query.industrySubclassCode != 'null'">
                and t.industry_subclass_code = #{query.industrySubclassCode}
            </if>
            <if test="query.itemLocation != null and query.itemLocation != 'null'">
                and t.item_location like concat("%",#{query.itemLocation},"%")
            </if>
        </trim>
        group by left(t.item_location,4)
        ) t2 on left(t1.item_location,4) = t2.loation
        <trim prefix="where" prefixOverrides="and">
            <if test="query.industryTypeCode != null and query.industryTypeCode != 'null'">
                and t1.industry_type_code = #{query.industryTypeCode}
            </if>
            <if test="query.industrySubclassCode != null and query.industrySubclassCode != 'null'">
                and t1.industry_subclass_code = #{query.industrySubclassCode}
            </if>
            <if test="query.itemLocation != null and query.itemLocation != 'null'">
                and t1.item_location like concat("%",#{query.itemLocation},"%")
            </if>
        </trim>


    </select>
    <select id="getConstructionProductIndex"
            resultType="com.nantian.cloud.jljc.vo.dischargeEnergy.DischargeEnergyConstructionVo">
        select a.id,a.industry_class_name, a.industry_type_code,a.industry_subclass_code,a.item_location,a.item_name,a.item_state,a.start_time,a.production_time,a.enterprise_name,a.enterprise_code,a.remark,a.dept_id,a.state,a.year,a.quarter,a.item_invest,a.energy_raw,a.energy_raw_value,a.energy_design_dl,a.energy_design_dj,a.energy_new_plan_dl,a.energy_new_plan_dj,a.energy_coal,a.energy_electricity,a.energy_saving_effect,
        c.product_id,c.index_name,c.index_unit,c.product_energy,
        b.id pid,b.product_name,b.product_num,b.product_output1,b.product_output2,b.product_output3,b.product_output4,b.product_output5,b.energy_office,b.energy_number,b.energy_time,b.production_value,b.capacity_design
        from t_discharge_energy_construction a
        LEFT JOIN t_discharge_energy_product b ON a.id=b.item_id and b.item_type='2'
        LEFT JOIN t_discharge_energy_index c ON b.id=c.product_id
        <trim prefix="where" prefixOverrides="and">
            <if test="query.industryTypeCode != null">
                and a.industry_type_code = #{query.industryTypeCode}
            </if>
            <if test="query.industrySubclassCode != null">
                and a.industry_subclass_code = #{query.industrySubclassCode}
            </if>
            <if test="query.itemName != null">
                and a.item_name = #{query.itemName}
            </if>
            <if test="query.delFlag != null">
                and a.del_flag = #{query.delFlag}
            </if>
            <if test="query.itemLocation != null">
                and a.item_location = #{query.itemLocation}
            </if>
            <if test="query.enterpriseName != null">
                and a.enterprise_name = #{query.enterpriseName}
            </if>
            <if test="query.enterpriseCode != null">
                and a.enterprise_code = #{query.enterpriseCode}
            </if>
            <if test="query.year != null">
                and a.year = #{query.year}
            </if>
            <if test="query.quarter != null">
                and a.quarter = #{query.quarter}
            </if>
            <if test="query.id != null">
                and a.id = #{query.id}
            </if>
            <if test="query.state != null">
                and a.state = #{query.state}
            </if>
        </trim>
        ORDER BY a.id DESC
    </select>

</mapper>