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

namespace Edu.Repository.Finance
{
    /// <summary>
    /// 财务审批流程模版仓储层
    /// </summary>
    public class Rb_Workflow_TemplateRepository : BaseRepository<Rb_Workflow_Template>
    {
        /// <summary>
        /// 获取我审批的，待我审批的。
        /// </summary>
        /// <param name="model"></param>
        /// <param name="FrIdStr"></param>
        /// <returns></returns>
        public List<Rb_Workflow_Auditrecord> GetAgreeOrWaitList(Rb_Workflow_Auditrecord model, string FrIdStr = "")
        {
            string where = " WHERE 1=1 ";
            //审核人ID
            if (model.AuditEmId > 0)
            {
                where += string.Format(" AND " + nameof(Rb_Workflow_Auditrecord.AuditEmId) + "={0}", model.AuditEmId);
            }
            if (model.WorkFlowId > 0)
            {
                where += string.Format(" AND " + nameof(Rb_Workflow_Auditrecord.WorkFlowId) + "={0}", model.WorkFlowId);
            }
            if (!string.IsNullOrWhiteSpace(FrIdStr))
            {
                where += string.Format(" AND " + nameof(Rb_Workflow_Auditrecord.WorkFlowId) + " in({0})", FrIdStr);
            }
            if (model.AuditStatus > 0)
            {
                where += string.Format(" AND " + nameof(Rb_Workflow_Auditrecord.AuditStatus) + "={0}", (int)model.AuditStatus);
            }
            if (model.TemplateType > 0)
            {
                where += string.Format(" AND " + nameof(Rb_Workflow_Auditrecord.TemplateType) + "={0}", (int)model.TemplateType);
            }
            string sql = string.Format(" SELECT * FROM {0} {1}", nameof(Rb_Workflow_Auditrecord), where);
            return Get<Rb_Workflow_Auditrecord>(sql).ToList();
        }
    }
}
