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

namespace Edu.Repository.Customer
{
    /// <summary>
    /// 同业提款账号仓储层对象
    /// </summary>
    public class RB_Customer_AccountRepository : BaseRepository<RB_Customer_Account>
    {
        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Customer_Account_Extend> GetAccountPageRepository(int pageIndex, int pageSize, out long rowsCount, RB_Customer_Account_Extend query)
        {
            var parameters = new DynamicParameters();
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@" 
SELECT A.*
FROM  RB_Customer_Account AS A
WHERE 1=1
");
            builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Customer_Account_Extend.Status), (int)DateStateEnum.Normal);
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Customer_Account_Extend.Group_Id), query.Group_Id);
                }
                if (!string.IsNullOrEmpty(query.BankName))
                {
                    builder.AppendFormat(" AND A.{0} LIKE @BankName ", nameof(RB_Customer_Account_Extend.BankName));
                    parameters.Add("BankName", "%" + query.BankName.Trim() + "%");
                }
                if (!string.IsNullOrEmpty(query.AccountHolder))
                {
                    builder.AppendFormat(" AND A.{0} LIKE @AccountHolder ", nameof(RB_Customer_Account_Extend.AccountHolder));
                    parameters.Add("AccountHolder", "%" + query.AccountHolder.Trim() + "%");
                }
                if (!string.IsNullOrEmpty(query.BankCardNo))
                {
                    builder.AppendFormat(" AND A.{0} LIKE @BankCardNo ", nameof(RB_Customer_Account_Extend.BankCardNo));
                    parameters.Add("BankCardNo", "%" + query.BankCardNo.Trim() + "%");
                }
            }
            return GetPage<RB_Customer_Account_Extend>(pageIndex, pageSize, out rowsCount, builder.ToString(), parameters).ToList();
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Customer_Account_Extend> GetAccountListRepository(RB_Customer_Account_Extend query)
        {
            var parameters = new DynamicParameters();
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@" 
SELECT A.*
FROM  RB_Customer_Account AS A
WHERE 1=1
");
            builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Customer_Account_Extend.Status), (int)DateStateEnum.Normal);
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Customer_Account_Extend.Group_Id), query.Group_Id);
                }
                if (!string.IsNullOrEmpty(query.BankName))
                {
                    builder.AppendFormat(" AND A.{0} LIKE @BankName ", nameof(RB_Customer_Account_Extend.BankName));
                    parameters.Add("BankName", "%" + query.BankName.Trim() + "%");
                }
                if (!string.IsNullOrEmpty(query.AccountHolder))
                {
                    builder.AppendFormat(" AND A.{0} LIKE @AccountHolder ", nameof(RB_Customer_Account_Extend.AccountHolder));
                    parameters.Add("AccountHolder", "%" + query.AccountHolder.Trim() + "%");
                }
                if (!string.IsNullOrEmpty(query.BankCardNo))
                {
                    builder.AppendFormat(" AND A.{0} LIKE @BankCardNo ", nameof(RB_Customer_Account_Extend.BankCardNo));
                    parameters.Add("BankCardNo", "%" + query.BankCardNo.Trim() + "%");
                }
                if (!string.IsNullOrEmpty(query.BankIds))
                {
                    builder.AppendFormat(" AND A.{0} in({1}) ", nameof(RB_Customer_Account_Extend.Id), query.BankIds);
                }
            }
            return Get<RB_Customer_Account_Extend>(builder.ToString(), parameters).ToList();
        }
    }
}
