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

namespace Edu.Repository.App
{
    /// <summary>
    /// 学生app系统消息
    /// </summary>
    public class RB_Student_SystemMsgRepository : BaseRepository<RB_Student_SystemMsg>
    {
        /// <summary>
        /// 获取学生app系统消息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Student_SystemMsg_ViewModel> GetStudentSystemMsgList(RB_Student_SystemMsg_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@" SELECT *  FROM RB_Student_SystemMsg  WHERE 1=1  ");
            builder.AppendFormat(" AND {0}={1} ", nameof(RB_Student_SystemMsg.Status), (int)DateStateEnum.Normal);
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Student_SystemMsg.Group_Id), query.Group_Id);
                }
                if (query.School_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Student_SystemMsg.School_Id), query.School_Id);
                }
                if (query.Student_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Student_SystemMsg.Student_Id), query.Student_Id);
                }
                if (query.MsgId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Student_SystemMsg.MsgId), query.MsgId);
                }
                if (query.IsRead > -1)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Student_SystemMsg.IsRead), query.IsRead);
                }
                if (query.MsgType.HasValue && query.MsgType.Value > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Student_SystemMsg.MsgType), (int)query.MsgType);
                }
                if (query.StudentType.HasValue && query.StudentType.Value > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Student_SystemMsg.StudentType), (int)query.StudentType);
                }
            }
            return Get<RB_Student_SystemMsg_ViewModel>(builder.ToString()).ToList();
        }


        /// <summary>
        /// 获取学生app系统分页列表
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <param name="rowsCount">总条数</param>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Student_SystemMsg_ViewModel> GetStudentSystemMsgPageListRepository(int pageIndex, int pageSize, out long rowsCount, RB_Student_SystemMsg_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@" SELECT *  FROM RB_Student_SystemMsg WHERE 1=1 ");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Student_SystemMsg.Group_Id), query.Group_Id);
                }
                if (query.School_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Student_SystemMsg.School_Id), query.School_Id);
                }
                if (query.Student_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Student_SystemMsg.Student_Id), query.Student_Id);
                }
                if (query.IsRead > -1)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Student_SystemMsg.IsRead), query.IsRead);
                }
                if (query.MsgType.HasValue && query.MsgType.Value > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Student_SystemMsg.MsgType), (int)query.MsgType);
                }
                if (query.StudentType.HasValue && query.StudentType.Value > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Student_SystemMsg.StudentType), (int)query.StudentType);
                }
            }
            builder.Append(" ORDER BY MsgId DESC ");
            return GetPage<RB_Student_SystemMsg_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList();
        }
    }
}