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

import com.its.op.entity.its.link.TbLinkParaClctSyst;
import com.its.op.entity.its.link.TbLinkParaClctSystKey;
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 org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface TbLinkParaClctSystRepository extends JpaRepository<TbLinkParaClctSyst, TbLinkParaClctSystKey>, JpaSpecificationExecutor<TbLinkParaClctSyst> {

    @Query("select p from TbLinkParaClctSyst p inner join fetch p.syst m order by p.paraId, p.fusnPrrt")
    List<TbLinkParaClctSyst> findAll();

    @Query(value = "select p from TbLinkParaClctSyst p inner join fetch p.syst m where p.paraId = :para_id order by p.paraId, p.fusnPrrt")
    List<TbLinkParaClctSyst> findClctsById(@Param("para_id") Long para_id);

    @Modifying
    @Query(value = "delete from TB_LINK_PARA_CLCT_SYST where PARA_ID = :para_id", nativeQuery = true)
    void deleteListById(@Param("para_id")Long para_id);

    @Transactional
    @Modifying
    @Query("delete from TbLinkParaClctSyst p where p.paraId = :paraId")
    void deleteDataById(@Param("paraId") Long paraId);
}
