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

namespace Edu.Repository.WeChat
{
    /// <summary>
    /// 投稿发布记录仓储层
    /// </summary>
    public class RB_Contribute_PublishLogRepository : BaseRepository<RB_Contribute_PublishLog>
    {
        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_Contribute_PublishLog_ViewModel> GetPageList(int pageIndex,int pageSize,out long count, RB_Contribute_PublishLog_ViewModel demodel)
        {
            DynamicParameters parameters = new DynamicParameters();
            string where = $@" 1=1 and r.{nameof(RB_Contribute_PublishLog_ViewModel.Status)} =0";
            if (demodel.Group_Id > 0)
            {
                where += $@" and r.{nameof(RB_Contribute_PublishLog_ViewModel.Group_Id)} ={demodel.Group_Id}";
            }
            if (demodel.ContributeId > 0)
            {
                where += $@" and r.{nameof(RB_Contribute_PublishLog_ViewModel.ContributeId)} ={demodel.ContributeId}";
            }
            if (demodel.PlatfromId > 0)
            {
                where += $@" and r.{nameof(RB_Contribute_PublishLog_ViewModel.PlatfromId)} ={(int)demodel.PlatfromId}";
            }

            string sql = $@" 
SELECT * From RB_Contribute_PublishLog r
WHERE {where} 
ORDER BY r.Id DESC ";
            return GetPage<RB_Contribute_PublishLog_ViewModel>(pageIndex, pageSize, out count, sql, parameters).ToList();
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_Contribute_PublishLog_ViewModel> GetList(RB_Contribute_PublishLog_ViewModel demodel)
        {
            DynamicParameters parameters = new DynamicParameters();
            string where = $@" 1=1 and r.{nameof(RB_Contribute_PublishLog_ViewModel.Status)} =0";
            if (demodel.Group_Id > 0)
            {
                where += $@" and r.{nameof(RB_Contribute_PublishLog_ViewModel.Group_Id)} ={demodel.Group_Id}";
            }
            if (demodel.ContributeId > 0)
            {
                where += $@" and r.{nameof(RB_Contribute_PublishLog_ViewModel.ContributeId)} ={demodel.ContributeId}";
            }
            if (demodel.PlatfromId > 0)
            {
                where += $@" and r.{nameof(RB_Contribute_PublishLog_ViewModel.PlatfromId)} ={(int)demodel.PlatfromId}";
            }

            string sql = $@" 
SELECT * From RB_Contribute_PublishLog r
WHERE {where} 
ORDER BY r.Id DESC ";
            return Get<RB_Contribute_PublishLog_ViewModel>(sql, parameters).ToList();
        }

    }
}
