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

namespace Edu.Repository.Course
{
    public class RB_Class_LessonPlanDetailsRepository : BaseRepository<RB_Class_LessonPlanDetails>
    {
        /// <summary>
        /// 获取老师教案详情分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Class_LessonPlanDetails_ViewModel> GetLessonPlanDetailsPageListRepository(int pageIndex, int pageSize, out long rowsCount, RB_Class_LessonPlanDetails_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@" SELECT *  FROM RB_Class_LessonPlanDetails WHERE 1=1  ");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonPlanDetails.Group_Id), query.Group_Id);
                }
                if (query.School_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonPlanDetails.School_Id), query.School_Id);
                }
                if (query.LessonPlanId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonPlanDetails.LessonPlanId), query.LessonPlanId);
                }
            }
            return GetPage<RB_Class_LessonPlanDetails_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList();
        }

        /// <summary>
        /// 获取老师教案详情分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Class_LessonPlanDetails_ViewModel> GetLessonPlanDetailsListRepository(RB_Class_LessonPlanDetails_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@" SELECT *  FROM RB_Class_LessonPlanDetails WHERE 1=1  ");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonPlanDetails.Group_Id), query.Group_Id);
                }
                if (query.School_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonPlanDetails.School_Id), query.School_Id);
                }
                if (query.LessonPlanId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonPlanDetails.LessonPlanId), query.LessonPlanId);
                }
                if ( !string.IsNullOrWhiteSpace(query.LessonPlanIds))
                {
                    builder.AppendFormat(" AND {0} in ({1}) ", nameof(RB_Class_LessonPlanDetails.LessonPlanId), query.LessonPlanIds);
                }
            }
            return Get<RB_Class_LessonPlanDetails_ViewModel>(builder.ToString()).ToList();
        }
    }
}
