<?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.plant.mapper.TMtEhsopenitemMapper">

    <resultMap type="TMtEhsopenitem" id="TMtEhsopenitemResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="category"    column="category"    />
        <result property="notopen"    column="notopen"    />
        <result property="closed"    column="closed"    />
        <result property="expired"    column="expired"    />
        <result property="inputdate"    column="inputdate"    />
        <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="meetingId"    column="meeting_id"    />
        <result property="isHis"    column="is_his"    />
        <result property="deptName" column="dept_name" />
        <result property="isNew" column="is_new" />
    </resultMap>

    <sql id="selectTMtEhsopenitemVo">
        select d.id,d.is_new, d.plant_code, d.category, d.notopen, d.closed, d.expired, d.inputdate, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks , d.meeting_id, d.is_his ,s.dept_name from t_mt_ehsopenitem d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTMtEhsopenitemList" parameterType="TMtEhsopenitem" resultMap="TMtEhsopenitemResult">
        <include refid="selectTMtEhsopenitemVo"/>
        <where>
            <if test="category != null  and category != ''"> and category like concat(concat('%', #{category}), '%')</if>
            <if test="notopen != null "> and notopen like concat(concat('%', #{notopen}), '%')</if>
            <if test="closed != null "> and closed like concat(concat('%', #{closed}), '%')</if>
            <if test="expired != null "> and expired like concat(concat('%', #{expired}), '%')</if>
            <if test="meetingId != null  and meetingId != ''"> and meeting_id = #{meetingId}</if>
            <if test="meetingId == null  or meetingId == ''"> and is_his = 0</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.createdate desc
    </select>

    <select id="selectTMtEhsopenitemById" parameterType="Long" resultMap="TMtEhsopenitemResult">
        <include refid="selectTMtEhsopenitemVo"/>
        where id = #{id}
    </select>

    <insert id="insertTMtEhsopenitem" parameterType="TMtEhsopenitem">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_mt_ehsopenitem.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_mt_ehsopenitem
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null">plant_code,</if>
            <if test="category != null">category,</if>
            <if test="notopen != null">notopen,</if>
            <if test="closed != null">closed,</if>
            <if test="expired != null">expired,</if>
            <if test="inputdate != null">inputdate,</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>
            <if test="meetingId != null">meeting_id,</if>
            <if test="isHis != null">is_his,</if>
            <if test="isNew != null">is_new,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null">#{plantCode},</if>
            <if test="category != null">#{category},</if>
            <if test="notopen != null">#{notopen},</if>
            <if test="closed != null">#{closed},</if>
            <if test="expired != null">#{expired},</if>
            <if test="inputdate != null">#{inputdate},</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>
            <if test="meetingId != null">#{meetingId},</if>
            <if test="isHis != null">#{isHis},</if>
            <if test="isNew != null">#{isNew},</if>
         </trim>
    </insert>

    <update id="updateTMtEhsopenitem" parameterType="TMtEhsopenitem">
        update t_mt_ehsopenitem
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null">plant_code = #{plantCode},</if>
            <if test="category != null">category = #{category},</if>
            <if test="notopen != null">notopen = #{notopen},</if>
            <if test="closed != null">closed = #{closed},</if>
            <if test="expired != null">expired = #{expired},</if>
            <if test="inputdate != null">inputdate = #{inputdate},</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>
            <if test="meetingId != null">meeting_id = #{meetingId},</if>
            <if test="isHis != null">is_his = #{isHis},</if>
            <if test="isNew != null">is_new = #{isNew},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
