using Edu.Common.Enum;
using Edu.Model.Entity.User;
using Edu.Model.ViewModel.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB.Dapper;

namespace Edu.Repository.User
{
    /// <summary>
    /// 公告阅读仓储层
    /// </summary>
    public class RB_Notice_ReadRepository : BaseRepository<RB_Notice_Read>
    {
        public List<RB_Notice_Read_ViewModel> GetList(RB_Notice_Read_ViewModel demodel)
        {
            string where = $@" 1=1 and Status=0 ";
            if (demodel.NoticeId > 0)
            {
                where += $@" and {nameof(RB_Notice_Read.NoticeId)} ={demodel.NoticeId}";
            }
            if (demodel.AccountId > 0)
            {
                where += $@" and {nameof(RB_Notice_Read.AccountId)} ={demodel.AccountId}";
            }

            string sql = $@" select * from RB_Notice_Read where {where}";
            return Get<RB_Notice_Read_ViewModel>(sql).ToList();
        }

        /// <summary>
        /// 获取阅读数量列表
        /// </summary>
        /// <param name="noticeIds"></param>
        /// <returns></returns>
        public List<RB_Notice_Read_ViewModel> GetNoticeReadNumList(string noticeIds)
        {
            string sql = $@" select NoticeId,count(0) as ReadNum from RB_Notice_Read where NoticeId in ({noticeIds}) group by NoticeId";
            return Get<RB_Notice_Read_ViewModel>(sql).ToList();
        }
    }
}