package com.huimv.admin.repo.primary;

import com.huimv.admin.domain.primary.SysGroupMenuEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface SysGroupMenuEntityRepository extends JpaRepository<SysGroupMenuEntity, Integer>, JpaSpecificationExecutor<SysGroupMenuEntity> {

    @Modifying
    @Transactional
    @Query(nativeQuery = true,value = "DELETE FROM sys_group_menu WHERE group_id=?1")
    void removeGroupMenu(String groupId);

    @Query(nativeQuery = true,value = "SELECT * FROM sys_group_menu WHERE group_id=?1")
    List<SysGroupMenuEntity> getMenuByGroup(String groupId);

    @Modifying
    @Transactional
    @Query(nativeQuery = true,value = "DELETE FROM sys_group_menu WHERE group_id=?1 AND menu_id=?2")
    void removeGroupMenu(String groupId, String menuId);

    @Modifying
    @Transactional
    @Query(nativeQuery = true,value = "DELETE FROM sys_group_menu WHERE group_id=?1")
    void deleteByGroupId(Integer groupId);
}