<?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="vip.xiaonuo.disk.mapper.ShareMapper">

    <select id="selectShareList" resultType="vip.xiaonuo.disk.vo.share.ShareListVO">
        SELECT * FROM share a
        LEFT JOIN sharefile b ON b.SHARE_BATCH_NUM = a.SHARE_BATCH_NUM
        LEFT JOIN userfile c ON c.USER_FILE_ID = b.USER_FILE_ID
        LEFT JOIN file d ON d.FILE_ID = c.FILE_ID
        WHERE SHARE_FILE_PATH = #{shareFilePath}
        <if test="shareBatchNum != null and shareBatchNum != ''">
            AND a.SHARE_BATCH_NUM = #{shareBatchNum}
        </if>
        AND c.USER_ID = #{userId}
        order BY SHARE_TIME desc
        limit #{beginCount}, #{pageCount}
    </select>

    <select id="selectShareListTotalCount" resultType="java.lang.Integer">
        SELECT count(*) FROM share a
        LEFT JOIN sharefile b ON b.SHARE_BATCH_NUM = a.SHARE_BATCH_NUM
        LEFT JOIN userfile c ON c.USER_FILE_ID = b.USER_FILE_ID
        LEFT JOIN file d ON d.FILE_ID = c.FILE_ID
        WHERE SHARE_FILE_PATH = #{shareFilePath}
        <if test="shareBatchNum != null  and shareBatchNum != ''">
            AND a.SHARE_BATCH_NUM = #{shareBatchNum}
        </if>
        AND c.USER_ID = #{userId}
    </select>


</mapper>
