package cn.palmte.work.model;

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

import java.math.BigDecimal;
import java.util.List;

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

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

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

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

    @Query(value = "select sum(cost_tax_exclude) from project_settle_cost_manage where project_id = ? and type = ?", nativeQuery = true)
    BigDecimal costTaxExcludeSum(int projectId, int type);

    List<ProjectSettleCostManage> findAllByProjectId(int id);

    List<ProjectSettleCostManage> findAllByTime(String time);

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

    @Query(value = "select sum(cost_tax_exclude) from project_settle_cost_manage where time = ? and type = ?", nativeQuery = true)
    BigDecimal costManageTaxExcludeSumByTime(String time, int type);

    @Query(value = "select sum(cost_tax_exclude) from project_settle_cost_manage where type = ?", nativeQuery = true)
    BigDecimal costManageTaxExcludeSumByType(int type);

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