using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Edu.Model.Entity.Finance;

namespace Edu.Repository.Finance
{
  public  class RB_Finance_OrderRecordRepository:BaseRepository<RB_Finance_OrderRecord>
    {
        /// <summary>
        /// 表名称
        /// </summary>
        public string TableName { get { return nameof(RB_Finance_OrderRecord); } }

        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<RB_Finance_OrderRecord> GetPageList(int pageIndex, int pageSize, out long count, RB_Finance_OrderRecord model)
        {
            string where = " WHERE 1=1 ";
            if (model.RB_Group_Id > 0)
            {
                where += string.Format(" AND " + nameof(RB_Finance_OrderRecord.RB_Group_Id) + "={0} ", model.RB_Group_Id);
            }
            if (model.ContractId > 0)
            {
                where += string.Format(" AND " + nameof(RB_Finance_OrderRecord.ContractId) + "={0} ", model.ContractId);
            }
            if (model.OrderId > 0)
            {
                where += string.Format(" AND " + nameof(RB_Finance_OrderRecord.OrderId) + "={0} ", model.OrderId);
            }
            if (model.FinanceId > 0)
            {
                where += string.Format(" AND " + nameof(RB_Finance_OrderRecord.FinanceId) + "={0} ", model.FinanceId);
            }
           
            if (model.Type > 0)
            {
                where += string.Format(" AND " + nameof(RB_Finance_OrderRecord.Type) + "={0} ", (int)model.Type);
            }
           
            return GetPage<RB_Finance_OrderRecord>(pageIndex, pageSize, out count, "select * from " + TableName + " " + where).ToList();
        }



        // <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<RB_Finance_OrderRecord> GetOrderRecordList( RB_Finance_OrderRecord model)
        {
            string where = " WHERE 1=1 ";
            if (model.RB_Group_Id > 0)
            {
                where += string.Format(" AND " + nameof(RB_Finance_OrderRecord.RB_Group_Id) + "={0} ", model.RB_Group_Id);
            }
            if (model.ContractId > 0)
            {
                where += string.Format(" AND " + nameof(RB_Finance_OrderRecord.ContractId) + "={0} ", model.ContractId);
            }
            if (model.OrderId > 0)
            {
                where += string.Format(" AND " + nameof(RB_Finance_OrderRecord.OrderId) + "={0} ", model.OrderId);
            }
            if (model.FinanceId > 0)
            {
                where += string.Format(" AND " + nameof(RB_Finance_OrderRecord.FinanceId) + "={0} ", model.FinanceId);
            }
            if (!string.IsNullOrWhiteSpace(model.OutTradeNo))
            {
                where += string.Format(" AND " + nameof(RB_Finance_OrderRecord.OutTradeNo) + "='{0}' ", model.OutTradeNo);
            }
            if (model.Type > 0)
            {
                where += string.Format(" AND " + nameof(RB_Finance_OrderRecord.Type) + "={0} ", (int)model.Type);
            }

            return Get<RB_Finance_OrderRecord>( "select * from " + TableName + " " + where).ToList();
        }
    }
}
