package com.lingyue.extract.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lingyue.extract.entity.Project;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 项目 Repository
 * 
 * @author lingyue
 * @since 2026-01-22
 */
@Mapper
public interface ProjectRepository extends BaseMapper<Project> {
    
    /**
     * 根据用户ID查询项目列表
     */
    @Select("SELECT * FROM extract_projects WHERE user_id = #{userId} ORDER BY create_time DESC")
    List<Project> findByUserId(@Param("userId") String userId);
    
    /**
     * 根据状态查询项目
     */
    @Select("SELECT * FROM extract_projects WHERE status = #{status} ORDER BY create_time DESC")
    List<Project> findByStatus(@Param("status") String status);
    
    /**
     * 根据用户ID和状态查询项目
     */
    @Select("SELECT * FROM extract_projects WHERE user_id = #{userId} AND status = #{status} ORDER BY create_time DESC")
    List<Project> findByUserIdAndStatus(@Param("userId") String userId, @Param("status") String status);
    
    /**
     * 统计用户项目数量
     */
    @Select("SELECT COUNT(*) FROM extract_projects WHERE user_id = #{userId}")
    int countByUserId(@Param("userId") String userId);
    
    /**
     * 统计用户各状态项目数量
     */
    @Select("SELECT status, COUNT(*) as count FROM extract_projects WHERE user_id = #{userId} GROUP BY status")
    List<java.util.Map<String, Object>> countByUserIdGroupByStatus(@Param("userId") String userId);
}
