<?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.gz.mapper.borrow.ArchiveBorrowMapper">

    <select id="selectArchiveBorrowHistory" resultType="com.gz.rvo.borrow.ArchiveBorrowHistoryRVO" parameterType="com.gz.vo.borrow.SearchBorrowVO">
        SELECT ab.id,
               a.dh,
               a.tm,
               a.ml,
               date_format(ab.create_time,'%Y-%m-%d') create_time,
               ab.borrow_type,
               date_format(ab.return_time,'%Y-%m-%d') return_time,
               ab.return_status,
               date_format(ab.estimate_return_time,'%Y-%m-%d') estimate_return_time,
               ab.audit_status,
               ab.name admin_name
        FROM tab_archive_borrow ab
                 LEFT JOIN
             tab_archives a
             ON ab.archive_id = a.id
        where ab.deleted = 0
          and a.deleted = 0
          <if test="adminId != null and adminId != ''">
              and ab.admin_id = #{adminId}
          </if>
        <if test="dh != null and dh != ''">
            and a.dh = #{dh}
        </if>
        <if test="tm != null and tm != ''">
            and a.tm like concat(concat('%',#{tm}),'%')
        </if>
        <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
            and ab.create_time BETWEEN #{startTime} AND #{endTime}
        </if>
        order by ab.create_time desc
    </select>

    <select id="selectBorrowInfo" resultType="com.gz.rvo.borrow.AuditInfoRVO">
        SELECT
            a.tm,
            a.dh,
            ab.name,
            ab.dept,
            ab.id_card,
            ab.phone,
            ab.use_purpose,
            ab.create_time,
            ab.return_time,
            ab.borrow_type,
            f.original_file_name,
            f.file_path,
            f.file_name
        FROM
            `tab_archive_borrow` ab
                LEFT JOIN tab_archives a
                          ON ab.archive_id = a.id
                LEFT JOIN tab_archive_file f
                          ON ab.relevant_certification = f.id
        WHERE a.deleted = 0
          AND ab.deleted = 0
          AND ab.id = #{id}
    </select>
</mapper>
