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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jljc.entity.TReportEnergyProject">
        <id column="id" property="id"/>
        <result column="report_id" property="reportId"/>
        <result column="name" property="name"/>
        <result column="content" property="content"/>
        <result column="money" property="money"/>
        <result column="energy_saving_effect" property="energySavingEffect"/>
        <result column="status" property="status"/>
        <result column="progress" property="progress"/>
        <result column="audit_department" property="auditDepartment"/>
        <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="project_type" property="projectType"/>
        <result column="poject_classification" property="pojectClassification"/>
        <result column="start_time" property="startTime"/>
        <result column="end_time" property="endTime"/>
        <result column="energy_json" property="energyJson"/>
        <!--<result column="energy_year" property="energyYear"/>-->
        <!--<result column="action" property="action"/>-->
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, report_id, name, content, money, energy_saving_effect, status, progress, audit_department,
         userid, update_time, del_flag, dept_id, project_type, poject_classification, start_time, end_time, energy_json
    </sql>

    <select id="queryList" resultType="com.nantian.cloud.jljc.entity.TReportEnergyProject">
        SELECT
        p.*,t.year as year,ee.enterprise_name as enterpriseName
        FROM
        t_report_energy_project p
        LEFT JOIN t_report t ON p.report_id = t.id
        left join (select e.* from t_report_enterprise e left join t_report tt on e.enterprise_code=tt.enterprise_code where tt.year=e.year and tt.year=#{query.modelYear} and tt.type='5') ee
        on ee.enterprise_code=t.enterprise_code
        where p.del_flag='1' and t.del_flag='1'
        <if test="query.reportId != null" >
            and p.report_id = #{query.reportId}
        </if>
        <if test="query.modelYear != null" >
            and t.year = #{query.modelYear}
        </if>
        <if test="query.modeEpc != null and query.modeEpc !=''" >
            and t.enterprise_code LIKE CONCAT('%',#{query.modeEpc}, '%')
        </if>
        <if test="query.modeCmpName != null and query.modeCmpName !=''" >
            and ee.enterprise_name LIKE CONCAT('%',#{query.modeCmpName}, '%')
        </if>
        <if test="query.modeClassification != null and query.modeClassification !=''" >
            and p.poject_classification LIKE  CONCAT('%',#{query.modeClassification}, '%')
        </if>
        <if test="query.modeType != null and query.modeType !=''" >
            and p.project_type LIKE  CONCAT('%',#{query.modeType}, '%')
        </if>
        <if test="query.modeName != null and query.modeName !=''" >
            and p.name LIKE CONCAT('%',#{query.modeName}, '%')
        </if>
    </select>

    <select id="getProjectByReportId" resultType="com.nantian.cloud.jljc.entity.TReportEnergyProject">
        select <include refid="Base_Column_List"></include>
        from t_report_energy_project
        where report_id = #{reportId} and del_flag = "1"
    </select>
    <select id="getProjectTypeList" resultType="com.nantian.cloud.jljc.entity.TReportEnergyProject">
        select distinct project_type
        from t_report_energy_project
        where del_flag = "1"
    </select>

    <select id="getByYear" resultType="com.nantian.cloud.jljc.entity.TReportEnergyProject">
        SELECT distinct
        p.*,t.year as year,ee.enterprise_name as enterpriseName
        FROM
        t_report_energy_project p
        LEFT JOIN t_report t ON p.report_id = t.id
        left join (select e.* from t_report_enterprise e left join t_report tt on e.enterprise_code=tt.enterprise_code where tt.year=e.year and tt.year=#{query.modelYear} and tt.type='5') ee
        on ee.enterprise_code=t.enterprise_code
        where p.del_flag='1' and t.del_flag='1'
        <if test="query.reportId != null" >
            and p.report_id = #{query.reportId}
        </if>
        <if test="query.modelYear != null" >
            and t.year = #{query.modelYear}
        </if>
        <if test="query.modeEpc != null and query.modeEpc !=''" >
            and t.enterprise_code LIKE CONCAT('%',#{query.modeEpc}, '%')
        </if>
        <if test="query.modeCmpName != null and query.modeCmpName !=''" >
            and ee.enterprise_name LIKE CONCAT('%',#{query.modeCmpName}, '%')
        </if>
        <if test="query.modeClassification != null and query.modeClassification !=''" >
            and p.poject_classification LIKE  CONCAT('%',#{query.modeClassification}, '%')
        </if>
        <if test="query.modeType != null and query.modeType !=''" >
            and p.project_type LIKE  CONCAT('%',#{query.modeType}, '%')
        </if>
        <if test="query.modeName != null and query.modeName !=''" >
            and p.name LIKE CONCAT('%',#{query.modeName}, '%')
        </if>
    </select>


</mapper>
