package com.crm.manager.dao.repository;

import com.crm.rely.backend.core.pojo.table.SysConfigTable;
import com.crm.rely.backend.dao.repository.BaseRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.stereotype.Repository;

import javax.persistence.LockModeType;
import java.util.List;

/**
 * @author: houn
 */
@Repository
public interface SysConfigRepository extends BaseRepository<SysConfigTable> {

    /**
     * 根据codes 获取系统配置信息
     *
     * @param codes code的列表
     * @return
     */
    List<SysConfigTable> getByCodeIn(List<String> codes);

    /**
     * 根据code 获取系统配置信息
     *
     * @param code code
     * @return
     */
    SysConfigTable getByCode(String code);


    List<SysConfigTable> getAllByIdIsNotNull();

    SysConfigTable getByIdAndCode(Long id,String code);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    SysConfigTable findFirstByCode(String code);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    List<SysConfigTable> findAllByCodeIn(List<String> codes);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    SysConfigTable findFirstByIdAndCode(Long id, String code);

    boolean existsByCode(String code);
}
