using Edu.Model.ViewModel.Course;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB.Dapper;

namespace Edu.Repository.Course
{
    /// <summary>
    /// 课程教案仓储层
    /// </summary>
    public class RB_Course_TeachPlanRepository : BaseRepository<Model.Entity.Course.RB_Course_TeachPlan>
    {
        /// <summary>
        /// 获取课程教案分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Course_TeachPlan_ViewModel> GetCourseTeachPlanPageListRepository(int pageIndex, int pageSize, out long rowsCount, RB_Course_TeachPlan_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            var parameters = new DynamicParameters();
            builder.AppendFormat(@"
SELECT * 
FROM rb_course_teachplan
WHERE 1=1 
"); 
            builder.AppendFormat(" AND {0}={1} ", nameof(RB_Course_TeachPlan_ViewModel.Group_Id), query.Group_Id);
            builder.AppendFormat(" AND {0}={1} ", nameof(RB_Course_TeachPlan_ViewModel.School_Id), query.School_Id);
            if (query.CourseId > 0)
            {
                builder.AppendFormat(" AND {0}={1} ", nameof(RB_Course_TeachPlan_ViewModel.CourseId), query.CourseId);
            }
            if (!string.IsNullOrWhiteSpace(query.PlanName))
            {
                builder.AppendFormat(" AND {0} LIKE @PlanName ", nameof(RB_Course_TeachPlan_ViewModel.PlanName));
                parameters.Add("PlanName", "%" + query.PlanName.Trim() + "%");
            }
            return GetPage<RB_Course_TeachPlan_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString(), parameters).ToList();
        }
    }
}