package com.rf.psychological.miniapp.comment.repository;

import com.rf.psychological.base.repository.BaseRepository;
import com.rf.psychological.miniapp.comment.model.CommentEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @Description:用户评论
 * @Author: mimang
 * @Date: 2023/5/16
 */
public interface CommentRepository extends BaseRepository<CommentEntity,String> {

    /**
     * 根据flag查询某量表或认知任务评论记录
     * @param flag
     * @return
     */
    @Query(value = "select * from t_comment_info where flag = :flag and status = :status order by create_time desc ",
            countQuery = "select count(*) from t_comment_info where flag = :flag and status = :status ",
            nativeQuery = true)
    Page<CommentEntity> queryByFlag(Pageable pageable, String flag, String status);

    /**
     * 根据flag查询某量表或认知任务评论记录数量
     * @param flag
     * @return
     */
    List<CommentEntity> findAllByFlagAndStatus(String flag, String status);
}
