@@ -35,10 +35,15 @@ public interface SysDictRepository extends JpaRepository<SysDict, Integer> {
|
||||
@Param("dictType") String dictType,
|
||||
@Param("enableFlag") Integer enableFlag);
|
||||
|
||||
/** 可见单条:本校优先,其次全局;同 key 多条时按本校优先 + id 升序,服务侧取首条 */
|
||||
/**
|
||||
* 可见单条:本校优先,其次全局;同 key 多条时按本校优先 + id 升序,服务侧取首条。
|
||||
* <p>排序按「sch_id 是否为空」判定,不写成 {@code case when d.schId = :schId}:where 已限定
|
||||
* 本校或全局,两种写法等价,但在 order by 里再次引用命名参数会触发 Hibernate 参数绑定错位
|
||||
* (Spring Data 只绑 4 个占位符,SQL 有 5 个 → "No value specified for parameter 5")。</p>
|
||||
*/
|
||||
@Query("select d from SysDict d where d.dictType = :dictType and d.dictKey = :dictKey " +
|
||||
"and (d.schId = :schId or d.schId is null) " +
|
||||
"order by case when d.schId = :schId then 0 else 1 end asc, d.id asc")
|
||||
"order by case when d.schId is null then 1 else 0 end asc, d.id asc")
|
||||
List<SysDict> findVisibleBySchIdAndDictTypeAndDictKey(@Param("schId") Integer schId,
|
||||
@Param("dictType") String dictType,
|
||||
@Param("dictKey") String dictKey);
|
||||
|
||||
Reference in New Issue
Block a user