package com.rf.psychological.group.dao.repository;

import com.rf.psychological.base.repository.BaseRepository;
import com.rf.psychological.group.dao.model.GroupEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lpf
 * @description:
 * @date 26/10/2021下午4:35
 */
public interface GroupInfoRepository extends BaseRepository<GroupEntity, String> {

    //查询机构下的组信息
    List<GroupEntity> findAllByInstitutionNo(@Param("institutionNo") String institutionNo);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update t_group_info set group_name = :groupName where id = :id ", nativeQuery = true)
    int updateGroup(String groupName, String id);

    //@Query(value = "select id ,group_name,institution_no from t_group_info where group_name = :groupName and institution_no = :institutionNo", nativeQuery=true)
    //GroupEntity findGroupByInstitutionNoAndName(@Param("institutionNo") String institutionNo,@Param("groupName") String groupName);
    GroupEntity findByInstitutionNoAndGroupName(@Param("institutionNo") String institutionNo,@Param("groupName") String groupName);

    @Transactional
    @Modifying(clearAutomatically = true)
    void deleteAllByInstitutionNo(String institutionNo);

}
