package com.ssj.dao.sys.shortcuts.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.ssj.bean.sys.shortcuts.domain.Shortcuts;

import java.util.List;

/**
 * @author Mount Liu
 * @date 2018/8/16
 */
@Repository
public interface ShortcutsDao extends JpaRepository<Shortcuts, String> {

    /**
     * 分页查询快捷语列表
     * @param specification
     * @param page
     * @return
     */
    Page<Shortcuts> findAll(Specification<Shortcuts> specification, Pageable page);

    /**
     * 查询所有快捷语列表
     * @return
     */
    @Override
    @Query(nativeQuery = true, value = "select * from scon_shortcuts where is_valid = 'Y' order by shortcuts_order asc,created_time desc")
    List<Shortcuts> findAll();

    /**
     * 更新序号
     * @param id
     * @param order
     * @return
     */
    @Query(nativeQuery = true, value = "update scon_shortcuts set shortcuts_order = ?2 where id =?1 ")
    @Modifying
    Integer updateShortcutsOrder(String id,int order);
}
