package com.yihu.jw.base.dao.menu;

import com.yihu.jw.entity.base.menu.BaseMenuDictDO;
import com.yihu.jw.entity.base.role.MenuDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface BaseMenuDictDao extends PagingAndSortingRepository<BaseMenuDictDO, String>, JpaSpecificationExecutor<BaseMenuDictDO> {
    @Query( value = "select max(t.menu_sort) AS \"zuida\" from base_menu_dict t where t.parent_id=?1 and t.is_del='1'",nativeQuery = true)
    Integer getMaxSort(String parentId);
    @Query( value = "select min(t.menu_sort) AS \"zuixiao\" from base_menu_dict t where t.parent_id=?1 and t.is_del='1'",nativeQuery = true)
    Integer getMinSort(String parentId);

    @Modifying
    @Query("update BaseMenuDictDO p set p.status=?2 where p.id=?1")
    void updateStatus(String id,Integer status);
    @Query("from BaseMenuDictDO p where p.parentId=?1 and p.isDel='1'")
    List<BaseMenuDictDO> findByParentId(String parentId);
}
