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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jljc.entity.TReportProduct">
        <id column="id" property="id"/>
        <result column="report_id" property="reportId"/>
        <result column="product_num" property="productNum"/>
        <result column="product_name" property="productName"/>
        <result column="capacity_num" property="capacityNum"/>
        <result column="capacity_unit" property="capacityUnit"/>
        <result column="yield_num" property="yieldNum"/>
        <result column="yield_unit" property="yieldUnit"/>
        <result column="energy_consumption" property="energyConsumption"/>
        <result column="energy_consumption_unit" property="energyConsumptionUnit"/>
        <result column="unit_energy_consumption" property="unitEnergyConsumption"/>
        <result column="unit_energy_consumption_unit" property="unitEnergyConsumptionUnit"/>
        <result column="unit_energy_consumption_old_old" property="unitEnergyConsumptionOldOld"/>
        <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, product_num, product_name, capacity_num, capacity_unit, yield_num, yield_unit,
        energy_consumption, energy_consumption_unit, unit_energy_consumption,
        unit_energy_consumption_unit, userid, update_time, del_flag, dept_id, unit_energy_consumption_old_old
    </sql>

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

    <select id="getProductName" resultType="java.lang.String">
        select distinct product_name from t_report_product where report_id = #{reportId} and del_flag = "1"
    </select>

    <select id="getProductsByReportIds" resultType="com.nantian.cloud.jljc.entity.TReportProduct">
        select p.*, t.year as year
        from t_report_product p left join t_report t on p.report_id = t.id
        where p.report_id = #{id1} and p.del_flag = "1"
        union
        select p.*, t.year as year
        from t_report_product p left join t_report t on p.report_id = t.id
        where p.report_id = #{id2} and p.del_flag = "1"
        union
        select p.*, t.year as year
        from t_report_product p left join t_report t on p.report_id = t.id
        where p.report_id = #{id3} and p.del_flag = "1"
    </select>

</mapper>
