<?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.ruoyi.project.aspen.mapper.TDashboarddayMapper">

    <resultMap type="TDashboardday" id="TDashboarddayResult">
        <result property="id"    column="id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="dailyYixi"    column="daily_yixi"    />
        <result property="dailyBingxi"    column="daily_bingxi"    />
        <result property="lossRate"    column="loss_rate"    />
        <result property="energyConsumption"    column="energy_consumption"    />
        <result property="productPutput"    column="product_putput"    />
        <result property="dataDate"    column="data_date"    />
        <result property="dateDay"    column="date_day"    />
    </resultMap>

    <sql id="selectTDashboarddayVo">
        select id, del_flag, creater_code, createdate, updater_code, updatedate, daily_yixi, daily_bingxi, loss_rate, energy_consumption, product_putput, data_date, date_day from t_dashboardday
    </sql>

    <select id="selectTDashboarddayList" parameterType="TDashboardday" resultMap="TDashboarddayResult">
        <include refid="selectTDashboarddayVo"/>
        <where>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="dailyYixi != null  and dailyYixi != ''"> and daily_yixi = #{dailyYixi}</if>
            <if test="dailyBingxi != null  and dailyBingxi != ''"> and daily_bingxi = #{dailyBingxi}</if>
            <if test="lossRate != null  and lossRate != ''"> and loss_rate = #{lossRate}</if>
            <if test="energyConsumption != null  and energyConsumption != ''"> and energy_consumption = #{energyConsumption}</if>
            <if test="productPutput != null  and productPutput != ''"> and product_putput = #{productPutput}</if>
            <if test="dataDate != null "> and data_date = #{dataDate}</if>
            and del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectLast" parameterType="TDashboardday" resultMap="TDashboarddayResult">
--         select * from ( select * from t_dashboardday where del_flag = 0 order by id asc ) WHERE 32 > ROWNUM
        SELECT
            *
        FROM
            (
                SELECT
                    id,
                    LOSS_PERCENTAGE AS loss_rate,
                    ETHYLEN_PRODUCED AS product_putput,
                    TOTAL_CRACKER_KGCE AS energy_consumption,
                    REPORT_DATE,
                    EXTRACT( DAY FROM REPORT_DATE ) AS date_day
                FROM
                    t_daily_production_report
                ORDER BY
                    REPORT_DATE DESC
            )
        WHERE
            32 > ROWNUM
        ORDER BY REPORT_DATE ASC
    </select>

    <select id="selectTDashboarddayById" parameterType="Long" resultMap="TDashboarddayResult">
        <include refid="selectTDashboarddayVo"/>
        where id = #{id}
    </select>

    <insert id="insertTDashboardday" parameterType="TDashboardday">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_dashboardday.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_dashboardday
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="dailyYixi != null">daily_yixi,</if>
            <if test="dailyBingxi != null">daily_bingxi,</if>
            <if test="lossRate != null">loss_rate,</if>
            <if test="energyConsumption != null">energy_consumption,</if>
            <if test="productPutput != null">product_putput,</if>
            <if test="dataDate != null">data_date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="dailyYixi != null">#{dailyYixi},</if>
            <if test="dailyBingxi != null">#{dailyBingxi},</if>
            <if test="lossRate != null">#{lossRate},</if>
            <if test="energyConsumption != null">#{energyConsumption},</if>
            <if test="productPutput != null">#{productPutput},</if>
            <if test="dataDate != null">#{dataDate},</if>
         </trim>
    </insert>

    <update id="updateTDashboardday" parameterType="TDashboardday">
        update t_dashboardday
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="dailyYixi != null">daily_yixi = #{dailyYixi},</if>
            <if test="dailyBingxi != null">daily_bingxi = #{dailyBingxi},</if>
            <if test="lossRate != null">loss_rate = #{lossRate},</if>
            <if test="energyConsumption != null">energy_consumption = #{energyConsumption},</if>
            <if test="productPutput != null">product_putput = #{productPutput},</if>
            <if test="dataDate != null">data_date = #{dataDate},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTDashboarddayById" parameterType="Long">
        update t_dashboardday set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTDashboarddayByIds" parameterType="String">
        update t_dashboardday set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>
