package com.huimv.admin.repo.primary;

import com.huimv.admin.domain.primary.SysAccountGroupEntity;
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 SysAccountGroupEntityRepository extends JpaRepository<SysAccountGroupEntity, Integer>, JpaSpecificationExecutor<SysAccountGroupEntity> {

    @Modifying
    @Transactional
    @Query(nativeQuery = true,value = "DELETE FROM sys_account_group WHERE group_id=?1")
    void removeAccountGroup(String groupIds);

    @Query(nativeQuery = true,value = "SELECT * FROM sys_account_group WHERE account_id=?1")
    List<SysAccountGroupEntity> getGroupByAccount(String accountId);

    @Query(nativeQuery = true,value = "SELECT * FROM sys_account_group WHERE group_id=?1")
    List<SysAccountGroupEntity> getAccountByGroup(String groupId);

    @Transactional
    @Modifying
    @Query(nativeQuery = true,value = "INSERT INTO sys_account_group(account_id,group_id)VALUES(?1,?2)")
    void insert(int accountId, int groupId);

    @Modifying
    @Transactional
    @Query(nativeQuery = true,value = "DELETE FROM sys_account_group WHERE account_id=?1 AND group_id=?2")
    void removeAccountGroup(String accountId, String groupId);
}