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_AuditRelevanceRepository : BaseRepository<Rb_Workflow_AuditRelevance>
    {
        /// <summary>
        /// 根据工作流id和模版类型获取所有审核流程
        /// </summary>
        /// <param name="WorkFlowId">工作流ID</param>
        /// <param name="TemplateType">模板类型</param>
        /// <returns></returns>
        public List<Rb_Workflow_AuditRelevance_Extend> GetAuditRelevanceList(int WorkFlowId, int TemplateType)
        {
            string where = $@" where 1=1 ";
            if (WorkFlowId > 0)
            {
                where += $@" and ar.{nameof(Rb_Workflow_AuditRelevance.WorkFlowId) }={WorkFlowId}";
            }
            if (TemplateType > 0)
            {
                where += $@" and ar.{nameof(Rb_Workflow_AuditRelevance.TemplateType)}={TemplateType}";
            }
            string sql = $@"SELECT (select group_concat(e.EmName) from rb_employee e where instr(concat(',',ar.ToAuditId,','),concat(',',e.EmployeeId,','))) as ToAuditName,
ar.* from rb_workflow_auditrelevance ar {where} ORDER BY ar.Sort asc";
            return Get<Rb_Workflow_AuditRelevance_Extend>(sql).ToList();
        }
    }
}
