package com.ssj.dao.sys.template;

import com.ssj.bean.sys.template.CommentTemplate;
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.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Mount Liu
 * @date 2018/11/19
 */
@Repository
public interface CommentTemplateDao extends JpaRepository<CommentTemplate, String> {

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

    /**
     * 查询作文模板列表
     * @param ids
     * @return
     */
    List<CommentTemplate> findByIdIn(List<String> ids);

    /**
     * 按年级查询作文模板
     * @param grade
     * @return
     */
    @Query(nativeQuery = true, value = "select * from scon_comment_template where grade regexp ?1 order by sort")
    List<CommentTemplate> findByGradeOrderBySort (String grade);

    /**
     * 根据作业图片id查询作文评语
     * @param homeworkPictureId 作业图片id
     */
    @Query(nativeQuery = true, value = "select scon_comment_template.* from scon_composition_comment, scon_comment_template " +
            "where scon_composition_comment.comment_template_id = scon_comment_template.id " +
            " and scon_composition_comment.homework_picture_id = ?1 " +
            "order by scon_comment_template.sort ")
    List<CommentTemplate> findByHomeworkPictureId(String homeworkPictureId);
}
