package com.erp.file.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.erp.file.entity.FileEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 文件Mapper
 */
@Mapper
public interface FileMapper extends BaseMapper<FileEntity> {
    
    /**
     * 获取用户文件数
     */
    @Select("SELECT COUNT(DISTINCT user_id) FROM files WHERE deleted_at IS NULL")
    Long countDistinctUsers();
    
    /**
     * 获取模块数
     */
    @Select("SELECT COUNT(DISTINCT module) FROM files WHERE deleted_at IS NULL")
    Long countDistinctModules();
    
    /**
     * 根据用户ID和状态统计
     */
    @Select("SELECT COUNT(*) FROM files WHERE user_id = #{userId} AND status = #{status} AND deleted_at IS NULL")
    Long countByUserIdAndStatus(@Param("userId") Long userId, @Param("status") String status);
    
    /**
     * 获取用户总文件大小
     */
    @Select("SELECT COALESCE(SUM(size), 0) FROM files WHERE user_id = #{userId} AND deleted_at IS NULL")
    Long sumSizeByUserId(@Param("userId") Long userId);
}
