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

    <resultMap type="TConfRoom" id="TConfRoomResult">
        <result property="id"    column="id"    />
        <result property="roomName"    column="room_name"    />
        <result property="areaName"    column="area_name"    />
        <result property="roomCapacity"    column="room_capacity"    />
        <result property="deviceList"    column="device_list"    />
        <result property="roomManageUser"    column="room_manage_user"    />
        <result property="roomManageName"    column="room_manage_name"    />
        <result property="status"    column="status"    />
        <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="roomPic"    column="room_pic"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTConfRoomVo">
        select d.id, d.room_name, d.area_name, d.room_capacity, d.device_list, d.room_manage_user, d.room_manage_name, d.status, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks, d.room_pic ,s.dept_name from t_conf_room d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTConfRoomList" parameterType="TConfRoom" resultMap="TConfRoomResult">
        <include refid="selectTConfRoomVo"/>
        <where>
            <if test="roomName != null  and roomName != ''"> and room_name like concat(concat('%', #{roomName}), '%')</if>
            <if test="areaName != null  and areaName != ''"> and area_name like concat(concat('%', #{areaName}), '%')</if>
            <if test="roomCapacity != null "> and room_capacity = #{roomCapacity}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTConfRoomById" parameterType="Long" resultMap="TConfRoomResult">
        <include refid="selectTConfRoomVo"/>
        where id = #{id}
    </select>

    <insert id="insertTConfRoom" parameterType="TConfRoom">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_conf_room.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_conf_room
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="roomName != null and roomName != ''">room_name,</if>
            <if test="areaName != null">area_name,</if>
            <if test="roomCapacity != null">room_capacity,</if>
            <if test="deviceList != null">device_list,</if>
            <if test="roomManageUser != null">room_manage_user,</if>
            <if test="roomManageName != null">room_manage_name,</if>
            <if test="status != null">status,</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="roomPic != null">room_pic,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="roomName != null and roomName != ''">#{roomName},</if>
            <if test="areaName != null">#{areaName},</if>
            <if test="roomCapacity != null">#{roomCapacity},</if>
            <if test="deviceList != null">#{deviceList},</if>
            <if test="roomManageUser != null">#{roomManageUser},</if>
            <if test="roomManageName != null">#{roomManageName},</if>
            <if test="status != null">#{status},</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="roomPic != null">#{roomPic},</if>
         </trim>
    </insert>

    <update id="updateTConfRoom" parameterType="TConfRoom">
        update t_conf_room
        <trim prefix="SET" suffixOverrides=",">
            <if test="roomName != null and roomName != ''">room_name = #{roomName},</if>
            <if test="areaName != null">area_name = #{areaName},</if>
            <if test="roomCapacity != null">room_capacity = #{roomCapacity},</if>
            <if test="deviceList != null">device_list = #{deviceList},</if>
            <if test="roomManageUser != null">room_manage_user = #{roomManageUser},</if>
            <if test="roomManageName != null">room_manage_name = #{roomManageName},</if>
            <if test="status != null">status = #{status},</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="roomPic != null">room_pic = #{roomPic},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
