package cn.com.ty.lift.ud.expertComment.mapper;


import cn.com.ty.lift.ud.expertComment.controller.query.ExpertCommentQuery;
import cn.com.ty.lift.ud.expertComment.mapper.entity.ExpertCommentEntity;
import cn.com.ty.lift.ud.expertComment.mapper.entity.ScoreInfo;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 诊单评论  -Repository
 *
 * @author Xson
 * @date 2020-05-06
 */
public interface ExpertCommentMapper extends BaseMapper<ExpertCommentEntity> {

    /**
     * 多表查询
     *
     * @param condition
     * @param page
     * @return
     */
    List<ExpertCommentEntity> selectByQuery(@Param("ew") Wrapper condition, @Param("page") ExpertCommentQuery page);

    /**
     * 查询总数量
     *
     * @param condition
     * @return
     */
    int countByQuery(@Param("ew") Wrapper condition);

    /**
     * 获取专家评论
     * @@return
     * @param condition
     * @param page
     */
    List<ExpertCommentEntity> getExpertComment(@Param("ew") Wrapper condition, @Param("page") ExpertCommentQuery page);

    /**
     * 查询评论总数量
     *
     * @param condition
     * @return
     */
    int countAllByQuery(@Param("ew") Wrapper condition);

    /**
     * 根据专家ID查询评论个数和总分
     * @param userId
     * @return
     */
    @Select("select count(*) as num,sum(average_score) as totalScore from expert_comment where expert_id = #{userId} ")
    ScoreInfo getScoreByExpertId(Long userId);
    
    @Select("    SELECT * FROM expert_comment WHERE expert_id=#{rxperId}")
    List<ExpertCommentEntity>getCommentByUserId(Long rxperId);
}
