using System;
using System.Collections.Generic;
using System.Text;
using Edu.Model.ViewModel.App;
using Edu.Repository.App;
using VT.FW.DB;

namespace Edu.Module.System
{
    public class AppSystemMsgModule
    {


        /// <summary>
        /// app学生系统消息仓储层对象
        /// </summary>
        private readonly RB_Student_SystemMsgRepository studentSystemMsgRepository = new RB_Student_SystemMsgRepository();
        #region 学生app系统消息
        /// <summary>
        /// 获取学生app系统消息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Student_SystemMsg_ViewModel> GetStudentSystemMsgList(RB_Student_SystemMsg_ViewModel query)
        {
            return studentSystemMsgRepository.GetStudentSystemMsgList(query);
        }



        /// <summary>
        /// 新增系统消息
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        //[TransactionCallHandler]
        public bool SetStudentSystemMsg(RB_Student_SystemMsg_ViewModel model)
        {
            bool flag = false;
            if (model.MsgId == 0)
            {
                return studentSystemMsgRepository.Insert(model) > 0;
            }
            return flag;
        }
        /// <summary>
        /// 批量新增系统消息
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        //[TransactionCallHandler]
        public bool BatchSetStudentSystemMsg(List<RB_Student_SystemMsg_ViewModel> list)
        {

            return studentSystemMsgRepository.InsertBatch(list);
        }


        /// <summary>
        /// 批量删除消息
        /// </summary>
        /// <param name="MsgType"></param>
        /// <param name="Group_Id"></param>
        /// <param name="AccountId"></param>
        /// <returns></returns>
        public bool DelStudentMsgById(string MsgIds, int Group_Id)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_Student_SystemMsg_ViewModel.Status),1 }

                };
            List<WhereHelper> wheres = new List<WhereHelper>() {
                    new WhereHelper(){
                         FiledName=nameof(RB_Student_SystemMsg_ViewModel.MsgId),
                          FiledValue=MsgIds,
                           OperatorEnum=OperatorEnum.IN
                    },
                     new WhereHelper(){
                         FiledName=nameof(RB_Student_SystemMsg_ViewModel.Group_Id),
                          FiledValue=Group_Id,
                           OperatorEnum=OperatorEnum.Equal
                    }
                };
            return studentSystemMsgRepository.Update(fileds, wheres);
        }


        /// <summary>
        /// 批量更新未读消息
        /// </summary>
        /// <param name="MsgType"></param>
        /// <param name="Group_Id"></param>
        /// <param name="AccountId"></param>
        /// <returns></returns>
        public bool UpdateStudentMsgById(int MsgId, int Group_Id, int AccountId)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_Student_SystemMsg_ViewModel.IsRead),1 },
                    {nameof(RB_Student_SystemMsg_ViewModel.ReadTime),DateTime.Now}

                };
            List<WhereHelper> wheres = new List<WhereHelper>() {
                    new WhereHelper(){
                         FiledName=nameof(RB_Student_SystemMsg_ViewModel.MsgId),
                          FiledValue=MsgId,
                           OperatorEnum=OperatorEnum.Equal
                    },
                     new WhereHelper(){
                         FiledName=nameof(RB_Student_SystemMsg_ViewModel.Group_Id),
                          FiledValue=Group_Id,
                           OperatorEnum=OperatorEnum.Equal
                    }
                     , new WhereHelper(){
                         FiledName=nameof(RB_Student_SystemMsg_ViewModel.Student_Id),
                          FiledValue=AccountId,
                           OperatorEnum=OperatorEnum.Equal
                    }
                };
            return studentSystemMsgRepository.Update(fileds, wheres);
        }

        /// <summary>
        /// 批量更新未读消息
        /// </summary>
        /// <param name="MsgType"></param>
        /// <param name="Group_Id"></param>
        /// <param name="AccountId"></param>
        /// <returns></returns>
        public bool UpdateStudentMsg(int MsgType, int Group_Id, int AccountId)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_Student_SystemMsg_ViewModel.IsRead),1 },
                    {nameof(RB_Student_SystemMsg_ViewModel.ReadTime),DateTime.Now}

                };
            List<WhereHelper> wheres = new List<WhereHelper>() {
                    new WhereHelper(){
                         FiledName=nameof(RB_Student_SystemMsg_ViewModel.MsgType),
                          FiledValue=MsgType,
                           OperatorEnum=OperatorEnum.Equal
                    },
                     new WhereHelper(){
                         FiledName=nameof(RB_Student_SystemMsg_ViewModel.Group_Id),
                          FiledValue=Group_Id,
                           OperatorEnum=OperatorEnum.Equal
                    }
                     , new WhereHelper(){
                         FiledName=nameof(RB_Student_SystemMsg_ViewModel.Student_Id),
                          FiledValue=AccountId,
                           OperatorEnum=OperatorEnum.Equal
                    }
                };
            return studentSystemMsgRepository.Update(fileds, wheres);
        }


        /// <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> GetStudentSystemMsgPageList(int pageIndex, int pageSize, out long rowsCount, RB_Student_SystemMsg_ViewModel query)
        {
            return studentSystemMsgRepository.GetStudentSystemMsgPageListRepository(pageIndex, pageSize, out rowsCount, query);
        }
        #endregion
    }
}
