<?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.archive.ArchiveMapper">

    <select id="searchList" resultType="com.gz.rvo.archive.ArchiveRVO"
            parameterType="com.gz.vo.archive.SearchArchiveVO">
        SELECT
        d.dict_name mj_text,
        a.*
        FROM `tab_archives` a
        LEFT JOIN tab_dict d
        ON a.mj = d.dict_code
        <where>
            a.deleted = 0
            <if test="dh != null and dh != ''">
                AND a.dh = #{dh}
            </if>
            <if test="mlh != null and mlh != ''">
                AND a.mlh = #{mlh}
            </if>
            <if test="ml != null and ml != ''">
                AND a.ml = #{ml}
            </if>
            <if test="bgqx != null and bgqx != ''">
                AND a.bgqx = #{bgqx}
            </if>
        </where>


    </select>

    <select id="selectBorrowList" resultType="com.gz.rvo.borrow.ArchiveBorrowListRVO">
        <![CDATA[
        SELECT IF
                   (
                           (SELECT count(admin_id) num
                            FROM tab_archive_borrow ab
                            WHERE ab.archive_id = a.id
                              AND ab.borrow_type = 1
                              AND ab.audit_status = 2
                              AND ab.return_status = 0) <= 0,
                           '可借阅',
                           '已借阅'
                   ) original_status,
               a.*
        FROM tab_archives a
        WHERE a.deleted = 0
        ]]>
    </select>
</mapper>
