package com.dashitech.businessdata.dao;

import com.dashitech.businessdata.entity.DictionaryEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Created by chi on 2020/8/25.
 */
public interface IDictionaryDAO extends JpaRepository<DictionaryEntity, String> {

    @SuppressWarnings("unchecked")
    DictionaryEntity save(DictionaryEntity dictionaryEntity);

    @Query(value = "SELECT * FROM itsm_base_dictionary g WHERE g.deleted = FALSE AND g._key =?1",nativeQuery = true)
    List<DictionaryEntity> selectDictionaryByKey(String key);

    @Query(value = "SELECT id FROM itsm_base_dictionary g WHERE g._key =:_key and g._value =:_value",nativeQuery = true)
    Long selectDictionaryByKeyValueId(@Param("_key")String _key, @Param("_value")String _value);

    @Query(value = "SELECT _value FROM itsm_base_dictionary g WHERE g._key =:_key and g._desc =:_desc limit 1",nativeQuery = true)
    String selectDictionaryByKeyDescValue(@Param("_key")String _key, @Param("_desc")String _desc);
}
