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 javax.transaction.Transactional;
import java.util.Date;
import java.util.List;

public interface ProjectRepository extends JpaRepository<Project,Integer> {

    @Query(value = "select * from project where name = ?1", nativeQuery = true)
    Project findByProjectName(String projectName);

    @Query(value = "select * from project where project_no = ?1", nativeQuery = true)
    Project findByProjectNo(String projectNo);

    @Query(value = "select * from project where dept_id = ?1", nativeQuery = true)
    List<Project> findByDeptId(int deptId);

    @Query(value = "select * from project where creator_id = ?1 and end_date >= ?2 and start_date <= ?2", nativeQuery = true)
    List<Project> findByCreator(int id, Date date);

    @Modifying
    @Transactional(rollbackOn = Exception.class)
    @Query(value = "update project set project_no = ?1 where id = ?2", nativeQuery = true)
    int updateProjectNo(String projectNo, int id);
}
