<?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.TWasteDangerdayMapper">
    
    <resultMap type="TWasteDangerday" id="TWasteDangerdayResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="name"    column="name"    />
        <result property="incomingDate"    column="incoming_date"    />
        <result property="incomingQuantity"    column="incoming_quantity"    />
        <result property="packaging"    column="packaging"    />
        <result property="containers"    column="containers"    />
        <result property="place"    column="place"    />
        <result property="deliveryQuantity"    column="delivery_quantity"    />
        <result property="handler"    column="handler"    />
        <result property="incomingTime"    column="incoming_time"    />
        <result property="receiver"    column="receiver"    />
        <result property="deliveryDirection"    column="delivery_direction"    />
        <result property="carPlate"    column="car_plate"    />
        <result property="logistics"    column="logistics"    />
        <result property="driver"    column="driver"    />
        <result property="sheetNumber"    column="sheet_number"    />
        <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="incoming_date"    />
        <result property="endDate"    column="incoming_date"    />
    </resultMap>

    <sql id="selectTWasteDangerdayVo">
        select d.id, d.plant_code, d.name, d.incoming_date, d.incoming_quantity, d.packaging, d.containers, d.place, d.delivery_quantity, d.handler, d.incoming_time, d.receiver, d.delivery_direction, d.car_plate, d.logistics, d.driver, d.sheet_number, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_waste_dangerday d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTWasteDangerdayList" parameterType="TWasteDangerday" resultMap="TWasteDangerdayResult">
        <include refid="selectTWasteDangerdayVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat(concat('%', #{name}), '%')</if>
            <if test="startDate != null ">and incoming_date <![CDATA[>=]]> #{startDate}</if>
            <if test="endDate != null">and incoming_date <![CDATA[<=]]>#{endDate}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>
    
    <select id="selectTWasteDangerdayById" parameterType="Long" resultMap="TWasteDangerdayResult">
        <include refid="selectTWasteDangerdayVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTWasteDangerday" parameterType="TWasteDangerday">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_waste_dangerday.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_waste_dangerday
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="name != null">name,</if>
            <if test="incomingDate != null">incoming_date,</if>
            <if test="incomingQuantity != null">incoming_quantity,</if>
            <if test="packaging != null">packaging,</if>
            <if test="containers != null">containers,</if>
            <if test="place != null">place,</if>
            <if test="deliveryQuantity != null">delivery_quantity,</if>
            <if test="handler != null">handler,</if>
            <if test="incomingTime != null">incoming_time,</if>
            <if test="receiver != null">receiver,</if>
            <if test="deliveryDirection != null">delivery_direction,</if>
            <if test="carPlate != null">car_plate,</if>
            <if test="logistics != null">logistics,</if>
            <if test="driver != null">driver,</if>
            <if test="sheetNumber != null">sheet_number,</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="name != null">#{name},</if>
            <if test="incomingDate != null">#{incomingDate},</if>
            <if test="incomingQuantity != null">#{incomingQuantity},</if>
            <if test="packaging != null">#{packaging},</if>
            <if test="containers != null">#{containers},</if>
            <if test="place != null">#{place},</if>
            <if test="deliveryQuantity != null">#{deliveryQuantity},</if>
            <if test="handler != null">#{handler},</if>
            <if test="incomingTime != null">#{incomingTime},</if>
            <if test="receiver != null">#{receiver},</if>
            <if test="deliveryDirection != null">#{deliveryDirection},</if>
            <if test="carPlate != null">#{carPlate},</if>
            <if test="logistics != null">#{logistics},</if>
            <if test="driver != null">#{driver},</if>
            <if test="sheetNumber != null">#{sheetNumber},</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="updateTWasteDangerday" parameterType="TWasteDangerday">
        update t_waste_dangerday
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="name != null">name = #{name},</if>
            <if test="incomingDate != null">incoming_date = #{incomingDate},</if>
            <if test="incomingQuantity != null">incoming_quantity = #{incomingQuantity},</if>
            <if test="packaging != null">packaging = #{packaging},</if>
            <if test="containers != null">containers = #{containers},</if>
            <if test="place != null">place = #{place},</if>
            <if test="deliveryQuantity != null">delivery_quantity = #{deliveryQuantity},</if>
            <if test="handler != null">handler = #{handler},</if>
            <if test="incomingTime != null">incoming_time = #{incomingTime},</if>
            <if test="receiver != null">receiver = #{receiver},</if>
            <if test="deliveryDirection != null">delivery_direction = #{deliveryDirection},</if>
            <if test="carPlate != null">car_plate = #{carPlate},</if>
            <if test="logistics != null">logistics = #{logistics},</if>
            <if test="driver != null">driver = #{driver},</if>
            <if test="sheetNumber != null">sheet_number = #{sheetNumber},</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="deleteTWasteDangerdayById" parameterType="Long">
        update t_waste_dangerday set del_flag = 2 where id = #{id}
    </update>

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