<?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.api.manage.dao.butlerService.BorrowDao">
    <select id="list" parameterType="com.api.model.butlerService.SearchBorrow" resultType="com.api.vo.butlerService.VoBorrow">
        select sab.*,sad.code,sad.name,ur.name as borrow_name,ur.tel
        from sys_article_borrow as sab,sys_article_detail as sad,sys_article as sa,user_resident as ur
        <where>
            sab.article_detail_id = sad.id
            and sad.article_id = sa.id
            and sab.create_id = ur.id
            <if test="name != null and name != ''">
                and sa.name like concat('%',#{name},'%')
            </if>
            <if test="borrowStatus != null">
                and sab.borrow_status = #{borrowStatus}
            </if>
            <if test="borrowName != null and borrowName != ''">
                and ur.name like concat('%',#{borrowName},'%')
            </if>
            <if test="tel != null and tel != ''">
                and ur.tel like concat('%',#{tel},'%')
            </if>
            <if test="beginDate != null">
                and sab.begin_date <![CDATA[ > ]]> begin_date
            </if>
            <if test="endDate != null">
                and sab.end_date <![CDATA[ < ]]> end_date
            </if>

        </where>
    </select>

    <select id="findById" parameterType="java.lang.Integer" resultType="com.api.model.butlerService.SysArticleBorrow">
        select * from sys_article_borrow where id = #{id}
    </select>

    <select id="findAll" resultType="com.api.model.butlerService.SysArticleBorrow">
        select * from sys_article_borrow
    </select>

    <select id="countBorrowNum" parameterType="java.lang.Integer" resultType="java.lang.Integer">
        select count(*) as num
        from sys_article_borrow as sab,sys_article_detail as sad
        where sab.article_detail_id = sad.id and borrow_status = 1 and sad.article_id = #{id}
    </select>
</mapper>