<?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.TWasteDangerMapper">
    
    <resultMap type="TWasteDanger" id="TWasteDangerResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="name"    column="name"    />
        <result property="category"    column="category"    />
        <result property="code"    column="code"    />
        <result property="description"    column="description"    />
        <result property="disposalMode"    column="disposal_mode"    />
        <result property="productLink"    column="product_link"    />
        <result property="storagePlace"    column="storage_place"    />
        <result property="disposalDestination"    column="disposal_destination"    />
        <result property="hazardsSpec"    column="hazards_spec"    />
        <result property="owner"    column="owner"    />
        <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="selectTWasteDangerVo">
        select d.id, d.plant_code, d.name, d.category, d.code, d.description, d.disposal_mode, d.product_link, d.storage_place, d.disposal_destination, d.hazards_spec, d.owner, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_waste_danger d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTWasteDangerList" parameterType="TWasteDanger" resultMap="TWasteDangerResult">
        <include refid="selectTWasteDangerVo"/>
        <where>  
            <if test="plantCode != null  and plantCode != ''"> and plant_code = #{plantCode}</if>
            <if test="name != null  and name != ''"> and name like concat(concat('%', #{name}), '%')</if>
            <if test="category != null  and category != ''"> and category like concat(concat('%', #{category}), '%')</if>
            <if test="code != null  and code != ''"> and code like concat(concat('%', #{code}), '%')</if>
            <if test="description != null  and description != ''"> and description like concat(concat('%', #{description}), '%')</if>
            <if test="disposalMode != null  and disposalMode != ''"> and disposal_mode like concat(concat('%', #{disposalMode}), '%')</if>
            <if test="productLink != null  and productLink != ''"> and product_link like concat(concat('%', #{productLink}), '%')</if>
            <if test="storagePlace != null  and storagePlace != ''"> and storage_place like concat(concat('%', #{storagePlace}), '%')</if>
            <if test="disposalDestination != null  and disposalDestination != ''"> and disposal_destination like concat(concat('%', #{disposalDestination}), '%')</if>
            <if test="hazardsSpec != null  and hazardsSpec != ''"> and hazards_spec like concat(concat('%', #{hazardsSpec}), '%')</if>
            <if test="owner != null  and owner != ''"> and owner like concat(concat('%', #{owner}), '%')</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>
    
    <select id="selectTWasteDangerById" parameterType="Long" resultMap="TWasteDangerResult">
        <include refid="selectTWasteDangerVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTWasteDanger" parameterType="TWasteDanger">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_waste_danger.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_waste_danger
        <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="category != null">category,</if>
            <if test="code != null">code,</if>
            <if test="description != null">description,</if>
            <if test="disposalMode != null">disposal_mode,</if>
            <if test="productLink != null">product_link,</if>
            <if test="storagePlace != null">storage_place,</if>
            <if test="disposalDestination != null">disposal_destination,</if>
            <if test="hazardsSpec != null">hazards_spec,</if>
            <if test="owner != null">owner,</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="category != null">#{category},</if>
            <if test="code != null">#{code},</if>
            <if test="description != null">#{description},</if>
            <if test="disposalMode != null">#{disposalMode},</if>
            <if test="productLink != null">#{productLink},</if>
            <if test="storagePlace != null">#{storagePlace},</if>
            <if test="disposalDestination != null">#{disposalDestination},</if>
            <if test="hazardsSpec != null">#{hazardsSpec},</if>
            <if test="owner != null">#{owner},</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="updateTWasteDanger" parameterType="TWasteDanger">
        update t_waste_danger
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="name != null">name = #{name},</if>
            <if test="category != null">category = #{category},</if>
            <if test="code != null">code = #{code},</if>
            <if test="description != null">description = #{description},</if>
            <if test="disposalMode != null">disposal_mode = #{disposalMode},</if>
            <if test="productLink != null">product_link = #{productLink},</if>
            <if test="storagePlace != null">storage_place = #{storagePlace},</if>
            <if test="disposalDestination != null">disposal_destination = #{disposalDestination},</if>
            <if test="hazardsSpec != null">hazards_spec = #{hazardsSpec},</if>
            <if test="owner != null">owner = #{owner},</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="deleteTWasteDangerById" parameterType="Long">
        update t_waste_danger set del_flag = 2 where id = #{id}
    </update>

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