 using Edu.Model.Entity.EduTask;
using Edu.Model.ViewModel.EduTask;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Edu.Repository.EduTask
{
    /// <summary>
    /// 教务单据审核记录仓储层
    /// </summary>
    public class RB_Education_RecordRepository : BaseRepository<RB_Education_Record>
    {
        /// <summary>
        /// 获取教务单据审核记录列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Education_Record_ViewModel> GetEducationRecordListRepository(RB_Education_Record_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*,IFNULL(B.AuditDescription,'') AS AuditNode
FROM RB_Education_Record AS A LEFT JOIN rb_education_relevance AS B ON A.AuditId=B.Id
WHERE 1=1
");
            if (query != null)
            {
                if (query.ConditionId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Education_Record_ViewModel.ConditionId), query.ConditionId);
                }
                if (query.AuditId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Education_Record_ViewModel.AuditId), query.AuditId);
                }
                if (!string.IsNullOrEmpty(query.QConditionIds))
                {
                    builder.AppendFormat(" AND A.{0} IN({1}) ", nameof(RB_Education_Record_ViewModel.ConditionId), query.QConditionIds);
                }
                if (query.AuditStatus > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Education_Record_ViewModel.AuditStatus), (int)query.AuditStatus);
                }
            }
            return Get<RB_Education_Record_ViewModel>(builder.ToString()).ToList();
        }
    }
}
