using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Edu.Model.Entity.Exam;
using Edu.Model.ViewModel.Exam;

namespace Edu.Repository.Exam
{
    /// <summary>
    /// 学生答题详情仓储类
    /// </summary>
    public class RB_Examination_StudentDetailsRepository : BaseRepository<RB_Examination_StudentDetails>
    {

        /// <summary>
        /// 获取考试学生列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Examination_StudentDetails_ViewModel> GetExaminationStudentListRepository(RB_Examination_StudentDetails_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*,IFNULL(B.GuestName,'') AS GuestName
FROM  RB_Examination_StudentDetails AS A
      INNER JOIN RB_Examination_Student AS c ON (C.GuestId=a.GuestId AND A.PaperId=C.PaperId AND A.PublishId=C.PublishId)
      INNER JOIN rb_order_guest AS B ON c.GuestId=B.Id
WHERE 1=1 
");
            builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Examination_StudentDetails_ViewModel.Status), 0);
            if (query != null)
            {
                if (query.GuestId > 0)
                {
                    builder.AppendFormat(" AND c.{0}={1} ", nameof(RB_Examination_Student.GuestId), query.GuestId);
                }
                if (query.PublishId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Examination_StudentDetails_ViewModel.PublishId), query.PublishId);
                }
                if (query.PaperId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Examination_StudentDetails_ViewModel.PaperId), query.PaperId);
                }
            }
            return Get<RB_Examination_StudentDetails_ViewModel>(builder.ToString()).ToList();
        }
    }
}
