<?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.srs.routine.mapper.RtStuLeaveOperationRecordsMapper">
    
    <resultMap type="RtStuLeaveOperationRecords" id="RtStuLeaveOperationRecordsResult">
        <result property="operationRecordsId"    column="operation_records_id"    />
        <result property="leaveApplicationId"    column="leave_application_id"    />
        <result property="operationType"    column="operation_type"    />
        <result property="operationResult"    column="operation_result"    />
        <result property="signature"    column="signature"    />
        <result property="signatureDate"    column="signature_date"    />
        <result property="comments"    column="comments"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectRtStuLeaveOperationRecordsVo">
        select operation_records_id, leave_application_id, operation_type, operation_result, signature, signature_date, comments, create_by, create_time, update_by, update_time, remark from rt_stu_leave_operation_records
    </sql>

    <select id="selectRtStuLeaveOperationRecordsList" parameterType="RtStuLeaveOperationRecords" resultMap="RtStuLeaveOperationRecordsResult">
        <include refid="selectRtStuLeaveOperationRecordsVo"/>
        <where>  
            <if test="leaveApplicationId != null "> and leave_application_id = #{leaveApplicationId}</if>
            <if test="operationType != null "> and operation_type = #{operationType}</if>
            <if test="operationResult != null "> and operation_result = #{operationResult}</if>
            <if test="signature != null  and signature != ''"> and signature = #{signature}</if>
            <if test="signatureDate != null "> and signature_date = #{signatureDate}</if>
            <if test="comments != null  and comments != ''"> and comments = #{comments}</if>
        </where>
    </select>
    
    <select id="selectRtStuLeaveOperationRecordsByOperationRecordsId" parameterType="Long" resultMap="RtStuLeaveOperationRecordsResult">
        <include refid="selectRtStuLeaveOperationRecordsVo"/>
        where operation_records_id = #{operationRecordsId}
    </select>

    <select id="selectRtStuLeaveOperationRecordsListByleaveApplicationId"
            resultType="com.srs.routine.domain.vo.StuLeaveOperationRecordsDetailsVo">
        SELECT a.operation_records_id AS operationRecordsId,
               b.leave_application_id AS leaveApplicationId,
               a.operation_type AS operationType,
               a.operation_result AS operationResult,
               a.signature AS signature,
               a.signature_date AS signatureDate,
               a.comments AS comments,
               a.create_time AS createTime
        FROM rt_stu_leave_operation_records a
                 LEFT JOIN rt_stu_leave_application b ON a.leave_application_id = b.leave_application_id
        WHERE b.leave_application_id = #{leaveApplicationId}
        ORDER BY a.operation_type
    </select>

    <insert id="insertRtStuLeaveOperationRecords" parameterType="RtStuLeaveOperationRecords" useGeneratedKeys="true" keyProperty="operationRecordsId">
        insert into rt_stu_leave_operation_records
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="leaveApplicationId != null">leave_application_id,</if>
            <if test="operationType != null">operation_type,</if>
            <if test="operationResult != null">operation_result,</if>
            <if test="signature != null and signature != ''">signature,</if>
            <if test="signatureDate != null">signature_date,</if>
            <if test="comments != null">comments,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="leaveApplicationId != null">#{leaveApplicationId},</if>
            <if test="operationType != null">#{operationType},</if>
            <if test="operationResult != null">#{operationResult},</if>
            <if test="signature != null and signature != ''">#{signature},</if>
            <if test="signatureDate != null">#{signatureDate},</if>
            <if test="comments != null">#{comments},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateRtStuLeaveOperationRecords" parameterType="RtStuLeaveOperationRecords">
        update rt_stu_leave_operation_records
        <trim prefix="SET" suffixOverrides=",">
            <if test="leaveApplicationId != null">leave_application_id = #{leaveApplicationId},</if>
            <if test="operationType != null">operation_type = #{operationType},</if>
            <if test="operationResult != null">operation_result = #{operationResult},</if>
            <if test="signature != null and signature != ''">signature = #{signature},</if>
            <if test="signatureDate != null">signature_date = #{signatureDate},</if>
            <if test="comments != null">comments = #{comments},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where operation_records_id = #{operationRecordsId}
    </update>

    <delete id="deleteRtStuLeaveOperationRecordsByOperationRecordsId" parameterType="Long">
        delete from rt_stu_leave_operation_records where operation_records_id = #{operationRecordsId}
    </delete>

    <delete id="deleteRtStuLeaveOperationRecordsByOperationRecordsIds" parameterType="String">
        delete from rt_stu_leave_operation_records where operation_records_id in 
        <foreach item="operationRecordsId" collection="array" open="(" separator="," close=")">
            #{operationRecordsId}
        </foreach>
    </delete>
</mapper>