<?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.production.mapper.TLbnhjstjMapper">

    <resultMap type="TLbnhjstj" id="TLbnhjstjResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="starttime"    column="starttime"    />
        <result property="endtime"    column="endtime"    />
        <result property="team"    column="team"    />
        <result property="correcenergysaving"    column="correcenergysaving"    />
        <result property="ethyleneprocd"    column="ethyleneprocd"    />
        <result property="ethyenergyconsump"    column="ethyenergyconsump"    />
        <result property="btxprocd"    column="btxprocd"    />
        <result property="btxenergyconsump"    column="btxenergyconsump"    />
        <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="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTLbnhjstjVo">
        select d.id, d.plant_code, d.starttime, d.endtime, d.team, d.correcenergysaving, d.ethyleneprocd, d.ethyenergyconsump, d.btxprocd, d.btxenergyconsump, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_lbnhjstj d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTLbnhjstjList" parameterType="TLbnhjstj" resultMap="TLbnhjstjResult">
        <include refid="selectTLbnhjstjVo"/>
        <where>
            <if test="starttime != null "> and starttime = #{starttime}</if>
            <if test="endtime != null "> and endtime = #{endtime}</if>
            <if test="team != null  and team != ''"> and team = #{team}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        <if test="sortOrder == 'desc'">
            <if test="sortDate == 'correcenergysaving'"> ORDER BY correcenergysaving desc</if>
            <if test="sortDate == 'ethyleneprocd'"> ORDER BY ethyleneprocd desc</if>
            <if test="sortDate == 'ethyenergyconsump'"> ORDER BY ethyenergyconsump desc</if>
            <if test="sortDate == 'btxprocd'"> ORDER BY btxprocd desc</if>
            <if test="sortDate == 'btxenergyconsump'"> ORDER BY btxenergyconsump desc</if>
        </if>
        <if test="sortOrder == 'asc'">
            <if test="sortDate == 'correcenergysaving'"> ORDER BY correcenergysaving asc</if>
            <if test="sortDate == 'ethyleneprocd'"> ORDER BY ethyleneprocd asc</if>
            <if test="sortDate == 'ethyenergyconsump'"> ORDER BY ethyenergyconsump asc</if>
            <if test="sortDate == 'btxprocd'"> ORDER BY btxprocd asc</if>
            <if test="sortDate == 'btxenergyconsump'"> ORDER BY btxenergyconsump asc</if>
        </if>
    </select>

    <select id="selectTLbnhjstjById" parameterType="Long" resultMap="TLbnhjstjResult">
        <include refid="selectTLbnhjstjVo"/>
        where id = #{id}
    </select>

    <insert id="insertTLbnhjstj" parameterType="TLbnhjstj">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_lbnhjstj.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_lbnhjstj
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="starttime != null">starttime,</if>
            <if test="endtime != null">endtime,</if>
            <if test="team != null">team,</if>
            <if test="correcenergysaving != null">correcenergysaving,</if>
            <if test="ethyleneprocd != null">ethyleneprocd,</if>
            <if test="ethyenergyconsump != null">ethyenergyconsump,</if>
            <if test="btxprocd != null">btxprocd,</if>
            <if test="btxenergyconsump != null">btxenergyconsump,</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="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="starttime != null">#{starttime},</if>
            <if test="endtime != null">#{endtime},</if>
            <if test="team != null">#{team},</if>
            <if test="correcenergysaving != null">#{correcenergysaving},</if>
            <if test="ethyleneprocd != null">#{ethyleneprocd},</if>
            <if test="ethyenergyconsump != null">#{ethyenergyconsump},</if>
            <if test="btxprocd != null">#{btxprocd},</if>
            <if test="btxenergyconsump != null">#{btxenergyconsump},</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="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
        </trim>
    </insert>

    <update id="updateTLbnhjstj" parameterType="TLbnhjstj">
        update t_lbnhjstj
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="starttime != null">starttime = #{starttime},</if>
            <if test="endtime != null">endtime = #{endtime},</if>
            <if test="team != null">team = #{team},</if>
            <if test="correcenergysaving != null">correcenergysaving = #{correcenergysaving},</if>
            <if test="ethyleneprocd != null">ethyleneprocd = #{ethyleneprocd},</if>
            <if test="ethyenergyconsump != null">ethyenergyconsump = #{ethyenergyconsump},</if>
            <if test="btxprocd != null">btxprocd = #{btxprocd},</if>
            <if test="btxenergyconsump != null">btxenergyconsump = #{btxenergyconsump},</if>
            <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="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>