<?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.TMatterProtectMapper">

    <resultMap type="TMatterProtect" id="TMatterProtectResult">
        <result property="id" column="id"/>
        <result property="conservatoryMeasureName" column="conservatory_measure_name"/>
        <result property="conservatoryMeasureCode" column="conservatory_measure_code"/>
        <result property="conservatoryMeasureNo" column="conservatory_measure_no"/>
        <result property="conservatoryMeasureContent" column="conservatory_measure_content"/>
        <result property="deptName" column="dept_name"/>
    </resultMap>

    <select id="queryByIds" resultMap="TMatterProtectResult">
        select d.id, d.conservatory_measure_name, d.conservatory_measure_code, d.conservatory_measure_no,
        d.conservatory_measure_content
        from t_matter_protect d
        where
        d.id in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>

    </select>

    <sql id="selectTMatterProtectVo">
        select d.id, d.conservatory_measure_name, d.conservatory_measure_code, d.conservatory_measure_no, s.dept_name
        from t_matter_protect d
                 left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTMatterProtectList" parameterType="TMatterProtect" resultMap="TMatterProtectResult">
        <include refid="selectTMatterProtectVo"/>
        <where>
            <if test="conservatoryMeasureName != null  and conservatoryMeasureName != ''">and conservatory_measure_name
                like concat(concat('%', #{conservatoryMeasureName}), '%')
            </if>
            <if test="conservatoryMeasureCode != null  and conservatoryMeasureCode != ''">and conservatory_measure_code
                = #{conservatoryMeasureCode}
            </if>
            <if test="conservatoryMeasureNo != null  and conservatoryMeasureNo != ''">and conservatory_measure_no =
                #{conservatoryMeasureNo}
            </if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTMatterProtectById" parameterType="Long" resultMap="TMatterProtectResult">
        <include refid="selectTMatterProtectVo"/>
        where id = #{id}
    </select>

    <insert id="insertTMatterProtect" parameterType="TMatterProtect">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_matter_protect.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_matter_protect
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="conservatoryMeasureName != null and conservatoryMeasureName != ''">conservatory_measure_name,</if>
            <if test="conservatoryMeasureCode != null">conservatory_measure_code,</if>
            <if test="conservatoryMeasureNo != null">conservatory_measure_no,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="conservatoryMeasureName != null and conservatoryMeasureName != ''">#{conservatoryMeasureName},
            </if>
            <if test="conservatoryMeasureCode != null">#{conservatoryMeasureCode},</if>
            <if test="conservatoryMeasureNo != null">#{conservatoryMeasureNo},</if>
        </trim>
    </insert>

    <update id="updateTMatterProtect" parameterType="TMatterProtect">
        update t_matter_protect
        <trim prefix="SET" suffixOverrides=",">
            <if test="conservatoryMeasureName != null and conservatoryMeasureName != ''">conservatory_measure_name =
                #{conservatoryMeasureName},
            </if>
            <if test="conservatoryMeasureCode != null">conservatory_measure_code = #{conservatoryMeasureCode},</if>
            <if test="conservatoryMeasureNo != null">conservatory_measure_no = #{conservatoryMeasureNo},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>