package cn.palmte.work.model;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * @author Yuanping Zhang
 * @date 2021/11/1
 */
@Transactional(rollbackFor = Exception.class)
public interface ProjectUserTimeRepository extends JpaRepository<ProjectUserTime, Integer> {

    @Query(value = "select * from project_user_time where user_id = ?1 and project_id = ?2 and time = ?3 limit 1", nativeQuery = true)
    ProjectUserTime findByUserIdAndProjectIdAndTime(int userId, int projectId, String time);

    @Query(value = "select * from project_user_time where time = ?1", nativeQuery = true)
    List<ProjectUserTime> findAllByTime(String time);

    @Query(value = "select * from project_user_time where project_id = ?1 and time = ?2", nativeQuery = true)
    List<ProjectUserTime> findByProjectIdAndTime(int projectId, String time);

    @Modifying
    @Query(value = "delete from project_user_time where time = ?1", nativeQuery = true)
    int deleteByTime(String date);
}
