<?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.zxdmy.excite.system.mapper.cloud.collection.CloudUserCollectionMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.zxdmy.excite.system.entity.cloud.collection.CloudUserCollection">
        <id column="id" property="id" />
        <result column="file_id" property="fileId" />
        <result column="user_id" property="userId" />
        <result column="create_time" property="createTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, file_id, user_id, create_time
    </sql>


    <select id="queryByPage" resultType="com.zxdmy.excite.system.entity.vo.space.CloudFileVo" >
        select f.* from cloud_file f
        left join cloud_user_collection c on c.file_id = f.id
        <trim prefix="WHERE" prefixOverrides="AND">
            f.delete_time is null
            <if test="data.userId != null and data.userId != ''">
                AND c.user_id = #{data.userId}
            </if>
        </trim>
        LIMIT #{page},#{size};
    </select>

    <select id="queryByPageCount" resultType="java.lang.Integer">
        select count(*) from cloud_file f
        left join cloud_user_collection c on c.file_id = f.id
        <trim prefix="WHERE" prefixOverrides="AND">
            f.delete_time is null
            <if test="data.userId != null and data.userId != ''">
                AND c.user_id = #{data.userId}
            </if>
        </trim>
    </select>

    <select id="getData" resultType="com.zxdmy.excite.system.entity.vo.collection.CloudUserCollectionVo" >
        select <include refid="Base_Column_List"/>
        from cloud_user_collection
        <trim prefix="WHERE" prefixOverrides="AND">
            <if test="data.fileId != null and data.fileId != ''">
                AND file_id = #{data.fileId}
            </if>
            <if test="data.userId != null and data.userId != ''">
                AND user_id = #{data.userId}
            </if>
        </trim>
    </select>
</mapper>
