using System.Collections.Generic;
using System.Linq;
using Edu.Model.Entity.User;
using Edu.Model.ViewModel.User;

namespace Edu.Repository.User
{

    /// <summary>
    /// 行政备注仓储层
    /// </summary>
    public class RB_AccountRemarkRepository : BaseRepository<RB_AccountRemark>
    {
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_AccountRemark_ViewModel> GetList(RB_AccountRemark_ViewModel demodel)
        {
            string where = $@" 1=1";
            if (demodel.Group_Id > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.Group_Id)} ={demodel.Group_Id}";
            }
            if (demodel.RemarkType > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.RemarkType)} ={(int)demodel.RemarkType}";
            }
            if (demodel.AccountType > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.AccountType)} ={(int)demodel.AccountType}";
            }
            if (demodel.AccountId > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.AccountId)} ={(int)demodel.AccountId}";
            }

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

        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_AccountRemark_ViewModel> GetPageList(int pageIndex, int pageSize, out long rowsCount, RB_AccountRemark_ViewModel demodel)
        {
            string where = $@" 1=1";

            if (demodel.Group_Id > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.Group_Id)} ={demodel.Group_Id}";
            }
            if (demodel.RemarkType > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.RemarkType)} ={(int)demodel.RemarkType}";
            }
            if (demodel.AccountType > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.AccountType)} ={(int)demodel.AccountType}";
            }
            if (demodel.AccountId > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.AccountId)} ={(int)demodel.AccountId}";
            }

            string sql = $@" select * from RB_AccountRemark where {where}";
            return GetPage<RB_AccountRemark_ViewModel>(pageIndex, pageSize, out rowsCount, sql).ToList();
        }


        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_AccountRemark_ViewList> GetAccountRemarkPageList(int pageIndex, int pageSize, out long rowsCount, RB_AccountRemark_ViewList demodel)
        {
            string where = $@" ";

            if (demodel.Group_Id > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.Group_Id)} ={demodel.Group_Id}";
            }
            if (demodel.RemarkType > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.RemarkType)} ={(int)demodel.RemarkType}";
            }
            if (demodel.AccountType > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.AccountType)} ={(int)demodel.AccountType}";
            }
            if (demodel.AccountId > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.AccountId)} ={(int)demodel.AccountId}";
            }
            if (!string.IsNullOrWhiteSpace(demodel.KeyWord))
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.AccountId)} ={(int)demodel.AccountId}";
            }
            if (!string.IsNullOrWhiteSpace(demodel.StartDate))
            {
                where += $@" and  DATE_FORMAT({nameof(RB_AccountRemark_ViewModel.CreateTime)},'%Y-%m-%d' )>=DATE_FORMAT('{demodel.StartDate}','%Y-%m-%d' ) ";
            }
            if (!string.IsNullOrWhiteSpace(demodel.EndDate))
            {
                where += $@" and  DATE_FORMAT({nameof(RB_AccountRemark_ViewModel.CreateTime)},'%Y-%m-%d' )<= DATE_FORMAT('{demodel.EndDate}','%Y-%m-%d' ) ";
            }
            string sql = $@"
SELECT  DATE_FORMAT(CreateTime,'%Y-%m-%d') as CreateStr from rb_accountremark where `Status`=0   
{where}  
GROUP BY DATE_FORMAT(CreateTime,'%Y-%m-%d')
ORDER BY DATE_FORMAT(CreateTime,'%Y-%m-%d') DESC 
";
            return GetPage<RB_AccountRemark_ViewList>(pageIndex, pageSize, out rowsCount, sql).ToList();
        }
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="demodel"></param>
        /// <param name="orderIds"></param>
        /// <returns></returns>
        public List<RB_AccountRemark_ViewModel> GetListByWhere(RB_AccountRemark_ViewList demodel)
        {
            string where = $@" ";
            if (demodel.Group_Id > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.Group_Id)} ={demodel.Group_Id}";
            }
            if (demodel.RemarkType > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.RemarkType)} ={(int)demodel.RemarkType}";
            }
            if (demodel.AccountType > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.AccountType)} ={(int)demodel.AccountType}";
            }
            if (demodel.AccountId > 0)
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.AccountId)} ={(int)demodel.AccountId}";
            }
            if (!string.IsNullOrWhiteSpace(demodel.KeyWord))
            {
                where += $@" and {nameof(RB_AccountRemark_ViewModel.AccountId)} ={(int)demodel.AccountId}";
            }
            if (!string.IsNullOrWhiteSpace(demodel.StartDate))
            {
                where += $@" and  DATE_FORMAT({nameof(RB_AccountRemark_ViewModel.CreateTime)},'%Y-%m-%d' )>=DATE_FORMAT('{demodel.StartDate}','%Y-%m-%d' ) ";
            }
            if (!string.IsNullOrWhiteSpace(demodel.EndDate))
            {
                where += $@" and  DATE_FORMAT({nameof(RB_AccountRemark_ViewModel.CreateTime)},'%Y-%m-%d' )<= DATE_FORMAT('{demodel.EndDate}','%Y-%m-%d' ) ";
            }
            string sql = $@" select * from RB_AccountRemark where `Status`=0  {where}";
            return Get<RB_AccountRemark_ViewModel>(sql).ToList();
        }
    }
}