<?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.process.mapper.TAlarmmodifyMapper">

    <resultMap type="TAlarmmodify" id="TAlarmmodifyResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="time"    column="time"    />
        <result property="area"    column="area"    />
        <result property="contents"    column="contents"    />
        <result property="applicant"    column="applicant"    />
        <result property="reviewer"    column="reviewer"    />
        <result property="approver"    column="approver"    />
        <result property="executor"    column="executor"    />
        <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="time"    />
        <result property="endDate"    column="time"    />
    </resultMap>

    <sql id="selectTAlarmmodifyVo">
        select d.id, d.plant_code, d.time, d.area, d.contents, d.applicant, d.reviewer, d.approver, d.executor, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_alarmmodify d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTAlarmmodifyList" parameterType="TAlarmmodify" resultMap="TAlarmmodifyResult">
        <include refid="selectTAlarmmodifyVo"/>
        <where>
            <if test="area != null  and area != ''"> and area like concat(concat('%', #{area}), '%')</if>
            <if test="contents != null  and contents != ''"> and contents like concat(concat('%', #{contents}), '%')</if>
            <if test="startDate != null ">and time <![CDATA[>=]]> #{startDate}</if>
            <if test="endDate != null">and time <![CDATA[<=]]>#{endDate}</if>
            <if test="areas != null  and areas != ''">
                and
                d.area in
                <foreach collection="areas.split(',')" item="item" index="index"
                         open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>

    <select id="selectTAlarmmodifyById" parameterType="Long" resultMap="TAlarmmodifyResult">
        <include refid="selectTAlarmmodifyVo"/>
        where id = #{id}
    </select>

    <insert id="insertTAlarmmodify" parameterType="TAlarmmodify">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_alarmmodify.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_alarmmodify
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="time != null">time,</if>
            <if test="area != null">area,</if>
            <if test="contents != null">contents,</if>
            <if test="applicant != null">applicant,</if>
            <if test="reviewer != null">reviewer,</if>
            <if test="approver != null">approver,</if>
            <if test="executor != null">executor,</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="time != null">#{time},</if>
            <if test="area != null">#{area},</if>
            <if test="contents != null">#{contents},</if>
            <if test="applicant != null">#{applicant},</if>
            <if test="reviewer != null">#{reviewer},</if>
            <if test="approver != null">#{approver},</if>
            <if test="executor != null">#{executor},</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="updateTAlarmmodify" parameterType="TAlarmmodify">
        update t_alarmmodify
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="time != null">time = #{time},</if>
            <if test="area != null">area = #{area},</if>
            <if test="contents != null">contents = #{contents},</if>
            <if test="applicant != null">applicant = #{applicant},</if>
            <if test="reviewer != null">reviewer = #{reviewer},</if>
            <if test="approver != null">approver = #{approver},</if>
            <if test="executor != null">executor = #{executor},</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="deleteTAlarmmodifyById" parameterType="Long">
        update t_alarmmodify set del_flag = 2 where id = #{id}
    </update>

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

</mapper>
