package com.its.op.dao.repository.its.oper;

import com.its.op.entity.its.oper.TbUserGropMenuAthr;
import com.its.op.entity.its.oper.TbUserGropMenuAthrKey;
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.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TbUserGropMenuAthrRepository extends JpaRepository<TbUserGropMenuAthr, TbUserGropMenuAthrKey>, JpaSpecificationExecutor<TbUserGropMenuAthr> {

    @Query(value = "select p from TbUserGropMenuAthr p inner join fetch p.operMenu inner join fetch p.userGrop")
    List<TbUserGropMenuAthr> findAll();

    @Modifying
    @Query("delete from TbUserGropMenuAthr p where p.gropId = :gropId and p.menuId = :menuId")
    void deleteByOperSystMenuId(@Param("gropId") String gropId, @Param("menuId") String menuId);

    @Modifying
    @Query(value = "insert into TB_USER_GROP_MENU_ATHR(GROP_ID, MENU_ID, ATHR_YN) values(:gropId, :menuId, :authrYn)", nativeQuery = true)
    void insertData(@Param("gropId") String gropId, @Param("menuId") String menuId, @Param("authrYn") String authrYn);

}
