<?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.apply.mapper.TApplyLockMapper">

    <resultMap type="TApplyLock" id="TApplyLockResult">
        <result property="id"    column="id"    />
        <result property="unit"    column="unit"    />
        <result property="lockPost"    column="lock_post"    />
        <result property="pidNo"    column="pid_no"    />
        <result property="lockCode"    column="lock_code"    />
        <result property="medium"    column="medium"    />
        <result property="position"    column="position"    />
        <result property="reason"    column="reason"    />
        <result property="technology"    column="technology"    />
        <result property="riskLevel"    column="risk_level"    />
        <result property="lockSize"    column="lock_size"    />
        <result property="remarks"    column="remarks"    />
        <result property="status"    column="status"    />
        <result property="valveStatus"    column="valve_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="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTApplyLockVo">
        select d.id, d.unit, d.lock_post, d.pid_no, d.lock_code, d.medium, d.position, d.reason, d.technology, d.risk_level, d.lock_size, d.remarks, d.status, d.valve_status, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id ,s.dept_name from t_apply_lock d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTApplyLockList" parameterType="TApplyLock" resultMap="TApplyLockResult">
        <include refid="selectTApplyLockVo"/>
        <where>
            <if test="unit != null  and unit != ''"> and unit  like concat(concat('%',#{unit}),'%')</if>
            <if test="lockPost != null  and lockPost != ''"> and lock_post = #{lockPost}</if>
            <if test="pidNo != null  and pidNo != ''"> and pid_no  like concat(concat('%', #{pidNo}),'%')</if>
            <if test="lockCode != null  and lockCode != ''"> and lock_code  like concat(concat('%',#{lockCode}),'%')</if>
            <if test="medium != null  and medium != ''"> and medium  like concat(concat('%',#{medium}),'%')</if>
            <if test="position != null  and position != ''"> and position  like concat(concat('%',#{position}),'%')</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
            <if test="technology != null  and technology != ''"> and technology = #{technology}</if>
            <if test="riskLevel != null  and riskLevel != ''"> and risk_level = #{riskLevel}</if>
            <if test="lockSize != null  and lockSize != ''"> and lock_size = #{lockSize}</if>
            <if test="remarks != null  and remarks != ''"> and d.remarks = #{remarks}</if>
            <if test="status != null "> and d.status = #{status}</if>
            <if test="valveStatus != null "> and valve_status = #{valveStatus}</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>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by createdate asc
    </select>

    <select id="selectTApplyLockById" parameterType="Long" resultMap="TApplyLockResult">
        <include refid="selectTApplyLockVo"/>
        where id = #{id}
    </select>

    <select id="selectTApplyLockByLockCode" parameterType="String" resultMap="TApplyLockResult">
        <include refid="selectTApplyLockVo"/>
        where lock_code =#{lockCode}
    </select>

    <insert id="insertTApplyLock" parameterType="TApplyLock">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_apply_lock.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_apply_lock
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="unit != null">unit,</if>
            <if test="lockPost != null">lock_post,</if>
            <if test="pidNo != null">pid_no,</if>
            <if test="lockCode != null">lock_code,</if>
            <if test="medium != null">medium,</if>
            <if test="position != null">position,</if>
            <if test="reason != null">reason,</if>
            <if test="technology != null">technology,</if>
            <if test="riskLevel != null">risk_level,</if>
            <if test="lockSize != null">lock_size,</if>
            <if test="remarks != null">remarks,</if>
            <if test="status != null">status,</if>
            <if test="valveStatus != null">valve_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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="unit != null">#{unit},</if>
            <if test="lockPost != null">#{lockPost},</if>
            <if test="pidNo != null">#{pidNo},</if>
            <if test="lockCode != null">#{lockCode},</if>
            <if test="medium != null">#{medium},</if>
            <if test="position != null">#{position},</if>
            <if test="reason != null">#{reason},</if>
            <if test="technology != null">#{technology},</if>
            <if test="riskLevel != null">#{riskLevel},</if>
            <if test="lockSize != null">#{lockSize},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="status != null">#{status},</if>
            <if test="valveStatus != null">#{valveStatus},</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>
         </trim>
    </insert>

    <update id="updateTApplyLock" parameterType="TApplyLock">
        update t_apply_lock
        <trim prefix="SET" suffixOverrides=",">
            <if test="unit != null">unit = #{unit},</if>
            <if test="lockPost != null">lock_post = #{lockPost},</if>
            <if test="pidNo != null">pid_no = #{pidNo},</if>
            <if test="lockCode != null">lock_code = #{lockCode},</if>
            <if test="medium != null">medium = #{medium},</if>
            <if test="position != null">position = #{position},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="technology != null">technology = #{technology},</if>
            <if test="riskLevel != null">risk_level = #{riskLevel},</if>
            <if test="lockSize != null">lock_size = #{lockSize},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="status != null">status = #{status},</if>
            <if test="valveStatus != null">valve_status = #{valveStatus},</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>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTApplyLockById" parameterType="Long">
        update t_apply_lock set status = 2 where id = #{id}
    </update>

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

</mapper>
