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

import com.rf.psychological.base.repository.BaseRepository;
import com.rf.psychological.user.dao.model.UserRepeatNameNumEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lpf
 * @description:
 * @date 17/12/2021下午4:35
 */
public interface UserRepeatNameNumRepository extends BaseRepository<UserRepeatNameNumEntity, String> {

    List<UserRepeatNameNumEntity> findAllByInstitutionNo(String institutionNo);

    UserRepeatNameNumEntity findUserRepeatNameNumEntityByNamePinyinAndInstitutionNo(String namePinyin, String institutionNo);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update t_repeat_username set num = ?3 where name_pinyin=?1 and institution_no=?2", nativeQuery = true)
    int updateNum(String namePinyin, String institutionNo, int num);


}
