SystemDictEntryRepository.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.yihu.ehr.basic.dict.dao;
  2. import com.yihu.ehr.entity.dict.DictEntryKey;
  3. import com.yihu.ehr.entity.dict.SystemDictEntry;
  4. import org.springframework.data.domain.Page;
  5. import org.springframework.data.domain.Pageable;
  6. import org.springframework.data.jpa.repository.JpaRepository;
  7. import org.springframework.data.jpa.repository.Modifying;
  8. import org.springframework.data.jpa.repository.Query;
  9. import org.springframework.data.repository.query.Param;
  10. import java.util.List;
  11. /**
  12. * 字典项DAO。
  13. *
  14. * @author Sand
  15. * @version 1.0
  16. * @created 2017.01.30 14:43
  17. */
  18. public interface SystemDictEntryRepository extends JpaRepository<SystemDictEntry, DictEntryKey> {
  19. List<SystemDictEntry> findByDictId(long dictId);
  20. Page<SystemDictEntry> findByDictId(long dictId, Pageable pageable);
  21. Page<SystemDictEntry> findByDictIdAndValueLike(long dictId, String value, Pageable pageable);
  22. @Modifying
  23. void deleteByDictId(long dictId);
  24. /**
  25. * 获取字典项下一排序号.
  26. *
  27. * @param dictId
  28. * @return
  29. */
  30. @Query("select max(entry.sort) from SystemDictEntry entry where entry.dictId = :dictId")
  31. Integer getNextEntrySN(@Param("dictId") long dictId);
  32. /**
  33. * 批量获取字典项列表.
  34. *
  35. * @param dictId
  36. * @param codes
  37. * @return
  38. */
  39. @Query("select entry from SystemDictEntry entry where entry.dictId = :dictId and entry.code in (:codes) order by entry.sort asc")
  40. List<SystemDictEntry> findByDictIdAndCodes(@Param("dictId") long dictId, @Param("codes") String[] codes);
  41. @Query("select entry from SystemDictEntry entry where entry.dictId = :dictId and entry.value = :value")
  42. List<SystemDictEntry> findByDictIdAndValue(@Param("dictId") long dictId, @Param("value") String value);
  43. List<SystemDictEntry> findByDictIdAndCode(@Param("dictId") long dictId, @Param("code") String code);
  44. }