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

    <resultMap type="TApplySafetychange" id="TApplySafetychangeResult">
        <result property="id"    column="id"    />
        <result property="changeDescribe"    column="change_describe"    />
        <result property="changeReason"    column="change_reason"    />
        <result property="applicant"    column="applicant"    />
        <result property="applicantName"    column="applicant_name"    />
        <result property="applicationTime"    column="application_time"    />
        <result property="safa"    column="safa"    />
        <result property="safaer"    column="safaer"    />
        <result property="safaerName"    column="safaer_name"    />
        <result property="safaTime"    column="safa_time"    />
        <result property="approver"    column="approver"    />
        <result property="approverName"    column="approver_name"    />
        <result property="approveTime"    column="approve_time"    />
        <result property="executor"    column="executor"    />
        <result property="executorName"    column="executor_name"    />
        <result property="executionTime"    column="execution_time"    />
        <result property="confirmer"    column="confirmer"    />
        <result property="confirmerName"    column="confirmer_name"    />
        <result property="confirmTime"    column="confirm_time"    />
        <result property="changeExecution"    column="change_execution"    />
        <result property="changeExecutor"    column="change_executor"    />
        <result property="changeExecutorName"    column="change_executor_name"    />
        <result property="changeExecutorTime"    column="change_executor_time"    />
        <result property="resetConfirm"    column="reset_confirm"    />
        <result property="resetConfirmer1"    column="reset_confirmer1"    />
        <result property="resetConfirmerName1"    column="reset_confirmer_name1"    />
        <result property="resetConfirmTime1"    column="reset_confirm_time1"    />
        <result property="resetConfirmer2"    column="reset_confirmer2"    />
        <result property="resetConfirmerName2"    column="reset_confirmer_name2"    />
        <result property="resetConfirmTime2"    column="reset_confirm_time2"    />
        <result property="revokeConfirm"    column="revoke_confirm"    />
        <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="approveStatus"    column="approve_status"    />
        <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="selectTApplySafetychangeVo">
        select d.lock_no,d.ap_no,d.process_id,d.id, d.change_describe, d.change_reason, d.applicant, d.applicant_name, d.application_time, d.safa, d.safaer, d.safaer_name, d.safa_time, d.approver, d.approver_name, d.approve_time, d.executor, d.executor_name, d.execution_time, d.confirmer, d.confirmer_name, d.confirm_time, d.change_execution, d.change_executor, d.change_executor_name, d.change_executor_time, d.reset_confirm, d.reset_confirmer1, d.reset_confirmer_name1, d.reset_confirm_time1, d.reset_confirmer2, d.reset_confirmer_name2, d.reset_confirm_time2, d.revoke_confirm, d.remarks, d.status, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.approve_status ,s.dept_name from t_apply_safetychange d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTApplySafetychangeList" parameterType="TApplySafetychange" resultMap="TApplySafetychangeResult">
        <include refid="selectTApplySafetychangeVo"/>
        <where>
            <if test="changeDescribe != null  and changeDescribe != ''"> and change_describe like concat(concat('%', #{changeDescribe}), '%')</if>
            <if test="changeReason != null  and changeReason != ''"> and change_reason = #{changeReason}</if>
            <if test="lockNo != null  and lockNo != ''"> and lock_no like concat(concat('%', #{lockNo}), '%')</if>
            <if test="applicant != null  and applicant != ''"> and applicant = #{applicant}</if>
            <if test="applicantName != null  and applicantName != ''"> and applicant_name like concat(concat('%', #{applicantName}), '%')</if>
            <if test="applicationTime != null "> and application_time = #{applicationTime}</if>
            <if test="safa != null  and safa != ''"> and safa = #{safa}</if>
            <if test="safaer != null  and safaer != ''"> and safaer = #{safaer}</if>
            <if test="safaerName != null  and safaerName != ''"> and safaer_name like concat(concat('%', #{safaerName}), '%')</if>
            <if test="safaTime != null "> and safa_time = #{safaTime}</if>
            <if test="approver != null  and approver != ''"> and approver = #{approver}</if>
            <if test="approverName != null  and approverName != ''"> and approver_name like concat(concat('%', #{approverName}), '%')</if>
            <if test="approveTime != null "> and approve_time = #{approveTime}</if>
            <if test="executor != null  and executor != ''"> and executor = #{executor}</if>
            <if test="executorName != null  and executorName != ''"> and executor_name like concat(concat('%', #{executorName}), '%')</if>
            <if test="executionTime != null "> and execution_time = #{executionTime}</if>
            <if test="confirmer != null  and confirmer != ''"> and confirmer = #{confirmer}</if>
            <if test="confirmerName != null  and confirmerName != ''"> and confirmer_name like concat(concat('%', #{confirmerName}), '%')</if>
            <if test="confirmTime != null "> and confirm_time = #{confirmTime}</if>
            <if test="changeExecution != null  and changeExecution != ''"> and change_execution = #{changeExecution}</if>
            <if test="changeExecutor != null  and changeExecutor != ''"> and change_executor = #{changeExecutor}</if>
            <if test="changeExecutorName != null  and changeExecutorName != ''"> and change_executor_name like concat(concat('%', #{changeExecutorName}), '%')</if>
            <if test="changeExecutorTime != null "> and change_executor_time = #{changeExecutorTime}</if>
            <if test="resetConfirm != null  and resetConfirm != ''"> and reset_confirm = #{resetConfirm}</if>
            <if test="resetConfirmer1 != null  and resetConfirmer1 != ''"> and reset_confirmer1 = #{resetConfirmer1}</if>
            <if test="resetConfirmerName1 != null  and resetConfirmerName1 != ''"> and reset_confirmer_name1 = #{resetConfirmerName1}</if>
            <if test="resetConfirmTime1 != null "> and reset_confirm_time1 = #{resetConfirmTime1}</if>
            <if test="resetConfirmer2 != null  and resetConfirmer2 != ''"> and reset_confirmer2 = #{resetConfirmer2}</if>
            <if test="resetConfirmerName2 != null  and resetConfirmerName2 != ''"> and reset_confirmer_name2 = #{resetConfirmerName2}</if>
            <if test="resetConfirmTime2 != null "> and reset_confirm_time2 = #{resetConfirmTime2}</if>
            <if test="revokeConfirm != null  and revokeConfirm != ''"> and revoke_confirm = #{revokeConfirm}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</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="ids != null and ids.length > 0"> and id in
                <foreach item="id" collection="ids" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by createdate desc
    </select>

    <select id="selectChangeDescribe" parameterType="TApplySafetychange" resultMap="TApplySafetychangeResult">
        select distinct(change_describe) from  t_apply_safetychange d
        left join sys_dept s on s.dept_id = d.dept_id
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

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

    <select id="selectSAFA" parameterType="TApplySafetychange" resultMap="TApplySafetychangeResult">
        select distinct(safa) from  t_apply_safetychange 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>

    <select id="selectTApplySafetychangeById" parameterType="Long" resultMap="TApplySafetychangeResult">
        <include refid="selectTApplySafetychangeVo"/>
        where id = #{id}
    </select>

    <select id="selectTApplySafetychangeByLock" parameterType="String" resultMap="TApplySafetychangeResult">
        <include refid="selectTApplySafetychangeVo"/>
        where lock_no like concat(concat('%',#{lockNo}),'%') and d.status=0 and d.approve_status=2
    </select>

    <insert id="insertTApplySafetychange" parameterType="TApplySafetychange">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_apply_safetychange.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_apply_safetychange
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="changeDescribe != null">change_describe,</if>
            <if test="changeReason != null">change_reason,</if>
            <if test="applicant != null">applicant,</if>
            <if test="applicantName != null">applicant_name,</if>
            <if test="applicationTime != null">application_time,</if>
            <if test="safa != null">safa,</if>
            <if test="safaer != null">safaer,</if>
            <if test="safaerName != null">safaer_name,</if>
            <if test="safaTime != null">safa_time,</if>
            <if test="approver != null">approver,</if>
            <if test="approverName != null">approver_name,</if>
            <if test="approveTime != null">approve_time,</if>
            <if test="executor != null">executor,</if>
            <if test="executorName != null">executor_name,</if>
            <if test="executionTime != null">execution_time,</if>
            <if test="confirmer != null">confirmer,</if>
            <if test="confirmerName != null">confirmer_name,</if>
            <if test="confirmTime != null">confirm_time,</if>
            <if test="changeExecution != null">change_execution,</if>
            <if test="changeExecutor != null">change_executor,</if>
            <if test="changeExecutorName != null">change_executor_name,</if>
            <if test="changeExecutorTime != null">change_executor_time,</if>
            <if test="resetConfirm != null">reset_confirm,</if>
            <if test="resetConfirmer1 != null">reset_confirmer1,</if>
            <if test="resetConfirmerName1 != null">reset_confirmer_name1,</if>
            <if test="resetConfirmTime1 != null">reset_confirm_time1,</if>
            <if test="resetConfirmer2 != null">reset_confirmer2,</if>
            <if test="resetConfirmerName2 != null">reset_confirmer_name2,</if>
            <if test="resetConfirmTime2 != null">reset_confirm_time2,</if>
            <if test="revokeConfirm != null">revoke_confirm,</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="approveStatus != null">approve_status,</if>
            <if test="lockNo != null">lock_no,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="changeDescribe != null">#{changeDescribe},</if>
            <if test="changeReason != null">#{changeReason},</if>
            <if test="applicant != null">#{applicant},</if>
            <if test="applicantName != null">#{applicantName},</if>
            <if test="applicationTime != null">#{applicationTime},</if>
            <if test="safa != null">#{safa},</if>
            <if test="safaer != null">#{safaer},</if>
            <if test="safaerName != null">#{safaerName},</if>
            <if test="safaTime != null">#{safaTime},</if>
            <if test="approver != null">#{approver},</if>
            <if test="approverName != null">#{approverName},</if>
            <if test="approveTime != null">#{approveTime},</if>
            <if test="executor != null">#{executor},</if>
            <if test="executorName != null">#{executorName},</if>
            <if test="executionTime != null">#{executionTime},</if>
            <if test="confirmer != null">#{confirmer},</if>
            <if test="confirmerName != null">#{confirmerName},</if>
            <if test="confirmTime != null">#{confirmTime},</if>
            <if test="changeExecution != null">#{changeExecution},</if>
            <if test="changeExecutor != null">#{changeExecutor},</if>
            <if test="changeExecutorName != null">#{changeExecutorName},</if>
            <if test="changeExecutorTime != null">#{changeExecutorTime},</if>
            <if test="resetConfirm != null">#{resetConfirm},</if>
            <if test="resetConfirmer1 != null">#{resetConfirmer1},</if>
            <if test="resetConfirmerName1 != null">#{resetConfirmerName1},</if>
            <if test="resetConfirmTime1 != null">#{resetConfirmTime1},</if>
            <if test="resetConfirmer2 != null">#{resetConfirmer2},</if>
            <if test="resetConfirmerName2 != null">#{resetConfirmerName2},</if>
            <if test="resetConfirmTime2 != null">#{resetConfirmTime2},</if>
            <if test="revokeConfirm != null">#{revokeConfirm},</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="approveStatus != null">#{approveStatus},</if>
            <if test="lockNo != null">#{lockNo},</if>
         </trim>
    </insert>

    <update id="updateTApplySafetychange" parameterType="TApplySafetychange">
        update t_apply_safetychange
        <trim prefix="SET" suffixOverrides=",">
            <if test="changeDescribe != null">change_describe = #{changeDescribe},</if>
            <if test="changeReason != null">change_reason = #{changeReason},</if>
            <if test="applicant != null">applicant = #{applicant},</if>
            <if test="applicantName != null">applicant_name = #{applicantName},</if>
            <if test="applicationTime != null">application_time = #{applicationTime},</if>
            <if test="safa != null">safa = #{safa},</if>
            <if test="safaer != null">safaer = #{safaer},</if>
            <if test="safaerName != null">safaer_name = #{safaerName},</if>
            <if test="safaTime != null">safa_time = #{safaTime},</if>
            <if test="approver != null">approver = #{approver},</if>
            <if test="approverName != null">approver_name = #{approverName},</if>
            <if test="approveTime != null">approve_time = #{approveTime},</if>
            <if test="executor != null">executor = #{executor},</if>
            <if test="executorName != null">executor_name = #{executorName},</if>
            <if test="executionTime != null">execution_time = #{executionTime},</if>
            <if test="confirmer != null">confirmer = #{confirmer},</if>
            <if test="confirmerName != null">confirmer_name = #{confirmerName},</if>
            <if test="confirmTime != null">confirm_time = #{confirmTime},</if>
            <if test="changeExecution != null">change_execution = #{changeExecution},</if>
            <if test="changeExecutor != null">change_executor = #{changeExecutor},</if>
            <if test="changeExecutorName != null">change_executor_name = #{changeExecutorName},</if>
            <if test="changeExecutorTime != null">change_executor_time = #{changeExecutorTime},</if>
            <if test="resetConfirm != null">reset_confirm = #{resetConfirm},</if>
            <if test="resetConfirmer1 != null">reset_confirmer1 = #{resetConfirmer1},</if>
            <if test="resetConfirmerName1 != null">reset_confirmer_name1 = #{resetConfirmerName1},</if>
            <if test="resetConfirmTime1 != null">reset_confirm_time1 = #{resetConfirmTime1},</if>
            <if test="resetConfirmer2 != null">reset_confirmer2 = #{resetConfirmer2},</if>
            <if test="resetConfirmerName2 != null">reset_confirmer_name2 = #{resetConfirmerName2},</if>
            <if test="resetConfirmTime2 != null">reset_confirm_time2 = #{resetConfirmTime2},</if>
            <if test="revokeConfirm != null">revoke_confirm = #{revokeConfirm},</if>
            <if test="remarks != null and remarks != ''">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="approveStatus != null">approve_status = #{approveStatus},</if>
            <if test="apNo != null">ap_no = #{apNo},</if>
            <if test="processId != null">process_id = #{processId},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
