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

    <resultMap type="TApplyOfflinevalve" id="TApplyOfflinevalveResult">
        <result property="id"    column="id"    />
        <result property="devNo"    column="dev_no"    />
        <result property="unit"    column="unit"    />
        <result property="offlineReason"    column="offline_reason"    />
        <result property="safa"    column="safa"    />
        <result property="disassembly"    column="disassembly"    />
        <result property="executor"    column="executor"    />
        <result property="confirmer"    column="confirmer"    />
        <result property="applicant"    column="applicant"    />
        <result property="applicationTime"    column="application_time"    />
        <result property="approver"    column="approver"    />
        <result property="approveTime"    column="approve_time"    />
        <result property="resetConfirm"    column="reset_confirm"    />
        <result property="leakConfirm"    column="leak_confirm"    />
        <result property="revokeConfirm"    column="revoke_confirm"    />
        <result property="lockConfirm"    column="lock_confirm"    />
        <result property="lockConfirmer1"    column="lock_confirmer1"    />
        <result property="lockConfirmer2"    column="lock_confirmer2"    />
        <result property="infoConfirmer"    column="info_confirmer"    />
        <result property="confirmTime"    column="confirm_time"    />
        <result property="remarks"    column="remarks"    />
        <result property="temporaryTime"    column="temporary_time"    />
        <result property="executionTime"    column="execution_time"    />
        <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="approveStatus"    column="approve_status"    />
        <result property="lockConfirmer1Name"    column="lock_confirmer1_name"    />
        <result property="lockConfirmer2Name"    column="lock_confirmer2_name"    />
        <result property="infoConfirmerName"    column="info_confirmer_name"    />
        <result property="executorName"    column="executor_name"    />
        <result property="confirmerName"    column="confirmer_name"    />
        <result property="approverName"    column="approver_name"    />
        <result property="applicantName"    column="applicant_name"    />
        <result property="apNo"    column="ap_no"    />
        <result property="processId"    column="process_id"    />
        <result property="deptName" column="dept_name" />
        <result property="lockNo" column="lock_no" />
    </resultMap>

    <sql id="selectTApplyOfflinevalveVo">
        select d.lock_no,d.ap_no,d.process_id,d.id, d.dev_no, d.unit, d.offline_reason, d.safa, d.disassembly, d.executor, d.confirmer, d.applicant, d.application_time, d.approver, d.approve_time, d.reset_confirm, d.leak_confirm, d.revoke_confirm, d.lock_confirm, d.lock_confirmer1, d.lock_confirmer2, d.info_confirmer, d.confirm_time, d.remarks, d.temporary_time, d.execution_time, d.status, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.approve_status, d.lock_confirmer1_name, d.lock_confirmer2_name, d.info_confirmer_name, d.executor_name, d.confirmer_name, d.approver_name, d.applicant_name ,s.dept_name from t_apply_offlinevalve d
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTApplyOfflinevalveList" parameterType="TApplyOfflinevalve" resultMap="TApplyOfflinevalveResult">
        <include refid="selectTApplyOfflinevalveVo"/>
        <where>
            <if test="devNo != null  and devNo != ''"> and dev_no like concat(concat('%', #{devNo}), '%')</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="lockNo != null  and lockNo != ''"> and lock_no like concat(concat('%', #{lockNo}), '%')</if>
            <if test="offlineReason != null  and offlineReason != ''"> and offline_reason like concat(concat('%', #{offlineReason}), '%')</if>
            <if test="safa != null  and safa != ''"> and safa = #{safa}</if>
            <if test="disassembly != null "> and disassembly = #{disassembly}</if>
            <if test="executor != null  and executor != ''"> and executor = #{executor}</if>
            <if test="confirmer != null  and confirmer != ''"> and confirmer = #{confirmer}</if>
            <if test="applicant != null  and applicant != ''"> and applicant = #{applicant}</if>
            <if test="applicationTime != null "> and application_time = #{applicationTime}</if>
            <if test="approver != null  and approver != ''"> and approver = #{approver}</if>
            <if test="approveTime != null "> and approve_time = #{approveTime}</if>
            <if test="resetConfirm != null "> and reset_confirm = #{resetConfirm}</if>
            <if test="leakConfirm != null "> and leak_confirm = #{leakConfirm}</if>
            <if test="revokeConfirm != null "> and revoke_confirm = #{revokeConfirm}</if>
            <if test="lockConfirm != null "> and lock_confirm = #{lockConfirm}</if>
            <if test="lockConfirmer1 != null  and lockConfirmer1 != ''"> and lock_confirmer1 = #{lockConfirmer1}</if>
            <if test="lockConfirmer2 != null  and lockConfirmer2 != ''"> and lock_confirmer2 = #{lockConfirmer2}</if>
            <if test="infoConfirmer != null  and infoConfirmer != ''"> and info_confirmer = #{infoConfirmer}</if>
            <if test="confirmTime != null "> and confirm_time = #{confirmTime}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="temporaryTime != null "> and temporary_time = #{temporaryTime}</if>
            <if test="executionTime != null "> and execution_time = #{executionTime}</if>
            <if test="status != null "> and d.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="approveStatus != null  and approveStatus != ''"> and d.approve_status = #{approveStatus}</if>
            <if test="lockConfirmer1Name != null  and lockConfirmer1Name != ''"> and lock_confirmer1_name like concat(concat('%', #{lockConfirmer1Name}), '%')</if>
            <if test="lockConfirmer2Name != null  and lockConfirmer2Name != ''"> and lock_confirmer2_name like concat(concat('%', #{lockConfirmer2Name}), '%')</if>
            <if test="infoConfirmerName != null  and infoConfirmerName != ''"> and info_confirmer_name like concat(concat('%', #{infoConfirmerName}), '%')</if>
            <if test="executorName != null  and executorName != ''"> and executor_name like concat(concat('%', #{executorName}), '%')</if>
            <if test="confirmerName != null  and confirmerName != ''"> and confirmer_name like concat(concat('%', #{confirmerName}), '%')</if>
            <if test="approverName != null  and approverName != ''"> and approver_name like concat(concat('%', #{approverName}), '%')</if>
            <if test="applicantName != null  and applicantName != ''"> and applicant_name like concat(concat('%', #{applicantName}), '%')</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by createdate desc
    </select>

    <select id="selectTApplyOfflinevalveById" parameterType="Long" resultMap="TApplyOfflinevalveResult">
        <include refid="selectTApplyOfflinevalveVo"/>
        where id = #{id}
    </select>

    <insert id="insertTApplyOfflinevalve" parameterType="TApplyOfflinevalve">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_apply_offlinevalve.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_apply_offlinevalve
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="devNo != null">dev_no,</if>
            <if test="unit != null">unit,</if>
            <if test="offlineReason != null">offline_reason,</if>
            <if test="safa != null">safa,</if>
            <if test="disassembly != null">disassembly,</if>
            <if test="executor != null">executor,</if>
            <if test="confirmer != null">confirmer,</if>
            <if test="applicant != null">applicant,</if>
            <if test="applicationTime != null">application_time,</if>
            <if test="approver != null">approver,</if>
            <if test="approveTime != null">approve_time,</if>
            <if test="resetConfirm != null">reset_confirm,</if>
            <if test="leakConfirm != null">leak_confirm,</if>
            <if test="revokeConfirm != null">revoke_confirm,</if>
            <if test="lockConfirm != null">lock_confirm,</if>
            <if test="lockConfirmer1 != null">lock_confirmer1,</if>
            <if test="lockConfirmer2 != null">lock_confirmer2,</if>
            <if test="infoConfirmer != null">info_confirmer,</if>
            <if test="confirmTime != null">confirm_time,</if>
            <if test="remarks != null">remarks,</if>
            <if test="temporaryTime != null">temporary_time,</if>
            <if test="executionTime != null">execution_time,</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="approveStatus != null">approve_status,</if>
            <if test="lockConfirmer1Name != null">lock_confirmer1_name,</if>
            <if test="lockConfirmer2Name != null">lock_confirmer2_name,</if>
            <if test="infoConfirmerName != null">info_confirmer_name,</if>
            <if test="executorName != null">executor_name,</if>
            <if test="confirmerName != null">confirmer_name,</if>
            <if test="approverName != null">approver_name,</if>
            <if test="applicantName != null">applicant_name,</if>
            <if test="lockNo != null">lock_no,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="devNo != null">#{devNo},</if>
            <if test="unit != null">#{unit},</if>
            <if test="offlineReason != null">#{offlineReason},</if>
            <if test="safa != null">#{safa},</if>
            <if test="disassembly != null">#{disassembly},</if>
            <if test="executor != null">#{executor},</if>
            <if test="confirmer != null">#{confirmer},</if>
            <if test="applicant != null">#{applicant},</if>
            <if test="applicationTime != null">#{applicationTime},</if>
            <if test="approver != null">#{approver},</if>
            <if test="approveTime != null">#{approveTime},</if>
            <if test="resetConfirm != null">#{resetConfirm},</if>
            <if test="leakConfirm != null">#{leakConfirm},</if>
            <if test="revokeConfirm != null">#{revokeConfirm},</if>
            <if test="lockConfirm != null">#{lockConfirm},</if>
            <if test="lockConfirmer1 != null">#{lockConfirmer1},</if>
            <if test="lockConfirmer2 != null">#{lockConfirmer2},</if>
            <if test="infoConfirmer != null">#{infoConfirmer},</if>
            <if test="confirmTime != null">#{confirmTime},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="temporaryTime != null">#{temporaryTime},</if>
            <if test="executionTime != null">#{executionTime},</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="approveStatus != null">#{approveStatus},</if>
            <if test="lockConfirmer1Name != null">#{lockConfirmer1Name},</if>
            <if test="lockConfirmer2Name != null">#{lockConfirmer2Name},</if>
            <if test="infoConfirmerName != null">#{infoConfirmerName},</if>
            <if test="executorName != null">#{executorName},</if>
            <if test="confirmerName != null">#{confirmerName},</if>
            <if test="approverName != null">#{approverName},</if>
            <if test="applicantName != null">#{applicantName},</if>
            <if test="lockNo != null">#{lockNo},</if>
        </trim>
    </insert>

    <update id="updateTApplyOfflinevalve" parameterType="TApplyOfflinevalve">
        update t_apply_offlinevalve
        <trim prefix="SET" suffixOverrides=",">
            <if test="devNo != null">dev_no = #{devNo},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="offlineReason != null">offline_reason = #{offlineReason},</if>
            <if test="safa != null">safa = #{safa},</if>
            <if test="disassembly != null">disassembly = #{disassembly},</if>
            <if test="executor != null">executor = #{executor},</if>
            <if test="confirmer != null">confirmer = #{confirmer},</if>
            <if test="applicant != null">applicant = #{applicant},</if>
            <if test="applicationTime != null">application_time = #{applicationTime},</if>
            <if test="approver != null">approver = #{approver},</if>
            <if test="approveTime != null">approve_time = #{approveTime},</if>
            <if test="resetConfirm != null">reset_confirm = #{resetConfirm},</if>
            <if test="leakConfirm != null">leak_confirm = #{leakConfirm},</if>
            <if test="lockNo != null">lock_no = #{lockNo},</if>
            <if test="revokeConfirm != null">revoke_confirm = #{revokeConfirm},</if>
            <if test="lockConfirm != null">lock_confirm = #{lockConfirm},</if>
            <if test="lockConfirmer1 != null">lock_confirmer1 = #{lockConfirmer1},</if>
            <if test="lockConfirmer2 != null">lock_confirmer2 = #{lockConfirmer2},</if>
            <if test="infoConfirmer != null">info_confirmer = #{infoConfirmer},</if>
            <if test="confirmTime != null">confirm_time = #{confirmTime},</if>
            <if test="remarks != null and remarks != ''" >remarks = #{remarks},</if>
            <if test="temporaryTime != null">temporary_time = #{temporaryTime},</if>
            <if test="executionTime != null">execution_time = #{executionTime},</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="approveStatus != null">approve_status = #{approveStatus},</if>
            <if test="lockConfirmer1Name != null">lock_confirmer1_name = #{lockConfirmer1Name},</if>
            <if test="lockConfirmer2Name != null">lock_confirmer2_name = #{lockConfirmer2Name},</if>
            <if test="infoConfirmerName != null">info_confirmer_name = #{infoConfirmerName},</if>
            <if test="executorName != null">executor_name = #{executorName},</if>
            <if test="confirmerName != null">confirmer_name = #{confirmerName},</if>
            <if test="approverName != null">approver_name = #{approverName},</if>
            <if test="applicantName != null">applicant_name = #{applicantName},</if>
            <if test="apNo != null">ap_no = #{apNo},</if>
            <if test="processId != null">process_id = #{processId},</if>
        </trim>
        where id = #{id}
    </update>

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

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

    <select id="selectTApplyOfflinevalveByLock" parameterType="string" resultMap="TApplyOfflinevalveResult">
        <include refid="selectTApplyOfflinevalveVo"/>
        where lock_no like concat(concat('%',#{lockNo}),'%') and d.status=0 and d.approve_status=2
    </select>


    <select id="selectSAFA" parameterType="TApplyOfflinevalve" resultMap="TApplyOfflinevalveResult">
        select distinct(safa) from  T_APPLY_OFFLINEVALVE d
        left join sys_dept s on s.dept_id = d.dept_id
        <where>
            and d.del_flag = 0
            and d.safa is not null
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

</mapper>
