package com.qqchen.deploy.backend.deploy.repository;

import com.qqchen.deploy.backend.deploy.entity.Environment;
import com.qqchen.deploy.backend.framework.repository.IBaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 环境数据访问接口
 */
@Repository
public interface IEnvironmentRepository extends IBaseRepository<Environment, Long> {


    @Query(value = "SELECT e.* FROM deploy_environment e " +
        "INNER JOIN deploy_project_group_environment pge ON e.id = pge.environment_id " +
        "WHERE pge.project_group_id = :projectGroupId",
        nativeQuery = true)
    List<Environment> findByProjectGroupId(@Param("projectGroupId") Long projectGroupId);

    @Query(value = "SELECT COUNT(*) FROM deploy_environment e " +
        "INNER JOIN deploy_project_group_environment pge ON e.id = pge.environment_id " +
        "WHERE pge.project_group_id = :projectGroupId",
        nativeQuery = true)
    Integer countByProjectGroupId(@Param("projectGroupId") Long projectGroupId);

} 