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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jljc.entity.TSupervisionComprehensiveEnergy">
        <id column="id" property="id" />
        <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="monitor_id" property="monitorId" />
        <result column="remark" property="remark" />
        <result column="type" property="type" />
        <result column="code" property="code" />
        <result column="energy_name" property="energyName" />
        <result column="equal_modulus" property="equalModulus" />
        <result column="tce" property="tce" />
        <result column="unit_modulus" property="unitModulus" />
        <result column="unit_energy_consumption" property="unitEnergyConsumption" />
        <result column="year" property="year" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, userid, update_time, del_flag, dept_id, monitor_id, remark, type, code, energy_name, equal_modulus,
        tce, unit_modulus, unit_energy_consumption,year
    </sql>

    <select id="getByUnitEnergyId" resultType="map">
        select t1.monitored_ent,t.monitor_id,t.year,sum(t.tce) as tce,t1.epc,t1.industry,t1.locate,t1.inspectors,t1.source,t1.task_handle,t1.type
        from (
            select monitor_id, type, year, case when type in ('0','1','5','6') then tce when type in ('2','3','4') then tce*-1 else 0 end tce from  t_supervision_comprehensive_energy
        ) t join   t_supervise_task t1 on t.monitor_id=t1.monitor_id where t.monitor_id=#{query.monitorId}
        group by t.monitor_id, t.year
    </select>

</mapper>
