<?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.production.mapper.TFivesRegionMapper">

    <resultMap type="TFivesRegion" id="TFivesRegionResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="orderNo"    column="order_no"    />
        <result property="position"    column="position"    />
        <result property="personLiable"    column="person_liable"    />
        <result property="roomNo"    column="room_no"    />
        <result property="fileId"    column="file_id"    />
        <result property="remarks"    column="remarks"    />
        <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="inSys"    column="in_sys"    />
        <result property="personFile"    column="person_file"    />
        <result property="staffId"    column="staff_id"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTFivesRegionVo">
        select d.id, d.plant_code, d.order_no, d.position, d.person_liable, d.room_no, d.file_id, d.remarks, d.status, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.in_sys, d.person_file, d.staff_id ,s.dept_name from t_fives_region d
                                                                                                                                                                                                                                                                    left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTFivesRegionList" parameterType="TFivesRegion" resultMap="TFivesRegionResult">
        <include refid="selectTFivesRegionVo"/>
        <where>
            <if test="plantCode != null  and plantCode != ''"> and plant_code = #{plantCode}</if>
            <if test="orderNo != null  and orderNo != ''"> and order_no = #{orderNo}</if>
            <if test="position != null  and position != ''"> and position = #{position}</if>
            <if test="personLiable != null  and personLiable != ''"> and person_liable = #{personLiable}</if>
            <if test="roomNo != null  and roomNo != ''"> and room_no = #{roomNo}</if>
            <if test="fileId != null  and fileId != ''"> and file_id = #{fileId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="inSys != null  and inSys != ''"> and in_sys = #{inSys}</if>
            <if test="personFile != null  and personFile != ''"> and person_file = #{personFile}</if>
            <if test="staffId != null  and staffId != ''"> and staff_id = #{staffId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by createdate desc
    </select>

    <select id="selectTFivesRegionById" parameterType="Long" resultMap="TFivesRegionResult">
        <include refid="selectTFivesRegionVo"/>
        where id = #{id}
    </select>

    <insert id="insertTFivesRegion" parameterType="TFivesRegion">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_fives_region.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_fives_region
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null">plant_code,</if>
            <if test="orderNo != null">order_no,</if>
            <if test="position != null">position,</if>
            <if test="personLiable != null">person_liable,</if>
            <if test="roomNo != null">room_no,</if>
            <if test="fileId != null">file_id,</if>
            <if test="remarks != null">remarks,</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="inSys != null">in_sys,</if>
            <if test="personFile != null">person_file,</if>
            <if test="staffId != null">staff_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null">#{plantCode},</if>
            <if test="orderNo != null">#{orderNo},</if>
            <if test="position != null">#{position},</if>
            <if test="personLiable != null">#{personLiable},</if>
            <if test="roomNo != null">#{roomNo},</if>
            <if test="fileId != null">#{fileId},</if>
            <if test="remarks != null">#{remarks},</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="inSys != null">#{inSys},</if>
            <if test="personFile != null">#{personFile},</if>
            <if test="staffId != null">#{staffId},</if>
        </trim>
    </insert>

    <update id="updateTFivesRegion" parameterType="TFivesRegion">
        update t_fives_region
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null">plant_code = #{plantCode},</if>
            <if test="orderNo != null">order_no = #{orderNo},</if>
            <if test="position != null">position = #{position},</if>
            <if test="personLiable != null">person_liable = #{personLiable},</if>
            <if test="roomNo != null">room_no = #{roomNo},</if>
            <if test="fileId != null and fileId != ''">file_id = #{fileId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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="inSys != null">in_sys = #{inSys},</if>
            <if test="personFile != null and personFile != ''">person_file = #{personFile},</if>
            <if test="staffId != null and staffId != ''">staff_id = #{staffId},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
