package cn.palmte.work.model;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author Yuanping Zhang
 * @date 2021/11/11
 */
public interface ProjectSettleProfitMarginRepository extends JpaRepository<ProjectSettleProfitMargin, Integer> {

    List<ProjectSettleProfitMargin> findAllByProjectIdAndTime(int id, String time);

    @Query(value = "select * from project_settle_profit_margin where project_id = ?1 and time < ?2", nativeQuery = true)
    List<ProjectSettleProfitMargin> findAllByProjectIdBefore(int id, String time);

    @Query(value = "select * from project_settle_profit_margin where project_id = ?1 and time <= ?2", nativeQuery = true)
    List<ProjectSettleProfitMargin> findAllByProjectIdAndTimeBeforeAndEquals(int id, String time);

    List<ProjectSettleProfitMargin> findAllByProjectId(int id);

    List<ProjectSettleProfitMargin> findAllByTime(String time);

    @Query(value = "select * from project_settle_profit_margin where project_id in ?1 and time = ?2", nativeQuery = true)
    List<ProjectSettleProfitMargin> findAllByProjectsAndTime(List<Integer> ids, String time);

    @Query(value = "select * from project_settle_profit_margin where project_id in ?1", nativeQuery = true)
    List<ProjectSettleProfitMargin> findAllByProjectIds(List<Integer> projectIds);
}
