<?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.ehs.mapper.TWasteDangermonthMapper">
    
    <resultMap type="TWasteDangermonth" id="TWasteDangermonthResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="month"    column="month"    />
        <result property="hazardousWasteCode"    column="hazardous_waste_code"    />
        <result property="name"    column="name"    />
        <result property="incomingQuantity"    column="incoming_quantity"    />
        <result property="transferQuantity"    column="transfer_quantity"    />
        <result property="periodStock"    column="period_stock"    />
        <result property="endStock"    column="end_stock"    />
        <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" />
        <result property="startDate"    column="month"    />
        <result property="endDate"    column="month"    />
    </resultMap>

    <sql id="selectTWasteDangermonthVo">
        select d.id, d.plant_code, d.month, d.hazardous_waste_code, d.name, d.incoming_quantity, d.transfer_quantity, d.period_stock, d.end_stock, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_waste_dangermonth d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTWasteDangermonthList" parameterType="TWasteDangermonth" resultMap="TWasteDangermonthResult">
        <include refid="selectTWasteDangermonthVo"/>
        <where>
            <if test="hazardousWasteCode != null  and hazardousWasteCode != ''"> and hazardous_waste_code like concat(concat('%', #{hazardousWasteCode}), '%')</if>
            <if test="name != null  and name != ''"> and name like concat(concat('%', #{name}), '%')</if>
            <if test="startDate != null ">and month <![CDATA[>=]]> #{startDate}</if>
            <if test="endDate != null">and month <![CDATA[<=]]>#{endDate}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>
    
    <select id="selectTWasteDangermonthById" parameterType="Long" resultMap="TWasteDangermonthResult">
        <include refid="selectTWasteDangermonthVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTWasteDangermonth" parameterType="TWasteDangermonth">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_waste_dangermonth.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_waste_dangermonth
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="month != null">month,</if>
            <if test="hazardousWasteCode != null">hazardous_waste_code,</if>
            <if test="name != null">name,</if>
            <if test="incomingQuantity != null">incoming_quantity,</if>
            <if test="transferQuantity != null">transfer_quantity,</if>
            <if test="periodStock != null">period_stock,</if>
            <if test="endStock != null">end_stock,</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="month != null">#{month},</if>
            <if test="hazardousWasteCode != null">#{hazardousWasteCode},</if>
            <if test="name != null">#{name},</if>
            <if test="incomingQuantity != null">#{incomingQuantity},</if>
            <if test="transferQuantity != null">#{transferQuantity},</if>
            <if test="periodStock != null">#{periodStock},</if>
            <if test="endStock != null">#{endStock},</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="updateTWasteDangermonth" parameterType="TWasteDangermonth">
        update t_waste_dangermonth
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="month != null">month = #{month},</if>
            <if test="hazardousWasteCode != null">hazardous_waste_code = #{hazardousWasteCode},</if>
            <if test="name != null">name = #{name},</if>
            <if test="incomingQuantity != null">incoming_quantity = #{incomingQuantity},</if>
            <if test="transferQuantity != null">transfer_quantity = #{transferQuantity},</if>
            <if test="periodStock != null">period_stock = #{periodStock},</if>
            <if test="endStock != null">end_stock = #{endStock},</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="deleteTWasteDangermonthById" parameterType="Long">
        update t_waste_dangermonth set del_flag = 2 where id = #{id}
    </update>

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