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

namespace Edu.Repository.User
{
    /// <summary>
    /// 打卡记录扩展信息
    /// </summary>
    public partial class Rb_Workflow_TemplateRepository : BaseRepository<Rb_Workflow_Template>
    {
        /// <summary>
        /// 获取审批模版
        /// </summary>
        /// <param name="GroupId"></param>
        /// <param name="BranchId"></param>
        /// <returns></returns>
        public List<Rb_Workflow_Template> GetTempateList(int GroupId, int BranchId)
        {
            string where = " where 1=1";
            where += " and " + nameof(Rb_Workflow_Template.Type) + "=" + (int)WFTempTypeEnum.OA;
            if (GroupId > 0)
            {
                where += " and " + nameof(Rb_Workflow_Template.RB_GroupId) + "=" + GroupId;
            }
            if (BranchId >= 0)
            {
                where += " and " + nameof(Rb_Workflow_Template.RB_BranchId) + "=" + BranchId;
            }
            return Get($@" select * from Rb_Workflow_Template {where}").ToList();
        }

        /// <summary>
        /// 根据员工id获取审批模板
        /// </summary>
        /// <param name="empId"></param>
        /// <returns></returns>
        public List<Rb_Workflow_Template_Extend> GetTemplateByEmpId(int empId)
        {
            return Get<Rb_Workflow_Template_Extend>($@"SELECT * from rb_workflow_template t 
                    INNER JOIN rb_employee e on e.RB_Branch_id = t.RB_BranchId
                    where e.EmployeeId = {empId} and t.`Status` = 1 and t.RB_GroupId=e.RB_Group_id and t.Type=" + (int)WFTempTypeEnum.OA + "").ToList();
        }

        /// <summary>
        /// 根据员工id和模板类型获取对应审批模版
        /// </summary>
        /// <param name="empId">员工id</param>
        /// <param name="templateType">模板类型</param>
        /// <returns></returns>
        public Rb_Workflow_Template_Extend GetTempateByTempateType(int empId, int templateType)
        {
            return Get<Rb_Workflow_Template_Extend>($@"SELECT * from rb_workflow_template t 
                    INNER JOIN rb_employee e on e.RB_Branch_id = t.RB_BranchId
                    where e.EmployeeId = {empId} and t.`Status` = 1 AND t.TemplateType ={templateType}").FirstOrDefault();
        }
        /// <summary>
        /// 通过条件获取模板列表
        /// </summary>
        /// <param name="GroupId"></param>
        /// <param name="Type"></param>
        /// <param name="TempLateClass"></param>
        /// <param name="TemplateType"></param>
        /// <returns></returns>
        public List<Rb_Workflow_Template> GetTempateList(int GroupId,int Type,int TempLateClass,int TemplateType)
        {
            string where = " where 1=1";
            if (GroupId > 0)
            {
                where += " and " + nameof(Rb_Workflow_Template.RB_GroupId) + "=" + GroupId;
            }
            if (Type > 0)
            {
                where += " and " + nameof(Rb_Workflow_Template.Type) + "=" + Type;
            }
            if (TempLateClass > 0)
            {
                where += " and " + nameof(Rb_Workflow_Template.TempLateClass) + "=" + TempLateClass;
            }
            if (TemplateType > 0)
            {
                where += " and " + nameof(Rb_Workflow_Template.TemplateType) + "=" + TemplateType;
            }
            return Get($@" select * from Rb_Workflow_Template {where}").ToList();
        }
    }
}