using System.Collections.Generic;
using System.Linq;
using Edu.Common.Enum;
using Edu.Model.Entity.Finance;
using Edu.Model.ViewModel.Finance;

namespace Edu.Repository.Finance
{
    /// <summary>
    /// 费用类型仓储层
    /// </summary>
    public class RB_CosttypeRepository : BaseRepository<RB_Costtype>
    {
        /// <summary>
        /// 表名称
        /// </summary>
        public string TableName { get { return nameof(RB_Costtype); } }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<RB_Costtype_Extend> GetList(RB_Costtype_Extend model)
        {
            string where = " WHERE 1=1 ";
            where += string.Format(" AND " + nameof(RB_Costtype.Status) + "={0} ", (int)DateStateEnum.Normal);
            if (model.RB_Group_Id > 0)
            {
                where += string.Format(" AND " + nameof(RB_Costtype.RB_Group_Id) + "={0} ", model.RB_Group_Id);
            }
            if (model.Type > 0)
            {
                where += string.Format(" AND " + nameof(RB_Costtype_Extend.Type) + " in({0},{1})", (int)model.Type, (int)Common.Enum.Finance.WFTempLateClassEnum.INAndOUT);
            }
            if (model.Tier > 0)
            {
                where += string.Format(" AND " + nameof(RB_Costtype.Tier) + "={0} ", model.Tier);
            }
            if (model.Is_Report >= 0)
            {
                where += string.Format(" AND " + nameof(RB_Costtype.Is_Report) + "={0} ", model.Is_Report);
            }
            if ((model.IsSecret ?? -1) >= 0)
            {
                where += string.Format(" AND " + nameof(RB_Costtype.IsSecret) + "={0} ", model.IsSecret);
            }
            if (!string.IsNullOrEmpty(model.Name))
            {
                where += string.Format(" AND " + nameof(RB_Costtype.Name) + " like '%{0}%' ", model.Name);
            }
            if (!string.IsNullOrEmpty(model.CName))
            {
                where += string.Format(" AND " + nameof(RB_Costtype.Name) + "='{0}'", model.CName);
            }
            if (!string.IsNullOrEmpty(model.CostIds))
            {
                where += string.Format(" AND " + nameof(RB_Costtype_Extend.ID) + " in({0})", model.CostIds);
            }
            return Get<RB_Costtype_Extend>("select * from " + TableName + where).ToList();
        }
    }
}
