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

namespace Edu.Repository.Grade
{
    /// <summary>
    /// 班级关联课程仓储层
    /// </summary>
    public class RB_Class_CourseRepository : BaseRepository<RB_Class_Course>
    {
        /// <summary>
        /// 获取班级关联课程列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Class_Course_Extend> GetClassCourseListRepository(RB_Class_Course_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.* ,IFNULL(B.CourseName,'') AS CourseName,IFNULL(B.ClassHours,0) AS ClassHours,IFNULL(B.SellPrice,0) AS SellPrice
FROM RB_Class_Course AS A LEFT JOIN rb_course AS B ON A.CourseId=B.CourseId
WHERE 1=1
");
            builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Class_Course_Extend.Status), (int)DateStateEnum.Normal);
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Class_Course_Extend.Group_Id), query.Group_Id);
                }
                if (query.ClassId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Class_Course_Extend.ClassId), query.ClassId);
                }
                if (query.CourseId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Class_Course_Extend.CourseId), query.CourseId);
                }
                if (!string.IsNullOrEmpty(query.QClassIds))
                {
                    builder.AppendFormat(" AND A.{0} IN({1}) ", nameof(RB_Class_Course_Extend.ClassId), query.QClassIds);
                }
            }
            return Get<RB_Class_Course_Extend>(builder.ToString()).ToList();
        }
    }
}
