package com.sysu.admin.support.system.region;

import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface RegionRepository extends JpaPlusRepository<Region, Integer> {

    Region findByCode(Integer code);

    Region findByNameShortAndParent(String nameShort, Integer parentCode);

    @Query(value = "SELECT * FROM (SELECT * FROM sys_region a WHERE a.`parent` = ?2) b WHERE b.code IN (?1)", nativeQuery = true)
    List<Region> findByCodeIsInParent(Integer child, Integer parent);
}
