using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mall.Common.Enum;
using Mall.Model.Entity.Education;
using Mall.Model.Extend.Education;

namespace Mall.Repository.Education
{
    public class RB_Education_EduSellRepository : BaseRepository<RB_Education_EduSell>
    {
        /// <summary>
        /// 获取教育销售的基础信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Education_EduSell_Extend> GetEducationSellBaseInfo(RB_Education_EduSell_Extend query)
        {

            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT * 
FROM RB_Education_EduSell
WHERE 1=1
");
            builder.AppendFormat(" AND {0}={1} ", nameof(RB_Education_EduSell_Extend.Status), (int)DateStateEnum.Normal);
            if (query == null)
            {
                return new List<RB_Education_EduSell_Extend>();
            }
            else
            {
                if (query.TenantId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Education_EduSell_Extend.TenantId), query.TenantId);
                }
                if (query.MallBaseId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Education_EduSell_Extend.MallBaseId), query.MallBaseId);
                }
                if (query.UserId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Education_EduSell_Extend.UserId), query.UserId);
                }
                if (query.EduSellId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Education_EduSell_Extend.EduSellId), query.EduSellId);
                }
                if (!string.IsNullOrWhiteSpace(query.Ids))
                {
                    builder.AppendFormat($@" AND { nameof(RB_Education_EduSell_Extend.UserId)} in ({query.Ids}) ");
                }
            }
            return Get<RB_Education_EduSell_Extend>(builder.ToString()).ToList();
        }
    }
}
