package com.dtok.repository;
import com.dtok.entity.Permission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @Description  
 * @Author  C.J
 * @Date 2024-03-08 
 */

public interface PermissionRepository extends JpaRepository<Permission, String>, JpaSpecificationExecutor<Permission> {

    @Query("select AP from Account AU LEFT JOIN RolePermission ARP ON AU.roleCode = ARP.roleCode\n" +
            "LEFT JOIN Permission AP ON AP.code = ARP.pmCode\n" +
            "where AU.username = :code and AP.isActive = 1 order by AP.seq asc ")
    List<Permission> findPermissionByUsername(@Param("code") String code);

    @Query("select AP from Account AU LEFT JOIN RolePermission ARP ON AU.roleCode = ARP.roleCode\n" +
            "LEFT JOIN Permission AP ON AP.code = ARP.pmCode\n" +
            "where AU.username = :code and AP.isActive = 1 and AP.isMenu = 1 order by AP.seq asc")
    List<Permission> findPermissionMenuByUsername(@Param("code") String code);
    List<Permission> findAllByIsMenuOrderBySeqAsc(Boolean isMenu);

}
